set custom text by using ~ (tilde) in filename

foo~bar@example.org will show "foo" in s3h and connect to
"bar@example.org"
This commit is contained in:
damage 2023-12-17 20:56:55 +01:00
parent 53212b705a
commit 0c1c0d4788
2 changed files with 15 additions and 3 deletions

18
s3h.sh
View File

@ -47,7 +47,13 @@ while [[ -z "$configFile" ]]; do
# add file selectors
files=`find $dir -mindepth 1 -maxdepth 1 ! -name '.*' -type f -printf "%f\n" |sort`
for d in $files; do
para+=("$d" "$d")
# text before ~ is tag
if [[ "$d" == *"~"* ]]; then
tag="${d%%~*}"
para+=("$d" "$tag")
else
para+=("$d" "$d")
fi
done
if [[ ${#para[@]} -eq 0 ]]; then
@ -97,7 +103,13 @@ if [[ -f "$configFile" ]]; then
# clear screen // remove dialog colors
echo "config file '$configFile' selected. connecting..."
# extract user@host if ~ in config file name
login=`basename "$configFile"`
if [[ "$login" == *"~"* ]]; then
login="${login#*~}"
fi
# execute ssh
echo "Running 'ssh ${para[@]} `basename \"$configFile\"`'"
ssh ${para[@]} `basename "$configFile"`
echo "Running 'ssh ${para[@]} $login'"
ssh ${para[@]} "$login"
fi

View File