Tools Link to heading
These are the tools I can’t live without. I use them everyday and they are fantastic at removing some of the more cumbersome parts of using the shell. I don’t recommend using these tools if you want portability, but if you’re on a workstation that is more or less customized to your tastes, I think all these tools are worth exploring.
Tmux Link to heading
Check Github for more info.
I LOVE tmux. Extremely useful, customizable, and just plain badass.
Tmux’s most basic functionality is similar to screen
, it multiplexes multiple terminals into a server that you, as a user, then interfaces into. Having the terminals run in tmux means that since tmux “owns” them, they don’t exit when you exit the terminal. This means you can leave things running and don’t have to keep the terminal open or a ssh session alive to keep something running.
🟢 I use this feature all the time for leaving servers running, leaving sessions alive for development, and shoddy ssh connections.
Tmux adds a few more features on top of screen
that make it shine. Screen can only show one window, but tmux can split a single terminal into multiple panes, each with it’s own instance, running it’s own program:
Out-of-the-box the box the experience is very cumbersome (IMHO), but the next thing that makes tmux great is how customizable it is. I may get into my personal config file, but that’s a rabbit hole itself. These are some highlights tho:
- Binding the tmux prefix to
ctrl+a
, I just can’t do the defaultctrl+b
and when I started I was already used toctrl+a
from screen:
set-option -g prefix C-a
- Binding navigation to
ctrl+h/j/k/l
, navigate panes in tmux, matching my emacs config as well when running emacs in tmux:
bind -n C-h run tmux select-pane -L" bind -n C-j run tmux select-pane -D" bind -n C-k run tmux select-pane -U" bind -n C-l run tmux select-pane -R"
- Setting my windows to start at 1 and count up. Easier than starting at 0 for a keyboard mnemonic pattern. Since you’re going 1-9 for windows it matches with the keys quite well:
set-option -g base-index 1 set-window-option -g pane-base-index 1
- Renumber windows when you delete them, long sessions with random window numbers everywhere can be a hassle:
set-option -g renumber-windows on
There’s a lot more customization in the config as well, but I don’t want to go into that now. You can customize a lot of things with tmux to make it work for you. With all this customization you might find yourself forgetting key-combos. The last cool tmux feature I want to mention is that if you do <prefix> ?
(so ctrl+b ?
on default config), you can get a list of every shortcut. I use tmux in just about every terminal, shit rocks.
If you want to see my configs, check it.
fzf Link to heading
The Github is filled with far more information. I only go over a very small (but useful) subsection of fzf
’s capability here.
fzf, the command-line fuzzy finder is one of the most versatile tools for decreasing cognitive load. It uses “fuzzy” logic to help you sort and search through a long list of text. In short, “fuzzy” logic means that when searching for a word you don’t need to be precise. Instead, it will show exact matches first, then show similar matches with decreasing similarities. How is this helpful, exactly? The github page shows how robust and useful it is, but it is more for an advanced user. For beginners, if you select “yes” for options when setting up fzf’s default installation, it will automatically setup two extremely important shortcuts to remove a fair amount of work when interacting with the command-line.
- Better
history
:
On most shells, by default you can look at what commands you have run by running
history
in the terminal. There is also a built-in way to search and run previous commands by hitting the key combo,ctrl+r
. By default, this reverse search just… sucks. Not because it actually sucks, it’s just that once you do the samectrl+r
key combo after installingfzf
, you get a much better interface. You can now see a list of commands that kinda match your search. So let’s say you log back onto your computer after a few days, you were running a command that you didn’t put in a script, and it’s a loooong command with a specific file path. You don’t know what the heck the command was called, just that it had read from a file in/tmp/readthis
. You couldhistory | grep -i '/tmp/readthis'
, but you don’t see it. So you start hitting the up arrow until you see it, but you don’t know about 100 commands were ran in-between the other command and now. Anyone who has used the command-line for just about anything serious has been here, and has learned through pain and hardship how to perform those set of steps to maybe get the command again. Withfzf
though, it’s trivial. Just do,ctrl+r
and type the one part you kinda remember, (the file/tmp/readthis
). Now, any search term that has similar matches will pop up and presto! There it is.
- Quick file finding:
When installing fzf, on top of setting up
ctrl+r
for looking through history. It also sets up the key-comboctrl-t
to show an interactive list of files from your current directory downward. I find this to be a lot easier than using the usualfind
command and remembering EXACT filename.
- Extremely customizable:
Fzf also works great in the shell ecosystem. Any list of items, you can just pipe into fzf. The most simple thing to try is just
ls | fzf
. You can get an idea of how powerful the tool is to make selecting text with far less cognitive load.
🟡 Tip: I like having ctrl+h/j/k/l
both move around tmux windows, but also navigate fzf
prompts. You can add this to you ~/.tmux.conf
to allow both. I set the variable is_vim_emacs
to work with instances of nvim
, vim
, and emacs
in the terminal (sorry, no vi instances).
is_vim_emacs='echo "#{pane_current_command}" | \ grep -iqE "((^|\/)g?(view|n?vim?x?)(diff)?$)|emacs"' is_fzf="ps -o state= -o comm= -t '#{pane_tty}' \ | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?fzf$'" bind -n C-h run "($is_vim_emacs && tmux send-keys C-h) || \ tmux select-pane -L" bind -n C-j run "($is_vim_emacs && tmux send-keys C-j) || \ ($is_fzf && tmux send-keys C-j) || \ tmux select-pane -D" bind -n C-k run "($is_vim_emacs && tmux send-keys C-k) || \ ($is_fzf && tmux send-keys C-k) || \ tmux select-pane -U" bind -n C-l run "($is_vim_emacs && tmux send-keys C-l) || \ tmux select-pane -R"
Ripgrep Link to heading
Check Github for more info.
I use the grep
replacement tool ripgrep
all the time on workstations. Admittedly less important than tmux
and fzf
for me (there’s not more features than grep
, just better). Ripgrep does 5 things that justify it’s use for me:
- Is far faster than grep.
- Has default filtering, respecting
.gitignore
and removing hidden directories and files by default. - Envoked as a recursive text search by default (analogous to
grep -nri
, which is what I use the most). - There are other compatibilities with grep. You can pretty much pass the same parameters as you would for
grep
. - It supports unicode by default.
Basically, if you find yourself running grep -nri
constantly for searching text. Envoking rg
is both slightly faster than filling out the entire grep command, but also is ran way faster than grep can. Since nothing new is really provided, it’s not as crucial as the other tools for me, but it’s available on every OS and nearly every package manager. So if you’re not looking for portablility then why not?
🟢 ripgrep
and fzf
are used extensively in many emacs/vim plugins. They are well supported and fill the niche of quick and simple terminal tools required to be that dork ass developer who stresses over keystrokes.
BONUS Using the history command Link to heading
The history
command is available on every shell. You type history
and you get a numbered list of every command you have ran (since the history was reset). While you can use the arrow keys to go through recent history, sometimes it is easier to history | grep "something"
or let fzf
handle searching for you. It’s a powerful tool, but I often see one of it’s biggest features is never used by many developers, Event Designators and Word Designators. You can find more info in the manual man history
; but I want to go over how I use it daily.
sudo
your previous command.
We’ve all done it. Getting a permission error on a command that you forgot to
sudo
to run as root. Don’t bother hitting the up arrow to get the previous command and moving the cursor to the beginning and addingsudo
. The previous command event designator (!!) makes this a lot easier.
!!
is a shortcut for your previous command. If you neededsudo
in front of your last command, hit it with asudo !!
.!!
will substitute your last command. You can also put text afterwards if you forgot an argument. Just treat!!
as a variable that expands to whatever your last command is, there’s a lot of creative uses.
- Get previous command arguments.
Maybe you just typed out a loooong ass filepath, but your command has a typo, for example:
la /etc/test/massive/long/filepath/who/made/this/thing/whatever.txt
Here, I intended to use
ls
and notla
. Instead of bringing up the previous command, moving your cursor to the front and changing it. You can use the pattern:!!:1
and it will substitute/etc/test/massive/long/filepath/who/made/this/thing/whatever.txt
in your text. So you could dols !!:1
. Similarly!!:0
would bela
, and etc.# On the next command typing `ls !!:1` will expand to: ls /etc/test/massive/long/filepath/who/made/this/thing/whatever.txt
Going even deeper, lets say you’re last command is
zero one two three four five
. You can have multiple arguments. For example!!:2-4
would substitute astwo three four
in your next command. You can also get up to the nth word. If you did!!:-2
you would getzero one two
.
- Chosing previous commands.
You can also chose the command to modify using some syntax on the event designator.
!!
is only the previous command. But,!-2
would be the command before the previous. Similarlyt!1001
is the 1001 command in the history. You can apply the word designators in the same way. Combining our last example:!-2:2-4
instead of!!:2-4
.
Going deeper, there are equivalents of running sed
on arguments as well as borrowing that ed
syntax. !!:$
is the last word of the previous command and !!:^
is the first word. Just look at the man page at this point. Realistically you’ll only use the first two points ever, especially the first for sudo
.
Summary Link to heading
That’s really it! I find that these tools make my daily fun in the terminal a lot more efficient and takes away the cognative load of typing out and remembering commands all the time. None of these are strictly necessary, and honestly should be avoided if you need portable solutions. However, if you’re in the terminal a lot on your workstation, I find these tools to be invaluable. Take care and enjoy!