Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
367128ffab | |||
921efeb8d2 | |||
d7100267ce | |||
4c08363b7f | |||
d975e38ef3 | |||
a3c476ca20 | |||
db7f539bd1 | |||
0c1c0d4788 | |||
53212b705a | |||
453a453f4f | |||
31b5e29c69 | |||
8b10b4b709 |
@ -2,10 +2,15 @@
|
||||
|
||||
|
||||
NAME=s3h
|
||||
VERSION=1.2
|
||||
VERSION=`../../s3h.sh -v`
|
||||
REVISION=1
|
||||
ARCH=all
|
||||
|
||||
if ! git tag -l |fgrep $VERSION; then
|
||||
git tag $VERSION
|
||||
git push origin $VERSION
|
||||
fi
|
||||
|
||||
curdir=`dirname $0`
|
||||
workdir="$curdir/${NAME}_${VERSION}-${REVISION}_${ARCH}"
|
||||
mkdir -p "$workdir"
|
||||
|
54
s3h.sh
54
s3h.sh
@ -2,8 +2,8 @@
|
||||
|
||||
# config
|
||||
DIALOG=dialog #gdialog kdialog
|
||||
START_DIR='~/.s3h'
|
||||
VERSION="1.3"
|
||||
START_DIR="$HOME/.s3h"
|
||||
VERSION="1.8"
|
||||
|
||||
# TODO: use opt parsing
|
||||
if [[ $# -eq 1 && "$1" == "-v" ]]; then
|
||||
@ -15,6 +15,8 @@ if [[ $# -eq 1 && -d "$1" ]]; then
|
||||
START_DIR="$1"
|
||||
fi
|
||||
|
||||
START_DIR=$(realpath "$START_DIR")
|
||||
|
||||
if [[ ! -d "$START_DIR" ]]; then
|
||||
echo "start directory '$START_DIR' does not exist" >&2
|
||||
echo -e "either create or set 'start directory' parameter\n" >&2
|
||||
@ -22,6 +24,19 @@ if [[ ! -d "$START_DIR" ]]; then
|
||||
exit 2
|
||||
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
|
||||
configFile=''
|
||||
while [[ -z "$configFile" ]]; do
|
||||
@ -30,6 +45,10 @@ while [[ -z "$configFile" ]]; do
|
||||
dir="$START_DIR"
|
||||
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
|
||||
if [[ "$START_DIR" == "$dir" ]]; then
|
||||
para=()
|
||||
@ -38,14 +57,20 @@ while [[ -z "$configFile" ]]; do
|
||||
fi
|
||||
|
||||
# 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
|
||||
para+=("$d" "<$d>")
|
||||
done
|
||||
# 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
|
||||
# text before ~ is tag
|
||||
if [[ "$d" == *"~"* ]]; then
|
||||
tag="${d%%~*}"
|
||||
para+=("$d" "$tag")
|
||||
else
|
||||
para+=("$d" "$d")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#para[@]} -eq 0 ]]; then
|
||||
@ -57,8 +82,13 @@ while [[ -z "$configFile" ]]; do
|
||||
fi
|
||||
|
||||
# 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
|
||||
clear
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -71,7 +101,7 @@ while [[ -z "$configFile" ]]; do
|
||||
configFile=$ret
|
||||
fi
|
||||
else
|
||||
dir=`dirname "$dir"`
|
||||
dir=$(dirname "$dir")
|
||||
fi
|
||||
done
|
||||
|
||||
@ -95,6 +125,16 @@ if [[ -f "$configFile" ]]; then
|
||||
# clear screen // remove dialog colors
|
||||
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
|
||||
login=$(basename "$configFile")
|
||||
if [[ "$login" == *"~"* ]]; then
|
||||
login="${login#*~}"
|
||||
fi
|
||||
|
||||
# execute ssh
|
||||
ssh ${para[@]} `basename "$configFile"`
|
||||
echo "Running 'ssh ${para[@]} $login'"
|
||||
ssh ${para[@]} "$login"
|
||||
fi
|
||||
|
0
test/blah~foobar@devloop.de
Normal file
0
test/blah~foobar@devloop.de
Normal file
Reference in New Issue
Block a user