diff options
author | EuAndreh <eu@euandre.org> | 2023-07-11 17:00:26 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2023-07-11 17:00:26 -0300 |
commit | 68fa1c1ab4d1473af2ff585e0094783af8d11e64 (patch) | |
tree | 261a1a00cedf731a0f5639703e0a8a63b89842d9 /bin/gc | |
parent | etc/sh/rc: Increase priority of $XDG_PREFIX/bin in $PATH (diff) | |
download | dotfiles-68fa1c1ab4d1473af2ff585e0094783af8d11e64.tar.gz dotfiles-68fa1c1ab4d1473af2ff585e0094783af8d11e64.tar.xz |
bin/gc: Make it more flexible by accepting multiple TYPE arguments
Diffstat (limited to 'bin/gc')
-rwxr-xr-x | bin/gc | 46 |
1 files changed, 26 insertions, 20 deletions
@@ -4,7 +4,7 @@ set -eu usage() { cat <<-'EOF' Usage: - gc [TYPE] + gc [TYPE...] gc -h EOF } @@ -35,9 +35,9 @@ help() { $ gc - Cleanup tmpdir: + Cleanup trash and tmpdir: - $ gc tmpdir + $ gc trash tmpdir EOF } @@ -139,28 +139,34 @@ gc_vcs() { } -gc_all() { - set -x - gc_guix - gc_nix - gc_trash - gc_tmpdir - gc_docker - gc_vcs - set +x -} +TYPES=' +guix +nix +trash +tmpdir +docker +vcs +' -TYPE="${1:-all}" -CMD=gc_"$TYPE" -if ! command -v "$CMD" >/dev/null; then - printf 'Invalid TYPE: "%s".\n\n' "$TYPE" >&2 - usage >&2 - exit 2 +if [ $# -eq 0 ]; then + set -- $TYPES fi +for type in "$@"; do + CMD=gc_"$type" + if ! command -v "$CMD" >/dev/null; then + printf 'Invalid TYPE: "%s".\n\n' "$type" >&2 + usage >&2 + exit 2 + fi +done BEFORE="$(disk)" -"$CMD" +for type in "$@"; do + set -x + "$CMD" + { set +x; } 2>/dev/null +done AFTER="$(disk)" cat <<-EOF |