Skip to content

Instantly share code, notes, and snippets.

@dblume
Last active December 13, 2025 18:32
Show Gist options
  • Select an option

  • Save dblume/274ef77aa9541a619e9fd8839698c607 to your computer and use it in GitHub Desktop.

Select an option

Save dblume/274ef77aa9541a619e9fd8839698c607 to your computer and use it in GitHub Desktop.
Bash functions that execute commands on your behalf should append them to the history (see line 11)
gf() {
local file
if type batcat >/dev/null 2>&1; then
file="$(git ls-files | fzf --preview 'batcat --color=always --wrap never --terminal-width $COLUMNS {}' --preview-window=right:60%)"
else
file="$(git ls-files | fzf --preview 'cat {}' --preview-window=right:60%)"
fi
if [ -n "$file" ]; then
echo ${EDITOR:-vim} "$file"
# vvvvvvvv It's more useful to have "vim [file]" in your history than just a "gf".
history -s "${EDITOR:-vim} \"$file\""
${EDITOR:-vim} "$file"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment