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 ++++++++++++++++++++++++++++++++++++++++- programs/tmux.nix | 5 +---- 2 files changed, 41 insertions(+), 5 deletions(-) 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" + } + ''; }; diff --git a/programs/tmux.nix b/programs/tmux.nix index 8679222..e5c5aa1 100644 --- a/programs/tmux.nix +++ b/programs/tmux.nix @@ -26,6 +26,7 @@ setw -g pane-base-index 1 # pane binds + unbind-key E bind-key h select-pane -L bind-key n select-pane -D bind-key e select-pane -U @@ -58,10 +59,6 @@ bind-key -T copy-mode-vi r send-keys -X rectangle-toggle bind P paste-buffer - bind E command-prompt -p "Command:" \ - "run \"tmux list-panes -a -F '##{session_name}:##{window_index}.##{pane_index}' \ - | xargs -I PANE tmux send-keys -t PANE '%1' Enter\"" - set-window-option -g allow-rename off set -g pane-border-style fg=colour11 -- cgit v1.2.3