Hacker News new | comments | show | ask | jobs | submit login
Teleportation on the command line (thecakeisalie.in)
44 points by liquidwax 1347 days ago | hide | past | web | 35 comments | favorite

It looks like no one has posted what, in my opinion, is the most powerful of the "jump" programs: fasd.

My workflow for getting around is just to type "z <fragment of directory name>" and I almost always end up where I want. If I just want to edit a file, not a project, I do vim `f <filename fragment>` and likewise get the file I want typically.

The readme makes it pretty clear how awesome it is and I've stuck with it after using autojump, z, and others.


Second this recommendation. fasd works extremely well, and better than z and autojump for my usage. I use it all the time.

It seems to behave really good, thanks!

lighter (non python) alternative to autojump https://github.com/rupa/z

Since I discovered `z` I haven't typed in cd, except for changing into $HOME quickly.

I also use z

For those who aren't familiar with it, autojump learns directories that you use often. This eliminates the need to add specific bookmarks.

auto jump (or z) is so incredibly useful it should be built into the terminal. changed my life.

Fish[1] sort of has this built in. I explained more in another comment[2].

[1] http://fishshell.com/

[2] https://news.ycombinator.com/item?id=7043719

> Nobody types an entire URL like https://example.com/example-page?input=sample&another-input=.... We bookmark it and give it a keyword like ex or something. From then, we just type ex and hit return to access the website.

I don't wanna sound negative, but just being realistic.

I don't rely on bookmarks primarily. I rely on "most frequently visited gets auto-completed first" and fuzzy search of Chrome Omnibox. If I do bookmark something, it's to indicate to the algorithm "I care about this, make it easier to fuzzy find it later".

But it's a good step in the right direction, good job!

Edit: From the description, it sounds like autojump does something close.

You should try out fish[1], one of the features that makes it great is that it does exactly what the chrome omnibox does, just with commands. It shows what it will complete after you press ^F and it is a lot of times correct.

It also has lots of other features, like tab completion that tells you what the options of commands do. So reading the manpages or typing -h is generally not needed.

If you do try it, also try one of the themes of oh-my-fish[2], most of them have a git thing that lets you know if you have uncommitted stuff and on what branch you are.

[1] http://fishshell.com/

[2] https://github.com/bpinto/oh-my-fish

Why not just use the CDPATH variable in your shell? If the directory is one you go to frequently, add it to CDPATH, then just cd to it.

I'm quite happy with https://github.com/huyng/bashmarks

Also, the built-in pushd and popd commands are enough sometimes.

Also, the built-in pushd and popd commands are enough sometimes.

I came here to say this. A small wrapper around these commands would make for a sufficient script.

Interesting scripts are being posted in the comments, really neat tricks guys.

One thing I'd like to add, if you're like me and don't want to install too much "extra" stuff on your machines: Bash has native commands called pushd and popd[0]. They work as a stack, pushd will push the current directory onto the stack and jump to the new target, then you're free to move around, do whatever you want and then call popd to pop the latest directory from the stack.

I find these very useful, especially if I'm on a machine without additional installed software and just want to do my thing effortlessly.

[0] http://en.wikipedia.org/wiki/Pushd_and_popd

For a one-level undo there's always

  cd -
Passing a single dash as a parameter to cd takes you back to $OLDPWD and each invocation of cd sets OLDPWD to the directory you were in.

I use a similar method, which I based on a previous HN post:


I'm addicted to one/two-letter aliases, and between that and ZSH completion (https://github.com/akerl/dotfiles/blob/master/.completions/_...), the mark functions get me super-simple bookmarks

I also wish people would stop providing "curl this into .bashrc" as the primarily installation method. That's a really bad habit to get into, especially with a file like .bashrc. It's a bit less risky than piping the curl into bash, but still not a great plan.

Nice. This quick and dirty trick has been in my .bashrc forever and I still use it:

    function md(){
        pwd > /tmp/md_tmp

    function gomd(){
        cd `cat /tmp/md_tmp`
so `md` marks the current directory and `gomd`go to the marked directory. Unlike bash builtins like pushd and popd, it uses the file system to store the marked directory so you can pop up a new terminal and just do gomd. (you can't with pushd/popd since the bash processes of the old and the new terminal are not related)

Edit: I see that your script uses links, I'll check this out.

I don't get it. Why not just use aliases?

alias <name>='cd path/to/<name>'

Then you can just type: $ <name>

You can even set up an alias to add a new alias -> alias ea='vim ~/bash/alias'

With zsh, you could just do w/c/p/w/s<TAB>

Some time ago I put my directory changing tools up on GitHub at https://github.com/mattflower/bashcd

In addition to the bookmarking style capabilities other people have already mentioned it also includes integration with the locate database, the mac spotlight/mds database, and the plain old find command. It can switch to a sub directory containing a particular file. It also supports bash completion.

I made a tool a year ago to do the same thing, Metis: https://github.com/srcoley/metis

I like a solution that goes where ever your dotfiles go, instead of having to install a fuzzy search on each system.

Metis will list all of your currently saved Metis aliases as well, just by typing "metis". You can also tell Metis which dotfile you want to save your aliases.

Why not just use a symlink?

    ln -s ~/super/long/nested/directory/name ~/short
If you don't want to dump them in your home directory, just make a directory with a single-letter name for your links:

    ln -s ~/super/long/nested/directory/name ~/l/short

Personally I do something similar. I set up an alias in .zshrc from project names to commands. This allows me to do things like source environments as well.

    alias proj="cd /this/that/foo/projects/myproject/ && source .hsenv/bin/activate"

Well I though it was nice, but the script if quite buggy! works well when cleaned up

Thanks - all of the alternatives look interesting but this one seems to be the shortest of them, and since "mark" installed after a simple cut & paste into my profile, I'll try it out for a while.

This is sort of why I always just put everything in a shell script. Creating a text file with .sh extension is not that difficult, and I almost never use the command line interactively. Plus I use a GUI and just mount folders I need to browse. It boggles the mind how so many people still equate "Linux==Command Line Hacking". I actually had a boss once who said to me: "If you don't use the command line that much why do you use Linux instead of Windows?" You see, in his mind Linux was all about the command line. Yeah maybe in 1990 it was, but nowadays it's a normal OS like any other.

I enjoy posts like this because it brings out timtowtdi: pushd, cdpath, ln and aliases

Does any flavor of this functionality exist for Windows command prompt?

Windows makes this a little easier than bash does.

batch scripts in windows behave like scripts on unix do when you source them. That means that you can write a batch script called "foo.bat" with the contents of "cd \whatever\directory\you\please" and it will change your current directory when run.

From there, it would not be difficult to write a batch script that in turn wrote batch scripts like "foo.bat" above.

With bash, you would have to create functions or aliases to get the same effect.

Did anybody try the script in ZSH?

zsh has this feature built in. Look up named directories.

Tab works for me.

Applications are open for YC Winter 2018

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact