Explorar o código

Add Makefile, rename `setup.sh` to `install`

`make install` now does what `setup.sh` did.
`make` provides help text.

`setup.sh` is renamed to `install` and is a backup installation script
for when `make` is not available (e.g. OpenWRT, NixOS).

Support functions `linkup` and `show-versions` are now moved to their
own scripts.
Weiyi Lou %!s(int64=10) %!d(string=hai) anos
pai
achega
e9803d04a9
Modificáronse 6 ficheiros con 173 adicións e 86 borrados
  1. 84 0
      Makefile
  2. 7 14
      README.md
  3. 14 0
      bin/linkup
  4. 15 0
      bin/show-versions
  5. 53 0
      install
  6. 0 72
      setup.sh

+ 84 - 0
Makefile

@@ -0,0 +1,84 @@
+# vim: set sw=2 ts=2 sts=2 et tw=80 fmr={{{,}}} fdl=0 fdm=marker:
+# dotfiles setup. Run `make install` to perform all setup tasks.
+
+# Groups of targets
+all = git zsh tmux ack vimperator vim
+rm-all = rm-git rm-zsh rm-tmux rm-ack rm-vimperator rm-vim
+
+# Auto-Documenting Section. Displays a target list with `##` descriptions.
+help:
+	@echo "Available tasks:"
+	@grep -E '^[a-zA-Z_-]+:.*## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "%-16s %s\n", $$1, $$2}'
+	@echo ""
+	@echo "Individual setup tasks:"
+	@echo "$(all)"
+.PHONY: help uninstall install $(all) $(rm-all)
+
+install: prep $(all) ## Set up all configurations.
+	@echo "Install complete!"
+
+uninstall: $(rm-all) ## Remove all configurations.
+	@echo "Uninstalled!"
+
+show-versions: ## List versions of installed software.
+	@./bin/show-versions
+
+# Setup Tasks {{{
+
+prep:
+	@mkdir -p ~/.ssh $(XDG_CONFIG_HOME)
+	@touch ~/.ssh/known_hosts
+
+XDG_CONFIG_HOME ?= $(HOME)/.config
+
+submodules:
+	@cd ~/dotfiles && git submodule sync && git submodule update --init
+
+git:
+	git config --global color.ui true
+	git config --global core.editor vim
+	git config --global core.excludesFile ~/dotfiles/git/globalignore
+	git config --global diff.mnemonicPrefix true
+rm-git:
+	git config --global --unset color.ui true
+	git config --global --unset core.editor vim
+	git config --global --unset core.excludesFile ".*/dotfiles/git/globalignore"
+	git config --global --unset diff.mnemonicPrefix true
+
+zsh: submodules
+	./bin/linkup ~/dotfiles/zsh/zshenv ~/.zshenv
+	./bin/linkup ~/dotfiles/zsh/zshrc ~/.zshrc
+rm-zsh:
+	rm ~/.zshenv
+	rm ~/.zshrc
+
+tmux: submodules
+	./bin/linkup ~/dotfiles/tmux/tmux.conf ~/.tmux.conf
+rm-tmux:
+	rm ~/.tmux.conf
+
+ack:
+	./bin/linkup ~/dotfiles/ack/ackrc ~/.ackrc
+rm-ack:
+	rm ~/.ackrc
+
+vimperator:
+	./bin/linkup ~/dotfiles/vimperator ~/.vimperator
+	./bin/linkup ~/dotfiles/vimperator/vimperatorrc ~/.vimperatorrc
+rm-vimperator:
+	rm ~/.vimperator
+	rm ~/.vimperatorrc
+
+vim:
+	./bin/linkup ~/dotfiles/vim ~/.vim
+	./bin/linkup ~/dotfiles/vim/vimrc ~/.vimrc
+	./bin/linkup ~/dotfiles/vim $(XDG_CONFIG_HOME)/nvim
+	./bin/linkup ~/dotfiles/vim/vimrc $(XDG_CONFIG_HOME)/nvim/init.vim
+	@vim -u ~/dotfiles/vim/plugins.vim -N +PlugClean! +PlugUpdate! +quitall!
+rm-vim:
+	rm ~/.vim
+	rm ~/.vimrc
+	rm $(XDG_CONFIG_HOME)/nvim/init.vim
+	rm $(XDG_CONFIG_HOME)/nvim
+
+# }}}

