From 3006fe397bc2500d65c85308edff67f751bf4265 Mon Sep 17 00:00:00 2001 From: hcraT Date: Tue, 26 Aug 2014 01:39:38 -0700 Subject: [PATCH] Changed history selection so that acutal selected command will appear in the history instead of "fh". fhe is the same but allows to edit the command before executing it. I'll leave both versions so you can decide which version you want to keep --- Examples.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 ---------