diff --git a/bootstrap.sh b/bootstrap.sh index 12f5fd79..fabae897 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,12 +1,7 @@ -#!/bin/sh -case `uname` in - 'Darwin') - readlink_command='greadlink' - ;; - *) - readlink_command='readlink' -esac -DOTFILES_DIRECTORY="$(dirname "${BASH_SOURCE}" | xargs ${readlink_command} -f)/dotfiles" +#!/usr/bin/env bash +cd $BASH_SOURCE && source dotfiles/lib/shellrc/aliases.sh && source dotfiles/lib/bash/aliases.sh +DOTFILES_DIRECTORY="(sourcefile_abspath)/dotfiles" +echo $DOTFILES_DIRECTORY function symlink_dotfiles() { cd $DOTFILES_DIRECTORY @@ -25,15 +20,24 @@ function symlink_dotfiles() { [ -a ~/.dotfiles-backups.old ] && mv ~/.dotfiles-backups.old ~/.dotfiles-backups/.dotfiles-backups } -if [ "$1" = "--force" -o "$1" = "-f" ]; then - symlink_dotfiles -else + +function parse_options() { + while getopts "f" OPTCHAR; do + case $optchar in + f) + symlink_dotfiles + return + ;; + esac + done + shift $((OPTIND-1)) + read -p "Symlinking files from $DOTFILES_DIRECTORY. This may overwrite existing files in your home directory. Do you wish to proceed? (y/n) " -n 1 echo if [[ $REPLY =~ ^[Yy]$ ]]; then symlink_dotfiles fi -fi + +} -unset symlink_dotfiles -unset DOTFILES_DIRECTORY +parse_options() diff --git a/dotfiles/gitconfig b/dotfiles/gitconfig index 4d771e15..a3ae108b 100644 --- a/dotfiles/gitconfig +++ b/dotfiles/gitconfig @@ -1,34 +1,36 @@ [alias] - # View the SHA, description, and history graph of the latest 20 commits l = log --pretty=oneline -n 20 --graph - # View the current working tree status using the short format s = status -s - # Clone a repository including all submodules c = clone --recursive ff = merge --ff-only + ca = !git add -A && git commit -av + cam = commit -am + suir = submodule update --init --recursive + poh = push origin HEAD + pohm = push origin HEAD:master + amend = commit -a --amend -C HEAD + dirty = "!t() { test -n \"$(git status --porcelain)\"; }; t" + + branches = branch -a + remotes = remote -v + + which-branch = "!wb() { b="$(git symbolic-ref HEAD)" && echo ${b#refs/heads/}; }; wb" + sha = rev-parse HEAD + branch-or-sha = "!bs() { git which-branch 2> /dev/null || git sha 2> /dev/null ; }; bs" + # In newer versions of git, this simpler definition of which-branch would work. + # symbolic-ref HEAD --short + ffr = "!ffr() { git fetch $1 && git ff origin/$(git which-branch) && git suir; }; ffr" ffo = !git ffr origin - cam = commit -am - # Commit all changes - ca = !git add -A && git commit -av - branches = branch -a - remotes = remote -v + reset-origin = "!r() { git reset --hard origin/\"$(git which-branch)\" && git suir; }; r" + # Credit an author on the latest commit credit = "!f() { git commit --amend --author \"$1 <$2>\" -C HEAD; }; f" # Interactive rebase with the given number of latest commits reb = "!r() { git rebase -i HEAD~$1; }; r" - suir = submodule update --init --recursive - poh = push origin HEAD - pohm = push origin HEAD:master - # Diff a file or show it in git's pager if it is untracked du = "!d() { git ls-files $1 --error-unmatch 2>/dev/null 1>/dev/null && git diff $1 || `git config --get core.pager` $1; }; d" - which-branch = "!wb() { b="$(git symbolic-ref HEAD)" && echo ${b#refs/heads/}; }; wb" # symbolic-ref HEAD --short - sha = rev-parse HEAD - branch-or-sha = "!bs() { git which-branch 2> /dev/null || git sha 2> /dev/null ; }; bs" - amend = commit -a --amend -C HEAD - reset-origin = "!r() { git reset --hard origin/\"$(git which-branch)\" && git suir; }; r" - + [core] # Use custom `.gitignore` and `.gitattributes` excludesfile = ~/.gitignore diff --git a/dotfiles/lib/bash/aliases.sh b/dotfiles/lib/bash/aliases.sh new file mode 100644 index 00000000..f254a9f3 --- /dev/null +++ b/dotfiles/lib/bash/aliases.sh @@ -0,0 +1 @@ +alias sourcefile_abspath='$(readlink -f "$BASH_SOURCE" | xargs dirname)' diff --git a/dotfiles/lib/shellrc/aliases.sh b/dotfiles/lib/shellrc/aliases.sh index 37e2b09c..27254214 100644 --- a/dotfiles/lib/shellrc/aliases.sh +++ b/dotfiles/lib/shellrc/aliases.sh @@ -6,6 +6,7 @@ alias go2dotfiles='cd $(dirname `readlink -f ~/.zshrc | xargs dirname`)' # enables the sudoing of aliases. alias sudo='sudo ' +alias get_absolute_directory= # Detect which `ls` flavor is in use if ls --color > /dev/null 2>&1; then # GNU `ls` diff --git a/dotfiles/lib/shellrc/functions.sh b/dotfiles/lib/shellrc/functions.sh index 64d858b8..47557e0c 100644 --- a/dotfiles/lib/shellrc/functions.sh +++ b/dotfiles/lib/shellrc/functions.sh @@ -1,15 +1,5 @@ -function parse_git_branch() { - ref=$(git symbolic-ref HEAD 2> /dev/null) || \ - ref=$(git rev-parse --short HEAD 2> /dev/null) || return - echo ${ref#refs/heads/} -} - -function git_is_dirty() { - ! test -z "$(git status --porcelain)" -} - function current_shell() { - greadlink -f $(which "$(ps -p $$ | tail -1 | awk '{print $NF}' | sed 's/\-//')") + readlink -f $(which "$(ps -p $$ | tail -1 | awk '{print $NF}' | sed 's/\-//')") } function is_zsh() { diff --git a/dotfiles/lib/zsh/prompt.sh b/dotfiles/lib/zsh/prompt.sh index 80afc34c..61b6e27c 100644 --- a/dotfiles/lib/zsh/prompt.sh +++ b/dotfiles/lib/zsh/prompt.sh @@ -13,7 +13,7 @@ function git_prompt_info() { } function git_status_character() { - if git_is_dirty; + if git dirty; then echo "%{$FG[202]%}✘%{$reset_color%}" else @@ -29,7 +29,7 @@ function sandbox_prompt() { } PROMPT='╭─% %{$FG[040]%}%n%{$reset_color%} %{$FG[239]%}at%{$reset_color%} %{$FG[033]%}$(hostname -s)%{$reset_color%} %{$FG[239]%}in%{$reset_color%} %{$terminfo[bold]$FG[226]%}$(current_directory)%{$reset_color%}$(git_prompt_info)$(sandbox_prompt) -$FG[255]╰─± ' +$FG[255]%{$reset_color%}╰─± ' PS2=''