40 lines
929 B
Bash
Executable File
40 lines
929 B
Bash
Executable File
#!/usr/bin/env zsh
|
|
|
|
[[ -z "$REPOTOOL_PATH" ]] && export REPOTOOL_PATH="$HOME/repo"
|
|
|
|
_activate_hook() {
|
|
if [[ -f "$REPOTOOL_PATH/.hooks/$1.zsh" ]]; then
|
|
. "$REPOTOOL_PATH/.hooks/$1.zsh" $2
|
|
return 0
|
|
fi
|
|
if [[ -f "$REPOTOOL_PATH/.hooks/$1.sh" ]]; then
|
|
. "$REPOTOOL_PATH/.hooks/$1.sh" $2
|
|
return 0
|
|
fi
|
|
if [[ -f "$REPOTOOL_PATH/.hooks/$1" ]]; then
|
|
. "$REPOTOOL_PATH/.hooks/$1" $2
|
|
return 0
|
|
fi
|
|
return 1
|
|
}
|
|
case "$1" in
|
|
get | g)
|
|
shift;
|
|
response=$($REPOTOOL_PATH/.bin/repotool get $@)
|
|
if [[ $? != 0 ]] then;
|
|
echo "failed to get repo with args $@"
|
|
return $?
|
|
fi
|
|
declare -A obj
|
|
for item in ${(z)response}; do
|
|
parts=(${(s[=])item})
|
|
# NOTE: zsh is 1 indexed arrays
|
|
obj[${parts[1]}]=${parts[2]}
|
|
done
|
|
_activate_hook "before_cd" $response
|
|
cd ${obj[dir]}
|
|
_activate_hook "after_cd" $response
|
|
;;
|
|
'help' | "-h"| "-help" | "--help")
|
|
esac
|