Last active
December 20, 2015 17:08
-
-
Save ktravis/6165999 to your computer and use it in GitHub Desktop.
Fish-do-last is dolast, for fish-shell.
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
# $ echo "kermit" | |
# kermit | |
# $ echo "fozzie bear" | |
# fozzie bear | |
# $ echo "miss piggy" | |
# miss piggy | |
# $ fdl 3 | |
# kermit | |
# fozzie bear | |
# miss piggy | |
# [ fdl ignores calls to itself in history ] | |
# [ up-arrow ] | |
# $ fdl 3 | |
# kermit | |
# fozzie bear | |
# miss piggy | |
function fdl | |
fish-do-last $argv | |
end | |
function fish-do-last | |
set x $argv[1] | |
if not set -q x # repeat one command if no arg | |
set x 1 | |
end | |
for h in (history) | |
if begin echo $h | grep -q "fdl" | |
or echo $h | grep -q "fish-do-last" | |
end # fish, wtf | |
else | |
set x (echo "$x - 1" | bc) | |
set out "$h;$out" | |
end | |
if [ $x -lt 1 ] | |
break | |
end | |
end | |
eval $out | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment