aboutsummaryrefslogtreecommitdiff
path: root/dmenu-filepicker
blob: a14bd5354967256d460340969955260a37ecf76a (plain)
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
#!/bin/sh

# A dmenu-based file picker (prints selected file to stdout)
# Requires: dmenu (or similar)
# Usage: dmenu-filepicker [path]

menu=${MENU:-dmenu}
menuopts="-i -l 15"

basedir="$(pwd)"

next="${@:-$(pwd)}"

while true; do
	if [ -z "$next" ]; then
		break
	elif [ "$next" = "." ]; then
		pwd
		break
	elif [ -d "$next" ]; then
		cd "$next"
		next=$(ls -a | $menu $menuopts)
	else
		echo "$(pwd)/$next"
		break
	fi
done

cd "$basedir"

Generated with cgit - Back to sebastiano.tronto.net