Created
March 29, 2011 00:33
-
-
Save hhallman/891610 to your computer and use it in GitHub Desktop.
Aliases, many for mac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Rename the last screen dump on Mac | |
function sdname { | |
screen_dump_dir=$(defaults read com.apple.screencapture location); | |
filename="$( ls -rt $screen_dump_dir | tail -1 )"; | |
echo renaming $screen_dump_dir/$filename; | |
title="$@"; | |
while test -z "$title"; do echo "Give the dump a title (break to abort)"; read title; done; | |
mv "$screen_dump_dir/$filename" "$screen_dump_dir/$title-$filename"; | |
} | |
aliasfiles="$HOME/.profile $HOME/aliases.sh" | |
#Echo the current aliases that are not registered in any of $aliasfiles | |
function nonregged-alias { | |
for alias in `alias|grep '^alias' | sed 's/alias \([^=]*\).*/\1/g'`; do | |
grep -q "^alias $alias" $aliasfiles || { | |
echo "$alias"; | |
} | |
done; | |
} | |
function reg-alias { | |
[ -z "$2" ] && { echo "usage reg-alias <alias> <alias-file> #Note that there is tab completion"; return 1; } | |
echo "Registering alias `alias $1` in file $2"; | |
alias $1 >> $2; | |
} | |
function _reg-alias { | |
local cur prev opts | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
opts=$(nonregged-alias); | |
if [ $COMP_CWORD -eq 1 ] ; then | |
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | |
return 0 | |
fi | |
if [ $COMP_CWORD -eq 2 ] ; then | |
COMPREPLY=( $(compgen -W "$aliasfiles" -- ${cur}) ) | |
fi | |
} | |
complete -F _reg-alias reg-alias |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment