-
Notifications
You must be signed in to change notification settings - Fork 11
/
konsole_fork_ssh
executable file
·43 lines (35 loc) · 1.24 KB
/
konsole_fork_ssh
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
#!/bin/bash
help() {
echo 'usage: konsole_fork_ssh'
echo ' konsole_fork_ssh --help'
echo
echo ' Fork a konsole tab that is running a ssh session.'
echo
echo ' The idea is to bind this program to a key-combination'
echo ' and press the respectiv key while working inside konsole.'
echo
echo ' When the currently active tab is running a ssh session,'
echo ' konsole will open a new Tab and execute ssh to the same host.'
echo
exit 1
}
[ "$1" == "--help" ] && help
# debug:
#set -x
#exec > /tmp/foo.log 2>&1
KONSOLE_DBUS_SESSION=/Sessions/35
KONSOLE_DBUS_WINDOW=/Windows/2
shell_pid=$( qdbus org.kde.konsole $KONSOLE_DBUS_SESSION org.kde.konsole.Session.processId )
child_pid=$( pgrep -P $shell_pid )
# check if we indeed a child of the shell was found
#
if [ "$child_pid" ]; then
child_commandline=$( ps --pid $child_pid -o "%a" h )
# restrict forking to ssh commands
#
command=$( echo "$child_commandline" | sed 's/ .*//' )
if [ "$command" == "ssh" ]; then
new_konsole_session=$( qdbus org.kde.konsole $KONSOLE_DBUS_WINDOW org.kde.konsole.Window.newSession )
qdbus org.kde.konsole /Sessions/$new_konsole_session org.kde.konsole.Session.runCommand "$child_commandline"
fi
fi