News for hackers. Stuff that matters.
Re:Cdpath: Easily Navigate Directories in the Terminal by julianeon on Wednesday December 06, 2023 @11:35PM (#38552868)
My 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.

Re:Cdpath: Easily Navigate Directories in the Terminal by dog321 on Thursday December 07, 2023 @12:34AM (#38553209)
Same, i literally have an alias that is 'w', which takes me to my primary working dir. It's great.
Re:Cdpath: Easily Navigate Directories in the Terminal by bee_rider on Thursday December 07, 2023 @12:41AM (#38553242)
Another option could be to have a tmux session open for each of your projects, although of course this wouldn’t survive reboots.
Re:Cdpath: Easily Navigate Directories in the Terminal by mr_mitm on Thursday December 07, 2023 @04:39AM (#38554590)
It does with the plugin tmux-resurrect. Not perfect, but good enough most of the time.
Re:Cdpath: Easily Navigate Directories in the Terminal by samuell on Thursday December 07, 2023 @02:10AM (#38553706)
Same 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.

Re:Cdpath: Easily Navigate Directories in the Terminal by samuell on Thursday December 07, 2023 @04:46AM (#38554620)
The source for my "c" bash function as well:

  c() {
    cd "$1";
    ls -ltra --color=always | tail -n 25;
    echo;
    pwd;
  }
Re:Cdpath: Easily Navigate Directories in the Terminal by samuell on Thursday December 07, 2023 @04:50AM (#38554648)
What was my surprising finding in this, is that I don't need to think much about how I name the bookmarks either.

I can just throw in new short-hand bookmarks for whatever I'm working at the moment.

If I happen to override any previous aliases, that doesn't matter much if I already forgot about that one anyways.

Another cool thing: You can check the end of your ~/.bash_aliases_local file to find out what are your most recent bookmarks, and in other words, what are the relevant folders you are using a lot right now.

One can of course also clean up this list of bookmark-aliases from time to time, but I often don't even care about that.

Re:Cdpath: Easily Navigate Directories in the Terminal by shzhdbi09gv8ioi on Thursday December 07, 2023 @06:16AM (#38555179)
Me too, here's some of my most commonly used

    alias cdrs='cd ~/dev/rs`
    alias cdgo='cd ~/dev/go`
    alias cddev='cd ~/dev'
    alias cddl='cd ~/Downloads'
Re:Cdpath: Easily Navigate Directories in the Terminal by unfamiliar on Thursday December 07, 2023 @07:18AM (#38555556)
Zsh has a better builtin solution.

    hash -d x=/path/to/x
Then you can cd to there with just

    ~x
And use it in commands like

    ls ~x/whatever/
Re:Cdpath: Easily Navigate Directories in the Terminal by brushfoot on Thursday December 07, 2023 @08:00AM (#38555822)
On Windows, I used to use AutoHotkey hotstrings for that so that they'd be available in file dialogs and Explorer as well as the terminal. Example:

    ::$pmd::C:\my\directory
For those unfamiliar with AutoHotkey, it has a global keyboard hook that watches for hotstrings like this and expands them to the text after the second pair of colons.

"$" is a sigil I chose to use for all hotstrings since I didn't use a language that used it and it helped avoid collisions with text that wasn't meant to be a hotstring, "p" was my prefix for pathing hotstrings, and "md" was an abbreviation for the mnemonic I chose for this particular directory, "my directory."

Then I realized z saves you the work of all that by learning which directories you use regularly and letting you switch to them with partial matching on its arguments:

    z my dir
No more coming up with mnemonics and editing my hotstrings file when I started new projects; now z handles it.

For the GUI (file dialogs etc.), my profile script now includes a command that copies the current directory to the clipboard. I'm happy with that workflow since I pretty much always have a terminal open anyway.

Re:Cdpath: Easily Navigate Directories in the Terminal by ametrau on Thursday December 07, 2023 @10:30AM (#38557425)
I do the exact same thing with bash aliases.

cdd is for the desktop.

Re:Cdpath: Easily Navigate Directories in the Terminal by VTimofeenko on Thursday December 07, 2023 @11:06AM (#38557959)
I have been using slightly customized bookmarks.zsh[1]. Bookmark a directoey by `bookmark .` and jump there later by double-tapping @ symbol. Works well with completions and stores bookmarks in .cache

[1]: https://github.com/VTimofeenko/monorepo-machine-config/blob/...