Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I generally work in only a few folders (we'll call them project a, project b, project c), so once I taught it these are high priority, it just works when I type any part of their names


Same and I'm about to try the counter approach: just alias those few things


In Zsh with `setopt autocd cdablevars`, shell variables more or less work like cd-aliases. You could also just add `a=projectA; b=projectB; c=projectC` to your `~/.zprofile` and then at prompts type 1-letter commands `a`, `b`, `c`.

One added bonus of such file tree bookmarks via variables (over a similar `alias a='cd foo'`) is that if you get muscle-memory/active memory for those few abbreviations other use cases like `make -C $a` also work. I usually leave `$hb` & `$lb` set to `$HOME/bin` and `/usr/local/bin`, for example.


Interesting !

I have this alternative in my zsh config:

    # BOOKMARKS (mark b)
    declare -x -A bookmarks
    bookmarks=(
     d            "$HOME/Desktop"
     dd           "$HOME/Downloads"
     c            "$XDG_CONFIG_HOME"
    )
    for key value in ${(kv)marks}; do
     hash -d $key=$value
    done
Then I can just use ~c, ~d or ~dd or anything temporary I want to put there


`hash -d` (aka "named directories") is surely an alternative and if that suits you, by all means.

I see at least two downsides: 1) now you have to remember to say `make -C ~c` { not `make -C $c` which I think most would find more natural } 2) the hash cannot be exported to inheriting subprocesses like a regular scalar $var.

Of course, 1) is kind of weak since you can also use "~var" most places. It's just not as familiar to many as $var.

One notable equivalency is that Zsh prompt escapes for $PS1 and friends like %~ would treat both the same - converting them to a "~c" inside your prompt.

So, in terms of "looking like what you type", that maybe makes ~c better. Maybe there is some setopt to make Zsh expand %~ as $c or $dd? Not sure. There are a lot of setopts.

Anyway, I actually use the exporting feature to non-Zsh subprocesses myself. So, I'm pretty locked-in to vars not just hash entries.


The comment above is something I love about HN. I never knew this existed and would not have even thought to search for it but, but that’s something that I see me using everyday.


Glad to be appreciated. You might also enjoy this snippet from my zshrc:

    my-expand() BUFFER=${(e)BUFFER} CURSOR=$#BUFFER
    zle -N my-expand        # Make Alt-E expand environ vars w/o val escape
    bindkey '^[e' my-expand # Allows eVar "short cuts" for history !!:gs etc
It's vaguely related in that it lets you put a variable in the main Zsh Line Editor (ZLE) buffer (with the leading `$`) and then press Alt-E to expand it. ('e' for E)nvironment-E)xpand).

As per the comment I did this so that I could have "history substitution expressions" stored in variables, then Alt-E - look (& maybe edit) & ENTER.

The history syntax itself is very cryptic, derived from early 1980s BSD csh. As with most such crypticnesses, figuring it out once, storing it somewhere you can remember, and expanding it on demand is a not awful way to learn it.

But besides cryptic history directives you could also use it for the `$a<Alt-E>` above to "see before you do". You need an extra `$`, though, as written. It would be pretty easy to auto-add a `$` prefix in `my-expand`, though (with Alt-E just becoming a sort of different kind of TAB for expansion rather than completion).




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: