Live data from Hacker News

Scripts I wrote that I use all the time

evanhahn.com

171–180 of 408 posts

Re: Scripts I wrote that I use all the time

#171
post #4

It's been a while since I haven't read something as useful! There also some very niche stuff that I won't use but found funny

The nato phonetic alphabet one cracked me up. My dude you don't need that, call center employees don't know it, just say S as in Sugar like ur grandma used to.

I've found the NATO alphabet fairly common at call centers, with globalization being a factor.

Re: Scripts I wrote that I use all the time

#172
post #156
post #146

Earlier quoted context omitted.

Or more abstractly: post anything to the internet and people will always detail how you’re wrong. Sometimes that can be useful.

That seems to be especially true on HN. Other forums there is some of that as well, but HN it seems nearly every single comment section is like 75% (random number) pointing out faults in the posted article.

Although I normally loathe pedantic assholes, I've found the ones on HN seem to be more tolerable because they typically know they'll have to back up what they're saying with facts (and ideally citations).

I've found that pedantic conversations here seem to actually have a greater potential for me to learn something from them than other forums/social platforms. On other platforms, I see someone providing a pedantic response and I'll just keep moving on, but on HN, I get curious to not only see who wins the nerd fight, but also that I might learn at least one thing along the way. I like that it's had an effect on how I engage with comment sections.

Re: Scripts I wrote that I use all the time

#173
post #38

I have mkcd exactly ( I wonder how many of us do, it's so obvious) I have almost the same, but differently named with scratch(day), copy(xc), markdown quote(blockquote), murder, waitfor, tryna, etc. I used to use telegram-send with a custom notification sounnd a lot for notifications from long-running scripts if I walked away from the laptop. I used to have one called timespeak that would speak the time to me every h…

Doesn’t the built in `take` do exactly what `mkcd` does? Or is `take` a zsh/macos specific thing? Edit: looks like it’s a zsh thing

it's an .oh-my-zsh thing (~/.oh-my-zsh/lib/functions.zsh) but thanks, I didn't know about it.

Re: Scripts I wrote that I use all the time

#175
post #156

Earlier quoted context omitted.

That seems to be especially true on HN. Other forums there is some of that as well, but HN it seems nearly every single comment section is like 75% (random number) pointing out faults in the posted article.

Although I normally loathe pedantic assholes, I've found the ones on HN seem to be more tolerable because they typically know they'll have to back up what they're saying with facts (and ideally citations). I've found that pedantic conversations here seem to actually have a greater potential for me to learn something from them than other forums/social platforms. On other platforms, I see someone providing a pedantic r…

And the worst of it gets flagged and even dead-ed so most skip it after a bit, as I assumed would happen recently

https://news.ycombinator.com/item?id=45649771

Re: Scripts I wrote that I use all the time

#176

> wifi toggle this fella doesn't know what "toggle" means. in this context, it means "turn off if it's currently on, or turn on if it's currently off." this should be named `wifi cycle` instead. "cycle" is a good word for turning something off then on again. naming things is hard, but it's not so hard that you can't use the right word. :)

or wifi toggle-toggle!

Re: Scripts I wrote that I use all the time

#177
I find that I like working with the directory stack and having a shortened version of the directory stack in the title bar, e.g. by modifying the stock Debian .bashrc

  # If this is an xterm set the title to the directory stack
  case "$TERM" in
  xterm*|rxvt*)
      if [ -x ~/bin/shorten-ds.pl ]; then
    PS1="\[\e]0;\$(dirs -v | ~/bin/shorten-ds.pl)\a\]$PS1"
      else
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h:   \w\a\]$PS1"
      fi
      ;;
  \*)
      ;;
  esac
The script shorten_ds.pl takes e.g.

  0  /var/log/apt
  1  ~/Downloads
  2  ~
and shortens it to:

  0:apt 1:Downloads 2:~

  #!/usr/bin/perl -w
  use strict;
  my @lines;
  while () {
    chomp;
    s%^ (\d+)  %$1:%;
    s%:.*/([^/]+)$%:$1%;
    push @lines, $_
  }
  print join ' ', @lines;

That coupled with functions that take 'u 2' as shorthand for 'pushd +2' and 'o 2' for 'popd +2' make for easy manipulation of the directory stack:

  u() {
    if [[ $1 =~ ^[0-9]+$ ]]; then
      pushd "+$1"
    else
      pushd "$@"
    fi
  }

  o() {
    if [[ $1 =~ ^[0-9]+$ ]]; then
      popd "+$1"
    else
      popd "$@" # lazy way to cause an error
    fi
  }

Re: Scripts I wrote that I use all the time

#178

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…

`tar xf` autodetects compressed files now. You can replace any of your instances of tar with that.

Re: Scripts I wrote that I use all the time

#179

It's weird how the circle of life progresses for a developer or whatever. - When I was a fresh engineer I used a pretty vanilla shell environment - When I got a year or two of experience, I wrote tons of scripts and bash aliases and had a 1k+ line .bashrc the same as OP - Now, as a more tenured engineer (15 years of experience), I basically just want a vanilla shell with zero distractions, aliases or scripts and use…

man, i couldn't live without alias ..='cd ..' or alias ...='cd ../..' to this day, i still get tripped up when using a shell for the first time without those as they're muscle memory now.

I just use the autocd zsh shell option for this. And I also use `hash -d` to define shortcuts for common directories. Then just “executing” something like `~gh/apache/kafka` will cd to the right place.

Re: Scripts I wrote that I use all the time

#180
The scripts from my junk drawer (https://github.com/peterwwillis/junkdrawer) I use every day are 'kd' and 'gw', which use the Unix dialog command to provide an easy terminal UI for Kubectl and Git Worktrees (respectively)... I probably save 15+ minutes a day just flitting around in those UIs. The rest of the scripts I use for random things; tasks in AWS/Git/etc I can never remember, Terraform module refactoring, Bitbucket/GitHub user management, Docker shortcuts, random password generation, mirroring websites with Wget, finding duplicate files, etc.
Post reply on HN