-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellpers.sh
More file actions
37 lines (34 loc) · 1.14 KB
/
shellpers.sh
File metadata and controls
37 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Source this in your shell configuration to enable helper functions for NGM.
# eval "$(ngm shell)"
#
# The 'ngm shell' command outputs this file's contents to stdout.
#
# Source: https://github.com/ackledotdev/ngm/blob/gitmaster/shellpers.sh
ngmcd() {
local NICKNAME="$1"
local REPO_PATH
REPO_PATH=$(ngm dir "$NICKNAME" -q)
NGM_STATUS_CODE=$?
if [ -z "$NICKNAME" ]; then
echo "ngmcd: No nickname provided." >&2
return 1
fi
if [ -z "$REPO_PATH" ] || [ $NGM_STATUS_CODE -eq 2 ]; then
echo "ngmcd: No registered repository found with nickname '$NICKNAME'." >&2
return $NGM_STATUS_CODE
elif [ ! -e "$REPO_PATH" ] || [ $NGM_STATUS_CODE -eq 3 ]; then
echo "ngmcd: Repository path '$REPO_PATH' does not exist." >&2
echo "$REPO_PATH"
return $NGM_STATUS_CODE
elif [ ! -d "$REPO_PATH" ]; then
echo "ngmcd: Repository path '$REPO_PATH' is not a directory." >&2
return 4
elif [ $NGM_STATUS_CODE -eq 5 ]; then
echo "ngmcd: Repository path '$REPO_PATH' does not contain a valid Git repository." >&2
return $NGM_STATUS_CODE
fi
cd "$REPO_PATH" || {
echo "ngmcd: Failed to change directory to '$REPO_PATH'." >&2
return 6
}
}