/ de-omarchy / bin / omarchy-menu-file
swadhinbiswas Initial de-omarchy: Omarchy UI layer for Arch-based distros · 8/22/2026
9f393b2
49 lines · 1.3 KB
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
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash

# omarchy:summary=Pick a file from a menu
# omarchy:group=menu
# omarchy:name=file
# omarchy:args=label paths formats [menu args...]
# omarchy:examples=omarchy menu file "Select image" "$HOME/Pictures" "jpg png webp"|omarchy-menu-file "Select media" "$HOME/Pictures:$HOME/Videos" "jpg png mp4 mov" --width 800

set -euo pipefail

if (( $# < 3 )); then
  echo "Usage: omarchy-menu-file <label> <paths> <formats> [menu args...]" >&2
  exit 1
fi

label="$1"
paths_arg="$2"
formats_arg="$3"
shift 3

IFS=: read -r -a paths <<<"$paths_arg"
read -r -a formats <<<"$formats_arg"

if (( ${#paths[@]} == 0 || ${#formats[@]} == 0 )); then
  echo "Usage: omarchy-menu-file <label> <paths> <formats> [menu args...]" >&2
  exit 1
fi

for path in "${paths[@]}"; do
  [[ -e $path ]] || { echo "Path not found: $path" >&2; exit 1; }
done

find_args=("${paths[@]}" "(" -type d -name ".*" ! -name "." -prune ")" -o -type f ! -name ".*" "(")
first_format=true
for format in "${formats[@]}"; do
  if [[ $first_format == "true" ]]; then
    first_format=false
  else
    find_args+=(-o)
  fi

  format="${format#.}"
  find_args+=(-iname "*.$format")
done
find_args+=(")" -printf '%T@\t%p\n')

find "${find_args[@]}" 2>/dev/null | sort -rn | cut -f2- |
  omarchy-menu-select "$label" -- --width 800 --maxheight 500 "$@"