From 6f837ad27be1d52c4b5415c408eebffd85212f5d Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Thu, 12 Oct 2023 16:22:01 +0200 Subject: [PATCH] add forgotten nsxiv-dirchanger script --- nsxiv-dirchanger | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 nsxiv-dirchanger diff --git a/nsxiv-dirchanger b/nsxiv-dirchanger new file mode 100755 index 0000000..248f849 --- /dev/null +++ b/nsxiv-dirchanger @@ -0,0 +1,53 @@ +#!/bin/bash +shopt -s nullglob globstar + +typeit=0 +if [[ $1 == "--type" ]]; then + typeit=1 + shift +fi + + +STARTDIR=$(pwd) +BASEDIR="" +DONE=0 +SELECTION="$STARTDIR" + +while [ "$DONE" -eq 0 ] ; do + dir_content=() + images="$(find "$STARTDIR" -maxdepth 1 -type f -iregex '.*\(jpg\|jpeg\|png\|gif\|webp\)' -printf "%f\n")" + folders="$(find "$STARTDIR" -maxdepth 1 -not -path '*/.*' -not -path '*/__*' -type d,l -printf "%f\n" | + tail -n +2 )" # exclude basedir + if [ -n "$images" ]; then + dir_content=( "$images" ) + fi + if [ -n "$folders" ]; then + dir_content=( "$folders" "${dir_content[@]}" ) + fi + dir_content=(".." "./" "${dir_content[@]}") + entry=$(printf '%s\n' "${dir_content[@]}" | dmenu -i -p "Select a directory or files:" "$@" -l 15) + + if [ -z "$entry" ] ; then + DONE=1 + exit + fi + + if [ "$entry" = "./" ]; then + DONE=1 + elif [ "$entry" != ".." ] ; then + SELECTION="$SELECTION/$entry" + + # check if another dir + if [ -d "$STARTDIR/$entry" ] ; then + STARTDIR="$STARTDIR/$entry" + else + # not a directory so it must be a real password entry + DONE=1 + fi + #chose to go up one dir + else + STARTDIR="${STARTDIR%/*}" + SELECTION="$STARTDIR" + fi +done +echo $SELECTION