summaryrefslogtreecommitdiff
path: root/scripts/dmenu-filepicker
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-05-06 08:30:49 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2026-05-06 08:30:49 +0200
commit60052659b98832c78c902e4f27ecee2663d8e913 (patch)
tree9efc1388569c43456557aa1975b4bec99bf06c94 /scripts/dmenu-filepicker
parent10e16c2fb2266bb2b46ec7ea64d721de0c29a0d9 (diff)
downloadconfig-60052659b98832c78c902e4f27ecee2663d8e913.tar.gz
config-60052659b98832c78c902e4f27ecee2663d8e913.zip
Added scripts
Diffstat (limited to 'scripts/dmenu-filepicker')
-rwxr-xr-xscripts/dmenu-filepicker47
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/dmenu-filepicker b/scripts/dmenu-filepicker
new file mode 100755
index 0000000..288cac9
--- /dev/null
+++ b/scripts/dmenu-filepicker
@@ -0,0 +1,47 @@
1#!/bin/sh
2
3# A dmenu-based file picker (prints selected file to stdout)
4# Requires: dmenu (or similar)
5
6# Usage: dmenu-filepicker [-m menu] [path]
7
8menu="dmenu -i -l 15"
9
10usage() {
11 echo "Usage: dmenu-filepicker [-m MENU] [PATH]"
12}
13
14while getopts "m:" opt; do
15 case "$opt" in
16 m)
17 menu="$OPTARG"
18 ;;
19 *)
20 usage
21 exit 1
22 ;;
23 esac
24done
25shift $((OPTIND - 1))
26
27fullpath=$(realpath "${@:-"$(pwd)"}")
28
29while true; do
30 if [ "$sel" = "." ]; then
31 echo "$fullpath" | sed 's|/\.||'
32 break
33 elif [ -d "$fullpath" ] || [ -z "$fullpath" ]; then
34 if [ -z "$fullpath" ]; then fp="/"; else fp="$fullpath"; fi
35 sel=$(ls -a "$fp" | sed 's|.*/||' | $menu)
36 if [ "$sel" = ".." ]; then
37 fullpath=$(echo "$fullpath" | sed "s|/[^/]*$||")
38 else
39 fullpath=$(echo "$sel" | sed "s|^|$fullpath/|")
40 fi
41 else
42 echo "$fullpath"
43 break
44 fi
45
46 [ -z "$sel" ] && break
47done

Generated with cgit - Back to sebastiano.tronto.net