From 1e620361e1717d9eae4964d7bbcc58b537585d80 Mon Sep 17 00:00:00 2001
From: Rudis Muiznieks <rudis@sitosis.com>
Date: Thu, 20 Mar 2025 10:02:57 -0500
Subject: [PATCH] made wl-copy dependency optional in fzy script

---
 yash/fzy-hist.sh | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/yash/fzy-hist.sh b/yash/fzy-hist.sh
index c5debe0..04fea4c 100644
--- a/yash/fzy-hist.sh
+++ b/yash/fzy-hist.sh
@@ -1,9 +1,15 @@
 h() {
   input="$*"
   SED_ARG='s/^[[:digit:]]*[[:space:]]*//'
+
+  cmd="history | sed '\$d' | sort --reverse --numeric-sort | fzy "
   if [ -n "$input" ]; then
-    history | sed '$d' | sort --reverse --numeric-sort | fzy -q"$input" | sed "$SED_ARG" | tr -d '\n' | wl-copy 2>/dev/null
-  else
-    history | sed '$d' | sort --reverse --numeric-sort | fzy | sed "$SED_ARG" | tr -d '\n' | wl-copy 2>/dev/null
+    cmd="$cmd -q\"\$input\" "
   fi
+  cmd="$cmd | sed \"\$SED_ARG\" | tr -d '\n'"
+  if command -v wl-copy>/dev/null; then
+    cmd="$cmd | wl-copy 2>/dev/null"
+  fi
+
+  eval "$cmd"
 }