Skip to content

Instantly share code, notes, and snippets.

View ganeshkumar269's full-sized avatar

గణేష్ ganeshkumar269

View GitHub Profile
@ganeshkumar269
ganeshkumar269 / gist:d20b912e34f860ed0f6a88075640d4b0
Last active March 4, 2025 18:55
Better CLI history navigation
fzf_history() {
local selected
setopt localoptions pipefail no_aliases 2> /dev/null
selected=$(fc -l -n -t "%s" 1 | awk '{cmd=$0; sub(/^[0-9]+ /, "", cmd); print $1 "|" cmd}' | awk -F '|' '!seen[$2]++ {print $0}' | cut -d '|' -f2- | \
fzf --tac --tiebreak=index --height 50% --layout=reverse --preview 'echo {}' --preview-window=up:3:wrap \
--bind 'ctrl-y:execute-silent(echo -n {+} | pbcopy)' \
--header 'Press CTRL-Y to copy command into clipboard')
if [[ -n "$selected" ]]; then
BUFFER=${selected}