Fun hacks, WP plugins, photography, and PKI junk. Languishing since 2008.
Posts tagged bash
Bash Productivity Enhancers
Jan 20th
Bash is an extremely powerful shell, but its shortcuts are not readily apparent. Here are a few shortcuts and tips that I’ve noticed many (already proficient) bash users are not aware of. You can also check out Improved Bash History and More Useful Bash/Terminal Settings for more ideas for improving your bash productivity.
Bash Navigation ShortcutsWhen editing a long command, there are quite a few navigation and editing shortcuts. By default bash typically operates in emacs mode.
- Ctrl-A to go to the beginning of the line
- Ctrl-E to go to the end of a line.
- Ctrl-W will cut the current word (searching backward)
- Ctrl-U will cut More >
Fixing GrowlMail for Mail 4.2
Nov 9th
Lately Apple has been revving the version number (and plugin compatibility UUID) of Mail.app with every version of 10.6. This breaks bundles like GrowlMail even when they are still compatible. The easy fix (although not necessarily the best if it turns out an update is required!) is to run a few commands in Terminal to add the new UUIDs1 to the SupportedPluginCompatibilityUUID key in the Info.plist.2
If you have already had your plugins disabled by opening Mail.app you’ll need to look in ~/Library/Mail (or /Library/Mail if you installed globally) and move the files back to the active bundles directory. They’ll typically be More >
Find A Matching Certificate And Key Pair
Nov 8th
If you have a list of keys and SSL certs and don’t know which cert belongs with which key, here’s a script for you. It’s not efficient (nested for loop!), but it gets the job done quickly.1
#!/bin/bash for i in `ls *.key` do key_mod=`openssl rsa -noout -in $i -modulus` for j in `ls *.cer` do x509_mod=`openssl x509 -noout -in $j -modulus` if [ "$x509_mod" == "$key_mod" ]; then echo "$j matches $i" fi done done
- If bash allowed multidimensional or associative arrays this would be trivial to optimize. ↩
More Useful Bash/Terminal Settings
Nov 2nd
A few more tricks to make your bash environment better. As always, add them to your ~/.profile or ~/.bash_profile to enable.
Disable the pagination of long lists when ambiguously tab completing.
bind 'set page-completions off'
Increase max returned items before being prompted. (ie, “Display all 380 possibilities? (y or n”). You can set the number to whatever you’d like.
bind 'set completion-query-items 300'
Show the list of autocompletion options after the first tab. This prevents the beep + second tab behavior.
bind 'set show-all-if-ambiguous on'
When autocompleting for cd or rmdir, list only directories as choices.
complete -d cd rmdir
Autocompletion for ssh known_hosts. Add this to your ~/.ssh/config (if the file doesn’t exist, create More >
Improved Bash History
Oct 30th
If you use multiple shells simultaneously (in my case with Terminal.app on OS X) you’ve undoubtedly noticed that the history of the last closed shell clobbers any commands you might have executed in others. This makes it difficult to use reverse-i-search to find commands you recall using. However, with a few modifications to your bash history you can greatly increase its utility.
export HISTCONTROL=erasedups export HISTSIZE=10000 export HISTTIMEFORMAT="%D %T " export HISTIGNORE="&:ls:exit" shopt -s histappend
Save the above lines to your home directory’s .profile (or .bash_profile) and your shell history will now prevent duplicates, have a maximum of 10,000 items, append a timestamp to all new commands, exclude a list of More >
RAM Disks in OS X
Apr 21st
If you’ve ever wanted to set up a ramdisk in Mac OS X, here’s a quick script you can use. Simply invoke it with a size in MB and the name for your volume and it will create and automount it for you. It also won’t leave any dangling directories in your /Volumes/ when you eject it! Be sure to chmod the file you place the script in to make it executable (755 or likewise).
#!/bin/bash if [ -n "$3" ]; then NUM_ARG=ERR; fi if [ -z "$1" ]; then NUM_ARG=ERR; fi if [ -n "$NUM_ARG" ]; then echo 'Usage: ./ramdisk <size in MB> <name, optional>' exit fi SIZE=$1 NAME='my_ramdisk' let "SIZE *= 2048" if [ -n "$2" ]; then NAME=$2; fi diskutil erasevolume HFS+ "$NAME" `hdiutil attach -nomount ram://${SIZE}` echo 'Done'More >