Skip to content

Instantly share code, notes, and snippets.

@puppybits
Created August 12, 2011 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save puppybits/1142810 to your computer and use it in GitHub Desktop.
Save puppybits/1142810 to your computer and use it in GitHub Desktop.
OSX terminal commands
PS1="\[\033[1;31m\]\u\[\033[1;31m\]$ \[\033[0m\]"
UIARESULTSPATH="/var/log/iphone"
############## MACROS ##############
function imagefilehash(){ (sips -g make -g model -g pixelHeight -g pixelWidth $1 | tail -n 4; GetFileInfo -d $1;) | openssl sha1 | sed 's/^(.*)..//g'; }
function imagehash(){ openssl sha1 | sed 's/^(.*)..//g'; }
alias updateproflie= "pushd ~ && curl -O https://gist.github.com/raw/1142810/a7680ba07bacf8f4a6b2cef262a99312307a76da/.profile.sh"
##### DEVELOPMENT
alias sshcopy="cat ~/.ssh/id_rsa.pub | pbcopy"
alias iphonesim="open ~/Library/Application\ Support/iPhone\ Simulator"
alias flashlibrary="open ~/Library/Preferences/Macromedia/Flash\ Player/\#SharedObjects"
alias flashsdk="~/Applications/Adobe\ Flash\ Builder\ 4/sdks"
alias apacheerrors="open /private/var/log/apache2/error_log"
alias apacheaccess="open /private/var/log/apache2/access_log"
function curljson(){
curl $1 | python -mjson.tool
}
#not working yet
function curlpost(){ URL_PARAMS=$1; POST_URL=$2; curl --data-urlencode "$URL_PARAMS" $POST_URL; }
#not working yet
function curlget(){ URL_PARAMS=$1; POST_URL=$2; curl "$URL_PARAMS?$POST_URL"; }
#curl is better than wget
function wget(){ URL = $1; curl -O $URL; }
alias curldownload=wget
#create encrypted drive and fix permissions for apache
function newprojectdrive(){
hdiutil create -size 4.2g -fs HFS+J -layout SPUD -type SPARSEBUNDLE -encryption AES-256 -attach -volname $1 ~/Store/$1
chmod go+rX /Volumes/$1
}
#bundle id for automating wth macruby or others
function appbundleid(){
while read file
do
id=$(mdls -name kMDItemCFBundleIdentifier "$file" | awk '{print $3}')
echo $(basename "$file") $id
done < <(find ~/Applications -type d -iname *$1*.app)
}
function p4changelistdiff(){ # Create a diff from a changelist number
CHANGE_LIST_NUMBER=$1;
p4 opened -c $CHANGE_LIST_NUMBER | awk 'BEGIN { FS = "#" } // { print "p4 diff " $1 }' | csh
}
function itest(){ # Automated testing in iphone simulator
MOBILE_SAFARI="/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/Applications/MobileSafari.app";
JS_AUTOMATION_SCRIPT=$1;
APP_NAME=$2;
TEMPLATE_DIR="/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate";
APP_DIR=$(find ~/Library/Application\ Support/iPhone\ Simulator -iname $APP_NAME.app)
if [ !$APP_DIR ]
then
APP_DIR=$MOBILE_SAFARI;
fi
instruments -t \"$TEMPLATE_DIR\" \"$APP_DIR\" -e UIASCRIPT $JS_AUTOMATION_SCRIPT
}
function halfPNGs(){ # Create @1x PNGs
dir=$1
n=0
while read f
do
i=$(basename "$f")
if [[ $i == *\@2x\.png ]]; then
h=$(sips -g pixelHeight $f)
h=${h#*:}
w=$(sips -g pixelWidth $f)
w=${w#*:}
sips -s format png -z $(expr $h / 2) $(expr $w / 2) $f --out ${f%@*}\.png
fi
done < <(find $dir -iname *.png)
}
function image64(){
filename=$(basename $1)
xtype=${filename##*.}
append=""
if [ $xtype == gif ]; then
append="data:image/gif;base64,";
elif [ $xtype == jpeg ] || [ $xtype == jpg ]; then
append="data:image/jpeg;base64,";
elif [ $xtype == png ]; then
append="data:image/png;base64,";
elif [ $xtype == svg ]; then
append="data:svg+xml;base64,";
elif [ $xtype == ico ]; then
append="data:image/vnd.microsoft.icon;base64,";
fi
data=$(openssl base64 < $1 | tr -d '\n')
if [ "$#" -eq 2 ] && [ $2 == -img ]; then
data=\<img\ src\=\"$append$data\"\>
else
data=$append$data
fi
echo $data | pbcopy
echo "copied to clipboard"
}
##### PROCESSES
#show all process with name..
function psx(){ PROCESS_NAME=$1; ps -a | grep $PROCESS_NAME; }
#kill all instances of a process
function overkill(){ PROCESS_NAME=$1; kill `ps auxww | grep -i $PROCESS_NAME | awk '{print $2}'`; }
##### NETWORK
alias forceHostname="sudo scutil --set HostName $HOSTNAME.local"
alias gatewayip="netstat -nr -f inet | grep default | grep en | awk '{print $2}'"
alias gatewayinterface="netstat -nr -f inet | grep default | grep en | awk '{print $6}'"
#name of the currently connected wireless
alias ssid="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep SSID | tail -n 1 | awk '{print $2}'"
#find all ports open from app
function appport(){ APP_NAME=$1; lsof -i -P | grep $APP_NAME; }
##### USERS
alias allgroups="dscl . -list /Groups PrimaryGroupID | sort -n -k2,2"
##### GENERAL
#lock the mac and go to login screen
alias lock="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
#hide or show all files
alias showfiles="defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder"
alias hidefiles="defaults write com.apple.finder AppleShowAllFiles FALSE; killall Finder"
##### RANDOM
alias where=which #cause i keep forgetting
#2d dock is much prettier
alias dock2d="defaults write com.apple.dock no-glass -boolean YES; killall Dock"
alias dock3d="defaults write com.apple.dock no-glass -boolean NO; killall Dock"
alias screensaver="/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &"
function replace(){ sed -i 's/$1.*/$2/' $3;} #replace this for that
############## SETTINGS ##############
#textmate
export EDITOR='mate -w'
export VISUAL="mate -w"
export SVN_EDITOR="mate -w"
#ffmpeg
export FFMPEG_DATADIR=/opt/local/var/macports/software/ffmpeg/0.6.2_0/opt/local/share/ffmpeg
#MacPorts
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
##### EXTERN
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
source ~/.rga
##
# Your previous /Users/bobbys/.profile file was backed up as /Users/bobbys/.profile.macports-saved_2012-04-13_at_12:00:20
##
# MacPorts Installer addition on 2012-04-13_at_12:00:20: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
##
# Your previous /Users/bobbys/.profile file was backed up as /Users/bobbys/.profile.macports-saved_2012-05-03_at_15:27:38
##
# MacPorts Installer addition on 2012-05-03_at_15:27:38: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment