aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-07-11 17:00:26 -0300
committerEuAndreh <eu@euandre.org>2023-07-11 17:00:26 -0300
commit68fa1c1ab4d1473af2ff585e0094783af8d11e64 (patch)
tree261a1a00cedf731a0f5639703e0a8a63b89842d9 /bin
parentetc/sh/rc: Increase priority of $XDG_PREFIX/bin in $PATH (diff)
downloaddotfiles-68fa1c1ab4d1473af2ff585e0094783af8d11e64.tar.gz
dotfiles-68fa1c1ab4d1473af2ff585e0094783af8d11e64.tar.xz
bin/gc: Make it more flexible by accepting multiple TYPE arguments
Diffstat (limited to 'bin')
-rwxr-xr-xbin/gc46
1 files changed, 26 insertions, 20 deletions
diff --git a/bin/gc b/bin/gc
index 49f25ce..25c5b5e 100755
--- a/bin/gc
+++ b/bin/gc
@@ -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