Typing cd from the command line is a waste of life

Comment: As an engineer, the most common commands you type on the command line are cd and ls. How much time have you wasted over the years?
As a programmer or someone who spends a lot of time in the shell, you may often move back and forth through directories in an inefficient way, especially if the same directory is frequently accessed every day.

For example like this:

https://segmentfault.com/img/bV9eFt?w=677&h=276

Of course, you may be a little more proficient in using it, and using Tab can save a lot of work, like this:

https://segmentfault.com/img/bV9eFv?w=677&h=204

good! You saved about 20 typings, which is commendable. You also use mkdir to create a new directory and go directly to the new directory (cd !$), and you also remember the project's directory, so you don't have to do old ls to find files. But the real problem is that people are not computers. We can remember one or two, but it is impossible to remember all of them. Our efficiency is not high enough.

Have you thought about this way?

https://segmentfault.com/img/bV9eFF?w=668&h=169

Now you only need jd (or j dev, j develop) to jump to the ~/Develop directory, and jp to jump to ~/Develop/project. Efficiency is greatly improved.

Check out the comparison:

https://segmentfault.com/img/bV9eFK?w=680&h=132

How is this achieved?

You can do it with AutoJump. (GitHub address: weighting/autojump)

According to the official introduction, it can browse system files in a faster way, which is not accurate, or very modest. By my full estimate, AutoJump saved me at least 100 hours, at least that much.

How does Autojump work?

Take a look at these two commands:

https://segmentfault.com/img/bV9eF0?w=672&h=73eee92ddf9_hd.jpg

https://segmentfault.com/img/bV9eF6?w=672&h=73

They do the same thing. AutoJump will remember the cd command and use j to enter all directories. More importantly, AutoJump can fuzzy match. It means that only one letter needs to be provided to match the directory of the first letter that has been visited before.

What if there are two directories starting with p?

This is where it gets interesting.

When you enter cd directory_name for the first time, AutoJump records the directory as an absolute path and assigns it a weight of 10.0 points.

for example:

https://segmentfault.com/img/bV9eF9?w=670&h=53

Then enter the j -s command to see (s stands for statistics):

https://segmentfault.com/img/bV9eGb?w=667&h=46

If you cd /var again, j -s and see what happens?

https://segmentfault.com/img/bV9eGm?w=670&h=51

Yes, the weight of this path is increased. For example, if you look at j-s on my computer, you will see at a glance what I usually do:

https://segmentfault.com/img/bV9eGq?w=673&h=363

My first campus and my fourth SodeSchool both contain the letter c, so which directory should AutoJump jump to?

Due to the low weight of campus, jc will jump to the CodeSchool directory. If the jc command is repeated, it will jump to the campus directory.

https://segmentfault.com/img/bV9eGF?w=670&h=123

If you don't like the path that AutoJump sets automatically, you can set the match yourself:

https://segmentfault.com/img/bV9eGQ?w=671&h=222

You can set the following numbers, jc _4 is jc jumps to the fourth directory.

Advanced Features

jc (note that no space is not the above jc) only jumps in subdirectories, which is very suitable for finding nested log
jo will open the matching directory under the operating system.
ji increases the weight
of the current directory jd reduces the weight of the current directory
j--purge removes all weights
Install AutoJump

AutoJump supports:


Supported shells for Python v2.6+ (except 3.2) :
bash v4.0+
zsh
fish
tcsh (experimental)
clink (Windows, experimental)
You can install via many Linux package installers. For MacOS, I recommend Homebrew's brew install autojump, which is really super easy and convenient.

Put Autojump under .bash_profile or .szhrc and enter the command line:

[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
It will automatically check if the script is available and loaded into the shell.

You can also clone the git repository and install it manually. Regardless, it's a very simple, stable tool.

I've never regretted it in the years I've used it.

Download address: wting/autojump (GitHub)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324752836&siteId=291194637