Reputation: 4902
I have a script that does a lot, setting up a new development server, pushing source to it, putting sample data on it, synchronizing the name of the server with my current git
branch.
Then, once it's set up, I have an alias that pushes new source code to it.
I run the first command a few times a day. I run the alias all the time. And my muscle memory has me making a change to the source, going to the terminal, pressing the up arrow, and pressing return. 90% of the time, this is exactly what I want.
But, after setting up the server, and then making a change to the code, that muscle memory is betraying me, and I end up starting to spin up a new development server. Yes, I just press Ctrl-C to stop it, but it's still annoying.
Is there any way to prevent the server setup command from being run twice in a row?
Upvotes: 0
Views: 109
Reputation: 665
If you are feeling adventurous, you can rebind your enter key to use this widget
accept-line() {
if [ -z "$BUFFER" ]; then
local prevCommand=$(fc -ln -1)
if [ $prevCommand = "ls" ]; then
# do nothing
else
zle up-history
fi
fi
zle ".accept-line";
}
zle -N accept-line
In zsh how do I bind a keyboard shortcut to run the last command?
Upvotes: 1