Refactor setup script to be re-runnable

This commit is contained in:
Raoul Snyman 2020-12-14 15:19:44 -07:00
parent 11bdbd022d
commit 8944bc3c30
No known key found for this signature in database
GPG Key ID: E45BF62BC5260598

107
setup.sh Normal file → Executable file
View File

@ -5,7 +5,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
APT=`command -v apt` APT=`command -v apt`
DNF=`command -v dnf` DNF=`command -v dnf`
function check_or_install { function check_or_install() {
CMD=`command -v $1` CMD=`command -v $1`
PKG=$2 PKG=$2
if [[ -z "$CMD" ]]; then if [[ -z "$CMD" ]]; then
@ -18,46 +18,73 @@ function check_or_install {
} }
# Set up a generic bin directory for scripts and tools function setup_neovim() {
mkdir -p ~/bin # Set up Neovim
if [[ -d "$HOME/.config/nvim" ]]; then
# Set up Neovim return
check_or_install nvim "neovim python3-neovim" fi
mkdir -p ~/.config echo "Setting up neovim..."
cd ~/.config check_or_install nvim "neovim python3-neovim"
ln -s $DIR/nvim cd $HOME/.config
curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ ln -s $DIR/nvim
curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
}
# Set up Git function setup_git() {
check_or_install git git # Set up Git
git config --global alias.co checkout echo "Setting up git..."
git config --global alias.ci "commit -a" check_or_install git git
git config --global alias.st status git config --global alias.co checkout
git config --global alias.br "checkout -b" git config --global alias.ci "commit -a"
git config --global alias.rv "reset --hard HEAD" git config --global alias.st status
git config --global alias.pum "pull upstream master" git config --global alias.br "checkout -b"
git config --global alias.pom "push origin master" git config --global alias.rv "reset --hard HEAD"
git config --global alias.rbm "rebase master" git config --global alias.pum "pull upstream master"
git config --global alias.last "log -1 HEAD" git config --global alias.pom "push origin master"
git config --global alias.unstage "reset HEAD --" git config --global alias.rbm "rebase master"
git config --global alias.uncommit "reset --soft HEAD^" git config --global alias.last "log -1 HEAD"
git config --global alias.changelog "!_() { t=$(git describe --abbrev=0 --tags); git log ${t}..HEAD --no-merges --pretty=format:'* %s'; }; _" git config --global alias.unstage "reset HEAD --"
git config --global pull.rebase false git config --global alias.uncommit "reset --soft HEAD^"
git config --global alias.changelog "!_() { t=\$(git describe --abbrev=0 --tags); git log \${t}..HEAD --no-merges --pretty=format:'* %s'; }; _"
git config --global pull.rebase false
}
# Set up ZSH function setup_zsh() {
check_or_install zsh zsh # Set up ZSH
sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" if [[ -d "$HOME/.oh-my-zsh" ]]; then
cd ~/.oh-my-zsh/custom return
ln -s $DIR/zsh/themes fi
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="raoul"/' ~/.zshrc echo "Setting up zsh..."
check_or_install zsh zsh
sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
cd $HOME/.oh-my-zsh/custom
ln -s $DIR/zsh/themes
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="raoul"/' $HOME/.zshrc
}
# Set up topydo function setup_topydo() {
check_or_install virtualenv python3-virtualenv # Set up topydo
cd ~/.config if [[ -d "$HOME/.topydo" ]]; then
ln -s $DIR/topydo return
virtualenv -p python3 ~/.config/topydo/venv fi
~/.config/topydo/venv/bin/pip install topydo echo "Set up topydo (as 'todo')..."
cd ~/bin check_or_install virtualenv python3-virtualenv
ln -s $HOME/.config/topydo/venv/bin/topydo cd $HOME/.config
ln -s $HOME/.config/topydo/venv/bin/topydo todo ln -s $DIR/topydo
virtualenv -p python3 $HOME/.topydo
$HOME/.topydo/bin/pip install topydo
$HOME/.topydo/bin/pip install 'topydo[prompt]'
$HOME/.topydo/bin/pip install 'topydo[columns]'
cd $HOME/bin
ln -s $HOME/.topydo/bin/topydo
ln -s $HOME/.topydo/bin/topydo todo
}
# Set up a generic bin directory for scripts and tools
mkdir -p $HOME/bin
mkdir -p $HOME/.config
setup_neovim
setup_git
setup_zsh
setup_topydo