起因
公司内部每个人需要负责的应用都有不少,刚入职时候,对一些站点地址不熟,有时想打开某个应用对应的git仓库都要翻一会浏览器。
方案确定
日常开发工作中,我会打开很多项目对应的vscode,那是不是可以通过本地与远程仓库的对应关系快速定位打开应用的git仓库。
我使用的终端也是 iTerm2 + Oh My Zsh,所以最后的方案就是写一个zsh插件,通过一个命令直接打开本地应用对应的git仓库页面。
插件代码
因为做的事情比较简单,所以代码比较少。
jump() {
isGitStash=$(command git rev-parse --is-inside-work-tree)
if [[ "$isGitStash" == "true" ]] {
gitAddress=$(command git remote get-url origin)
echo $gitAddress
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --enable-speech-input $gitAddress
} else {
echo $isGitStash
}
}
安装使用
1.将文件克隆到 .oh-my-zsh 文件夹下
git clone https://git.cai-inc.com/f2e-cube/plugins/zsh-jump-git.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-jump-git
2. 修改 .zshrc
命令行输入
code ~/.zshrc
在.zshrc文件中加入一行
source $ZSH/custom/plugins/zsh-jump-git/zsh-jump-git.zsh
保存,最后再应用一下 .zshrc 配置文件即可
source ~/.zshrc
3. 使用
在命令行输入 jump