diff options
author | EuAndreh <eu@euandre.org> | 2022-05-12 12:01:54 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2022-05-12 12:01:54 -0300 |
commit | 90eaebabcaaea74237f34cf05709625345f276cc (patch) | |
tree | 349e7609d20ecfb6567652a7e28595cec9647eb0 /bin/pre | |
parent | .usr/etc/i3/config: WIP setup extra bindings (diff) | |
download | dotfiles-90eaebabcaaea74237f34cf05709625345f276cc.tar.gz dotfiles-90eaebabcaaea74237f34cf05709625345f276cc.tar.xz |
Move Git repository into ~/.usr/.git/
Diffstat (limited to 'bin/pre')
-rwxr-xr-x | bin/pre | 72 |
1 files changed, 72 insertions, 0 deletions
@@ -0,0 +1,72 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + pre [-c COLOR] PREFIX + pre -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -c COLOR ANSI color to be used on the prefix text + -h, --help show this message + EOF +} + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +COLOR='' +while getopts 'c:h' flag; do + case "$flag" in + c) + COLOR="$OPTARG" + ;; + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +assert_arg() { + if [ -z "$1" ]; then + printf 'Missing %s\n\n' "$2" >&2 + usage >&2 + exit 2 + fi +} + +PREFIX="${1:-}" +assert_arg "$PREFIX" 'PREFIX' + +while read -r line; do + if [ -z "$COLOR" ]; then + printf '%s: %s\n' "$PREFIX" "$line" + else + printf '%s: %s\n' "$(color -c "$COLOR" "$PREFIX")" "$line" + fi +done |