#!/bin/sh # A dmenu-based file picker (prints selected file to stdout) # Requires: dmenu (or similar) # Usage: dmenu-filepicker [path] menu=dmenu menuopts="-i -l 15" fullpath=$(realpath ${@:-$(pwd)}) while true; do if [ "$sel" = "." ]; then echo "$fullpath" | sed 's|/\.||' break elif [ -d "$fullpath" ]; then sel=$(ls -a "$fullpath" | sed 's|.*/||' | $menu $menuopts) fullpath=$(printf "$fullpath/%s\n" $sel) else echo "$fullpath" break fi [ -z "$sel" ] && break done