DEV Community

Nikita Sobolev
Nikita Sobolev

Posted on • Updated on

Instant +100% command line productivity boost

Being productive is fun.

There are a lot of fields to improve your productivity. Today I am going to share some command line tips and tricks to make your life easier.

TLDR

My full setup includes all the stuff discussed in this article and even more. Check it out: https://github.com/sobolevn/dotfiles

Shell

Using a good, helping, and the stable shell is the key to your command line productivity. While there are many choices, I prefer zsh coupled with oh-my-zsh. It is amazing for several reasons:

  • Autocomplete nearly everything
  • Tons of plugins
  • Really helping and customizable PROMPT

You can follow these steps to install this setup:

  1. Install zsh: https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH
  2. Install oh-my-zsh: http://ohmyz.sh/
  3. Choose plugins that might be useful for you: https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins

You may also want to tweak your settings to turn off case sensitive autocomplete. Or change how your history works.

That's it. You will gain instant +50% productivity. Now hit tab as much as you can!

Theme

Choosing theme is quite important as well since you see it all the time. It has to be functional and pretty. I also prefer minimalistic themes, since it does not contain a lot of visual noise and unused information.

Your theme should show you:

  • current folder
  • current branch
  • current repository status: clean or dirty
  • error codes if any

I also prefer my theme to have new commands on a new line, so there is enough space to read and write it.

I personally use sobole. It looks pretty awesome. It has two modes.

Light:

sobole.zsh-theme

And dark:

sobole.zsh-theme

Get your another +15% boost. And an awesome-looking theme.

Syntax highlighting

For me, it is very important to have enough visual information from my shell to make right decisions. Like "does this command have any typos in its name" or "do I have paired scopes in this command"? And I really make tpyos all the time.

So, zsh-syntax-highlighting was a big finding for me. It comes with reasonable defaults, but you can change anything you want.

These steps brings us extra +5%.

Working with files

I travel inside my directories a lot. Like a lot. And I do all the things there:

  • navigating back and forwards
  • listing files and directories
  • printing files' contents

I prefer to use z to navigate to the folders I have already been to. This tool is awesome. It uses 'frecency' method to turn your .dot TAB into ~/dev/shell/config/.dotfiles. Really nice!

When printing files you want usually to know several things:

  • file names
  • permissions
  • owner
  • git status of the file
  • modified date
  • size in human readable form

You also probably what to show hidden files to show up by default as well. So, I use exa as the replacement for standard ls. Why? Because it has a lot of stuff enabled by default:

exa

To print the file contents I use standard cat or if I want to see to proper syntax highlighting I use a custom alias:

# exa:
alias la="exa -abghl --git --color=automatic"

# `cat` with beautiful colors. requires: pip install -U Pygments
alias c='pygmentize -O style=borland -f console256 -g'

Now you have mastered the navigation. Get your +15% productivity boost.

Searching

When searching in a source code of your applications you don't want to include folders like node_modules or bower_components into your results by default. You also want your search to be fast and smooth.

Here's a good replacement for the built in search methods: the_silver_searcher.

It is written in pure C and uses a lot of smart logic to work fast.

Using ctrl + R for reverse search in history is very useful. But have you ever found yourself in a situation when I can quite remember a command? What if there were a tool that makes this search even greater enabling fuzzy searching and a nice UI?

There is such a tool, actually. It is called fzf:

fzf

It can be used to fuzzy-find anything, not just history. But it requires some configuration.

You are now a search ninja with +15% productivity bonus.

Further reading

Using better CLIs: https://dev.to/sobolevn/using-better-clis-6o8

Conclusion

Following these simple steps, you can dramatically increase your command line productivity, like +100% (numbers are approximate).

There are other tools and hacks I will cover in the next articles.

Do you like reading about the latest trends in software development? Subscribe to our blog on Medium: https://medium.com/wemake-services

Top comments (37)

Collapse
 
paveltrufi profile image
Pavel Razgovorov

fish shell is even better

Collapse
 
mariosant profile image
Marios Antonoudiou

I was about to say that! So much better indeed!

Collapse
 
xavierartot profile image
Xavier Artot • Edited

And what's better with Fish shell?
Thanks!

EDIT: I gave a shot and I love the real autocompletion without plugin :)

Thread Thread
 
mariosant profile image
Marios Antonoudiou

It provides a great experience, right out of the box!

A few sample points that I find really useful:

  • Very nice history search. Type a word and hit up arrow on your keyboard.
  • fish_config - Try executing this :)
  • I prefer the way things are configured. This is a directory inside your ~/.config.
  • Syntax highlighting, colors etc.

Now if you are into scripting, you might find it a bit easier to write your own autocompletion, it did for me for sure ;)

Thread Thread
 
paveltrufi profile image
Pavel Razgovorov

Another thing I use the most is the reverse-i-search, but, instead of typing Ctrl+R and the text I want to search, I just type it and use the arrow keys. The shell looks in the history but matching my query, and the visual result looks much more intuitive :D

And that's just one feature (appart for, for example, the "bobthefish" theme, a must have for using git) out of a large list.

Thread Thread
 
xavierartot profile image
Xavier Artot • Edited

As a vim user I hate the arrow key, I lost some productivity when I moved from the row.

Thread Thread
 
jospoortvliet profile image
Jos Poortvliet

