2023-08-23 23:40:14 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# config
|
|
|
|
DIALOG=dialog #gdialog kdialog
|
2023-08-24 22:13:52 +02:00
|
|
|
START_DIR='~/.s3h'
|
2023-08-23 23:40:14 +02:00
|
|
|
|
|
|
|
if [[ $# -eq 1 && -d "$1" ]]; then
|
|
|
|
START_DIR="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# select config file
|
|
|
|
configFile=''
|
|
|
|
while [[ -z "$configFile" ]]; do
|
|
|
|
# init dir variable
|
|
|
|
if [[ -z "$dir" ]]; then
|
|
|
|
dir="$START_DIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# add parent selector if not already in $START_DIR
|
|
|
|
if [[ "$START_DIR" == "$dir" ]]; then
|
|
|
|
para=()
|
|
|
|
else
|
|
|
|
para=(".." "<..>")
|
|
|
|
fi
|
|
|
|
|
|
|
|
# add directory selectors
|
|
|
|
for d in `find $dir -mindepth 1 -maxdepth 1 -type d -printf "%f\n" |sort`; do
|
|
|
|
para+=("$d" "<$d>")
|
|
|
|
done
|
|
|
|
# add file selectors
|
|
|
|
for d in `find $dir -mindepth 1 -maxdepth 1 -type f -printf "%f\n" |sort`; do
|
|
|
|
para+=("$d" "$d")
|
|
|
|
done
|
|
|
|
|
|
|
|
# run dialog
|
|
|
|
ret=$("$DIALOG" --no-tags --stdout --menu "select connection" 0 0 0 ${para[@]} 2>&1)
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# sepcial handling of parent selector
|
|
|
|
if [[ "$ret" != ".." ]]; then
|
|
|
|
ret="$dir/$ret"
|
|
|
|
if [[ -d "$ret" ]]; then
|
|
|
|
dir=$ret
|
|
|
|
else
|
|
|
|
configFile=$ret
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
dir=`dirname "$dir"`
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "config file '$configFile' selected. connecting..."
|
|
|
|
|
|
|
|
# read config file and connect
|
|
|
|
if [[ -f "$configFile" ]]; then
|
|
|
|
# each line equals one config option
|
|
|
|
para=()
|
|
|
|
while read -r configLine; do
|
|
|
|
para+=($configLine)
|
|
|
|
done < "$configFile"
|
|
|
|
|
|
|
|
# execute ssh
|
|
|
|
ssh ${para[@]} `basename "$configFile"`
|
|
|
|
fi
|