Last active
February 7, 2025 02:08
-
-
Save brbsix/5e4f18833133b3accac78e333129295b to your computer and use it in GitHub Desktop.
Configure fzf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Configure fzf | |
# Set up fzf tab completion | |
. /usr/share/fzf/completion.bash | |
# Set up fzf key bindings | |
. /usr/share/fzf/key-bindings.bash | |
# Unset vars to prevent them from being appended to multiple times if bash | |
# shells are nested and as a result .bashrc is sourced multiple times | |
unset FZF_ALT_C_OPTS FZF_CTRL_R_OPTS FZF_DEFAULT_OPTS | |
# View full path in preview window (?) | |
export FZF_ALT_C_OPTS="${FZF_ALT_C_OPTS:+$FZF_ALT_C_OPTS }--preview 'echo {}' --preview-window down:5:hidden:wrap --bind '?:toggle-preview'" | |
# View full command in preview window (?) | |
export FZF_CTRL_R_OPTS="${FZF_CTRL_R_OPTS:+$FZF_CTRL_R_OPTS }--preview 'echo {}' --preview-window down:5:hidden:wrap --bind '?:toggle-preview'" | |
# Exact-match rather than fuzzy matching by default (use ' to negate) | |
export FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS:+$FZF_DEFAULT_OPTS }--exact" | |
# Prevent fzf from reducing height to 40% by default | |
export FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS:+$FZF_DEFAULT_OPTS }--no-height" | |
# Directly execute the command (Ctrl-X Ctrl-R) | |
bind "$(bind -s | grep '^"\\C-r"' | sed 's/"/"\\C-x/;s/"$/\\C-m"/')" |
I applied this same idea to the ALT_C binding:
export FZF_ALT_C_OPTS="${FZF_ALT_C_OPTS:+$FZF_ALT_C_OPTS }--preview 'echo {}' --preview-window down:5:hidden:wrap --bind '?:toggle-preview'"
@tiwaria1 Great suggestion, glad you found it helpful. I updated the gist.
This was very helpful thank you! Specially the Ctrl+R binding to highlight the full wrapped line of a command in history search. :)
Agree. This is gold. Cheers!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was very helpful thank you! Specially the Ctrl+R binding to highlight the full wrapped line of a command in history search. :)