2022-02-03
This commit is contained in:
parent
f86b8496ec
commit
db393215ce
55 changed files with 1907 additions and 0 deletions
31
home/dot-local/lib/bash/common.sh
Normal file
31
home/dot-local/lib/bash/common.sh
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# -*- mode: bash -*-
|
||||
|
||||
function abort() {
|
||||
local status="${1:?"abort requires status"}"
|
||||
local reason="${2:?"abort requires reason"}"
|
||||
shift 2
|
||||
# here we want the string as template
|
||||
# shellcheck disable=SC2059
|
||||
printf "error: ${reason}\n" "$@" >&2
|
||||
exit "${status}"
|
||||
}
|
||||
|
||||
function has_software() {
|
||||
for software in "$@"; do
|
||||
type "${software}" >/dev/null 2>&1 ||
|
||||
abort 1 $"%s not found in path\n" "${software}"
|
||||
done
|
||||
}
|
||||
|
||||
function import() {
|
||||
local name path file
|
||||
for name in "$@"; do
|
||||
local IFS=:; set -o noglob
|
||||
for path in ${IMPORTPATH}; do
|
||||
file="${path}/${name}"
|
||||
[[ -e "${file}" && -r "${file}" ]] && {
|
||||
source "${file}" && continue 2 || return 1
|
||||
}
|
||||
done
|
||||
done
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue