Create library for modules written as ZSH scripts
This commit is contained in:
19
install.sh
19
install.sh
@@ -1,20 +1,6 @@
|
|||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
# vi: set expandtab ft=zsh tw=80 ts=2
|
# vi: set expandtab ft=zsh tw=80 ts=2
|
||||||
|
|
||||||
function autoloadZShLib() {
|
|
||||||
export ASTZWEIG_ZSHLIB=${_DIR}/zshlib
|
|
||||||
FPATH="${ASTZWEIG_ZSHLIB}:${FPATH}"
|
|
||||||
local funcNames=(${(f)"$(find "${ASTZWEIG_ZSHLIB}" -type f -perm +u=x -maxdepth 1 | awk -F/ '{ print $NF }')"})
|
|
||||||
autoload -Uz ${funcNames}
|
|
||||||
}
|
|
||||||
|
|
||||||
function configureLogging() {
|
|
||||||
local output=tostdout level=info
|
|
||||||
[ -n "${logfile}" ] && output=${logfile}
|
|
||||||
[ "${verbose}" = true ] && level=debug
|
|
||||||
lop setoutput -l ${level} ${output}
|
|
||||||
}
|
|
||||||
|
|
||||||
function filterModules() {
|
function filterModules() {
|
||||||
if [ ${#module} -eq 0 ]; then
|
if [ ${#module} -eq 0 ]; then
|
||||||
lop debug 'No modules given as arguments. Taking all modules.'
|
lop debug 'No modules given as arguments. Taking all modules.'
|
||||||
@@ -252,7 +238,7 @@ function checkPrerequisites() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
autoloadZShLib
|
autoloadZShLib || return
|
||||||
checkPrerequisites || return
|
checkPrerequisites || return
|
||||||
eval "`docopts -f -V - -h - : "$@" <<- USAGE
|
eval "`docopts -f -V - -h - : "$@" <<- USAGE
|
||||||
Usage: $0 [options] [-m PATH]... [<module>...]
|
Usage: $0 [options] [-m PATH]... [<module>...]
|
||||||
@@ -291,5 +277,8 @@ function main() {
|
|||||||
|
|
||||||
if [[ "${ZSH_EVAL_CONTEXT}" == toplevel ]]; then
|
if [[ "${ZSH_EVAL_CONTEXT}" == toplevel ]]; then
|
||||||
_DIR="${0:A:h}"
|
_DIR="${0:A:h}"
|
||||||
|
export ASTZWEIG_MACOS_SYSTEM_LIB=${_DIR}/modules/lib.sh
|
||||||
|
export ASTZWEIG_ZSHLIB=${_DIR}/zshlib
|
||||||
|
source "${ASTZWEIG_MACOS_SYSTEM_LIB}"
|
||||||
main "$@"
|
main "$@"
|
||||||
fi
|
fi
|
||||||
|
|||||||
27
modules/lib.sh
Normal file
27
modules/lib.sh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
function autoloadZShLib() {
|
||||||
|
test -d "${ASTZWEIG_ZSHLIB}" || { echo "This module needs astzweig/zshlib to work." >&2; return 99 }
|
||||||
|
FPATH="${ASTZWEIG_ZSHLIB}:${FPATH}"
|
||||||
|
local funcNames=(${(f)"$(find "${ASTZWEIG_ZSHLIB}" -type f -perm +u=x -maxdepth 1 | awk -F/ '{ print $NF }')"})
|
||||||
|
autoload -Uz "${funcNames[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function configureLogging() {
|
||||||
|
local output=tostdout level=info
|
||||||
|
[ -n "${logfile}" ] && output=${logfile}
|
||||||
|
[ "${verbose}" = true ] && level=debug
|
||||||
|
lop setoutput -l ${level} ${output}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkCommands() {
|
||||||
|
local cmd
|
||||||
|
for cmd in ${(k)cmds}; do
|
||||||
|
if ! which "${cmd}" >&! /dev/null; then
|
||||||
|
local comment=''
|
||||||
|
[ -n "${cmds[$cmd]}" ] && comment=" ${cmds[$cmd]}"
|
||||||
|
lop error "This module needs ${cmd}${comment} to work."
|
||||||
|
return 11
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
Describe 'configureLogging'
|
Describe 'configureLogging'
|
||||||
Include ./install.sh
|
Include ./modules/lib.sh
|
||||||
args=()
|
args=()
|
||||||
lop() { args=("$@") }
|
lop() { args=("$@") }
|
||||||
setup() { args=() }
|
setup() { args=() }
|
||||||
|
|||||||
Reference in New Issue
Block a user