.profile 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. ###############################################################################
  2. # Non-interactive shell configuration
  3. ###############################################################################
  4. OS=$(uname -s)
  5. # Add $HOME/bin to PATH
  6. export PATH="$PATH:$HOME/bin"
  7. # Homebrew
  8. export PATH="$PATH:$HOME/homebrew/bin"
  9. BREW_BIN=$(which brew)
  10. BREW_PREFIX=$(which brew &>/dev/null && brew --prefix || echo "")
  11. if [ "$BREW_BIN" ]; then
  12. export PYTHONPATH="$BREW_PREFIX/lib/python2.7/site-packages/" # also facilitates: easy_install -d "$PYTHONPATH" awesome_pkg
  13. export HOMEBREW_CASK_OPTS="--caskroom=$BREW_PREFIX/Caskroom --binarydir=$BREW_PREFIX/bin"
  14. fi
  15. # Default editor
  16. export EDITOR="vim"
  17. # Configure go lang
  18. if [ "$OS" = "Darwin" ]; then
  19. export GOROOT="$BREW_PREFIX/opt/go"
  20. else
  21. export GOROOT="$HOME/golang"
  22. fi
  23. export PATH="$PATH:$GOROOT/bin"
  24. export GOPATH="$HOME/go"
  25. export PATH="$PATH:$GOPATH/bin"
  26. # Configure less allow colors
  27. export LESS="-FRX"
  28. # If not running interactively, don't do anything else
  29. [ "$PS1" ] || return
  30. ###############################################################################
  31. # Interactive shell configuration
  32. ###############################################################################
  33. # tweak history behavior a bit
  34. HISTSIZE=50000
  35. HISTFILESIZE=500000
  36. HISTCONTROL="ignoredups:ignorespace"
  37. shopt -s histappend
  38. # check window size after each command
  39. shopt -s checkwinsize
  40. # Custom shell aliases
  41. if [ "$OS" = "Darwin" ]; then
  42. alias ls="ls -G -CF"
  43. else
  44. alias ls="ls --color -CF"
  45. fi
  46. alias ll="ls -alF"
  47. alias la="ls -A"
  48. alias l="ls"
  49. alias d="ls"
  50. alias grep="grep --color --exclude-dir=.svn --exclude-dir=.git --exclude-dir=node_modules"
  51. alias egrep="egrep --color --exclude-dir=.svn --exclude-dir=.git --exclude-dir=node_modules"
  52. alias fgrep="fgrep --color --exclude-dir=.svn --exclude-dir=.git --exclude-dir=node_modules"
  53. alias tree="tree -CF"
  54. # color diffs
  55. ! which colordiff &>/dev/null || alias diff="colordiff"
  56. # MacVim shell aliases
  57. if [ "$OS" = "Darwin" ]; then
  58. alias gvim="mvim"
  59. fi
  60. # bash completion FTW
  61. if [ "$OS" = "Darwin" ]; then
  62. ! [ -f "$BREW_PREFIX/etc/bash_completion" ] || . "$BREW_PREFIX/etc/bash_completion"
  63. else
  64. ! [ -f "/etc/bash_completion" ] || . "/etc/bash_completion"
  65. fi
  66. # Git shell aliases
  67. F="/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash"; ! [ -f "$F" ] || . "$F"
  68. # Liquid Prompt
  69. F="$HOME/liquidprompt/liquidprompt"; ! [ "$PS1" -a -f "$F" ] || . "$F"
  70. ###############################################################################
  71. # Installers
  72. ###############################################################################
  73. _install_homebrew() {
  74. xcode-select --install 2>&1 | grep -q "already installed" || exit
  75. [ -d "$HOME/homebrew" ] || (mkdir "$HOME/homebrew" 2>/dev/null && curl -L "https://github.com/Homebrew/homebrew/tarball/master" | tar xz --strip 1 -C "$HOME/homebrew" && brew update)
  76. brew install caskroom/cask/brew-cask
  77. }
  78. _install_tools() {
  79. _install_homebrew
  80. [ -f "$HOME/.bash_profile" ] || ln -sv "$HOME/.profile" "$HOME/.bash_profile"
  81. [ -f "$HOME/.bashrc" ] || ln -sv "$HOME/.profile" "$HOME/.bashrc"
  82. [ -d "$HOME/liquidprompt" ] || git clone "https://github.com/nojhan/liquidprompt.git" "$HOME/liquidprompt"
  83. [ -f "$HOME/.gitconfig" ] || (
  84. git config --global color.ui true
  85. git config --global credential.helper "$([ "$(uname -s)" = "Darwin" ] && echo "osxkeychain" || echo "cache --timeout=3600")"
  86. )
  87. which git-alias >/dev/null || brew install git-extras
  88. [ "$(git alias)" ] || (
  89. git alias br branch
  90. git alias ci commit
  91. git alias co checkout
  92. git alias di diff
  93. git alias st status
  94. )
  95. which tmux >/dev/null || brew install tmux
  96. which tree >/dev/null || brew install tree
  97. [ -d "$HOME/Applications/SourceTree.app" ] || brew cask install sourcetree
  98. [ -d "$HOME/Applications/Atom.app" ] || brew cask install atom
  99. [ -d "$HOME/Applications/Google Chrome.app" ] || brew cask install google-chrome
  100. [ -d "$HOME/Applications/Firefox.app" ] || brew cask install firefox
  101. }
  102. _install_dev_js() {
  103. _install_homebrew
  104. which node >/dev/null || brew install node
  105. PKG="jshint"; which "$PKG" >/dev/null || npm install -g "$PKG"
  106. PKG="js-beautify"; which "$PKG" >/dev/null || npm install -g "$PKG"
  107. PKG="json"; which "$PKG" >/dev/null || npm install -g "$PKG"
  108. PKG="jscs"; which "$PKG" >/dev/null || npm install -g "$PKG"
  109. }
  110. _install_dev_sh() {
  111. _install_homebrew
  112. which shellcheck >/dev/null || brew install shellcheck
  113. }
  114. _install_dev_py() {
  115. _install_homebrew
  116. mkdir -p "$PYTHONPATH"
  117. PKG="pylint"; which "$PKG" >/dev/null || (easy_install -d "$PYTHONPATH" "$PKG" && ln -sv "$PYTHONPATH/$PKG" "$BREW_PREFIX/bin/$PKG")
  118. PKG="pep8"; which "$PKG" >/dev/null || (easy_install -d "$PYTHONPATH" "$PKG" && ln -sv "$PYTHONPATH/$PKG" "$BREW_PREFIX/bin/$PKG")
  119. }
  120. _install_dev_db() {
  121. _install_homebrew
  122. which mongod >/dev/null || brew install mongodb && ln -sfv "$BREW_PREFIX/opt/mongodb"/*.plist ~/Library/LaunchAgents/
  123. which redis >/dev/null || brew install redis && ln -sfv "$BREW_PREFIX/opt/redis"/*.plist ~/Library/LaunchAgents/
  124. which pg_config >/dev/null || brew install postgresql && ln -sfv "$BREW_PREFIX/opt/postgresql"/*.plist ~/Library/LaunchAgents/
  125. }
  126. _install_dev_go() {
  127. _install_homebrew
  128. which go >/dev/null || brew install go --with-cc-common
  129. }