diff --git a/.gitmodules b/.gitmodules index 25c11f2..ab9a703 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "tmux/dot-tmux/plugins/tpm"] - path = tmux/dot-tmux/plugins/tpm + path = stowers/tmux/dot-tmux/plugins/tpm url = https://github.com/tmux-plugins/tpm [submodule "zsh/dot-oh-my-zsh"] - path = zsh/dot-oh-my-zsh + path = stowers/zsh/dot-oh-my-zsh url = https://github.com/ohmyzsh/ohmyzsh diff --git a/install.sh b/install.sh index 8c5fad9..0ceab59 100755 --- a/install.sh +++ b/install.sh @@ -1,50 +1,102 @@ #!/bin/bash -function do_stow() { - local package="$1" - local opts=( "--dotfiles" "--dir" "${DOTFILES_DIR}" ) +set -euo pipefail - if [[ "$#" -ge 2 ]]; then - opts+=( "--target" "$2" ) - fi +DOTFILES_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" +STOWERS_DIR="${DOTFILES_DIR}/stowers" +MODULES_DIR="${DOTFILES_DIR}/modules" +TARGET_DIR="${HOME}" - stow "${opts[@]}" "$package" -} - -function basic_git_setup() { - if ! command -v git &> /dev/null; then - echo "[!] Git is not installed! Not running git setup." +install_stower() { + if ! command -v stow &>/dev/null; then + echo "[!] GNU Stow is not installed!" >&2 return 1 fi - git config --global user.name "Hans Goor" - git config --global user.email "me@eyedevelop.org" - git config --global push.autoSetupRemote true - git config --global pull.rebase true - git config --global commit.gpgsign true - git config --global merge.ff no - git config --global init.defaultBranch main + if [[ "$#" -lt 1 ]]; then + echo "[!] No stower given!" >&2 + return 1 + fi + + local stower_name stower_dir + stower_name="$1" + stower_dir="${STOWERS_DIR}/${stower_name}" + + if [[ ! -d "${stower_dir}" ]]; then + echo "[!] Stower (${stower_dir}) is not a directory!" >&2 + return 1 + fi + + local COMMAND_DEPS + COMMAND_DEPS=() + if [[ -f "${stower_dir}"/config.sh ]]; then + source "${stower_dir}"/config.sh + fi + + for required_cmd in "${COMMAND_DEPS[@]}"; do + if ! command -v "${required_cmd}" &>/dev/null; then + echo "[${stower_name}] Missing required command: ${required_cmd}" >&2 + return 1 + fi + done + + stow --dotfiles \ + --dir "${STOWERS_DIR}" \ + --target "${TARGET_DIR}" \ + --ignore "config.sh" "${stower_name}" || \ + { echo "[!] [${stower_name}] Failed to install!" >&2; return 1; } + + echo "[+] [${stower_name}] Installed!" } -set -eo pipefail +install_module() { + if [[ "$#" -lt 1 ]]; then + echo "[!] No module given!" >&2 + return 1 + fi -DOTFILES_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" -TARGET_DIR="${HOME}" + local module_dir + module_dir="${MODULES_DIR}/$1" -if ! command -v stow &> /dev/null; then - echo "[!] Stow is not installed!" - exit 1 + if [[ ! -d "${module_dir}" ]] || [[ ! -f "${module_dir}/install.sh" ]]; then + echo "[!] Module (${module_dir}) is not a module!" >&2 + return 1 + fi + + /bin/bash "${module_dir}/install.sh" +} + +STOWERS=() +MODULES=() +if [[ "$#" -gt 0 ]]; then + for stower_or_module in "$@"; do + if [[ -e "${STOWERS_DIR}/${stower_or_module}" ]]; then + STOWERS+=("${stower_or_module}") + elif [[ -e "${MODULES_DIR}/${stower_or_module}" ]]; then + MODULES+=("${stower_or_module}") + else + echo "[!] No such stower/module: ${stower_or_module}" >&2 + return 1 + fi + done +else + for stower in "${STOWERS_DIR}"/*/; do + stower_name="$(basename -- "${stower}")" + STOWERS+=("${stower_name}") + done + + for module in "${MODULES_DIR}"/*/; do + module_name="$(basename -- "${module}")" + MODULES+=("$module") + done fi -# Make sure directories exist. -mkdir -p "${TARGET_DIR}/.ssh" -mkdir -p "${TARGET_DIR}/.config" +for stower in "${STOWERS[@]}"; do + install_stower "${stower}" || true +done -# Install SSH separately, as it requres a different target. -do_stow ssh "${TARGET_DIR}/.ssh" || true -do_stow tmux || true -do_stow git || (basic_git_setup || true) -do_stow zsh || true -do_stow nvim "${TARGET_DIR}/.config" || true +for module in "${MODULES[@]}"; do + install_module "${module}" || true +done -echo "[+] Installed!" +echo "[!] Installed everything!" diff --git a/stowers/bash/config.sh b/stowers/bash/config.sh new file mode 100644 index 0000000..5ba72b4 --- /dev/null +++ b/stowers/bash/config.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +COMMAND_DEPS=("bash") diff --git a/bash/dot-bashrc b/stowers/bash/dot-bashrc similarity index 100% rename from bash/dot-bashrc rename to stowers/bash/dot-bashrc diff --git a/stowers/git/config.sh b/stowers/git/config.sh new file mode 100644 index 0000000..8ea9ae7 --- /dev/null +++ b/stowers/git/config.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +COMMAND_DEPS=("git") diff --git a/git/dot-gitconfig b/stowers/git/dot-gitconfig similarity index 100% rename from git/dot-gitconfig rename to stowers/git/dot-gitconfig diff --git a/stowers/nvim/config.sh b/stowers/nvim/config.sh new file mode 100644 index 0000000..2b7de01 --- /dev/null +++ b/stowers/nvim/config.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +COMMAND_DEPS=("nvim") diff --git a/nvim/nvim/after/plugin/autopairs.lua b/stowers/nvim/dot-config/nvim/after/plugin/autopairs.lua similarity index 100% rename from nvim/nvim/after/plugin/autopairs.lua rename to stowers/nvim/dot-config/nvim/after/plugin/autopairs.lua diff --git a/nvim/nvim/after/plugin/blamer.vim b/stowers/nvim/dot-config/nvim/after/plugin/blamer.vim similarity index 100% rename from nvim/nvim/after/plugin/blamer.vim rename to stowers/nvim/dot-config/nvim/after/plugin/blamer.vim diff --git a/nvim/nvim/after/plugin/indent-o-matic.lua b/stowers/nvim/dot-config/nvim/after/plugin/indent-o-matic.lua similarity index 100% rename from nvim/nvim/after/plugin/indent-o-matic.lua rename to stowers/nvim/dot-config/nvim/after/plugin/indent-o-matic.lua diff --git a/nvim/nvim/after/plugin/lsp.lua b/stowers/nvim/dot-config/nvim/after/plugin/lsp.lua similarity index 100% rename from nvim/nvim/after/plugin/lsp.lua rename to stowers/nvim/dot-config/nvim/after/plugin/lsp.lua diff --git a/nvim/nvim/after/plugin/nvim-tree.lua b/stowers/nvim/dot-config/nvim/after/plugin/nvim-tree.lua similarity index 100% rename from nvim/nvim/after/plugin/nvim-tree.lua rename to stowers/nvim/dot-config/nvim/after/plugin/nvim-tree.lua diff --git a/nvim/nvim/after/plugin/telescope.lua b/stowers/nvim/dot-config/nvim/after/plugin/telescope.lua similarity index 100% rename from nvim/nvim/after/plugin/telescope.lua rename to stowers/nvim/dot-config/nvim/after/plugin/telescope.lua diff --git a/nvim/nvim/after/plugin/treesitter.lua b/stowers/nvim/dot-config/nvim/after/plugin/treesitter.lua similarity index 100% rename from nvim/nvim/after/plugin/treesitter.lua rename to stowers/nvim/dot-config/nvim/after/plugin/treesitter.lua diff --git a/nvim/nvim/after/plugin/undotree.lua b/stowers/nvim/dot-config/nvim/after/plugin/undotree.lua similarity index 100% rename from nvim/nvim/after/plugin/undotree.lua rename to stowers/nvim/dot-config/nvim/after/plugin/undotree.lua diff --git a/nvim/nvim/init.lua b/stowers/nvim/dot-config/nvim/init.lua similarity index 100% rename from nvim/nvim/init.lua rename to stowers/nvim/dot-config/nvim/init.lua diff --git a/nvim/nvim/lua/eyedevelop/init.lua b/stowers/nvim/dot-config/nvim/lua/eyedevelop/init.lua similarity index 100% rename from nvim/nvim/lua/eyedevelop/init.lua rename to stowers/nvim/dot-config/nvim/lua/eyedevelop/init.lua diff --git a/nvim/nvim/lua/eyedevelop/packer.lua b/stowers/nvim/dot-config/nvim/lua/eyedevelop/packer.lua similarity index 100% rename from nvim/nvim/lua/eyedevelop/packer.lua rename to stowers/nvim/dot-config/nvim/lua/eyedevelop/packer.lua diff --git a/nvim/nvim/lua/eyedevelop/remap.lua b/stowers/nvim/dot-config/nvim/lua/eyedevelop/remap.lua similarity index 100% rename from nvim/nvim/lua/eyedevelop/remap.lua rename to stowers/nvim/dot-config/nvim/lua/eyedevelop/remap.lua diff --git a/nvim/nvim/lua/eyedevelop/settings.lua b/stowers/nvim/dot-config/nvim/lua/eyedevelop/settings.lua similarity index 100% rename from nvim/nvim/lua/eyedevelop/settings.lua rename to stowers/nvim/dot-config/nvim/lua/eyedevelop/settings.lua diff --git a/nvim/nvim/lua/eyedevelop/theme.lua b/stowers/nvim/dot-config/nvim/lua/eyedevelop/theme.lua similarity index 100% rename from nvim/nvim/lua/eyedevelop/theme.lua rename to stowers/nvim/dot-config/nvim/lua/eyedevelop/theme.lua diff --git a/nvim/nvim/plugin/packer_compiled.lua b/stowers/nvim/dot-config/nvim/plugin/packer_compiled.lua similarity index 100% rename from nvim/nvim/plugin/packer_compiled.lua rename to stowers/nvim/dot-config/nvim/plugin/packer_compiled.lua diff --git a/stowers/ssh/config.sh b/stowers/ssh/config.sh new file mode 100644 index 0000000..b411535 --- /dev/null +++ b/stowers/ssh/config.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +COMMAND_DEPS=("ssh") diff --git a/ssh/config b/stowers/ssh/dot-ssh/config similarity index 100% rename from ssh/config rename to stowers/ssh/dot-ssh/config diff --git a/stowers/tmux/config.sh b/stowers/tmux/config.sh new file mode 100644 index 0000000..d390d51 --- /dev/null +++ b/stowers/tmux/config.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +COMMAND_DEPS=("tmux") diff --git a/tmux/dot-tmux.conf b/stowers/tmux/dot-tmux.conf similarity index 100% rename from tmux/dot-tmux.conf rename to stowers/tmux/dot-tmux.conf diff --git a/tmux/dot-tmux/.gitignore b/stowers/tmux/dot-tmux/.gitignore similarity index 100% rename from tmux/dot-tmux/.gitignore rename to stowers/tmux/dot-tmux/.gitignore diff --git a/tmux/dot-tmux/bindings.conf b/stowers/tmux/dot-tmux/bindings.conf similarity index 100% rename from tmux/dot-tmux/bindings.conf rename to stowers/tmux/dot-tmux/bindings.conf diff --git a/tmux/dot-tmux/gitmux.conf b/stowers/tmux/dot-tmux/gitmux.conf similarity index 100% rename from tmux/dot-tmux/gitmux.conf rename to stowers/tmux/dot-tmux/gitmux.conf diff --git a/tmux/dot-tmux/globals.conf b/stowers/tmux/dot-tmux/globals.conf similarity index 100% rename from tmux/dot-tmux/globals.conf rename to stowers/tmux/dot-tmux/globals.conf diff --git a/tmux/dot-tmux/nvim.conf b/stowers/tmux/dot-tmux/nvim.conf similarity index 100% rename from tmux/dot-tmux/nvim.conf rename to stowers/tmux/dot-tmux/nvim.conf diff --git a/tmux/dot-tmux/plugin-configs/rose-pine.conf b/stowers/tmux/dot-tmux/plugin-configs/rose-pine.conf similarity index 100% rename from tmux/dot-tmux/plugin-configs/rose-pine.conf rename to stowers/tmux/dot-tmux/plugin-configs/rose-pine.conf diff --git a/tmux/dot-tmux/plugins/tpm b/stowers/tmux/dot-tmux/plugins/tpm similarity index 100% rename from tmux/dot-tmux/plugins/tpm rename to stowers/tmux/dot-tmux/plugins/tpm diff --git a/stowers/zsh/config.sh b/stowers/zsh/config.sh new file mode 100644 index 0000000..85a804a --- /dev/null +++ b/stowers/zsh/config.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +COMMAND_DEPS=("zsh") diff --git a/zsh/dot-oh-my-zsh b/stowers/zsh/dot-oh-my-zsh similarity index 100% rename from zsh/dot-oh-my-zsh rename to stowers/zsh/dot-oh-my-zsh diff --git a/zsh/dot-zshrc b/stowers/zsh/dot-zshrc similarity index 100% rename from zsh/dot-zshrc rename to stowers/zsh/dot-zshrc diff --git a/zsh/dot-zshrc.d/00-setup.sh b/stowers/zsh/dot-zshrc.d/00-setup.sh similarity index 100% rename from zsh/dot-zshrc.d/00-setup.sh rename to stowers/zsh/dot-zshrc.d/00-setup.sh diff --git a/zsh/dot-zshrc.d/01-aliases.sh b/stowers/zsh/dot-zshrc.d/01-aliases.sh similarity index 100% rename from zsh/dot-zshrc.d/01-aliases.sh rename to stowers/zsh/dot-zshrc.d/01-aliases.sh diff --git a/zsh/dot-zshrc.d/10-workspace.sh b/stowers/zsh/dot-zshrc.d/10-workspace.sh similarity index 100% rename from zsh/dot-zshrc.d/10-workspace.sh rename to stowers/zsh/dot-zshrc.d/10-workspace.sh