3 Commits
1.6 ... 1.7

Author SHA1 Message Date
d7100267ce version bump 2024-06-14 21:32:30 +02:00
4c08363b7f use one type of execute
replaced ` by $()
2024-06-14 21:29:15 +02:00
d975e38ef3 add preselection of last selected item #1 2024-06-14 21:25:04 +02:00

34
s3h.sh
View File

@ -3,7 +3,7 @@
# config # config
DIALOG=dialog #gdialog kdialog DIALOG=dialog #gdialog kdialog
START_DIR="$HOME/.s3h" START_DIR="$HOME/.s3h"
VERSION="1.5" VERSION="1.7"
# TODO: use opt parsing # TODO: use opt parsing
if [[ $# -eq 1 && "$1" == "-v" ]]; then if [[ $# -eq 1 && "$1" == "-v" ]]; then
@ -15,7 +15,7 @@ if [[ $# -eq 1 && -d "$1" ]]; then
START_DIR="$1" START_DIR="$1"
fi fi
START_DIR=`realpath "$START_DIR"` START_DIR=$(realpath "$START_DIR")
if [[ ! -d "$START_DIR" ]]; then if [[ ! -d "$START_DIR" ]]; then
echo "start directory '$START_DIR' does not exist" >&2 echo "start directory '$START_DIR' does not exist" >&2
@ -24,6 +24,19 @@ if [[ ! -d "$START_DIR" ]]; then
exit 2 exit 2
fi fi
LAST="$START_DIR/.last"
# check if there was a last call, if so fake while loop variable
preselect=''
if [[ -f "$LAST" ]]; then
last=$(cat "$LAST")
# check if config file still exists
if [[ -f "$last" ]]; then
dir=$(dirname "$last")
preselect=$(basename "$last")
fi
fi
# select config file # select config file
configFile='' configFile=''
while [[ -z "$configFile" ]]; do while [[ -z "$configFile" ]]; do
@ -40,12 +53,12 @@ while [[ -z "$configFile" ]]; do
fi fi
# add directory selectors # add directory selectors
dirs=`find $dir -mindepth 1 -maxdepth 1 ! -name '.*' -type d -printf "%f\n" |sort` dirs=$(find $dir -mindepth 1 -maxdepth 1 ! -name '.*' -type d -printf "%f\n" |sort)
for d in $dirs; do for d in $dirs; do
para+=("$d" "<$d>") para+=("$d" "<$d>")
done done
# add file selectors # add file selectors
files=`find $dir -mindepth 1 -maxdepth 1 ! -name '.*' -type f -printf "%f\n" |sort` files=$(find $dir -mindepth 1 -maxdepth 1 ! -name '.*' -type f -printf "%f\n" |sort)
for d in $files; do for d in $files; do
# text before ~ is tag # text before ~ is tag
if [[ "$d" == *"~"* ]]; then if [[ "$d" == *"~"* ]]; then
@ -65,7 +78,11 @@ while [[ -z "$configFile" ]]; do
fi fi
# run dialog # run dialog
ret=$("$DIALOG" --no-tags --stdout --menu "select connection" 0 0 0 ${para[@]} 2>&1) dialogOptions=''
if [[ ! -z "$preselect" ]]; then
dialogOptions="$dialogOptions --default-item $preselect"
fi
ret=$("$DIALOG" --no-tags --stdout $dialogOptions --menu "select connection" 0 0 0 ${para[@]} 2>&1)
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
clear clear
exit 1 exit 1
@ -80,7 +97,7 @@ while [[ -z "$configFile" ]]; do
configFile=$ret configFile=$ret
fi fi
else else
dir=`dirname "$dir"` dir=$(dirname "$dir")
fi fi
done done
@ -104,8 +121,11 @@ if [[ -f "$configFile" ]]; then
# clear screen // remove dialog colors # clear screen // remove dialog colors
echo "config file '$configFile' selected. connecting..." echo "config file '$configFile' selected. connecting..."
# save selected configFile for next call of s3h
echo "$configFile" > "$LAST"
# extract user@host if ~ in config file name # extract user@host if ~ in config file name
login=`basename "$configFile"` login=$(basename "$configFile")
if [[ "$login" == *"~"* ]]; then if [[ "$login" == *"~"* ]]; then
login="${login#*~}" login="${login#*~}"
fi fi