view setup @ 86:4a22703b183c

Merge.
author Edho Prima Arief <me@myconan.net>
date Sat, 09 Jul 2011 15:39:00 +0700
parents 54a82956bb11
children 7c01fc6f7460
line wrap: on
line source

#!/bin/sh

install() {
  uninstall
  #create symlinks
  linker "tcsh" ".ecos_tcsh"
  linker "bash" ".ecos_bash"
  linker "zsh" ".ecos_zsh"
  linker "tmux" ".tmux.conf"
  linker "hg" ".hgrc"
  linker "vim" ".vimrc"
  linker "inputrc" ".inputrc"
  #originally bin-ec. Renamed to .ecos.bin for sanity when listing home
  #and replaced . with _ for more sanity
  linker "bin" ".ecos_bin"

  #modify cshrc
  echo '[ -r "${HOME}/.ecos_tcsh" ] && source "${HOME}/.ecos_tcsh" #ECCORE_TCSH' >> "${HOME}/.cshrc"
  #modify bash_profile and bashrc
  echo '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' >> "${HOME}/.bash_profile"
  echo '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' >> "${HOME}/.bashrc"
  #modify zshrc
  echo '[ -r "${HOME}/.ecos_zsh" ] && . "${HOME}/.ecos_zsh" #ECCORE_ZSH' >> "${HOME}/.zshrc"
}

linker() {
  echo "Creating symlink: ${1} => ~/${2}"
  ln -fs "${PWD}/${1}" "${HOME}/${2}"
}

uninstall_tcsh() {
  if [ -f "${HOME}/.cshrc" ]; then
    grep -v '#ECCORE_TCSH' "${HOME}/.cshrc" > .cleancshrc
    mv .cleancshrc "${HOME}/.cshrc"
  fi
}

uninstall() {
  for i in .ecos_tcsh .tmux.conf .hgrc .vimrc .inputrc bin-ec .ecos.bin .ecos_bin .ecos_bash .ecos_zsh; do
    if [ -f "${HOME}/${i}" ]; then
      echo "Removing file: ~/${i}"
      rm -f "${HOME}/${i}"
    fi
  done
  uninstall_tcsh
}

update() {
  if [ -f "${HOME}/.tcsh_exec" ]; then
    mv -f "${HOME}/.tcsh_exec" "${HOME}/.ecos_tcsh.after"
    echo "Moved: ${HOME}/.tcsh_exec => ${HOME}/.ecos_tcsh.after"
  fi
}

help() {
  cat <<EOF
Usage: ${0} [install|uninstall]
EOF
}

case "$1" in
  install)
    install
  ;;
  uninstall)
    uninstall
  ;;
  update)
    update
  ;;
  *)
    help
  ;;
esac