It might be total anathema but... type + arrow keys to search is what I use in bash ;-)

:see_no_evil:

Thread Thread
 
paveltrufi profile image
Pavel Razgovorov

But I think it doesn't work the same way:

In bash, when you use reverse-i-search, you first press Ctrl+R and then you start typing the command you was looking for. While you type, the command is appearing in console. To look for previous commands that also match your query, you press Ctrl+R as many times as you will need in order to you find your command.

In Fish Shell, you just type as you would do in bash when you're in reverse-i-search, and then use the arrow keys to go to the previous commands (you can go back to the following ones of the current you have selected by pressing the down-arrow key, I don't know if that exists in bash). Plus, the query you typed will be highlighted in the current command.

Thread Thread
 
jospoortvliet profile image
Jos Poortvliet

It does work that way - I type, hit arrow-up to cycle through previous times I typed that command. No ctrl-R required.

You put in your .inputrc:

arrow up

"\e[A":history-search-backward

arrow down

"\e[B":history-search-forward

;-)

Thread Thread
 
paveltrufi profile image
Pavel Razgovorov

Wow, I'll try this when I arrive home just for the curiosity xD

Collapse
 
akrasic profile image
akrasic

Just wanted to comment that..
Fish shell + fzf = pure gold

Collapse
 
lardissone profile image
Leandro Ardissone

I like fish but I had problems with NVM and to get it working on CD into a dir with a .nvmrc file. It was like one year ago, so probably it's fixed now.

Collapse
 
dmerejkowsky profile image
Dimitri Merejkowsky

Nice article! We have similar setups, so I though you might want to know more about mine:

Personally, I use zsh-pure-prompt.

I also use fzf a lot, and I even re-wrote z using fzf

More info on my blog, you may find this interesting:

Lastly, I recently added a bit of code that allow me to quiclky insert the most recent file in the given directory into the current command line:
latest.zsh

end of self promotion

There are other tools and hacks I will cover in the next articles.

Can't wait to read them!

Collapse
 
sobolevn profile image
Nikita Sobolev

Thanks for your feedback and interesting articles!

Collapse
 
yoannfleurydev profile image
Yoann Fleury

We have quite a similar setup. You should give a try to software like tig, ag, ranger or fpp.

Collapse
 
sobolevn profile image
Nikita Sobolev

+++ Thanks!

Nice coincidence, just installed tig. And I am already using ag.

Collapse
 
jandedobbeleer profile image
Jan De Dobbeleer

Add powerlevel9k and we've almost got the same setup. Didn't know about fzf, I'm going to add that right away. 👍🏻

Collapse
 
d53dave profile image
Dave

Never heard of exa, but it's awesome.

Collapse
 
curusarn profile image
Šimon Let • Edited

How do you use machines that don't have all your new fancy commands? Eg. when you ssh to different server?

Collapse
 
sobolevn profile image
Nikita Sobolev

I suffer most of the time.

Collapse
 
scheidig profile image
Albrecht Scheidig

I recommend to (semi)automate a way to prepare a new box to suit your needs.
I use developer.atlassian.com/blog/2016/... for this and can tweek a new box within 15 minutes.

Collapse
 
xavierartot profile image
Xavier Artot

iterm on mac increase my productivity by 50%

Collapse
 
sobolevn profile image
Nikita Sobolev

What are the features you use the most?

Collapse
 
xavierartot profile image
Xavier Artot • Edited

To switch between Iterm and Chrome, hotkey: maj + space

Tmux integration is native and I'm working with Vim, then the preference / appareance / Tabs are very nice too.

I think I'm pretty good, but I always look for more idea.

Collapse
 
dsuurlant profile image
Daniëlle Suurlant

You can combine iTerm2 with Oh-my-Zsh! That's my current setup.

Collapse
 
xavierartot profile image
Xavier Artot

it's mine too...

Collapse
 
greyhoundforty profile image
Ryan Tiffany

Prezto over oh-my-zsh every time. Same idea but much more lightweight. And if you want to also trick out vim, git and zsh look at Yadr which uses Prezto.

Collapse
 
ogham profile image
Benjamin Sago

You shouldn't need the --color=automatic on exa, it does that automatically anyway

+1 for fzf

Collapse
 
xavierartot profile image
Xavier Artot

I definitively adopted Sobole, I love it :)

Collapse
 
fedejsoren profile image
Federico Sörenson

I have been using powerline shell on my Linux for the nice help working with git. Have you tried it? :D

Collapse
 
kunde21 profile image
Chad Kunde

I like powerline, but got annoyed by the slow speed. Thankfully, a kind soul ported it over to powerline-go and gave us the speed back.

Collapse
 
sobolevn profile image
Nikita Sobolev

Nope, but it looks nice.

Collapse
 
xavierartot profile image
Xavier Artot • Edited

z for navigate doesn't work on my config?

Edit: I installed brew install z, but doesn't autocomplete with most folder.

Collapse
 
sobolevn profile image
Nikita Sobolev

you have to cd into directory at least once for z to work.

Collapse
 
hanqin profile image
Han

Oh, don't forget github.com/nvbn/thefuck it's awesome :D

Collapse
 
jandedobbeleer profile image
Jan De Dobbeleer

Like it? I love it! Going to add my config 😉

Collapse
 
letsbsocial1 profile image
Maria Campbell

I use it and love it too! Great post.