在进行高效的SHELL实践以前,首先配置一下基础环境,固然首先是须要一台MacOS电脑。这里采用: zsh
+ oh-my-zsh
+ zsh-completions
+ zsh-autosuggestions
。具体安装步骤以下:git
# 切换默认SHELL为 zsh
$: chsh -s /bin/zsh
# 安装 oh-my-zsh
$: sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# 安装 zsh-completions
$: git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-completions
# 安装 zsh-autosuggestions
$: git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
复制代码
安装完成后,轻松敲打几个命令,该提示的、补全的也都如预期般的展现,的确大大的提高了命令输入的效率。github
减小输入的另外一个办法就是对拼写复杂的命令设置简易的别名。alias
别名命令最常规的用法就是,定义别名。固然这是alias
命令的主要功能之一。不过它还具备其它功能,不细看的话很容易被忽略掉。shell
不妨经过tldr
命令查询看看alias
的功能列表:bash
$: tldr alias
alias
Creates aliases -- words that are replaced by a command string.
Aliases expire with the current shell session, unless they're defined in the shell's configuration file, e.g. `~/.bashrc`.
- List all aliases:
alias
- Create a generic alias:
alias word="command"
- View the command associated to a given alias:
alias word
- Remove an aliased command:
unalias word
- Turn `rm` into an interactive command:
alias rm="rm -i"
- Create `la` as a shortcut for `ls -a`:
alias la="ls -a"
复制代码
不难看出,alias
命令还有另外检索的功能,该功能在咱们设置别名时先判断是否已经存在别名很是有用。session
若是仅仅认为oh-my-zsh只是提供的个性化的主题脚本框架,真是过小看它了。它一套真正的基于zsh
的脚本框架,其真正的威力还表如今其提供的200多个插件上, 固然这些插件是须要安装的,在 oh-my-zsh
的插件目录中仅仅是这些工具的辅助函数或是别名。经过这个插件目录,咱们能够发现大量功能强大的工具。固然咱们也能够将本身经常使用的脚本放进来,做为独立的分支维护我的命令。app
一般,oh-my-zsh
都会开启默认插件git
功能。可是具体git
插件提供了哪些功能则须要经过插件的README文件。打开一看,里面提供的别名有 141 个之多,这么多的别名很明显是没法记忆的。框架
# 统计一些git的别名总数
$: alias | grep ^g | wc -l
141
复制代码
若是可以在使用时快速的查询这些别名,用时查询,一旦用得多了,也就记住了。先经过别名命令手动查询:less
$: alias | grep ^g
g=git
ga='git add'
gaa='git add --all'
gap='git apply'
gapa='git add --patch'
gau='git add --update'
gav='git add --verbose'
gb='git branch'
gbD='git branch -D'
...
复制代码
如今,咱们就能够经过将这个简单命令行,写出本身的脚本,集成的oh-my-zsh
的框架,做为本身的插件独立维护。在oh-my-zsh
的插件目录中,增长一个自定义的插件alias
.提供一个快速查询现有别名的功能。curl
$: mkdir ~/.oh-my-zsh/plugins/alias
$: cd ~/.oh-my-zsh/plugins/alias
$: cat <<EOF > alias.plugin.zsh
function alias-find(){
alias | grep $1
}
alias af="alias-find "
EOF
复制代码
完成编辑后,.zshrc
中增长alias
插件。从新开启新的SHELL窗口,如今就能够经过af
别名命令查询已有的别名了。svn
$: af commit
gc='git commit -v'
'gc!'='git commit -v --amend'
gca='git commit -v -a'
'gca!'='git commit -v -a --amend'
gcam='git commit -a -m'
'gcan!'='git commit -v -a --no-edit --amend'
'gcans!'='git commit -v -a -s --no-edit --amend'
gcmsg='git commit -m'
'gcn!'='git commit -v --no-edit --amend'
gcs='git commit -S'
gcsm='git commit -s -m'
gdt='git diff-tree --no-commit-id --name-only -r'
git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
gsd='git svn dcommit'
gwch='git whatchanged -p --abbrev-commit --pretty=medium'
gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]"'
复制代码
这样就能够快速的查询已有存在commit
内容的别名命令了。
oh-my-zsh
是一个脚本框架,若是使用该框架,尽量最大化的使用到它的功能。我的的alias
插件项目,请参阅:liujianping/oh-my-zsh.