]> git.alrj.org Git - zsh.d.git/blob - S61_konsoletabs
Use emacs bindings
[zsh.d.git] / S61_konsoletabs
1 #! /usr/binn/zsh
2
3 # Change konsole tab to current path
4 konsole-rename-path () {
5     if [ "$KONSOLE_DCOP_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         dcop ${KONSOLE_DCOP_SESSION} renameSession "$SDIR"
17     fi
18 }
19
20 # Change konsole tab to current command
21 konsole-rename-cmd () {
22     if [ "$KONSOLE_DCOP_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 TXT
29             TXT="${1[0,33]}"
30             if [[ "$1" != "$TXT" ]]
31             then
32                 TXT="${1[0,30]}..."
33             else
34                 TXT="$1"
35             fi
36             dcop ${KONSOLE_DCOP_SESSION} renameSession "$TXT"
37         fi
38     fi
39 }
40
41 precmd_functions+='konsole-rename-path'
42 preexec_functions+='konsole-rename-cmd'
43
44 # On changing directory, when in mc (automatically called).
45 mc_chpwd () {
46     if [ -n "$MC_SID" ]
47     then
48         konsole-rename-path
49     fi
50 }
51