Neurohazard
暮雲煙月,皓首窮經;森羅萬象,如是我聞。

oh-my-zsh Agnoster 主题配置

wpadmin~August 23, 2018 /System Management

Contents

zsh 相关配置

oh-my-zsh Agnoster theme configration

zsh Agnoster 主题

操作指南

切换 oh-my-zsh 主题

vim ~/.zshrc
#================
ZSH_THEME="agnoster"
#================

安装 Powerline 字体

git clone https://github.com/powerline/fonts.git
cd fonts
./install.sh

参考资料

Jazz Up Your “ZSH” Terminal In Seven Steps — A Visual Guide
https://medium.freecodecamp.org/jazz-up-your-zsh-terminal-in-seven-steps-a-visual-guide-e81a8fd59a38

Super Charging Terminal with Powerline
https://blog.netsarang.com/93/super-charging-terminal-with-powerline/

agnoster-zsh-theme
https://github.com/agnoster/agnoster-zsh-theme

oh-my-zsh wiki Themes
https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

OhMyZsh,Agnoster主题配置
https://swp-song.com/2017/09/04/Tools/OhMyZsh%E4%B8%ADAgnoster%E4%B8%BB%E9%A2%98%E9%85%8D%E7%BD%AE/

主动更新 oh-my-zsh

omz update

【推荐】自动补全插件 zsh-autosuggestions

https://www.jianshu.com/p/aea390c1c8ef

【废弃】incr 增量自动补全插件 (不建议用 incr)

incr 这个插件扩展了 zsh 的自动补全功能,每按一个按键就会有补全提示,这个功能和 fish 的自动补全有些接近。

操作指南

1 新建插件目录 mkdir ~/.oh-my-zsh/plugins/incr
2 下载源码 wget https://raw.githubusercontent.com/ggggle/myEnv/master/ubuntu/.oh-my-zsh/plugins/incr/incr-0.2.zsh,权限设置可以 644
3 修改配置文件 vim ~/.zshrc,在结尾添加如下内容 source ~/.oh-my-zsh/plugins/incr/incr*.zsh

插件源码

原始地址
http://mimosa-pudica.net/zsh-incremental.html
http://mimosa-pudica.net/src/incr-0.2.zsh

修改版地址
https://raw.githubusercontent.com/ggggle/myEnv/master/ubuntu/.oh-my-zsh/plugins/incr/incr-0.2.zsh

# 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"
        BUFFER="$buffer_org"
        CURSOR="$cursor_org"
        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 (incr 修改版) zsh-incr自动补全插件
2 How to make zsh completion show the first guess on the same line (like fish’s)?
3 https://github.com/zsh-users/zsh-autosuggestions
4 incr.zsh 补全插件 让你在zsh 模式下全自动补全指令或目录

其他补充

1 那些我希望在一开始使用 Zsh(oh-my-zsh) 时就知道的

Leave a Reply

Your email address will not be published. Required fields are marked *