]> git.alrj.org Git - zsh.d.git/blob - S61_konsoletabs
Rework the prompt config.
[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=${PWD/#${HOME}/\~}
9         SDIR="${DIR[-28,-1]}"
10         if [[ "$SDIR" != "$DIR" ]]
11         then
12            SDIR="...${DIR[-25,-1]}"
13         else
14            SDIR="$DIR"
15         fi
16         if [ -n "$KONSOLE_DCOP_SESSION" ]
17         then
18           dcop ${KONSOLE_DCOP_SESSION} renameSession "$SDIR"
19         elif [ -n "$KONSOLE_DBUS_SESSION" ]
20         then
21           qdbus ${KONSOLE_DBUS_SERVICE} ${KONSOLE_DBUS_SESSION} setTitle 0 "$SDIR" > /dev/null 2>&1
22           qdbus ${KONSOLE_DBUS_SERVICE} ${KONSOLE_DBUS_SESSION} setTitle 1 "$SDIR" > /dev/null 2>&1
23         fi
24     fi
25 }
26
27 # Change konsole tab to current command
28 konsole-rename-cmd () {
29     if [ -n "$KONSOLE_DCOP_SESSION" -o -n "$KONSOLE_DBUS_SESSION" ]
30     then
31         # We don't need to change tab to "cd xyz" or precmd redefinition
32         # Yes, this is a dirty hack
33         if [[ "$1" != \ cd\ \"* && "$1" != \ precmd* ]]
34         then
35             local TXT
36             TXT="${1[0,33]}"
37             if [[ "$1" != "$TXT" ]]
38             then
39                 TXT="${1[0,30]}..."
40             else
41                 TXT="$1"
42             fi
43             if [ -n "$KONSOLE_DCOP_SESSION" ]
44             then
45               dcop ${KONSOLE_DCOP_SESSION} renameSession "$TXT"
46             elif [ -n "$KONSOLE_DBUS_SESSION" ]
47             then
48               qdbus ${KONSOLE_DBUS_SERVICE} ${KONSOLE_DBUS_SESSION} setTitle 0 "$TXT" > /dev/null 2>&1
49               qdbus ${KONSOLE_DBUS_SERVICE} ${KONSOLE_DBUS_SESSION} setTitle 1 "$TXT" > /dev/null 2>&1
50             fi
51         fi
52     fi
53 }
54
55 precmd_functions+='konsole-rename-path'
56 preexec_functions+='konsole-rename-cmd'
57
58 # On changing directory, when in mc (automatically called).
59 mc_chpwd () {
60     if [ -n "$MC_SID" ]
61     then
62         konsole-rename-path
63     fi
64 }
65