Skip to content

Instantly share code, notes, and snippets.

@yanick
Created May 28, 2020 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanick/fb6b62645759ef9b3db2102eb64356a2 to your computer and use it in GitHub Desktop.
Save yanick/fb6b62645759ef9b3db2102eb64356a2 to your computer and use it in GitHub Desktop.
cd to the repo root
# Defined in /home/yanick/.config/fish/functions/cdr.fish @ line 1
function cdr --description 'cd to the repo root'
set -l repo_dir ( perl -MPath::Tiny \
-E'$x = path(".")->absolute; while(1){ exit say $x if $x->child(".git")->is_dir; exit if $x eq "/"; $x = $x->parent }' )
if [ $repo_dir != "" ]
cd $repo_dir
else
echo "not in a git repo"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment