[HN Gopher] Scripts I wrote that I use all the time
___________________________________________________________________
Scripts I wrote that I use all the time
Author : speckx
Score : 370 points
Date : 2025-10-22 14:53 UTC (8 hours ago)
(HTM) web link (evanhahn.com)
(TXT) w3m dump (evanhahn.com)
| weregiraffe wrote:
| Looks very useful!
| southwindcg wrote:
| Regarding the `line` script, just a note that sed can print an
| arbitrary line from a file, no need to invoke a pipeline of cat,
| head, and tail: sed -n 2p file
|
| prints the second line of file. The advantage sed has over this
| line script is it can also print more than one line, should you
| need to: sed -n 2,4p file
|
| prints lines 2 through 4, inclusive.
| tonmoy wrote:
| It is often useful to chain multiple sed commands and sometimes
| shuffle them around. In those cases I would need to keep
| changing the fist sed. Sometimes I need to grep before I sed.
| Using cat, tail and head makes things more modular in the long
| run I feel. It's the ethos of each command doing one small
| thing
| southwindcg wrote:
| True, everything depends on what one is trying to do at the
| time.
| 1-more wrote:
| yeah I almost always start with `cat` but I still pipe it
| into `sed -n 1,4p`
| wiether wrote:
| 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
| giraffe_lady wrote:
| 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.
| ericyd wrote:
| The nato phonetic alphabet is still useful even if the other
| party doesn't know it, I've used it a bunch of times on the
| phone to spell out my 10- letter last name. Saves quite a lot
| of time and energy for me vs saying "letter as in word" for
| each letter.
| SoftTalker wrote:
| > saying "letter as in word" for each letter
|
| Which often just confuses things further.
|
| Me: My name is "Farb" F-A-R-B. B as in Baker.
|
| Them: Farb-Baker, got it.
| giraffe_lady wrote:
| "M as in Mancy."
| giraffe_lady wrote:
| Right but it's not much more useful than any other phonetic
| alphabet the other party doesn't know, including the one
| you make up on the spot.
| sfink wrote:
| If you're me, it's still useful because the ones I make
| up on the spot aren't great.
|
| "S-T-E-V-E @ gmail.com, S as in sun, T as in taste, ..."
| "Got it, fpeve."
| dragonwriter wrote:
| I dunno, there's a pretty good chance that the one that
| people spent time and effort designing to replace earlier
| efforts with the goal of reducing potential ambiguity and
| for use over noisy connections with expectation that
| mistakes could cost lives is probably better than what
| you improvise on the spot
| vunderba wrote:
| Exactly. The listening party doesn't need to have knowledge
| of the NATO alphabet to still benefit from it since they
| are just regular English words.
|
| I once had someone sound out a serial number over a spotty
| phone connection years ago and they said _" N as in NAIL"_.
| You know what sounds a lot like NAIL? MAIL.
|
| And that is why we don't just arbitrarily make up phonetic
| alphabets.
| senkora wrote:
| I once had the customer service agent for Iberia (the Spanish
| airline) confirm my confirmation number with me using it.
|
| It worked with me and I guess it must have usually worked for
| him in most of his customer interactions.
| kelvinjps10 wrote:
| When I worked in customer service, I asked a teammate what I
| could do to spell back something the customer said, and she
| taught me that system, it helped me a lot.
| WCSTombs wrote:
| The NATO alphabet is made of commonly known words that are
| hard to misspell and hard to mishear (at least the initial
| phonemes). The person on the other end doesn't need to be
| able to recite the words, they just need to be able to hear
| "november" and recognize that it starts with N.
| soiltype wrote:
| This is exactly the kind of stuff I'm most interested in finding
| on HN. How do other developers work, and how can I get better at
| my work from it?
|
| What's always interesting to me is how many of these I'll see and
| initially think, "I don't really need that." Because I'm well
| aware of the effect (which I'm sure has a name - I suppose it's
| similar to induced demand) of "make $uncommon_task much cheaper"
| -> "$uncommon_task becomes the basis of an entirely new
| workflow/skill". So I'm going to try out most of them and see
| what sticks!
|
| Also: really love the style of the post. It's very clear but also
| includes super valuable information about how often the author
| actually uses each script, to get a sense ahead of time for which
| ones are more likely to trigger the effect described above.
|
| A final aside about my own workflows which betrays my origins...
| for some of these operations and for others i occasionally need,
| I'll just open a browser dev tools window and use JS to do it,
| for example lowercasing a string :)
| chipsrafferty wrote:
| I'd love to see a cost benefit analysis of the author's
| approach vs yours, which includes the time it took the author
| to create the scripts, remember/learn to use them/reference
| them when forgetting syntax, plus time spent migrating whenever
| changing systems.
| te_cima wrote:
| why is this interesting to you? the whole point of doing all
| of this is to be more efficient in the long run. of course
| there is an initial setup cost and learning curve after which
| you will hopefully feel quite efficient with your development
| environment. you are making it sound like it is not worth the
| effort because you have to potentially spend time learning
| "it"? i do not believe that it takes long to "learning" it,
| but of course it can differ a lot from person to person. your
| remarks seem like non-issues to me.
| akersten wrote:
| It's interesting because there's a significant chance one
| wastes more time tinkering around with custom scripts than
| saving in the long run. See https://xkcd.com/1205/
|
| For example. The "saves 5 seconds task that I do once a
| month" from the blog post. Hopefully the author did not
| spend more than 5 minutes writing said script and
| maintaining it, or they're losing time in the long run.
| kelvinjps10 wrote:
| I find that now with AI, you can make scripts very
| quickly, reducing the time to write them by a lot. There
| is still some time needed for prompting and testing but
| still.
| karczex wrote:
| Sometimes it's rather matter of sanity than time management.
| I once created systemd service which goes to company web page
| and downloads some files which I sometimes need. This script
| was pretty hacky, and writing it took me a lot of time -
| probably more than clicking manually on this page in the long
| run. But clicking it so annoying, that I feel it was totally
| worth.
| taejavu wrote:
| Not all time is created equal. I'll happily invest more time
| than I'll ever get back in refining a script or vim config or
| whatever, so that later, when I'm busy and don't have time to
| muck around, I can stay in the flow and not be annoyed by
| distractions.
| fragmede wrote:
| https://raw.githubusercontent.com/fliptheweb/bash-shortcuts-...
| has served me very well.
| pmontra wrote:
| I also have a radio script to play internet streams with mpv (?).
| Other random stuff
|
| A password or token generator, simple or complicated random text.
|
| Scripts to list, view and delete mail messages inside POP3
| servers
|
| n, to start Nautilus from terminal in the current directory.
|
| lastpdf, to open the last file I printed as PDF.
|
| lastdownload, to view the names of the n most recent files in the
| Downloads directory.
|
| And many more but those are the ones that I use often and I
| remember without looking at ~/bin
| oceanplexian wrote:
| 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 native UNIX implementations. If it's
| more complicated than that, I'll code it in Python or Go.
| D13Fd wrote:
| I would still call my Python scripts "scripts." I don't think
| the term "scripts" is limited to shell scripts.
| trenchpilgrim wrote:
| When I had one _nix computer, I wanted to customize it heavily.
|
| Now I have many _nix computers and I want them consistent and
| with only the most necessary packages installed.
| ozim wrote:
| Besides many nix computers I also have wife, dog, children,
| chores, shopping to be done. Unlike when I was young engineer
| I could stay all night fiddling with bash scripts and
| environments.
| sestep wrote:
| For anyone else reading this comment who was confused because
| this seems like the opposite of what you'd expect about Nix:
| Hacker News ate the asterisks and turned them into italics.
| fragmede wrote:
| use a backslash. \\*
|
| (had to use a double backslash to render that correctly)
| latexr wrote:
| Or two consecutive asterisks: ** becomes *
| nonethewiser wrote:
| On the other hand, the author seems to have a lot of experience
| as well.
|
| Personally I tend to agree... there is a very small subset of
| things I find worth aliasing. I have a very small amount and
| probably only use half of them regularly. Frankly I wonder how
| my use case is so different.
|
| edit: In the case of the author I guess he's probably wants to
| live in the terminal full time. And perhaps offline. there is a
| lot of static data he's stored like http status codes:
| https://codeberg.org/EvanHahn/dotfiles/src/commit/843b9ee13d...
|
| In my case i'd start typing it in my browser then just click
| something i've visited 100 times before. There is something to
| be said about reducing that redundant network call but I dont
| think it makes much practical difference and the mental
| mapping/discoverability of aliases isnt nothing.
| jamesbelchamber wrote:
| I am going through a phase of working with younger engineers
| who have many dotfiles, and I just think "Oh, yeh, I remember
| having lots of dotfiles. What a hassle that was."
|
| Nowadays I just try to be quite selective with my tooling and
| learn to change with it - "like water", so to speak.
|
| (I say this with no shade to those who like maintaining their
| dotfiles - it takes all sorts :))
| denimnerd42 wrote:
| I prefer using kubectl than any other method so i have plenty
| of functions to help with that. I'd never consider using python
| or go for this although I do have plenty of python and go
| "scripts" on my path too.
| planb wrote:
| Yeah - been there, done that, too. I feel like the time I gain
| from having a shortcut is often less that what I wound need to
| maintain it or to remember the real syntax when I'm on a
| machine where it's not available (which happens quite often in
| my case). I try to go with system defaults as much as possible
| nowadays.
| eikenberry wrote:
| Prepare to swing back again. With nearly 30 years experience I
| find the shell to be the best integration point for so many
| things due to its ability to adapt to whatever is needed and
| its universal availability. My use of a vanilla shell has been
| reduced to scripting cases only.
| fragmede wrote:
| If you come through the other side, you set up LocalCommand in
| your .ssh/config which copies your config to every server you
| ssh to, and get your setup everywhere.
| grimgrin wrote:
| this is how it works for you
|
| as a person who loves their computer, my ~/bin is full. i
| definitely (not that you said this) do not think "everything i
| do has to be possible on every computer i am ever shelled into"
|
| being a person on a computer for decades, i have tuned how i
| want to do things that are incredibly common for me
|
| though perhaps you're referring to work and not hobby/life
| stronglikedan wrote:
| Different strokes for different folks - tenured engineers just
| settle into whatever works best for them.
| chis wrote:
| I think it's more likely to say that this comes from a place of
| laziness than some enlightened peak. (I say this as someone who
| does the same, and is lazy).
|
| When I watch the work of coworkers or friends who have gone
| these rabbit holes of customization I always learn some
| interesting new tools to use - lately I've added atuin, fzf,
| and a few others to my linux install
| heyitsguay wrote:
| 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 more efficiently with the defaults.
| nijaru wrote:
| 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.
| theshrike79 wrote:
| 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.
| fragmede wrote:
| 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.
| nijaru wrote:
| Do you have experience with these tools? Some such as
| sshrc only apply temporarily per session and don't
| persist or affect other users. I keep plain 'ssh'
| separate from shell functions that apply dotfiles and use
| each where appropriate. You can also set up temporary
| application yourself pretty easily.
| YouAreWRONGtoo wrote:
| Someone else's environment? That should never happen. You
| should get your own user account and that's it.
| bigwheels wrote:
| Atuin is new to me!
|
| https://github.com/atuinsh/atuin
|
| Discussed 4 months ago:
|
| _Atuin - Magical Shell History_
| https://news.ycombinator.com/item?id=44364186 - June 2025, 71
| comments
| apprentice7 wrote:
| It's the bell curve meme all along.
| imiric wrote:
| I've heard this often, but I'm going on ~25 years of using
| Linux, and I would be lost without my dotfiles. They represent
| years of carefully crafting my environment to suit my
| preferences, and without them it would be like working on
| someone else's machine. Not impossible, just very cumbersome.
|
| Admittedly, I've toned down the configs of some programs, as my
| usage of them has evolved or diminished, but many are still
| highly tailored to my preferences. For example, you can't
| really use Emacs without a considerable amount of tweaking. I
| mean, you technically _could_ , but such programs are a blank
| slate made to be configured (and Emacs is awful OOB...).
| Similarly for zsh, which is my main shell, although I keep bash
| more vanilla. Practically the entire command-line environment
| and the choices you make about which programs to use can be
| considered configuration. If you use NixOS or Guix, then that
| extends to the entire system.
|
| If you're willing to allow someone else to tell you how you
| should use your computer, then you might as well use macOS or
| Windows. :)
| russellbeattie wrote:
| The moment of true enlightenment is when you finally decide to
| once and for all memorize all the arguments and their order for
| those command line utilities that you use at an interval that's
| just at the edge of your memory: xargs, find, curl, rsync, etc.
|
| That, plus knowing how to parse a man file to actually
| understand how to use a command (a skill that takes years to
| master) pretty much removes the need for most aliases and
| scripts.
| subsection1h wrote:
| > _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_
|
| Does this mean that you learned to code to earn a paycheck? I'm
| asking because I had written hundreds of scripts and Emacs Lisp
| functions to optimize my PC before I got my first job.
| vunderba wrote:
| Nice. I have a bash script similar to the one listed "removeexif"
| called _prep_for_web_ which takes any image file (PNG, BMP, JPG,
| WebP), scrubs EXIF data, checks for transparency and then
| compresses it to either JPG using MozJPEG or to PNG using
| PNGQuant.
|
| [1] https://github.com/mozilla/mozjpeg
|
| [2] https://pngquant.org
| SoftTalker wrote:
| Some cool things here but in general I like to learn and use the
| standard utilities for most of this. Main reason is I hop in and
| out of a lot of different systems and my personal aliases and
| scripts are not on most of them.
|
| sed, awk, grep, and xargs along with standard utilities get you a
| long long way.
| pinkmuffinere wrote:
| I totally agree with this, I end up working on many systems,
| and very few of them have all my creature comforts. At the same
| time, really good tools can stick around and become impactful
| enough to ship by default, or to be easily apt-get-able. I
| don't think a personal collection of scripts is the way, but
| maybe a well maintained package.
| dannyobrien wrote:
| Historical note: getting hold of these scripts by chatting to
| various developers was the motivation for the original 2004
| "lifehacks" talk[1][2]. If you ever get into an online argument
| over what is a "life hack" and what isn't, feel free to use short
| scripts like these as the canonical example.
|
| Otherwise, I am happy to be pulled into your discussion, Marshall
| McLuhan style[3] to adjudicate, for a very reasonable fee.
|
| [1] https://craphound.com/lifehacksetcon04.txt
|
| [2] https://archive.org/details/Notcon2004DannyOBrienLifehacks
|
| [3] https://www.openculture.com/2017/05/woody-allen-gets-
| marshal...
| helicaltwine wrote:
| 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.
| dunb wrote:
| 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 ",<tab>" and see all my custom
| scripts appear.
| headgasket wrote:
| if you use x0vnc (useful if you use a linux machine both from the
| attached screen and from vnc, and in a bunch of other scenarios),
| copy and paste to and fro the vnc client is not implemented,
| quite frustrating. here's 2 scripts that does that for you, I now
| use this _all day_. https://github.com/francoisp/clipshare
| latexr wrote:
| > 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, official, and still allows "Put Back".
|
| > jsonformat takes JSON at stdin and pretty-prints it to stdout.
|
| Why prioritise node instead of jq? The latter is considerably
| less code and even comes preinstalled with macOS, now.
|
| > uuid prints a v4 UUID. I use this about once a month.
|
| Any reason to not simply use `uuidgen`, which ships with macOS
| and likely your Linux distro?
|
| https://www.man7.org/linux/man-pages/man1/uuidgen.1.html
| sedatk wrote:
| and it's `New-Guid` in PowerShell.
| rbonvall wrote:
| Python also pretty-prints out of the box: $
| echo '{ "hello": "world" }' | python3 -m json.tool {
| "hello": "world" }
| tester457 wrote:
| I am not the author, but my bet is that he didn't know of its
| existence.
|
| The best part about sharing your config or knowledge is that
| someone will always light up your blind spots.
| gigatexal wrote:
| Exactly! I didn't know macOS ships JQ or the uuidgen tool.
| Very cool
| shortrounddev2 wrote:
| > Why prioritise node instead of jq?
|
| In powershell I just do > echo '{"foo":
| "bar"} | ConvertFrom-Json | ConvertTo-Json {
| "foo": "bar" }
|
| But as a function
| mmmm2 wrote:
| `trash` is good to know, thanks! I'd been doing: "tell app
| \"Finder\" to move {%s} to trash" where %s is a comma separated
| list of "the POSIX file <path-to-file>".
| Grimburger wrote:
| Shoutout to rip as an alternative to rm and trash:
|
| https://github.com/nivekuil/rip
| frumplestlatz wrote:
| For trash on macOS, I recommend https://github.com/ali-
| rantakari/trash
|
| Does all the right things and works great.
|
| There's a similar tool that works well on Linux/BSDs that I've
| used for years, but I don't have my FreeBSD desktop handy to
| check.
| YouAreWRONGtoo wrote:
| Instead of trash, reimplementing rm (to only really delete
| after some time or depending on resource usage or to shred of
| you are paranoid if the goal is to really delete something) or
| using zfs makes much more sense.
| jrm4 wrote:
| Broadly, I very much _love_ this approach to things and wish it
| was more "acceptable?" It reminds me of the opposite of things
| like "the useless use of cat" which to me is one of the WORST
| meme-type-things in this space.
|
| Like, it's okay -- even good -- for the tools to bend to the user
| and not the other way around.
| yipbub wrote:
| 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 hour or half hour.
|
| I have go_clone that clones a repo into GOPATH which I use for
| organising even non-go projects long after putting go projects in
| GOPATH stopped being needed.
|
| I liked writing one-offs, and I don't think it's premature
| optimization because I kept getting faster at it.
| justusthane wrote:
| Obviously that script is more convenient, but if you're on a
| system where you don't have it, you can do the following
| instead: mkdir /some/dir cd !$
| (or cd <alt+.>)
| taejavu wrote:
| 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
| WhyNotHugo wrote:
| > cpwd copies the current directory to the clipboard. Basically
| pwd | copy. I often use this when I'm in a directory and I want
| use that directory in another terminal tab; I copy it in one tab
| and cd to it in another. I use this once a day or so.
|
| You can configure your shell to notify the terminal of directory
| changes, and then use your terminal's "open new window" function
| (eg: ctrl+shift+n) to open a new window retaining the current
| directory.
| yegle wrote:
| The markdownquote can be replaced by (at least in vim):
|
| ^ (jump to the beginning)
|
| ctrl+v (block selection)
|
| j (move cursor down)
|
| shift+i (bulk insert?)
|
| type ><space>
|
| ESC
| javier123454321 wrote:
| :'<,'>s/.*$/> \0/ also
| fragmede wrote:
| Where are the one letter aliases? My life got better after I
| _alias k=kubectl_
| interestica wrote:
| Share yours!
|
| I use this as a bookmarklet to grab the front page of the new
| york times (print edition). (You can also go back to any date up
| to like 2011)
|
| I think they go out at like 4 am. So, day-of, note that it will
| fail if you're in that window before publishing.
| javascript:(()=>{let d=new Date(new Date().toLocaleString('en-US'
| ,{timeZone:'America/New_York'})),y=d.getFullYear(),m=('0'+(d.getM
| onth()+1)).slice(-2),g=('0'+d.getDate()).slice(-2);location.href=
| `https://static01.nyt.com/images/${y}/${m}/${g}/nytfrontpage/scan
| .pdf`})()
| xiphias2 wrote:
| An important advantage of aliases was not mentioned: I see
| everything in one place and can easily build aliases on top of
| other aliases without much thinking.
|
| Anyways, my favourite alias that I use all the time is this:
| alias a='nvim ~/.zshrc && . ~/.zshrc'
|
| It solves the ,,not loaded automatically'' part at least for the
| current terminal
| munchlax wrote:
| mksh is already the MirBSD Korn SHell
| o11c wrote:
| I keep meaning to generalize this (directory target, multiple
| sources, flags), but I get quite a bit of mileage out of this
| `unmv` script even as it is: #!/bin/sh if
| test "$#" != 2 then echo 'Error: unmv must have
| exactly 2 arguments' exit 1 fi exec mv "$2"
| "$1"
| alentred wrote:
| > alphabet just prints the English alphabet in upper and
| lowercase. I use this surprisingly often (probably about once a
| month)
|
| I genuinely wonder, why would anyone want to use this, often?
| revicon wrote:
| I have a bunch of little scripts and aliases I've written over
| the years, but none are used more than these...
|
| alias ..='cd ..'
|
| alias ...='cd ../..'
|
| alias ....='cd ../../..'
|
| alias .....='cd ../../../..'
|
| alias ......='cd ../../../../..'
|
| alias .......='cd ../../../../../..'
| Bishonen88 wrote:
| up() { local d="" for ((i=1; i<=$1; i++)); do d="../$d" done cd
| "$d" }
|
| up 2, up 3 etc.
| vunderba wrote:
| Does zsh support this out-of-the-box? Because I definitely
| never had to setup any of these kinds of aliases but have been
| using this shorthand dot notation for years.
| machomaster wrote:
| Yes it does.
| Noumenon72 wrote:
| Not on my Mac. zsh: permission denied: ..
| zsh: command not found: ...
| tacone wrote:
| I have setup a shortcut: alt+. to run cd.., it's pretty cool.
|
| I also aliased - to run cd -
| fragmede wrote:
| but alt-. in bash is used for pasting the last argument to
| the previous command into the current one.
| cosmos0072 wrote:
| I need this *so* often that I programmed my shell to execute
| 'cd ..' every time I press KP/ i.e. '/' on the keypad, without
| having to hit Return.
|
| Other single-key bindings I use often are:
|
| KP* executes 'ls'
|
| KP- executes 'cd -'
|
| KP+ executes 'make -j `nproc`'
| holyknight wrote:
| cool collection
| sedatk wrote:
| > `rn` prints the current time and date using date and cal.
|
| And you can type `rn -rf *` to see all timezones recursively. :)
| javier123454321 wrote:
| This is one area that I've found success in vibe coding with.
| Making scripts for repetitive tasks that are just above the
| complexity threshold where the math between automating and doing
| manually is not so clear. I have copilot generate the code for me
| and honestly I don't care too much of its quality, extensibility,
| and are easy enough to read through where I don't feel like my
| job is AI pr reviewer.
| samtrack2019 wrote:
| no offense but a lot of those script are pretty hacky they may
| work for the user but i would not use them without making sure to
| review them and adapt them to my workflow
| nberkman wrote:
| 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://github.com/neilberkman/clippy / brew install clippy
| Tempest1981 wrote:
| 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
| nberkman wrote:
| Updated, I appreciate it!
| gigatexal wrote:
| Awesome. Gonna check this out.
| thibran wrote:
| 30% of the productivity hacks can be archived in vanilla Nushell.
| some_guy_nobel wrote:
| These are great, and I have a few matching myself.
|
| Here are some super simple ones I didn't see that I use almost
| every day:
|
| cl="clear"
|
| g="git"
|
| h="history"
|
| ll="ls -al"
|
| path='echo -e ${PATH//:/\\\n}'
|
| lv="live-server"
|
| And for common navigation:
|
| dl="cd ~/Downloads"
|
| dt="cd ~/Desktop"
| fragmede wrote:
| k=kubectl
| vzaliva wrote:
| A lot of these scripts could be just shell aliases.
| 27theo wrote:
| OP links to a long blog post with reasons for using scripts
|
| https://evanhahn.com/why-alias-is-my-last-resort-for-aliases...
| chasil wrote:
| 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 <
| in print "helo " ENVIRON["HOSTNAME"] |& smtp;
| smtp |& getline j; print j print "mail from:" s
| |& smtp; smtp |& getline j; print j if(match(r, ","))
| { split(r, z, ",") for(y in z) { print "rcpt to:"
| z[y] |& smtp; smtp |& getline j; print j } }
| else { print "rcpt to:" r |& smtp; smtp |&
| getline j; print j } print "data"
| |& smtp; smtp |& getline j; print j print "From:" s
| |& smtp; ARGV[2] = "" # not a file print "To:" r
| |& smtp; ARGV[1] = "" # not a file if(length(sbj)) {
| print "Subject: " sbj |& smtp; ARGV[3] = "" } # not a file
| print "" |& smtp
| while(getline > 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
| alberand wrote:
| My fav script to unpack anything, found a few years ago somewhere
| # ex - archive extractor # usage: ex <file>
| 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 }
| alanbernstein wrote:
| `aunpack` does the trick for me.
| juancroldan wrote:
| That's brilliant. Now I need its compressing counterpart.
| gigatexal wrote:
| Very nice and clean
| rbonvall wrote:
| I use dtrx, which also ensures that all files are extracted
| into a folder.
| YouAreWRONGtoo wrote:
| Now, add inotify and a systemd user service and you would be
| getting somewhere. Also packaged versions of that exist
| already.
|
| So, you created a square wheel, instead of a NASA wheel.
| SuperHeavy256 wrote:
| I hope to see an operating system with these scripts as built-in,
| because they are so intuitive and helpful! Which OS will be the
| first to take this on?
| CrimpCity wrote:
| Lately I've been using caffeinate to run long running scripts
| without interruption from sleep on Mac. Nothing crazy but could
| be useful to newer devs.
| sid- wrote:
| Why dont we have mkcd in linux natively boggles my mind :)
| taejavu wrote:
| zsh has a `take` utility that is exactly this
| Tempest1981 wrote:
| > alphabet just prints the English alphabet in upper and
| lowercase. I use this surprisingly often
|
| I'm curious to hear some examples (feel like I'm missing out)
| lillesvin wrote:
| Obviously, to each their own, but to me, this is an overwhelming
| amount of commands to remember on top of all the ones they are
| composed of that you will likely need to know anyway --
| regardless if all the custom ones exist.
|
| Like, I'd have to remember both `prettypath` and `sed`, and given
| that there's hardly any chance I'll not need `sed` in other
| situations, I now need to remember two commands instead of one.
|
| On top of that `prettypath` only does s/:/\\\n/ on my path, not
| on other strings, making its use extremely narrow. But generally
| doing search and replace in a string is incredibly useful, so I'd
| personally rather just use `sed` directly and become more
| comfortable with it. (Or `perl`, but the point is the same.)
|
| As I said, that's obviously just my opinion, if loads of custom
| scripts/commands works for you, all the more power to you!
| naikrovek wrote:
| > 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. :)
| Noumenon72 wrote:
| While you're creating and testing aliases, it's handy to source
| your ~/.zshrc whenever you edit it: alias
| vz="vim ~/.zshrc && . ~/.zshrc"
|
| I alias mdfind to grep my .docx files on my Mac:
| docgrep() { mdfind "\"$@\"" -onlyin /Users/xxxx/Notes
| 2> >(grep --invert-match ' \[UserQueryParser\] ' >&2) | grep -v
| -e '/Inactive/' | sort }
|
| I use an `anon` function to anonymize my Mac clipboard when I
| want to paste something to the public ChatGPT, company Slack,
| private notes, etc. I ran it through itself before pasting it
| here, for example. anonymizeclipboard() {
| my_user_id=xxxx account_ids="1234567890|1234567890"
| #regex corp_words="xxxx|xxxx|xxxx|xxxx|xxxx" #regex
| project_names="xxxx|xxxx|xxxx|xxxx|xxxx" # regex
| pii="xxxx|xxxx|xxxx|xxxx|xxxx|xxxx" # regex
| hostnames="xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx" # regex
| # anonymize IPs pbpaste | sed -E -e
| 's/([0-9]{1,3})\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/\1.x.x.x/g' \
| -e "s/(${corp_words}|${project_names}|${my_user_id}|${pii}|${host
| names})/xxxx/g" -e "s/(${account_ids})/1234567890/g" | pbcopy
| pbpaste } alias anon=anonymizeclipboard
|
| It prints the new clipboard to stdout so you can inspect what
| you'll be pasting for anything it missed.
| amterp wrote:
| Love this, lots of great ideas I'll be stealing :)
|
| Folks interested in scripting like this might like this tool I'm
| working on https://github.com/amterp/rad
|
| Rad is built specifically for writing CLI scripts and is perfect
| for these sorts of small to medium scripts, takes a declarative
| approach to script arguments, and has first-class shell command
| integration. I basically don't write scripts in anything else
| anymore.
| andai wrote:
| alias mpa='mpv --no-video' mpa [youtube_url]
|
| I use this to listen to music / lectures in the terminal.
|
| I think it needs yt-dlp installed -- and reasonably up to date,
| since YouTube keeps breaking yt-dlp... but the updates keep
| fixing it :)
| andai wrote:
| On the subject of yt-dlp, I use it to get (timestamped)
| transcripts from YouTube, to shove into LLMs for summaries.
| ytsub() { yt-dlp \ --write-sub \
| --write-auto-sub \ --sub-lang "en.*" \
| --skip-download \ "$1" && vtt2txt }
| ytsub [youtube_url]
|
| Where vtt2txt is a python script -- slightly too long to paste
| here -- which strips out the subtitle formatting, leaving a
| (mostly) human readable transcript.
| sorenjan wrote:
| I got a ccurl python script that extracts the cookies from my
| Firefox profile and then passes those on to curl, that way I can
| get webpages where I'm logged in.
| Noumenon72 wrote:
| > ocr my_image.png extracts text from an image and prints it to
| stdout. It only works on macOS
|
| The Mac Shortcut at https://github.com/e-kotov/macos-shortcuts
| lets you select a particular area of the screen (as with Cmd-
| Shift-4) and copies the text out of that, allowing you to copy
| exactly the text you need from anywhere on your screen with one
| keyboard shortcut. Great for popups with unselectable text, and
| copying error messages from coworkers' screenshares.
| andai wrote:
| I use these two all the time to encode and cut mp4s.
|
| The flags are for maximum compatibility (e.g. without them, some
| MP4s don't play in WhatsApp, or Discord on mobile, or whatever.)
| ffmp4() { input_file="$1"
| output_file="${input_file%.*}_sd.mp4" ffmpeg -i
| "$input_file" -c:v libx264 -crf 33 -profile:v baseline -level 3.0
| -pix_fmt yuv420p -movflags faststart "$output_file"
| echo "Compressed video saved as: $output_file" }
|
| ffmp4 foo.webm
|
| -> foo_sd.mp4 fftime() {
| input_file="$1"
| output_file="${input_file%.*}_cut.mp4" ffmpeg -i
| "$input_file" -c copy -ss "$2" -to "$3" "$output_file"
| echo "Cut video saved as: $output_file" }
|
| fftime foo.mp4 01:30 01:45
|
| -> foo_cut.mp4
|
| Note, fftime copies the audio and video data without re-encoding,
| which can be a little janky, but often works fine, and can be
| much (100x) faster on large files. To re-encode just remove "-c
| copy"
| chamomeal wrote:
| I started writing way more utility scripts when I found babashka.
| Magic of clojure, instant startup, easy to shell out to any other
| command, tons of useful built in stuff, developing with the REPL.
| It's just a good time!!
| banku_brougham wrote:
| this is really great. at some point i gavenup on being more
| efficient on the terminal, but many pain points are solved by
| your work
| hiq wrote:
| I've started using snippets for code reviews, where I find myself
| making the same comments (for different colleagues) regularly. I
| have a keyboard shortcut opening a fuzzy search to find the entry
| in a single text file. That saves a lot of time.
|
| As an aside, I find most of these commands very long. I tend to
| use very short aliases, ideally 2 characters. I'm assuming the
| author uses tab most of the time, if the prefixes don't overlap
| beyond 3 characters it's not that bad, and maybe the history is
| more readable.
| haskellshill wrote:
| > `nato bar` returns Bravo Alfa Romeo. I use this most often when
| talking to customer service and need to read out a long
| alphanumeric string, which has only happened a couple of times in
| my whole life. But it's sometimes useful!
|
| Even more useful is just learning the ICAO Spelling Alphabet (aka
| NATO Phonetic Alphabet, of which it is neither). It takes like an
| afternoon and is useful in many situations, even if the receiver
| does not know it.
| indigodaddy wrote:
| Not really a one liner but this comes in handy for quick dns on
| multiple hostnames:
|
| https://gist.github.com/jgbrwn/7dd4b262c544f750cb0291161b2ec...
|
| (actually avoids having to do a one liner like: for h in {1..5};
| do dig +short A mail"${h}".domain.com @1.1.1.1 )
|
| Hmm speaking of which I need to add in support for using a
| specific DNS server
___________________________________________________________________
(page generated 2025-10-22 23:00 UTC)