1

This my snippet alias hst="history 1 -1 | cut -c 8- | uniq | fzf ". when I run hst The output is

$ ~ hst (the output from hst) $ 

This is what I want

$ ~ hst $ (the output from hst) 

Example

$ ~ hst vi .zshrc $ 

should be

$ ~ hst $ vi .zshrc 

How to fix this? (or enhance the script)

3
  • $(hst) or eval $(hst) would just directly execute whatever hst outputs; would skip a step. Commented Jun 20, 2022 at 16:21
  • @frabjous You'd need eval "$(hst)" in general. And you wouldn't get the opportunity to edit. Commented Jun 20, 2022 at 19:06
  • There are several integrations of fzf with zsh that may be more convenient that your home-grown one. I don't cite any specific one because I'm not familiar with any of them. Commented Jun 20, 2022 at 19:07

1 Answer 1

1

To add something to the shell input stack as if it was input by the user, you'd use print -z:

hst() { local cmd cmd=$(print -rNC1 -- ${(u)history} | fzf --read0 "$@") && print -rz -- $cmd } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.