So I'm interested in binding the up-arrow key to go to the next unique command in the history, as opposed to the one immediately previous?
For example: I'm in college, coding in java and when debugging I need to compile and recompile the java files several times in terminal before I end up running the file, and so my command-line history might look something like this.
1: javac Hello_World.java
2: java Hello_World
3: javac Hello_World.java
4: javac Hello_World.java
5: javac Hello_World.java
6: javac Hello_World.java
and I currently need to press the up arrow key several times (in this example 4 times) to get back to the command where I just run it.
So is there any way to go back to the next unique command so that I need only press the up-arrow once to skip through the repetitive commands?
There really isn't an effective way to do what you are asking. You would need to run some type of service in the background that constantly scanned the history to know how many prior commands to skip, which would likely be very sluggish. I'd imagine the most effective solution is to get rid of duplicate commands in your ~/.bash_history.
You can add this into your ~/.bash_profile to automatically remove dupe commands:
# clean up history:
export HISTCONTROL=erasedups:ignoreboth
now you should only need to tap ↑ twice to get to your last unique command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With