add forgotten nsxiv-dirchanger script
This commit is contained in:
parent
7e957f8310
commit
6f837ad27b
53
nsxiv-dirchanger
Executable file
53
nsxiv-dirchanger
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user