rc/install.sh

46 lines
1.7 KiB
Bash
Raw Normal View History

2016-10-22 05:10:25 +00:00
#!/bin/sh
2015-06-03 21:39:41 +00:00
SCRIPT=$(readlink -f "$0")
RC_PATH=$(dirname "$SCRIPT")
2016-10-22 05:10:25 +00:00
HOST=$(hostname)
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
2015-06-03 21:39:41 +00:00
2015-06-06 22:47:56 +00:00
# List of the config files to install
2019-11-19 13:22:31 +00:00
FILES="vimrc zshrc gitconfig vim gitignore_global git_user ctags.d mailcap"
CONF_DIR="config"
DATA_DIR="data"
2016-10-22 05:10:25 +00:00
if [ ! -e "$HOME/.git_user" ]; then
cp "$RC_PATH/git_user.def" "$RC_PATH/git_user"
sed -i -e "s/{username}/$USER/" "$RC_PATH/git_user"
sed -i -e "s/{email}/$USER@$HOST/" "$RC_PATH/git_user"
fi
2015-06-03 21:39:41 +00:00
# Init or update submodules
cd "$RC_PATH" || exit
git submodule update --init --recursive
cd - > /dev/null || exit
2018-07-20 01:09:03 +00:00
# Setup fast-syntax-highlighting theme customization
cp "$RC_PATH/fsh_theme.zsh" "$RC_PATH/fast-syntax-highlighting/current_theme.zsh"
2018-07-20 01:09:03 +00:00
2015-06-06 22:47:56 +00:00
# Create symbolic links in the user's home dir
2015-06-03 21:45:41 +00:00
for file in $FILES
do
2016-10-22 05:10:25 +00:00
if [ ! -e "$HOME/.${file}" ]; then
ln -s "${RC_PATH}/${file}" "$HOME/.${file}"
# Only warn if an actual file exist, else we suppose it is from a previous install
elif [ ! -L "$HOME/.$file" ]; then
>&2 echo "File $HOME/.$file exists. Keeping old version."
fi
2015-06-03 21:39:41 +00:00
done
mkdir -p "$XDG_CONFIG_HOME"
mkdir -p "$XDG_DATA_HOME"
# https://github.com/koalaman/shellcheck/wiki/SC2156
find "$RC_PATH/$CONF_DIR" -mindepth 1 -maxdepth 1 -type d \
-exec sh -c 'ln -s -t "$1" "$2" 2> /dev/null || ( link="$1/$(basename "$2")"; test -L "$link" || >&2 echo "Folder $link exists. Keeping old version.")' _ "$XDG_CONFIG_HOME" '{}' \;
find "$RC_PATH/$DATA_DIR" -mindepth 1 -maxdepth 1 -type d \
-exec sh -c 'ln -s -t "$1" "$2" 2> /dev/null || ( link="$1/$(basename "$2")"; test -L "$link" || >&2 echo "Folder $link exists. Keeping old version.")' _ "$XDG_DATA_HOME" '{}' \;