‹ BackHN Continuity

Thread

Small programming tricks

681 points · 294 comments · signa11

  1. GNOMES · · focus · HN ↗
    Simple trick I use almost daily for navigating backwards to an exact directory:

    <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;GNOMES&#x2F;6bf65926648e260d8023aebb9ede9573" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;GNOMES&#x2F;6bf65926648e260d8023aebb9ede9...

    I use this often instead of chaining together multiple &#x27;..&#x2F;..&#x27;.

    Also nice for when I use Zoxide to CD into a deep nested directory. I quickly found out unless you manually CD each hop, the different parent directories aren&#x27;t added to your Zoxide DB. (I have come across snippits to recursively CD into all directories in a path to &quot;prepopulate&quot; Zoxide).

    I made this to jump directly from say `&#x2F;foo&#x2F;bar&#x2F;batz&#x2F;abc&#x2F;123` to `&#x2F;foo&#x2F;bar&#x2F;batz`.

    1. zh3 · · focus · HN ↗
      Somewhat along the same lines, as I regularly SSH to other hosts with the same network filesystem mounts, &#x27;scd&#x27; starts an SSH session on a remote host in the same directory.

        #!&#x2F;bin&#x2F;bash
        # SSH to remote system and change into same (current) directory
        DIR=$(pwd)
        ssh -t $1 &quot;cd $DIR; bash -l -i&quot;
      1. bandie91 · · focus · HN ↗
        i made `rr` (remote run) for a use-case very similar to this.

        it expects the remote fs is mounted under ...&#x2F;ssh&#x2F;HOSTNAME&#x2F; and runs any command in that dir on the remote host. if it is not the root which is mounted, looks up mtab for the remote base directory.

        <a href="https:&#x2F;&#x2F;codeberg.org&#x2F;hband&#x2F;hband-tools&#x2F;src&#x2F;branch&#x2F;master&#x2F;user-tools&#x2F;rr" rel="nofollow">https:&#x2F;&#x2F;codeberg.org&#x2F;hband&#x2F;hband-tools&#x2F;src&#x2F;branch&#x2F;master&#x2F;use...

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.