Live data from Hacker News

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

huyng.com

41–50 of 124 posts

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

#41

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 t…

Open one per directory you want to operate in, for instance.

This is a common source of headache when using the terminal as an IDE. Not only is it easy to get lost in a sea of terminal-tabs, but it's also quite cumbersome to restore the state of 5+ tabs after a shutdown or disconnect. Even more so when GNU screen enters the mix.

What I'd really like to have is a terminal that can attach to a remote GNU screen and display the screen-windows as local tabs.

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

#42
post #36

Earlier quoted context omitted.

I'd be extremely careful with CDPATH, never use this on an important host. Having "cd foo" potentially take you to an entirely different location can be dangerous, to say the least.

I'm not sure I follow. There's nothing dangerous about cd-ing to a directory, though of course it could be dangerous to start work in 'foo', thinking it was 'bar'. Most people use a prompt, or the title bar of their shell to protect against that. But either way, I'm not sure how CDPATH makes that danger greater than any other trick that allows you to jump quickly to a directory using a bookmark, popd or the like.

  cd foo
  rm -f *
Removing predictability from the 'cd' command is not a good idea. If you want a smart 'cd' then just call it 'j' or something else. Easier to type, too.

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

#43

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.

nice stuff. You got your dotfiles on a github?

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

#44
post #42

Earlier quoted context omitted.

I'm not sure I follow. There's nothing dangerous about cd-ing to a directory, though of course it could be dangerous to start work in 'foo', thinking it was 'bar'. Most people use a prompt, or the title bar of their shell to protect against that. But either way, I'm not sure how CDPATH makes that danger greater than any other trick that allows you to jump quickly to a directory using a bookmark, popd or the like.

cd foo rm -f * Removing predictability from the 'cd' command is not a good idea. If you want a smart 'cd' then just call it 'j' or something else. Easier to type, too.

Certainly a possible scenario, but anyone who cds into any directory (by whatever means) and enters 'rm -f *' without first checking contents deserves what they get.

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

#45
post #34

I like this workflow better: 1. Go to the directory in question 2. Type "save nm" where "nm" is any short name for the directory, like "blog" or "blg" 3. From now on, type "cd nm" whenever you want to go there. No session restart required, even. I copied the code that enables this workflow from http://dotfiles.org/~jacqui/.bashrc (or was it https://gist.github.com/117528 ) The idea is discussed here: http://hints.mac…

Or in zsh:

    setopt cdablevars
    nm=/path/to/whatever
    cd nm

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

#46

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.

How about `setopt cdablevars`?

    setopt cdablevars
    proj=$HOME/Projects
    cd proj
    pwd # => /Users/sjs/Projects

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

#47
post #43

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.

nice stuff. You got your dotfiles on a github?

I know you didn't ask me, but you might find something you like here: https://github.com/samsonjs/config (dot files) and https://github.com/samsonjs/bin

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

#48

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 t…

And use tools that are aware of directories: tar -C, NERDtree for Vim, zsh globbing.

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

#49
post #42

Earlier quoted context omitted.

cd foo rm -f * Removing predictability from the 'cd' command is not a good idea. If you want a smart 'cd' then just call it 'j' or something else. Easier to type, too.

Certainly a possible scenario, but anyone who cds into any directory (by whatever means) and enters 'rm -f *' without first checking contents deserves what they get.

Well, this was just the most graphic example, there are more subtle ways to create a mess. Directory names are far from unique, a misfiring 'cd tmp' or 'cd src' can easily lead to nasty surprises, even without 'rm' ever getting involved at all.

And you do know that CDPATH also affects shell scripts, right?

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

#50

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 t…

Also, pushd and popd. And "cd -". And ctrl-Z and fg to jump out of your editor for a moment. And dragging dirs from the Finder (or whatever) to the terminal.
Post reply on HN