mirror of
https://github.com/joshuadavidthomas/dotfiles.git
synced 2025-12-23 05:36:53 +00:00
139 lines
3.8 KiB
Bash
Executable file
139 lines
3.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
INSTALL_DIR=${HOME}/.cfg
|
|
|
|
config () {
|
|
/usr/bin/git --git-dir=${INSTALL_DIR}/ --work-tree=${HOME} $@
|
|
}
|
|
|
|
install_bare_dotfiles () {
|
|
git clone --bare https://github.com/joshuadavidthomas/dotfiles.git ${INSTALL_DIR}
|
|
mkdir -p .config-backup
|
|
if ! config checkout; then
|
|
echo "Backing up pre-existing dot files."
|
|
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} .config-backup/{}
|
|
fi
|
|
config checkout
|
|
config config status.showUntrackedFiles no
|
|
}
|
|
|
|
update_bare_dotfiles () {
|
|
config pull
|
|
}z
|
|
|
|
set -o errexit
|
|
set -o pipefail
|
|
set -o nounset
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
OH_MY_ZSH_DIR=${HOME}/.oh-my-zsh
|
|
ZSH_CUSTOM=${OH_MY_ZSH_DIR}/custom
|
|
LOCAL_BIN_DIR=${HOME}/.local/bin
|
|
|
|
[[ -d ${LOCAL_BIN_DIR} ]] || mkdir -p ${LOCAL_BIN_DIR}
|
|
|
|
set_kernal_and_machine_env_var () {
|
|
KERNAL=$(uname -s | tr "[:upper:]" "[:lower:]")
|
|
case "$(uname -m)" in
|
|
x86_64)
|
|
MACHINE=amd64
|
|
;;
|
|
i686 | i386)
|
|
MACHINE=386
|
|
;;
|
|
aarch64)
|
|
MACHINE=arm64
|
|
;;
|
|
*)
|
|
echo "Machine $(uname -m) not supported by the installer.\n" \
|
|
"Go to https://direnv for alternate installation methods."
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
install_zsh () {
|
|
if [[ ! -x $(command -v zsh) ]]; then
|
|
echo "Installing zsh"
|
|
sudo apt install zsh
|
|
fi
|
|
}
|
|
|
|
install_oh_my_zsh () {
|
|
if [[ ! -d $OH_MY_ZSH_DIR ]]; then
|
|
echo "Cloning oh-my-zsh in to ${OH_MY_ZSH_DIR}"
|
|
umask g-w,o-w
|
|
git clone -c core.eol=lf -c core.autocrlf=false \
|
|
-c fsck.zeroPaddedFilemode=ignore \
|
|
-c fetch.fsck.zeroPaddedFilemode=ignore \
|
|
-c receive.fsck.zeroPaddedFilemode=ignore \
|
|
--depth=1 --branch master https://github.com/ohmyzsh/ohmyzsh ${OH_MY_ZSH_DIR}
|
|
else
|
|
echo "Updating oh-my-zsh"
|
|
cd ${OH_MY_ZSH_DIR}
|
|
git pull
|
|
fi
|
|
}
|
|
|
|
install_tmux_plugin_manager () {
|
|
[[ -d "${HOME}/.tmux/plugins/tpm" ]] || git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
|
|
}
|
|
|
|
|
|
install_starship () {
|
|
if ! [ -x "$(command -v starship)" ]; then
|
|
sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- --force --bin-dir ${LOCAL_BIN_DIR}
|
|
fi
|
|
}
|
|
|
|
install_direnv () {
|
|
if ! [ -x "$(command -v direnv)" ]; then
|
|
set_kernal_and_machine_env_var
|
|
download_url=$(
|
|
curl -fL https://api.github.com/repos/direnv/direnv/releases/latest \
|
|
| grep browser_download_url \
|
|
| cut -d '"' -f 4 \
|
|
| grep "direnv.$KERNAL.$MACHINE"
|
|
)
|
|
curl -o "${LOCAL_BIN_DIR}/direnv" -fL "$download_url"
|
|
chmod +x "${LOCAL_BIN_DIR}/direnv"
|
|
fi
|
|
}
|
|
|
|
install_just () {
|
|
if ! [ -x "$(command -v just)" ]; then
|
|
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --force --to ${LOCAL_BIN_DIR}
|
|
fi
|
|
}
|
|
|
|
install_fzf () {
|
|
[[ -d ${HOME}/.fzf ]] || git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install --key-bindings --completion --update-rc --no-bash
|
|
}
|
|
|
|
install_gh_cli () {
|
|
if ! [ -x "$(command -v gh)" ]; then
|
|
set_kernal_and_machine_env_var
|
|
version=`curl "https://api.github.com/repos/cli/cli/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/' | cut -c2-`
|
|
curl -sSL https://github.com/cli/cli/releases/download/v${version}/gh_${version}_${KERNAL}_${MACHINE}.tar.gz -o gh_${version}_${KERNAL}_${MACHINE}.tar.gz
|
|
tar xvf gh_${version}_${KERNAL}_${MACHINE}.tar.gz
|
|
mv gh_${version}_${KERNAL}_${MACHINE}/bin/gh ${LOCAL_BIN_DIR}/gh
|
|
sudo mv gh_${version}_${KERNAL}_${MACHINE}/share/man/man1/* /usr/share/man/man1/
|
|
chmod +x "${LOCAL_BIN_DIR}/gh"
|
|
fi
|
|
}
|
|
|
|
if [[ ! -d ${INSTALL_DIR} ]]; then
|
|
install_bare_dotfiles
|
|
else
|
|
update_bare_dotfiles
|
|
fi
|
|
|
|
install_zsh
|
|
install_oh_my_zsh
|
|
install_tmux_plugin_manager
|
|
install_starship
|
|
install_direnv
|
|
install_just
|
|
install_fzf
|
|
install_gh_cli
|