Last active
December 13, 2025 18:32
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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