Hacker News new | ask | show | jobs
by graffitici 3164 days ago
I love the combination of these! Really opens up a world of possibilities. The one command I'm still trying to replace is `cd` itself. For instance, can anyone suggest a way to add bookmarks, so that I can move around faster? I found a few, but was never happy with them.
10 comments

I use a combination of https://github.com/clvv/fasd and https://github.com/ranger/ranger.

When tasks like navigating into a project, starting tests, local server and neovim become repetitive I usually end up making a tmux script which does everything for me.

Also, aliasing ‘..’ to ‘cd ..’ and such.

Probably not exactly what you want, but the pushd/popd/dirs commands have existed in all major shells forever.

You can run dirs -v to get the list, and do cd +(num) to go there.

So:

  FreeBSD <jubei/pts/2> (219 /var): dirs -v
  0	/var
  1	/usr/local
  2	~
  FreeBSD <jubei/pts/2> (220 /var): cd +1
  /usr/local
  FreeBSD <jubei/pts/2> (221 /usr/local): _
I’ve been enjoying autojump [1], it automagically creates bookmarks and prioritises them based on frequency of visiting said folders.

[1] https://github.com/wting/autojump

Autojump is the answer here. Totally a gamechanger. If you like its semantics enough, check out fasd [1] , which is a superset of autojump that applies its cache in many other places. Absolutely awesome.

[1] https://github.com/clvv/fasd

The $CDPATH variable (built into `cd`)[0] plus the `bash_completion`[1] script to enable tab-completion of CDPATH dirs - works for my use case (FWIW).

[0] http://linuxcommand.org/lc3_man_pages/cdh.html [1] http://www.caliban.org/bash/index.shtml#completion

I recommend https://github.com/clvv/fasd It basically makes bookmarks automatically as you navigate your filesystem anyway.
Scratched that itch of mine for bash/zsh in 30 lines[0]. kd stands for quicKDir or worKDir depending on the moon.

    kd foobar ~/Workspace/foobar  # define bookmark
    cd ~/some/where
    kd foobar                     # goes to bookmark
    kd foo                        # matches on string prefix, last entry wins
    
    cd ~/Workspace/quuuuuux
    kd qux "$PWD"                 # quick bookmark current dir
    
    touch Gemfile                 # define project root
    cd app/controllers/name/space/whatevs
    kd                            # goes to project root
Turns out autojump doesn't work for me, too many projects in parallel. Since this one is manual, it can be very semantic. Those 30 lines saved me hours on end of tab mashing, especially in Go workspaces.

[0]: https://github.com/lloeki/dotfiles/blob/master/shell/kd

http://cryptonector.com/2007/04/c-shell-pushdpopd-on-steroid...

I have been doing something similar for many years. Someone ported this to Bash... I'll try to get that port up on github.

EDIT: https://raw.githubusercontent.com/jakobi/script-archive/mast...

It isn't super clear in the article, but I now use bfs & fzf for replacing cd.

https://github.com/bag-man/dotfiles/blob/master/bashrc#L73

Lets you change directory with alt+c, although I have tweaked it so you always search from your root folder. Which isn't for everyone. Otherwise fzf alt+c doesn't let you go back up directories which gets frustrating.

Hey, bfs author here, glad you've found it useful! You can do that whole thing in one command with

    bfs ~ -nohidden -type d -printf '~/%P\n'
I've just tried this and in my case it leads to "cd \~[...]" which obviously does not work.
That's strange. Maybe just change it to:

    export FZF_ALT_C_COMMAND="bfs -type d -nohidden"
(and install bfs of course)

It won't let you go back up the tree, but if you are clever you can use `cd -` to jump back to your previous location.

https://github.com/rupa/z could also be interesting for you.
Also interesting is fzf-marks:

https://github.com/urbainvaes/fzf-marks.git

I have a little script that combines z and fzf.

https://gist.github.com/chew-z/44f3bcdc08eaecdf306868f9a3d0e...

> The one command I'm still trying to replace is `cd` itself.

zsh will implicitly cd if you just mention a directory e.g. `$ ../foo/bar [RET]` will cd there without mention. These days I only use `cd -`.

> These days I only use `cd -`.

There's also `cd foo bar` in zsh, which substitutes foo with bar in the name of $PWD. I rarely used it, and when I do, it's usually for a well known pair of lengthy named dirs, yet it also shaves off a couple of keystrokes pretty much daily for me.

IIRC that isn't the default. You need to enable the option for that to work.

zsh has about a thousand options you can configure.

> IIRC that isn't the default. You need to enable the option for that to work.

You're right, it's been so long I completely forgot.

It's auto_cd, and auto_pushd will also automatically push new directories to the dstack.

> zsh has about a thousand options you can configure.

I should probably go through the options list in its entirety one day, but technically according to http://zsh.sourceforge.net/Doc/Release/Options.html it's closer to a quarter of that ;)

I think it is enabled by default. I never explicitly enabled it for my zsh configuration and it behaves that way.