1
0
forked from a/repotool
repotool/repotool.zsh

52 lines
1.1 KiB
Bash
Raw Normal View History

2024-05-02 00:43:43 +00:00
#!/usr/bin/env zsh
[[ -z "$REPOTOOL_PATH" ]] && export REPOTOOL_PATH="$HOME/repo"
2025-05-12 17:09:06 +00:00
2024-05-02 00:43:43 +00:00
_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
}
2025-05-12 17:09:06 +00:00
TOOL_BIN="$REPOTOOL_PATH/.bin/repotool"
2024-05-02 00:43:43 +00:00
case "$1" in
2024-05-05 21:54:08 +00:00
get | g)
2024-05-02 00:43:43 +00:00
shift;
2025-05-12 17:09:06 +00:00
response=$($TOOL_BIN get $@)
2024-05-02 00:43:43 +00:00
if [[ $? != 0 ]] then;
2024-05-05 21:54:08 +00:00
echo "failed to get repo with args $@"
return $?
2024-05-02 00:43:43 +00:00
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")
2025-05-12 17:09:06 +00:00
echo <<EOF
usage:
repo get <repo-name>
EOF
2025-05-12 17:23:17 +00:00
;;
"open")
raw_url=$(git ls-remote --get-url | cut -d '@' -f2 | sed 's/:/\//1')
xdg-open "https://${raw_url}"
;;
2024-05-02 00:43:43 +00:00
esac