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
is() { | |
[ "${1}" = "not" ] && shift 1; ! is "${@}"; return "${?}" | |
_condition="${1}"; _var_a="${2}"; _var_b="${3}" | |
case "${_condition}" in | |
(-[bcdefghLnprsStuwxz]) | |
test "${_condition}" "${_var_a}"; return "${?}" | |
;; | |
(command) command -v "${_var_a}"; return "${?}" ;; | |
(file) [ -f "${_var_a}" ]; return "${?}" ;; | |
(dir|directory) [ -d "${_var_a}" ]; return "${?}" ;; |
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
# Get the top level PID and setup a trap so that we can call die() within subshells | |
trap "exit 1" TERM | |
_self_pid="${$}" | |
export _self_pid | |
# Function to print an error message and exit | |
die() { | |
if [ -t 0 ]; then | |
printf '\e[31;1m====>%s\e[0m\n' "${0}:(${LINENO}): ${*}" >&2 | |
else |
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
daikin() { | |
local remote_unit temp_info unit_info unit_mode inside_temperature | |
local outside_temperature target_temperature | |
remote_unit=$(host -4 Client.burnination.net | awk '{print $4}') | |
case "${remote_unit}" in | |
(found:) | |
printf -- '%s\n' "Daikin Aircon Information" \ | |
"=========================" \ | |
"Remote unit not found" >&2 |
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
# Because $SHELL is an unreliable thing to test against, we provide this function | |
# This won't work for 'fish', which needs 'ps -p %self' or similar | |
# non-bourne-esque syntax. | |
# TO-DO: Investigate application of 'export PS_PERSONALITY="posix"' | |
get_shell() { | |
if [ -r "/proc/$$/cmdline" ]; then | |
# We use 'tr' because 'cmdline' files have NUL terminated lines | |
# TO-DO: Possibly handle multi-word output e.g. 'busybox ash' | |
printf -- '%s\n' "$(tr '\0' ' ' </proc/"$$"/cmdline)" | |
elif ps -p "$$" >/dev/null 2>&1; then |
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
get_rc() { | |
"${@}" >/dev/null 2>&1 && return "${?}" | |
} |
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 function prints the terminfo details for 'xterm-256color' | |
# This is for importing this into systems that don't have this | |
print-xterm-256color() { | |
cat <<'NEWTERM' | |
xterm-256color|xterm with 256 colors, | |
am, bce, ccc, km, mc5i, mir, msgr, npc, xenl, | |
colors#256, cols#80, it#8, lines#24, pairs#32767, | |
acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, | |
bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l, | |
clear=\E[H\E[2J, cnorm=\E[?12l\E[?25h, cr=^M, |
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
# shellcheck shell=bash | |
# The MIT License (MIT) | |
# Copyright (c) 2019 -, Rawiri Blundell | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is |
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
#!/bin/bash | |
# Functionalise 'command -v' to allow 'if get_command [command]' idiom | |
get_command() { command -v "${1}" &>/dev/null; } | |
# TO-DO: Update environment to ensure a sane $ARCH variable | |
# This will allow us to make this portable to various arm implementations | |
setup_glow() { | |
# If it's already present, there's nothing to do here | |
if get_command glow; then |
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
# A portability function for older systems that don't have the mapfile builtin | |
if ! command -v mapfile >/dev/null 2>&1; then | |
mapfile() { | |
local _arrName i IFS | |
unset MAPFILE | |
set -f # Turn off globbing | |
set +H # Prevent parsing of '!' via history substitution | |
# We use the behaviour of '-t' by default, so if it's given, skip it |
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
#!/bin/bash | |
# A quick script to automate upgrading the shellcheck binary | |
# Terse assign our default proxy settings if required | |
#: "${http_proxy:=http://proxy.company.org:3128}" | |
#: "${https_proxy:=$http_proxy}" | |
trap "rm -rf /tmp/shellcheck-latest*" EXIT |