From f9c961bf4f36d580a9b444ff14411789e59bab0a Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Thu, 30 Apr 2026 15:21:55 +0200 Subject: [PATCH] fgit --- .../home/profiles/minimal/bashrc.d/fgit.sh | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 users/pbsds/home/profiles/minimal/bashrc.d/fgit.sh diff --git a/users/pbsds/home/profiles/minimal/bashrc.d/fgit.sh b/users/pbsds/home/profiles/minimal/bashrc.d/fgit.sh new file mode 100644 index 0000000..f09d8f7 --- /dev/null +++ b/users/pbsds/home/profiles/minimal/bashrc.d/fgit.sh @@ -0,0 +1,50 @@ +# inspired by https://oppi.li/posts/jjj/ +# using what i made for +# - https://git.pvv.ntnu.no/pederbs/just-nixpkgs +# - https://git.pvv.ntnu.no/pederbs/config/src/commit/5a2927372b180d7bfcf67f93151f3756bc4f26df/users/pbsds/home/profiles/headless/fzf.nix + +# TODO: use gum/fzf to make a menu with various modes +# * [ ] mode with git log --oneline --all +# * [ ] mode with branches/tags +# * [ ] mode with commit from a specific branch/tag +# * [ ] mode with commit ranges (aaa..bbb) +# * [ ] mode with multiple commits in single command +# * [ ] mode with multiple commits across multiple command like https://arch1t3cht.org/blog/jjjj/ + +if command -v git >/dev/null \ +&& command -v fzf >/dev/null \ +&& command -v cut >/dev/null \ +&& command -v head >/dev/null +then + +fgit() { + local -a git_color=() + if [[ -t 2 ]]; then + git_color+=( --color=always ) + fi + + local -a fzf_args=( + --height=15 + # --multi + + --reverse + --bind 'home:first' + --bind 'end:last' + --cycle + --ansi + --prompt "git $* " + --preview 'git show "$(cut -d" " -f1 <<< {} )" '"${git_color[*]}"' --stat | head -n$FZF_PREVIEW_LINES' + --preview-window follow + ) + + local commit_id="$( git log --oneline "${git_color[@]}" | fzf "${fzf_args[@]}" | cut -d" " -f1 )" + + if [[ -n "$commit_id" ]]; then + # recreate 'set -x' to avoid a subshell + >&2 echo "+$(printf " %q" git "$@" "$commit_id")" + + git "$@" "$commit_id" + fi +} + +fi