• Mac下zsh配置


    zsh配置文件.zshrc设置:

    修改.zshrc文件,添加以下内容:

    #关于历史纪录的配置 {{{
    
    #历史纪录条目数量
    export HISTSIZE=10000
    #注销后保存的历史纪录条目数量
    export SAVEHIST=10000
    #历史纪录文件
    export HISTFILE=~/.histfile
    #以附加的方式写入历史纪录
    setopt INC_APPEND_HISTORY
    #如果连续输入的命令相同,历史纪录中只保留一个
    setopt HIST_IGNORE_DUPS
    #为历史纪录中的命令添加时间戳
    #setopt EXTENDED_HISTORY      
     
    #启用 cd 命令的历史纪录,cd -[TAB]进入历史路径
    setopt AUTO_PUSHD
    #相同的历史路径只保留一个
    setopt PUSHD_IGNORE_DUPS
     
    #在命令前添加空格,不将此命令添加到纪录文件中
    #setopt HIST_IGNORE_SPACE
    
    # 不保留重复的历史记录项
    setopt hist_ignore_all_dups
    # 在命令前添加空格,不将此命令添加到记录文件中
    setopt hist_ignore_space
    # zsh 4.3.6 doesn't have this option
    setopt hist_fcntl_lock 2>/dev/null
    setopt hist_reduce_blanks
    # 共享历史记录
    setopt SHARE_HISTORY
    
    #}}}
    
    

    使用上述的命令,就可以保存zsh历史记录

    特别是这一行,本来是要使用默认的历史记录文件.zsh_history,但是发现怎么都不行,换成下面就可以了

    export HISTFILE=~/.histfile
    

    这里设置以后就方便使用zsh-autosuggestions,不然的话,提示信息,每次重新打开终端就没有了

    更多的配置为:

    #杂项 {{{
    #允许在交互模式中使用注释 例如:
    #cmd #这是注释
    setopt INTERACTIVE_COMMENTS
    
    #启用自动 cd,输入目录名回车进入目录
    #稍微有点混乱,不如 cd 补全实用
    #setopt AUTO_CD
    
    #扩展路径
    #/v/c/p/p => /var/cache/pacman/pkg
    setopt complete_in_word
    
    #禁用 core dumps
    limit coredumpsize 0
    
    #Emacs风格 键绑定
    bindkey -e
    #设置 [DEL]键 为向后删除
    bindkey "e[3~" delete-char
    
    #以下字符视为单词的一部分
    WORDCHARS='*?_-[]~=&;!#$%^(){}<>'
    #}}}
    
    #自动补全功能 {{{
    setopt AUTO_LIST
    setopt AUTO_MENU
    #开启此选项,补全时会直接选中菜单项
    #setopt MENU_COMPLETE
    
    autoload -U compinit
    compinit
    
    #自动补全缓存
    #zstyle ':completion::complete:*' use-cache on
    #zstyle ':completion::complete:*' cache-path .zcache
    #zstyle ':completion:*:cd:*' ignore-parents parent pwd
    
    #自动补全选项
    zstyle ':completion:*' verbose yes
    zstyle ':completion:*' menu select
    zstyle ':completion:*:*:default' force-list always
    zstyle ':completion:*' select-prompt '%SSelect: lines: %L matches: %M   [%p]'
    
    zstyle ':completion:*:match:*' original only
    zstyle ':completion::prefix-1:*' completer _complete
    zstyle ':completion:predict:*' completer _complete
    zstyle ':completion:incremental:*' completer _complete _correct
    zstyle ':completion:*' completer _complete _prefix _correct _prefix   _match _approximate
    
    #路径补全
    zstyle ':completion:*' expand 'yes'
    zstyle ':completion:*' squeeze-slashes 'yes'
    zstyle ':completion::complete:*' '\'
    
    #修正大小写
    zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
    #错误校正
    zstyle ':completion:*' completer _complete _match _approximate
    zstyle ':completion:*:match:*' original only
    zstyle ':completion:*:approximate:*' max-errors 1 numeric
    
    #kill 命令补全
    compdef pkill=killall
    zstyle ':completion:*:*:kill:*' menu yes select
    zstyle ':completion:*:*:*:*:processes' force-list always
    zstyle ':completion:*:processes' command 'ps -au$USER'
    
    #补全类型提示分组
    zstyle ':completion:*:matches' group 'yes'
    zstyle ':completion:*' group-name ''
    zstyle ':completion:*:options' description 'yes'
    zstyle ':completion:*:options' auto-description '%d'
    zstyle ':completion:*:descriptions' format $'e[01;33m -- %d --e[0m'
    zstyle ':completion:*:messages' format $'e[01;35m -- %d --e[0m'
    zstyle ':completion:*:warnings' format $'e[01;31m -- No Matches Found --e[0m'
    zstyle ':completion:*:corrections' format $'e[01;32m -- %d (errors: %e) --e[0m'
    
    # cd ~ 补全顺序
    zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path- directories' 'users' 'expand'
    #}}}
    
    ##行编辑高亮模式 {{{
    # Ctrl+@ 设置标记,标记和光标点之间为 region
    zle_highlight=(region:bg=magenta #选中区域
    special:bold #特殊字符
    isearch:underline)#搜索时使用的关键字
    #}}}
    
    ##空行(光标在行首)补全 "cd " {{{
    user-complete(){
    case $BUFFER in
    "" ) # 空行填入 "cd "
    BUFFER="cd "
    zle end-of-line
    zle expand-or-complete
    ;;
    "cd " ) # TAB + 空格 替换为 "cd ~"
    BUFFER="cd ~"
    zle end-of-line
    zle expand-or-complete
    ;;
    " " )
    BUFFER="!?"
    zle end-of-line
    ;;
    "cd --" ) # "cd --" 替换为 "cd +"
    BUFFER="cd +"
    zle end-of-line
    zle expand-or-complete
    ;;
    "cd +-" ) # "cd +-" 替换为 "cd -"
    BUFFER="cd -"
    zle end-of-line
    zle expand-or-complete
    ;;
    * )
    zle expand-or-complete
    ;;
    esac
    }
    zle -N user-complete
    bindkey "	" user-complete
    
    #显示 path-directories ,避免候选项唯一时直接选中
    cdpath="/home"
    #}}}
    
    ##在命令前插入 sudo {{{
    #定义功能
    sudo-command-line() {
    [[ -z $BUFFER ]] && zle up-history
    [[ $BUFFER != sudo * ]] && BUFFER="sudo $BUFFER"
    zle end-of-line #光标移动到行末
    }
    zle -N sudo-command-line
    #定义快捷键为: [Esc] [Esc]
    bindkey "ee" sudo-command-line
    #}}}
     
    

    这些是网上找到的,但是我并没有使用,没有研究.

    zsh别名设置:

    zkc='zkCli.sh -server
     
    
    alias setproxy='export ALL_PROXY=socks5://127.0.0.1:1080'
    alias setall='export ALL_PROXY=socks5://127.0.0.1:1080'
    alias sethttps='export https_proxy=https://127.0.0.1:1087'
    alias sethttp='export http_proxy=http://127.0.0.1:1087'
    
    alias usall='export ALL_PROXY='
    alias ushttps='export https_proxy='
    alias ushttp='export http_proxy='
    
    
    alias mcm='mvn compile -Dmaven.test.skip=true'
    alias mpm='mvn package -Dmaven.test.skip=true'
    alias mim='mvn install -Dmaven.test.skip=true'
    alias mcmc='mvn compile -Dmaven.test.skip=true --settings /Users/hongda/.m2/settings.xml'
    alias mpmc='mvn package -Dmaven.test.skip=true --settings /Users/hongda/.m2/settings.xml'
    alias mimc='mvn install -Dmaven.test.skip=true --settings /Users/hongda/.m2/settings.xml'
    alias mcs='mvn compile -DskipTests'
    alias mps='mvn package -DskipTests'
    alias mis='mvn install -DskipTests'
    alias mcsc='mvn compile -DskipTests --settings /Users/hongda/.m2/settings.xml'
    alias mpsc='mvn package -DskipTests --settings /Users/hongda/.m2/settings.xml'
    alias misc='mvn install -DskipTests --settings /Users/hongda/.m2/settings.xml'
    alias mccm='mvn clean compile -Dmaven.test.skip=true'
    alias mcpm='mvn clean package -Dmaven.test.skip=true'
    alias mcim='mvn clean install -Dmaven.test.skip=true'
    alias mccmc='mvn clean compile -Dmaven.test.skip=true --settings /Users/hongda/.m2/settings.xml'
    alias mcpmc='mvn clean package -Dmaven.test.skip=true --settings /Users/hongda/.m2/settings.xml'
    alias mcimc='mvn clean install -Dmaven.test.skip=true --settings /Users/hongda/.m2/settings.xml'
    alias mccs='mvn clean compile -DskipTests'
    alias mcps='mvn clean package -DskipTests'
    alias mcis='mvn clean install -DskipTests'
    alias mccsc='mvn clean compile -DskipTests --settings /Users/hongda/.m2/settings.xml'
    alias mcpsc='mvn clean package -DskipTests --settings /Users/hongda/.m2/settings.xml'
    alias mcisc='mvn clean install -DskipTests --settings /Users/hongda/.m2/settings.xml'
    alias mdt='mvn dependency:tree'
    alias mdtv='mvn dependency:tree -Dverbose'
    alias mdti='mvn dependency:tree -Dincludes='
    alias mdte='mvn dependency:tree -Dexcludes='
    alias mdtvi='mvn dependency:tree -Dverbose -Dincludes='
    alias mdtve='mvn dependency:tree -Dverbose -Dexcludes='
    alias mdd='mvn deploy -Dnexus=18.16.200.10:8081'
    alias mdp='mvn dependency:purge-local-repository'
    alias mdpi='mvn dependency:purge-local-repository -Dincludes='
    alias mdpe='mvn dependency:purge-local-repository -Dexcludes='
    alias mdpa='mvn dependency:purge-local-repository -DactTransitively=false'
    alias mdpai='mvn dependency:purge-local-repository -DactTransitively=false -Dincludes='
    alias mdpae='mvn dependency:purge-local-repository -DactTransitively=false -Dexcludes='
    alias mdpr='mvn dependency:purge-local-repository -DreResolve=false'
    alias mdpri='mvn dependency:purge-local-repository -DreResolve=false -Dincludes='
    alias mdpre='mvn dependency:purge-local-repository -DreResolve=false -Dexcludes='
    alias mdpar='mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false'
    alias mdparf='mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false --fail-at-end'
    alias mdpari='mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false -Dincludes='
    alias mdpare='mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false -Dexcludes='
    alias mdparm='mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false -DmanualIncludes='
    alias mcpd='mvn clean package docker:build'
    alias mcpdp='mvn clean package docker:build -DpushImage'
    alias mcpdpm='mvn clean package docker:build -DpushImage -Dmaven.test.skip=true'
    alias mcpdpms='mvn clean package docker:build -DpushImage -Dmaven.test.skip=true  --settings /Users/hongda/.m2/settings.xml'
    alias ga='git add '
    alias gaa='git add . '
    alias gb='git branch '
    alias gba='git branch -a '
    alias gbc='git branch --contains '
    alias gbr='git branch '
    alias gbuu='git branch --unset-upstream '
    alias gca='git commit - a '
    alias gcc='git commit -a -m '
    alias gci='git commit '
    alias gcl='git clone '
    alias gcm='git commit -m '
    alias gco='git checkout '
    alias gcoo='git checkout --orphan '
    alias gcov='git count-objects -v '
    alias gcp='git cherry-pick '
    alias gcv='git cherry -v '
    alias gcvm='git cherry -v master  '
    alias gd='git diff '
    alias gdc='git diff --cached '
    alias gf='git fsck '
    alias gl='git l '
    alias gle='git l --grep='
    alias glg='git lg  '
    alias glgg='git lgg '
    alias gln='git l --author='
    alias gmn='git merge --no-ff '
    alias gms='git merge --squash '
    alias gmt='git mergetool '
    alias gnb='git checkout -b '
    alias gp='git pull '
    alias gpa='sh gpa.sh'
    alias gpl='git pull origin '
    alias gplm='git pull origin master '
    alias gpr='git prune '
    alias gps='git push origin '
    alias gpsm='git push origin master '
    alias gr='git rebase '
    alias grh='git reset --hard '
    alias gri='git rebase -i '
    alias grpo='git remote prune origin '
    alias grs='git reset '
    alias gs='git show '
    alias gst='git status -sb '
    alias gt='git tag '
    
    alias dnsclear="dscacheutil -flushcache"
    

    zsh设置带参数的别名设置

    #alias example='f() { echo Your arg was $1. };f'
    
    alias gle='gle() { git l --grep=$1 };gle'
    alias gln='gln() { git l --author=$1 };gln'
    

    可以使用这种方式,可以用第一个进行测试,或者写成方法也是可以的.

    example(){echo your arg was $1 };
    

    linux中shell变量(#,)@,$0,$1,$2的含义解释:

    变量说明: 
    $$ 
    Shell本身的PID(ProcessID) 
    $! 
    Shell最后运行的后台Process的PID 
    $? 
    最后运行的命令的结束代码(返回值) 
    $- 
    使用Set命令设定的Flag一览 
    $* 
    所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。 
    $@ 
    所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。 
    $# 
    添加到Shell的参数个数 
    $0 
    Shell本身的文件名 
    $1~$n 
    添加到Shell的各参数值。$1是第1参数、$2是第2参数…。 
    

    Oh-my-zsh插件中git几个特殊的命令

    function ggl() {
      if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
        git pull origin "${*}"
      else
        [[ "$#" == 0 ]] && local b="$(git_current_branch)"
        git pull origin "${b:=$1}"
      fi
    }
    compdef _git ggl=git-checkout
    
    function ggp() {
      if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
        git push origin "${*}"
      else
        [[ "$#" == 0 ]] && local b="$(git_current_branch)"
        git push origin "${b:=$1}"
      fi
    }
    compdef _git ggp=git-checkout
    
    function ggpnp() {
      if [[ "$#" == 0 ]]; then
        ggl && ggp
      else
        ggl "${*}" && ggp "${*}"
      fi
    }
    compdef _git ggpnp=git-checkout
    
    function ggu() {
      [[ "$#" != 1 ]] && local b="$(git_current_branch)"
      git pull --rebase origin "${b:=$1}"
    }
    
    alias ggpull='git pull origin "$(git_current_branch)"'
    alias ggpush='git push origin "$(git_current_branch)"'
    
    alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
    alias gpsup='git push --set-upstream origin $(git_current_branch)'
    
    alias gpoat='git push origin --all && git push origin --tags'
    

    参考:

    手动保存/读取 zsh 历史记录

    强大的zsh配置文件

    Zsh (简体中文)

    Zsh使用

  • 相关阅读:
    Mysql 批量插入数据的方法
    sql server 多行合并一行
    跨服务器多库多表查询
    OPENQUERY用法以及使用需要注意的地方
    C# 判断操作系统的位数
    rpc介绍
    JavaScript decodeURI()与decodeURIComponent() 使用与区别
    UNIX 时间戳 C#
    C# winform javascript 互调用
    oracle 实例名和服务名以及数据库名区别
  • 原文地址:https://www.cnblogs.com/hongdada/p/12992661.html
Copyright © 2020-2023  润新知