Skip to content

Commit

Permalink
feat(one dep): new command "one dep status" to show status of deps
Browse files Browse the repository at this point in the history
  • Loading branch information
adoyle-h committed May 30, 2023
1 parent 04e4b6e commit 7852009
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions one-cmds/dep
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Desc: Manage one.bash deps
ACTION:
i, install Install all deps.
u, update [<DEP>] If <DEP> not passed, update all deps.
s, status [<DEP>] Show status of deps
EOF
exit 0
fi
Expand All @@ -29,18 +30,13 @@ fi
# one.bash:completion
if [[ "${1:-}" == --complete ]]; then
if (( COMP_CWORD < 3 )); then
words=(i install u update --help -h)
words=(install update status --help -h)
printf '%s\n' "${words[@]}"
else
case $2 in
i|install|u|update)
readarray -t list < <(compgen -A directory "$ONE_DIR/deps/")
for dir in "${list[@]}"; do
if [[ -d "$dir/.git" ]]; then
# shellcheck disable=2001
sed "s|^$ONE_DIR/deps/||" <<<"$dir"
fi
done
i|install|u|update|s|status)
words=(one.share one-bash-it bash-it composure dotbot)
printf '%s\n' "${words[@]}"
;;
esac
fi
Expand Down Expand Up @@ -74,6 +70,14 @@ git_update() {
git -C "$dir" pull --recurse-submodules="${SUBMOD:-no}" "$@"
}

git_status() {
local dir=$1
shift
echo "[$(basename "$dir")]"
git -C "$dir" show --oneline -s
echo ""
}

install() {
SUBMOD=true git_clone "https://github.com/anishathalye/dotbot.git" "$ONE_DIR/deps/dotbot"
git_clone "https://github.com/adoyle-h/composure.git" "$ONE_DIR/deps/composure"
Expand Down Expand Up @@ -108,6 +112,17 @@ update() {
fi
}

list_status() {
if (( $# == 0 )); then
git_status "$ONE_DIR/deps/dotbot"
git_status "$ONE_DIR/deps/composure"
[[ ${ONE_SHARE_ENABLE:-} == true ]] && git_status "$ONE_SHARE_DIR"
[[ ${ONE_BASH_IT_ENABLE:-} == true ]] && git_status "$ONE_BASH_IT_DIR"
else
git_status "$ONE_DIR/deps/$1"
fi
}

action=$1
shift

Expand All @@ -119,6 +134,8 @@ case "$action" in

u|update) update "$@" ;;

s|status) list_status "$@" ;;

*)
echo "Invalid action '$action'" >&2
exit 1
Expand Down

0 comments on commit 7852009

Please sign in to comment.