1

I'd like to configure Bash to run a particular command before running each command line I enter at the prompt. Specifically, I'd like to tell Vim (which is running in another terminal) to write all open buffers, because in my workflow if anything's unsaved when I leave Vim it's a mistake.

Is there an option for this in Bash? If not, is there an option in Zsh?

(There is a readline-based solution that somewhat fits this problem on another question, but it feels a bit hacky. It'll take it as a last resort.)

Peeja
  • 3,009

2 Answers2

2

You might use 'precmd' in zsh for that.

Probably you might want to configure backups in Vim though, because doing such kind of stuff in precmd doesn't sound right to me.

0

I have done similar things using a pseudo-sub-shell using the builtin read as follows:

#!/bin/sh
#public domain fake shell template
while read -p "$PS1" CMD; do
   case "$CMD" in
      *bad_case*|*another_bad_case*)echo bad command: user info logged etc..;;
      *)<your_command_here>
         eval "$CMD";;
   esac
done
technosaurus
  • 1,112