-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lower complexity of code (hopefully).
Has fewer levels of indirection. Functions are used pretty much only when reuse is a factor, unless it makes good sense to package a piece of functionality as a unit. Uses file descriptors and a logging system. More sensible command line options. TODOs added for what's left. Various renames to lower redundancy.
- Loading branch information
1 parent
fb2a26b
commit c3bb0fc
Showing
18 changed files
with
274 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
git-tmp/* | ||
*.swp | ||
TODO.md | ||
*.log | ||
runcoms/bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,53 @@ | ||
#!/bin/bash | ||
#!/bin/bash -e | ||
|
||
# | ||
# Basic logging | ||
# | ||
timestamp() { | ||
echo "[$(date +"%y-%m-%d %T")]" | ||
} | ||
|
||
log () { | ||
local -r term_width="$(tput cols)" | ||
printf "%s %s\n" "$(timestamp)" "${@}" | fold -sw "${term_width}" | ||
} | ||
# Set colors for STDOUT | ||
if [ -t 1 ]; then | ||
declare -r TTY_STDOUT='true' | ||
else | ||
declare -r TTY_STDOUT='false' | ||
fi | ||
|
||
log_stderr() { | ||
1>&2 log "$@" | ||
} | ||
readonly GRN="$([ "$TTY_STDOUT" = 'true' ] && tput setaf 2)" | ||
readonly CLR="$([ "$TTY_STDOUT" = 'true' ] && tput sgr0)" | ||
|
||
# | ||
# Script verbosity management | ||
# | ||
# Set colors for STDERR | ||
if [ -t 2 ]; then | ||
declare -r TTY_STDERR='true' | ||
else | ||
declare -r TTY_STDERR='false' | ||
fi | ||
|
||
run_cmd_with_verbosity() { | ||
local -r volume_limit="${1}" | ||
if [ "${VERBOSITY:-0}" -ge "${volume_limit}" ]; then | ||
eval "${@:2}" | ||
else | ||
>/dev/null eval "${@:2}" | ||
fi | ||
} | ||
readonly ERR_RED="$([ "$TTY_STDERR" = 'true' ] && tput setaf 1)" | ||
readonly ERR_YLW="$([ "$TTY_STDERR" = 'true' ] && tput setaf 3)" | ||
readonly ERR_CLR="$([ "$TTY_STDERR" = 'true' ] && tput sgr0)" | ||
|
||
run_quiet() { | ||
run_cmd_with_verbosity '1' "${@}" | ||
} | ||
|
||
run_very_quiet() { | ||
run_cmd_with_verbosity '2' "${@}" | ||
} | ||
|
||
log_quiet() { | ||
run_cmd_with_verbosity '1' "echo '${*}'" | ||
} | ||
|
||
log_very_quiet() { | ||
run_cmd_with_verbosity '2' "echo '${*}'" | ||
timestamp() { | ||
printf "[%s]" "$(date +"%y-%m-%d %T")" | ||
} | ||
|
||
# | ||
# Write colored log messages | ||
# | ||
|
||
color_reset() { | ||
tput sgr0 | ||
log () { | ||
>&3 printf "%-5s%s\n" 'LOG' "$(timestamp) ${*}" | fold -sw "$(tput cols)" | ||
} | ||
|
||
log_info() { | ||
local -r color="$(tput setaf 2)" | ||
printf "%s %s\n%s" "$(timestamp)" "${color}${*}" "$(color_reset)" | ||
tput sgr0 | ||
printf "%s%-5s%s\n" "${GRN}" 'INFO' "$(timestamp) ${*}${CLR}" \ | ||
| fold -sw "$(tput cols)" | ||
} | ||
|
||
log_warn() { | ||
local -r color="$(tput setaf 3)" | ||
>&2 printf "%s %s\n%s" "$(timestamp)" "${color}${*}" "$(color_reset)" | ||
>&2 printf "%s%-5s%s\n" "${ERR_YLW}" 'WARN' \ | ||
"$(timestamp) ${*}${ERR_CLR}" | fold -sw "$(tput cols)" | ||
} | ||
|
||
log_error() { | ||
local -r color="$(tput setaf 1)" | ||
>&2 printf "%s %s\n%s" "$(timestamp)" "${color}${*}" "$(color_reset)" | ||
>&2 printf "%s%-5s%s\n" "${ERR_RED}" 'ERR' \ | ||
"$(timestamp) ${*}${ERR_CLR}" | fold -sw "$(tput cols)" | ||
} | ||
|
||
quiet_popd() { | ||
popd >/dev/null | ||
} | ||
|
||
quiet_pushd() { | ||
pushd "${*}" >/dev/null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.