Make ZSHRC portable between Xorg and Wayland

This commit is contained in:
Out Of Ideas 2024-05-05 15:33:31 -05:00
parent 3122a00f15
commit 11dbd0dc6d
1 changed files with 23 additions and 4 deletions

View File

@ -350,7 +350,11 @@ zle -N widget::copy-selection
function widget::copy-selection {
if ((REGION_ACTIVE)); then
zle copy-region-as-kill
printf "%s" $CUTBUFFER | wl-copy
if test "$XDG_SESSION_TYPE" = "x11"; then
printf "%s" $CUTBUFFER | xclip
elif test "$XDG_SESSION_TYPE" = "wayland"; then
printf "%s" $CUTBUFFER | wl-copy
fi
fi
}
@ -359,7 +363,11 @@ zle -N widget::cut-selection
function widget::cut-selection() {
if ((REGION_ACTIVE)) then
zle kill-region
printf "%s" $CUTBUFFER | wl-copy
if test "$XDG_SESSION_TYPE" = "x11"; then
printf "%s" $CUTBUFFER | xclip
elif test "$XDG_SESSION_TYPE" = "wayland"; then
printf "%s" $CUTBUFFER | wl-copy
fi
fi
}
@ -367,8 +375,14 @@ function widget::cut-selection() {
zle -N widget::paste
function widget::paste() {
((REGION_ACTIVE)) && zle kill-region
RBUFFER="$(pbpaste)${RBUFFER}"
CURSOR=$(( CURSOR + $(echo -n "$(pbpaste)" | wc -m | bc) ))
# change to use xclip/wl-copy
if test "$XDG_SESSION_TYPE" = "x11"; then
RBUFFER="$(xclip -o -selection clipboard)${RBUFFER}"
CURSOR=$(( CURSOR + $(echo -n "$(xclip -o -selection clipboard)" | wc -m | bc) ))
elif test "$XDG_SESSION_TYPE" = "wayland"; then
RBUFFER="$(wl-paste)${RBUFFER}"
CURSOR=$(( CURSOR + $(echo -n "$(wl-paste)" | wc -m | bc) ))
fi
}
# select entire prompt
@ -396,6 +410,11 @@ function widget::util-select() {
zle $widget_name -- $@
zle copy-region-as-kill
printf "%s" $CUTBUFFER | wl-copy --primary
if test "$XDG_SESSION_TYPE" = "x11"; then
printf "%s" $CUTBUFFER | xclip -selection --primary
elif test "$XDG_SESSION_TYPE" = "wayland"; then
printf "%s" $CUTBUFFER | wl-copy --primary
fi
}
function widget::util-unselect() {