aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-08-12 19:23:40 -0300
committerEuAndreh <eu@euandre.org>2022-08-12 19:25:24 -0300
commit46d741799c2e6c097c21a5bf74707c925e1257be (patch)
tree9c719b23c99a8b0fa90173b3f86d5b5d369fbb66 /bin
parentetc/ssh/known_hosts: Add camarada.site entry (diff)
downloaddotfiles-46d741799c2e6c097c21a5bf74707c925e1257be.tar.gz
dotfiles-46d741799c2e6c097c21a5bf74707c925e1257be.tar.xz
bin/bins: Add helper utility for listing binaries
Diffstat (limited to 'bin')
-rwxr-xr-xbin/bins73
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"