3 ms·
This is a great idea, thanks for it! I've done similar things with using fzf to git add, git diff, and so on, but I hadn't thought of using it to pick a commit
by kbd 7y ago
This is a great idea, thanks for it! I've done similar things with using fzf to git add, git diff, and so on, but I hadn't thought of using it to pick a commit to rebase from.
I made a few changes so I figured I'd post them back here in case you're interested:
pick-commit = # equivalent to your git log... cut...
rif = "!f() { rev=$(git pick-commit); [[ $rev ]] && git ri $rev~; }; f"
"rif" = "rebase interactive fzf/fuzzyfind". The function and test just makes it exit cleanly if you escape out of the filter instead of giving "fatal: invalid upstream '~'" (and I changed it from ^ to ~ because I think ~ is usually what one should use over ^, but I'm willing to be corrected). And obviously I already have 'ri' aliased to 'rebase -i'.
While I'm here, here are my similar git aliases for adding, diffing, etc. files using fzf:
pick-status-files = "!f() { git status -z | xargs -0n1 | cut -c4- | fzi --print0 | xargs -0to git "$@"; }; f"
af = !git pick-status-files add
# and so on for diff, difftool, checkout, etc.
Oh, and 'fzi' (fuzzy-inline) is a small shell script that just calls:
fzf --height 30% --reverse --multi "$@"
- graton 7y agoThanks for that. I like your improvements to my idea too! :)
- kbd 7y agoYay. Btw, one more improvement. TIL xargs will skip blank inputs (depending on bsd/gnu xargs, flags etc...), so my version above: rif = "!f() { rev=$(git pick-commit); [[ $rev ]] && git ri $rev~; }; f" can just be: rif = !git pick-commit | xargs -tI% git ri %~
- girishso 7y agoThat looks great. Do you have your dotfiles shared by any chance?
- kbd 7y agoSure: https://github.com/kbd/setup https://github.com/kbd/setup Here's my git config with a bajillion aliases: https://github.com/kbd/setup/blob/master/HOME/.config/git/config https://github.com/kbd/setup/blob/master/HOME/.config/git/co... Since git commands are one of the most common things to type, I alias all short git aliases like so: https://github.com/kbd/setup/blob/fd1f826a9365895b7a3b8b5c585e5154863d87cd/HOME/bin/shell_sources/aliases.sh#L126 https://github.com/kbd/setup/blob/fd1f826a9365895b7a3b8b5c58... (link to particular commit so line numbers stay correct). That way my workflow looks like: $ ga (fuzzy find files to add) $ gcm "commit message" etc.
- kbd 7y agoCan't edit this anymore. pick-status-files = "!f() { git status -z | xargs -0n1 | cut -c4- | fzi --print0 | xargs -0to git "$@"; }; f" can just be: pick-status-files = !git status -z | xargs -0n1 | cut -c4- | fzi --print0 | xargs -0t git I'd recently converted it from a standalone script so I just converted it verbatim into a function.