diff --git a/Examples.md b/Examples.md index eb118f8..00c642c 100644 --- a/Examples.md +++ b/Examples.md @@ -75,6 +75,27 @@ fh() { Replacing `eval` with `print -z` will push the arguments onto the editing buffer stack, allowing you to edit the command before running it. It also means the command you run will appear in your history rather than just `fh`. Unfortunately this only works for zsh. +### With write to terminal capabilities + +```sh +# utility function used to write the command in the shell +writecmd() { + perl -e '$TIOCSTI = 0x5412; $l = ; $lc = $ARGV[0] eq "-run" ? "\n" : ""; $l =~ s/\s*$/$lc/; map { ioctl STDOUT, $TIOCSTI, $_; } split "", $l;' -- $1 +} + +# fh - repeat history +fh() { + ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s | sed -re 's/^\s*[0-9]+\s*//' | writecmd -run +} + +# fhe - repeat history edit +fhe() { + ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s | sed -re 's/^\s*[0-9]+\s*//' | writecmd +} +``` + +This have been tested in bash and works. + Processes ---------