+ 7 - 14
README.md

@@ -4,16 +4,17 @@ Configuration files for:
 
 - Vim (7.4+) or NeoVim
 - Vimperator (3.8+)
-- Tmux
-- Zsh
+- Tmux (1.8+)
+- Zsh (4.3.17+)
 - Other bits and pieces
 
 Heavy preference for `vim`-like bindings.
 
-## Requirements
+## Installation
 
-- `zsh` has been used with 4.3.17+.
-- `vim` can work with 7.3, but best with 7.4.
+Clone to a home folder.
+Run `make install` or `./install`.
+Restart the terminal session.
 
 ## Recommended
 
@@ -34,17 +35,9 @@ Heavy preference for `vim`-like bindings.
 [Pandoc Markdown]: http://pandoc.org/README.html#pandocs-markdown
 [pandoc-citeproc]: https://github.com/jgm/pandoc-citeproc
 
-## Installation
-
-    $ cd ~
-    $ git clone https://code.parsleygardens.net/cinaeco/dotfiles.git
-    $ ~/dotfiles/setup.sh
-
-Make sure the default shell is ZSH. Restart the terminal session after that.
-
 ## Usage
 
-Below is a non-exhaustive list of how this config is used.
+Below is a non-exhaustive list of dotfiles usage.
 
 ### Zsh
 

+ 14 - 0
bin/linkup

@@ -0,0 +1,14 @@
+#!/bin/bash
+set -euo pipefail
+IFS=$'\n\t'
+
+# Create symlink after backing up the target.
+
+usage="Usage: ${0##*/} source_file target_file"
+src=${1:?$usage}
+tgt=${2:?$usage}
+backup=~/.backup
+
+[[ ! -d $backup ]] && mkdir $backup
+[[ -e "$tgt" ]] && mv "$tgt" "$backup/${tgt##*/}-$(date '+%Y-%m-%d-%H%M%S')" || true
+ln -sf "$src" "$tgt"

+ 15 - 0
bin/show-versions

@@ -0,0 +1,15 @@
+#!/bin/bash
+set -euo pipefail
+IFS=$'\n\t'
+
+# Display a list of software versions dotfiles is interested in.
+
+echo "Installed:"
+command -v git >/dev/null && git version || true
+command -v zsh >/dev/null && zsh --version || true
+command -v tmux >/dev/null && tmux -V || true
+command -v vim >/dev/null  && vim --version | head -n 1 || true
+command -v nvim >/dev/null && nvim -v | head -n 1 || true
+command -v ag >/dev/null && ag --version | head -n 1 || true
+command -v pandoc >/dev/null && pandoc -v | head -n 1 || true
+command -v pandoc-citeproc >/dev/null && pandoc-citeproc -V | head -n 1 || true

+ 53 - 0
install

