-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[UX] Show in readme how to replace bash history search with fzy #179
Comments
There are some examples in the wiki but they're for ZSH. Perhaps as a starting point, you could contribute to the wiki first by adapting how fzf binds to Bash? |
So I found this https://unix.stackexchange.com/a/523619. If I add # Replicate fuzzy file finding
alias fzf='find . -type f | fzy'
# Replicate Ctrl+r history search
alias fzhist="HISTTIMEFORMAT= history | cut -f4- -d' ' | fzy"
bind '"\C-r":" \C-e\C-u\C-y\ey\C-u$(fzhist)\e\C-e\er\e^"' I can get a history search going, but the sorting is "off". We'd need to somehow not only sort by distance of the match but also recency, not sure how to do this. I think that's what they do with the fzf_history command, which I didn't have the time to check. |
I think fzy algorithm is agnostic to input sort order (i.e. recent) unlike fzf. It gives its ordering based on how each match scores. |
Hm, ok the usefulness is then quite limited for history search, since recency is kind of important here. Usually you want the command that happened 10 or 100 calls ago much more likely than 1000 or 10000 calls ago. |
Recently I've also created a simple snippet for Bash history reverse search (lines shown in a reversed order with duplicates removed). Simply add it to bind -x '"\C-r": __history_fuzzy_search'
__history_fuzzy_search() {
READLINE_LINE=$(
HISTTIMEFORMAT=
history | sort -rn \
| awk '{ $1="" ; if (!x[$0]++) print substr($0,2) }' \
| fzy -q "$READLINE_LINE")
READLINE_POINT=0x7FFFFFFF
} |
Trying to do a simple launcher that would use data from '.bash_history' and 'compgen -c', example
but if the match is not found it will force me to select one anyway, any clues how to work around that? (basically I'd like to preserve user input when no matches are found. ) Example recording of unwanted behavior: |
The killer feature that convinced me to use fzf was searching for files (shown in readme), but also ctrl+R bash history search and git branch search.
https://github.com/junegunn/fzf#key-bindings-for-command-line
It would be nice if fzy could provide similar functionality. Or at least point out how to add these in the readme. This might also attract more people.
For fzf you only need this in your ~/.bashrc
The text was updated successfully, but these errors were encountered: