5 ms·
Cdpath: Easily Navigate Directories in the Terminal
- ARandomerDude 3y agoFor even more power use z https://github.com/rupa/z https://github.com/rupa/z
- kstrauser 3y agoI prefer zoxide, which is very similar: https://github.com/ajeetdsouza/zoxide https://github.com/ajeetdsouza/zoxide
- notnmeyer 3y agowhat do you prefer about it?
- kstrauser 3y agoIt’s a few things that aren’t big but add up: it’s compiled, and given how often it’s execute, that can make a difference (and especially on a heavily loaded system); it still gets updates; it plays better with Fish shell from my recollection; it supports fzf. Z is perfectly fine. If zoxide didn’t exist, I’d use z instead. As it stands today, I think zoxide is niftier.
- battles 3y agoThat repo has an ad in its readme. Never seen that before.
- TheCycoONE 3y agoI preferred fasd or specifically the oh-my-zsh fasd plugin for what I felt was more natural disambiguation completion (tab after vs remembering zi up front or space tab) and additional shortcuts. I use zoxide now slightly reluctantly since fasd isn't maintained.
- ilyagr 3y agoIf you are willing to install a lua interpreter, https://github.com/skywind3000/z.lua https://github.com/skywind3000/z.lua is quite nice and has more features, e.g. fzf integration and an interactive mode.
- sgt 3y agoJust installed z. After activating it, it outputs the directory when you use cd. Can one make that stop?
- JNRowe 3y agoThe article spends a little time talking about the drawbacks of using CDPATH because it will break scripts, but the better answer is simply not to export it. CDPATH is a shell variable, not an environment variable, and should be treated that way. Simply use "CDPATH=here:there" without the export, get the same functionality and no additional breakage. Plus, on zsh you can use the tied variable cdpath instead of CDPATH(see typeset -T¹). cdpath is an array that accepts all the regular array operations. For bonus points you can even declare it with -U to remove the need to consider duplicates in your config. Other common -- and useful -- tied variables include path/PATH and fpath/FPATH². ¹ https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html#index-typeset https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Command... ² https://zsh.sourceforge.io/Doc/Release/Parameters.html#Parameters-Used-By-The-Shell https://zsh.sourceforge.io/Doc/Release/Parameters.html#Param...
- polm23 3y agoWhy not just use symlinks in your home dir? Like: cd ~/blog
- tedunangst 3y agoBecause I don't want to constantly update 6000 symlinks as I add and remove directories in other locations.
- hibbelig 3y agoThe other option was to put them into CDPATH instead... 6,000 of them? (I guess you are using an alternative to CDPATH, but you haven't said.)
- tedunangst 3y agoNo, because you put the parent directory in CDPATH. If I have funstuff/blogs/pics, funstuff/blogs/foods, funstuff/blogs/cats, etc., I put funstuff/blogs in CDPATH and now cd cats just works. If I created a pile of symlinks, I would have to individually create one symlink each for ~/pics, ~/foods, ~/cats, etc. And also type cd ~/cats.
- hibbelig 3y agoI see. Thank you, I missed that aspect. Of course, adding a symlink “~/f” that points to “funstuff” would work around the limitation, at the expense of typing two more characters. Four more if you count the leading “~/”.
- from-nibly 3y agoI have a little bash script/alias that when you call it searchesy source directory for .git folders and lists all the parent directories in an fzf selector, which then cds to your selection. I don't go anywhere else in my filesystem often enough to want anything more than that.
- tedunangst 3y agoWhether the shell searches . absent its presence in CDPATH is shell dependent. It may not try . unless explicitly set.
- hbogert 3y agoYeah I hit this hard and if I remember correctly it was the '/bin/sh' under Mac that did not look for . That was nasty troubleshooting as CDPATH had been working correctly for years for me under Linux.
- julianeon 3y agoMy surprising finding was that its easier to just hardcode abbreviations to directories. The most unimpressive solution technically and yet also the most effective. I have abbreviations for about 20 directories, which essentially combine "cd" and the directory path in one string, no spaces. It works because I probably spend about 50-80% of my time in those directories, it's not too much to remember, and nothing can be faster than a one-word command abbreviation to that exact directory.
- dog321 3y agoSame, i literally have an alias that is 'w', which takes me to my primary working dir. It's great.
- deleted 3y ago[deleted]
- bee_rider 3y agoAnother option could be to have a tmux session open for each of your projects, although of course this wouldn’t survive reboots.
- mr_mitm 3y agoIt does with the plugin tmux-resurrect. Not perfect, but good enough most of the time.
- samuell 3y agoSame here. I use "c.<bookmark-name>" so that I can hit "c." and tab twice to see all my available bookmarks. Then I created a little bash f function: bookmark <bookmark-name> ... that adds such an alias pointing to the current folder to my aliases file, and sources it. The source, if anybody is interested: bookmark() { if [[ ! $1 ]]; then echo "Please provide a bookmark name (will be prepended with 'c.'):"; read name; else name=$1; fi dir=$(pwd); echo "alias c.$name='c $dir'" >> ~/.bash_aliases_local source ~/.bash_aliases_local } Very efficient! The reason I use c. rather than cd. is partly because I use an alias "c" all the time instead of "cd", that does all of this: - cd into the folder - run ls -ltr to see my last modified files at the bottom near the prompt. - create an empty like with echo - run pwd to print out the current folder path. This was after I ran statistics on my bash history file and realized I constantly running ls -ltr and sometimes pwd in new folders.
- betenoire 3y agoHere is a little fish function I've used for years. function p set -l argc (count $argv) if test $argc -eq 0 cd ~/projects return end set -l project $argv[1] cd ~/projects/$project test $argc -eq 1; and return set -l file (fzf -q (string join " " $argv[2..-1])) test -z $file; and return $EDITOR $file end Jumps to my project roots, and even opens my editor with extra args. Completion, too. set -l commands (command ls -p ~/projects/ | grep "/" | tr '\n/' ' ') complete -c p -f \ -n "not __fish_seen_subcommand_from $commands" \ -a $commands Maybe someone who uses Fish will find this useful
- philsnow 3y ago> If you put too many directories with common names into CDPATH and export it, it might break your scripts. It will also break your shell history. I’m probably in the minority but I’m wary of tools like this (asdf’s .tool-versions and similar things like rbenv/pyenv, and especially direnv) that change behavior based on the state of your shell’s working directory. I like being able to ^R to a shell command from a month ago and just run it without worrying whence I’m running it. I do like that you can directly use shims from asdf/pyenv/etc.
- ughitsaaron 3y agoI’ve been using autojump for years to the point of forgetting it’s not out-of-the-box behavior for zsh. https://github.com/wting/autojump https://github.com/wting/autojump
- hiAndrewQuinn 3y agoVery cool! Very helpful if you want to use the CDPATH variable in your shell scripts. For my money, I just use fzf's built in Alt+C keybindings, as I outlined here [1] some months ago. It's been a game changer. [1]: https://andrew-quinn.me/fzf/ https://andrew-quinn.me/fzf/
- thelastknowngod 3y agoI've been using zshmarks or bashmarks for years now. I couldn't get by without it at this point. https://github.com/huyng/bashmarks https://github.com/huyng/bashmarks https://github.com/jocelynmallon/zshmarks https://github.com/jocelynmallon/zshmarks
- yasser_kaddoura 3y agoJust automate the process using tools that use https://en.wikipedia.org/wiki/Frecency https://en.wikipedia.org/wiki/Frecency like autojump and fasd. No need to put a cognitive load on maintaining something that change over time when it can be easily automated.
- amelius 3y agoLooking for a tool/shell that combines navigation and history. E.g. it would tell which commands I previously used while at the current directory.
- f_kai 3y agoI've had a great time using McFly (https://github.com/cantino/mcfly https://github.com/cantino/mcfly) for going through my command history. It prioritizes showing commands that were previously run in your current directory!
- abhinickz 3y agoI use https://github.com/ajeetdsouza/zoxide https://github.com/ajeetdsouza/zoxide, which is inspired by z and autojump.
- spelufo 3y agoAlso, `cd -` to go back to the previous directory. And for git branches `git checkout -`. Handy.