From f743c8025b58c10e1e4309a9cbe959e166ff9ddd Mon Sep 17 00:00:00 2001
From: Ben Elan <no-reply@benelan.dev>
Date: Sat, 6 Jul 2024 20:17:18 -0700
Subject: [PATCH] fix(linux): check XDG_SESSION_TYPE when determining copy
 command

Resolve an issue with the GH_FZF_COPY_CMD config option's default value
on linux machines where both Wayland and X11 are installed.
---
 gh-fzf | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gh-fzf b/gh-fzf
index 86d5837..0195e67 100755
--- a/gh-fzf
+++ b/gh-fzf
@@ -87,12 +87,12 @@ GH_FZF_DEFAULT_LIMIT="${GH_FZF_DEFAULT_LIMIT:-75}"
 if [ -z "$GH_FZF_COPY_CMD" ]; then
     if has /mnt/c/Windows/System32/clip.exe; then
         GH_FZF_COPY_CMD="/mnt/c/Windows/System32/clip.exe" # Windows (WSL)
+    elif has wl-copy && [ "$XDG_SESSION_TYPE" = "wayland" ]; then
+        GH_FZF_COPY_CMD="wl-copy" # Linux (Wayland)
     elif has xsel; then
         GH_FZF_COPY_CMD="xsel -bi" # Linux (X11)
     elif has xclip; then
         GH_FZF_COPY_CMD="xclip -selection clipboard" # Linux (X11)
-    elif has wl-copy; then
-        GH_FZF_COPY_CMD="wl-copy" # Linux (Wayland)
     elif has pbcopy; then
         GH_FZF_COPY_CMD="pbcopy" # OSX
     fi