Live data from Hacker News

Behold z, the unsung jewel that rethinks shell navigation

aymericbeaumet.com

51–60 of 71 posts

Re: Behold z, the unsung jewel that rethinks shell navigation

#51

don't forget about CDPATH $ export CDPATH=~/Workspace/src/github.com # in .bashrc $ cd brigad/ops

In my experience, CDPATH is a great way to lose hours chasing down errors throughout your scripts.

"CDPATH=" without the export will work as you'd want, and won't pollute the environment for subshells and scripts. It is unlikely you really want to export anything listed in the shell variables section of the man page, but yeah everybody does :/

[This message brought to you by https://news.ycombinator.com/item?id=22978770]

Re: Behold z, the unsung jewel that rethinks shell navigation

#52
post #47
post #21

Earlier quoted context omitted.

You press z, type a few letters and then hit tab until you get the thing you want. It's not spatial. If you use ctrl-r frequently it's similar.

Is there any advantage over CTRL-R?

With ctrl-R you'd presumably need a bunch of absolute path navigation commands in the past, with z you don't need to worry about that.

There may be more clashes, like picking up on filenames instead of directories.

Typing `z res` or whatever is also a bit faster than hitting ctrl-R then `res`.

Re: Behold z, the unsung jewel that rethinks shell navigation

#53

With Bash I use "pushd .", "dirs" and "pushd +1"/"pushd -1". I guess that's not quite as advanced as z or fasd though!

Not for you, but perhaps for others who also like that behaviour.

With zsh you can enable the auto_pushd option, which makes cd manipulate the directory stack itself. You could probably simply alias cd as pushd too under zsh too, but in bash that would break cd's argument handling.

Re: Behold z, the unsung jewel that rethinks shell navigation

#54
post #33

Oh-my-zsh with the fzf plugin has a lot of navigation-friction removal. cd ~/r/pr/e/de Becomes cd ~/repos/projectlongname/environments/development It also has built in push/pop, with minus always returning to the previous path, various numbers of dots, up to six I believe, navigating up the tree, and cd - showing interactive breadcrumbs of recent paths for easy as click-and-click navigation.

I think most of this is out of the box OMZ (without the fzf plugin).

Built-in zsh behaviour in fact, oh-my-zsh just enables some extremely useful non-default options.

With a compinit call the directory substring expansion will work. And, with auto_pushd enabled cd fiddles with the directory stack.

The ....... behaviour is interesting because it uses a global alias(alias -g) which is an awesome feature for text expansion anywhere in a line, unlike standard aliases which only expand where commands should be given. It means, for example, you can do `readlink -f ......` and it would perform `readlink ../../../../../..`. Aliases on zsh are very powerful indeed.

I'm writing this text in the hope it drives at least one person to burn an afternoon on the amazing(but huge) zsh documentation, because the entire thing is full of gems.

Re: Behold z, the unsung jewel that rethinks shell navigation

#55

funfact: vim does this with **, and tab-complete. For navigating between parallel directory structures (src/ and test/), I made an awful hack called c-, that sed subs src/ for test/ and vice versa on pwd. A fluke grade.

When actually inside vim Tim Pope's excellent vim-projectionist has a wonderfully useful feature for flipping between various related files(:h projectionist-alternate). The whole plugin is really cool, it makes it so simple to configure project specific working environments with it.

https://github.com/tpope/vim-projectionist

Re: Behold z, the unsung jewel that rethinks shell navigation

#56

I develop apps on Windows, but I use Linux to do lots of my work and automate cumbersome boring tasks where I can (there are still many more to be automated....). I'm constantly amazed at what Windows dev people can get done without a programmable command line. I've seen several thousand line long cmd/bat files to do relatively simple things. They work, which is good. They are a lot of work to maintain though. I find…

For shell scripts that are longer then a handful lines, python is the better alternative IMHO, especially if the scripts need to work across Windows, Linux and macOS.

Windows has some nice tricks to connect the UI to the cmdline. For instance you can type "cmd" or "powershell" in the breadcrumbs-bar of an Explorer window, and it opens a terminal at that filesystem location (and the other way around, "start ." on the command line opens an Explorer window in the current directory.

Historically, pure command line workflows are somewhat rare on Windows though.

Re: Behold z, the unsung jewel that rethinks shell navigation

#57
post #17

I'm mildly skeptical of any shortcuts that are based on "learning habits". I've already gotten enough of user interfaces that move items based on use all the time (The spotify playlist list is the worst offender - playlists move up and down in rank after every use, so there is never any spatial memory, startled every time).

I found the per-directory "suggest-while-typing" history in Fish (and Zsh with the right extension) very intuitive. It speeds up getting around the filesystem, and to common locations tremendously, and of course also remembers regular commands. And it "just works", there is nothing to setup and no commands to remember.

Re: Behold z, the unsung jewel that rethinks shell navigation

#58
post #50
post #40

Earlier quoted context omitted.

I find the persistent directory stack of ohmyzsh (easy enough to enable yourself in zsh) easier to use than things like autojump or z, and pretty much makes them unnecessary. I miss this basic functionality in fish (hoping someone will point out that I have overlooked it)

Care to elaborate? Nowadays i usually use history with fzf to find old cd commands.

cd - to view numbered list of previous directories. hit the number to cd there

Re: Behold z, the unsung jewel that rethinks shell navigation

#59
post #40
post #35

Earlier quoted context omitted.

I’ve used fish for quite a while but after Many a scripting incompatibility I went back to ohmyzsh. Fish is great if you can port your whole ecosystem into it.

I find the persistent directory stack of ohmyzsh (easy enough to enable yourself in zsh) easier to use than things like autojump or z, and pretty much makes them unnecessary. I miss this basic functionality in fish (hoping someone will point out that I have overlooked it)

If you just type cd space and hit the up arrow X times.. normally it give a good guess without having to do that just after entering cd space.
Post reply on HN