美文网首页
Mac/Linux使用ZSH (oh-my-zsh)

Mac/Linux使用ZSH (oh-my-zsh)

作者: 大道至简_Andy | 来源:发表于2016-09-17 14:24 被阅读1092次

    写在最前

    平时比较喜欢命令行,不喜欢从图形化界面一个个的点过去;感觉还是命令搜索,查找方便些,快速些。但是,Bash本身提供的功能又不够方便,自己也懒得折腾。幸得github上有前辈大神们开源的 zsh工具集,甚至方便。此工具可以很方便的统一我们的平时的命令,无论在mac,linux,unix上,基本都可以使用同样的命令,配置。oh-my-zsh的提示功能非常强悍,插件功能更是牛x,支持各种语法着色等等,大神们又分享出自己平时常用的命令简写,值得平实用linux/mac的程序员们一试。我用zsh的时间也不短了,平实很少有命令需要我自己添加alias的,由此可见oh-my-zsh的alias功能很实用。

    1. 从github下载并安装oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh
    2. 开启下面的plugins: 大致位置在~/.zshrc的第52行:plugins=(git brew sublime web-search osx npm node mvn last-working-dir history httpie encode64 dirhistory macports redis-cli sudo systemd urltools wd github common-aliases)
      如图:
      aliases.png

    设置好后,别忘记source下。source ~/.zshrc设置生效后,zsh会帮我们增加很多命令的别名和有用的工具,大大提高我们的效率。增加的命令(根据上面开启的插件)
    如下:

    -='cd -'
    ...=../..
    ....=../../..
    .....=../../../..
    ......=../../../../..
    1='cd -'
    2='cd -2'
    3='cd -3'
    4='cd -4'
    5='cd -5'
    6='cd -6'
    7='cd -7'
    8='cd -8'
    9='cd -9'
    CA='2>&1 | cat -A'
    G='| grep'
    H='| head'
    L='| less'
    LL='2>&1 | less'
    M='| most'
    NE='2> /dev/null'
    NUL='> /dev/null 2>&1'
    P='2>&1| pygmentize -l pytb'
    T='| tail'
    _=sudo
    afind='ack -il'
    baidu='web_search baidu'
    bing='web_search bing'
    brews='brew list -1'
    bubc='brew upgrade && brew cleanup'
    bubo='brew update && brew outdated'
    bubu='bubo && bubc'
    cp='cp -i'
    d='dirs -v | head -10'
    d64=decode64
    ddg='web_search duckduckgo'
    ducky='web_search duckduckgo \!'
    dud='du -d 1 -h'
    duf='du -sh *'
    e64=encode64
    ecosia='web_search ecosia'
    fd='find . -type d -name'
    ff='find . -type f -name'
    g=git
    ga='git add'
    gaa='git add --all'
    gapa='git add --patch'
    gb='git branch'
    gba='git branch -a'
    gbda='git branch --no-color --merged | command grep -vE "^(\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d'
    gbl='git blame -b -w'
    gbnm='git branch --no-merged'
    gbr='git branch --remote'
    gbs='git bisect'
    gbsb='git bisect bad'
    gbsg='git bisect good'
    gbsr='git bisect reset'
    gbss='git bisect start'
    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'
    gcb='git checkout -b'
    gcd='git checkout develop'
    gcf='git config --list'
    gcl='git clone --recursive'
    gclean='git clean -fd'
    gcm='git checkout master'
    gcmsg='git commit -m'
    'gcn!'='git commit -v --no-edit --amend'
    gco='git checkout'
    gcount='git shortlog -sn'
    gcp='git cherry-pick'
    gcpa='git cherry-pick --abort'
    gcpc='git cherry-pick --continue'
    gcs='git commit -S'
    gd='git diff'
    gdca='git diff --cached'
    gdct='git describe --tags `git rev-list --tags --max-count=1`'
    gdt='git diff-tree --no-commit-id --name-only -r'
    gdw='git diff --word-diff'
    gf='git fetch'
    gfa='git fetch --all --prune'
    gfo='git fetch origin'
    gg='git gui citool'
    gga='git gui citool --amend'
    ggpull='git pull origin $(git_current_branch)'
    ggpur=ggu
    ggpush='git push origin $(git_current_branch)'
    ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
    ghh='git help'
    gignore='git update-index --assume-unchanged'
    gignored='git ls-files -v | grep "^[[:lower:]]"'
    git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
    github='web_search github'
    gk='\gitk --all --branches'
    gke='\gitk --all $(git log -g --pretty=%h)'
    gl='git pull'
    glg='git log --stat'
    glgg='git log --graph'
    glgga='git log --graph --decorate --all'
    glgm='git log --graph --max-count=10'
    glgp='git log --stat -p'
    glo='git log --oneline --decorate'
    globurl='noglob urlglobber '
    glog='git log --oneline --decorate --graph'
    gloga='git log --oneline --decorate --graph --all'
    glol='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit'
    glola='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --all'
    glp=_git_log_prettily
    glum='git pull upstream master'
    gm='git merge'
    gmom='git merge origin/master'
    gmt='git mergetool --no-prompt'
    gmtvim='git mergetool --no-prompt --tool=vimdiff'
    gmum='git merge upstream/master'
    google='web_search google'
    gp='git push'
    gpd='git push --dry-run'
    gpoat='git push origin --all && git push origin --tags'
    gpristine='git reset --hard && git clean -dfx'
    gpsup='git push --set-upstream origin $(git_current_branch)'
    gpu='git push upstream'
    gpv='git push -v'
    gr='git remote'
    gra='git remote add'
    grb='git rebase'
    grba='git rebase --abort'
    grbc='git rebase --continue'
    grbi='git rebase -i'
    grbm='git rebase master'
    grbs='git rebase --skip'
    grep='grep --color'
    grh='git reset HEAD'
    grhh='git reset HEAD --hard'
    grmv='git remote rename'
    grrm='git remote remove'
    grset='git remote set-url'
    grt='cd $(git rev-parse --show-toplevel || echo ".")'
    gru='git reset --'
    grup='git remote update'
    grv='git remote -v'
    gsb='git status -sb'
    gsd='git svn dcommit'
    gsi='git submodule init'
    gsps='git show --pretty=short --show-signature'
    gsr='git svn rebase'
    gss='git status -s'
    gst='git status'
    gsta='git stash save'
    gstaa='git stash apply'
    gstc='git stash clear'
    gstd='git stash drop'
    gstl='git stash list'
    gstp='git stash pop'
    gsts='git stash show --text'
    gsu='git submodule update'
    gts='git tag -s'
    gtv='git tag | sort -V'
    gunignore='git update-index --no-assume-unchanged'
    gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
    gup='git pull --rebase'
    gupv='git pull --rebase -v'
    gwch='git whatchanged -p --abbrev-commit --pretty=medium'
    gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit -m "--wip--"'
    h=history
    help=man
    hgrep='fc -El 0 | grep'
    hidefiles='defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder'
    history='fc -l 1'
    hsi='hs -i'
    image='web_search duckduckgo \!i'
    l='ls -lFh'
    lS='ls -1FSsh'
    la='ls -lAFh'
    lart='ls -1Fcart'
    ldot='ls -ld .*'
    ll='ls -lfG'
    lr='ls -tRFh'
    lrt='ls -1Fcrt'
    ls='ls -G'
    lsa='ls -lah'
    lt='ls -ltFh'
    map='web_search duckduckgo \!m'
    md='mkdir -p'
    mv='mv -i'
    mvn-updates='mvn versions:display-dependency-updates'
    mvnag='mvn archetype:generate'
    mvnc='mvn clean'
    mvnce='mvn clean eclipse:clean eclipse:eclipse'
    mvnci='mvn clean install'
    mvncie='mvn clean install eclipse:eclipse'
    mvncist='mvn clean install -DskipTests'
    mvncisto='mvn clean install -DskipTests --offline'
    mvncom='mvn compile'
    mvnct='mvn clean test'
    mvnd='mvn deploy'
    mvndocs='mvn dependency:resolve -Dclassifier=javadoc'
    mvndt='mvn dependency:tree'
    mvne='mvn eclipse:eclipse'
    mvnjetty='mvn jetty:run'
    mvnp='mvn package'
    mvns='mvn site'
    mvnsrc='mvn dependency:sources'
    mvnt='mvn test'
    mvntc='mvn tomcat:run'
    mvntc7='mvn tomcat7:run'
    news='web_search duckduckgo \!n'
    npmD='npm i -D '
    npmE='PATH="$(npm bin)":"$PATH"'
    npmO='npm outdated'
    npmS='npm i -S '
    npmg='npm i -g '
    npmst='npm start'
    npmt='npm test'
    ofd='open_command $PWD'
    p='ps -f'
    pc='sudo port clean --all installed'
    pi='sudo port install '
    please=sudo
    po=popd
    psu='sudo port selfupdate'
    pu=pushd
    puni='sudo port uninstall inactive'
    puo='sudo port upgrade outdated'
    pup='psu && puo'
    rd=rmdir
    rm='rm -i'
    run-help=man
    sc-cancel='sudo systemctl cancel'
    sc-cat='systemctl cat'
    sc-disable='sudo systemctl disable'
    sc-disable-now='sc-disable --now'
    sc-edit='sudo systemctl edit'
    sc-enable='sudo systemctl enable'
    sc-enable-now='sc-enable --now'
    sc-help='systemctl help'
    sc-is-active='systemctl is-active'
    sc-is-enabled='systemctl is-enabled'
    sc-isolate='sudo systemctl isolate'
    sc-kill='sudo systemctl kill'
    sc-link='sudo systemctl link'
    sc-list-jobs='systemctl list-jobs'
    sc-list-timers='systemctl list-timers'
    sc-list-unit-files='systemctl list-unit-files'
    sc-list-units='systemctl list-units'
    sc-load='sudo systemctl load'
    sc-mask='sudo systemctl mask'
    sc-mask-now='sc-mask --now'
    sc-preset='sudo systemctl preset'
    sc-reenable='sudo systemctl reenable'
    sc-reload='sudo systemctl reload'
    sc-reset-failed='sudo systemctl reset-failed'
    sc-restart='sudo systemctl restart'
    sc-set-environment='sudo systemctl set-environment'
    sc-show='systemctl show'
    sc-show-environment='systemctl show-environment'
    sc-start='sudo systemctl start'
    sc-status='systemctl status'
    sc-stop='sudo systemctl stop'
    sc-try-restart='sudo systemctl try-restart'
    sc-unmask='sudo systemctl unmask'
    sc-unset-environment='sudo systemctl unset-environment'
    sgrep='grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS} '
    shadowSocks='/Volumes/Shadowsocks/ShadowsocksX.app/Contents/MacOS/ShadowsocksX &'
    showfiles='defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder'
    sortnr='sort -n -r'
    sp='web_search startpage'
    st=subl
    stp=find_project
    stt='st .'
    t='tail -f'
    targz='tar -zxvf'
    unexport=unset
    urldecode='node -e "console.log(decodeURIComponent(process.argv[1]))"'
    urlencode='node -e "console.log(encodeURIComponent(process.argv[1]))"'
    vi=vim
    whereami=display_info
    which-command=whence
    wiki='web_search duckduckgo \!w'
    yahoo='web_search yahoo'
    yandex='web_search yandex'
    youtube='web_search duckduckgo \!yt'
    zshrc='$EDITOR ~/.zshrc'
    

    根据上面的例子,简单举几个例子:

    1. 命令行快速Google google "andy"
      如图:

      google.png
    2. 使用 encode64
      如图:

      en64.png

    写在最后

    很多实用命令和工具,值得一试。 zsh可以用在Mac, Linux等unix-like系统上。 插件列表和介绍的地址: https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
    以上是简单的记录,防止以后自己忘记。

    相关文章

      网友评论

          本文标题:Mac/Linux使用ZSH (oh-my-zsh)

          本文链接:https://www.haomeiwen.com/subject/jexwettx.html