Skip to content

Instantly share code, notes, and snippets.

@newlawrence
Last active January 3, 2018 13:02
Show Gist options
  • Save newlawrence/8b963fa2b0cee830b4a0a6d03108500d to your computer and use it in GitHub Desktop.
Save newlawrence/8b963fa2b0cee830b4a0a6d03108500d to your computer and use it in GitHub Desktop.
Some macOS tricks - just add to .bash_profile
# Customize prompt
export PROMPT_COMMAND="BRANCH=\
\"\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')\""
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]"\
"\h:\[\033[33;1m\]\w\[\033[m\]\[\033[0;36m\]\${BRANCH}\[\033[0m\]\$ "
# Customize command line
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls="ls -GFh"
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# Alias to restore Launch Services
alias restore_services="/System/Library/Frameworks/CoreServices.framework/"\
"Frameworks/LaunchServices.framework/Support/lsregister "\
"-kill -r -domain local -domain system -domain user ; killall Dock"
# Alias to disable .DS_Store on network and external drives
alias no_ds_store="defaults write com.apple.desktopservices "\
"DSDontWriteUSBStores -bool true && "\
"defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true"
# Aliases for showing hidden files in Finder
alias show_files="defaults write com.apple.finder AppleShowAllFiles YES;"\
"killall Finder /System/Library/CoreServices/Finder.app"
alias hide_files="defaults write com.apple.finder AppleShowAllFiles NO;"\
"killall Finder /System/Library/CoreServices/Finder.app"
# Enable/Disable antialias on Terminal.app
function set_aa_level() {
defaults write $1 AppleFontSmoothing -int $2;
}
function terminal_aa_level() {
set_aa_level com.apple.Terminal $1;
}
# Cleaning
function clean() {
read -p "Warning! This will erase all $1 recursively. Continue? " choice;
case "$choice" in
y|Y ) find . -name "*.$1" -depth -exec rm {} \;;;
n|N ) echo "Aborted...";;
* ) echo "invalid";;
esac;
}
alias clean_all="clean_ds; clean_dot; clean_nb"
# Create a localized folder
function mkdir_localized() {
folder="$2.localized/.localized";
mkdir -p "$2.localized" "$folder";
rm -f "$2" "$folder/en.strings" "$folder/$1.strings";
ln -s "$2.localized" "$2";
SetFile -P -a V "$2";
touch "$folder/en.strings" "$folder/$1.strings";
echo \"$2\" = \"$2\"\; >> "$folder/en.strings";
echo \"$2\" = \"$3\"\; >> "$folder/$1.strings";
}
# Create a RAM disk
function ramdisk() {
diskutil erasevolume HFS+ 'ram_disk'\
`hdiutil attach -nomount ram://$(( 2048 * $1 ))`;
}
# Create floppy disk image
function floppy() {
dd if=/dev/zero bs=1024 count=1440 > $1;
diskutil eraseVolume MS-DOS $2 `hdiutil attach -nomount $1`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment