Skip to content

Instantly share code, notes, and snippets.

@pamo
Last active July 18, 2018 21:25
Show Gist options
  • Save pamo/bc477f40e1146c69c3697d3ff7cfa30e to your computer and use it in GitHub Desktop.
Save pamo/bc477f40e1146c69c3697d3ff7cfa30e to your computer and use it in GitHub Desktop.
Mac Tweaks

Opt-in setup tweaks for your new system:

Profile:

  # Better `ls`
  export CLICOLOR=1
  export LSCOLORS=GxFxCxDxBxegedabagaced
  alias ls='ls -p'

  # Better `grep`
  export GREP_OPTIONS='--color=auto'

  # brew install prc

  # Colorized `traceroute`, `tail`, `head` (requires prepending command with `grc`)
  source "`brew --prefix`/etc/grc.bashrc"

  # Case-insensitive globbing (used in pathname expansion)
  shopt -s nocaseglob

  # Append to the Bash history file, rather than overwriting it
  shopt -s histappend

  # Autocorrect typos in path names when using `cd`
  shopt -s cdspell

  source `brew --prefix`/Library/Contributions/brew_bash_completion.sh

  # Make Tab autocomplete regardless of filename case
  set completion-ignore-case on

  # List all matches in case multiple possible completions are possible
  set show-all-if-ambiguous on

  # Immediately add a trailing slash when autocompleting symlinks to directories
  set mark-symlinked-directories on

  # Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards
  [ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2)" scp sftp ssh

  # IP addresses
  alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
  alias localip="ipconfig getifaddr en1"
  alias ips="ifconfig -a | grep -o 'inet6\? \(\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)\|[a-fA-F0-9:]\+\)' | sed -e 's/inet6* //'"

  # Enhanced WHOIS lookups
  alias whois="whois -h whois-servers.net"

  # Flush Directory Service cache
  alias flush="dscacheutil -flushcache"

  # Don’t clear the screen after quitting a manual page
  export MANPAGER="less -X"

  # Make some commands not show up in history
  export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"

  # Automatically jump to your onelife directory from anywhere 
  alias onelife='cd ~/onelife'

Mac plist settings (you can simply input each line into Terminal):

  # Because Library is hidden by default:
  chflags nohidden ~/Library

  # Mountain Lion forces the fluid scrolling animation when you hit space or page-down. This change
  # fixes that, but sometimes (as with the scroll behavior on Safari) the settings aren't applied globally.
  defaults write NSGlobalDomain AppleScrollAnimationEnabled -bool false
  # Hidden apps show translucently:
  defaults write com.apple.dock showhidden -bool true
  defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
  # Make Safari’s search banners default to Contains instead of Starts With
  defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false
  # Enable the Develop menu and the Web Inspector in Safari
  defaults write com.apple.Safari IncludeDevelopMenu -bool true
  defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true
  defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true
  # Add a context menu item for showing the Web Inspector in web views
  defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
  # Disable the iTunes store link arrows
  defaults write com.apple.iTunes show-store-link-arrows -bool false
  # Enable Dashboard dev mode (allows keeping widgets on the desktop)
  defaults write com.apple.dashboard devmode -bool true
  # Enable the debug menu in Disk Utility
  defaults write com.apple.DiskUtility DUDebugMenuEnabled -bool true
  defaults write com.apple.DiskUtility advanced-image-options -bool true
  # Re-enable backspace to go back in Safari, shift delete to forward.
  defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2BackspaceKeyNavigationEnabled -bool YES

Visual Distinction for when you are SSH'd in Terminal

To help prevent running errant code on production, it's darn handy to change your terminal theme when opening an ssh connection. This involves adding two bash functions, and choosing a suitable terminal theme.

Create a new theme for the ssh connection (I called it "SSH-theme" and gave it a red background). My main theme is called "Visor"

Add these functions to ~/.bashrc (for whatever reason, mine is actually called ~/.profile)

function tabc {
  NAME=$1; if [ -z "$NAME" ]; then NAME="Default"; fi
  osascript -e "tell application "Terminal" to set current settings of front window to settings set "$NAME""
}

function ssh {
  tabc "SSH-theme"
  /usr/bin/ssh "$@"
  tabc "Visor"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment