帮助

  • man zshall

    • 即:zsh all
    • 包含所有 zsh 文档说明

zsh-autocomplete

ref: https://github.com/marlonrichert/zsh-autocomplete/discussions/308

问题:

配置文件 $XDG_CONFIG_HOME

参考:zshrc - How to make zsh search configuration in $XDG_CONFIG_HOME - Stack Over…

方法:

  1. 修改 /etc/zsh/zshenv

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    if [[ -z "$XDG_CONFIG_HOME" ]]
    then
            export XDG_CONFIG_HOME="$HOME/.config/"
    fi
    
    if [[ -d "$XDG_CONFIG_HOME/zsh" ]]
    then
            export ZDOTDIR="$XDG_CONFIG_HOME/zsh/"
    fi

bindkey 快捷键绑定

参考:

注意:

  • Shift 按键无法被绑定,即 Ctrl + B 和 Ctrl + b 同等效果

按键名称获取

步骤:

  1. 输入 bindkey
  2. 输入空格
  3. 按下 C-v
  4. 按下想要查询的按键

举例:

1
2
bindkey Ctrl + v Alt + b
# output: "^[b" backward-word

解释:

  1. "^[b" : Alt + b 的按键名称
  2. backward-word : Alt + b 被绑定的函数名称

组合按键查看

ctrl + x ctrl +h : bindkey [ctrl + v][ctrl + x] [ctrl + v][ctrl + h] 注意:

  • 每一组按键之前都要加 ctrl + v

    • 类似 string 中的转义符号

绑定按键到函数

1
bindkey "^[b" backward-word

绑定按键到 string

1
bindkey -s "key-name" "string"

说明:

  • "string" 可以是系统命令

举例 举例:

1
bindkey -s '^T' 'uptime\n'

zsh on windows

参考:

修复 conda

参考:

方法:

  1. 修改 conda init 方法(.zshrc)

    1
    
    . /d/soft/miniconda3/etc/profile.d/conda.sh
  2. 修改 d:/soft/miniconda3/etc/profile.d/conda.shconda.sh 文件,修复 \r\n\n 导致的问题

      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
    
    export CONDA_EXE='/d/soft/miniconda3/Scripts/conda.exe'
    export _CE_M=''
    export _CE_CONDA=''
    export CONDA_PYTHON_EXE='D:\soft\miniconda3\python.exe'
    
    # Copyright (C) 2012 Anaconda, Inc
    # SPDX-License-Identifier: BSD-3-Clause
    
    
    __add_sys_prefix_to_path() {
        # In dev-mode CONDA_EXE is python.exe and on Windows
        # it is in a different relative location to condabin.
        if [ -n "${_CE_CONDA}" ] && [ -n "${WINDIR+x}" ]; then
            SYSP=$(\dirname "${CONDA_EXE}")
            SYSP=$(echo ${SYSP} | tr -d '\r')
        else
            SYSP=$(\dirname "${CONDA_EXE}")
            SYSP=$(\dirname "${SYSP}")
            SYSP=$(echo ${SYSP} | tr -d '\r')
        fi
    
        if [ -n "${WINDIR+x}" ]; then
            PATH="${SYSP}/bin:${PATH}"
            PATH="${SYSP}/Scripts:${PATH}"
            PATH="${SYSP}/Library/bin:${PATH}"
            PATH="${SYSP}/Library/usr/bin:${PATH}"
            PATH="${SYSP}/Library/mingw-w64/bin:${PATH}"
            PATH="${SYSP}:${PATH}"
            PATH=$(echo ${PATH} | tr -d '\r')
        else
            PATH="${SYSP}/bin:${PATH}"
            PATH=$(echo ${PATH} | tr -d '\r')
        fi
        \export PATH
    }
    
    __conda_exe() (
        __add_sys_prefix_to_path
        $(echo "$CONDA_EXE" | tr -d '\r') $_CE_M $_CE_CONDA $(echo "$@" | tr -d '\r')
    )
    
    __conda_hashr() {
        if [ -n "${ZSH_VERSION:+x}" ]; then
            \rehash
        elif [ -n "${POSH_VERSION:+x}" ]; then
            :  # pass
        else
            \hash -r
        fi
    }
    
    __conda_activate() {
        if [ -n "${CONDA_PS1_BACKUP:+x}" ]; then
            # Handle transition from shell activated with conda <= 4.3 to a subsequent activation
            # after conda updated to >= 4.4. See issue #6173.
            PS1="$CONDA_PS1_BACKUP"
            PS1=$(echo ${PS1} | tr -d '\r')
            \unset CONDA_PS1_BACKUP
        fi
        \local ask_conda
        ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix "$@")" || \return
        ask_conda=$(echo ${ask_conda} | tr -d '\r')
        \eval "$ask_conda"
        __conda_hashr
    }
    
    __conda_reactivate() {
        \local ask_conda
        ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix reactivate)" || \return
        ask_conda=$(echo ${ask_conda} | tr -d '\r')
        \eval "$ask_conda"
        __conda_hashr
    }
    
    conda() {
        \local cmd="${1-__missing__}"
        case "$cmd" in
            activate|deactivate)
                __conda_activate $(echo "$@" | tr -d '\r')
                ;;
            install|update|upgrade|remove|uninstall)
                __conda_exe $(echo "$@" | tr -d '\r') || \return
                __conda_reactivate
                ;;
            ,*)
                __conda_exe $(echo "$@" | tr -d '\r')
                ;;
        esac
    }
    
    if [ -z "${CONDA_SHLVL+x}" ]; then
        \export CONDA_SHLVL=0
        # In dev-mode CONDA_EXE is python.exe and on Windows
        # it is in a different relative location to condabin.
        if [ -n "${_CE_CONDA:+x}" ] && [ -n "${WINDIR+x}" ]; then
            PATH="$(\dirname "$CONDA_EXE")/condabin${PATH:+":${PATH}"}"
        else
            PATH="$(\dirname "$(\dirname "$CONDA_EXE")")/condabin${PATH:+":${PATH}"}"
        fi
        \export PATH
    
        # We're not allowing PS1 to be unbound. It must at least be set.
        # However, we're not exporting it, which can cause problems when starting a second shell
        # via a first shell (i.e. starting zsh from bash).
        if [ -z "${PS1+x}" ]; then
            PS1=
        fi
    fi

word 跳转问题

zsh 通过 WORDCHARS 变量控制,如何分词

控制 forward-word (Alt+F)像 bash 一样跳转:

1
2
3
export WORDCHARS='*?_-.[]~=&;!#$%^(){}<>'
# default, 默认值包括"/",所以会把文件路径当成单个word
# export WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>'
  • 注: 这里删除 / 就可以实现

history 命令添加时间戳

参考:

方法:

history -i # 中国人友好的时间格式

fix compaudit 错误

问题:

  • 当使用 compinit 时会出现 insecure 错误,需要你通过 compaudit 查看修复

修复方法:

  1. 通过 compaudit 查看错误权限文件夹有哪些
  2. 通过 chown 修复所有权
  3. 通过 chmod 755 修复权限
1
2
❯ compaudit |xargs sudo chown $UID:$GID
❯ compaudit |xargs chmod 755