You are not logged in.

#1 2010-11-24 21:46:06

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

custom preexec/precmd in oh-my-zsh

oh-my-zsh users, where do you put your custom preexec/precmd stuff?
If I understand correctly, stuff in lib shouldn't contain user-specific stuff, although lib/termsupport.zsh is where preexec and precmd are defined.
so if we have custom logic, where should we put it? 

here's my current code.  The idea is that many programs (mplayer is one, but I'll add more) warrant an mpc toggle before and after they run (if mpd is running, that is)
my code currently works fine, but it doesn't feel organized well.

22:43:35 dieter@ws .oh-my-zsh dieter ? cat lib/termsupport.zsh                                                                                                                                                                                                                    

(....)
case "$TERM" in
  xterm*|rxvt*)
    preexec () {
        if [[ $1 =~ ^mplayer ]] && mpc 2>/dev/null | grep -q playing
        then
            toggle=1
            mpc toggle
        fi
      print -Pn "\e]0;%n${host} $1\a"  # xterm
    }
    precmd () {
        if [ "$toggle" = 1 ]
        then
            mpc toggle
            toggle=0
        fi
      print -Pn "\e]0;%n${host} %~\a"  # xterm
    }
    ;;
  screen*)
    preexec () {
      local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]}
      echo -ne "\ek$CMD\e\\"
      print -Pn "\e]0;%n${host} $1\a"  # xterm
    }
    precmd () {
      echo -ne "\ekzsh\e\\"
      print -Pn "\e]0;%n${host} %~\a"  # xterm
    }
    ;;
esac

Last edited by Dieter@be (2010-11-24 21:47:08)


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

Board footer

Powered by FluxBB