What unique compositions of common Unix commands do you use often?
Here’s one I use to see which commands I’m running most often:
alias mostusedcomms="history \
| awk '{CMD[\$2]++;count++;}END { for (a in CMD)print CMD[a] \" \" CMD[a]/count*100 \"% \" a;}' \
| grep -v \"./\" | column -c3 -s \" \" -t | sort -nr | nl | head -n20"
Or one which prints giant text to the screen, to let me know when long running jobs are done:
#!/bin/bash
if [ $# -eq 1 ]; then
MSG="$1"
else
MSG="done"
fi
osascript -e "tell application \"Quicksilver\" to show large type \"$MSG\""
When I’m in doubt about shell expansion, I usually run
echo-eolwhich is like this:Also, since at work I’ve got a secondary monitor, I use the
workscreencommands, which is a shorthand for xrandr:As Vim user, I don’t like caps lock and I prefer esc instead…
…those are the most interesting home-made commands of mine. I’ve got some other commands which are more complex, but they’re very specific for my routine.
A long time ago, I started putting all the random C utilities and shell scripts I was writing for myself in a git repo.
I haven’t really used most of those utilities in a while. This post prompted me to go back and document some of them more properly. Some useful ones are
webpipe.sh - Pipe standard input into an HTML file and open it in the browser. So you could do something like
redcarpet README.md | webpipe.shto see what your README will look like on Github.pdfcat.sh - Basically an alias for a hairy invocation of GhostScript that will combine several PDF documents together.
lrange - The middle sibling of
headandtail;lrange a b file.txtwill print the lines a-b inclusive from the file to standard output.I frequently use the classic
overwritefrom K&P:For example, while
json_reformat < test.json > test.jsonwon’t work,overwrite test.json json_reformat < test.jsonwill.I also use this handy utility for converting plain text files wrapped at 80 columns to PDF, with a header that includes the file name: (requires
enscriptandps2pdffromghostscript)Finally, I bind edit_textbuf to
Super-Shift-e, which automatically loads text from a textarea in a browser intovimin a terminal. (And when you quit vim, it overwrites the textarea with your modifications.) I believe the script can be configured for other terminals/editors.The projectors at my school are all connected to some hub thing which make my Arch install only detect 800x600 as a possible resolution (sometimes smaller). I got sick of writing the commands to force it to output at 1920x1080 and mirror my laptop’s built in display so I put together a script to do it for me. It’s just three
xrandrcommands, but it’s so nice.I also have a tiny python script to upload a specified file to a “stuff I want to share quickly” site.
https://github.com/leifwalsh/df/tree/master/bin
All of that is cruft I no longer use, except for
mypass:It’s my own little 1password/lastpass/keepass replacement.
I’ve dropped
Larry's filename fixerinto~/binfor as long as I can remember. It’s from the Perl Cookbook and that Larry.It lets you apply
perlreto file renaming operations:More examples and notes here.
Unfortunately my
~/binalso containscvs-wtf-arg:because I work on one project that still uses CVS. If you know why I need this then I apologise.
[Comment removed by author]
I use this (in my ~/.gitconfig) to prevent myself having to write out the remote names:
If you named it “git-pushall” or something then you could use “git pushall” like any other git command, fwiw.
Would that work? Wouldn’t you need to call
git-pushallnotgit pushall? Because at least for me, I don’t have agit-pushorgit-pullcommand, which makes me think they’re just nice ways to separate sections of the manual.You could write an alias, which would let you use
git pushall:It works, give it a try. The main
gitbinary will look for agit-FOOexecutable for you.You actually do, it’s just not on your standard path.
gitknows where to look for it, on my system for example there is/usr/lib/git-core/git-pulland thatgit-coredir is full of the same.I get a lot of mileage from my
git-deployscript. It’s pretty simple, just force-pushes the current HEAD onto a given remote.This assumes you use git for deployments. You’ll take some serious heat from your fellow developers if you used this on a remote that isn’t a “functional” repository (I classify most repos as archival, deployments as functional).
The latter two lines fetch the history of the remote and push any auto-generated deployment tags with the origin.This useful when
git log --decorateing to see what is live compared to what is in dev.I rarely remember what our latest release was. I keep this around under
git-latest-tagso I can quickly check. It relies on GNU sort’s version sort, so for Mac usersgsortis available on Homebrew in the coreutils package.I also spend a lot of time managing Redis instances, so I keep this in
redis-delkeys. It removes all the keys in a database matching a pattern. It takes the same switches asredis-clifor host, port, and db number. I have a couple variants of it for different tasks (moving keys between two different instances, etc.), but they all have this general structure.Browse cvsweb for current directory or named file:
Simple alternative to ag or ack:
http://chneukirchen.org/dotfiles/tools.html and more. :)