Skip to content

Commit b071e17

Browse files
Add support for wl-copy/Wayland
1 parent 348db3e commit b071e17

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

share/cht.sh.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,11 @@ else
514514
fi
515515

516516
if [ "$is_macos" != yes ]; then
517-
command -v xsel >/dev/null || echo 'DEPENDENCY: please install "xsel" for "copy"' >&2
517+
if [ "$XDG_SESSION_TYPE" = wayland ]; then
518+
command -v wl-copy >/dev/null || echo 'DEPENDENCY: please install "wl-copy" for "copy"' >&2
519+
else
520+
command -v xsel >/dev/null || echo 'DEPENDENCY: please install "xsel" for "copy"' >&2
521+
fi
518522
fi
519523
command -v rlwrap >/dev/null || { echo 'DEPENDENCY: install "rlwrap" to use cht.sh in the shell mode' >&2; exit 1; }
520524

@@ -562,7 +566,11 @@ cmd_copy() {
562566
else
563567
curl -s "${CHTSH_URL}"/"$(get_query_options "$query"?T)" > "$TMP1"
564568
if [ "$is_macos" != yes ]; then
565-
xsel -bi < "$TMP1"
569+
if [ "$XDG_SESSION_TYPE" = wayland ]; then
570+
wl-copy < "$TMP1"
571+
else
572+
xsel -bi < "$TMP1"
573+
fi
566574
else
567575
pbcopy < "$TMP1"
568576
fi
@@ -578,7 +586,11 @@ cmd_ccopy() {
578586
else
579587
curl -s "${CHTSH_URL}"/"$(get_query_options "$query"?TQ)" > "$TMP1"
580588
if [ "$is_macos" != yes ]; then
581-
xsel -bi < "$TMP1"
589+
if [ "$XDG_SESSION_TYPE" = wayland ]; then
590+
wl-copy < "$TMP1"
591+
else
592+
xsel -bi < "$TMP1"
593+
fi
582594
else
583595
pbcopy < "$TMP1"
584596
fi

0 commit comments

Comments
 (0)