Jonathan Dumaine
Jonathan Dumaine

Reputation: 5756

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 to store favorites/bookmark directories so I could do "cd myPath"

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

Upvotes: 3

Views: 5615

Answers (6)

Grafluxe
Grafluxe

Reputation: 481

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

Upvotes: 0

Jonathan Dumaine
Jonathan Dumaine

Reputation: 5756

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

Upvotes: 8

Bilal Syed Hussain
Bilal Syed Hussain

Reputation: 9214

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

Upvotes: 7

Ted Naleid
Ted Naleid

Reputation: 26801

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

Upvotes: 1

Jamie Wong
Jamie Wong

Reputation: 18350

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

Upvotes: 4

Nicolas Viennot
Nicolas Viennot

Reputation: 3969

Why not having a symlink ?

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

Upvotes: 0

Related Questions