37 lines
901 B
Bash
Executable file
37 lines
901 B
Bash
Executable file
#!/bin/zsh
|
|
|
|
histdb="$1"
|
|
shift
|
|
|
|
copy_cmd=
|
|
case "$XDG_SESSION_TYPE" in
|
|
x11) copy_cmd="xsel --clipboard" ;;
|
|
wayland) copy_cmd="wl-copy --trim-newline" ;;
|
|
*) echo "Session type not detected."; return ;;
|
|
esac
|
|
|
|
if [[ -d "$histdb" ]]; then
|
|
pushd -q "$histdb"
|
|
|
|
RG_PREFIX="rg --no-filename --no-line-number --no-heading --color=always --smart-case "
|
|
INITIAL_QUERY="${*:-}"
|
|
|
|
entry="$(
|
|
fzf --ansi --disabled --query "$INITIAL_QUERY" \
|
|
--bind "start:reload:$RG_PREFIX {q}" \
|
|
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
|
|
--delimiter :
|
|
)"
|
|
|
|
entry_cmd="$(<<<$entry awk -F' ' '{ print substr($0, index($0, $4)) }')"
|
|
|
|
if [[ "$entry" ]]; then
|
|
eval $copy_cmd <<< "$entry_cmd" >/dev/null
|
|
echo "Copied to clipboard." >&2
|
|
fi
|
|
|
|
popd -q
|
|
else
|
|
echo "\$histdb does not exist at: \"$histdb\" "
|
|
fi
|