|
|
@ -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,111 +158,135 @@ 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 |
|
|
|
(){ |
|
|
|
pushd $DOT/dotfiles |
|
|
|
local -A names prios |
|
|
|
add_names names prios * |
|
|
|
pushd $DOT/dotfiles |
|
|
|
for name src in ${(@kv)names}; do |
|
|
|
add_names names prios * |
|
|
|
color 32 echo " Adding .$name" |
|
|
|
for name src in ${(@kv)names}; do |
|
|
|
relink $src $HOME/.$name |
|
|
|
color 32 echo " Adding .$name" |
|
|
|
done |
|
|
|
relink $src $HOME/.$name |
|
|
|
popd |
|
|
|
done |
|
|
|
} |
|
|
|
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() { |
|
|
|
(){ |
|
|
|
local target=$1 dest=$2 name=${3:-$2} from |
|
|
|
function relink_r() { |
|
|
|
[[ ${target:t} != ${dest:t} ]] && from=" (${target:t})" |
|
|
|
local target=$1 dest=$2 name=${3:-$2} from |
|
|
|
if [[ ! -d $target ]]; then |
|
|
|
[[ ${target:t} != ${dest:t} ]] && from=" (${target:t})" |
|
|
|
color 32 echo " Adding $name$from" |
|
|
|
if [[ ! -d $target ]]; then |
|
|
|
relink $target $dest |
|
|
|
color 32 echo " Adding $name$from" |
|
|
|
else |
|
|
|
relink $target $dest |
|
|
|
if [[ ! -d $dest ]]; then |
|
|
|
else |
|
|
|
color 32 echo " Creating directory $name/$from" |
|
|
|
if [[ ! -d $dest ]]; then |
|
|
|
mkdir $dest |
|
|
|
color 32 echo " Creating directory $name/$from" |
|
|
|
elif [[ -n $from ]]; then |
|
|
|
mkdir $dest |
|
|
|
color 32 echo " Adding directory $name/$from" |
|
|
|
elif [[ -n $from ]]; then |
|
|
|
|
|
|
|
color 32 echo " Adding directory $name/$from" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
# This is still slightly ugly |
|
|
|
|
|
|
|
local -A names prios |
|
|
|
|
|
|
|
add_names names prios $target/* |
|
|
|
|
|
|
|
for dst src in ${(@kv)names}; do |
|
|
|
|
|
|
|
relink_r $src $dest/${dst:t} $name/${dst:t} |
|
|
|
|
|
|
|
done |
|
|
|
fi |
|
|
|
fi |
|
|
|
# This is still slightly ugly |
|
|
|
} |
|
|
|
local -A names prios |
|
|
|
pushd $DOT/config |
|
|
|
add_names names prios $target/* |
|
|
|
local -A names prios |
|
|
|
for dst src in ${(@kv)names}; do |
|
|
|
add_names names prios * |
|
|
|
relink_r $src $dest/${dst:t} $name/${dst:t} |
|
|
|
for dst src in ${(@kv)names}; do |
|
|
|
done |
|
|
|
relink_r $src $XDG_CONFIG_HOME/$dst $dst |
|
|
|
fi |
|
|
|
done |
|
|
|
|
|
|
|
popd |
|
|
|
} |
|
|
|
} |
|
|
|
pushd $DOT/config |
|
|
|
else |
|
|
|
local -A names prios |
|
|
|
msg "Skipped .config" |
|
|
|
add_names names prios * |
|
|
|
fi |
|
|
|
for dst src in ${(@kv)names}; do |
|
|
|
|
|
|
|
relink_r $src $XDG_CONFIG_HOME/$dst $dst |
|
|
|
|
|
|
|
done |
|
|
|
|
|
|
|
popd |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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 |
|
|
|
msg "Login shell is already set to zsh, you're good to go!" |
|
|
|
if getent passwd $(id -un) | grep -q 'zsh$'; then |
|
|
|
else |
|
|
|
msg "Login shell is already set to zsh, you're good to go!" |
|
|
|
msg "Setting login shell to '$(which zsh)'..." |
|
|
|
else |
|
|
|
chsh -s "$(which zsh)" |
|
|
|
msg "Setting login shell to '$(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." |
|
|
|
|
|
|
|
|
|
|
|