Live data from Hacker News

Scripts I wrote that I use all the time

evanhahn.com

81–90 of 408 posts

Re: Scripts I wrote that I use all the time

#81
post #71

Earlier quoted context omitted.

I went through a similar cycle. Going back to simplicity wasn't about laziness for me, it was because i started working across a bunch more systems and didn't want to do my whole custom setup on all of them, especially ephemeral stuff like containers allocated on a cluster for a single job. So rather than using my fancy setup sometimes and fumbling through the defaults at other times, i just got used to operating mor…

You can apply your dotfiles to servers you SSH into rather easily. I'm not sure what your workflow is like but frameworks like zsh4humans have this built in, and there are tools like sshrc that handle it as well. Just automate the sync on SSH connection. This also applies to containers if you ssh into them.

I'm guessing you haven't worked in Someone Else's environment?

The amount of shit you'll get for "applying your dotfiles" on a client machine or a production server is going to be legendary.

Same with containers, please don't install random dotfiles inside them. The whole point of a container is to be predictable.

Re: Scripts I wrote that I use all the time

#84
I like this one.

  $ cat /usr/local/bin/awkmail
  #!/bin/gawk -f

  BEGIN { smtp="/inet/tcp/0/smtp.yourco.com/25";
  ORS="\r\n"; r=ARGV[1]; s=ARGV[2]; sbj=ARGV[3]; # /bin/awkmail to from subj  0) print                 |& smtp

  print "."                                |& smtp;  smtp |& getline j; print j
  print "quit"                             |& smtp;  smtp |& getline j; print j

  close(smtp) } # /inet/protocol/local-port/remote-host/remote-port

Re: Scripts I wrote that I use all the time

#85
post #33

> trash a.txt b.png moves `a.txt` and `b.png` to the trash. Supports macOS and Linux. The way you’re doing it trashes files sequentially, meaning you hear the trashing sound once per file and ⌘Z in the Finder will only restore the last one. You can improve that (I did it for years) but consider just using the `trash` commands which ships with macOS. Doesn’t use the Finder, so no sound and no ⌘Z, but it’s fast, offici…

> Why prioritise node instead of jq?

In powershell I just do

    > echo '{"foo": "bar"} | ConvertFrom-Json | ConvertTo-Json
    {
        "foo": "bar"
    }
But as a function

Re: Scripts I wrote that I use all the time

#86
My fav script to unpack anything, found a few years ago somewhere

      # ex - archive extractor
      # usage: ex 
      function ex() {
          if [ -f $1 ] ; then
          case $1 in
              *.tar.bz2) tar xjf $1 ;;
              *.tar.gz) tar xzf $1 ;;
              *.tar.xz) tar xf $1 ;;
              *.bz2) bunzip2 $1 ;;
              *.rar) unrar x $1 ;;
              *.gz) gunzip $1 ;;
              *.tar) tar xf $1 ;;
              *.tbz2) tar xjf $1 ;;
              *.tgz) tar xzf $1 ;;
              *.zip) unzip $1 ;;
              *.Z) uncompress $1;;
              *.7z) 7z x $1 ;;
              *) echo "'$1' cannot be extracted via ex()" ;;
          esac
          else
              echo "'$1' is not a valid file"
          fi
      }

Re: Scripts I wrote that I use all the time

#87

As a bonus, I prepend my custom aliases or scripts with my user name and hyphen (i.e helicaltwine-). It helps me recall rarely used scripts when I need them and forget the names.

I follow a similar but more terse pattern. I prepend them all with a comma, and I have yet to find any collisions. If you're using bash (and I assume posix sh as well), the comma character has no special meaning, so this is quite a nice use for it. I agree that it's nice to type "," and see all my custom scripts appear.

Re: Scripts I wrote that I use all the time

#88

My fav script to unpack anything, found a few years ago somewhere # ex - archive extractor # usage: ex function ex() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.tar.xz) tar xf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjf $1 ;; *.tgz) tar xzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1;; *.7z) 7z x $1 ;; *) echo "'$1' can…

`aunpack` does the trick for me.

Re: Scripts I wrote that I use all the time

#89

Nice! Tangentially related: I built a (MacOS only) tool called clippy to be a much better pbcopy. It was just added to homebrew core. Among other things, it auto-detects when you want files as references so they paste into GUI apps as uploads, not bytes. clippy image.png # then paste into Slack, etc. as upload clippy -r # copy most recent download pasty # copy file in Finder, then paste actual file here https://githu…

Adding the word "then" to your first comment would have helped me: (lacking context, I thought the comments explained what the command does, as is common convention)

  clippy image.png   # then paste into Slack, etc. as upload
Also:

  pasty              # paste actual file, after copying file in Finder

Re: Scripts I wrote that I use all the time

#90
post #71

Earlier quoted context omitted.

You can apply your dotfiles to servers you SSH into rather easily. I'm not sure what your workflow is like but frameworks like zsh4humans have this built in, and there are tools like sshrc that handle it as well. Just automate the sync on SSH connection. This also applies to containers if you ssh into them.

I'm guessing you haven't worked in Someone Else's environment? The amount of shit you'll get for "applying your dotfiles" on a client machine or a production server is going to be legendary. Same with containers, please don't install random dotfiles inside them. The whole point of a container is to be predictable.

If, in the year 2025, you are still using a shared account called "root" (password: "password"), and it's not a hardware switch or something (and even they support user accounts these days), I'm sorry, but you need to do better. If you're the vendor, you need to do better, if you're the client, you need to make it an issue with the vendor and tell them they need to do better. I know, it's easy for me to say from the safety of my armchair at 127.0.0.1. I've got some friends in IT doing support that have some truly horrifying stories. But holy shit why does some stuff suck so fucking much still. Sorry, I'm not mad at you or calling you names, it's the state of the industry. If there were more pushback on broken busted ass shit where this would be a problem, I could sleep better at night, knowing that there's somebody else that isn't being tortured.
Post reply on HN