You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.0 KiB
124 lines
3.0 KiB
11 years ago
|
#!/bin/zsh
|
||
|
# .files installer
|
||
|
# (c) 2014 MORI Taeyeon
|
||
|
|
||
|
# Paths & Utils
|
||
|
DOT="$(realpath "$(dirname "$0")")"
|
||
|
|
||
|
setopt EXTENDED_GLOB
|
||
|
source "$DOT/zsh/lib.zsh"
|
||
|
|
||
|
# Parse commandline
|
||
|
OVERWRITE=false
|
||
|
|
||
|
function print_usage() {
|
||
|
echo "Usage: $0 [--help] [--overwrite]"
|
||
|
echo
|
||
|
echo "Install Tae's dotfiles"
|
||
|
echo
|
||
|
echo "Parameters:"
|
||
|
echo " -h, --help Display this help message"
|
||
|
echo " --overwrite Just overwrite existing dotfiles"
|
||
|
}
|
||
|
|
||
|
for arg in "$@"; do
|
||
|
[[ -z "$STATE" ]] && {
|
||
|
case "$arg" in
|
||
|
-h|--help) print_usage; exit 0;;
|
||
|
--overwrite) OVERWRITE=true;;
|
||
|
*) print_usage; exit 1;;
|
||
|
esac
|
||
|
} || {
|
||
|
case "$STATE" in
|
||
|
# handle options with parameters
|
||
|
esac
|
||
|
STATE=
|
||
|
}
|
||
|
done
|
||
|
[[ -n "$STATE" ]] && err "Option $STATE is missing it's parameter!" && exit 1
|
||
|
|
||
|
# Helper functions
|
||
|
function generate() {
|
||
|
[[ -e "$1" ]] && ! $OVERWRITE && ! grep -q "Generated by .files/install" "$1" && \
|
||
|
err "Custom version of $1 detected. Please delete it before running .files/install" && exit 1
|
||
|
echo "# Generated by .files/install" >"$1"
|
||
|
echo "# `date "+%m/%d/%Y %H:%M:%S"`" >>"$1"
|
||
|
echo >>"$1"
|
||
|
cat >>"$1"
|
||
|
}
|
||
|
|
||
|
function relink() {
|
||
|
[[ ! -e "$1" ]] && err "No such file or directory: '$1'" && return 1
|
||
|
[[ -L "$2" ]] && rm -f "$2"
|
||
|
[[ -e "$2" ]] && ! $OVERWRITE && err "File already exists and isn't a symbolic link: '$2'" && return 1
|
||
|
color 31 ln -s "$1" "$2"
|
||
|
}
|
||
|
|
||
|
# Update git modules
|
||
|
msg "Updating git submodules..."
|
||
|
git submodule update --init --recursive
|
||
|
|
||
|
# Ask questions about user
|
||
|
msg "Asking questions..."
|
||
|
|
||
|
[[ -e "$DOT/user-info" ]] && source "$DOT/user-info"
|
||
|
|
||
|
[[ -z "$REAL_NAME" ]] && REALNAME=`grep "^$USER:[^:]*:$UID:" /etc/passwd | cut -d: -f5 | cut -d, -f1`
|
||
|
ask "Real name" REALNAME
|
||
|
ask "E-Mail address" EMAIL
|
||
|
|
||
|
generate "$DOT/user-info" <<EOF
|
||
|
REALNAME="$REALNAME"
|
||
|
EMAIL="$EMAIL"
|
||
|
EOF
|
||
|
|
||
|
# Setup dotfiles
|
||
|
msg "Linking dotfiles..."
|
||
|
for file in "$DOT/dotfiles"/*; do
|
||
|
NAM="${file:t}"
|
||
|
color 32 echo " Adding .$NAM"
|
||
|
relink "$file" "$HOME/.$NAM"
|
||
|
done
|
||
|
|
||
|
# Setup git
|
||
|
msg "Setting up Git configuration..."
|
||
|
|
||
|
GIT="$DOT/git"
|
||
|
[[ -e "$HOME/.gitconfig" ]] && ! grep -q ".files/install" "$HOME/.gitconfig" && err "Custom ~/.gitconfig already exists! Please remove it before running .files/install" && exit 1
|
||
|
|
||
|
generate "$HOME/.gitconfig" <<EOF
|
||
|
[include]
|
||
|
path = $GIT/config
|
||
|
path = $GIT/user-info
|
||
|
EOF
|
||
|
|
||
|
generate "$GIT/user-info" <<EOF
|
||
|
[user]
|
||
|
name = $REALNAME
|
||
|
email = $EMAIL
|
||
|
EOF
|
||
|
|
||
|
# Setup ZSH/Prezto
|
||
|
msg "Setting up ZSH configuration..."
|
||
|
ZSH="$DOT/zsh"
|
||
|
|
||
|
generate "$HOME/.zshenv" <<EOF
|
||
|
export DOTFILES="$DOT"
|
||
|
ZDOTDIR="\$DOTFILES/zsh"
|
||
|
source "\$ZDOTDIR/zshenv"
|
||
|
EOF
|
||
|
|
||
|
for file in zprofile zshrc zpreztorc zlogin zlogout; do
|
||
|
relink "$ZSH/$file" "$ZSH/.$file"
|
||
|
done
|
||
|
|
||
|
relink "$ZSH/prezto" "$ZSH/.zprezto"
|
||
|
|
||
|
# Set login shell
|
||
|
msg "Setting login shell to '/bin/zsh'..."
|
||
|
echo $SHELL | grep -q zsh || chsh -s /bin/zsh
|
||
|
|
||
|
# Warn user
|
||
|
color 33 echo "You need to relog to apply shell configuration."
|
||
|
|