mirror of
https://github.com/rwxrob/dot
synced 2024-11-14 18:12:56 +00:00
82 lines
1.7 KiB
Bash
Executable File
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
|