dbrowse (888B)
1 #!/bin/sh 2 3 NEWLINE=" 4 " 5 6 fullpath() { 7 name="$(sh -c "echo '$1'")" 8 path="$2" 9 c="$(echo "$name" |cut -b1)" 10 11 if [ "$c" = "/" ]; then 12 full="$name" 13 else 14 full="$path/$name" 15 fi 16 realpath "$full" 17 18 } 19 20 main() { 21 target="$1" 22 [ -z "$target" ] && target="$(realpath .)" 23 prompt="$2" 24 25 while true; do 26 p="$prompt" 27 [ -z "$p" ] && p="$target" 28 items="$(ls -1a "$target" |grep -v '^\.$' | dmenu -p "$p" -l 25)" 29 ec=$? 30 [ "$ec" -ne 0 ] && exit $ec 31 32 # ignore duplicates 33 items="$(echo "$items" |sort -u)" 34 35 nitems=$(echo "$items" |wc -l) 36 if [ $nitems -eq 1 ]; then 37 newt="$(fullpath "$items" "$target")" 38 [ ! -e "$newt" ] && continue 39 if [ -d "$newt" ]; then 40 target="$newt" 41 continue 42 fi 43 fi 44 IFS="$NEWLINE" 45 for item in $items; do 46 item="$(fullpath "$item" "$target")" 47 [ ! -e "$item" ] && continue 48 echo "$item" 49 done 50 unset IFS 51 exit 0 52 done 53 } 54 55 main "$@"