News for hackers. Stuff that matters.
Re:J: an alternative to cd that learns where you spend time by calambrac on Tuesday February 17, 2009 @06:28PM (#485149)
This is nice.

Kind of but not really in a similar vein: I have 'sd' aliased to a small script that goes to the 'next interesting directory', where an 'interesting directory' is one with a visible non-directory or more than one sub-directory. So, for instance, if you're sitting at foo, and underneath you is bar/baz/bat/bit.txt, 'sd bar' will bring you all the way down to bat, and then 'sd ..' will pull you all the way back up to the previous interesting directory.

Just to keep from getting lost, it does a pwd when it gets where it's going, and because typing ls after cd had burned itself into my muscle memory, it goes ahead and does that, too.

It's a small thing, but I really like it for hopping around source trees in languages that use directories to denote package structure.

Re:J: an alternative to cd that learns where you spend time by brunoqc on Tuesday February 17, 2009 @06:32PM (#485152)
Post like you just did should have a mandatory link to the code :)
Re:J: an alternative to cd that learns where you spend time by calambrac on Tuesday February 17, 2009 @06:42PM (#485163)
There's a python portion: http://pastebin.com/f16aae31d

And a small bash function (since you can only change your shell's pwd from the shell itself):

http://pastebin.com/f5d93d12a

Re:J: an alternative to cd that learns where you spend time by brunoqc on Tuesday February 17, 2009 @06:50PM (#485172)
Thanks!
Re:J: an alternative to cd that learns where you spend time by jrockway on Tuesday February 17, 2009 @07:11PM (#485189)
The name "sd" conflicts with this, however:

http://github.com/obra/sd/tree/master

Yay for two-letter identifiers. ;)

Re:J: an alternative to cd that learns where you spend time by calambrac on Tuesday February 17, 2009 @07:26PM (#485202)
It's just a bash function, you can name it anything you want, and the tool you linked is hardly standard.
Re:J: an alternative to cd that learns where you spend time by burke on Tuesday February 17, 2009 @05:05PM (#485054)
For any zsh users out there, I made a couple changes so it works in zsh: http://github.com/burke/j
Re:J: an alternative to cd that learns where you spend time by codyrobbins on Wednesday February 18, 2009 @04:45AM (#485561)
Perfect, that's just what I was looking for. Thanks!
Re:J: an alternative to cd that learns where you spend time by thorax on Tuesday February 17, 2009 @08:01PM (#485229)
Very neat tool. I saw this when it was mentioned on a post I made not long ago.

If you want something you can simply add to .bashrc, here are some bash functions to also help jump around to directories you want: http://mattie.posterous.com/some-handy-bash-commands

There's a link there for the "up" command (taking you to some directory higher in your path with that name) and also for "down" (similar downward) and "cdd" which just does a rapid use of locate to find the first directory that matches.

Re:J: an alternative to cd that learns where you spend time by msg on Tuesday February 17, 2009 @06:35PM (#485154)
why not use CDPATH?

At work, I have the interesting heads of our source tree in CDPATH, so I can get to most directories I care about by typing their short names.

For instance http://www.macosxhints.com/article.php?story=200503181431142...

Re:J: an alternative to cd that learns where you spend time by Harkins on Tuesday February 17, 2009 @10:40PM (#485336)
Because you don't have to teach it, it just learns.
Re:J: an alternative to cd that learns where you spend time by msg on Wednesday February 18, 2009 @11:13AM (#485878)
With J I have to visit directories to add them to my index. This ramp-up is annoying.

With CDPATH, I index it all at the beginning. If I find a new major head in my directory tree, I just add it.

Re:J: an alternative to cd that learns where you spend time by doki_pen on Wednesday February 18, 2009 @12:26PM (#485965)
It would be nice if it could look through .bash_history when it's first run, or something.
Re:J: an alternative to cd that learns where you spend time by truebosko on Wednesday February 18, 2009 @08:40AM (#485709)
Ok, I feel like an idiot. When it says "source this into your .bashrc" what does it mean?

I know where .bashrc is, but simply pasting it into the file seems like .. the wrong way to do it. Couldn't really find an answer on Google

Re:J: an alternative to cd that learns where you spend time by inky on Wednesday February 18, 2009 @09:32AM (#485777)
Add a line to the end of your ~/.bashrc file with:

    . $HOME/.bash/j.sh
(Change that path to point to wherever j.sh is, though ~/.bash is probably a good place for it.)
Re:J: an alternative to cd that learns where you spend time by truebosko on Wednesday February 18, 2009 @09:57AM (#485800)
Thanks so much! Makes sense
Re:J: an alternative to cd that learns where you spend time by parenthesis on Wednesday February 18, 2009 @09:25AM (#485772)
I think what is referred to is bash's source command: when you've modified your .bashrc and you want the changes to be reflected in your current shell process, you do

  source .bashrc
or, equivalently

  . .bashrc
which runs .bashrc in the current shell, as opposed to in a forked subshell as happens if you did ./.bashrc ; and hence the new functions/aliases/variable settings you've put in .bashrc are now available in the current shell (as opposed to only being visible in a forked subshell and disappearing when it exits).
Re:J: an alternative to cd that learns where you spend time by truebosko on Wednesday February 18, 2009 @09:58AM (#485801)
Now it's clearer, thank you! :)
Re:J: an alternative to cd that learns where you spend time by bluishgreen on Tuesday February 17, 2009 @11:57PM (#485376)
Re:J: an alternative to cd that learns where you spend time by akkartik on Tuesday February 17, 2009 @09:17PM (#485281)
My version: http://akkartik.name/bash.html#cd

But this is nice and self-contained.

Re:J: an alternative to cd that learns where you spend time by braindead_in on Tuesday February 17, 2009 @08:52PM (#485260)
awesome. huge timesaver. wish it could for for cp paths too
Re:J: an alternative to cd that learns where you spend time by lysium on Wednesday February 18, 2009 @10:25AM (#485834)
you could add a completion for cp commands just like in the last line of j.sh

      complete -o dirnames -o filenames -C "j --complete" cp mv
or something similar.
Re:J: an alternative to cd that learns where you spend time by zacharypinter on Tuesday February 17, 2009 @09:40PM (#485289)
I prefer the proggit headline: "Where the fuck has this been for the last 30 years? A cd command that learns."