15 Commits
1.2 ... 1.8

Author SHA1 Message Date
367128ffab s3h.sh aktualisiert 2024-09-27 21:44:36 +02:00
921efeb8d2 added relative path into title of dialog 2024-07-13 20:21:33 +02:00
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
a3c476ca20 clear screen on cancel 2024-04-28 21:42:52 +02:00
db7f539bd1 version bump 2023-12-17 20:58:13 +01:00
0c1c0d4788 set custom text by using ~ (tilde) in filename
foo~bar@example.org will show "foo" in s3h and connect to
"bar@example.org"
2023-12-17 20:56:55 +01:00
53212b705a ~/.s3h might be a symlink 2023-10-09 19:46:27 +02:00
453a453f4f version bump 2023-09-16 22:07:39 +02:00
31b5e29c69 echo ssh command 2023-09-16 22:03:41 +02:00
8b10b4b709 stable build uses s3h.sh version no 2023-09-16 22:01:07 +02:00
aad26d3fdd add version + -v cli parameter 2023-09-16 21:53:58 +02:00
87a453c24c added quickstart instructions 2023-09-08 22:59:28 +02:00
19eef79c2d example global options file 2023-09-03 20:43:17 +02:00
5 changed files with 68 additions and 8 deletions

View File

@ -9,3 +9,10 @@ Select a ssh config file which will be used to connect to a host via - you guess
``` ```
Sample structure of `start directory` can be found in `test`. Sample structure of `start directory` can be found in `test`.
## Quickstart
```
mkdir ~/.s3h
touch root@example.org
./s3h.sh
```

View File

@ -2,10 +2,15 @@
NAME=s3h NAME=s3h
VERSION=1.2 VERSION=`../../s3h.sh -v`
REVISION=1 REVISION=1
ARCH=all ARCH=all
if ! git tag -l |fgrep $VERSION; then
git tag $VERSION
git push origin $VERSION
fi
curdir=`dirname $0` curdir=`dirname $0`
workdir="$curdir/${NAME}_${VERSION}-${REVISION}_${ARCH}" workdir="$curdir/${NAME}_${VERSION}-${REVISION}_${ARCH}"
mkdir -p "$workdir" mkdir -p "$workdir"

61
s3h.sh
View File

@ -2,12 +2,21 @@
# config # config
DIALOG=dialog #gdialog kdialog DIALOG=dialog #gdialog kdialog
START_DIR='~/.s3h' START_DIR="$HOME/.s3h"
VERSION="1.8"
# TODO: use opt parsing
if [[ $# -eq 1 && "$1" == "-v" ]]; then
echo "$VERSION"
exit 0
fi
if [[ $# -eq 1 && -d "$1" ]]; then if [[ $# -eq 1 && -d "$1" ]]; then
START_DIR="$1" START_DIR="$1"
fi fi
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
echo -e "either create or set 'start directory' parameter\n" >&2 echo -e "either create or set 'start directory' parameter\n" >&2
@ -15,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
@ -23,6 +45,10 @@ while [[ -z "$configFile" ]]; do
dir="$START_DIR" dir="$START_DIR"
fi fi
# relative path to START_DIR
# XXX: can be done in bash itself?
relPath=$(echo ${dir} |sed "s;^${START_DIR};;g")
# add parent selector if not already in $START_DIR # add parent selector if not already in $START_DIR
if [[ "$START_DIR" == "$dir" ]]; then if [[ "$START_DIR" == "$dir" ]]; then
para=() para=()
@ -31,14 +57,20 @@ 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
if [[ "$d" == *"~"* ]]; then
tag="${d%%~*}"
para+=("$d" "$tag")
else
para+=("$d" "$d") para+=("$d" "$d")
fi
done done
if [[ ${#para[@]} -eq 0 ]]; then if [[ ${#para[@]} -eq 0 ]]; then
@ -50,8 +82,13 @@ 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" --title "${relPath}" --no-tags --stdout $dialogOptions --menu "select connection" 0 0 0 ${para[@]} 2>&1)
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
clear
exit 1 exit 1
fi fi
@ -64,7 +101,7 @@ while [[ -z "$configFile" ]]; do
configFile=$ret configFile=$ret
fi fi
else else
dir=`dirname "$dir"` dir=$(dirname "$dir")
fi fi
done done
@ -88,6 +125,16 @@ 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..."
# execute ssh # save selected configFile for next call of s3h
ssh ${para[@]} `basename "$configFile"` echo "$configFile" > "$LAST"
# extract user@host if ~ in config file name
login=$(basename "$configFile")
if [[ "$login" == *"~"* ]]; then
login="${login#*~}"
fi
# execute ssh
echo "Running 'ssh ${para[@]} $login'"
ssh ${para[@]} "$login"
fi fi

View File

1
test/foo11/.options Normal file
View File

@ -0,0 +1 @@
-o AddKeysToAgent=yes