view setup @ 65:e6aa07cf62cc

Autoload for zsh
author Edho Prima Arief <me@myconan.net>
date Tue, 17 May 2011 13:29:53 -0400
parents 3cd3f31d8a82
children 54a82956bb11
line wrap: on
line source

#!/bin/sh

install() {
  uninstall
  #create symlinks
  linker "tcsh" ".tcsh_init"
  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}/.tcsh_init" ] && source "${HOME}/.tcsh_init" #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 .tcsh_init .tmux.conf .hgrc .vimrc .inputrc bin-ec .ecos.bin; 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}/.tcsh_init.after"
    echo "Moved: ${HOME}/.tcsh_exec => ${HOME}/.tcsh_init.after"
  fi
}

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

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