Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.)

share|improve this question
1  
See: superuser.com/q/175799/46005 –  cYrus Mar 23 '12 at 18:21
    
Are you sure you want to run a command before executing the next one, and not after finishing the previous one? –  Daniel Beck Mar 23 '12 at 18:36
    
Yes, I want to switch from my Vim tmux pane to my Bash pane, run a command, and ensure that all files in Vim have (attempted to) save before the command runs. I'm emulating the common GUI editor behavior of saving when losing focus. –  Peeja Mar 23 '12 at 18:42
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

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.