Skip to content

Instantly share code, notes, and snippets.

@siers
Created September 3, 2019 06:35
Show Gist options
  • Save siers/73a8cf857f4311370b5e5830d30ff200 to your computer and use it in GitHub Desktop.
Save siers/73a8cf857f4311370b5e5830d30ff200 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
# create or use ncdu's output from cache, then open ncdu
set -eu
sanit-path() { echo "$(tr / : <<< "$1" | tr -cd '0-9a-z\-.:')"; }
cache="$HOME/data/cache/ncdu" # RUN mkdir yourself!
dir="$1"; shift
key="$cache/$(sanit-path "$dir")"
mkdir -p "$cache"
(! [ -e "$key" ] || [ -n "${F:-}" ]) && ncdu -o "$key" "$dir" || :
echo ncdu -f "$key" "$@"
ncdu -f "$key" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment