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. 59
      scripts/appscripts/sxmo_files.sh

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

Loading…
Cancel
Save