diff --git a/lib/helper/mk_link b/lib/helper/mk_link new file mode 100755 index 0000000..50a3197 --- /dev/null +++ b/lib/helper/mk_link @@ -0,0 +1,14 @@ +#! env zsh +REPORT=`dirname $0`/report + +if [ -z "$1" ] || [ -z "$2" ] ; then + $REPORT error "ERROR: Both to and from string must be defined.\n source: $1 \n symlnk: $2" + exit +fi + +if [[ -e $2 ]] ; then + $REPORT warn "$2 already exist. Skipping." + exit +fi + +$REPORT info "Symlinked `ln -svf $1 $2`" diff --git a/lib/helper/report b/lib/helper/report new file mode 100755 index 0000000..75794b8 --- /dev/null +++ b/lib/helper/report @@ -0,0 +1,23 @@ +#! env zsh +R='\033[0;31m' +Y='\033[0;33m' +G='\033[0;32m' +NC='\033[0m' # No Color + +format(){ + case $1 in + "error") echo -e "$R x $2$NC";; + "warn") echo -e "$Y ⚠ $2$NC";; + "info") echo -e "$G ✔ $2$NC";; + *) echo -e "$1: $2";; + esac +} + +if [[ -z $2 ]] ; then + case "$LAST_RETURN" in + 0) format info $1;; + *) format error "FAILURE DURING: \"$1\"";; + esac +else + format $1 $2 +fi diff --git a/lib/helper/rm_link b/lib/helper/rm_link new file mode 100755 index 0000000..fa951d4 --- /dev/null +++ b/lib/helper/rm_link @@ -0,0 +1,20 @@ +#! env zsh +REPORT=`dirname $0`/report + +if [[ -z $1 ]] ; then + $REPORT error "ERROR: Symlink to delete does not exist.\n symlink: $1" + exit +fi + +if ! ( [[ -e $1 ]] || [[ -L $1 ]] ) ; then + $REPORT warn "$1 does not exist." + exit +fi + +if [[ ! -L $1 ]] ; then + $REPORT warn "$1 is not a symbolic link. Skipping." + exit +fi + +$REPORT info "Deleting $1" +rm $1 diff --git a/lib/shared.mk b/lib/shared.mk new file mode 100644 index 0000000..ebde197 --- /dev/null +++ b/lib/shared.mk @@ -0,0 +1,32 @@ +# This will make heavy use of the "$+commands[cmd]" function in bash. Make sure its installed. +_SHELL := $(shell which zsh ) +ifndef _SHELL + $(error ZSH is not installed on this machine. This makefile requires ZSH features) +endif +SHELL := $(_SHELL) + + +# Helper scripts for setting up and taking down links. +LIB_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) +mk_link := $(LIB_DIR)/helper/mk_link +rm_link := $(LIB_DIR)/helper/rm_link +report := LAST_RETURN=$$? $(LIB_DIR)/helper/report +cmd_exist = $(shell (($$+commands[$1])) && echo true || echo false ) + +# Shortcut for the XDG dir if it exist. default to ~/.confg +XDG_DIR := $${XDG_CONFIG_DIR:-~/.config} + +# Some things will OS specific. +# With this you can use `$(IS_MAC) && echo "I'm a Mac" || echo "I'm not a Mac"` +ifeq ($(shell uname), Darwin) + IS_MAC=true +else + IS_LINUX=true +endif +IS_MAC?=false +IS_LINUX?=false + +# TURN THIS OFF FOR DEBUGGING +MAKEFLAGS += --silent + +.PHONY: install update init remove