Created
August 6, 2013 15:54
-
-
Save ktravis/6165809 to your computer and use it in GitHub Desktop.
A bash function to do the last $1 commands, and combine them in history.
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
#dolast - for the lazy | |
# usage: dolast <n> | |
# where <n> is a positive integer representing the number of commands to repeat. | |
# | |
# example: | |
# $ echo "foo" | |
# foo | |
# $ echo "bar" | |
# bar | |
# $ echo "baz" | |
# baz | |
# $ dolast 3 | |
# foo | |
# bar | |
# baz | |
# $ <Up arrow> | |
# $ echo "foo"; echo "bar"; echo "baz"; | |
dolast () | |
{ | |
let "x = $1 + 1" | |
out="" | |
while [ $x -gt 1 ]; do | |
out=$out"$(fc -l -$x -$x | cut -f 2);" | |
let "x = x - 1" | |
done | |
eval $out | |
history -s $out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment