Anders's dotfiles

These are my dotfiles, which may or may not be helpful to you.

Tools

There are a number of tools I always seem to end up using. Some of these change over time. Some seem to more or less stay the same. For a while, I preferred MacPorts. These days I prefer Homebrew. Mostly, things stay more or less the same.

You probably want to install these manually before proceeding:

There are a number of other apps which I tend to install. You can have a look at the list and maybe feel inspired.

TL;DR

To set up your local computer just the way I like it, run:
bash <(curl -s https://cyborch.com/dotfiles/getall.sh)

On to the dotfiles

The easiest way to use any one of these is with curl:

cd;curl -O https://cyborch.com/dotfiles/{.whatever}

.bash_profile

Why?

There are several things going on here:

#!/bin/bash

# Load bash completions
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

# TextMate is still my favorite general purpose editor
export EDITOR="mate -w"

# Activate a named docker machine
docker-machine-set-active() {
  eval $(docker-machine env $1)
}

# Create digital ocean droplet
docker-create-droplet() {
  if [[ "$1" == "" || "$2" == "" || "$3" == "" ]] ; then
    echo "USAGE: docker-create-droplet TOKEN REGION NAME"
    echo "  TOKEN   the Digital Ocean access token"
    echo "  REGION  the region in which the droplet should be created"
    echo "  NAME    the name of the droplet"
    return
  fi
  docker-machine create --driver digitalocean --digitalocean-image ubuntu-16-04-x64 --digitalocean-access-token $1 --digitalocean-region $2 $3
}

docker-restart-droplet() {
  if [[ "$1" == "" || "$2" == "" ]] ; then
    echo "USAGE: docker-restart-droplet NAME ENVIRONMENT"
    echo "  NAME         the name of the service"
    echo "  ENVIRONMENT  the environment the service will run in"
    return
  fi
  echo -n "Stopping $1..."
  docker stop $1 >/dev/null 2>&1
  echo -e "   \033[32mdone\033[39m"
  echo -n "Cleaning $1..."
  docker rm $1 >/dev/null 2>&1
  echo -e "   \033[32mdone\033[39m"
  echo -n "Starting $1..."
  result=`docker run --name $1 -d --restart always $1:$2`
  if [[ "$?" == "0" ]] ; then
    echo -e "   \033[32mdone\033[39m"
  else
    echo -e "   \033[31m$result\033[39m"
  fi
}

# Open specified xcode project or workspace, or open a workspace or project in specified directory
xcode() {
  
  dir=`pwd`
  
  if [[ "$1" != "" ]] ; then
    if [ ! -d $1 ] ; then
      open -a Xcode $1
      return
    else
      dir=$1
    fi
  fi

  workspaces=( $(ls -d $dir/*.xcworkspace 2>/dev/null) )
  projects=( $(ls -d $dir/*.xcodeproj 2>/dev/null) )

  case ${#workspaces[@]} in
  0)
    case ${#projects[@]} in
    0)
      echo -e "\033[31mNo Xcode projects found in `dirname $dir`\033[39m"
      sleep 100
      return
      ;;
    1)
      open -a Xcode ${projects[0]}
      return
      ;;
    esac
    ;;
  1)
    open -a Xcode ${workspaces[0]}
    return
    ;;
  esac

  echo -e "\033[31mMore than one project or workspace found:\033[39m"
  echo ""
  ls -d *.xcworkspace *.xcodeproj
  echo ""
  echo -e "\033[32mPlease specify one.\033[39m"
}

Raw .bash_profile

.gitconfig

Why?

There are a lot of things git can do from the command line which to a large degree render UI tools irellevant. Formatting log output to add color and tree view goes a long way towards that. Also included in this is a set of shortcuts that I have committed to muscle memory since the days when I was using SVN. Added them as aliases in git just made sense.

[user]
  name = YOUR_NAME
  email = YOUR_CENTRAL_REPO_USER_EMAIL
[core]
  excludesfile = ABSOLUTE_PATH_TO_HOME/.gitignore_global
[alias]
  # Make rebase safe on osx https://www.git-tower.com/blog/make-git-rebase-safe-on-osx/
  rebase = -c core.trustctime=false rebase

  # A couple of shortcuts because I used to use svn
  ci = commit
  co = checkout
  st = status

  # Log, but with tree, colors, and changed files list
  lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --name-status

  # Log, just with tree
  tree = log --graph --oneline --all --color --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

  # Pull HEAD of master in all submodules
  sp = submodule foreach --recursive git fetch origin --tags && git checkout master && git pull
  
  # Initialize all submodules
  su = submodule update --init --recursive

  # Clone submodules when cloning a repository
  clone = clone --recurse

  # Words that are too long for me to bother with them
  br = branch
  ch = cherry-pick

  # Rebase local changes on top of anything you pull without nagging about local uncommitted changes
  pr = !git stash && git pull --rebase && git stash pop

  # Fast forward pull - should be the default imho
  pf = pull --ff-only

  # Set upstream when pushing - should be default imho
  pu = push -u

  # Merge without implicitly creating merge commits
  mf = merge --ff-only
  
  # Delete a remote branch
  bd = push origin --delete

[credential]
  # Use OSX keychain to remember passwords
  helper = osxkeychain

[push]
  # Assume that local branch name matches remote branch name
  default = current

[hub]
  # Use https for github (obviously)
  protocol = https

Raw .gitconfig

.gitignore_global

Why?

Because we specified it in .gitconfig and because everyone on OSX should ignore .DS_Store files.

# emacs backup file should always be ignored
*~

# OSX folder metadata is everywhere and should always be ignored
.DS_Store

# Xcode stores its state in this subfolder, and too many people forget to ignore it
*xcuserdata*

Raw .gitignore_global

.screenrc

Why?

Because telnet to a serial device by default doesn't provice the capabilities we are used to in a terminal. This allows us to scroll normally.

termcapinfo xterm* ti@:te@

Raw .screenrc

.ssh/config

Why?

# Keep connections alive by sending a null packet every 30 seconds
ServerAliveInterval 30
Host wedding
  User wedding
  HostName borch-andersen.dk
  # Allow editing remote files with rmate
  RemoteForward 52698 localhost:52698
Host magellanic
  User cyborch
  HostName magellanic.cyborch.com
  # Allow editing remote files with rmate
  RemoteForward 52698 localhost:52698

Raw .ssh/config