Live data from Hacker News

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

huyng.com

111–120 of 124 posts

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

#111
post #2

I've also wondered to myself why there isn't a terminal program with a directory tree by the side so you could just click on the directory that you want to be in, instead of ls -cd-tab-blah-^H-tab-^M. It would also a have a list of favorite and most-recently-used directories. A weekend project, perhaps...

There is dolphin, and a few others. http://unix.stackexchange.com/questions/3990/is-there-a-good...

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

#112
I use the following scripts, both by Petar Marinov, they've saved me an enormous amount of keystrokes. One replaces CTRL-R history search, the other makes a much friendlier replacement for pushd and popd.

http://geocities.com/h2428/petar/bash_acd.htm

http://geocities.com/h2428/petar/bash_hist.htm

highly recommended.

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

#113

1. How about we just learning to type fast(-er) and use file name completion 2. Use real shell like ksh, where history search actually works 3. cd $OLDPWD is occasionally helpful. Occasionally. Kids...

Is 'cd $OLDPWD' any different from 'cd -' ?

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

#114
post #78

Earlier quoted context omitted.

I've also been frustrated by these issues. I want to be able to edit a file with local typing speed (i.e., gvim on Windows), but then be able to hit a key and be in a terminal window on that server in that folder to perhaps do a manual grep or rebuild an index or whatever. I feel like we were closer in the 90s with innovative products like Slirp and Term and, yes, Zmodem (and Kermit). I started trying to build out so…

Sounds like you want Emacs' tramp. On your local emacs, open a file in the form "/user@remote-ssh-host:file" and it will grab the remote file and edit it locally. Crazily all the emacs version control commands and stuff like M-x compile and M-x grep all work in the remote context. Very cool stuff. Obviously this requires that you use Emacs instead of Vim though. Don't be afraid though, the grass is pretty green over…

No need to switch to an inferior editor. ;-)

Vim has this functionality built right in: http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html#netrw

However, as said above, for me Tramp/netrw are kludges that tend to add more problems than they solve. A real solution can't be constrained to a particular editor.

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

#115
post #104
post #45

Earlier quoted context omitted.

Or in zsh: setopt cdablevars nm=/path/to/whatever cd nm

you can put this in ~/.zshrc for persistent zsh bookmarks touch ~/.zshmarks && source ~/.zshmarks function b() { echo "hash -d $1=\"`pwd`\"" >> ~/.zshmarks && source ~/.zshmarks }

or you could just put some paths on your cdpath and enable autocd.

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

#116
Thank you for this awesome little script. However I found out that bashmarks doesn't work with folders which have whitespaces in the name.

For example:

  cd /Users/username/Library/Application\ Support
  s app_support
works great but if you do this it won't work:

  g app_support
I opened an issue on GitHub and after that I tried to fix it on my own. I never wrote a bash script and I'm really proud to have fixed this problem on my own.

Here are changes I made:

  # save current directory to bookmarks
  touch ~/.sdirs
  function s {
     cat ~/.sdirs | grep -v "export DIR_$1=" > ~/.sdirs1
     mv ~/.sdirs1 ~/.sdirs

     escaped_path=${PWD/ /\\ }
     echo "export DIR_$1=$escaped_path" >> ~/.sdirs
  }

  # jump to bookmark
  function g {
     source ~/.sdirs
     path=$(eval $(echo echo $(echo \$DIR_$1)))
  
     # replace whitespaces with "\ " for escaping
     escaped_path=${path/ /\\ }
     cd_eval="cd $escaped_path"
    
     eval $cd_eval
  }
Hope this helps you guys like it helped me. And if there is a way to do this in an more elegant way, please let me know. This would help me to improve my none existing bash skills :D

Edit: I opened up a fork and commited all my changes to this repo. I also opened a pull request and I hope my fix will get accepted.

GitHub fork: https://github.com/Oemera/bashmarks

Thanks

Ömer

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

#117
post #110

Earlier quoted context omitted.

You can also use the "dirs" command (I think part of bash as well) that tells you the state of the stack. If you set the -v option, you can get the depth of different directories, and you can just do pushd +N to jump to the specific directory.

funny- I don't see man pages (nor info pages) for pushd, popd, or dirs. What am I missing about the documentation?

They're shell built-ins, so use "man bash" to read about them.

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

#118
post #110

Earlier quoted context omitted.

funny- I don't see man pages (nor info pages) for pushd, popd, or dirs. What am I missing about the documentation?

They're shell built-ins, so use "man bash" to read about them.

To only display information about a specific command, you can also use

    help 

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

#119
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've created an AUR package for this script, found here: http://aur.archlinux.org/packages.php?ID=46675

Out of the box only with `z -l foo` # list all dirs matching foo (by frequency)

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

#120
post #60
post #2

I've also wondered to myself why there isn't a terminal program with a directory tree by the side so you could just click on the directory that you want to be in, instead of ls -cd-tab-blah-^H-tab-^M. It would also a have a list of favorite and most-recently-used directories. A weekend project, perhaps...

Unrelated but a nice alias "tree". alias tree="find . -name .svn -prune -o -name .DS_Store -prune -o -name .git -prune -o -print | sed -e 's;[^/]*/;|___;g;s;___|; |;g'" It shows your directory listing in the form of a tree. Easier to visualize.

Or, you could just use "tree":

http://mama.indstate.edu/users/ice/tree/

Post reply on HN