Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Question: Is there an easy way how I can teach zsh to check the command line before executing it? I know that I can completely wrap a specific program with an extra script, but this is not what I want to do.

Example: Using tab completion, it could happen to me easily, that I overwrite my input file by calling gcc wrongly e.g.

gcc test.c -o test.c

instead of

gcc test.c -o test
share|improve this question
up vote 3 down vote accepted

You could redefine the accept-line zle widget to do all the checks you want like:

accept-line() {
  if [[ $BUFFER =~ '^gcc.*-o\s*\S*\.c\b' ]]; then
    zle -M 'I will not do that!'
    zle .$WIDGET "$@"
zle -N accept-line
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.