Skip to content

Commit

Permalink
Add correct check for Wayland in clipboard plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jarun committed Nov 26, 2022
1 parent 07c5590 commit 0c23406
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions plugins/.cbcp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
[ -s "$selection" ] || { echo "plugin .cbcp error: empty selection" >&2 ; exit 1; }

if type xsel >/dev/null 2>&1; then
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
# Wayland
tr '\0' '\n' < "$selection" | wl-copy
elif type xsel >/dev/null 2>&1; then
# Linux
tr '\0' '\n' < "$selection" | xsel -bi
elif type xclip >/dev/null 2>&1; then
Expand All @@ -42,9 +45,6 @@ elif type clip.exe >/dev/null 2>&1; then
elif type clip >/dev/null 2>&1; then
# Cygwin
tr '\0' '\n' < "$selection" | clip
elif type wl-copy >/dev/null 2>&1; then
# Wayland
tr '\0' '\n' < "$selection" | wl-copy
elif type clipboard >/dev/null 2>&1; then
# Haiku
tr '\0' '\n' < "$selection" | clipboard --stdin
Expand Down
8 changes: 4 additions & 4 deletions plugins/x2sel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}

getclip () {
if type xsel >/dev/null 2>&1; then
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
# Wayland
wl-paste
elif type xsel >/dev/null 2>&1; then
# Linux
xsel -bo
elif type xclip >/dev/null 2>&1; then
Expand All @@ -41,9 +44,6 @@ getclip () {
elif [ -r /dev/clipboard ] ; then
# Cygwin
cat /dev/clipboard
elif type wl-paste >/dev/null 2>&1; then
# Wayland
wl-paste
elif type clipboard >/dev/null 2>&1; then
# Haiku
clipboard --print
Expand Down

2 comments on commit 0c23406

@raffaem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still doesn't look right to me.

It should also check for XDG_SESSION_TYPE=="x11". Call xsel or xclip if true, and throws an error if XDG_SESSION_TYPE is neither wayland or x11.

@jarun
Copy link
Owner Author

@jarun jarun commented on 0c23406 Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any session type other than wayland where xsel/xclip will not work?

Please sign in to comment.