6 ms·
This is more in the "hack" category, but here is a solution for bookmarking directories[1] that I am quite fond of: mkdir ~/.marks/ export CDPATH=.:~/.mark
by kkoncevicius 4y ago
This is more in the "hack" category, but here is a solution for bookmarking directories[1] that I am quite fond of:
mkdir ~/.marks/
export CDPATH=.:~/.marks/
function mark { ln -sr "$(pwd)" ~/.marks/"$1"; }
Then:
mark @name # add bookmark called @name for the current directory
cd @name # jump to the bookmarked location
cd @<tab> # list all available bookmarks
It can list bookmarks, auto-complete, jump to sub-directories within bookmarks, all without introducing any new commands - just `cd`.
[1]: http://karolis.koncevicius.lt/posts/fast_navigation_in_the_command_line/ http://karolis.koncevicius.lt/posts/fast_navigation_in_the_c...
- porcc 4y agoFor people interested in this def look into autojump before doing this
- evgpbfhnr 4y agoI've been trying this for a few days and now noticed u-boot no longer builds with an output dir ( `make O=subdir whatever` ). It sure took me ages to figure it was CDPATH, but CDPATH it is. I won't retry without making that "cd @" thing a subfunction (that might involve making its own completion, but that's easy compared to debugging make... I still don't know WHY it broke, just that it's CDPATH that broke it -- it decided to duplicate the subdir arg when invoking a submake so make was now left with a weird unknown target, but it obviously wouldn't say that and just failed weirdly)
- kkoncevicius 4y agoInteresting, thanks for sharing. I would be tempted to call this a bug in the Makefile if this is the case. CDPATH is a standard bash environment variable, people use it in various ways: https://github.com/search?q=%22export+CDPATH%22&type=code https://github.com/search?q=%22export+CDPATH%22&type=code If all these causes the build to fail then the maintainers of that build should be informed.
- deleted 4y ago[deleted]
- the_fury 4y agoI've just spent the last few minutes playing with the bookmarks snippet. This is both elegant and immediately useful to me. Thanks for sharing!
- kkoncevicius 4y agoGlad it is useful. Just a note of advice - prefix your bookmarks with a symbol that is not used to start directory names (was @ in my case). This is useful for two things - 1) avoiding clashes with existing directories, 2) having a quick command to list all the bookmarks: cd @<tab>
- p4l4g4 4y agoAwesome snippet! I organize most of my work using something similar to the Johnny decimal system[0] and use CDPATH for quicker lookups. But I love how you build a dynamic system with a simple oneliner! [0] https://johnnydecimal.com/ https://johnnydecimal.com/
- meain 4y agoYou might be interested in hash in zsh. https://til.hashrocket.com/posts/xsavbhlrz4-shortcuts-with-hash-d-in-zsh https://til.hashrocket.com/posts/xsavbhlrz4-shortcuts-with-h...
- behnamoh 4y agoI just use ranger and mark/bookmark directories like in Vim.
- gbrindisi 4y agoNice! I gave up on bookmarking so I now use an alias to quickly find what I am looking for with fzf and fd: p () { cd $(fd $1 $HOME -d 4 -i -E Pictures -E Desktop | fzf) }