diff --git a/.gitignore b/.gitignore index b19f637..9187d5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,9 @@ +dist + README.html +pub.css + +crud *.swp *.swo diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5dc707f --- /dev/null +++ b/Makefile @@ -0,0 +1,60 @@ +PREFIX ?= /usr/local +INSTALL ?= install + +HELPERS := $(wildcard *.bash) +DIST_HELPERS := $(foreach HELPER,$(HELPERS),dist/lib/bash-util/$(HELPER)) +DIST_HELPER_LINKS := $(foreach HELPER,$(HELPERS),dist/bin/$(HELPER)) + +SCRIPTS := $(shell for fsname in $(wildcard scripts/*); \ + do [ ! -d $$fsname ] && echo $$fsname || :; done) +DIST_SCRIPTS := $(foreach SCRIPT,$(SCRIPTS),dist/bin/$(shell basename $(SCRIPT))) + +dist: dist/bin dist/lib/bash-util $(DIST_HELPERS) $(DIST_HELPER_LINKS) $(DIST_SCRIPTS) + +dist/bin: + mkdir -pv $@ + +dist/bin/%.bash: %.bash + ln -s ../lib/bash-util/$*.bash $@ + +dist/bin/%: scripts/% dist/bin + sed 's/^\(.\s\+\)\("\)*.\+\/util\//\1\2$(shell \ + sed 's/\([$\/]\)/\\\1/g' <<<$(PREFIX))\/lib\/bash-util\//' < $< > $@ + chmod 755 $@ + +dist/lib/bash-util: + mkdir -pv $@ + +dist/lib/bash-util/%.bash: %.bash + cp $< $@ + chmod 644 $@ + +install: dist + cd dist && \ + for each in *; \ + do cp -rv "$$each" "$(PREFIX)/$$each"; \ + done + +clean: + rm -rf dist + +.PHONY: dist install + +### README ##################################################################### + +UNAME := $(shell uname) +ifeq ($(UNAME),Linux) + OPEN=xdg-open +else ifeq ($(UNAME),Darwin) + OPEN=open +endif + +pub.css: + wget https://github.com/manuelp/pandoc-stylesheet/raw/acac36b976966f76544176161ba826d519b6f40c/pub.css + +# Requires Pandoc to be installed +README.html: README.md pub.css + pandoc $< -s -c pub.css -o README.html + $(OPEN) README.html + +README: README.html diff --git a/README.md b/README.md index b256c4a..6d7525a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,57 @@ # Bash Helpers + Arcane incantations that we're tired of remembering how to do in Bash will end up here. Include me as a submodule in whenever you're writing shell scripts. Patches welcome! + +### Installing + +Simply install with `make`! +``` +# make install +``` + +If you'd like to install it to a different `PREFIX` simply specify one on the +`make` command-line (or in your environment): +``` +$ PREFIX="$HOME/.local" make install +``` + +### Using in your scripts! + +You can use the bash helpers in two ways: + + 1. As a Git submodule + 2. From Bash's `$PATH` environment variable. + +#### As a Git submodule + +``` +$ git submodule add https://github.com/targetdisk/bash-util.git +``` + +From your scripts you can now source the .bash files relative to the `bash-util` +directory in your tree. + + +#### From Bash's PATH + +If you followed along with the **Installing** section you should have installed +the helpers somewhere in your environment's `$PATH`. If so, you should now be +able to write scripts like: + +```bash +#!/usr/bin/env bash + +. logging.bash + +die "I am dead now!" + +echo "I never execute!" +``` + +Or even run this in your Bash shell: +``` +$ . env.bash && add_path "$HOME/.local/bin" +```