News for hackers. Stuff that matters.
Re:Ask HN: Small scripts, hacks and automations you're proud... by kkoncevicius on Sunday March 12, 2023 @01:43PM (#35123388)
I like minimal things that work well without adding complexity. This is more in the "hack" category, but here is a solution for bookmarking directories[1] that I am quite fond of:

  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`.

Another hack is using cd for jumping to the root directory of any git project. This one is borrowed[2]. It expands "cd" with an additional argument `cd ...` for jumping to the root of .git:

  cd() {
    case "$*" in
      '...')
        local dir
        dir="$(git rev-parse --show-toplevel 2>/dev/null)"
        if [[ $? -ne 0 ]]; then
          printf '%s\n' "${FUNCNAME[0]}: not inside a git repository"
          return 1
        fi
        set -- "$dir"
      ;;
    esac

    builtin cd "$@" && ls
  }
[1]: http://karolis.koncevicius.lt/posts/fast_navigation_in_the_c...

[2]: https://github.com/egladman/dotfiles/blob/master/src/bash.co...

Re:Ask HN: Small scripts, hacks and automations you're proud... by the_fury on Sunday March 12, 2023 @02:20PM (#35124005)
I've just spent the last few minutes playing with the bookmarks snippet. This is both elegant and immediately useful to me. Thanks for sharing!
Re:Ask HN: Small scripts, hacks and automations you're proud... by kkoncevicius on Sunday March 12, 2023 @02:32PM (#35124175)
Glad 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>

Re:Ask HN: Small scripts, hacks and automations you're proud... by p4l4g4 on Sunday March 12, 2023 @04:29PM (#35125823)
Awesome 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/

Re:Ask HN: Small scripts, hacks and automations you're proud... by meain on Monday March 13, 2023 @01:04AM (#35131321)
Re:Ask HN: Small scripts, hacks and automations you're proud... by behnamoh on Monday March 13, 2023 @02:05AM (#35131749)
I just use ranger and mark/bookmark directories like in Vim.
Re:Ask HN: Small scripts, hacks and automations you're proud... by gbrindisi on Monday March 13, 2023 @05:22AM (#35133143)
Nice!

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) }
Re:Ask HN: Small scripts, hacks and automations you're proud... by porcc on Tuesday March 14, 2023 @12:17AM (#35147396)
For people interested in this def look into autojump before doing this
Re:Ask HN: Small scripts, hacks and automations you're proud... by evgpbfhnr on Thursday March 23, 2023 @07:54PM (#35283203)
I'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)

Re:Ask HN: Small scripts, hacks and automations you're proud... by kkoncevicius on Saturday March 25, 2023 @01:41PM (#35305026)
Interesting, 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

If all these causes the build to fail then the maintainers of that build should be informed.