From 8e33d2f5f7a702ae113a54ac1ed1aa379c1e146c Mon Sep 17 00:00:00 2001 From: rydesun Date: Thu, 4 Feb 2021 20:52:21 +0800 Subject: [PATCH] Update zsh config --- .config/zsh/.gitignore | 2 +- .config/zsh/.zshrc | 28 +++++++++++++------ .config/zsh/functions/_pm | 6 ++++ ...h_collapsed_pwd.zsh => fish_collapsed_pwd} | 6 ++-- .config/zsh/hostrc.d/funcs.zsh | 8 ++++++ 5 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 .config/zsh/functions/_pm rename .config/zsh/functions/{fish_collapsed_pwd.zsh => fish_collapsed_pwd} (95%) create mode 100644 .config/zsh/hostrc.d/funcs.zsh diff --git a/.config/zsh/.gitignore b/.config/zsh/.gitignore index 2fb1066..8535af7 100644 --- a/.config/zsh/.gitignore +++ b/.config/zsh/.gitignore @@ -1 +1 @@ -/hostrc.d/ +/hostrc.d/colors.zsh diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 1f0f735..e5f0fd9 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -1,8 +1,10 @@ -# zle基础配置 +# 基础配置 setopt no_beep # 不响铃 setopt correct # 修正命令 setopt interactive_comments # 交互模式支持注释 +fpath=(${ZDOTDIR}/functions $fpath) + # 插件 <<<------------------------------ command -v antibody &>/dev/null && source <(antibody init) && \ antibody bundle <>>----------------------------------- # 历史记录 <<<-------------------------- @@ -52,6 +52,9 @@ if [[ ! -d ${XDG_CACHE_HOME}/zsh/ ]]; then mkdir -p ${XDG_CACHE_HOME}/zsh/ fi compinit -d ${XDG_CACHE_HOME}/zsh/zcompdump-${ZSH_VERSION} + +# 补全失败时的提示 +zstyle ':completion:*:warnings' format $'\e[31m -- No Matches Found --\e[0m' setopt complete_aliases # 补全别名 setopt list_packed # 补全列表压缩列宽 zstyle :compinstall filename ${XDG_CONFIG_HOME}/zsh/.zshrc @@ -66,6 +69,8 @@ export FZF_COMPLETION_TRIGGER='~~' export FZF_DEFAULT_COMMAND='fd -uu -E .git -E .node_modules' export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" +compdef proxychains=command + # 当前环境的配置 _ZSH_HOSTRC_COMMAND=${XDG_CONFIG_HOME}/zsh/hostrc.d/funcs.zsh if [[ -e $_ZSH_HOSTRC_COMMAND ]]; then @@ -76,6 +81,10 @@ fi # 按键绑定 <<<-------------------------- # 默认Emacs bindkey -e +# 用$EDITOR编辑命令 +autoload -Uz edit-command-line +zle -N edit-command-line +bindkey '^X^E' edit-command-line # fzf if [[ -f /usr/share/fzf/key-bindings.zsh ]]; then source /usr/share/fzf/key-bindings.zsh @@ -118,8 +127,8 @@ precmd() { PROMPT_err="" fi - if command -v _fish_collapsed_pwd &>/dev/null; then - _collapsed_pwd=$(_fish_collapsed_pwd) + if command -v fish_collapsed_pwd &>/dev/null; then + _collapsed_pwd=$(fish_collapsed_pwd) fi PROMPT_host="${_color_host}${_color_invert} %n@%m ${_color_reset}" # ssh标志 @@ -191,8 +200,11 @@ mcd() { mkdir -p $1 && cd $1 } alias x='xdg-open' 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 +if [[ -e $VIMRUNTIME ]]; then + alias e='nvr' +else + alias e='nvim' && compdef e=nvim +fi 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 diff --git a/.config/zsh/functions/_pm b/.config/zsh/functions/_pm new file mode 100644 index 0000000..46d7f27 --- /dev/null +++ b/.config/zsh/functions/_pm @@ -0,0 +1,6 @@ +#compdef pactree pmq pms pmi pml pmb pmd + +source /usr/share/zsh/site-functions/_pacman + +compdef _pacman_completions_installed_packages pactree pmq +compdef _pacman_completions_all_packages pms pmi pml pmb pmd diff --git a/.config/zsh/functions/fish_collapsed_pwd.zsh b/.config/zsh/functions/fish_collapsed_pwd similarity index 95% rename from .config/zsh/functions/fish_collapsed_pwd.zsh rename to .config/zsh/functions/fish_collapsed_pwd index 411cec4..8b38cff 100644 --- a/.config/zsh/functions/fish_collapsed_pwd.zsh +++ b/.config/zsh/functions/fish_collapsed_pwd @@ -1,7 +1,5 @@ -#! /usr/bin/env zsh - # https://zhuanlan.zhihu.com/p/51008087 -function _fish_collapsed_pwd() { +() { local pwd="$1" # fix end slash local home="${HOME%/}" @@ -42,3 +40,5 @@ function _fish_collapsed_pwd() { local IFS="/" echo "${elements[*]}" } + +# vim:set filetype=zsh: diff --git a/.config/zsh/hostrc.d/funcs.zsh b/.config/zsh/hostrc.d/funcs.zsh new file mode 100644 index 0000000..b44d8f8 --- /dev/null +++ b/.config/zsh/hostrc.d/funcs.zsh @@ -0,0 +1,8 @@ +# Arch Linux +alias pmq='pacman -Qs' +alias pms='pacman -Ss' +pmi() { pacman -Qi $1 2>/dev/null || pacman -Sii $1 } +pmo() { pacman -Qoq $1 2>/dev/null || pkgfile -i $1 } +pml() { (pacman -Qlq $1 2>/dev/null || pkgfile -lq $1) | sed '/\/$/d' } +pmb() { (pacman -Qlq $1 2>/dev/null || pkgfile -lq $1) | awk -F/ '/\/usr\/bin\/.+[^/]$/{print $NF}' } +pmd() { (pacman -Qlq $1 2>/dev/null || pkgfile -lq $1) | grep -e '\.service$' -e '\.socket$' }