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.
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:
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)