Add this to ~/.bash_profile, ~/.bashrc, or wherever you prefer. You can then recursively remove annoying .DS_Store files from a directory by executing the command rm_dss.
Pop out
1 | alias rm_dss='find . -name *.DS_Store -type f -exec rm {} \;' |
Add this to ~/.bash_profile, ~/.bashrc, or wherever you prefer. You can then recursively remove annoying .DS_Store files from a directory by executing the command rm_dss.
Pop out
1 | alias rm_dss='find . -name *.DS_Store -type f -exec rm {} \;' |
This function pipes a javascript file to a Python implementation of Douglas Crockford’s handy JSMin, a javascript minifier.
Pop out
1 2 3 4 5 6 7 8 9 10 11 12 13 | minify() { if [ -f $1 ] then MIN=${1%.[^.]*}.min.js cat $1 | python ~/path/to/jsmin.py > ${1%.[^.]*}.min.js BEFORE=`wc -c <$1` AFTER=`wc -c <$MIN` echo "$BEFORE $1" echo "$AFTER $MIN ($(echo "scale=2; 100*$AFTER/$BEFORE" | bc)%)" else echo "$1 not found" fi } |
It also prints the minified version’s character count as a percentage of the original’s:
$ minify prototype.js 126127 prototype.js 93689 prototype.min.js (74.28%)
Disable:
Pop out
$ | sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist |
Reenable:
Pop out
$ | sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist |
Source: http://tech.karbassi.com/2007/11/06/leopard-turn-off-bonjour-mdnsresponder/
I wrote this bash function to print sequential lines starting from a random point in a text file. I use it to display a few lines of a song every time I open a new shell, but it’s general enough for many purposes.
Pop out
1 2 3 4 | lyrics() { S=$(( $(( RANDOM % $(( $(wc -l < $1)-1 )) )) + 1)) sed -n "$S,$(($S + $(($2-1)) ))"p $1 | awk '{print "+ "$0}' } |
Add the function above to ~/.bash_login, ~/.bash_profile or ~/.bashrc, followed by this line calling it:
Pop out
1 | lyrics .my_lyrics 3 |
Arguments: .my_lyrics is the name of the file containing the text, and 3 is the number of sequential lines to print. Here’s an example of what it produces in a shell:
Last login: Mon Mar 16 12:01:03 on ttys000 + well maybe you should just drink a lot less coffee + and never ever watch the ten o'clock news + maybe you should kiss someone nice, or lick a rock, or both heather@macbook:~ $
From Allan Odgaard’s excellent Working With History in Bash:
Pop out
1 2 3 | export HISTCONTROL=erasedups export HISTSIZE=10000 shopt -s histappend |
Place in ~/.bash_login, ~/.bash_profile, or ~/.bashrc after changing lines 2 and 3:
Pop out
1 2 3 4 5 6 7 8 9 10 11 | my() { user="your_username"; pass="your_password"; if [ $# = 1 ] then mysql -u $user --password=$pass $1; else mysql -u $user --password=$pass --execute='show databases'; mysql -u $user --password=$pass; fi } |
Before:
Pop out
$ | mysql -u [user] -p ([database]) |
Enter password: mysql >
After:
Pop out
$ | my ([database]) |
mysql >