@@ -0,0 +1,53 @@
+#!/bin/bash
+# vim: set sw=2 ts=2 sts=2 et tw=80 fmr={{{,}}} fdl=0 fdm=marker:
+set -euo pipefail
+IFS=$'\n\t'
+
+# dotfiles installer for when `make` is not available.
+
+# Prep tasks
+mkdir -p ~/.ssh ${XDG_CONFIG_HOME:=$HOME/.config}
+touch ~/.ssh/known_hosts
+echo "Preparing."
+
+# Initialise submodules
+(cd ~/dotfiles && git submodule sync && git submodule update --init)
+echo "Submodules done."
+
+# Git config
+git config --global color.ui true
+git config --global core.editor vim
+git config --global core.excludesfile ~/dotfiles/git/globalignore
+git config --global diff.mnemonicPrefix true
+echo "Git config done."
+
+# Zsh
+~/dotfiles/bin/linkup ~/dotfiles/zsh/zshenv ~/.zshenv
+~/dotfiles/bin/linkup ~/dotfiles/zsh/zshrc ~/.zshrc
+echo "Zsh linked."
+
+# Tmux
+~/dotfiles/bin/linkup ~/dotfiles/tmux/tmux.conf ~/.tmux.conf
+echo "Tmux linked."
+
+# Ack
+~/dotfiles/bin/linkup ~/dotfiles/ack/ackrc ~/.ackrc
+echo "Ack linked."
+
+# Vimperator
+~/dotfiles/bin/linkup ~/dotfiles/vimperator ~/.vimperator
+~/dotfiles/bin/linkup ~/dotfiles/vimperator/vimperatorrc ~/.vimperatorrc
+echo "Vimperator linked."
+
+# Vim
+~/dotfiles/bin/linkup ~/dotfiles/vim ~/.vim
+~/dotfiles/bin/linkup ~/dotfiles/vim/vimrc ~/.vimrc
+~/dotfiles/bin/linkup ~/dotfiles/vim $XDG_CONFIG_HOME/nvim
+~/dotfiles/bin/linkup ~/dotfiles/vim/vimrc $XDG_CONFIG_HOME/nvim/init.vim
+echo "Vim linked."
+
+# vim-plug install process. Starts with plugin list and `nocompatible` flag.
+vim -u ~/dotfiles/vim/plugins.vim -N +PlugClean! +PlugUpdate! +quitall!
+echo "Vim plugins done."
+
+echo "Install complete!"

+ 0 - 72
setup.sh

@@ -1,72 +0,0 @@
-#!/bin/bash
-# vim: set sw=2 ts=2 sts=2 et tw=80 fmr={{{,}}} fdl=0 fdm=marker:
-set -euo pipefail
-IFS=$'\n\t'
-
-# Support Functions {{{
-
-# Backup a given file.
-backup() {
-  [[ -e "$1" ]] && mv "$1" "$backup_dir" || true
-}
-
-# Create links after backing up.
-linkup() {
-  backup "$2"; ln -sf "$1" "$2"
-}
-
-# }}}
-
-# Prepare folders
-backup_dir=~/.backup/dotfiles/$(date "+%Y-%m-%d-%H%M%S")
-mkdir -p "$backup_dir" ~/.ssh ${XDG_CONFIG_HOME:=$HOME/.config}
-echo "Prepared folders."
-
-# Make known_hosts file if none
-touch ~/.ssh/known_hosts
-echo "Touched known hosts."
-
-# Git config
-git config --global color.ui true
-git config --global core.editor vim
-git config --global core.excludesfile ~/dotfiles/git/globalignore
-git config --global diff.mnemonicPrefix true
-echo "Git config done."
-
-# Initialise and clone any submodules
-(cd ~/dotfiles && git submodule sync && git submodule update --init)
-echo "Submodules done."
-
-# Zsh
-linkup ~/dotfiles/zsh/zshenv ~/.zshenv
-linkup ~/dotfiles/zsh/zshrc ~/.zshrc
-echo "Zsh linked."
-
-# Vimperator
-linkup ~/dotfiles/vimperator ~/.vimperator
-linkup ~/dotfiles/vimperator/vimperatorrc ~/.vimperatorrc
-echo "Vimperator linked."
-
-# Tmux
-linkup ~/dotfiles/tmux/tmux.conf ~/.tmux.conf
-echo "Tmux linked."
-
-# Ack
-linkup ~/dotfiles/ack/ackrc ~/.ackrc
-echo "Ack linked."
-
-# Vim
-linkup ~/dotfiles/vim ~/.vim
-linkup ~/dotfiles/vim/vimrc ~/.vimrc
-echo "Vim linked."
-
-# NeoVim XDG Config
-linkup ~/dotfiles/vim $XDG_CONFIG_HOME/nvim
-linkup ~/dotfiles/vim/vimrc $XDG_CONFIG_HOME/nvim/init.vim
-echo "NeoVim linked."
-
-# vim-plug install process. Starts with plugin list and `nocompatible` flag.
-vim -u ~/dotfiles/vim/plugins.vim -N +PlugClean! +PlugUpdate! +quitall!
-echo "Vim plugins done."
-
-echo "Setup complete!"