diff --git a/bootstrap.sh b/bootstrap.sh deleted file mode 100755 index cd374845..00000000 --- a/bootstrap.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -cd `dirname $BASH_SOURCE` && source resources/bootstrapping.sh -DOTFILES_DIRECTORY="$(dotfiles_abspath)/dotfiles" - - -function symlink_dotfiles() { - cd $DOTFILES_DIRECTORY - [ -a ~/.dotfiles-backups ] && mv ~/.dotfiles-backups ~/.dotfiles-backups.old - mkdir ~/.dotfiles-backups - for filename in *; do - local link_destination="$HOME/.$filename" - local link_target=$(${readlink_command} -f $filename) - echo "linking $link_destination to $link_target" - # Using only test -e doesn't work here because it will return - # false if the destination of the symbolic link at does not exist. - test -e $link_destination || test -L $link_destination && mv $link_destination ~/.dotfiles-backups - ln -si $link_target $link_destination - done - [ -a ~/.dotfiles-backups.old ] && mv ~/.dotfiles-backups.old ~/.dotfiles-backups/.dotfiles-backups -} - - -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 - if [[ $REPLY =~ ^[Yy]$ ]]; then - echo - symlink_dotfiles - fi -} - -parse_options diff --git a/dotfiles/lib/shellrc/brew.sh b/dotfiles/lib/shellrc/brew.sh index a9eef843..fe153be2 100755 --- a/dotfiles/lib/shellrc/brew.sh +++ b/dotfiles/lib/shellrc/brew.sh @@ -1,11 +1,13 @@ function brew_install_items() { - echo $@ for package_install_string in $@; do - # Horrible hack to induce word splitting. - eval "package_args=($package_install_string)" + package_args=$package_install_string + if is_zsh; + then + # Horrible hack to induce word splitting. + eval "package_args=($package_install_string)" + fi brew install $package_args; - brew link $package_args[1]; done } @@ -18,68 +20,67 @@ function fix_brew_htop() { function do_the_brew() { ESSENTIAL=( - "emacs" - "git" - "tmux" - "python --with-brewed-openssl" - "htop" - "greadlink" - "vim --override-system-vi" - "zsh" - "make" + "emacs" \ + "tmux" \ + "python --with-brewed-openssl" \ + "htop" \ + "greadlink" \ + "vim --override-system-vi" \ + "zsh" \ + "make" \ ) # `find`, `locate`, `updatedb`, and `xargs`, g-prefixed # core utilities (those that come with OS X are outdated) BASICS=( - "findutils" - "coreutils" - "binutils" - "diffutils" - "ed --default-names" - "gawk" - "gnu-indent --default-names" - "gnu-sed --default-names" - "gnu-tar --default-names" - "gnu-which --default-names" - "gnutls --default-names" - "grep --default-names" - "gzip" - "watch" - "wdiff --with-gettext" - "wget --enable-iri" + "findutils" \ + "coreutils" \ + "binutils" \ + "diffutils" \ + "ed --default-names" \ + "gawk" \ + "gnu-indent --default-names" \ + "gnu-sed --default-names" \ + "gnu-tar --default-names" \ + "gnu-which --default-names" \ + "gnutls --default-names" \ + "grep --default-names" \ + "gzip" \ + "watch" \ + "wdiff --with-gettext" \ + "wget --enable-iri" \ ) SHOULD_INSTALL=( - "nmap" - "readline" - "netcat" - "reattach-to-user-namespace" - "daemonize" - "ngrep" - "gist" - "gawk" - "pstree" - "ack" - "hub" - "tig" - "heroku" - "scala" - "sbt" - "node" - "npm" + "nmap" \ + "readline" \ + "netcat" \ + "reattach-to-user-namespace" \ + "daemonize" \ + "ngrep" \ + "gist" \ + "gawk" \ + "pstree" \ + "ack" \ + "hub" \ + "tig" \ + "heroku" \ + "scala" \ + "sbt" \ + "node" \ + "npm" \ ) - MISC=( - "file-formula" - "git" - "less" - "openssh --with-brewed-openssl" - "perl518" - "rsync" - "svn" - "unzip" - "macvim --override-system-vim --custom-system-icons" + MISC=("file-formula" \ + "less" \ + "openssh --with-brewed-openssl" \ + "perl518" \ + "rsync" \ + "svn" \ + "unzip" \ + "macvim --override-system-vim --custom-system-icons" \ ) install_items=() + OPTIND=1 + echo "${MISC[@]}" while getopts "uebsmah" OPTCHAR; do case $OPTCHAR in @@ -103,7 +104,20 @@ function do_the_brew() { install_items=("${install_items[@]}" "${ESSENTIAL[@]}" "${BASICS[@]}" "${SHOULD_INSTALL[@]}" "${MISC[@]}") ;; h) - echo "Usage: + do_the_brew_help + return + ;; + esac + done + echo "Installing the following packages:" + for package_name in "${install_items[@]}"; do echo $package_name; done; + brew update + brew_install_items $install_items + brew cleanup +} + +function do_the_brew_help() { + echo "do_the_brew Usage: -a install all packages. -u upgrade brew packages. -e install essential packages @@ -112,12 +126,4 @@ function do_the_brew() { -m install very non-essential packages. -h display this help message. " - return - esac - done - echo "Installing:" - for package_name in $install_items; do echo $package_name; done; - brew update - brew_install_items $install_items - brew cleanup } diff --git a/dotfiles/lib/shellrc/colors.sh b/dotfiles/lib/shellrc/colors.sh index b73f991c..84b66662 100644 --- a/dotfiles/lib/shellrc/colors.sh +++ b/dotfiles/lib/shellrc/colors.sh @@ -1,2 +1,2 @@ -local dircolors_file="$HOME/.dircolors" +dircolors_file="$HOME/.dircolors" test -r $dircolors_files && eval "$(dircolors $dircolors_file)" diff --git a/dotfiles/lib/shellrc/functions.sh b/dotfiles/lib/shellrc/functions.sh index 7877fffb..c748f301 100644 --- a/dotfiles/lib/shellrc/functions.sh +++ b/dotfiles/lib/shellrc/functions.sh @@ -1,9 +1,3 @@ -function dotfiles_abspath() { - readlink_command='readlink' -command -v greadlink > /dev/null && readlink_command="greadlink" - echo "$(${readlink_command} -f "$BASH_SOURCE" | xargs dirname | xargs dirname)" -} - function go2dotfiles() { cd $(dirname `readlink -f ~/.zshrc | xargs dirname`) } @@ -42,6 +36,7 @@ function confirm() { function get_cols() { FS=' ' + OPTIND=1 while getopts "F:" OPTCHAR; do case $OPTCHAR in F) @@ -129,6 +124,7 @@ function git_root() { function git_diff_replacing() { local original_sha='HEAD~1' local new_sha='HEAD' + OPTIND=1 while getopts "do:n:" OPTCHAR; do case $OPTCHAR in @@ -154,6 +150,7 @@ function git_diff_replacing() { function git_reset_author() { local should_update_command='' local update_command='' + OPTIND=1 while getopts "a:e:A:E:h" OPTCHAR; do case $OPTCHAR in diff --git a/dotfiles/lib/shellrc/python.sh b/dotfiles/lib/shellrc/python.sh index e5e0960b..a2f8d132 100644 --- a/dotfiles/lib/shellrc/python.sh +++ b/dotfiles/lib/shellrc/python.sh @@ -1,17 +1,16 @@ -ESSENTIAL=(ipdb ipython virtualenv) -FOR_EDITOR=(jedi pyflakes) -USEFUL=( - Flask - ddg - ouimeaux - readline - simplejson - tox - numpy -) - function install_python_packages() { - sudo pip install $ESSENTIAL + ESSENTIAL=(ipdb ipython virtualenv) + FOR_EDITOR=(jedi pyflakes) + USEFUL=( + Flask + ddg + ouimeaux + readline + simplejson + tox + numpy + ) + OPTIND=1 while getopts "uea" OPTCHAR; do case $OPTCHAR in @@ -24,8 +23,18 @@ function install_python_packages() { a) sudo pip install $FOR_EDITOR sudo pip install $USEFUL + install_pygame + install_powerline + ;; + h) + echo " +-u Install useful but non essential python. +-e Install editor python packages. +-a Install all python utilities." + ;; esac done + sudo pip install $ESSENTIAL } function install_pygame() { diff --git a/dotfiles/lib/shellrc/synergy.sh b/dotfiles/lib/shellrc/synergy.sh index 7d4edc49..0b4d98c9 100644 --- a/dotfiles/lib/shellrc/synergy.sh +++ b/dotfiles/lib/shellrc/synergy.sh @@ -1,5 +1,6 @@ function make_me_synergy() { local new_host_name="$(echo $SSH_CONNECTION | get_cols 1)" + OPTIND=1 while getopts "h:" OPTCHAR; do case $OPTCHAR in h) diff --git a/dotfiles/lib/zsh.sh b/dotfiles/lib/zsh.sh index 5f272f6e..3990be48 100644 --- a/dotfiles/lib/zsh.sh +++ b/dotfiles/lib/zsh.sh @@ -5,6 +5,6 @@ done alias srczsh="source ~/.zshrc" # Online help. -unalias run-help +unalias run-help 2> /dev/null 1>/dev/null autoload run-help HELPDIR=/usr/local/share/zsh/helpfiles diff --git a/setup.sh b/setup.sh index de830b48..808f3998 100755 --- a/setup.sh +++ b/setup.sh @@ -1,33 +1,85 @@ #!/usr/bin/env bash -function setup() { - cd `dirname $BASH_SOURCE` && source resources/bootstrapping.sh - source dotfiles/lib/shellrc/functions.sh - source dotfiles/lib/shellrc/brew.sh - source dotfiles/lib/shellrc/python.sh +cd `dirname $BASH_SOURCE` && source resources/bootstrapping.sh +source dotfiles/lib/shellrc/functions.sh +source dotfiles/lib/shellrc/brew.sh +source dotfiles/lib/shellrc/python.sh +DOTFILES_DIRECTORY="$(dotfiles_abspath)/dotfiles" - case `uname` in - 'Darwin') - osx_setup - ;; - 'Linux') - source resources/apt-get.sh - ;; - esac - install_powerline - source bootstrap.sh +function symlink_dotfiles() { + cd $DOTFILES_DIRECTORY + [ -a ~/.dotfiles-backups ] && mv ~/.dotfiles-backups ~/.dotfiles-backups.old + mkdir ~/.dotfiles-backups + for filename in *; do + local link_destination="$HOME/.$filename" + local link_target=$(${readlink_command} -f $filename) + echo "linking $link_destination to $link_target" + # Using only test -e doesn't work here because it will return + # false if the destination of the symbolic link at does not exist. + test -e $link_destination || test -L $link_destination && mv $link_destination ~/.dotfiles-backups + ln -si $link_target $link_destination + done + [ -a ~/.dotfiles-backups.old ] && mv ~/.dotfiles-backups.old ~/.dotfiles-backups/.dotfiles-backups } -function osx_setup() { - while getopts "uebsmaho" OPTCHAR; +function symlink_dotfiles_prompt() { + 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 + if [[ $REPLY =~ ^[Yy]$ ]]; then + echo + symlink_dotfiles + fi +} + +function setup_help() { + echo "setup Usage: +-a Install apt-get packages. +-o Run OSX configuration commands. +-s Symlink dotfiles to home directory. +-b Install brew packages. +-p Install python packages. +-h display this help message." +} + +function setup() { + if [[ $# -eq 0 ]] ; then + setup_help + exit 0 + fi + while getopts "aosbp" OPTCHAR; do case $OPTCHAR in - h) - echo "brew options:" - do_the_brew -h - exit + a) + source resources/apt-get.sh ;; - source resources/osx.sh - do_the_brew $@ + b) + do_the_brew_help + read -p "Enter flags for brew package installation: +" + [[ $REPLY[0] != '-' ]] && REPLY="-$REPLY" + do_the_brew $REPLY + ;; + o) + sudo -v + source resources/osx.sh + ;; + s) + symlink_dotfiles_prompt + ;; + p) + install_python_packages -h + read -p "Enter flags for python package installation" + if [[ $REPLY[0] != '-' ]]; then + REPLY="-$REPLY" + fi + install_python_packages $REPLY + ;; + h) + setup_help + return + ;; + esac + done } + +setup $@