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"
 }