zsh: Use zr plugin manager if it exists

By default we use the 'zr' plugin manager for zsh. It is quick and
painless and takes managing the plugins across two environments not our
problem anymore.
This commit is contained in:
Marty Oehme 2025-02-23 21:06:50 +01:00 committed by Marty Oehme
parent 1aa94aa866
commit f04340acbd

View file

@ -1,5 +1,4 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
#
CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}" CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}"
ZSHCONFDIR="$CONFDIR/zsh" ZSHCONFDIR="$CONFDIR/zsh"
@ -17,20 +16,36 @@ zstyle :compinstall filename "$ZSHCONFDIR/.zshrc"
compinit compinit
# End of lines added by compinstall # End of lines added by compinstall
# load plugins # load plugins with the zr plugin manager
[ -e /usr/share/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh ] && source /usr/share/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh AUTO_NOTIFY_THRESHOLD=60
[ -e /usr/share/oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh ] && source /usr/share/oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh TIPZ_TEXT='ALIAS:'
[ -e /usr/share/fzf/key-bindings.zsh ] && source /usr/share/fzf/key-bindings.zsh if command -v zr >/dev/null 2>&1; then
#source /usr/share/nvm/init-nvm.sh . <(
## find the correct installed tab-completion version zr \
PLUG_FOLDER="/usr/share/zsh/plugins" molovo/tipz \
[ -e $PLUG_FOLDER/fzf-tab/fzf-tab.plugin.zsh ] && source $PLUG_FOLDER/fzf-tab/fzf-tab.plugin.zsh ael-code/zsh-colored-man-pages \
[ -e $PLUG_FOLDER/fzf-tab-bin-git/fzf-tab.plugin.zsh ] && source $PLUG_FOLDER/fzf-tab-bin-git/fzf-tab.plugin.zsh MichaelAquilina/zsh-auto-notify \
# these need to be sourced after fzf-tab junegunn/fzf.git/shell/key-bindings.zsh \
[ -e $PLUG_FOLDER/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh ] && source $PLUG_FOLDER/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh Aloxaf/fzf-tab \
[ -e $PLUG_FOLDER/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ] && source $PLUG_FOLDER/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh zdharma-continuum/fast-syntax-highlighting \
[ -e $PLUG_FOLDER/alias-tips/alias-tips.plugin.zsh ] && source $PLUG_FOLDER/alias-tips/alias-tips.plugin.zsh zsh-users/zsh-autosuggestions \
[ -e $PLUG_FOLDER/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh ] && source $PLUG_FOLDER/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh zsh-users/zsh-completions \
)
else # or manually
[ -e /usr/share/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh ] && source /usr/share/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh
[ -e /usr/share/oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh ] && source /usr/share/oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh
[ -e /usr/share/fzf/key-bindings.zsh ] && source /usr/share/fzf/key-bindings.zsh
## find the correct installed tab-completion version
PLUG_FOLDER="/usr/share/zsh/plugins"
[ -e $PLUG_FOLDER/fzf-tab/fzf-tab.plugin.zsh ] && source $PLUG_FOLDER/fzf-tab/fzf-tab.plugin.zsh
[ -e $PLUG_FOLDER/fzf-tab-bin-git/fzf-tab.plugin.zsh ] && source $PLUG_FOLDER/fzf-tab-bin-git/fzf-tab.plugin.zsh
# these need to be sourced after fzf-tab
[ -e $PLUG_FOLDER/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh ] && source $PLUG_FOLDER/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
[ -e $PLUG_FOLDER/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ] && source $PLUG_FOLDER/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
[ -e $PLUG_FOLDER/alias-tips/alias-tips.plugin.zsh ] && source $PLUG_FOLDER/alias-tips/alias-tips.plugin.zsh
[ -e $PLUG_FOLDER/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh ] && source $PLUG_FOLDER/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh
fi
unset PLUG_FOLDER unset PLUG_FOLDER
# simple fzf-tab settings # simple fzf-tab settings
@ -39,7 +54,18 @@ zstyle ":fzf-tab:*" fzf-flags "--ansi" "--expect='$continuous_trigger,$print_que
zstyle ':fzf-tab:*' fzf-command fzf zstyle ':fzf-tab:*' fzf-command fzf
# format colorful groups for different completion actions # format colorful groups for different completion actions
zstyle ':completion:*:descriptions' format '[%d]' zstyle ':completion:*:descriptions' format '[%d]'
zstyle ':fzf-tab:*' show-group brief # set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# force zsh not to show completion menu, which allows fzf-tab to capture the unambiguous prefix
zstyle ':completion:*' menu no
# fzf-tab does not follow FZF_DEFAULT_OPTS by default since some setups can break completion
zstyle ':fzf-tab:*' fzf-flags --color=fg:1,fg+:2
zstyle ':fzf-tab:*' fzf-bindings 'ctrl-j:accept' 'ctrl-a:toggle-all' 'ctrl-d:preview-down' 'ctrl-u:preview-up'
zstyle ':fzf-tab:*' continuous-trigger '/'
zstyle ':fzf-tab:*' switch-group '<' '>'
# use input as query string when completing zlua # use input as query string when completing zlua
zstyle ':fzf-tab:complete:_zlua:*' query-string input zstyle ':fzf-tab:complete:_zlua:*' query-string input
# (experimental, may change in the future) # (experimental, may change in the future)
@ -55,10 +81,17 @@ local realpath=\${ctxt[IPREFIX]}\${ctxt[hpre]}\$in
realpath=\${(Qe)~realpath} realpath=\${(Qe)~realpath}
" "
# give a preview of commandline arguments when completing `kill` # give a preview of commandline arguments when completing `kill`
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm,cmd -w -w" zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
zstyle ':fzf-tab:complete:kill:argument-rest' extra-opts --preview=$extract'ps --pid=$in[(w)1] -o cmd --no-headers -w -w' --preview-window=down:3:wrap zstyle ':fzf-tab:complete:(kill|ps):argument-rest' fzf-preview \
# give a preview of directory by exa when completing cd '[[ $group == "[process ID]" ]] && ps --pid=$word -o cmd --no-headers -w -w'
zstyle ':fzf-tab:complete:cd:*' extra-opts --preview=$extract'exa -1 --color=always $realpath' zstyle ':fzf-tab:complete:(kill|ps):argument-rest' fzf-flags --preview-window=down:3:wrap
# preview directory's content with eza when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
# show systemd unit status
zstyle ':fzf-tab:complete:systemctl-*:*' fzf-preview 'SYSTEMD_COLORS=1 systemctl status $word'
# env var contents
zstyle ':fzf-tab:complete:(-command-|-parameter-|-brace-parameter-|export|unset|expand):*' \
fzf-preview 'echo ${(P)word}'
# show hostname if we are in a distrobox environment # show hostname if we are in a distrobox environment
if [ -n "$DISTROBOX_ENTER_PATH" ] && [ -f /run/.containerenv ]; then if [ -n "$DISTROBOX_ENTER_PATH" ] && [ -f /run/.containerenv ]; then
@ -154,21 +187,21 @@ bindkey -v
export KEYTIMEOUT=1 export KEYTIMEOUT=1
# Change cursor shape for different vi modes. # Change cursor shape for different vi modes.
function zle-keymap-select { function zle-keymap-select {
if [[ ${KEYMAP} == vicmd ]] || if [[ ${KEYMAP} == vicmd ]] ||
[[ $1 = 'block' ]]; then [[ $1 = 'block' ]]; then
echo -ne '\e[2 q' echo -ne '\e[2 q'
elif [[ ${KEYMAP} == main ]] || elif [[ ${KEYMAP} == main ]] ||
[[ ${KEYMAP} == viins ]] || [[ ${KEYMAP} == viins ]] ||
[[ ${KEYMAP} = '' ]] || [[ ${KEYMAP} = '' ]] ||
[[ $1 = 'beam' ]]; then [[ $1 = 'beam' ]]; then
echo -ne '\e[6 q' echo -ne '\e[6 q'
fi fi
} }
zle -N zle-keymap-select zle -N zle-keymap-select
# Use beam shape cursor on startup. # Use beam shape cursor on startup.
_fix_cursor() { _fix_cursor() {
echo -ne '\e[6 q' echo -ne '\e[6 q'
} }
precmd_functions+=(_fix_cursor) precmd_functions+=(_fix_cursor)