diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..b6610342 --- /dev/null +++ b/Makefile @@ -0,0 +1,72 @@ +.PHONY := all force clean config bin + +LOCAL_BIN := $(HOME)/.local/bin +CONFIG_DIR := $(if $(XDG_CONFIG_HOME), $(XDG_CONFIG_HOME), $(HOME)/.config) +SYSTEMD_DIR := $(CONFIG_DIR)/systemd/user +FONT_DIR := $(HOME)/.local/share/fonts +ZSH_DIR := $(if $(ZSH), $(ZSH), $(HOME)/.oh-my-zsh) +ZSH_CUSTOM_DIR := $(if $(ZSH_CUSTOM), $(ZSH_CUSTOM), $(ZSH)/custom) + +CONFIG_ITEMS := $(wildcard config/*) +CONFIG_TARGETS := $(CONFIG_ITEMS:config/%=$(CONFIG_DIR)/%) +SYSTEMD_ITEMS := $(wildcard systemd/*) +SYSTEMD_TARGETS := $(SYSTEMD_ITEMS:systemd/%=$(SYSTEMD_DIR)/%) +FONT_ITEMS := $(wildcard nerdfont_symbols/*) +FONT_TARGETS := $(FONT_ITEMS:nerdfont_symbols/%=$(FONT_DIR)/%) +BIN_ITEMS := $(wildcard bin/*) +BIN_TARGETS := $(BIN_ITEMS:bin/%=$(LOCAL_BIN)/%) +ZSH_ITEMS := $(wildcard *.zsh) +ZSH_TARGETS := $(ZSH_ITEMS:%.zsh=$(ZSH_CUSTOM_DIR)/custom/%.zsh) + +PACKER_REPO := https://github.com/wbthomason/packer.nvim +PACKER_DIR := $(HOME)/.local/share/nvim/site/pack/packer/start/packer.nvim +POWERLEVEL_REPO := https://github.com/romkatv/powerlevel10k.git +POWERLEVEL_DIR := $(ZSH_CUSTOM_DIR)/themes/powerlevel10k + +all: config + +force: clean all + +clean: + echo "TODO" + +config: $(CONFIG_TARGETS) $(SYSTEMD_TARGETS) $(FONT_TARGETS) + +bin: $(BIN_TARGETS) $(PACKER_DIR) + +$(CONFIG_TARGETS): $(CONFIG_DIR)/%: config/% + ln -s $(PWD)/$? $@ + +$(SYSTEMD_TARGETS): $(SYSTEMD_DIR)/%: systemd/% + ln -s $(PWD)/$? $@ + +$(FONT_TARGETS): $(FONT_DIR)/%: nerdfont_symbols/% + ln -s $(PWD)/$? $@ + +$(BIN_TARGETS): $(LOCAL_BIN)/%: bin/% + command -v $? 2> /dev/null || ln -s $(PWD)$? $@ + +$(HOME)/.ssh/config: $(HOME)/.ssh + cp $@ "$@"~ + cp templates/ssh-config $@ + +$(PACKER_DIR): + git clone --depth 1 $(PACKER_REPO) $@ + +$(ZSH_DIR): + curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | sh - + +$(ZSH_CUSTOM_DIR): $(ZSH_DIR) + +$(POWERLEVEL_DIR): $(ZSH_CUSTOM_DIR) + git clone --depth 1 $(POWERLEVEL_REPO) $@ + +$(ZSH_TARGETS): $(ZSH_CUSTOM_DIR)/%.zsh: %.zsh + ln -s $(PWD)/$? $@ + +$(HOME)/.gitconfig: + grep "editor" $@ > /dev/null || git config --global core.editor "nvim" + grep "pull.rebase" $@ > /dev/null || git config --global pull.rebase false + +$(LOCAL_BIN) $(CONFIG_DIR) $(SYSTEMD_DIR) $(FONT_DIR) $(HOME)/.ssh $(HOME)/.ssh/sockets: + mkdir -p $@ diff --git a/install.sh b/install.sh deleted file mode 100755 index 23657ded..00000000 --- a/install.sh +++ /dev/null @@ -1,83 +0,0 @@ -#! /usr/bin/env sh -# Install various dotfiles into their proper places - -create_symlink () { - FILENAME="$(basename $2)" - if [ ! -e "$1/$FILENAME" ] - then - ln -s $(readlink -f "$2") "$1/$FILENAME" - echo "$(readlink -f $2) -> $1/$FILENAME" - else - echo "$1/$FILENAME already exists" - fi -} - -git_clone_if_missing () { - if [ ! -d "$2" ] - then - git clone --depth 1 "$1" "$2" - else - echo "$1 already checked out: $2" - fi -} - -# .config files -CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}" - -mkdir -p "$CONFIG_DIR" -for FILE in config/* -do - create_symlink "$CONFIG_DIR" "$FILE" -done - -mkdir -p "$CONFIG_DIR/systemd/user" -for FILE in systemd/* -do - create_symlink "$CONFIG_DIR/systemd/user" "$FILE" -done - -# SSH sockets -mkdir -p "$HOME/.ssh/sockets" -[ ! -e "$HOME/.ssh/config" ] && cp templates/ssh-config "$HOME/.ssh/config" - -# nvim setup - install Packer -PACKER_REPO="https://github.com/wbthomason/packer.nvim" -PACKER_DIR="$HOME/.local/share/nvim/site/pack/packer/start/packer.nvim" -git_clone_if_missing "$PACKER_REPO" "$PACKER_DIR" - -# Set up git editor if missing -grep "editor" "$HOME/.gitconfig" > /dev/null || git config --global core.editor "nvim" - -# Add NerdFont symbols -mkdir -p "$HOME/.local/share/fonts" -for FILE in nerdfont_symbols/* -do - create_symlink "$HOME/.local/share/fonts" "$FILE" -done - -# Ensure nvim plugins -mkdir -p "$HOME/.local/bin" -for FILE in bin/* -do - which -a "$(basename $FILE)" > /dev/null || create_symlink "$HOME/.local/bin" "$FILE" -done - -# oh-my-zsh -if [ ! -d "$ZSH" ] -then - sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" -else - echo "oh-my-zsh already installed: $ZSH" -fi -OHMYZSH_DIR="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}" -if [ -d "$OHMYZSH_DIR" ] -then - # Powerlevel10k theme - POWERLEVEL_REPO="https://github.com/romkatv/powerlevel10k.git" - POWERLEVEL_DIR="$OHMYZSH_DIR/themes/powerlevel10k" - git_clone_if_missing "$POWERLEVEL_REPO" "$POWERLEVEL_DIR" - # aliases - create_symlink "$OHMYZSH_DIR" "./aliases.zsh" - create_symlink "$OHMYZSH_DIR" "./completions.zsh" - create_symlink "$OHMYZSH_DIR" "./paths.zsh" -fi