If you master your Terminal it always looks like you are a superhero. Therefore, I always try to present a lot using terminal during my lecture, just to provide some smoke and mirrors.
However, I am far away from mastering Terminal truly. Therefore, it comes in handy that one of my students pointed me to reverse-i-search which is available on Terminal.
To search through similar typed commands, you can use fzf, a command-line fuzzy finder available at GitHub.
It’s an interactive Unix filter for command-line that can be used with any list; files, command history, processes, hostnames, bookmarks, git commits, etc.
Installing on macOS using Homebrew
For your convenience you can install fzf using Homebrew using the command
brew install fzf
For me, the bash integration was not available after the installation. After some investigation (I might haven’t read the instruction well enough), I realized the installation script needs to be run:
/usr/local/opt/fzf/install
Eventually, the installation routines put [ -f ~/.fzf.bash ] && source ~/.fzf.bash into .bashrc. I run into this issue
When you open a terminal application, it does not ask for login. You will just get a command prompt. In other versions of Unix or Linux, this will not run
the .bash_profile
but a differentfile .bashrc
. The underlying idea is thatthe .bash_profile
should be run only once when youlogin , andthe .bashrc
for every new interactive shell.However, Terminal.app on
macOS, does not follow this convention. When Terminal.app opens a new window, it willrun .bash_profile
. Not, as users familiar with other Unix systems would expect, .bashrc
.
Moving the line mentioned above into .bash_profile and deleting .bashrc eventually solved the issue. After restarting Terminal the key bindings CTRL-R and CTRL-T have been available as expected.
With this little trick the installations of fzf works quite well on macOS X Mojave.
tl;dr
Use reverse-i-search by pressing control-r on macOS to search previous commands typed in Terminal. In addition, you can use fzf, a command-line fuzzy finder to find similar commands and all other kinds of stuff.
To install run
- brew install fzf
- /usr/local/opt/fzf/install
- copy [ -f ~/.fzf.bash ] && source ~/.fzf.bash from .bashrc into ~/.bash_profile (and remove .bashrc if not needed) or source .basrc from .bash_profile
Andre
andreas