Last active
November 3, 2015 12:16
-
-
Save pmaoui/c254a91fdb990348af68 to your computer and use it in GitHub Desktop.
Execute one of your last 5 history commands with one key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# run with: history -a && ./lastc.sh | |
clear | |
echo "Use \"history -a\" before to populate ~/.bash_history with your current history" | |
sleep 2 | |
last5=$(cat ~/.bash_history |tail -n6 |head -n1 |xargs echo -n) | |
last4=$(cat ~/.bash_history |tail -n5 |head -n1 |xargs echo -n) | |
last3=$(cat ~/.bash_history |tail -n4 |head -n1 |xargs echo -n) | |
last2=$(cat ~/.bash_history |tail -n3 |head -n1 |xargs echo -n) | |
last1=$(cat ~/.bash_history |tail -n2 |head -n1 |xargs echo -n) | |
function printCommands { | |
clear | |
for num in 5 4 3 2 1; do | |
varname="last$num" | |
printf " $num - ${!varname}\n" | |
done | |
printf " 0 - Exit\n\n\n" | |
} | |
printCommands | |
while : | |
do | |
read -t 1 -n 1 key | |
if [[ "$key" -gt 0 && "$key" -lt 6 ]]; then | |
printCommands | |
varname="last$key" | |
printf "${!varname}:\n\n" | |
${!varname} | |
fi | |
if [[ $key = 0 ]]; then | |
printf "\n" | |
exit | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment