diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 57fa7d4..0d0111f 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -3,12 +3,42 @@ setopt no_beep # 不响铃 setopt correct # 修正命令 setopt interactive_comments # 交互模式支持注释 +# 插件 <<<------------------------------ +source <(antibody init) +antibody bundle <>>----------------------------------- +# zsh-autosuggestions <<<--------------- +# 建议策略: history, completion, match_prev_cmd +ZSH_AUTOSUGGEST_STRATEGY=(history completion) +# 开启异步模式 +ZSH_AUTOSUGGEST_USE_ASYNC=1 +# >>>----------------------------------- +# pkgfile: 命令找不到时提示安装包 +source /usr/share/doc/pkgfile/command-not-found.zsh +# function: 模仿fish折叠路径 +source ${ZDOTDIR}/functions/fish_collapsed_pwd.sh +# >>>----------------------------------- + # 历史记录 <<<-------------------------- HISTSIZE=10000 SAVEHIST=100000 setopt share_history -# 写入时去掉重复和空白 -setopt hist_ignore_dups hist_reduce_blanks +# 去掉重复和空白 +setopt hist_ignore_dups hist_reduce_blanks hist_find_no_dups # >>>----------------------------------- # 命令补全 <<<-------------------------- @@ -24,6 +54,7 @@ zstyle ':completion:*' matcher-list '' 'm:{-a-zA-Z}={_A-Za-z}' # >>>----------------------------------- # 按键绑定 <<<-------------------------- +# 默认Emacs bindkey -e # >>>----------------------------------- @@ -34,8 +65,8 @@ promptinit autoload -Uz colors colors setopt transient_rprompt # 右提示符只出现一次 -PROMPT='%F{magenta}%B$(__git_ps1) %1~>%b%f ' -RPROMPT='[%F{yellow}%?%f]%F{green}%n@%m Lv.%L%f' +PROMPT='%F{163}%B$(__git_ps1) $(_fish_collapsed_pwd)> %b%f' +RPROMPT='[%F{120}%?%f]%F{135}%n@%m%f' # git <<<------------------------------- source /usr/share/git/completion/git-prompt.sh GIT_PS1_SHOWDIRTYSTATE=1 @@ -46,38 +77,27 @@ GIT_PS1_DESCRIBE_STYLE="default" # >>>----------------------------------- # >>>----------------------------------- -# 扩展 <<<------------------------- -source /usr/share/doc/pkgfile/command-not-found.zsh -source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh -# >>>----------------------------------- - # 命令别名 <<<----------------------------- +# sudo后面的命令可以是别名 alias sudo='sudo ' - -alias e='nvim' && compdef e=nvim -alias ec='nvim -S' -alias g='git' && compdef g=git -alias p='python' && compdef p=python -alias mitm='proxychains -f ~/Archway/proxychains-mitm.conf' -alias gfw='proxychains -f ~/Archway/proxychains-gfw.conf' -alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME' && compdef config=git - -alias sl='ls' -alias l='ls -l --color=auto' -alias ll='ls -Al --color=auto' -alias ls='ls --color=auto' +# 设置命令默认行为 +alias ls='ls --color=auto --time-style=iso --human-readable' alias grep='grep --color=auto' alias diff='diff --color=auto' alias mv='mv -i' -alias rmf='rm -rf' && compdef rmf='rm' -alias ds='du -sh' + +alias sl='ls' +alias l='ls -l' +alias la='ls -Al' mcd() { mkdir -p $1 && cd $1 } -# 使用neovim作为pager -alias v='nvim -R -c "nnoremap q :exit"' && compdef v=nvim +alias v='nvim -R -c "nnoremap q :exit"' && compdef v=nvim # 使用neovim作为pager +alias e='nvim' && compdef e=nvim +alias es='nvim -S' && compdef es=nvim +alias g='git' && compdef g=git +alias py='python' && compdef py=python +alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME' && compdef config=git -alias pm='pacman' -alias pmu='sudo pacman -Syu' alias pmq='pacman -Qs' alias pms='pacman -Ss' pmi() { pacman -Qi $1 2>/dev/null || pacman -Sii $1 } diff --git a/.config/zsh/functions/fish_collapsed_pwd.sh b/.config/zsh/functions/fish_collapsed_pwd.sh new file mode 100644 index 0000000..88a7d32 --- /dev/null +++ b/.config/zsh/functions/fish_collapsed_pwd.sh @@ -0,0 +1,42 @@ +# https://zhuanlan.zhihu.com/p/51008087 +function _fish_collapsed_pwd() { + local pwd="$1" + # fix end slash + local home="${HOME%/}" + local size=${#home} + [[ $# == 0 ]] && pwd="$PWD" + # fix end slash + pwd=${pwd%/} + + [[ -z "$pwd" ]] && return + if [[ "$pwd" == "/" ]]; then + echo "/" + return + elif [[ "$pwd" == "$home" ]]; then + echo "~" + return + fi + [[ "$pwd" == "$home/"* ]] && pwd="~${pwd:$size}" + if [[ -n "$BASH_VERSION" ]]; then + local IFS="/" + local elements=($pwd) + local length=${#elements[@]} + for ((i=0;i 1 ]]; then + elements[$i]=${elem[1]} + fi + done + fi + local IFS="/" + echo "${elements[*]}" +}