commit 7efb41ff926e6012f8d8d77fb1547ace540ef44d parent 7158141312f9b9a9fb35160b99744cfbbebf050b Author: clamiax <smoppy@gmail.com> Date: Sat, 17 Oct 2015 17:29:14 +0200 Simplify. Also handle absolute paths. Diffstat:
M | browse | | | 31 | ++++++++++++++++--------------- |
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/browse b/browse @@ -1,23 +1,24 @@ #!/bin/sh # TODO: multisel -TARGET="$1" -[ -z "$TARGET" ] && TARGET=. +target="$1" +[ -z "$target" ] && target=. while true; do - if [ ! -d "$TARGET" ]; then - mimeopen "$TARGET" - exit 0 - fi + sel="$(ls -1a "$target" |grep -v '^\.$' | dmenu -l 25)" + ec=$? + [ "$ec" -ne 0 ] && exit $ec - # skip non-existing files - ne=true - while "$ne"; do - sel="$(ls -1a "$TARGET" |grep -v '^\.$' | dmenu -l 25)" - ec=$? - [ "$ec" -ne 0 ] && exit $ec - [ -e "${TARGET}/${sel}" ] && ne=false - done + c="$(echo "$sel" |cut -b1)" + if [ "$c" = "/" ]; then + newt="$sel" + else + newt="$(realpath "${target}/${sel}")" + fi - TARGET="${TARGET}/${sel}" + [ -e "$newt" ] && target="$newt" + if [ ! -d "$target" ]; then + mimeopen "$target" + exit 0 + fi done