From 62752d385ab661a09c06b369f588f17622fa2719 Mon Sep 17 00:00:00 2001 From: Yax <1949284+kianby@users.noreply.github.com> Date: Thu, 20 May 2021 09:07:39 +0200 Subject: [PATCH] add fstash --- dot_bashrc.d/git.bashrc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 dot_bashrc.d/git.bashrc diff --git a/dot_bashrc.d/git.bashrc b/dot_bashrc.d/git.bashrc new file mode 100644 index 0000000..dfcf578 --- /dev/null +++ b/dot_bashrc.d/git.bashrc @@ -0,0 +1,28 @@ +# fstash - easier way to deal with stashes +# type fstash to get a list of your stashes +# enter shows you the contents of the stash +# ctrl-d shows a diff of the stash against your current HEAD +# ctrl-b checks the stash out as a branch, for easier merging +fstash() { + local out q k sha + while out=$( + git stash list --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs" | + fzf --ansi --no-sort --query="$q" --print-query \ + --expect=ctrl-d,ctrl-b); + do + mapfile -t out <<< "$out" + q="${out[0]}" + k="${out[1]}" + sha="${out[-1]}" + sha="${sha%% *}" + [[ -z "$sha" ]] && continue + if [[ "$k" == 'ctrl-d' ]]; then + git diff $sha + elif [[ "$k" == 'ctrl-b' ]]; then + git stash branch "stash-$sha" $sha + break; + else + git stash show -p $sha + fi + done +}