Found a couple neat ideas that I'm going to steal--thx for sharing; but I must mention: Should probably be pgrep and pkill Should probably be setsid -f or at least use the double subshell trick...
Found a couple neat ideas that I'm going to steal--thx for sharing; but I must mention:
running foo is like ps aux | grep foo
Should probably be pgrep and pkill
bb my_command is like my_command & but it really really runs it in the background
Should probably be setsid -f or at least use the double subshell trick (ie. ((command &) &) which immediately backgrounds the process and orphans it, effectively daemonizing it)
A lot of cool ideas here, I especially like nato bar - I feel there's been a handful of occasions lately where I'm trying to read a string of letters and numbers verbally and it's been difficult....
A lot of cool ideas here, I especially like nato bar - I feel there's been a handful of occasions lately where I'm trying to read a string of letters and numbers verbally and it's been difficult. It may just be a better web app for my use case though - since it's often a phone call issue, having it on my phone would be the most beneficial.
I tend to string commands together that I use all the time into aliases in zsh. Some of my favorites: # common ways I style ls commands alias lsc="ls --color" alias lsa="ls -lha --color" alias...
I tend to string commands together that I use all the time into aliases in zsh. Some of my favorites:
# common ways I style ls commands aliaslsc="ls --color"aliaslsa="ls -lha --color"aliaslsd="ls -d --color */"aliaslsall="ls -latrh --color */"# I need cls like I need cd and lsaliascls="clear"# If you connect via SSH it'll ask for a fingerprint of your machine on each new client.# I got tired of looking up and copying this commandaliasfingerprint="ssh-keygen -E md5 -lf <(ssh-keyscan localhost 2>/dev/null)"# Technically only . ~/zshrc is doing anything useful.#The rest is# 1) an anonymous function that echos what I'm doing# 2) does what I said I'd do# 3) then confirms we're still in zsh.aliassrc="() { echo 'Reloading ZSH'; . ~/.zshrc; echo $0 }"# I honestly forgot that these aren't real commands I use them so dang much.aliashome="cd ~/"aliaswhichenv="echo $VIRTUAL_ENV"
What this does is it it updates homebrew, upgrades any packages that need upgrading, and then it clears the cached downloads. (Edited to take out the mkcd command as it... doesn't work.)
For things like your lsc, I prefer to just alias ls to itself along with some others where I pretty much never want the vanilla defaults. alias ls="ls --color=auto" alias grep="grep --color=auto"...
For things like your lsc, I prefer to just alias ls to itself along with some others where I pretty much never want the vanilla defaults.
For the very rare occasions where I actually do want the default behavior, prefixing the command with backslash disables alias expansion. E.g., \ls. This way, I give my common case the shorter name, and the uncommon case the longer name.
$ alias alias clip='xsel --clipboard --input < ' alias cls='clear' alias dj='cd $HOME/dev/java/keenwrite' alias gc='git commit -a -m' alias gp='git push' alias rd='rmdir' The dj alias points to...
I'm definitely going to have steal some of these. (Both from the article, from this thread, and from the HN thread.) Anyway, in the spirit of sharing here are some Zsh aliases and functions of my...
I'm definitely going to have steal some of these. (Both from the article, from this thread, and from the HN thread.)
Anyway, in the spirit of sharing here are some Zsh aliases and functions of my own:
rshare recurses through a directory tree and for each file or directory copies my user permissions, minus write access, to group and other. I usually run locked down with umask 077, so rshare makes things accessible to others. runshare revokes those perms. runexec is useful for cleaning up directory trees copied from Windows filesystems where the executable bit comes set on everything.
function go(){local i;for i ($@);do xdg-open $i;done}
I use this one constantly. It opens up a file or list of files with whatever desktop program is assigned to them. Or for directories, it shows me the contents in the desktop file browser, etc. (Regarding the name, I was using a version of this alias long before Golang existed, damnit!)
Quick edits in Emacs via the client. I have Emacs set to launch the server on startup, and ec just tells that instance to open whatever files I give it and then immediately returns. It's useful when I'm just cding around in the terminal and want to pop a file into my Emacs window. cde kind of goes the opposite direction and tries to cd me into the directory holding the active buffer's file.
Some image utilities: opng crunches down PNG files as much as possible, toimg renders stdin or a text/source file to a syntax highlighted image, pdf2png renders the pages of a PDF to images.
And finally a grab bag: pdiff uses Git's patience diff on two arbitrary files (which may be outside of repos), attach tries to attach the GDB debugger to a running process by name so I don't have to look up the PID, alarm takes a time in seconds and a command to run and kills the command after the time is up, countdn takes a time in seconds and gives me a little count down (useful when I want to delay or stagger the start times of some commands to run unattended), vbreak shows a honking big bold magenta divider bar with timestamp that I can't miss in the scrollback buffer, and echob just echoes some text in bold red.
I use this a lot to create a directory and enter it in one shot mkcd() { mkdir $1 && cd $_ } in skhd I have skip ahead and skip back in big and small for Kodi. Its on a different box with a screen...
I use this a lot to create a directory and enter it in one shot
mkcd(){
mkdir $1&&cd$_}
in skhd I have skip ahead and skip back in big and small for Kodi. Its on a different box with a screen just to my left -- so instead of moving my hands for the remote or the remapped keypad, I can use hyper + vim keys to skip ahead etc.
hyper - k : curl -s -u "username:password" -X POST http://pear:8080/jsonrpc -H "Content-Type: application/json" -d '{"jsonrpc
":"2.0","id":1,"method":"Player.Seek","params":{"playerid":1,"value":{"step":"smallbackward"}}}
I have similar key combos to control Hue lights, too -- but that calls a proper script.
Good article, and good thread to keep an eye on! I use the following oneliner to open a document of notes for the day: #!/bin/bash exec $EDITOR $HOME/docs/notes/$(date --iso-8601).txt I'll warn...
Good article, and good thread to keep an eye on!
I use the following oneliner to open a document of notes for the day:
I'll warn that it's for GNU date and I don't know that *BSD or busybox implement --iso-8601.
I use this to browse and search my music library with fzf and play back albums using audacious:
#!/bin/bash
cd $HOME/storage/musik/shared
case "$1" in
"") exec fzf --walker=dir --bind "enter:execute($0 play {})" ;;
play) audacious "$2" & disown ;;
esac
The library is organized in an <artist name>/<album name> hierarchy, and I tend to listen to music in units of albums. Consequently I don't use the library features of audacious.
I also use the following script to synchronize the music library to VLC on my phone (an Iphone) using ifuse and rsync:
My (macOS’) man date has this to say, which I also make use of all the time: HISTORY […] The -I flag was added in FreeBSD 12.0. Interestingly, it doesn’t have the long-form option though. And I...
I'll warn that it's for GNU date and I don't know that *BSD or busybox implement --iso-8601.
My (macOS’) man date has this to say, which I also make use of all the time:
HISTORY
[…]
The -I flag was added in FreeBSD 12.0.
Interestingly, it doesn’t have the long-form option though.
And I just spun up a quick container to check for Alpine/busybox:
52f92d631fce# date -I
2025-11-21
52f92d631fce# date --iso-8601
date: unrecognized option: iso-8601
BusyBox v1.36.1 (2024-06-10 07:11:47 UTC) multi-call binary.
Usage: date [OPTIONS][+FMT][[-s] TIME]
…
Now we know which version busybox is reimplementing, haha!
Edit because I realized I never actually checked the “opposite” side: My basic-setup VPS’ date yields the following:
~% date --iso-8601
2025-11-25
~% date -I
2025-11-25
~% date --version
date (GNU coreutils) 9.3
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David MacKenzie.
~%
I have a gitviz/gitvizl that visualizes the commit tree in the terminal with nice coloring. The regular variant just shows the head of every branch and the merges, the l suffix shows every commit....
I have a gitviz/gitvizl that visualizes the commit tree in the terminal with nice coloring. The regular variant just shows the head of every branch and the merges, the l suffix shows every commit.
For a Particular project or environment, usually make a cgrep (code grep) that aliases grep with exclusions for folders I don't want to search like .git, node_modules, build, dist, coverage, etc.
I wrote a program called ask that passes the rest of the line to an llm as a prompt and asks it to return a command and only a command, then offers to cool it to the clipboard. It has a few optimizations, like if you mention git/commit/merge it will include the output of git status, and if you mention a file in the current directory it will inckude the first 500kb of it. Though I guess it's not a script (go compiled binary).
I used to have a script called slackit that I could append to long running tasks to get a notification that they finished.
No idea how I missed this thread when it was originally posted, so thanks @mxuribe for commenting it to the top again :P My version of this takes it a step further: before opening the new tab, I...
No idea how I missed this thread when it was originally posted, so thanks @mxuribe for commenting it to the top again :P
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.
My version of this takes it a step further: before opening the new tab, I enter my command nt to copy the pwd into the clipboard (if pwd isn’t $HOME), but in the new tab (if it’s not a Kitty tab, which I have configured to open in the same directory by default anyways), when I enter the same nt command in my home directory, it will cd to the path, no pasting needed! Not very unixy behavior, I guess, but it’s convenient.
The code in my shell profile config:
nt () {
default_dir="$HOME"
current_wd="$(pwd)"
if [ "$current_wd" != "$default_dir" ]
then
echo "$current_wd" | cb copy
else
cd "$(cb --no-progress paste)" || {
echo "Failed to change directory to pasted target dir"
return 1
}
fi
}
I’ll probably get back later here when I have more time and edit my comment with even more useful shell script stuff that I use that isn’t mentioned in the article or comments yet.
I'm happy to have helped @tauon (even though it was a happy accident)! :-D And, funny that you should mention about your version of the author's copy/pasta...Now, that i've been getting more and...
I'm happy to have helped @tauon (even though it was a happy accident)! :-D
And, funny that you should mention about your version of the author's copy/pasta...Now, that i've been getting more and more back into using the terminal on a more regular basis...I'm really enjoying reading about these scripts that others create and use. And, of course, inspiring me to create my own for personal use...which are by no means sophisticated. But getting back into all this, has begun to generate some fun and energy for me - some of it bringing me back to my earlier computing days...ah, the fun i had, and am now beginning to have again!
Easily my most used and most general script is a slightly modified version of this (archive link since the original seems to be down), letting me cycle between audio devices with a keyboard...
Easily my most used and most general script is a slightly modified version of this (archive link since the original seems to be down), letting me cycle between audio devices with a keyboard shortcut.
My other most commonly used scripts are way too niche to matter here.
Found a couple neat ideas that I'm going to steal--thx for sharing; but I must mention:
Should probably be
pgrepandpkillShould probably be
setsid -for at least use the double subshell trick (ie.((command &) &)which immediately backgrounds the process and orphans it, effectively daemonizing it)A lot of cool ideas here, I especially like
nato bar- I feel there's been a handful of occasions lately where I'm trying to read a string of letters and numbers verbally and it's been difficult. It may just be a better web app for my use case though - since it's often a phone call issue, having it on my phone would be the most beneficial.I tend to string commands together that I use all the time into aliases in zsh. Some of my favorites:
What this does is it it updates homebrew, upgrades any packages that need upgrading, and then it clears the cached downloads. (Edited to take out the mkcd command as it... doesn't work.)
re
home, you can get the same effect by just runningcd!I knew there had to be something like that out there. Thanks!
For things like your
lsc, I prefer to just aliaslsto itself along with some others where I pretty much never want the vanilla defaults.For the very rare occasions where I actually do want the default behavior, prefixing the command with backslash disables alias expansion. E.g.,
\ls. This way, I give my common case the shorter name, and the uncommon case the longer name.Nice! I’ll probably incorporate some of that into my zshrc tonight after work! Thank you.
One alternative you could do is SSH Art 🎨😎
There’s always something new and interesting to learn about POSIX. Very cool! Thanks!
The
djalias points to whatever project has my attention. Theclipalias will copy the contents of a file to the clipboard, ready for pasting.Scripts of note:
I'm definitely going to have steal some of these. (Both from the article, from this thread, and from the HN thread.)
Anyway, in the spirit of sharing here are some Zsh aliases and functions of my own:
rsharerecurses through a directory tree and for each file or directory copies my user permissions, minus write access, to group and other. I usually run locked down withumask 077, sorsharemakes things accessible to others.runsharerevokes those perms.runexecis useful for cleaning up directory trees copied from Windows filesystems where the executable bit comes set on everything.I use this one constantly. It opens up a file or list of files with whatever desktop program is assigned to them. Or for directories, it shows me the contents in the desktop file browser, etc. (Regarding the name, I was using a version of this alias long before Golang existed, damnit!)
Quick edits in Emacs via the client. I have Emacs set to launch the server on startup, and
ecjust tells that instance to open whatever files I give it and then immediately returns. It's useful when I'm justcding around in the terminal and want to pop a file into my Emacs window.cdekind of goes the opposite direction and tries tocdme into the directory holding the active buffer's file.Some image utilities:
opngcrunches down PNG files as much as possible,toimgrenders stdin or a text/source file to a syntax highlighted image,pdf2pngrenders the pages of a PDF to images.And finally a grab bag:
pdiffuses Git's patience diff on two arbitrary files (which may be outside of repos),attachtries to attach the GDB debugger to a running process by name so I don't have to look up the PID,alarmtakes a time in seconds and a command to run and kills the command after the time is up,countdntakes a time in seconds and gives me a little count down (useful when I want to delay or stagger the start times of some commands to run unattended),vbreakshows a honking big bold magenta divider bar with timestamp that I can't miss in the scrollback buffer, andechobjust echoes some text in bold red.Oh wow @Boojum, I'm going to have to borrow 1 or 2 of your snippets myself! Your "toimg" alias function is brilliant! Kudos!
I use this a lot to create a directory and enter it in one shot
in skhd I have skip ahead and skip back in big and small for Kodi. Its on a different box with a screen just to my left -- so instead of moving my hands for the remote or the remapped keypad, I can use hyper + vim keys to skip ahead etc.
I have similar key combos to control Hue lights, too -- but that calls a proper script.
Good article, and good thread to keep an eye on!
I use the following oneliner to open a document of notes for the day:
I'll warn that it's for GNU date and I don't know that *BSD or busybox implement
--iso-8601.I use this to browse and search my music library with fzf and play back albums using audacious:
The library is organized in an <artist name>/<album name> hierarchy, and I tend to listen to music in units of albums. Consequently I don't use the library features of audacious.
I also use the following script to synchronize the music library to VLC on my phone (an Iphone) using ifuse and rsync:
My (macOS’)
man datehas this to say, which I also make use of all the time:Interestingly, it doesn’t have the long-form option though.
And I just spun up a quick container to check for Alpine/busybox:
Now we know which version busybox is reimplementing, haha!
Edit because I realized I never actually checked the “opposite” side: My basic-setup VPS’
dateyields the following:— it has both, so yours might too!
I have a
gitviz/gitvizlthat visualizes the commit tree in the terminal with nice coloring. The regular variant just shows the head of every branch and the merges, thelsuffix shows every commit.For a Particular project or environment, usually make a
cgrep(code grep) that aliases grep with exclusions for folders I don't want to search like .git, node_modules, build, dist, coverage, etc.I wrote a program called
askthat passes the rest of the line to an llm as a prompt and asks it to return a command and only a command, then offers to cool it to the clipboard. It has a few optimizations, like if you mention git/commit/merge it will include the output ofgit status, and if you mention a file in the current directory it will inckude the first 500kb of it. Though I guess it's not a script (go compiled binary).I used to have a script called
slackitthat I could append to long running tasks to get a notification that they finished.No idea how I missed this thread when it was originally posted, so thanks @mxuribe for commenting it to the top again :P
My version of this takes it a step further: before opening the new tab, I enter my command
ntto copy the pwd into the clipboard (if pwd isn’t $HOME), but in the new tab (if it’s not a Kitty tab, which I have configured to open in the same directory by default anyways), when I enter the samentcommand in my home directory, it will cd to the path, no pasting needed! Not very unixy behavior, I guess, but it’s convenient.The code in my shell profile config:
(
cbis “my” version of the author’s copy/pasta)I’ll probably get back later here when I have more time and edit my comment with even more useful shell script stuff that I use that isn’t mentioned in the article or comments yet.
I'm happy to have helped @tauon (even though it was a happy accident)! :-D
And, funny that you should mention about your version of the author's copy/pasta...Now, that i've been getting more and more back into using the terminal on a more regular basis...I'm really enjoying reading about these scripts that others create and use. And, of course, inspiring me to create my own for personal use...which are by no means sophisticated. But getting back into all this, has begun to generate some fun and energy for me - some of it bringing me back to my earlier computing days...ah, the fun i had, and am now beginning to have again!
Easily my most used and most general script is a slightly modified version of this (archive link since the original seems to be down), letting me cycle between audio devices with a keyboard shortcut.
My other most commonly used scripts are way too niche to matter here.