~mil/sxmo-utils

ref: 9bd3f31ba9c2b3a49493601c1d59d328c58a87f8 sxmo-utils/scripts/appscripts/sxmo_files.sh -rwxr-xr-x 1.2 KiB
9bd3f31bStacy Harper Cleanup sxmo_file.sh 2 months ago
                                                                                
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env sh

# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

set -e

DIR="$1"
[ -z "$DIR" ] && DIR="$HOME"
cd "$DIR" || exit 1

SORT=
REVERSE=

sort_loop() {
	CHOICES="$([ -z "$SORT" ] && printf "date" || printf "name")\n$([ -z "$REVERSE" ] && printf "desc" || printf "asc")\n"

	PICKED="$(
		printf %b "$CHOICES" |
		sxmo_dmenu.sh -p "Sort" -i
	)"

	case "$PICKED" in
		"date")
			SORT="--sort=t"
			;;
		"name")
			SORT=
			;;
		"desc")
			REVERSE="-r"
			;;
		"asc")
			REVERSE=
			;;
	esac
}


while true; do
	# shellcheck disable=SC2086
	FILES="$(ls -1p $SORT $REVERSE)"
	CHOICES="$(printf %b 'Reload\nOpen in terminal\nClose Menu\nSort By\n../\n*\n'"$FILES")"
	DIR="$(basename "$(pwd)")"
	TRUNCATED="$(printf %.7s "$DIR")"
	if [ "$DIR" != "$TRUNCATED" ]; then
		DIR="$TRUNCATED..."
	fi

	PICKED="$(
		printf %b "$CHOICES" |
		sxmo_dmenu.sh -p "$DIR" -i
	)"

	case "$PICKED" in
		"Sort By")
			sort_loop
			;;
		"Open in terminal")
			cd "$(pwd)" && sxmo_terminal.sh && continue
			;;
		"Close Menu")
			exit 0
			;;
		"Reload")
			continue
			;;
		\*)
			sxmo_open.sh -a ./*
			;;
		*)
			[ -d "$PICKED" ] && cd "$PICKED" && continue
			[ -f "$PICKED" ] && sxmo_open.sh -a "$PICKED"
			;;
	esac
done