rwxrob-dot/scripts/repos
Rob Muhlestein 2ea0289e9f Rebase
2022-02-09 02:29:05 -05:00

82 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/bash
list () {
gl list
# FIXME have it work for anyone
for i in skilstak rwxrob afkworks essential-web pegn soil; do
gh repos $i
done
}
path () {
if [[ -n "$REPOS" ]]; then
echo "${REPOS}"
return
fi
return -1
# TODO eventually look for in config as well
}
# Returns the full path to the argument if contained and file or
# directory exists within the current repos path (see path()). If
# a relative path is passed then calls find at the repo path root and
# properly ignores all .git directories. If only a name is passed the
# specific file name will be searched for with find.
has () {
local what="$1"
if [[ $what =~ ^/ ]];then
if [[ $what =~ $(path) ]]; then
echo "$what"
fi
return
fi
if [[ $what =~ / ]];then
find $(path) -path "*$what"
return
fi
find $(path) -name "$what"
}
hascmd () {
local things=$(has "$@")
for this in ${things[@]}; do
if [[ -x $this && ! -d $this ]]; then
echo "${this}"
fi
done
}
############################## Main Command #############################
subcommand="${1-usage}"
shift 2>/dev/null
if [ -z "${subcommand}" ]; then
usage
exit 1
fi
commands () {
echo ${commands[@]}
}
declare -a commands=(commands list path has hascmd)
for i in ${commands[@]}; do
if [[ "${i}" == "${subcommand}" ]]; then
"${subcommand}" "$@"
exit 0
fi
done
######################### Tab Completion Context ########################
# remember COMP_LINE is changed by shift
if [ -n "${COMP_LINE}" ]; then
for cmd in ${commands[@]}; do
[[ "${cmd:0:${#1}}" == "$1" ]] && echo "${cmd}"
done
exit 0
fi