config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 779ae9cf4fef71058caf68ba6f214ba2ab9ab5ab
parent 5a8766dbe97c2cd3b4248f73e7f0d2d9bae82134
Author: Jacob R. Edwards <n/a>
Date:   Tue, 15 Nov 2022 21:58:44 -0600

Add script to select easily files and directories

Diffstat:
Alocal/bin/bin/xgetfile | 50++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+), 0 deletions(-)

diff --git a/local/bin/bin/xgetfile b/local/bin/bin/xgetfile @@ -0,0 +1,50 @@ +#!/bin/sh +# Copyright Nov 2022 Jacob R. Edwards +# Select files and directories using dmenu + +list() { + find "$1" -mindepth 1 -maxdepth $depth ${type:+-type $type} \ + -exec ls -dp '{}' + | sed 's/^\.\/\/*//' +} + +sel() + dmenu -p "$wd" + +depth=3 +while test $# -gt 0 -a "${1#-}" != "$1" +do + case "$1" in + (-t) + case "${2:?-t requires an argument}" in + (d|f) + type="$2" + shift + ;; + (*) + echo "$2: Invalid type" 1>&2 + exit 1 + esac + ;; + (-d) + depth="$2" + shift + ;; + (*) + echo "$1: Unknown option" 1>&2 + exit 1 + ;; + esac + shift +done + +wd="${1:-.}" +while name="$(list "$wd" | sel)" && test "$name" -a -d "$name" +do + wd="$name" +done + +if ! test "$name"; then + echo "$wd" +else + echo "$name" +fi