瞬间提升命令行的生产力 100%
命令行
![](/data/attachment/album/201711/12/010750vk5tkm5ipkxxi59v.png)


关于生产力的话题总是让人充满兴趣的。


这里有许多方式提升你的生产力。今天，我共享一些命令行的小技巧，以及让你的人生更轻松的小秘诀。


### TL;DR


在本文中讨论的内容的全部设置及更多的信息，可以查看： <https://github.com/sobolevn/dotfiles> 。


### Shell


使用一个好用的，并且稳定的 shell 对你的命令行生产力是非常关键的。这儿有很多选择，我喜欢 `zsh` 和 `oh-my-zsh`。它是非常神奇的，理由如下：


* 自动补完几乎所有的东西
* 大量的插件
* 确实有用且能定制化的“提示符”


你可以通过下列的步骤去安装它：


1. 安装 `zsh`： <https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH>
2. 安装 `oh-my-zsh`： <http://ohmyz.sh/>
3. 选择对你有用的插件： <https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins>


你也可以调整你的设置以 [关闭自动补完的大小写敏感](https://github.com/sobolevn/dotfiles/blob/master/zshrc#L12) ，或改变你的 [命令行历史的工作方式](https://github.com/sobolevn/dotfiles/blob/master/zshrc#L24)。


就是这样。你将立马获得 +50% 的生产力提升。现在你可以打开足够多的选项卡（tab）了！（LCTT 译注：指多选项卡的命令行窗口）


### 主题


选择主题也很重要，因为你从头到尾都在看它。它必须是有用且漂亮的。我也喜欢简约的主题，因为它不包含一些视觉噪音和没用的信息。


你的主题将为你展示：


* 当前文件夹
* 当前的版本分支
* 当前版本库状态：干净或脏的（LCTT 译注：指是否有未提交版本库的内容）
* 任何的错误返回码（如果有）（LCTT 译注：Linux 命令如果执行错误，会返回错误码）


我也喜欢我的主题可以在新起的一行输入新命令，这样就有足够的空间去阅读和书写命令了。


我个人使用 [`sobole`](https://github.com/sobolevn/sobole-zsh-theme) 主题。它看起来非常棒，它有两种模式。


亮色的：


[![sobole.zsh-theme](/data/attachment/album/201711/12/010801wbcyg01ayi2qjb0m.png)](https://res.cloudinary.com/practicaldev/image/fetch/s--Lz_uthoR--/c_limit,f_auto,fl_progressive,q_auto,w_880/https://raw.githubusercontent.com/sobolevn/sobole-zsh-theme/master/showcases/env-and-user.png)


以及暗色的：


[![sobole.zsh-theme](/data/attachment/album/201711/12/010802eyryor5apmsbt3m6.png)](https://res.cloudinary.com/practicaldev/image/fetch/s--4o6hZwL9--/c_limit,f_auto,fl_progressive,q_auto,w_880/https://raw.githubusercontent.com/sobolevn/sobole-zsh-theme/master/showcases/dark-mode.png)


你得到了另外 +15% 的提升，以及一个看起来很漂亮的主题。


### 语法高亮


对我来说，从我的 shell 中得到足够的可视信息对做出正确的判断是非常重要的。比如 “这个命令有没有拼写错误？” 或者 “这个命令有相应的作用域吗？” 这样的提示。我经常会有拼写错误。


因此， [`zsh-syntax-highlighting`](https://github.com/zsh-users/zsh-syntax-highlighting) 对我是非常有用的。 它有合适的默认值，当然你可以 [改变任何你想要的设置](https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md)。


这个步骤可以带给我们额外的 +5% 的提升。


### 文件处理


我在我的目录中经常遍历许多文件，至少看起来很多。我经常做这些事情：


* 来回导航
* 列出文件和目录
* 显示文件内容


我喜欢去使用 [`z`](https://github.com/rupa/z) 导航到我已经去过的文件夹。这个工具是非常棒的。 它使用“<ruby> 近常 <rt>  frecency </rt></ruby>” 方法来把你输入的 `.dot TAB` 转换成 `~/dev/shell/config/.dotfiles`。真的很不错！


当你显示文件时，你通常要了解如下几个内容：


* 文件名
* 权限
* 所有者
* 这个文件的 git 版本状态
* 修改日期
* 人类可读形式的文件大小


你也或许希望缺省展示隐藏文件。因此，我使用 [`exa`](https://github.com/ogham/exa) 来替代标准的 `ls`。为什么呢？因为它缺省启用了很多的东西：


[![exa](/data/attachment/album/201711/12/010808pz0d222j277770j3.png)](https://res.cloudinary.com/practicaldev/image/fetch/s--n_YCO9Hj--/c_limit,f_auto,fl_progressive,q_auto,w_880/https://raw.githubusercontent.com/ogham/exa/master/screenshots.png)


要显示文件内容，我使用标准的 `cat`，或者，如果我希望看到语法高亮，我使用一个定制的别名：



```
# 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'

```

现在，你已经掌握了导航。它使你的生产力提升 +15% 。


### 搜索


当你在应用程序的源代码中搜索时，你不会想在你的搜索结果中缺省包含像 `node_modules` 或 `bower_components` 这样的文件夹。或者，当你想搜索执行的更快更流畅时。


这里有一个比内置的搜索方式更好的替代： [`the_silver_searcher`](https://github.com/ggreer/the_silver_searcher)。


它是用纯 `C` 写成的，并且使用了很多智能化的逻辑让它工作的更快。


在命令行 `history` 中，使用 `ctrl` + `R` 进行 [反向搜索](https://unix.stackexchange.com/questions/73498/how-to-cycle-through-reverse-i-search-in-bash) 是非常有用的。但是，你有没有发现你自己甚至不能完全记住一个命令呢？如果有一个工具可以模糊搜索而且用户界面更好呢？


这里确实有这样一个工具。它叫做 `fzf`：


![fzf](/data/attachment/album/201711/12/004508bhx4ll28gzzgnyvv.png)


它可以被用于任何模糊查询，而不仅是在命令行历史中，但它需要 [一些配置](https://github.com/sobolevn/dotfiles/blob/master/shell/.external#L19)。


你现在有了一个搜索工具，可以额外提升 +15% 的生产力。


### 延伸阅读


更好地使用命令行： <https://dev.to/sobolevn/using-better-clis-6o8>。


### 总结


通过这些简单的步骤，你可以显著提升你的命令行的生产力 +100% 以上（数字是估计的）。


这里还有其它的工具和技巧，我将在下一篇文章中介绍。


你喜欢阅读软件开发方面的最新趋势吗？在这里订阅我们的愽客吧 <https://medium.com/wemake-services>。




---


via: <https://dev.to/sobolevn/instant-100-command-line-productivity-boost>


作者：[Nikita Sobolev](https://dev.to/sobolevn) 译者：[qhwdw](https://github.com/qhwdw) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
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)
TLDR

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

##
[
](#shell)
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:

- Install
`zsh`

:[https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH](https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH) - Install
`oh-my-zsh`

:[http://ohmyz.sh/](http://ohmyz.sh/) - Choose plugins that might be useful for you:
[https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins](https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins)

You may also want to tweak your settings to [turn off case sensitive autocomplete](https://github.com/sobolevn/dotfiles/blob/master/config/zshrc#L12). Or change how your [history works](https://github.com/sobolevn/dotfiles/blob/master/config/zshrc#L24).

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

##
[
](#theme)
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](https://github.com/sobolevn/sobole-zsh-theme). It looks pretty awesome. It has two modes.

Light:

And dark:

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

##
[
](#syntax-highlighting)
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](https://github.com/zsh-users/zsh-syntax-highlighting) was a big finding for me. It comes with reasonable defaults, but you can

[change anything you want](https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md).

These steps brings us extra +5%.

##
[
](#working-with-files)
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](https://github.com/rupa/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](https://github.com/ogham/exa) as the replacement for standard

`ls`

. Why? Because it has a lot of stuff enabled by default: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)
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](https://github.com/ggreer/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](https://unix.stackexchange.com/questions/73498/how-to-cycle-through-reverse-i-search-in-bash) 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`

:

It can be used to fuzzy-find anything, not just history. But it requires [some configuration](https://github.com/sobolevn/dotfiles/blob/master/shell/.external#L19).

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

##
[
](#further-reading)
Further reading

Using better CLIs: [https://dev.to/sobolevn/using-better-clis-6o8](https://dev.to/sobolevn/using-better-clis-6o8)

##
[
](#conclusion)
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](https://medium.com/wemake-services)

## Top comments (37)

fish shell is even better

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

And what's better with Fish shell?

Thanks!

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

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

A few sample points that I find really useful:

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

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.

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

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

:see_no_evil:

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.

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

;-)

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

Just wanted to comment that..

Fish shell + fzf = pure gold

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.

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 promotionCan't wait to read them!

Thanks for your feedback and interesting articles!

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

+++ Thanks!

Nice coincidence, just installed

`tig`

. And I am already using`ag`

.iterm on mac increase my productivity by 50%

What are the features you use the most?

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.

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

it's mine too...

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

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

I suffer most of the time.

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.

Never heard of exa, but it's awesome.

I definitively adopted Sobole, I love it :)

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.

You shouldn't need the

`--color=automatic`

on exa, it does that automatically anyway+1 for fzf

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

Nope, but it looks nice.

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.

`z`

for navigate doesn't work on my config?Edit: I installed brew install z, but doesn't autocomplete with most folder.

you have to

`cd`

into directory at least once for`z`

to work.I use it and love it too! Great post.

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

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