5

I want to run a function when I start typing in the terminal.

Specifically I want to run the fzf function, for which I currently need to press ctrl-r to trigger it. I would like any keystroke to trigger it so history always appears when I type.

Only the first keystroke should run the function, because running it multiple time toggles between path and filename selection.

1
  • Interesting. Thoughts: bind probably won't work, as I don't think you can meet the "first keystroke only" requirement. A faux command line with a high speed read loop might work. Using the terminal in raw mode or modifying the bash source code are probably the most likely avenues. Also, consider selector instead of fzf. Commented Jun 5, 2015 at 12:38

1 Answer 1

1

I have bound the Up and Down arrow keys to history-search-backward and history-search-forward respectively. So when I type something and then press Up or Down, it does a history search starting with typed letters. This works for me as I don't want to do a history search for every command entered.

I know this isn't exactly what you're looking for, but it's close.

# Bind up and down arrows to do backward and forward history search if [[ $- == *i* ]] then bind '"\e[A": history-search-backward' bind '"\e[B": history-search-forward' fi 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the alternative, but I think I still prefer using ctrl-r to the arrow keys.
Sure. One advantage of this is you can search through history after you've typed few letters. Ctrl-r needs to be fired before typing anything. But yeah, different strokes for different folks.
Unrelated, but I prefer up-line-or-search and down-line-or-search for up and down arrows. This has the additional advantage of "search backward/forward in the history for a line beginning with the first word in the buffer" over the default (very similar to history-search-backward) And I use history-incremental-search-backward and history-incremental-search-forward for C-r and C-s.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.