|
|
@ -1,6 +1,6 @@ |
|
|
|
#!/bin/zsh |
|
|
|
#!/bin/zsh |
|
|
|
# .files/install |
|
|
|
# .files/install |
|
|
|
# (c) 2014-2017 MORI Taeyeon |
|
|
|
# (c) 2014-2021 MORI Taeyeon |
|
|
|
|
|
|
|
|
|
|
|
# Paths & Utils |
|
|
|
# Paths & Utils |
|
|
|
DOT="$(realpath "$(dirname "$0")")" |
|
|
|
DOT="$(realpath "$(dirname "$0")")" |
|
|
@ -14,6 +14,12 @@ source "$DOT/lib/libzsh-utils.zsh" |
|
|
|
# ============================= |
|
|
|
# ============================= |
|
|
|
OVERWRITE=false |
|
|
|
OVERWRITE=false |
|
|
|
ASK=true |
|
|
|
ASK=true |
|
|
|
|
|
|
|
INSTALL_ZSH=true |
|
|
|
|
|
|
|
INSTALL_DOT=true |
|
|
|
|
|
|
|
INSTALL_CNF=true |
|
|
|
|
|
|
|
INSTALL_GIT=true |
|
|
|
|
|
|
|
INSTALL_CHSH=true |
|
|
|
|
|
|
|
INSTALL_EXTRA=true |
|
|
|
|
|
|
|
|
|
|
|
function print_usage() { |
|
|
|
function print_usage() { |
|
|
|
echo "Usage: $1 [--help] [--overwrite] [--dont-ask]" |
|
|
|
echo "Usage: $1 [--help] [--overwrite] [--dont-ask]" |
|
|
@ -24,6 +30,8 @@ function print_usage() { |
|
|
|
echo " -h, --help Display this help message" |
|
|
|
echo " -h, --help Display this help message" |
|
|
|
echo " --overwrite Just overwrite existing dotfiles" |
|
|
|
echo " --overwrite Just overwrite existing dotfiles" |
|
|
|
echo " --dont-ask Don't ask questions. Use default values" |
|
|
|
echo " --dont-ask Don't ask questions. Use default values" |
|
|
|
|
|
|
|
echo " --no-{zsh,dotfiles,config,git,chsh,extra}" |
|
|
|
|
|
|
|
echo " Don't set up the specific component" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for arg in "$@"; do |
|
|
|
for arg in "$@"; do |
|
|
@ -32,6 +40,12 @@ for arg in "$@"; do |
|
|
|
-h|--help) print_usage "$0"; exit 0;; |
|
|
|
-h|--help) print_usage "$0"; exit 0;; |
|
|
|
--overwrite) OVERWRITE=true;; |
|
|
|
--overwrite) OVERWRITE=true;; |
|
|
|
--dont-ask) ASK=false;; |
|
|
|
--dont-ask) ASK=false;; |
|
|
|
|
|
|
|
--no-zsh) INSTALL_ZSH=false;; |
|
|
|
|
|
|
|
--no-dotfiles) INSTALL_DOT=false;; |
|
|
|
|
|
|
|
--no-config) INSTALL_CNF=false;; |
|
|
|
|
|
|
|
--no-git) INSTALL_GIT=false;; |
|
|
|
|
|
|
|
--no-chsh) INSTALL_CHSH=false;; |
|
|
|
|
|
|
|
--no-extra) INSTALL_EXTRA=false;; |
|
|
|
*) print_usage "$0"; exit 1;; |
|
|
|
*) print_usage "$0"; exit 1;; |
|
|
|
esac |
|
|
|
esac |
|
|
|
} || { |
|
|
|
} || { |
|
|
@ -144,8 +158,9 @@ function add_names() { |
|
|
|
# Write files to $HOME |
|
|
|
# Write files to $HOME |
|
|
|
# ============================= |
|
|
|
# ============================= |
|
|
|
# Setup dotfiles |
|
|
|
# Setup dotfiles |
|
|
|
msg "Linking dotfiles..." |
|
|
|
if $INSTALL_DOT; then |
|
|
|
(){ |
|
|
|
msg "Linking dotfiles..." |
|
|
|
|
|
|
|
(){ |
|
|
|
local -A names prios |
|
|
|
local -A names prios |
|
|
|
pushd $DOT/dotfiles |
|
|
|
pushd $DOT/dotfiles |
|
|
|
add_names names prios * |
|
|
|
add_names names prios * |
|
|
@ -154,12 +169,16 @@ msg "Linking dotfiles..." |
|
|
|
relink $src $HOME/.$name |
|
|
|
relink $src $HOME/.$name |
|
|
|
done |
|
|
|
done |
|
|
|
popd |
|
|
|
popd |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
msg "Skipped dotfiles." |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Setup .config |
|
|
|
# Setup .config |
|
|
|
: ${XDG_CONFIG_HOME:=~/.config} |
|
|
|
if $INSTALL_CNF; then |
|
|
|
msg "Linking .config files... ($XDG_CONFIG_HOME)" |
|
|
|
: ${XDG_CONFIG_HOME:=~/.config} |
|
|
|
(){ |
|
|
|
msg "Linking .config files... ($XDG_CONFIG_HOME)" |
|
|
|
|
|
|
|
(){ |
|
|
|
function relink_r() { |
|
|
|
function relink_r() { |
|
|
|
local target=$1 dest=$2 name=${3:-$2} from |
|
|
|
local target=$1 dest=$2 name=${3:-$2} from |
|
|
|
[[ ${target:t} != ${dest:t} ]] && from=" (${target:t})" |
|
|
|
[[ ${target:t} != ${dest:t} ]] && from=" (${target:t})" |
|
|
@ -188,67 +207,86 @@ msg "Linking .config files... ($XDG_CONFIG_HOME)" |
|
|
|
relink_r $src $XDG_CONFIG_HOME/$dst $dst |
|
|
|
relink_r $src $XDG_CONFIG_HOME/$dst $dst |
|
|
|
done |
|
|
|
done |
|
|
|
popd |
|
|
|
popd |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
msg "Skipped .config" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Setup git |
|
|
|
# Setup git |
|
|
|
# ============================= |
|
|
|
# ============================= |
|
|
|
msg "Setting up Git configuration..." |
|
|
|
if $INSTALL_GIT; then |
|
|
|
|
|
|
|
msg "Setting up Git configuration..." |
|
|
|
|
|
|
|
|
|
|
|
GIT="$DOT/git" |
|
|
|
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 |
|
|
|
[[ -e "$HOME/.gitconfig" ]] && ! grep -q ".files/install" "$HOME/.gitconfig" && err "Custom ~/.gitconfig already exists! Please remove it before running .files/install" && exit 1 |
|
|
|
|
|
|
|
|
|
|
|
color 32 echo " Writing .gitconfig" |
|
|
|
color 32 echo " Writing .gitconfig" |
|
|
|
generate "$HOME/.gitconfig" <<EOF |
|
|
|
generate "$HOME/.gitconfig" <<EOF |
|
|
|
[include] |
|
|
|
[include] |
|
|
|
path = $(relpath "$GIT" "$HOME")/config |
|
|
|
path = $(relpath "$GIT" "$HOME")/config |
|
|
|
path = $(relpath "$GIT" "$HOME")/user-info |
|
|
|
path = $(relpath "$GIT" "$HOME")/user-info |
|
|
|
EOF |
|
|
|
EOF |
|
|
|
|
|
|
|
|
|
|
|
[ "`uname -s`" = "Darwin" ] && \ |
|
|
|
[ "`uname -s`" = "Darwin" ] && \ |
|
|
|
cat >>"$HOME/.gitconfig" <<EOF |
|
|
|
cat >>"$HOME/.gitconfig" <<EOF |
|
|
|
path = $(relpath "$GIT" "$HOME")/osx |
|
|
|
path = $(relpath "$GIT" "$HOME")/osx |
|
|
|
EOF |
|
|
|
EOF |
|
|
|
|
|
|
|
|
|
|
|
color 32 echo " Writing git/user-info" |
|
|
|
color 32 echo " Writing git/user-info" |
|
|
|
generate "$GIT/user-info" <<EOF |
|
|
|
generate "$GIT/user-info" <<EOF |
|
|
|
[user] |
|
|
|
[user] |
|
|
|
name = $REALNAME |
|
|
|
name = $REALNAME |
|
|
|
email = $EMAIL |
|
|
|
email = $EMAIL |
|
|
|
EOF |
|
|
|
EOF |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
msg "Skipped git configuration" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Setup ZSH/Prezto |
|
|
|
# Setup ZSH/Prezto |
|
|
|
# ============================= |
|
|
|
# ============================= |
|
|
|
msg "Setting up ZSH configuration..." |
|
|
|
if $INSTALL_ZSH; then |
|
|
|
ZSH="$DOT/zsh" |
|
|
|
msg "Setting up ZSH configuration..." |
|
|
|
|
|
|
|
ZSH="$DOT/zsh" |
|
|
|
|
|
|
|
|
|
|
|
color 32 echo " Writing .zshenv" |
|
|
|
color 32 echo " Writing .zshenv" |
|
|
|
generate "$HOME/.zshenv" <<EOF |
|
|
|
generate "$HOME/.zshenv" <<EOF |
|
|
|
export DOTFILES="\$HOME/$(relpath "$DOT" "$HOME")" |
|
|
|
export DOTFILES="\$HOME/$(relpath "$DOT" "$HOME")" |
|
|
|
ZDOTDIR="\$DOTFILES/zsh" |
|
|
|
ZDOTDIR="\$DOTFILES/zsh" |
|
|
|
[[ -f "\$ZDOTDIR/zshenv" ]] && source "\$ZDOTDIR/zshenv" |
|
|
|
[[ -f "\$ZDOTDIR/zshenv" ]] && source "\$ZDOTDIR/zshenv" |
|
|
|
[[ ! -o LOGIN && "\$SHLVL" == 1 && -f "\$ZDOTDIR/zprofile" ]] && source "\$ZDOTDIR/zprofile" |
|
|
|
[[ ! -o LOGIN && "\$SHLVL" == 1 && -f "\$ZDOTDIR/zprofile" ]] && source "\$ZDOTDIR/zprofile" |
|
|
|
EOF |
|
|
|
EOF |
|
|
|
|
|
|
|
|
|
|
|
for file in zshrc zpreztorc zlogin zlogout zprofile; do |
|
|
|
for file in zshrc zpreztorc zlogin zlogout zprofile; do |
|
|
|
color 32 echo " Adding .$file" |
|
|
|
color 32 echo " Adding .$file" |
|
|
|
relink "$ZSH/$file" "$ZSH/.$file" |
|
|
|
relink "$ZSH/$file" "$ZSH/.$file" |
|
|
|
done |
|
|
|
done |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
msg "Skipped ZSH configuration." |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Do misc setup |
|
|
|
# Do misc setup |
|
|
|
# ============================= |
|
|
|
# ============================= |
|
|
|
test -f "$DOTFILES/install.extra" && "$DOTFILES/install.extra" |
|
|
|
if [ -x "$DOT/install.extra" ]; then |
|
|
|
|
|
|
|
if $INSTALL_EXTRA; then |
|
|
|
|
|
|
|
msg "Running install.extra..." |
|
|
|
|
|
|
|
"$DOT/install.extra" |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
msg "Not running install.extra." |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Check login shell |
|
|
|
# Check login shell |
|
|
|
if getent passwd $(id -un) | grep -q 'zsh$'; then |
|
|
|
if $INSTALL_CHSH; then |
|
|
|
|
|
|
|
if getent passwd $(id -un) | grep -q 'zsh$'; then |
|
|
|
msg "Login shell is already set to zsh, you're good to go!" |
|
|
|
msg "Login shell is already set to zsh, you're good to go!" |
|
|
|
else |
|
|
|
else |
|
|
|
msg "Setting login shell to '$(which zsh)'..." |
|
|
|
msg "Setting login shell to '$(which zsh)'..." |
|
|
|
chsh -s "$(which zsh)" |
|
|
|
chsh -s "$(which zsh)" |
|
|
|
|
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Done. |
|
|
|
# Done. |
|
|
|
warn "You may need to relog for all changes to take effect." |
|
|
|
warn "You may need to relog for all changes to take effect." |
|
|
|
warn "If you're currently running zsh, you definitely need to at least restart the shell to apply changes." |
|
|
|
$INSTALL_ZSH && warn "If you're currently running zsh, you definitely need to at least restart the shell to apply changes." |
|
|
|
|
|
|
|
|
|
|
|