Este script mejora la búsqueda en el historial de comandos en Bash, reemplazando la función estándar de Ctrl-R con una interfaz
interactiva y moderna basada en fzf.
This script enhances Bash’s reverse history search by replacing the default Ctrl-R behavior with an interactive, modern
interface powered by fzf.
Ctrl-R Replacement with FZF for Bash
This script enhances Bash’s reverse history search by replacing the default Ctrl-R behavior with an interactive, modern interface powered by fzf.
Features
- Searches your Bash history in reverse order (most recent first).
- Interactive fuzzy search with
fzf. - Selected command is inserted directly into the prompt, editable.
- Works with Bash.
- Detects system language (Spanish or English) and adapts interface texts.
- Clean visual style with borders, colors, and margins.
Requirements
- Bash
fzfinstalled and available in yourPATH.
Installation
- Make sure
fzfis installed. - Add the following function to your
~/.bashrc:
__fzf_historial() {
echo " "
echo -ne "\033[2;H"
local histfile="${HISTFILE:-$HOME/.bash_history}"
[[ ! -f "$histfile" ]] && return
local lang="${LANG:-en}"
local titulo prompt
if [[ "$lang" =~ ^es ]]; then
titulo="Historial de comandos"
prompt="Comando ▶ "
else
titulo="Command history"
prompt="Command ▶ "
fi
local cmd
cmd=$(awk '{ l[NR]=$0 } END { for (i=NR;i>0;i--) print l[i] }' "$histfile" \
| grep -v '^#' | grep -v '^$' \
| fzf \
--height=50% \
--layout=default \
--border=rounded \
--cycle \
--border-label="] $titulo [" \
--preview='echo {}' \
--preview-window=down:0:hidden \
--margin=1,35% \
--color='border:2,label:6:bold,bg+:1,fg+:15:bold,pointer:6:bold,marker:2:bold,prompt:6:bold' \
--pointer='▶ ' \
--marker='▶ ' \
--prompt="$prompt")
[[ -n "$cmd" ]] && READLINE_LINE="$cmd" && READLINE_POINT="${#cmd}"
}
bind -x '"\C-r": __fzf_historial'
- Apply the changes with:
source ~/.bashrc
Usage
Press Ctrl-R in your Bash prompt.
An interactive history menu will appear. Once you choose a command, it will be inserted directly into the prompt so you can edit or run it.
Note
This method does not auto-execute the selected command. It gives you the chance to review and modify it first.
License
This script is free to use and modify. You may share it under the MIT license or similar.
Si a alguien le sirve…
If it helps anyone…
![]()

