From b12ca7147f34726a5849736a35864956fe09b574 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 10 May 2020 18:56:02 -0500 Subject: Update to v. 0.2 --- licenser | 287 +++++++++++++++++++++++++++++---------------------------------- 1 file changed, 131 insertions(+), 156 deletions(-) diff --git a/licenser b/licenser index 9e921e1..7d710d3 100755 --- a/licenser +++ b/licenser @@ -1,28 +1,77 @@ -#!/usr/bin/env bash -# licenser: do a license +#!/bin/sh +# licenser: drop a little ol license in there +# Author: Case Duckworth +# License: MIT +# Version: 0.2 + +# Constants +## where to download licenses from +PRGN="${0##*/}" +LICENSER_SOURCE="https://git.sr.ht/~acdw/licenser-licenses/blob/master" +LICENSER_CACHE="${XDG_DATA_HOME:-$HOME/.local/share}/licenser" +LICENSER_LICENSE="${LICENSER_LICENSE:-MIT}" +EXEC="${EXEC:-true}" -# defaults -__DEFAULT_LICENSE=MIT -: "${LICENSER_LICENSE:=$__DEFAULT_LICENSE}" +usage() { + cat </dev/null 2>&1; then - echo "Unknown license: $__LICENSE" - echo "Available licenses:" + if ! __CACHED=$(get_license "$__LICENSE"); then list_licenses exit 2 fi - if [[ -e "$__OUTPUT" && ! $_force ]]; then - echo "File exists: $__OUTPUT" + if [ -e "$__OUT" ] && ! $_force; then + log "File exists: $__OUT" exit 3 fi - "licenser_$__LICENSE" >"$__OUTPUT" -} + eval "$( + put "cat<<_END_LICENSE_" + cat "$__CACHED" + put + put "_END_LICENSE_" + )" > "$__OUT" -list_licenses() { - declare -F | awk '/licenser_/{sub(/licenser_/,"",$NF); print $NF;}' + log "$__LICENSE written to $__OUT." } -usage() { - cat < - - Everyone is permitted to copy and distribute verbatim or modified - copies of this license document, and changing it is allowed as long - as the name is changed. - - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. You just DO WHAT THE FUCK YOU WANT TO. -END -} +# helpers +put() { printf '%s\n' "$*"; } +log() { $_quiet || put "$PRGN: $*" >&2; } -# enable sourcing or executing -if [[ ${BASH_SOURCE[0]} == "$0" ]]; then - licenser "$@" -fi +# run +$EXEC && licenser "$@" -- cgit 1.4.1-21-gabe81