-
Notifications
You must be signed in to change notification settings - Fork 3
/
khxcon
executable file
·67 lines (58 loc) · 1.68 KB
/
khxcon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
#set -x
KHQUITCON=0
KHSSH=khssh
SCREENNAME=""
SETTY=""
CON=""
function usage
{
echo -e \
"\`$(basename $0)' [-N ] [-s <name>] con xtermargs\n" \
"\n" \
" -N \n" \
" -s <name> use screen instead of xterm\n" \
" -t <tty setting> tty settings\n" \
" -h print this usage\n"
}
processargs()
{
local origargs="$@"
local -i optcount=0
while getopts "Ns:t:h" OPT
do
case $OPT in
("N")
output=$(khget $@)
if (( $? == 0 ))
then
read CON <<EOF
$output
EOF
echo "$output"
echo "Connecting to $CON "
else
echo "$output"
exit -1
fi
(( optcount=optcount + 1 ))
;;
("s") SCREENNAME=$OPTARG; (( optcount=optcount + 2 ));;
("t") SETTY="stty $OPTARG;"; (( optcount+=2 ));;
("h") usage; exit -1;;
esac
done
shift $optcount
if [[ -z $CON ]]
then
CON="$1"
xtermargs="$2"
fi
}
processargs "$@"
if [[ -z $SCREENNAME ]]
then
exec xterm $xtermargs -fg orange -bg black -e bash -c "$SETTY echo starting console: $CON connection;$KHSSH $CON; echo console connection terminated; if (( $KHQUITCON == 1)); then echo Quitting in 20 seconds; sleep 20; exit -1; fi; echo Press \<ctl-c\> to close window; read"
else
screen -d -m -S $SCREENNAME bash -c "$SETTY echo starting console: $CON connection;$KHSSH $CON; echo console connection terminated; if (( $KHQUITCON == 1)); then echo Quitting in 20 seconds; sleep 20; exit -1; fi; echo Press \<ctl-c\> to close window; read"
fi