Skip to content

Instantly share code, notes, and snippets.

@towry
Created December 8, 2023 06:18
Show Gist options
  • Save towry/ed812031a117e8e155350775aadb914c to your computer and use it in GitHub Desktop.
Save towry/ed812031a117e8e155350775aadb914c to your computer and use it in GitHub Desktop.
quickly switch between git workspace folders.
# put this fish function in your fish config.
#
# usage:
# ~:> wt
# or
# ~:> wt path_or_branch_keyword
function wt
set worktree (git worktree list | awk '{print $1, $NF}' | awk -v home="$HOME" '{sub(home, "~"); print $1, $NF}' | fzf --exact --reverse -1 -0 --query=$argv[1] | awk '{print $1}')
if test -n "$worktree"
eval cd $worktree
end
end
@towry
Copy link
Author

towry commented Dec 8, 2023

To use with zoxide to quickly jump to folder and switch to git workspace folder:

# jump to dir and change workspace
function jw
    if test -z $argv[2] && test "$argv[1]" = "-"
        wt $argv[1]
        return
    end
    z $argv[1]
    wt $argv[2]
end

usage:

jw <folder> <git_folder_branch_keyword>

@towry
Copy link
Author

towry commented Dec 8, 2023

dependencies:

  • git
  • fzf
  • zoxide (optional)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment