Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

1 Answer 1

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.