From da6081e7a23d518344fb01841384f99dd8221668 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 22 Mar 2013 13:15:50 -0400 Subject: [PATCH] Refactor everything; now one repo for both mac and deb dotfiles --- README.md | 4 +- deploy | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ install.sh | 23 ----------- install/brew | 50 ------------------------ install/git | 25 ------------ install/rvm | 14 +++---- install/tmux | 22 +++++------ install/vim | 47 ++++++++++++++++------- install/zsh | 17 ++++----- zsh/aliases | 8 +--- zsh/functions | 9 +++-- zsh/lib/os | 42 ++++++++++++++++++++ zsh/lib/output | 17 +++++++++ zsh/lib/util | 16 ++++++++ zsh/paths | 6 +-- 15 files changed, 245 insertions(+), 157 deletions(-) create mode 100755 deploy delete mode 100755 install.sh delete mode 100755 install/brew delete mode 100755 install/git create mode 100644 zsh/lib/os create mode 100644 zsh/lib/output create mode 100644 zsh/lib/util diff --git a/README.md b/README.md index 2e4854b4..8a7005f8 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ My mac dotfiles. ## Installation - sh <(curl https://raw.github.com/hlissner/dotfiles/master/install.sh -L) + bash <(curl https://raw.github.com/hlissner/dotfiles/master/deploy -L) ## And if you want vim... - sh <(curl https://raw.github.com/hlissner/mlvim/master/install.sh -L) + bash <(curl https://raw.github.com/hlissner/mlvim/master/install.sh -L) diff --git a/deploy b/deploy new file mode 100755 index 00000000..b736b2da --- /dev/null +++ b/deploy @@ -0,0 +1,102 @@ +#!/bin/bash + +GREEN=$(tput setaf 2) +RS=$(tput sgr0) +src=$BASH_SOURCE + +source $src/zsh/functions + +##### GIT & DOTFILES ###### +# If the install folder doesn't exist, you bash < <(curl ...)'d this script! +if [ ! -d $src/install ]; then + # Check for git and install it if necessary + if ! command_exists git; then + echo-r "==> GIT isn't installed!" + echo-g "==> Installing GIT" + pkg-install git + + do_link $src/gitconfig ~/.gitconfig + do_link $src/gitignore ~/.gitignore + + # https://github.com/jamiew/git-friendly + bash < <(curl https://raw.github.com/jamiew/git-friendly/master/install.sh) + fi + + # Get the dotfiles + echo-g "==> Cloning dotfiles repo" + git clone https://github.com/hlissner/dotfiles.git ~/.dotfiles +fi + +###### DEPENDENCIES ####### +if is_mac; then + # Set up the OSX options + $src/install/osx + + # Detect homebrew; install it if necessary + if ! command_exists brew; then + echo-g "==> Installing Homebrew" + + # http://mxcl.github.com/homebrew/ + ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go) + + # Reregister the PATH so bash sees brew and its minions + PATH=/usr/local/bin:/usr/local/sbin:$PATH + + # Install GNU core utilities (those that come with OS X are outdated) + brew install coreutils + # echo "Don’t forget to add $(brew --prefix coreutils)/libexec/gnubin to \$PATH." + # Install GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed + brew install findutils + # Install Bash 4 + brew install bash + # Install wget with IRI support + brew install wget --enable-iri + + # Install more recent versions of some OS X tools + brew tap homebrew/dupes + brew install homebrew/dupes/grep + brew tap josegonzalez/homebrew-php + + # Install everything else + brew install macvim --override-system-vim --with-cscope + brew install vim --with-ruby --with-python + brew install ack git rename tree node nginx memcached ctags + brew install php54 --with-fpm --with-imap --with-mysql --with-pgsql --without-apache + brew install php54-imagick php54-mcrypt php54-xdebug readline + + echo-g "==> Homebrew: Updating" + brew update && brew upgrade + + echo-g "==> Homebrew: Cleaning up" + brew cleanup + else + echo-r "==> Homebrew is already installed!" + fi +elif is_linux; then + ehco-g "==> Installing dependencies" + pkg-install curl python ruby wget zsh + + echo-g "==> Aptitude: Updating" + pkg-update + + echo-g "==> Aptitude: Cleaning up" + pkg-clean +fi + +# Install & setup ZSH shell +$src/install/zsh + +# Install RVM & setup 1.8.7, 1.9.2 rubies +$src/install/rvm + +# Install & setup TMUX +$src/install/tmux + +# Install & setup VIM +$src/install/vim + +# Wrap things up +echo +echo-g "Done!" +echo "And if you want to install vim, run:" +echo " sh <(curl https://raw.github.com/hlissner/mlvim/master/install.sh -L)" diff --git a/install.sh b/install.sh deleted file mode 100755 index 2f266e7c..00000000 --- a/install.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -GREEN=$(tput setaf 2) -RS=$(tput sgr0) - -src=$(cd "$(dirname "$0")"; pwd) -if [ ! -d $src/install ]; then - echo -e "$GREEN==> Cloning dotfiles repo$RS" - git clone https://github.com/hlissner/dotfiles.git ~/.dotfiles | sed "s/^/ /" - src="~/.dotfiles" -fi - -$src/install/osx -$src/install/zsh -$src/install/brew -$src/install/git -$src/install/rvm -$src/install/tmux - -echo -echo "${GREEN}Done!$RS" -echo "And if you want to install vim, run:" -echo " sh <(curl https://raw.github.com/hlissner/mlvim/master/install.sh -L)" diff --git a/install/brew b/install/brew deleted file mode 100755 index 1858d4ab..00000000 --- a/install/brew +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/zsh - -if ! command-exists brew; then - echo "==> Homebrew: Installing" - - # http://mxcl.github.com/homebrew/ - ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go) | indent - FORCE=1 -elif [ "$1" = "--force" ]; then - FORCE=1 -fi - -echo "==> Homebrew: Updating" -# Make sure we’re using the latest Homebrew -brew update - -if [ $FORCE ]; then - echo "==> Homebrew: Installing essential brews" - - # Install GNU core utilities (those that come with OS X are outdated) - brew install coreutils - # echo "Don’t forget to add $(brew --prefix coreutils)/libexec/gnubin to \$PATH." - # Install GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed - brew install findutils - # Install Bash 4 - brew install bash - - # Install wget with IRI support - brew install wget --enable-iri - - # Install more recent versions of some OS X tools - brew tap homebrew/dupes - brew install homebrew/dupes/grep - brew tap josegonzalez/homebrew-php - - # Install everything else - brew install ack git rename tree python node nginx memcached ctags macvim - brew install php54 --with-fpm --with-imap --with-mysql --with-pgsql --without-apache - brew install php54-imagick php54-mcrypt php54-xdebug readline -else - echo "==> Homebrew: Upgrading" - # Upgrade any already-installed formulae - brew upgrade -fi - -echo "==> Homebrew: Cleaning up" -# Remove outdated versions from the cellar -brew cleanup - -echo "==> Homebrew: DONE!" diff --git a/install/git b/install/git deleted file mode 100755 index 7a4b14a6..00000000 --- a/install/git +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/zsh - -if ! command-exists git; then - if ! command-exists brew; then - echo "Homebrew is required!" - exit - fi - - echo "==> Git: Installing" - brew install git | indent -fi - -if [ ! -e /usr/local/bin/branch ]; then - echo "==> Git: Installing git-friendly" - - # https://github.com/jamiew/git-friendly - bash < <(curl https://raw.github.com/jamiew/git-friendly/master/install.sh) -fi - -# Create links -echo "==> Git: Setting up symlinks" -ln -sf ~/.dotfiles/gitignore ~/.gitignore -ln -sf ~/.dotfiles/gitconfig ~/.gitconfig - -echo "==> Git: DONE!" diff --git a/install/rvm b/install/rvm index 3176e7a9..5d8f4a4e 100755 --- a/install/rvm +++ b/install/rvm @@ -1,15 +1,13 @@ #!/bin/zsh -sudo -v - -if ! command-exists rvm; then +if ! command_exists rvm; then # If RVM's not installed, install it and the rubies - echo "==> Rvm: Installing" + echo-g "==> Rvm: Installing" # https://rvm.io curl -L https://get.rvm.io | bash -s stable --ruby | indent - echo "==> Rvm: Install rubies" + echo-g "==> Rvm: Install rubies" # Install rubies and update rubygems rvm install 1.9.3 rvm install 1.8.7-p371 @@ -30,17 +28,17 @@ else # Update all rubies and rubygems for v in 1.9.3 1.8.7; do - echo "==> Rvm: Updating ruby $v" + echo-g "==> Rvm: Updating ruby $v" rvm use $v gem update --system gem update done # Update system ruby - echo "==> Rvm: Updating system ruby" + echo-g "==> Rvm: Updating system ruby" rvm use system sudo gem update --system sudo gem update fi -echo "==> Rvm: DONE!" +echo-g "==> Rvm: DONE!" diff --git a/install/tmux b/install/tmux index fcdbcc2d..273e6db2 100755 --- a/install/tmux +++ b/install/tmux @@ -1,18 +1,16 @@ #!/bin/zsh -if ! command-exists brew; then - echo "Requires homebrew" - exit -fi - -if [ ! `command -v "tmux"` ]; then - echo "==> Tmux: Installing tmux & reattach-to-user-namespace" - brew install tmux reattach-to-user-namespace libevent | indent +if ! command_exists "tmux"; then + echo-g "==> Installing tmux" + pkg-install tmux + if is_mac; then + brew install reattach-to-user-namespace libevent + fi else - echo "==> Tmux: already installed!" + echo-r "==> Tmux is already installed!" fi -echo "==> Tmux: Setting up symlinks" -ln -sf ~/.dotfiles/tmux.conf ~/.tmux.conf +echo-g "==> Setting up symlinks" +do_link ~/.dotfiles/tmux.conf ~/.tmux.conf -echo "==> Tmux: DONE!" +echo-g "==> DONE!" diff --git a/install/vim b/install/vim index d2f76d82..b66b79b0 100755 --- a/install/vim +++ b/install/vim @@ -1,19 +1,36 @@ #!/bin/zsh -if ! command-exists "brew"; then - echo "Homebrew is required!" - exit 1 -fi - -if ! command-exists "mvim"; then - echo "==> Vim: Installing macvim" - brew install macvim --with-cscope --override-system-vim | indent +# Installing macvim/compiling vim +if is_mac && ! command_exists "mvim"; then + echo-g "==> Installing macvim" + brew install macvim --with-cscope --override-system-vim +elif is_deb; then + echo-g "==> Preparing to compile vim from source" + pkg-install libncurses5-dev libgnome2-dev libgnomeui-dev \ + libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \ + libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev ruby-dev mercurial + pkg-remove vim vim-runtime gvim + + cd ~ + hg clone https://code.google.com/p/vim/ + cd vim + echo-g "==> Compiling vim from source" + ./configure --with-features=huge \ + --enable-rubyinterp \ + --enable-pythoninterp \ + --enable-perlinterp \ +echo + --enable-gui=gtk2 --enable-cscope --prefix=/usr + make VIMRUNTIMEDIR=/usr/share/vim/vim73 + sudo make install + rm -rf ~/vim fi +# Installing vim rcfiles if [ ! -e ~/.vimrc ]; then - echo "==> Vim: Installing vim rcfiles" + echo-g "==> Installing vim rcfiles" - if [ -d ~/.vim ]; then + if [ -h ~/.vim ]; then rm -rf ~/.vim rm ~/.vimrc rm ~/.vimrc.bundles @@ -22,17 +39,19 @@ if [ ! -e ~/.vimrc ]; then sh <(curl https://raw.github.com/hlissner/mlvim/master/install.sh -L) | indent fi -echo "==> Vim: Updating..." +# Installing/updating vim bundles +echo-g "==> Vim: Updating..." find ~/.vim/bundle/ -type d -name .git \ | xargs -n 1 dirname \ | while read line; do cd $line && echo -n "$(basename $line): " && git pull; done +# Compiling YouCompleteMe YVM_DIR="~/.vim/bundle/YouCompleteMe" if [ -d $YVM_DIR ] && [ ! -e $YVM_DIR/python/ycm_core.so ]; then - echo "==> Vim: Trying to compile YCM" - brew install cmake + echo-g "==> Vim: Trying to compile YCM" + pkg-install cmake cd ~/.vim/bundle/YouCompleteMe ./install.sh --clang-completer fi -echo "==> Vim: DONE!" +echo-g "==> Vim: DONE!" diff --git a/install/zsh b/install/zsh index 04fc7f46..8e2a687c 100755 --- a/install/zsh +++ b/install/zsh @@ -2,20 +2,19 @@ if [ ! -d ~/.oh-my-zsh ]; then # https://github.com/robbyrussell/oh-my-zsh - echo "==> ZSH: Installing oh-my-zsh" + echo-g "==> ZSH: Installing oh-my-zsh" curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh # Set new shell - echo "==> ZSH: Changing shell" + echo-g "==> ZSH: Changing shell" chsh -s /bin/zsh fi # Create links -echo "==> ZSH: Setting up symlinks" -[ -d ~/.zsh ] && rm ~/.zsh -ln -sf ~/.dotfiles/zsh ~/.zsh -ln -sf ~/.dotfiles/zshrc ~/.zshrc -ln -sf ~/.dotfiles/zshenv ~/.zshenv -ln -sf ~/.dotfiles/bashrc ~/.bashrc +echo-g "==> ZSH: Setting up symlinks" +do_link ~/.dotfiles/zsh ~/.zsh +do_link ~/.dotfiles/zshrc ~/.zshrc +do_link ~/.dotfiles/zshenv ~/.zshenv +do_link ~/.dotfiles/bashrc ~/.bashrc -echo "==> ZSH: DONE!" +echo-g "==> ZSH: DONE!" diff --git a/zsh/aliases b/zsh/aliases index d32219f9..022ee370 100644 --- a/zsh/aliases +++ b/zsh/aliases @@ -9,14 +9,8 @@ alias l.='ls -Ad .*' alias du='du -h -d 1' alias q='exit' -# Directories ################## -alias dev='cd /usr/local/dev' -alias w='cd ~/Work/' -alias wd='cd ~/Work/Dev/' -alias wp='cd ~/Work/Projects/' - # Apps ######################### -if command-exists mvim; then +if command_exists mvim; then alias v='mvim' else alias v='vim' diff --git a/zsh/functions b/zsh/functions index 2e31bb9c..71b7c1b3 100644 --- a/zsh/functions +++ b/zsh/functions @@ -1,7 +1,3 @@ -# Check to see if a command exists -function command-exists { - command -v "$1" &> /dev/null -} # Open a file in Mac OS's quick-look function quick-look { @@ -28,3 +24,8 @@ function extract { echo "'$1' is not a valid file" fi } + +# Source library +source ~/.dotfiles/zsh/lib/util +source ~/.dotfiles/zsh/lib/output +source ~/.dotfiles/zsh/lib/os diff --git a/zsh/lib/os b/zsh/lib/os new file mode 100644 index 00000000..2b95c1a9 --- /dev/null +++ b/zsh/lib/os @@ -0,0 +1,42 @@ +function is_deb { + command_exists apt-get +} + +function is_mac { + [[ $(uname) == 'Darwin' ]] +} + +function is_linux { + [[ $(uname) == 'Linux' ]] +} + +if is_mac; then + + function pkg-install() { + brew install $1 + } + + function pkg-remove() { + brew remove $1 + } + + function pkg-update() { + brew update && brew upgrade + } + +elif is_deb; then + + function pkg-install() { + sudo apt-get install $1 + } + + function pkg-remove() { + sudo apt-get remove $1 + } + + function pkg-update() { + sudo apt-get update && sudo apt-get upgrade + } + +fi + diff --git a/zsh/lib/output b/zsh/lib/output new file mode 100644 index 00000000..aa63d2fb --- /dev/null +++ b/zsh/lib/output @@ -0,0 +1,17 @@ + +RED=$bg[red] +red=$fg[red] +GREEN=$bg[green] +green=$fg[green] +YELLOW=$bg[yellow] +yellow=$fg[yellow] +BOLD=$FX[bold] +NC=$reset_color + +function echo-g { + echo -e "$green$1$NC" +} + +function echo-r { + echo -e "$red$1$NC" +} diff --git a/zsh/lib/util b/zsh/lib/util new file mode 100644 index 00000000..9fe2ffff --- /dev/null +++ b/zsh/lib/util @@ -0,0 +1,16 @@ + +# Check to see if a command exists +function command_exists { + command -v "$1" &> /dev/null +} + +function do_log { + printf "[%s] %s: %s" "$(`basename $BASH_SOURCE`)" "`date`" "$1" >> $logfile +} + +function do_link { + if [ -h "$2" ]; then + rm "$2" + fi + ln -sf "$1" "$2" +} diff --git a/zsh/paths b/zsh/paths index 596c782e..7c0e2601 100644 --- a/zsh/paths +++ b/zsh/paths @@ -1,12 +1,12 @@ -if command-exists brew; then - BREWDIR=`brew --prefix` +if command_exists brew; then + local BREWDIR=`brew --prefix` PATH=$BREWDIR/sbin:$PATH PATH=$BREWDIR/bin:$PATH COREUTIL=`brew --prefix coreutils` if [ -d "$COREUTIL" ]; then - PATH=`brew --prefix coreutils`:$PATH + PATH=$COREUTIL/libexec/bin/gnubin:$PATH fi fi