Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Intercepting commands before they're run



On Apr 13, 12:57pm, Oliver Kiddle wrote:
} Subject: Intercepting commands before they're run
}
} I've just been experimenting with the MH mail system to see if it will
} do what I hope. In mush I can ...

Sigh.  It used to be that most people switched from MH to mush because
mush was so much faster.

} ... just type a message number to see a
} message so I tried to think of a way to persuade zsh to do this.
} 
} preexec() {
}   [[ $1 = <-> ]] && show $1
} }

Try (assuming you have FUNCTION_ARGZERO set):

    preexec() {
      [[ $1 = <-> ]] && function $1 { show $0 ; unfunction $0 }
    }

The more general case is of course

    preexec() {
      setopt localoptions extendedglob
      local cmd
      cmd=($=1)
      case $cmd[1] in
      (<->) function $1 { show $0 ; unfunction $0 };;
      (d(<->[-,])#<->) function $1 { delete ${0#d} ; unfunction $0 };;
      # ... do the whole mush command set ...
      (...#) eval function $1 \{ cd ..${${1#..}:gs@.@/..}\; unfunction $1 \};;
      # ... any other mappings you want go here ...
      (*) ;;
      esac
    }

} [...] maybe we should let preexec return an exit code to say the command
} should not be run [...]

I think I suggested that at one point, but I don't recall whether there
was any discussion.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author