To help with remembering bash commands and reducing typing long lines (i.e. a ssh destination), I wrote this short function and binding to save commands within a file and fzf search and send them to the terminal as needed. Comments can be appended to a command to aid in searching for actions that do not match the written command.
- bash
- fzf
Include in your .bashrc
:
# fzf saved commands and filter comments
saved_commands() {
strip_comment="sed 's/#.*$//;/^$/d'"
fzf_saved_commands="tac ~/.saved_commands.txt 2> /dev/null | fzf +m"
eval $fzf_saved_commands | eval $strip_comment
}
bind '"\C-f": "$(saved_commands)\e\C-e\er\e^"'
Make a .saved_commands.txt
file in $HOME
. Here is an example of adding a saved command for extracting tar.gz
files.
echo "tar -zxvf # extract tar.gz files" >> ~/.saved_commands.txt
Open search in termal with ctrl-f
and begin typing command. Hit enter to send command to termal.