From 8459e9163a9ba62eec20f696b69f2c0c5c676af3 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 2 Sep 2022 21:06:30 +0530 Subject: fresh worktree functions --- programs/bash.nix | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'programs/bash.nix') diff --git a/programs/bash.nix b/programs/bash.nix index 9ad3217..2a3cb97 100644 --- a/programs/bash.nix +++ b/programs/bash.nix @@ -23,7 +23,6 @@ rless = "less -r"; tmux = "tmux -u"; tree = "tree -C"; - vim = "nvim"; tb = "nc termbin.com 9999"; n = "j"; @@ -35,6 +34,7 @@ gl = "git log -p --abbrev-commit --pretty=medium"; glo = "git log --pretty=oneline --abbrev-commit"; gst = "git status --short"; + gwls = "git worktree list"; }; shellOptions = [ @@ -78,6 +78,45 @@ export PS1="\n\001\e[0;36m\002λ\001\e[0m\002 "; export PS2="> "; + # git functions + + function fuzzy_worktree () { + # 1: function that operates on the fzf result + # 2: an optional query + query="''${2:- }" + out=$( + set -o pipefail && \ + git worktree list | \ + fzf --min-height=15 \ + --preview-window=up,10 \ + --preview='git log --color=always -n10 --oneline {2}' \ + --cycle -1 \ + -q "$query" | \ + awk '{print $1}' + ) + [ $? -eq 0 ] && echo "$out" && $1 $out + } + + function gwj () { + fuzzy_worktree __cd $@ + } + + function gwa () { + git worktree add "$1" && cd "$1" + } + + function gwrm () { + fuzzy_worktree __rm $@ + } + + function __cd() { + cd "$1" + } + + function __rm() { + git worktree remove "$1" + } + ''; }; -- cgit v1.2.3