#!/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=: # Word-splitting is the goal: # shellcheck disable=2086 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"