开发者

Bookmark Directories In Terminal

Looking for a solution to quickly navigate to long paths in a shell (particularly Max OS X Terminal.app).

Say my path is ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently

Instead of cd ~/This/Is/A/....

I would like to be able开发者_StackOverflow社区 to store favorites/bookmark directories so I could do "cd myPath"

Are there any binaries or tools available to do something like this?


I've found the packages 'Apparix' and 'Goto' which together make the stuff dreams are made of for us terminal junkies.

Naturally, I had trouble installing Apparix, but I figured it out in the end.

How To Install Apparix on Mac OS X:

  1. Download the tarball from Apparix's homepage.
  2. Unpack the tarball, cd to the unpacked folder.
  3. Run this command ./configure --prefix=$HOME/local && make && make install.
  4. Run man apparix, scroll down to the heading BASH-style functions, copy everything within that section (delimited with ---) and paste it into ~/.bash_profile.

That's it. You should now have Apparix up and running on OS X (further install info and usage is on Apparix's homepage).


Another solution is to use Bashmarks, which allows you to this

$ cd ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently
$ s shortname # save current path as `shortname`
$ cd /          
$ g shortname # cd to ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently


You can use aliases (stick them in your ~/.bash_profile if you want them to always load)

alias cd_bmark1='cd ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently'

Then use by just typing

cd_bmark1

into the console


I know you already found an answer that worked for you, but a couple of more lightweight suggestions that might help others looking for similar things

  • If your directories are relatively fixed, just long and far away from each other, you can use the CDPATH environment variable to add directories to the search path when typing the "cd" command. If the directory name you try to cd to isn't in the current directory, the other entries in your CD path will also be looked at (and it's also tab complete aware, at least in bash and zsh).

  • Switching to zsh rather than bash and using the excellent directory stacks abilities. With it, you can maintain a history of directories that you've visited, view the history with the "dh" alias, and easily switch to a directory by using quick shortcuts (ex: cd -3 to switch to the 3rd directory in your history stack).


Why not having a symlink ?

ln -s ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently bmark
cd bmark


I use to.sh daily to create and navigate bookmarked paths in bash. It supports tag autocompletion and the ability to easily add/remove bookmarks.

https://github.com/Grafluxe/to.sh


Full disclosure, I wrote this tool :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