Live data from Hacker News

Don't waste your time by cd-ing in the terminal

huyng.com

21–30 of 124 posts

Re: Don't waste your time by cd-ing in the terminal

#21
post #5

Don't waste your time bookmarking directories, jump right to them ;) https://github.com/rupa/z `z` tracks your most used directories. After a short learning phase, it will take you to the directory, based on its usage frequency and a hint you give it on the command line. Say I am often cd'ing into /var/www - then after a while I can just type `z ww`.

I love projects like this. They so elegantly show what using the right tool for the job can do for you, in terms of code simplicity and conciseness. Doing this in, say, Perl or Python or Ruby, would be entirely possible, and folks who code exclusively in those languages might assume it would be easier in a "more powerful" language...but Bash has so many nice little built-ins that make it really concise and portable. One file, no modules, and it does exactly what it's supposed to do.

I think it's illustrative that the developer went through a Python-based version on the path to building z.

Re: Don't waste your time by cd-ing in the terminal

#22

No mention of ZSH directory stacks yet? http://www.acm.uiuc.edu/workshops/zsh/dir_stack.html Some helpful aliases to manage them: alias 1='cd -1' alias 2='cd -2' alias 3='cd -3' alias 4='cd -4' alias 5='cd -5' alias 6='cd -6' alias 7='cd -7' alias d='dirs -v' alias h='history' alias j='jobs' Just one of the many reasons to use ZSH.

Just one of the many reasons to use ZSH. What shell doesn't have a directory stack?

What's the bash equivalent to zsh's "setopt autopushd"?

Re: Don't waste your time by cd-ing in the terminal

#24
I first was excited by title "Don't waste your time by cd-ing in the terminal", but then it just turned out to be a blog post about making cd'ing quicker. If you want to boost your productivity, my advice is to stop cd'ing altogether.

I see a lot of people -- particularly vi users -- cd'ing back and forth through a large directory tree. I usually tell them to get a terminal emulator that lets you easily manage many terminals open. Open one per directory you want to operate in, for instance. Learn how to switch back and forth between the different shells.

But most importantly, don't quit the program to switch back and forth between directories and files. Learn to use your editor of choice properly: how to view directory listings, how to switch back and forth, etc. Vim can do this just fine btw. The choice of tool here doesn't matter so much. Just pick one and learn it. This applies to your choice of terminal emulator, shell, editor, etc.

Re: Don't waste your time by cd-ing in the terminal

#27
post #22

Earlier quoted context omitted.

Just one of the many reasons to use ZSH. What shell doesn't have a directory stack?

What's the bash equivalent to zsh's "setopt autopushd"?

I don't know what that is, but does it do more than alias cd='pushd'?

Re: Don't waste your time by cd-ing in the terminal

#28
I use "m1=`pwd`" and then "cd $m1" for example. No setup required, although admittedly slightly more typing and the need to quote directories with spaces in them (rare for Unix sysadmin tasks for which I'm using a shell in the first place).

Re: Don't waste your time by cd-ing in the terminal

#29
post #8

I use this function in my bash profile to navigate to my projects from anywhere on the file system. function to { cd ~/Sites/$1/ } eg. cd ~/Sites/coenhyde.com $ to coenhyde.com

I would suggest mapping an alias instead of creating a function so that you will still be able to take advantage of parameter completion:

> alias to='cd ~/Sites/'

Post reply on HN