Computing / /

5 Quick Tips For Instant Productivity Boost On The Terminal

J E Justin Etighe · 4 min. read

If you’re a frequent user macOS or Linux terminal user, you’re likely familiar with the basics already: navigating the file system, creating and deleting files, and running commands. However, there are some simple, yet often overlooked, techniques that can significantly boost your productivity.

1. Command Aliasing

Aliases are basically custom shortcuts for often-used commands.

Setting up aliases

To create an alias, open your shell configuration. Both Bash and Z-Shell use the .bashrc or .zshrc file, respectively. If you’re on a CLI-only environment, you probable edit files with nano or vi, but I’ll use Visual Studio Code in this example, just to show that you can easily use any editor you like.

For Bash:

Open Bash configuration file
code ~/.bashrc

And for Z-Shell:

Open Z-Shell configuration file
code ~/.zshrc

Add aliases for everyday Git commands by placing these at the end of the configuration file:

Aliases for Git commands
alias gs="git status"
alias ga="git add"
alias gc="git commit"
alias gco="git checkout"
alias gb="git branch"
alias gpl="git pull"
alias gps="git push"

Save the file and apply the changes by starting a new terminal session, or apply the updated configuration in the existing terminal by running source ~/.bashrc (for Bash) or source ~/.zshrc (for Z-Shell).

Using aliases

With this setup, you’ll have gs as a shorthand for git status across all terminal sessions, including integrated terminals in IDEs. The other aliases work similarly.

2. Type Faster With Tab Completion

Tab completion is a productivity superpower that speeds up your command-line work. It automatically completes filenames, directories, and even commands. On Linux and macOS, simply type the first few letters of a filename or command and hit the Tab key to auto-complete. If multiple options exist, hit Tab twice to see them all.

Note, however, that tab completion doesn’t behave the same on all operating systems. Also, for enhanced auto-complete, you probably need to introduce plugins like bash-completion. For simplicity, I’ll leave it at the basic tab completion that comes out of the box.

3. Master Your Command History

Your command history is a treasure trove of past actions. Instead of retyping commands, tap into this goldmine:

Access history

On Linux and macOS, use the history command to view a list of your past commands.

Reuse commands

Reuse previous commands by typing ! followed by the command number (e.g., !24). You can also use the !! command to reuse the last command.

Use the arrow keys to move up and down in your command history. The up arrow lets you revisit previous commands, while the down arrow moves you forward.

4. Navigate and search with Fuzzy Finder (fzf)

Fuzzy finder, or fzf, is a powerful tool for quick file and command searches. It offers components like the fzf executable, fzf-tmux script, shell extensions, and Vim/Neovim plugin. You can install only the fzf executable if you don’t need the extra components.

Install via Homebrew

# Install fuzzy finder
brew install fzf

# Install useful key bindings and fuzzy completion:
$(brew --prefix)/opt/fzf/install

Install via Git

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

For a guide to install via other package managers, and more installation options, check out the fzf GitHub repository.

Everyday usage

  • CTRL-R to search command history.
  • Use CTRL-K / CTRL-J (or CTRL-P / CTRL-N) to move cursor up and down. Arrow keys work too.
  • Hit Enter key to select an item or CTRL-C / CTRL-G / ESC to exit.

5. Exit Hanging/Broken SSH Sessions

When an SSH terminal hangs (usually due to network issues), it becomes impossible to exit gracefully. Instead of killing the terminal process, you can always use the “tilde escape” sequence:

Press Enter, followed by ~ (tilde), then . (period).

This ~. signals the SSH client to terminate the session immediately, even in the presence of network problems. As a result, responsiveness is promptly restored to your terminal.

Bonus: Save A Few More Keystrokes

Z-shell, with AUTO_CD enabled (which is usually the default), allows you to omit cd navigating the file system. You can simply type the path to the directory you want to navigate to. For example, instead of cd ~/Documents, you can simply type ~/Documents and hit Enter. It also works for relative paths, such as ../Documents and just .. (going one level up, to the parent directory).

By incorporating tips like use of command aliases and quick command history navigation into your daily use of the command prompt, you can ramp up your productivity. Tools like tab completion and fzf only add to this efficiency, while knowing how to exit stalled SSH sessions keeps your workflow unhampered.

Author
Justin Etighe

Spawn of Human<T>, where T varies by the hour. Passively logging knowledge and experiences.