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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# title="$icon_dir Files"
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
set -e
usage() {
printf "%s <FILES> [--date-sort] [--reverse-sort] [--select-only] [-h help]\n" \
"$(basename "$0")"
exit 1
}
DIR="$HOME"
SORT=
REVERSE=
SELECTONLY=0
while [ -n "$1" ]; do
case "$1" in
--select-only)
SELECTONLY=1
;;
--date-sort)
SORT="--sort=t"
;;
--reverse-sort)
REVERSE="-r"
;;
-h)
usage
;;
*)
DIR="$1"
esac
shift
done
cd "$DIR"
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
;;
\*)
if [ -n "$SELECTONLY" ]; then
printf %s "Can't do this"
else
sxmo_open.sh -a ./*
fi
;;
*)
[ -d "$PICKED" ] && cd "$PICKED" && continue
if [ -f "$PICKED" ]; then
if [ "$SELECTONLY" -eq 1 ]; then
printf "%s" "$(pwd)/$PICKED" && exit
else
sxmo_open.sh -a "$PICKED"
fi
fi
;;
esac
done
|