Mercurial > ec-dotfiles
view setup @ 343:32897d383f97
[bin/ren] Even more rules.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Sun, 25 Mar 2012 18:21:30 +0700 |
parents | 94d0e4826d28 |
children | 38fad89edd55 |
line wrap: on
line source
#!/bin/sh set -u set -e basedir="`dirname "${0}"`" cd "${basedir}" basedir="`pwd`" rcdir="${basedir}/rc" bindir="${basedir}/bin" test -n "${HOME}" || exit 1 _echo() { _echon "${*}"; printf "\n" } _echon() { printf '%s' "${*}" } _tcsh() { case "$1" in uninstall|install) _rc "${1}" "cshrc" ".ecos_tcsh" _init "${1}" 'test -r "${HOME}/.ecos_tcsh" && source "${HOME}/.ecos_tcsh" #ECCORE_TCSH' ".cshrc" ;; esac } _bash() { case "${1}" in uninstall|install) _rc "${1}" "bashrc" ".ecos_bash" _init "${1}" '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' ".bash_profile" _init "${1}" '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' ".bashrc" ;; esac } _zsh() { case "${1}" in uninstall|install) _rc "${1}" "zshrc" ".ecos_zsh" _init "${1}" '[ -r "${HOME}/.ecos_zsh" ] && . "${HOME}/.ecos_zsh" #ECCORE_ZSH' ".zshrc" ;; esac } _rc() { if test -z "${3}" || test -z "${2}" || test -z "${1}"; then _echo "Invalid command." return fi _srcfile="${rcdir}/${2}" _dstfile="${HOME}/${3}" _dstdir="`_echo "${_dstfile}" | sed -e 's,^\(.*\)/[^/]*$,\1,'`" mkdir -p "${_dstdir}" if test ! -h "${_dstfile}"; then if test -f "${_dstfile}"; then cp "${_dstfile}" "${_dstfile}.bak" _echo "${_dstfile} backed up to ${_dstfile}.bak" elif test -d "${_dstfile}"; then cp -r "${_dstfile}" "${_dstfile}.bak" _echo "Directory ${_dstfile} backed up to ${_dstfile}.bak" fi fi rm -rf "${_dstfile}" case "${1}" in install) ln -fs "${_srcfile}" "${_dstfile}" _echo "Installed ${_dstfile}" ;; uninstall) _echo "Removed ${_dstfile}" ;; esac } _init() { _script="${HOME}/${3}" _scripttmp="${HOME}/.tmp.${3}" rm -f "${_scripttmp}" _data="${2}" if [ -f "${_script}" ]; then sed -e "/`_echo "${_data}" | sed -e 's/.*#//'`/d" "${_script}" > "${_scripttmp}" mv -f "${_scripttmp}" "${_script}" fi case "${1}" in install) _echo "${_data}" >> "${_script}" _echo "Added autostart to ${_script}" ;; uninstall) _echo "Removed autostart from ${_script}" ;; esac } _help() { cat <<EOF Usage: ${0} [install|uninstall] EOF } case "${1}" in install|uninstall) _tcsh "${1}" _bash "${1}" _zsh "${1}" _rc "${1}" "tmux.conf" ".tmux.conf" _rc "${1}" "hgrc" ".hgrc" _rc "${1}" "vimrc" ".vimrc" _rc "${1}" "vim-solarized" ".vim/colors/solarized.vim" _rc "${1}" "inputrc" ".inputrc" _rc "${1}" "../bin" ".ecos_bin" ;; *) _help ;; esac