1
0
forked from a/repotool
repotool/repotool.zsh
2025-05-12 12:09:06 -05:00

47 lines
1009 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
}
TOOL_BIN="$REPOTOOL_PATH/.bin/repotool"
case "$1" in
get | g)
shift;
response=$($TOOL_BIN 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")
echo <<EOF
usage:
repo get <repo-name>
EOF
esac