]> git.alrj.org Git - zsh.d.git/blob - S61_konsoletabs
Add alias for tmux reattach
[zsh.d.git] / S61_konsoletabs
1 #! /usr/bin/zsh
2
3 # Change konsole tab to current path
4 konsole-rename-path () {
5     if [ -n "$KONSOLE_DCOP_SESSION" -o -n "$KONSOLE_DBUS_SESSION" ]
6     then
7         local DIR
8         DIR=`print -P "%28<...<%~"`
9         if [ -n "$KONSOLE_DCOP_SESSION" ]
10         then
11           dcop ${KONSOLE_DCOP_SESSION} renameSession "$DIR"
12         elif [ -n "$KONSOLE_DBUS_SESSION" ]
13         then
14           qdbus ${KONSOLE_DBUS_SERVICE} ${KONSOLE_DBUS_SESSION} setTitle 0 "$DIR" > /dev/null 2>&1
15           qdbus ${KONSOLE_DBUS_SERVICE} ${KONSOLE_DBUS_SESSION} setTitle 1 "$DIR" > /dev/null 2>&1
16         fi
17     fi
18 }
19
20 # Change konsole tab to current command
21 konsole-rename-cmd () {
22     if [ -n "$KONSOLE_DCOP_SESSION" -o -n "$KONSOLE_DBUS_SESSION" ]
23     then
24         # We don't need to change tab to "cd xyz" or precmd redefinition
25         # Yes, this is a dirty hack
26         if [[ "$1" != \ cd\ \"* && "$1" != \ precmd* ]]
27         then
28             local CMD
29             CMD=`print -P "%30>...>$1"`
30
31             if [ -n "$KONSOLE_DCOP_SESSION" ]
32             then
33               dcop ${KONSOLE_DCOP_SESSION} renameSession "$CMD"
34             elif [ -n "$KONSOLE_DBUS_SESSION" ]
35             then
36               qdbus ${KONSOLE_DBUS_SERVICE} ${KONSOLE_DBUS_SESSION} setTitle 0 "$CMD" > /dev/null 2>&1
37               qdbus ${KONSOLE_DBUS_SERVICE} ${KONSOLE_DBUS_SESSION} setTitle 1 "$CMD" > /dev/null 2>&1
38             fi
39         fi
40     fi
41 }
42
43 precmd_functions+='konsole-rename-path'
44 preexec_functions+='konsole-rename-cmd'
45
46 # On changing directory, when in mc (automatically called).
47 mc_chpwd () {
48     if [ -n "$MC_SID" ]
49     then
50         konsole-rename-path
51     fi
52 }
53