commit f896ceabe1ac5259d2285f3c6d0937d11c19507f parent 4a08995b2f1c90766f992668c67fb37ca534ff00 Author: Ed van Bruggen <edvb54@gmail.com> Date: Fri, 2 Dec 2016 21:45:44 -0800 Add browse.sh, returns selected file or folder Diffstat:
browse.sh | | | 26 | ++++++++++++++++++++++++++ |
1 file changed, 26 insertions(+), 0 deletions(-)
diff --git a/browse.sh b/browse.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# TODO: multisel + +target="$2" +[ -z "$target" ] && target="$(realpath .)" + +while true; do + sel="$(ls -1a "$target" | grep -v '^\.$' | dmenu -i -p "$target" -l 25 $@)" + ec=$? + [ "$ec" -ne 0 ] && exit $ec + + c="$(echo "$sel" |cut -b1)" + if [ "$c" = "/" ]; then + newt="$sel" + else + newt="$(realpath "${target}/${sel}")" + fi + + if [ -e "$newt" ]; then + target="$newt" + if [ ! -d "$target" ]; then + echo "$target" + exit 0 + fi + fi +done