Skip to content

Instantly share code, notes, and snippets.

@ktravis
Created August 6, 2013 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktravis/6165809 to your computer and use it in GitHub Desktop.
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.
#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