From 7852009c3fab6bc4ed94f0e6aba00323b2de8b4d Mon Sep 17 00:00:00 2001 From: ADoyle Date: Tue, 30 May 2023 18:15:50 +0800 Subject: [PATCH] feat(one dep): new command "one dep status" to show status of deps --- one-cmds/dep | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/one-cmds/dep b/one-cmds/dep index fd58509..de112a4 100755 --- a/one-cmds/dep +++ b/one-cmds/dep @@ -16,6 +16,7 @@ Desc: Manage one.bash deps ACTION: i, install Install all deps. u, update [] If not passed, update all deps. + s, status [] Show status of deps EOF exit 0 fi @@ -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 @@ -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" @@ -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 @@ -119,6 +134,8 @@ case "$action" in u|update) update "$@" ;; + s|status) list_status "$@" ;; + *) echo "Invalid action '$action'" >&2 exit 1