Quickly switch directories (reprinted) on the command line)

Source: Internet
Author: User

Today, I saw an article on Weibo that uses command line to quickly switch directories, which is much better than my own solution. I have to record and share it.

Every day in the command line, most of the work is input cd ~ /Some/very/deep/often-used/directory:

First, go to my daily work directory and mark a bookmarks mark sanguo.

Cd/Users/kimi/work/123guo/sanguo
Mark sanguo

In the future, I will go to this directory and only need g sanguo.

G sanguo

View all tags by entering the gs command

Gs
# App->/Applications
# Sanguo->/Users/kimi/work/123guo/sanguo
# Web->/Library/WebServer/Documents


The implementation principle is as follows:

Sudo vim/etc/profile


Edit the/etc/profile file, add the following content at the end, and then force save wq!

1 # mark 2 export MARKPATH = $ HOME /. marks 3 export MARKDEFAULT = sanguo # set your default bookmarks, you can directly enter g to jump to 4 5 function g {6 local m = $1 7 if ["$ m" = ""]; then m = $ MARKDEFAULT; fi 8 cd-P "$ MARKPATH/$ m" 2>/dev/null | echo "No such mark: $ m "9} 10 function mark {11 mkdir-p" $ MARKPATH "12 local m = $113 if [" $ m "=" "]; then m = $ MARKDEFAULT; fi14 rm-f "$ MARKPATH/$ m" 15 ln-s "$ (pwd) "" $ MARKPATH/$ m "16} 17 function unmark {18 local m = $119 if [" $ m "=" "]; then m = $ MARKDEFAULT; fi20 rm-I "$ MARKPATH/$ m" 21} 22 function gs {23 ls-l "$ MARKPATH" | grep ^ l | cut-d ''-f 13-24} 25 26 _ completemarks () {27 local curw =$ {COMP_WORDS [COMP_CWORD]} 28 local wordlist =$ (ls-l "$ MARKPATH" | grep ^ l | cut-d ''-f 13) 29 COMPREPLY = ($ (compgen-W' $ {wordlist [@]} '-- "$ curw") 30 return 031} 32 33 complete-F _ completemarks g unmark

The document path cannot be found.Add

Quickly switch directories (reprinted) on the command line)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.