Fixed cdg

This commit is contained in:
Bryan Ramos 2023-06-02 14:42:11 -04:00
parent 5c8b6706a1
commit 82ee336d74

View file

@ -87,15 +87,33 @@ fi
# Custom Functions # Custom Functions
## ##
# CD to Git root # cd to git root
function cdg() { function cdg() {
local root # Check for --help flag
root=$(git rev-parse --show-toplevel 2> /dev/null) if [[ $1 == "--help" ]]; then
if [[ -n $root ]]; then echo "A simple utility for navigating to the root of a git repo"
cd $root return 0
else
echo "Not a git repo"
fi fi
# Check for invalid command
if [[ -n "$1" ]]; then
echo "Invalid command: $1. Try 'cdg --help'."
return 1
fi
# Find the root of the git repository
local root_dir
root_dir=$(git rev-parse --show-toplevel 2>/dev/null)
local git_status=$?
# Check for git rev-parse failure
if [ $git_status -ne 0 ]; then
echo "Error: Not a git repo."
return 1
fi
# If we're inside a git repo, cd to the root
cd "$root_dir"
} }
# penpot {run|stop|update|help} alias function # penpot {run|stop|update|help} alias function