aboutsummaryrefslogtreecommitdiff
path: root/dmenu-scripts
blob: 6d9c9db0cb9d2d2f5e72fec2d0e8752722af6895 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
set -euo pipefail

script_path="${HOME}/.local/bin"

# Optional dmenu theming
# shellcheck disable=SC1090
[[ -r "${HOME}/.local/bin/dmenu-theming" ]] && . "${HOME}/.local/bin/dmenu-theming"

DMENU_CMD="${DMENU_CMD:-dmenu}"
PROMPT="${PROMPT:-Run: }"

# List only executable non-binary files in ~/.local/bin
choices="$(
  find "${script_path}" -maxdepth 1 -type f -executable -print0 \
  | xargs -0 -I{} sh -c 'grep -Iq . "$1" && printf "%s\n" "$(basename "$1")"' _ {} \
  | sort -u
)"

picked="$(
  printf "%s\n" "$choices" \
  | ${DMENU_CMD} -i -l 20 -p "${PROMPT}" ${lines:-} ${colors:-} ${font:-} \
  || true
)"

[[ -n "${picked}" ]] || exit 0

# Safety: only allow basenames (no slashes)
case "$picked" in
  */*|"") exit 0 ;;
esac

target="${script_path}/${picked}"

[[ -x "$target" ]] || { printf "ERROR: not executable: %s\n" "$target" >&2; exit 1; }

exec "$target"