diff options
| author | EuAndreh <eu@euandre.org> | 2022-08-12 19:23:40 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2022-08-12 19:25:24 -0300 |
| commit | 46d741799c2e6c097c21a5bf74707c925e1257be (patch) | |
| tree | 9c719b23c99a8b0fa90173b3f86d5b5d369fbb66 | |
| parent | etc/ssh/known_hosts: Add camarada.site entry (diff) | |
| download | dotfiles-46d741799c2e6c097c21a5bf74707c925e1257be.tar.gz dotfiles-46d741799c2e6c097c21a5bf74707c925e1257be.tar.xz | |
bin/bins: Add helper utility for listing binaries
| -rwxr-xr-x | bin/bins | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/bin/bins b/bin/bins new file mode 100755 index 0000000..28e92f1 --- /dev/null +++ b/bin/bins @@ -0,0 +1,73 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + bins + bins -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -h, --help show this message + + + List the available binaries in $PATH. The result is cached on + the $XDG_CACHE_HOME/euandreh/bins file if $PATH values didn't + change. + + + Examples: + + Pick an executable using `dmenu`: + + $ bins | dmenu + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND- 1)) + + +F="$XDG_CACHE_HOME/euandreh/bins" + +IFS=: +if stest -rdq -n "$F" $PATH; then + trap "rm -f $F-tmp" EXIT + stest -lxf $PATH | sort -u > "$F"-tmp + mv "$F"-tmp "$F" +fi + +cat "$F" |
