Oh-my-zsh插件

使用方法

1
2
3
4
5
vim ~/.zshrc
//找到下面这句,添加相应的插件 插件之间用空格分隔
plugins=(git z zsh-syntax-highlighting zsh-autosuggestions)
//使配置文件生效
source ~/.zshrc

Git 默认已开启

  • 可以使用各种 git 命令缩写。比如
    1
    2
    git add --all ===> gaa
    git commit -m ===> gcmsg
  • 看所有 git 命令缩写
    1
    cat ~/.oh-my-zsh/plugins/git/git.plugin.zsh

autojump

  • Hithub Rpo
  • 已经内置了,直接在.zshrc 配置文件添加即可。
  • 目录间快速跳转,不用再一直 cd 了

使用

  • 使用 autojump 的缩写 j
  • cd 命令进入~/user/github/Noye 文件夹,下一次再想进入Notr 文件夹的时候,直接j Note 即可,或者只输入 Note 的一部分 Not 都行.
  • 删除无效路径
    • j --purge 无效路径类似组件Z (也内置了,直接改配置文件即可)删除无效路径它的命令更短z -x 无效路径

zscrh-syntax-highlighting

  • Github Rpo

  • 作用:平常用的 ls cd 等命令输入正确会绿色高亮显示,输入错误会显示其他的颜色。

安装

  • 克隆项目
    1
    2
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
    echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
  • ~/.zshrc 中配置
    1
    plugins=(zsh-syntax-highlighting)

zsh-autosuggestions

输入命令时,会给出建议的命令

安装

  • 克隆项目
    1
    git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
  • ~/.zshrc 中配置
    1
    plugins=(zsh-autosuggestions)

incr

  • Ubuntu sudo
    1
    apt-get install zsh
  • ArchLinux
    1
    yacman -S #!/usr/bin/env zsh
  • 安装完成后执行:
    1
    chsh -s /bin/zsh

安装 oh my zsh

  • 自动安装:
    1
    wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
  • 手动安装:
    1
    2
    3
    4
    git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
    cp ~/.zshrc ~/.zshrc.orig
    cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
    chsh -s /bin/zsh

下载 incr

: 下载地址

  • 代码摘录如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    # Incremental completion for zsh
    # by y.fujii <y-fujii at mimosa-pudica.net>, public domain


    autoload -U compinit
    zle -N self-insert self-insert-incr
    zle -N vi-cmd-mode-incr
    zle -N vi-backward-delete-char-incr
    zle -N backward-delete-char-incr
    zle -N expand-or-complete-prefix-incr
    compinit

    bindkey -M viins '^[' vi-cmd-mode-incr
    bindkey -M viins '^h' vi-backward-delete-char-incr
    bindkey -M viins '^?' vi-backward-delete-char-incr
    bindkey -M viins '^i' expand-or-complete-prefix-incr
    bindkey -M emacs '^h' backward-delete-char-incr
    bindkey -M emacs '^?' backward-delete-char-incr
    bindkey -M emacs '^i' expand-or-complete-prefix-incr

    unsetopt automenu
    compdef -d scp
    compdef -d tar
    compdef -d make
    compdef -d java
    compdef -d svn
    compdef -d cvs

    # TODO:
    # cp dir/

    now_predict=0

    function limit-completion
    {
    if ((compstate[nmatches] <= 1)); then
    zle -M ""
    elif ((compstate[list_lines] > 6)); then
    compstate[list]=""
    zle -M "too many matches."
    fi
    }

    function correct-prediction
    {
    if ((now_predict == 1)); then
    if [[ "$BUFFER" != "$buffer_prd" ]] || ((CURSOR != cursor_org)); then
    now_predict=0
    fi
    fi
    }

    function remove-prediction
    {
    if ((now_predict == 1)); then
    BUFFER="$buffer_org"
    now_predict=0
    fi
    }

    function show-prediction
    {
    # assert(now_predict == 0)
    if
    ((PENDING == 0)) &&
    ((CURSOR > 1)) &&
    [[ "$PREBUFFER" == "" ]] &&
    [[ "$BUFFER[CURSOR]" != " " ]]
    then
    cursor_org="$CURSOR"
    buffer_org="$BUFFER"
    comppostfuncs=(limit-completion)
    zle complete-word
    cursor_prd="$CURSOR"
    buffer_prd="$BUFFER"
    if [[ "$buffer_org[1,cursor_org]" == "$buffer_prd[1,cursor_org]" ]]; then
    CURSOR="$cursor_org"
    if [[ "$buffer_org" != "$buffer_prd" ]] || ((cursor_org != cursor_prd)); then
    now_predict=1
    fi
    else
    BUFFER="$buffer_org"
    CURSOR="$cursor_org"
    fi
    echo -n "\e[32m"
    else
    zle -M ""
    fi
    }

    function preexec
    {
    echo -n "\e[39m"
    }

    function vi-cmd-mode-incr
    {
    correct-prediction
    remove-prediction
    zle vi-cmd-mode
    }

    function self-insert-incr
    {
    correct-prediction
    remove-prediction
    if zle .self-insert; then
    show-prediction
    fi
    }

    function vi-backward-delete-char-incr
    {
    correct-prediction
    remove-prediction
    if zle vi-backward-delete-char; then
    show-prediction
    fi
    }

    function backward-delete-char-incr
    {
    correct-prediction
    remove-prediction
    if zle backward-delete-char; then
    show-prediction
    fi
    }

    function expand-or-complete-prefix-incr
    {
    correct-prediction
    if ((now_predict == 1)); then
    CURSOR="$cursor_prd"
    now_predict=0
    comppostfuncs=(limit-completion)
    zle list-choices
    else
    remove-prediction
    zle expand-or-complete-prefix
    fi
    }
  • 执行如下命令:

    1
    2
    3
    4
    5
    cd ~/.oh-my-zsh/plugins/
    mkdir -p incr
    cd incr
    vim incr-0.2.zsh //(将代码复制粘贴到incr-0.2.zsh文件中)
    chmod 777 incr-0.2.zsh

配置 .zshrc 文件

  1. vim ~/.zshrc
    末尾加入
  2. ource ~/.oh-my-zsh/plugins/incr/incr*.zsh
  3. source ~/.zshrc #使其立即生效

本站由 VITAN 使用 Stellar 主题创建。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。