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
Scripts I wrote that I use all the time
101–110 of 408 posts
Re: Scripts I wrote that I use all the time
#102I 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 ../../../../../..'
Other single-key bindings I use often are:
KP* executes 'ls'
KP- executes 'cd -'
KP+ executes 'make -j `nproc`'
Re: Scripts I wrote that I use all the time
#103Earlier quoted context omitted.
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.
use a backslash. \* (had to use a double backslash to render that correctly)
Re: Scripts I wrote that I use all the time
#104> 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…
`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 ".
Re: Scripts I wrote that I use all the time
#105Like, 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!
Re: Scripts I wrote that I use all the time
#106> 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…
Re: Scripts I wrote that I use all the time
#107this 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. :)
Re: Scripts I wrote that I use all the time
#108 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}|${hostnames})/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.Re: Scripts I wrote that I use all the time
#109Folks 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.
Re: Scripts I wrote that I use all the time
#110It'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…
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. :)