4

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
3

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!'
  else
    zle .$WIDGET "$@"
  fi
}
zle -N accept-line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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