5 ms·
The single best shell productivity tip for me was to use z: https://github.com/rupa/z https://github.com/rupa/z It automatically makes a list of directories y
by alufers 6y ago
The single best shell productivity tip for me was to use z:
https://github.com/rupa/z https://github.com/rupa/z
It automatically makes a list of directories you frequently use in your shell and if you type `z a-small-substring-of-the-directory-path` it does a cd to that directory. (e.g. I type `z and` and it changes my current directory to $HOME/Work/Projects/android`). Saved me tons of typing.
- Spivak 6y agoA somewhat less fancy version of this is $CDPATH. export CDPATH="/path/to/my/projects:$HOME/Work/Projects" # From anywhere. cd andr<tab><enter>
- mceachen 6y agoNote that CDPATH can break shell scripts that assume `cd` hasn't been adulterated. A huge block of "unalias" calls at the beginning of shell scripts used to be a common practice, but they don't seem to be found in more widely-used tools these days.
- kubanczyk 6y agoExcept with CDPATH the `cd` is usually not an alias. Even `/usr/bin/cd` is aware of CDPATH. It's a bug in the script, just like reacting badly to $IFS or $LANG.
- sigjuice 6y agoWhat is /usr/bin/cd for? cd is supposed to be a shell built-in, because running /usr/bin/cd will make another process and that cannot change the current working directory of the shell you are in. EDIT: $ cat /usr/bin/cd #!/usr/bin/sh builtin cd "$@"
- saagarjha 6y agoLook, it's 'cperciva! $ cat /usr/bin/cd #!/bin/sh # $FreeBSD: src/usr.bin/alias/generic.sh,v 1.2 2005/10/24 22:32:19 cperciva Exp $ # This file is in the public domain. builtin `echo ${0##*/} | tr \[:upper:] \[:lower:]` ${1+"$@"}
- kubanczyk 6y agoTIL, magnificient! It doesn't work on the minimal Centos 7, so you need: yum install -y bash-completion bash # a fresh run
- JNRowe 6y agoCDPATH doesn't require the export as it is local to the shell session. Simply setting it will work as you'd want and won't pollute the environment for subshells and scripts. And zsh users get another advantage here. You can use assign to the cdpath array or the CDPATH colon-delimited string, they are both treated the same internally. The advantage is being able to `cdpath+=...`, much like adding to $PATH with `path+=` or removing from PATH with `path^=`. Check zshbuiltins(1) for how to make your variables work like this, or how to use typeset -U to remove duplicates automatically, or $thousand_other_cool_things.
- marcuskaz 6y agoAgree, so useful! A port is also available for PowerShell: https://github.com/vincpa/z https://github.com/vincpa/z
- andrelgomes 6y agoHave you checked out Warp drive for zsh? https://github.com/mfaerevaag/wd https://github.com/mfaerevaag/wd It is more manual than z, but takes out the learning phase. Will check out z though!
- alufers 6y agoIt depends on how you work, I have a lot of small projects which come and go, so setting up the paths every time I start or finish something would be inefficient. Although I might adopt it for different weird system configuration directories which I often forget the path to.
- andrelgomes 6y agoYes I have had that problem already, more specifically cleaning the lists in wd if directories are moved or removed. I do a cronjob to try to rectify that but interested to see if z mitigates this problem - seems there is an option -x to remove learned directories. [edit] Or z's based ageing ranking system will just aged those legacy directories, even better (in terms of more hands off)!
- __Joker 6y agoSound similar to autojump. https://github.com/wting/autojump https://github.com/wting/autojump
- fdw 6y agoThe advantage of autojump - at least for me - is that it doesn't depend on the shell, as it is implemented in Python. This makes it possible to read and write the data elsewhere, too, independent of your shell. For example, I integrated it into ranger (see my history, I don't want to spam HN with this project).
- gimboland 6y agoI use autojump, but I liked the idea of having an fzf-powered menu pop up when invoked without any args (which is not how autojump behaves). So I made rustled this up (zsh): https://pastebin.com/aLmqJVRy https://pastebin.com/aLmqJVRy
- kortex 6y agoThis is my workhorse, 'to'. No argument: start fzf (this really should read "to $(fzf)"), jump to that dir. One arg: if the path is a real file/dir, jump to it, else use zoxide (z in rust) to soft-match it from history. https://github.com/xkortex/bashbox/blob/master/aliases/core.sh#L33 https://github.com/xkortex/bashbox/blob/master/aliases/core....