Skip to content

Instantly share code, notes, and snippets.

@baetheus
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baetheus/1616cea67a73c0bcf4f9 to your computer and use it in GitHub Desktop.
Save baetheus/1616cea67a73c0bcf4f9 to your computer and use it in GitHub Desktop.
Brandon's Simple Env Setup

Bootstrap Zsh and Vim

Quick Start

To use, run this from the shell of the user you want to install for:

curl -Lsk http://goo.gl/ySIhkT |bash

The above url maps to https://gist.githubusercontent.com/baetheus/1616cea67a73c0bcf4f9/raw/brandon-shell-setup.sh

Information

As of 2014-11-21, this script installs zsh, sets it as the default shell for the current user, and also downloads .vimrc and .zshrc files. It's non-destructive and will not link the shell if an error occured during installation, nor will it overwrite existing .vimrc or .zshrc files.

Prerequisites

  • pkgsrc
  • bash
  • sudo
  • vim

This was meant to be run on OS X or a SmartOS Zone. Installation of zsh is achieved using pkgsrc, which runs on lots of stuff. If you don't have pkgsrc and don't want to install it, then you'll have to manually install zsh using another method. The installation script is fairly portable bash, if you find an issue with it please ping me. I don't expect anyone else to use this, since I only use it to quickly bootstrap remote machines that I don't configure.

set nocp
set nu
set history=700
filetype on
filetype plugin on
filetype indent on
set grepprg=grep\ -nH\ $*
set autoread
set so=7
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set ignorecase
set smartcase
set hlsearch
set incsearch
set magic
set noerrorbells
syntax enable
colorscheme desert
set background=dark
set encoding=utf8
set ffs=unix,dos,mac
set smarttab
set tabstop=2
set shiftwidth=2
set ai
set si
set wrap
set showcmd
set wildmenu
set wildmode=list:longest,full
set paste
### Window Header
case $TERM in
*xterm*|ansi)
function settitle { print -Pn "\e]2;%n@%m: %~\a" }
function chpwd { settitle }
settitle
;;
esac
### Conditional Environment Stuff
case "$(uname)" in
Darwin) export PATH=/opt/pkg/sbin:/opt/pkg/bin:/usr/sbin:/sbin:$PATH;;
SunOS)
export PATH=/usr/local/sbin:/usr/local/bin:/opt/local/sbin:/opt/local/bin:/sbin:$PATH
export LANG="en_US.UTF-8"
;;
esac
### Exports
export HISTSIZE=10000
export HISTFILE="$HOME/.zhistory"
export SAVEHIST=$HISTSIZE
### Variables
COLORLIST=(red green yellow blue magenta cyan)
MARKER="$(echo -e '\U276F')"
### Autoloads
autoload -U compinit && compinit
autoload -U promptinit && promptinit
autoload -U colors && colors
### Simple Styling
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
### Setopts
setopt correctall
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt extendedglob
### Aliases and functions
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias sf="defaults write com.apple.finder AppleShowAllFiles YES; killall Finder"
alias hf="defaults write com.apple.finder AppleShowAllFiles NO; killall Finder"
alias pkgrep="pkgin avail |grep -i "
sd() { sed -i. "$1d" ~/.ssh/known_hosts }
### Prompt Builder in precmd
function precmd {
local hostcol
local usercol
local dircol
local markcol
local rn
rn=$((RANDOM % 6))
hostcol=${COLORLIST[$(((rn) % 6 + 1))]}
usercol=${COLORLIST[$(((rn + 1) % 6 + 1))]}
dircol=${COLORLIST[$(((rn + 2) % 6 + 1))]}
markcol=${COLORLIST[$(((rn + 3) % 6 + 1))]}
PROMPT="%F{$usercol}%n%f%F{$markcol}@%f%F{$hostcol}%m%f %F{$dircol}%~%f %F{$markcol}$MARKER%f "
}
#!/bin/bash
### Begin
echo "Setting up brandon's defaults."
### Install zsh
if [[ "$(which zsh)" =~ ^no ]]; then
if [[ ! "$(which pkgin)" =~ ^no ]]; then
echo "Installing zsh, you may have to enter password for sudo."
sudo pkgin -y in zsh
[[ $? ]] && [[ ! "$(which zsh)" =~ ^no ]] && echo "Zsh successfully installed!"
else
echo "ERROR: Can't install zsh, you must install manually."
fi
fi
if [[ ! "$(which zsh)" =~ ^no ]]; then
echo "Found $(zsh --version)."
if [[ "$SHELL" == "$(which zsh)" ]]; then
echo "Default shell for $LOGNAME is already $(which zsh)."
else
echo "Setting default shell for $LOGNAME to $(which zsh)"
sudo usermod -s "$(which zsh)" $LOGNAME
[[ $? ]] && echo "Successfully set default shell!"
fi
fi
### Install .zshrc
if [[ ! -f "$HOME/.zshrc" ]]; then
echo "Grabbing .zshrc from github."
curl -sk https://gist.githubusercontent.com/baetheus/1616cea67a73c0bcf4f9/raw/.zshrc > $HOME/.zshrc
else
echo "Looks like you have a .zshrc, remove and rerun if you want a fresh copy."
fi
### Install .vimrc
if [[ ! -f "$HOME/.vimrc" ]]; then
echo "Grabbing .vimrc from github."
curl -sk https://gist.githubusercontent.com/baetheus/1616cea67a73c0bcf4f9/raw/.vimrc > $HOME/.vimrc
else
echo "Looks like you have a .vimrc, remove and rerun if you want a fresh copy."
fi
echo "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment