From 7c5e29036d89a64e669c12e8c22d3fcdf750bd55 Mon Sep 17 00:00:00 2001 From: Mat Marquis Date: Tue, 29 Jan 2013 21:18:07 -0500 Subject: [PATCH] =?UTF-8?q?Updatin=E2=80=99=20all=20my=20docfiles.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE.md | 19 +++ README.md | 209 +++++++++++++++++++++++--------- backup_excludes.txt | 15 +++ bash/{aliases => bash_aliases} | 27 +++-- bash/{exports => bash_config} | 21 ++-- bash/bash_paths | 40 ++++++ bash/bash_profile | 44 +++++-- bash/bash_prompt | 118 ++++++++++++------ bash/bashrc | 4 +- bash/functions/cleanup | 8 ++ bash/functions/datauri | 10 ++ bash/functions/gz | 11 ++ bash/functions/pyserver | 19 +++ bash/inputrc | 14 +++ bin/backup | 53 ++++++++ bin/dotfiles | 156 ++++++++++++++++++++++++ osx => bin/osxdefaults | 159 ++++++++++++++++++------ bootstrap.sh | 43 ------- git/gitattributes | 2 - git/gitconfig | 22 +++- git/gitignore | 12 +- lib/brew | 61 ++++++++++ lib/help | 22 ++++ lib/list | 37 ++++++ lib/npm | 23 ++++ lib/utils | 63 ++++++++++ vim/backups/.gitignore | 0 vim/bundle/vim-colors-solarized | 1 - vim/bundle/vim-pathogen | 1 - vim/gvimrc | 12 -- vim/swaps/.gitignore | 0 vim/undo/.gitignore | 0 vim/vimrc | 118 ------------------ 33 files changed, 996 insertions(+), 348 deletions(-) create mode 100644 LICENSE.md create mode 100644 backup_excludes.txt rename bash/{aliases => bash_aliases} (67%) rename bash/{exports => bash_config} (51%) create mode 100644 bash/bash_paths create mode 100644 bash/functions/cleanup create mode 100644 bash/functions/datauri create mode 100644 bash/functions/gz create mode 100644 bash/functions/pyserver create mode 100755 bin/backup create mode 100755 bin/dotfiles rename osx => bin/osxdefaults (50%) delete mode 100755 bootstrap.sh create mode 100644 lib/brew create mode 100644 lib/help create mode 100644 lib/list create mode 100644 lib/npm create mode 100644 lib/utils delete mode 100644 vim/backups/.gitignore delete mode 160000 vim/bundle/vim-colors-solarized delete mode 160000 vim/bundle/vim-pathogen delete mode 100644 vim/gvimrc delete mode 100644 vim/swaps/.gitignore delete mode 100644 vim/undo/.gitignore delete mode 100644 vim/vimrc diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 000000000..9339ff67b --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,19 @@ +Copyright (c) Nicolas Gallagher + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index efb83570b..0c5b3c373 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,162 @@ -# Dotfiles +# Dotfiles (Adapted from [Nicolas Gallagher’s](https://github.com/necolas/dotfiles)) My OS X dotfiles. -## Getting started +## How to install -### Prerequisites +The installation step requires the [XCode Command Line +Tools](https://developer.apple.com/downloads) and may overwrite existing +dotfiles in your HOME directory. -* Git (1.7+) -* Vim (7.3+) - I use MacVim installed with Homebrew +```bash +$ bash -c "$(curl -fsSL raw.github.com/Wilto/dotfiles/master/bin/dotfiles)" +``` + +N.B. If you wish to fork this project and maintain your own dotfiles, you must +substitute my username for your own in the above command and the 2 variables +found at the top of the `bin/dotfiles` script. + +## How to update + +You should run the update when: -### Installation +* You make a change to `~/.dotfiles/git/gitconfig` (the only file that is + copied rather than symlinked). +* You want to pull changes from the remote repository. +* You want to update Homebrew formulae and Node packages. -This will create symlinks for most of the files and the `vim` directory. -The `.gitconfig` file is copied to the HOME directory so that any private git -configuration taking place in `~/.extra` is not accidentally committed. +Run the dotfiles command: ```bash -git clone git://github.com/necolas/dotfiles.git ~/.dotfiles -cd ~/.dotfiles -bash bootstrap.sh +$ dotfiles ``` -N.B. This will overwrite any existing dotfiles in your HOME and `.vim` -directories that have the same names as those found in this repository. +Options: + + + + + + + + + + + + + + + + + + +
-h, --helpHelp
-l, --listList of additional applications to install
--no-packagesSuppress package updates
--no-syncSuppress pulling from the remote repository
+ + +## Features + +### Automatic software installation + +Homebrew formulae: + +* GNU core utilities +* [git](http://git-scm.com/) +* [ack](http://betterthangrep.com/) +* [bash-completion](http://bash-completion.alioth.debian.org/) +* jpeg +* [node](http://nodejs.org/) +* [optipng](http://optipng.sourceforge.net/) +* [phantomjs](http://phantomjs.org/) +* [tree](http://mama.indstate.edu/users/ice/tree/) +* [wget](http://www.gnu.org/software/wget/) + +Node packages: + +* [grunt](http://gruntjs.com/) +* [jshint](http://www.jshint.com/) + +N.B. If your pre-existing Homebrew installation is not in `/usr/local` then you +must prepend your custom installation's `bin` to the PATH in +`.bash_profile.local`: -### Updating +```bash +# Add `brew` command's custom location to PATH +PATH="/opt/acme/bin:$PATH" +``` + +### Custom OS X defaults -This must be done whenever you make a change to `.gitconfig` or pull -from the remote repo. +Custom OS X settings can be applied during the `dotfiles` process. They can +also be applied independently by running the following command: ```bash -cd ~/.dotfiles -bash bootstrap.sh +$ osxdefaults ``` +### Bootable backup-drive script -## Custom OS X defaults - -When setting up a new Mac, you may want to customise your OS X defaults after -installing the dotfiles. +These dotfiles include a script that will incrementally back up your data to an +external, bootable clone of your computer's internal drive. First, make sure +that the value of `DST` in the `bin/backup` script matches the name of your +backup-drive. Then run the following command: ```bash -bash .osx +$ backup ``` +For more information on how to setup your backup-drive, please read the +preparatory steps in this post on creating a [Mac OS X bootable backup +drive](http://nicolasgallagher.com/mac-osx-bootable-backup-drive-with-rsync/). + +### Custom bash prompt + +I use a custom bash prompt based on the Solarized color palette and influenced +by @gf3's and @cowboy's custom prompts. For best results, you should install +iTerm2 and import [Solarized +Dark.itermcolors](https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized). + +When your current working directory is a Git repository, the prompt will +display the checked-out branch's name (and failing that, the commit SHA that +HEAD is pointing to). The state of the working tree is reflected in the +following way: + + + + + + + + + + + + + + + + + + +
+Uncommitted changes in the index
!Unstaged changes
?Untracked files
$Stashed files
+ +Further details are in the `bash_prompt` file. + +Screenshot: + +![](http://i.imgur.com/DSJ1G.png) -## Adding custom commands +### Local and private configurations -You can use a `~/.extra` file to add custom commands without the need to fork -this repository, or to add commands that you don’t want to commit to a public -repository. If `~/.extra` exists, it will be sourced for inclusion in -`bash_profile`. +Any special-case Vim directives local to a machine should be stored in a +`.vimrc.local` file on that machine. The directives will then be automatically +imported into your master `.vimrc`. -Here is an example `~/.extra`: +Any private and custom commands should be stored in a `~/.bash_profile.local` +file. Any commands included in this file will not be under version control or +committed to a public repository. If `~/.bash_profile.local` exists, it will be +sourced for inclusion in `bash_profile`. + +Here is an example `~/.bash_profile.local`: ```bash # PATH exports @@ -60,39 +164,32 @@ PATH=$PATH:~/.gem/ruby/1.8/bin export PATH # Git credentials -# Not under version control to prevent people from accidentally -# committing with your details +# Not under version control to prevent people from +# accidentally committing with your details GIT_AUTHOR_NAME="Nicolas Gallagher" GIT_AUTHOR_EMAIL="nicolas@example.com" GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL" -# Set these credentials in ~/.gitconfig +# Set the credentials (modifies ~/.gitconfig) git config --global user.name "$GIT_AUTHOR_NAME" git config --global user.email "$GIT_AUTHOR_EMAIL" ``` - -## Custom bash prompt - -I use a custom bash prompt based on the Solarized color palette and influenced by @gf3's and @cowboy's custom prompts. Details are in the `bash_prompt` file. - -Screenshot: - -![](http://i.imgur.com/DSJ1G.png) +The `git/gitconfig` file is copied to `~/.gitconfig`, so any private git +configuration specified in `~/.bash_profile.local` will not be committed to +your dotfiles repository. ## Adding new git submodules -If you want to add more git submodules, e.g. vim plugins to be managed by +If you want to add more git submodules, e.g., Vim plugins to be managed by pathogen, then follow these steps while in the root of the superproject. ```bash # Add the new submodule -git submodule add git://example.com/remote/path/to/repo.git vim/bundle/one-submodule -# Initialize the submodule -git submodule init -# Clone the submodule -git submodule update +git submodule add https://example.com/remote/path/to/repo.git vim/bundle/one-submodule +# Initialize and clone the submodule +git submodule update --init # Stage the changes git add vim/bundle/one-submodule # Commit the changes @@ -121,9 +218,9 @@ git commit -m "Update submodule 'one-submodule' to the latest version" git push origin master ``` -Now, if anyone updates their local repository from the remote repository, then -using `git submodule update` will update the submodules (that have been -initialized) in their local repository. N.B This will wipe away any local +Now, if anyone updates their local repository from the remote repository, then +using `git submodule update` will update the submodules (that have been +initialized) in their local repository. N.B This will wipe away any local changes made to those submodules. @@ -131,7 +228,11 @@ changes made to those submodules. Inspiration and code was taken from many sources, including: -* [@mathiasbynens](https://github.com/mathiasbynens) (Mathias Bynens) [https://github.com/mathiasbynens/dotfiles](https://github.com/mathiasbynens/dotfiles) -* [@tejr](https://github.com/tejr) (Tom Ryder) [https://github.com/tejr/dotfiles](https://github.com/tejr/dotfiles) -* [@gf3](https://github.com/gf3) (Gianni Chiappetta) [https://github.com/gf3/dotfiles](https://github.com/gf3/dotfiles) -* [@cowboy](https://github.com/cowboy) (Ben Alman) [https://github.com/cowboy/dotfiles](https://github.com/cowboy/dotfiles) +* [@mathiasbynens](https://github.com/mathiasbynens) (Mathias Bynens) + [https://github.com/mathiasbynens/dotfiles](https://github.com/mathiasbynens/dotfiles) +* [@tejr](https://github.com/tejr) (Tom Ryder) + [https://github.com/tejr/dotfiles](https://github.com/tejr/dotfiles) +* [@gf3](https://github.com/gf3) (Gianni Chiappetta) + [https://github.com/gf3/dotfiles](https://github.com/gf3/dotfiles) +* [@cowboy](https://github.com/cowboy) (Ben Alman) + [https://github.com/cowboy/dotfiles](https://github.com/cowboy/dotfiles) diff --git a/backup_excludes.txt b/backup_excludes.txt new file mode 100644 index 000000000..56182c3b6 --- /dev/null +++ b/backup_excludes.txt @@ -0,0 +1,15 @@ +.Spotlight-*/ +.Trashes +/afs/* +/automount/* +/cores/* +/dev/* +/Network/* +/private/tmp/* +/private/var/run/* +/private/var/spool/postfix/* +/private/var/vm/* +/Previous Systems.localized +/tmp/* +/Volumes/* +*/.Trash diff --git a/bash/aliases b/bash/bash_aliases similarity index 67% rename from bash/aliases rename to bash/bash_aliases index ae7096e36..4f7306e9a 100644 --- a/bash/aliases +++ b/bash/bash_aliases @@ -1,4 +1,9 @@ -# aliases +#!/bin/bash + +# bash_aliases + +# Allow aliases to be with sudo +alias sudo="sudo " # Easier navigation: .., ..., ~ and - alias ..="cd .." @@ -6,6 +11,9 @@ alias ...="cd ../.." alias ~="cd ~" alias -- -="cd -" +# Git + + # List dir contents aliases # ref: http://ss64.com/osx/ls.html # Long form no user group, color @@ -20,9 +28,15 @@ alias lat="ls -AGFoth" # Concatenate and print content of files (add line numbers) alias catn="cat -n" +# Fancycat™ +alias c="pygmentize -O style=solarized -f console256 -g" + # IP addresses -alias ip="dig +short myip.opendns.com @resolver1.opendns.com" -alias localip="ipconfig getifaddr en1" +alias ip='IP=`dig +short myip.opendns.com @resolver1.opendns.com`; growlnotify -s -a terminal -t "IP Address" -m "${IP}"' +alias lip='IP=`ipconfig getifaddr en0`; growlnotify -s -a terminal -t "Local IP" -m "${IP}"' + +# Copy my public key to the pasteboard +alias pubkey="more ~/.ssh/id_rsa.pub | pbcopy | printf '=> Public key copied to pasteboard.\n'" # Flush DNS cache alias flushdns="dscacheutil -flushcache" @@ -31,12 +45,9 @@ alias flushdns="dscacheutil -flushcache" # Also, clear Apple’s System Logs to improve shell startup speed alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl" -# Recursively delete `.DS_Store` files -alias cleanup="find . -type f -name '*.DS_Store' -ls -delete" - # Show/hide hidden files in Finder -alias showdotfiles="defaults write com.apple.Finder AppleShowAllFiles -bool true && killall Finder" -alias hidedotfiles="defaults write com.apple.Finder AppleShowAllFiles -bool false && killall Finder" +alias showdotfiles="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder" +alias hidedotfiles="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder" # Hide/show all desktop icons (useful when presenting) alias showdeskicons="defaults write com.apple.finder CreateDesktop -bool true && killall Finder" diff --git a/bash/exports b/bash/bash_config similarity index 51% rename from bash/exports rename to bash/bash_config index ebfe31aac..031699d8f 100644 --- a/bash/exports +++ b/bash/bash_config @@ -1,21 +1,26 @@ -# Exports +#!/bin/bash + +# bash_config # Make vim the default editor export EDITOR="vim" + # Don't clear the screen after quitting a manual page export MANPAGER="less -X" + # Larger bash history (allow 32³ entries; default is 500) export HISTSIZE=32768 export HISTFILESIZE=$HISTSIZE export HISTCONTROL=ignoredups + # Make some commands not show up in history export HISTIGNORE="ls:ls *:cd:cd -:pwd;exit:date:* --help" -# if these bins exist, then add them to the PATH -[ -d "/usr/bin" ] && PATH="$PATH:/usr/bin"; -# add to beginning of PATH so that it always take precedence over /usr/bin -[ -d "/usr/local/bin" ] && PATH="/usr/local/bin:$PATH"; -# if the current user has a ~/bin, then add it to the PATH -[ -d "$HOME/bin" ] && PATH="$PATH:$HOME/bin"; +# Case-insensitive globbing (used in pathname expansion) +shopt -s nocaseglob + +# Append to the Bash history file, rather than overwriting it +shopt -s histappend -export PATH +# Autocorrect typos in path names when using `cd` +shopt -s cdspell diff --git a/bash/bash_paths b/bash/bash_paths new file mode 100644 index 000000000..d8d2fbe6b --- /dev/null +++ b/bash/bash_paths @@ -0,0 +1,40 @@ +#!/bin/bash + +# bash_paths + +# Directories to be prepended to PATH +declare -a dirs_to_prepend=( + "/usr/local/bin" # Ensure that this bin always takes precedence over `/usr/bin` +) + +# Directories to be appended to PATH +declare -a dirs_to_append=( + "/usr/bin" + "$HOME/bin" + "$HOME/.dotfiles/bin" + "$HOME/.rvm/bin" + "$(brew --prefix coreutils)/libexec/gnubin" # Add brew-installed GNU core utilities bin + "$(brew --prefix)/share/npm/bin" # Add npm-installed package bin +) + +# Prepend directories to PATH +for index in ${!dirs_to_prepend[*]} +do + if [ -d ${dirs_to_prepend[$index]} ]; then + # If these directories exist, then prepend them to existing PATH + PATH="${dirs_to_prepend[$index]}:$PATH" + fi +done + +# Append directories to PATH +for index in ${!dirs_to_append[*]} +do + if [ -d ${dirs_to_append[$index]} ]; then + # If these bins exist, then append them to existing PATH + PATH="$PATH:${dirs_to_append[$index]}" + fi +done + +unset dirs_to_prepend dirs_to_append + +export PATH diff --git a/bash/bash_profile b/bash/bash_profile index 43898fe44..b4feb8721 100644 --- a/bash/bash_profile +++ b/bash/bash_profile @@ -1,13 +1,31 @@ -# .bash_profile - -# Custom and private settings (e.g. git credentials) -[ -r "$HOME/.extra" ] && source "$HOME/.extra" -# Exports -[ -r "$HOME/.dotfiles/bash/exports" ] && source "$HOME/.dotfiles/bash/exports" -# Aliases -[ -r "$HOME/.dotfiles/bash/aliases" ] && source "$HOME/.dotfiles/bash/aliases" -# Custom bash prompt -[ -r "$HOME/.dotfiles/bash/bash_prompt" ] && source "$HOME/.dotfiles/bash/bash_prompt" - -# Append to the bash history file, rather than overwriting it -shopt -s histappend +#!/bin/bash + +# bash_profile + +declare -a files=( + $HOME/.rvm/scripts/rvm # Load RVM into a shell session *as a function* + $HOME/.dotfiles/bash/bash_config # Configuration + $HOME/.dotfiles/bash/bash_aliases # Aliases + $HOME/.dotfiles/bash/functions/* # Functions + $HOME/.dotfiles/bash/bash_prompt # Custom bash prompt + $HOME/.bash_profile.local # Local and private settings not under version control (e.g. git credentials) + $HOME/.dotfiles/bash/bash_paths # Path modifications (must source after `.bash_profile.local` in case of custom `brew` location) +) + +# If these files are readable, source them +for index in ${!files[*]} +do + if [[ -r ${files[$index]} ]]; then + source ${files[$index]} + fi +done + +unset files + +# Only use `brew` after it has been added to the PATH +bash_completion_path="$(brew --prefix)/etc/bash_completion" + +# Source Bash completion (installed via Homebrew) +if [[ -r $bash_completion_path ]]; then + source $bash_completion_path +fi diff --git a/bash/bash_prompt b/bash/bash_prompt index c940ceabf..7035896fd 100644 --- a/bash/bash_prompt +++ b/bash/bash_prompt @@ -1,14 +1,16 @@ +#!/bin/bash + # bash_prompt -# Based on @gf3’s Sexy Bash Prompt: https://github.com/gf3/dotfiles +# Example: +# nicolas@host: ~/.dotfiles on master[+!?$] +# $ + +# Screenshot: http://i.imgur.com/DSJ1G.png # iTerm2 prefs: import Solarized theme (disable bright colors for bold text) # Color ref: http://vim.wikia.com/wiki/Xterm256_color_names_for_console_Vim # More tips: http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html -# Screenshot: http://i.imgur.com/DSJ1G.png -# Example: -# nicolas@host: ~/.dotfiles on master[!?] -# $ # Check that terminfo exists before changing TERM var to xterm-256color # Prevents prompt flashing in Mac OS X 10.6 Terminal.app @@ -33,51 +35,91 @@ SOLAR_CYAN=$(tput setaf 37) SOLAR_GREEN=$(tput setaf 64) SOLAR_WHITE=$(tput setaf 254) -style_user="$RESET$SOLAR_ORANGE" -style_host="$RESET$SOLAR_YELLOW" -style_path="$RESET$SOLAR_GREEN" -style_branch="$RESET$SOLAR_CYAN" -style_chars="$RESET$SOLAR_WHITE" +style_user="\[${RESET}${SOLAR_ORANGE}\]" +style_host="\[${RESET}${SOLAR_YELLOW}\]" +style_path="\[${RESET}${SOLAR_GREEN}\]" +style_chars="\[${RESET}${SOLAR_WHITE}\]" +style_branch="${SOLAR_CYAN}" if [[ "$SSH_TTY" ]]; then # connected via ssh - style_host="$BOLD$SOLAR_RED" + style_host="\[${BOLD}${SOLAR_RED}\]" elif [[ "$USER" == "root" ]]; then # logged in as root - style_user="$BOLD$SOLAR_RED" + style_user="\[${BOLD}${SOLAR_RED}\]" fi +is_git_repo() { + $(git rev-parse --is-inside-work-tree &> /dev/null) +} + +is_git_dir() { + $(git rev-parse --is-inside-git-dir 2> /dev/null) +} + +get_git_branch() { + local branch_name + + # Get the short symbolic ref + branch_name=$(git symbolic-ref --quiet --short HEAD 2> /dev/null) || + # If HEAD isn't a symbolic ref, get the short SHA + branch_name=$(git rev-parse --short HEAD 2> /dev/null) || + # Otherwise, just give up + branch_name="(unknown)" + + printf $branch_name +} + +# Git status information +prompt_git() { + local git_info git_state uc us ut st + + if ! is_git_repo || is_git_dir; then + return 1 + fi + + git_info=$(get_git_branch) + + # Check for uncommitted changes in the index + if ! $(git diff --quiet --ignore-submodules --cached); then + uc="${SOLAR_GREEN}+" + fi + + # Check for unstaged changes + if ! $(git diff-files --quiet --ignore-submodules --); then + us="${SOLAR_RED}!" + fi -# Git status. -# Adapted from: https://github.com/cowboy/dotfiles/ -function prompt_git() { - local status output flags - status="$(git status 2>/dev/null)" - [[ $? != 0 ]] && return; - output="$(echo "$status" | awk '/# Initial commit/ {print "(init)"}')" - [[ "$output" ]] || output="$(echo "$status" | awk '/# On branch/ {print $4}')" - [[ "$output" ]] || output="$(git branch | perl -ne '/^\* (.*)/ && print $1')" - flags="$( - echo "$status" | awk 'BEGIN {r=""} \ - /^# Changes to be committed:$/ {r=r "+"}\ - /^# Changes not staged for commit:$/ {r=r "!"}\ - /^# Untracked files:$/ {r=r "?"}\ - END {print r}' - )" - if [[ "$flags" ]]; then - output="$output[$flags]" + # Check for untracked files + if [ -n "$(git ls-files --others --exclude-standard)" ]; then + ut="${SOLAR_ORANGE}?" fi - echo "$style_chars on $style_branch$output" + + # Check for stashed files + if $(git rev-parse --verify refs/stash &>/dev/null); then + st="${SOLAR_YELLOW}$" + fi + + git_state=$uc$us$ut$st + + # Combine the branch name and state information + if [[ $git_state ]]; then + git_info="$git_info[$git_state${SOLAR_CYAN}]" + fi + + printf "${SOLAR_WHITE} on ${style_branch}${git_info}" } +# Set the terminal title to the current working directory +PS1="\[\033]0;\w\007\]" # Build the prompt -PS1="\n" # Newline -PS1+="$style_user\u" # Username -PS1+="$style_chars@" # @ -PS1+="$style_host\h" # Host -PS1+="$style_chars: " # : -PS1+="$style_path\w" # Working directory +PS1+="\n" # Newline +PS1+="${style_user}\u" # Username +PS1+="${style_chars}@" # @ +PS1+="${style_host}\h" # Host +PS1+="${style_chars}: " # : +PS1+="${style_path}\w" # Working directory PS1+="\$(prompt_git)" # Git details PS1+="\n" # Newline -PS1+="$style_chars\$ $RESET" # $ (and reset color) +PS1+="${style_chars}\$ \[${RESET}\]" # $ (and reset color) diff --git a/bash/bashrc b/bash/bashrc index 594e078ec..f91dc2bf6 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -1,3 +1,5 @@ -# .bashrc +#!/bin/bash + +# bashrc [ -n "$PS1" ] && source ~/.bash_profile diff --git a/bash/functions/cleanup b/bash/functions/cleanup new file mode 100644 index 000000000..5f4cfd373 --- /dev/null +++ b/bash/functions/cleanup @@ -0,0 +1,8 @@ +#!/bin/bash + +# Recursively delete files that match a certain pattern +# (by default delete all `.DS_Store` files) +cleanup() { + local q="${1:-*.DS_Store}" + find . -type f -name "$q" -ls -delete +} diff --git a/bash/functions/datauri b/bash/functions/datauri new file mode 100644 index 000000000..8a1d0f213 --- /dev/null +++ b/bash/functions/datauri @@ -0,0 +1,10 @@ +#!/bin/bash + +# Create a data URI from a file and copy it to the pasteboard +datauri() { + local mimeType=$(file -b --mime-type "$1") + if [[ $mimeType == text/* ]]; then + mimeType="${mimeType};charset=utf-8" + fi + printf "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')" | pbcopy | printf "=> data URI copied to pasteboard.\n" +} diff --git a/bash/functions/gz b/bash/functions/gz new file mode 100644 index 000000000..87c5d4270 --- /dev/null +++ b/bash/functions/gz @@ -0,0 +1,11 @@ +#!/bin/bash + +# Compare original and gzipped file size +gz() { + local origsize=$(wc -c < "$1") + local gzipsize=$(gzip -c "$1" | wc -c) + local ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l) + + printf "orig: %d bytes\n" "$origsize" + printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio" +} diff --git a/bash/functions/pyserver b/bash/functions/pyserver new file mode 100644 index 000000000..eee309d3b --- /dev/null +++ b/bash/functions/pyserver @@ -0,0 +1,19 @@ +#!/bin/bash + +# Start an HTTP server from a directory, optionally specifying the port +pyserver() { + # Get port (if specified) + local port="${1:-8000}" + + # Open in the browser + open "http://localhost:${port}/" + + # Redefining the default content-type to text/plain instead of the default + # application/octet-stream allows "unknown" files to be viewable in-browser + # as text instead of being downloaded. + # + # Unfortunately, "python -m SimpleHTTPServer" doesn't allow you to redefine + # the default content-type, but the SimpleHTTPServer module can be executed + # manually with just a few lines of code. + python -c $'import SimpleHTTPServer;\nSimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map[""] = "text/plain";\nSimpleHTTPServer.test();' "$port" +} diff --git a/bash/inputrc b/bash/inputrc index e69de29bb..8e24bbf87 100644 --- a/bash/inputrc +++ b/bash/inputrc @@ -0,0 +1,14 @@ +#!/bin/bash + +# inputrc + +# Use case-insensitive TAB autocompletion +set completion-ignore-case on + +# Make TAB cycle through possible completions +"\t": menu-complete + +# Use the string that has already been typed as the prefix for searching +# through commands (i.e. more intelligent Up/Down behavior) +"\e[B": history-search-forward +"\e[A": history-search-backward diff --git a/bin/backup b/bin/backup new file mode 100755 index 000000000..f256f33c6 --- /dev/null +++ b/bin/backup @@ -0,0 +1,53 @@ +#!/bin/bash + +# Disc backup script + +# IMPORTANT: Make sure you update the `DST` variable to match the name of the +# destination backup drive + +PROG=$0 +RSYNC="/usr/bin/rsync" +LOGGER="/usr/bin/logger" +SRC="/" +DST="/Volumes/Macintosh HD/" +EXCLUDE="$HOME/.dotfiles/backup_excludes.txt" + +# --verbose increase verbosity +# --archive turn on archive mode (recursive copy + retain attributes) +# --one-file-system don't cross device boundaries (ignore mounted volumes) +# --sparse handle spare files efficiently +# --hard-links preserve hard-links +# --extended-attributes preserve ACLs and Resource Forks +# --delete delete any files that have been deleted locally +# --delete-excluded delete any files (on DST) that are part of the list of excluded files +# --exclude-from reference a list of files to exclude + +if [ ! -r "$SRC" ]; then + $LOGGER -t $PROG "Source $SRC not readable - Cannot start the sync process" + exit; +fi + +if [ ! -w "$DST" ]; then + $LOGGER -t $PROG "Destination $DST not writeable - Cannot start the sync process" + exit; +fi + +$LOGGER -t $PROG "Start rsync" + +sudo $RSYNC --verbose \ + --archive \ + --one-file-system \ + --sparse \ + --hard-links \ + --extended-attributes \ + --delete \ + --delete-excluded \ + --exclude-from=$EXCLUDE \ + "$SRC" "$DST" + +$LOGGER -t $PROG "End rsync" + +# Make the backup bootable +sudo bless -folder "$DST"/System/Library/CoreServices + +exit 0 diff --git a/bin/dotfiles b/bin/dotfiles new file mode 100755 index 000000000..b2250e967 --- /dev/null +++ b/bin/dotfiles @@ -0,0 +1,156 @@ +#!/bin/bash + +DOTFILES_DIRECTORY="${HOME}/.dotfiles" +DOTFILES_TARBALL_PATH="https://github.com/necolas/dotfiles/tarball/master" +DOTFILES_GIT_REMOTE="https://github.com/necolas/dotfiles" + +# If missing, download and extract the dotfiles repository +if [[ ! -d ${DOTFILES_DIRECTORY} ]]; then + printf "$(tput setaf 7)Downloading dotfiles...\033[m\n" + mkdir ${DOTFILES_DIRECTORY} + # Get the tarball + curl -fsSLo ${HOME}/dotfiles.tar.gz ${DOTFILES_TARBALL_PATH} + # Extract to the dotfiles directory + tar -zxf ${HOME}/dotfiles.tar.gz --strip-components 1 -C ${DOTFILES_DIRECTORY} + # Remove the tarball + rm -rf ${HOME}/dotfiles.tar.gz +fi + +cd ${DOTFILES_DIRECTORY} + +source ./lib/help +source ./lib/list +source ./lib/utils +source ./lib/brew +source ./lib/npm + +# Help text +if [[ "$1" == "-h" || "$1" == "--help" ]]; then + run_help + exit +fi + +# List additional software to install +if [[ "$1" == "-l" || "$1" == "--list" ]]; then + run_list + exit +fi + +# Test for known flags +for opt in $@ +do + case $opt in + --no-packages) no_packages=true ;; + --no-sync) no_sync=true ;; + -*|--*) e_warning "Warning: invalid option $opt" ;; + esac +done + +# Before relying on Homebrew, check that packages can be compiled +if ! type_exists 'gcc'; then + e_error "The XCode Command Line Tools must be installed first." + printf " Download them from: https://developer.apple.com/downloads\n" + printf " Then run: bash ~/.dotfiles/bin/dotfiles\n" + exit 1 +fi + +# Check for Homebrew +if ! type_exists 'brew'; then + e_header "Installing Homebrew..." + ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" +fi + +# Check for git +if ! type_exists 'git'; then + e_header "Updating Homebrew..." + brew update + e_header "Installing Git..." + brew install git +fi + +# Initialize the git repository if it's missing +if ! is_git_repo; then + e_header "Initializing git repository..." + git init + git remote add origin ${DOTFILES_GIT_REMOTE} + git fetch origin master + # Reset the index and working tree to the fetched HEAD + # (submodules are cloned in the subsequent sync step) + git reset --hard FETCH_HEAD + # Remove any untracked files + git clean -fd +fi + +# Conditionally sync with the remote repository +if [[ $no_sync ]]; then + printf "Skipped dotfiles sync.\n" +else + e_header "Syncing dotfiles..." + # Pull down the latest changes + git pull --rebase origin master + # Update submodules + git submodule update --recursive --init --quiet +fi + +# Install and update packages +if [[ $no_packages ]]; then + printf "Skipped package installations.\n" +else + printf "Updating packages...\n" + # Install Homebrew formulae + run_brew + # Install Node packages + run_npm +fi + +link() { + # Force create/replace the symlink. + ln -fs "${DOTFILES_DIRECTORY}/${1}" "${HOME}/${2}" +} + +mirrorfiles() { + # Copy `.gitconfig`. + # Any global git commands in `~/.bash_profile.local` will be written to + # `.gitconfig`. This prevents them being committed to the repository. + rsync -avz --quiet ${DOTFILES_DIRECTORY}/git/gitconfig ${HOME}/.gitconfig + + # Force remove the vim directory if it's already there. + if [ -e "${HOME}/.vim" ]; then + rm -rf "${HOME}/.vim" + fi + + # Create the necessary symbolic links between the `.dotfiles` and `HOME` + # directory. The `bash_profile` sources other files directly from the + # `.dotfiles` repository. + link "bash/bashrc" ".bashrc" + link "bash/bash_profile" ".bash_profile" + link "bash/inputrc" ".inputrc" + link "git/gitattributes" ".gitattributes" + link "git/gitignore" ".gitignore" + link "vim" ".vim" + link "vim/gvimrc" ".gvimrc" + link "vim/vimrc" ".vimrc" + + e_success "Dotfiles update complete!" +} + +# Ask before potentially overwriting files +seek_confirmation "Warning: This step may overwrite your existing dotfiles." + +if is_confirmed; then + mirrorfiles + source ${HOME}/.bash_profile +else + printf "Aborting...\n" + exit 1 +fi + +# Ask before potentially overwriting OS X defaults +seek_confirmation "Warning: This step may modify your OS X system defaults." + +if is_confirmed; then + bash ./bin/osxdefaults + e_success "OS X settings updated! You may need to restart." +else + printf "Skipped OS X settings update.\n" +fi diff --git a/osx b/bin/osxdefaults similarity index 50% rename from osx rename to bin/osxdefaults index f4528a05d..03682dbfa 100755 --- a/osx +++ b/bin/osxdefaults @@ -1,91 +1,174 @@ -# .osx +#!/bin/bash -# Menu bar: show remaining battery time; hide percentage -defaults write com.apple.menuextra.battery ShowPercent -string "NO" -defaults write com.apple.menuextra.battery ShowTime -string "YES" -# Menu bar: disable transparency -# defaults write NSGlobalDomain AppleEnableMenuBarTransparency -bool false +# Set custom OS X defaults +# See: github.com/mathiasbynens/dotfiles -# Desktop: enable snap-to-grid for desktop icons +# General UI/UX +# ---------------------------------------------------------------------- + +# Disable Menu bar transparency +defaults write NSGlobalDomain AppleEnableMenuBarTransparency -bool false + +# Enable snap-to-grid for desktop icons /usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist -# Desktop: enable Dashboard dev mode (allows keeping widgets on the desktop) -# defaults write com.apple.dashboard devmode -bool true -# Dock: enable 2D +# Always show scrollbars +defaults write NSGlobalDomain AppleShowScrollBars -string "Always" + +# Save to disk (not to iCloud) by default +defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false + +# Automatically quit printer app once the print jobs complete +defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true + +# Disable automatic termination of inactive apps +defaults write NSGlobalDomain NSDisableAutomaticTermination -bool true + +# Disable Resume system-wide +defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false + +# Disable press-and-hold for keys in favor of key repeat +defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false + +# Set a blazingly fast keyboard repeat rate +defaults write NSGlobalDomain KeyRepeat -int 0 + +# Finder: kill the desktop +defaults write com.apple.finder CreateDesktop -bool true + +# Dock +# ---------------------------------------------------------------------- + +# Dock: enable the 2D Dock defaults write com.apple.dock no-glass -bool true -# Dock: position on the left -defaults write com.apple.dock orientation left -# Dock: use the scale effect for window minimizing -defaults write com.apple.dock mineffect scale -# Dock: make icons of hidden applications translucent -defaults write com.apple.dock showhidden -bool true + +# Dock: set the icon size of Dock items to 28 pixels +defaults write com.apple.dock tilesize -int 28 + # Dock: show indicator lights for open applications defaults write com.apple.dock show-process-indicators -bool true + +# Dock: make icons of hidden applications translucent +defaults write com.apple.dock showhidden -bool true + # Dock: don’t animate opening applications defaults write com.apple.dock launchanim -bool false +# Dock: use the scale effect for window minimizing +defaults write com.apple.dock mineffect scale + +# Dock: speed up Mission Control animations +defaults write com.apple.dock expose-animation-duration -float 0.1 + + +# Finder +# ---------------------------------------------------------------------- + # Finder: show all filename extensions defaults write NSGlobalDomain AppleShowAllExtensions -bool true + # Finder: disable the warning when changing a file extension defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false + # Finder: empty Trash securely by default defaults write com.apple.finder EmptyTrashSecurely -bool true + # Finder: disable window and Get Info animations defaults write com.apple.finder DisableAllAnimations -bool true -# Finder: allow quitting via ⌘ + Q; doing so will also hide desktop icons -# defaults write com.apple.finder QuitMenuItem -bool true + # Finder: show the ~/Library folder (in OS X Lion) -# chflags nohidden ~/Library +chflags nohidden ~/Library + +# Finder: show hidden files by default +defaults write com.apple.finder AppleShowAllFiles -bool true + +# Finder: use list view in all windows by default +# Four-letter codes for the other view modes: `icnv`, `clmv`, `Flwv` +defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv" + +# Show icons for hard drives, servers, and removable media on the desktop +defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true +defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true +defaults write com.apple.finder ShowMountedServersOnDesktop -bool true +defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true + + +# Panels +# ---------------------------------------------------------------------- # Panels: expand save panel by default defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true + # Panels: expand print panel by default defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true + # Panels: disable the “Are you sure you want to open this application?” dialog defaults write com.apple.LaunchServices LSQuarantine -bool false + # Panels: enable full keyboard access for all controls (e.g. enable Tab in modal dialogs) defaults write NSGlobalDomain AppleKeyboardUIMode -int 3 + +# Screen +# ---------------------------------------------------------------------- + +# Screen: require password immediately after sleep or screen saver begins +defaults write com.apple.screensaver askForPassword -int 1 +defaults write com.apple.screensaver askForPasswordDelay -int 0 + +# Screen: save screenshots to the desktop +defaults write com.apple.screencapture location -string "$HOME/Desktop" + +# Screen: disable shadow in screenshots +defaults write com.apple.screencapture disable-shadow -bool true + +# Screen: enable subpixel font rendering on non-Apple LCDs +defaults write NSGlobalDomain AppleFontSmoothing -int 2 + + +# Disks +# ---------------------------------------------------------------------- + # Disks: avoid creating .DS_Store files on network volumes defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true -# Disks: disable TimeMachine prompts + +# Disks: disable Time Machine prompts defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true + # Disks: disable local Time Machine backups hash tmutil &> /dev/null && sudo tmutil disablelocal + # Disks: disable disk image verification # defaults write com.apple.frameworks.diskimages skip-verify -bool true # defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true # defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true -# ...if you really insist on using iTunes + +# iTunes +# ---------------------------------------------------------------------- + # iTunes: make ⌘ + F focus the search input defaults write com.apple.iTunes NSUserKeyEquivalents -dict-add "Target Search Field" "@F" + # iTunes: disable the Ping sidebar in iTunes defaults write com.apple.iTunes disablePingSidebar -bool true + # iTunes: disable all the other Ping stuff defaults write com.apple.iTunes disablePing -bool true -# Security: require password immediately after sleep or screen saver begins -defaults write com.apple.screensaver askForPassword -int 1 -defaults write com.apple.screensaver askForPasswordDelay -int 0 -# Misc: enable subpixel font rendering on non-Apple LCDs -defaults write NSGlobalDomain AppleFontSmoothing -int 2 -# Misc: disable shadow in screenshots -defaults write com.apple.screencapture disable-shadow -bool true -# Misc: disable Resume system-wide -defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false +# Misc +# ---------------------------------------------------------------------- + # Misc: only use UTF-8 in Terminal.app defaults write com.apple.terminal StringEncodings -array 4 + # Misc: disable Dictionary results defaults write com.apple.spotlight DictionaryLookupEnabled -bool false + # Misc: disable auto-correct defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false -# Misc: disable press-and-hold for keys in favor of key repeat -# defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false -# Misc: Set a blazingly fast keyboard repeat rate -# defaults write NSGlobalDomain KeyRepeat -int 0 - -# Map bottom right Trackpad corner to right-click -defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2 -defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true + +for app in "Dashboard" "Dock" "Finder" "SystemUIServer" "Terminal" "iTunes"; do + killall "$app" > /dev/null 2>&1 +done diff --git a/bootstrap.sh b/bootstrap.sh deleted file mode 100755 index ef266cdab..000000000 --- a/bootstrap.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -cd "${HOME}/.dotfiles" - -# Pull down the latest changes -# git pull origin master - -# Check out submodules -git submodule --quiet update --init - -cd "${OLDPWD}" - -function mirrorfiles() { - # Copy .gitconfig - # Any global git commands in ~/.extra will be written to .gitconfig - # This prevents them being committed to the repository - rsync -avz --quiet ${HOME}/.dotfiles/git/gitconfig ${HOME}/.gitconfig - - # Symlink everything else - # bash_profile sources other files from the repository - # Force remove the vim directory if it is already there - if [ -e "${HOME}/.vim" ]; then - rm -rf "${HOME}/.vim" - fi - ln -fs ".dotfiles/osx" "${HOME}/.osx" - ln -fs ".dotfiles/bash/bashrc" "${HOME}/.bashrc" - ln -fs ".dotfiles/bash/bash_profile" "${HOME}/.bash_profile" - ln -fs ".dotfiles/bash/inputrc" "${HOME}/.inputrc" - ln -fs ".dotfiles/git/gitattributes" "${HOME}/.gitattributes" - ln -fs ".dotfiles/git/gitignore" "${HOME}/.gitignore" - ln -fs ".dotfiles/vim" "${HOME}/.vim" - ln -fs ".dotfiles/vim/gvimrc" "${HOME}/.gvimrc" - ln -fs ".dotfiles/vim/vimrc" "${HOME}/.vimrc" - - echo "Dotfiles update complete" -} - -read -p "This will overwrite some existing files in your home directory. Are you sure? (y/n) " -n 1 -echo -if [[ $REPLY =~ ^[Yy]$ ]]; then - mirrorfiles - source ~/.bash_profile -fi diff --git a/git/gitattributes b/git/gitattributes index 0a91f7516..e69de29bb 100644 --- a/git/gitattributes +++ b/git/gitattributes @@ -1,2 +0,0 @@ -# Automatically normalize line endings for all text-based files -* text=auto diff --git a/git/gitconfig b/git/gitconfig index 3b6f6d651..eecd92ccf 100644 --- a/git/gitconfig +++ b/git/gitconfig @@ -9,23 +9,32 @@ cleanup = !git clean -df && git stash clear # Add untracked, remove deleted, and show status - addu = !git add . && git add -u && git status + adda = !git add -A && git status + + # Fetch a repository ($1) and checkout its ref ($2) HEAD + browse = !bash -c 'git fetch "$1" "$2" && git checkout FETCH_HEAD' - # Diff what is staged for the next commit diffc = diff --cached # Diff overview diffst = diff --stat - # Custom graph log (note, uses `logp` alias) - graph = !git logp --graph + # Custom graph log (append any tree-ish) + graph = log --pretty=nice --date-order --graph + # Custom graph log for all branches + grapha = log --pretty=nice --date-order --graph --all + # Custom pretty log - logp = log --pretty=nice --all --date-order + logp = log --pretty=nice --date-order # Diffstat log logst = log --stat # Short format diffstat log logsf = log --stat --format=oneline --abbrev-commit + # Display the number of commits per author in numerical order + who = shortlog -sn -- + [color] # color opts: normal, black, red, green, yellow, blue, magenta, cyan, or white ui = auto @@ -36,6 +45,9 @@ excludesfile = ~/.gitignore attributesfile = ~/.gitattributes +[credential] + helper = osxkeychain + [diff] tool = mvimdiff @@ -45,5 +57,5 @@ [pretty] # tut: http://gitimmersion.com/lab_10.html # ref: http://linux.die.net/man/1/git-log - # Result: abc1234 Commit message (HEAD, origin/master, master) -- Nicolas Gallagher; 5 hours ago + # Result: () -- ; nice = "%C(yellow)%h%C(reset) %C(white)%s%C(cyan)%d%C(reset) -- %an; %ar" diff --git a/git/gitignore b/git/gitignore index 23654afe9..b182f1d9d 100644 --- a/git/gitignore +++ b/git/gitignore @@ -1,6 +1,6 @@ # OS or Editor files -.DS_Store ._* +.DS_Store Thumbs.db # Files that might appear on external disks @@ -8,13 +8,13 @@ Thumbs.db .Trashes # Always-ignore extensions +*~ *.diff *.err -*.orig *.log +*.orig +*.pyc *.rej -*.swo -*.swp -*.vi -*~ *.sass-cache +*.sw? +*.vi diff --git a/lib/brew b/lib/brew new file mode 100644 index 000000000..dded9401a --- /dev/null +++ b/lib/brew @@ -0,0 +1,61 @@ +#!/bin/bash + +run_brew() { + + # Check for Homebrew + if type_exists 'brew'; then + e_header "Updating Homebrew..." + # Use the latest version of Homebrew + brew update + [[ $? ]] && e_success "Done" + + e_header "Updating any existing Homebrew formulae..." + # Upgrade any already-installed formulae + brew upgrade + [[ $? ]] && e_success "Done" + + e_header "Checking status of desired Homebrew formulae..." + local list_formulae + local -a missing_formulae + local -a desired_formulae=( + 'coreutils' # GNU core utilities (those that come with OS X are outdated) + 'git' + 'ack' + 'bash-completion' + 'jpeg' + 'node' + 'optipng' + 'phantomjs' + 'tree' + 'wget' + ) + + for index in ${!desired_formulae[*]} + do + if ! formula_exists ${desired_formulae[$index]}; then + # Store the name (and options) of every missing formula + missing_formulae=("${missing_formulae[@]}" "${desired_formulae[$index]}") + fi + done + + if [[ "$missing_formulae" ]]; then + # Convert the array of missing formula into a list of space-separate strings + list_formulae=$( printf "%s " "${missing_formulae[@]}" ) + + e_header "Installing missing Homebrew formulae..." + # Install all missing formulae + brew install $list_formulae + + [[ $? ]] && e_success "Done" + fi + + # Remove outdated versions from the Cellar + brew cleanup + else + printf "\n" + e_error "Error: Homebrew not found." + printf "Aborting...\n" + exit + fi + +} diff --git a/lib/help b/lib/help new file mode 100644 index 000000000..0de8af594 --- /dev/null +++ b/lib/help @@ -0,0 +1,22 @@ +#!/bin/bash + +run_help() { + +cat < /dev/null) +} + +# Test whether a command exists +# $1 - cmd to test +type_exists() { + if [ $(type -P $1) ]; then + return 0 + fi + return 1 +} + +# Test whether a Homebrew formula is already installed +# $1 - formula name (may include options) +formula_exists() { + if $(brew list $1 >/dev/null); then + printf "%s already installed.\n" "$1" + return 0 + fi + + e_warning "Missing formula: $1" + return 1 +} diff --git a/vim/backups/.gitignore b/vim/backups/.gitignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/vim/bundle/vim-colors-solarized b/vim/bundle/vim-colors-solarized deleted file mode 160000 index 528a59f26..000000000 --- a/vim/bundle/vim-colors-solarized +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 528a59f26d12278698bb946f8fb82a63711eec21 diff --git a/vim/bundle/vim-pathogen b/vim/bundle/vim-pathogen deleted file mode 160000 index c9fb89dd6..000000000 --- a/vim/bundle/vim-pathogen +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c9fb89dd6efdeedb95c411ec78b3a9493602d33d diff --git a/vim/gvimrc b/vim/gvimrc deleted file mode 100644 index 593e82de6..000000000 --- a/vim/gvimrc +++ /dev/null @@ -1,12 +0,0 @@ -" .gvimrc - -" Hide the MacVIm toolbar -set go-=T -" Always display the tab bar -set showtabline -" Turn off the blinking cursor in normal mode -set gcr=n:blinkon0 -" Set 6px space between lines -set linespace=5 -" Set GUI font -set guifont=Consolas:h14 diff --git a/vim/swaps/.gitignore b/vim/swaps/.gitignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/vim/undo/.gitignore b/vim/undo/.gitignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/vim/vimrc b/vim/vimrc deleted file mode 100644 index 42dcfe10f..000000000 --- a/vim/vimrc +++ /dev/null @@ -1,118 +0,0 @@ -" .vimrc - -" !silent is used to suppress error messages if the config line -" references plugins/colorschemes that might be missing - -" Disable Vi compatibility -set nocompatible - -" Point to location of pathogen submodule (since it's not in .vim/autoload) -silent! runtime bundle/vim-pathogen/autoload/pathogen.vim -" Call pathogen plugin management -silent! call pathogen#infect() - -" Load files for specific filetypes -if has("autocmd") - filetype on - filetype indent on - filetype plugin on -endif - -if has("syntax") - " Enable syntax highlighting - syntax enable - " Set 256 color terminal support - set t_Co=256 - " Set dark background - set background=dark - " Set colorscheme - silent! colorscheme solarized -endif - -if has("cmdline_info") - " Show the cursor line and column number - set ruler - " Show partial commands in status line - set showcmd - " Show whether in insert or replace mode - set showmode -endif - -if has('statusline') - " Always show status line - set laststatus=2 - " Broken down into easily includeable segments - " Filename - set statusline=%<%f\ - " Options - set statusline+=%w%h%m%r - " Current dir - set statusline+=\ [%{getcwd()}] - " Right aligned file nav info - set statusline+=%=%-14.(%l,%c%V%)\ %p%% -endif - -if has("wildmenu") - " Show a list of possible completions - set wildmenu - " Tab autocomplete longest possible part of a string, then list - set wildmode=longest,list - if has ("wildignore") - set wildignore+=*.a,*.o - set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png - set wildignore+=.DS_Store,.git,.hg,.svn - set wildignore+=*~,*.swp,*.tmp - endif -endif - -if has("extra_search") - " Highlight searches [use :noh to clear] - set hlsearch - " Highlight dynamically as pattern is typed - set incsearch - " Ignore case of searches... - set ignorecase - " ...unless has mixed case - set smartcase -endif - -" Backspace through everything in INSERT mode -set backspace=indent,eol,start -" Optimize for fast terminal connections -set ttyfast -" Use UTF-8 without BOM -set encoding=utf-8 nobomb - -" Use 4 spaces for indentation -set shiftwidth=4 -" Use 4 spaces for soft tab -set softtabstop=4 -" Use 4 spaces for tab -set tabstop=4 -" Expand tab to spaces -set expandtab -" Enable line numbers -set number -" Highlight current line -set cursorline -" Increase default number of lines -set lines=40 -" Start scrolling three lines before the horizontal window border -set scrolloff=3 -" Don’t reset cursor to start of line when moving around. -set nostartofline - -" Show 'invisible' characters -set list -" Set characters used to indicate 'invisible' characters -set listchars=tab:▸\ -set listchars+=trail:· -set listchars+=nbsp:_ -"set listchars+=eol:¬ - -" Centralize backups, swapfiles and undo history -set backupdir=~/.vim/backups -set directory=~/.vim/swaps -if exists("&undodir") - set undodir=~/.vim/undo -endif