Cleanup sxmo_file.sh

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
master
Stacy Harper 3 years ago committed by Maarten van Gompel
parent f0ca704812
commit 9bd3f31ba9
  1. 55
      scripts/appscripts/sxmo_files.sh

@ -4,6 +4,8 @@
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"
set -e
DIR="$1"
[ -z "$DIR" ] && DIR="$HOME"
cd "$DIR" || exit 1
@ -12,17 +14,27 @@ SORT=
REVERSE=
sort_loop() {
CHOICES="$([ -z "$SORT" ] && echo "date" || echo "name")\n$([ -z "$REVERSE" ] && echo "desc" || echo "asc")"
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
)"
echo "$PICKED" | grep -q "date" && SORT="--sort=t"
echo "$PICKED" | grep -q "name" && SORT=
echo "$PICKED" | grep -q "desc" && REVERSE="-r"
echo "$PICKED" | grep -q "asc" && REVERSE=
case "$PICKED" in
"date")
SORT="--sort=t"
;;
"name")
SORT=
;;
"desc")
REVERSE="-r"
;;
"asc")
REVERSE=
;;
esac
}
@ -36,19 +48,30 @@ while true; do
DIR="$TRUNCATED..."
fi
PICKED="$(
echo "$CHOICES" |
printf %b "$CHOICES" |
sxmo_dmenu.sh -p "$DIR" -i
)" || exit
)"
echo "$PICKED" | grep "Sort By" && sort_loop
echo "$PICKED" | grep "Open in terminal" && cd "$(pwd)" && sxmo_terminal.sh
echo "$PICKED" | grep "Close Menu" && exit 0
echo "$PICKED" | grep "Reload" && continue
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
echo "$PICKED" | grep -E '^[*]$' && sxmo_open.sh -a ./*
if [ -f "$PICKED" ] || [ "$PICKED" = "Open in terminal" ]; then
sxmo_open.sh -a "$PICKED"
fi
[ -f "$PICKED" ] && sxmo_open.sh -a "$PICKED"
;;
esac
done

Loading…
Cancel
Save