mirror of
https://github.com/itme-brain/nixos.git
synced 2026-03-24 00:29:43 -04:00
Fixed cdg
This commit is contained in:
parent
5c8b6706a1
commit
82ee336d74
1 changed files with 25 additions and 7 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue