From c95679e6cfa6fec3de2ab14bfa9f5830cb7ada4f Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Mon, 8 Aug 2022 22:37:19 -0400 Subject: [PATCH] ENH ensure xclip is installed for clipping function --- .../executable_bootstrap_runtime_pkgs.tmpl | 2 +- dot_config/zsh/dot_zshrc.tmpl | 72 ++++++++++--------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/dot_bin/executable_bootstrap_runtime_pkgs.tmpl b/dot_bin/executable_bootstrap_runtime_pkgs.tmpl index 9b832fc..1c2693a 100644 --- a/dot_bin/executable_bootstrap_runtime_pkgs.tmpl +++ b/dot_bin/executable_bootstrap_runtime_pkgs.tmpl @@ -34,7 +34,7 @@ pkgs+=(seafile-client) pkgs+=(rxvt-unicode urxvt-perls) # shell -pkgs+=(zsh zsh-completions) +pkgs+=(zsh zsh-completions xclip) # xmonad mapfile -t xmonad < <("$conf_dir/xmonad/scripts/runtime_pkgs") diff --git a/dot_config/zsh/dot_zshrc.tmpl b/dot_config/zsh/dot_zshrc.tmpl index dfc6d37..67da7a8 100644 --- a/dot_config/zsh/dot_zshrc.tmpl +++ b/dot_config/zsh/dot_zshrc.tmpl @@ -355,41 +355,43 @@ man() { ## -------------------------------------------------- # enable x11 clipboard sync ## -------------------------------------------------- -function x11-clip-wrap-widgets() { - # NB: Assume we are the first wrapper and that we only wrap native widgets - # See zsh-autosuggestions.zsh for a more generic and more robust wrapper - local copy_or_paste=$1 - shift - - for widget in $@; do - if [[ $copy_or_paste == "copy" ]]; then - eval " - function _x11-clip-wrapped-$widget() { - zle .$widget - xclip -in -selection clipboard <<<\$CUTBUFFER - } - " - else - eval " - function _x11-clip-wrapped-$widget() { - CUTBUFFER=\$(xclip -out -selection clipboard) - zle .$widget - } - " - fi - - zle -N $widget _x11-clip-wrapped-$widget - done -} - -local copy_widgets=( - vi-yank vi-yank-eol vi-delete vi-backward-kill-word vi-change-whole-line -) -local paste_widgets=( - vi-put-{before,after} -) -x11-clip-wrap-widgets copy $copy_widgets -x11-clip-wrap-widgets paste $paste_widgets +if exists xclip; then + function x11-clip-wrap-widgets() { + # NB: Assume we are the first wrapper and that we only wrap native widgets + # See zsh-autosuggestions.zsh for a more generic and more robust wrapper + local copy_or_paste=$1 + shift + + for widget in $@; do + if [[ $copy_or_paste == "copy" ]]; then + eval " + function _x11-clip-wrapped-$widget() { + zle .$widget + xclip -in -selection clipboard <<<\$CUTBUFFER + } + " + else + eval " + function _x11-clip-wrapped-$widget() { + CUTBUFFER=\$(xclip -out -selection clipboard) + zle .$widget + } + " + fi + + zle -N $widget _x11-clip-wrapped-$widget + done + } + + local copy_widgets=( + vi-yank vi-yank-eol vi-delete vi-backward-kill-word vi-change-whole-line + ) + local paste_widgets=( + vi-put-{before,after} + ) + x11-clip-wrap-widgets copy $copy_widgets + x11-clip-wrap-widgets paste $paste_widgets +fi {{- end }}