dotwryn/setup
2021-04-09 21:27:44 +00:00

245 lines
6.4 KiB
Bash
Executable File

#!/bin/zsh
################################################################################
### SETUP VERIFICATION #########################################################
################################################################################
DOTWRYN_PATH="$(pwd)"
function CHECK_DIR() {
read -p "Is DOTWRYN.git installed at '$DOTWRYN_PATH'? [Yn] : " validate;
case $validate in
[nN]* ) exit 1;;
* ) ;;
esac
}
CHECK_DIR; # verify install detected correct location before continuing
################################################################################
### SHELL SETUP ################################################################
################################################################################
function SOURCE_DOTWRYN_RC {
local HOME_RC="$1";
local WRYN_RC="$2";
[ ! -f "$HOME/$HOME_RC" ] && touch "$HOME/$HOME_RC";
grep "$WRYN_RC" "$HOME/$HOME_RC" && {
echo "already set up $HOME_RC";
} || {
echo "source $WRYN_RC" >> "$HOME/$HOME_RC";
echo "successfully set up $HOME_RC";
}
}
function ENV__SETUP_LOCAL_OVERRIDES() {
local DEFAULT_SHELL_ENV="$DOTWRYN_PATH/env/env"
local LOCAL_SHELL_ENV="$HOME/.config/wryn/env/env"
local DEFAULT_VIM_ENV="$DOTWRYN_PATH/env/env.vim"
local LOCAL_VIM_ENV="$HOME/.config/wryn/env/env.vim"
echo "source $DOTWRYN_PATH/env/env" > "$LOCAL_SHELL_ENV"
echo -e '\n#\n# ~/.wryn/env/env local overrides\n#\n' >> "$LOCAL_SHELL_ENV"
sed 's/[#]*\(.*\)/#\1/' $DEFAULT_SHELL_ENV >> "$LOCAL_SHELL_ENV"
echo "source $DOTWRYN_PATH/env/env.vim" > "$LOCAL_VIM_ENV"
echo -e '\n"\n" ~/.wryn/env/env.vim local overrides\n"\n' >> "$LOCAL_VIM_ENV"
sed 's/["]*\(.*\)/"\1/' $DEFAULT_VIM_ENV >> "$LOCAL_VIM_ENV"
}
function SHELL__SETUP {
SOURCE_DOTWRYN_RC '.bashrc' "$DOTWRYN_PATH/zsh/rc";
SOURCE_DOTWRYN_RC '.zshrc' "$DOTWRYN_PATH/zsh/rc";
ENV__SETUP_LOCAL_OVERRIDES;
}
################################################################################
### VIM SETUP ##################################################################
################################################################################
function VIM__UPDATE_COLORSCHEMES() {
$DOTWRYN_PATH/bin/vim/update_colorschemes
}
function VIM__INSTALL_VUNDLE_PLUGINS() {
[ ! -d "$HOME/.vim" ] && mkdir "$HOME/.vim"
[ ! -d "$HOME/.vim/bundle" ] && mkdir "$HOME/.vim/bundle"
[ ! -d "$HOME/.vim/bundle/Vundle.vim" ] && {
echo "installing vundle";
git clone https://github.com/VundleVim/Vundle.vim.git "$HOME/.vim/bundle/Vundle.vim";
}
echo "installing vundle plugins"
vim +PluginInstall +qall;
echo "building plugins"
$DOTWRYN_PATH/bin/vim/rebuild_plugins;
}
function VIM__SETUP() {
echo 'setting up vim';
SOURCE_DOTWRYN_RC '.vimrc' "$DOTWRYN_PATH/vim/rc.vim";
VIM__UPDATE_COLORSCHEMES;
VIM__INSTALL_VUNDLE_PLUGINS;
echo 'vim setup complete';
}
################################################################################
### LINK CONFIGURATION FILES ###################################################
################################################################################
function CONFIG__BASIC_SYMLINK() {
local HOME_CONFIG="$1";
local WRYN_CONFIG="$2";
mv "$HOME_CONFIG" "$HOME_CONFIG.bak" >/dev/null 2>&1;
ln -s "$WRYN_CONFIG" "$HOME_CONFIG";
}
function CONFIG__SYMLINK() {
local CONFIG_DIR="$1";
local FILENAME="$2";
local HOME_CONFIG_DIR="$HOME/.config/$CONFIG_DIR";
local HOME_CONFIG="$HOME_CONFIG_DIR/$FILENAME";
local WRYN_CONFIG="$DOTWRYN_PATH/config/$CONFIG_DIR/$FILENAME";
[ ! -d "$HOME_CONFIG_DIR" ] && mkdir "$HOME_CONFIG_DIR";
CONFIG__BASIC_SYMLINK $HOME_CONFIG $WRYN_CONFIG;
}
function CONFIG__I3() {
CONFIG__SYMLINK "i3" "config";
CONFIG__BASIC_SYMLINK "$HOME/.config/wryn/i3utils" "$DOTWRYN_PATH/config/i3/utils";
echo "linked i3 configuration";
}
function CONFIG__I3STATUS() {
CONFIG__SYMLINK "i3status" "config";
echo "linked i3status configuration";
}
function CONFIG__PGCLI() {
CONFIG__SYMLINK "pgcli" "config";
echo "linked pgcli configuration";
}
function CONFIG__MSSQLCLI() {
CONFIG__SYMLINK "mssqlcli" "config";
echo "linked mssqlcli configuration";
}
function CONFIG__COMPTON() {
CONFIG__SYMLINK "compton" "compton.conf";
echo "linked compton configuration"
}
function CONFIG__KITTY() {
CONFIG__SYMLINK "kitty" "kitty.conf";
CONFIG__SYMLINK "kitty" "theme.conf";
echo "linked kitty configuration"
}
function CONFIG__RIPGREP() {
CONFIG__SYMLINK "ripgrep" "config"
echo "linked ripgrep configuration"
}
function CONFIG__GIT() {
CONFIG__BASIC_SYMLINK "$HOME/.gitconfig" "$DOTWRYN_PATH/config/git/gitconfig";
echo "linked global git configuration"
}
function CONFIG__PYLINT() {
CONFIG__BASIC_SYMLINK "$HOME/.config/pylintrc" "$DOTWRYN_PATH/config/pylint/pylintrc";
echo "linked pylint configuration"
}
function CONFIG__SFX_APPLICATION() {
CONFIG__BASIC_SYMLINK "$HOME/.config/wryn/sfx" "$DOTWRYN_PATH/bin/desktop/sfx/play.sh";
echo "linked xinitrc"
}
function CONFIG__TMUX() {
CONFIG__BASIC_SYMLINK "$HOME/.tmux.conf" "$DOTWRYN_PATH/config/tmux/tmux.conf";
echo "linked tmux configuration"
}
function CONFIG__XINITRC() {
CONFIG__BASIC_SYMLINK "$HOME/.xinitrc" "$DOTWRYN_PATH/config/xorg/xinitrc"
echo "linked xinitrc"
}
function CONFIG__TERMINFO() {
echo "adding terminfo files"
for file in $(find "$DOTWRYN_PATH/config/terminfo" -type f); do
tic -x $file >/dev/null 2>&1 || echo "failed to add $file" ;
done
}
function CONFIG__SETUP() {
CONFIG__I3;
CONFIG__I3STATUS;
CONFIG__PGCLI;
CONFIG__MSSQLCLI;
CONFIG__COMPTON;
CONFIG__KITTY;
CONFIG__RIPGREP;
CONFIG__GIT;
CONFIG__PYLINT;
CONFIG__SFX_APPLICATION;
CONFIG__TMUX;
CONFIG__XINITRC;
CONFIG__TERMINFO;
}
################################################################################
### RUN CONFIG #################################################################
################################################################################
function CLEAN_BACKUP() {
read -p "Clean backup files? [Yn] : " yn;
case $yn in
[nN]* ) echo 'skipping cleanup';;
* )
echo 'cleaning backup files';
for file in $(find "$HOME/.config/" -name \*.bak 2>/dev/null); do rm $file && echo cleaned $file; done
for file in $(find "$HOME" -maxdepth 1 -name .\*.bak 2>/dev/null); do rm $file && echo cleaned $file; done
;;
esac
}
[ ! -d "$HOME/.config" ] && mkdir "$HOME/.config";
[ ! -d "$HOME/.config/wryn" ] && mkdir "$HOME/.config/wryn";
[ ! -d "$HOME/.config/wryn/env" ] && mkdir "$HOME/.config/wryn/env";
SHELL__SETUP;
VIM__SETUP;
CONFIG__SETUP;
CLEAN_BACKUP;
echo -e "\nsetup complete"