Skip to content

Commit

Permalink
Speed up sourcing in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kigster committed Mar 8, 2022
1 parent 5a183a1 commit d54d265
Show file tree
Hide file tree
Showing 76 changed files with 92 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"compile-hero.disable-compile-files-on-did-save-code": true,
"shellcheck.enableQuickFix": true,
"workbench.colorTheme": "Overnight",
"workbench.colorTheme": "Kimbie Dark",
"window.zoomLevel": 0,
"customPresentationMode.backup": {},
"gruvboxMaterial.jsson1Comments": false,
Expand Down
2 changes: 1 addition & 1 deletion bin/bashmatic-install
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
set -e

# Configuration
# Configuration
export HOME=${HOME:-"/"}
declare -a CHOWN_DIRS
declare -a BREW_PACKAGES
Expand Down
34 changes: 18 additions & 16 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#/usr/bin/env bash
# vim: ft=bash
# file: lib/init.bash
#
Expand All @@ -20,7 +20,6 @@
# https://github.com/kigster/bashmatic#4-installing-bashmatic

set +ex

export SCRIPT_SOURCE="$(cd "$(/usr/bin/dirname "${BASH_SOURCE[0]:-"${(%):-%x}"}")" || exit 1; pwd -P)"

export PATH="${PATH}:/usr/local/bin:/usr/bin:/bin:/sbin"
Expand Down Expand Up @@ -169,16 +168,18 @@ function bashmatic.init-core() {
printf "${BASHMATIC_PREFIX} evaluating all shell files under ${bldylw}${BASHMATIC_HOME}/lib...${clr}\n"
}

for f in $(find "${BASHMATIC_HOME}/lib" -name '[a-z]*.sh' -type f -print); do
((BASHMATIC_DEBUG)) && {
printf "${BASHMATIC_PREFIX} loading ${bldylw}%-50s${clr}\n" "$f"
}
source $f
done

for f in $(find "${BASHMATIC_HOME}/lib" -name '[a-z]*.sh' -type f -print); do
source $f
done
# for f in $(find "${BASHMATIC_HOME}/lib" -name '[a-z]*.sh' -type f -print); do
# ((BASHMATIC_DEBUG)) && {
# printf "${BASHMATIC_PREFIX} loading ${bldylw}%-50s${clr}\n" "$f"
# }
# source $f
# done
#
# for f in $(find "${BASHMATIC_HOME}/lib" -name '[a-z]*.sh' -type f -print); do
# source $f
# done

eval "$(/bin/cat "${BASHMATIC_HOME}"/lib/*.sh)"

# shellcheck disable=SC2155
[[ ${PATH} =~ ${BASHMATIC_HOME}/bin ]] || export PATH=${PATH}:${BASHMATIC_HOME}/bin
Expand All @@ -204,7 +205,7 @@ function .bashmatic.init.darwin() {

if [[ ${some_missing} -gt 0 ]]; then
set +e
source "${BASHMATIC_HOME}/bin/bashmatic-install"
source "${BASHMATIC_HOME}/bin/bashmatic-install" >/dev/null
fi

# shellcheck disable=SC2155
Expand All @@ -231,8 +232,10 @@ function .bashmatic.init.darwin() {

if [[ ${some_missing} -gt 0 ]]; then
set +e
source "${BASHMATIC_HOME}/bin/bashmatic-install"
darwin-requirements
# eval "$(curl -fsSL https://bashmatic.re1.re)" >/dev/null
source "${BASHMATIC_HOME}/bin/bashmatic-install" >/dev/null
local func=".install.darwin-requirements"
[[ -z $(type -f ${func}) ]] || eval "${func}"
fi
}

Expand Down Expand Up @@ -315,4 +318,3 @@ function bashmatic.init() {
}

bashmatic.init "$@"

Empty file removed lib/.vscode/notes.txt
Empty file.
1 change: 1 addition & 0 deletions lib/7z.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@
}

7z.x() { 7z.unzip "$@"; }

1 change: 1 addition & 0 deletions lib/array.sh
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,4 @@ array.eval.in-groups-of() {

return 0
}

1 change: 1 addition & 0 deletions lib/asciidoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ function asciidoc.rouge-themes() {
info "${bldlyw}:source-highlighter: ${bldgrn}rouge"
info "${bldlyw}:rouge-style: ${bldgrn}monokai"
}

1 change: 1 addition & 0 deletions lib/audio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,4 @@ audio.dir.rename-karaoke-wavs() {
audio.dir.rename-wavs karaoke "$@"
}


1 change: 1 addition & 0 deletions lib/aws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ aws.ec2() {
;;
esac
}

1 change: 1 addition & 0 deletions lib/bashit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,4 @@ function bashit-refresh() {
bashit-activate "$@"
}


1 change: 1 addition & 0 deletions lib/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,4 @@ function brew.service.restart() {
local svc="$1"
run "brew services restart ${svc}"
}

1 change: 1 addition & 0 deletions lib/caller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ caller.stack() {
stack.frame() {
caller.stack 0
}

1 change: 1 addition & 0 deletions lib/color.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,4 @@ function color.disable() {
}

[[ ${BashMatic__ColorLoaded} -eq 1 ]] || color.enable

1 change: 1 addition & 0 deletions lib/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ function config.dig.pretty() {
config.set-format "${format}"
return 0
}

1 change: 1 addition & 0 deletions lib/db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -583,3 +583,4 @@ db.actions.db-settings-pretty() {
db.actions.db-settings-toml() {
db.psql.connect.db-settings-toml "$@"
}

1 change: 1 addition & 0 deletions lib/db_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,4 @@ db.cli-setup() {
}



1 change: 1 addition & 0 deletions lib/db_rails.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ db.rails.schema.checksum() {
[[ -s ${schema} ]] && shasum.sha-only "${schema}"
fi
}

1 change: 1 addition & 0 deletions lib/db_top.sh
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,4 @@ db.top() {
done
return ${code}
}

1 change: 1 addition & 0 deletions lib/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ deploy.slack-ding() {
}

################################################################################

1 change: 1 addition & 0 deletions lib/dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ dir.rsync-to() {

rsync -avht "${from}" "${to}"
}

1 change: 1 addition & 0 deletions lib/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,4 @@ docker.images.inspect() {
local name=${1:-"<none>"}
docker.images-named "${name}" "docker.image.inspect"
}

1 change: 1 addition & 0 deletions lib/dropbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ function dropbox.unignore() {
;;
esac
}

1 change: 1 addition & 0 deletions lib/file-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ export bashmatic__temp_file_pattern=".bashmatic.${bashmatic__hostname}.${USER}."
done
return 0
}

1 change: 1 addition & 0 deletions lib/file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,4 @@ dir.find() {
ls.mb(){
du -k | grep -v '\''./.*\/'\' | sort -n | awk '{ printf("%20.1fMb %s\n", $1/1024, $2 )}' | tail -10
}

2 changes: 1 addition & 1 deletion lib/flatten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ function flatten-file() {
local command="cp -v \"${path}\" ${bldylw}\"${target}\""
printf -- "${command}"
return 0
}
}
1 change: 1 addition & 0 deletions lib/ftrace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ ftrace-out() {
export __LibTrace__StackLevel=$(( ${__LibTrace__StackLevel} - 1 ))
}


1 change: 1 addition & 0 deletions lib/gem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,4 @@ g-i() {
g-u() {
gem.uninstall "$@"
}

1 change: 1 addition & 0 deletions lib/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,4 @@ function git.generate-changelog() {
}



1 change: 1 addition & 0 deletions lib/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ github.validate() {
github.clone() {
test -n "$1" && github.validate && run "git clone [email protected]:$(github.org)/$1"
}

1 change: 1 addition & 0 deletions lib/gpg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ function gpgit.install() {
sudo make -C "gpgit-${VERSION}" PREFIX=/usr/local install
gpgit --helpp
}

1 change: 1 addition & 0 deletions lib/is.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,4 @@ function whenever() {
function unless() {
! __is.validation.error "${2}" "${1}" __is.validation.ignore-error "${@:3}"
}

1 change: 1 addition & 0 deletions lib/jemalloc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ jm.check() {

jm.jemalloc.detect-loud
}

1 change: 1 addition & 0 deletions lib/json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ json.end-hash() {
[[ "$1" == "true" ]] && printf ","
echo
}

1 change: 1 addition & 0 deletions lib/maths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ maths.eval() {
rm -f "${temp_file}"
return 0
}

1 change: 1 addition & 0 deletions lib/net.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ function net.is-host-port-protocol-open() {
${command} -Pn -p ${port} ${host} 2>&1 | ascii-pipe | grep -q -E "${port}/${protocol} open "
}


1 change: 1 addition & 0 deletions lib/nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ is.an-existing-file .nvmrc && {
nvm.activate
fi
}

1 change: 1 addition & 0 deletions lib/openssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ function openssl.certs.generate-csr() {
return 0
}


1 change: 1 addition & 0 deletions lib/osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,4 @@ ssh.servers() { osx.local-servers ssh; }
afp.servers() { osx.local-servers afp; }
http.servers() { osx.local-servers http; }
https.servers() { osx.local-servers https; }

1 change: 1 addition & 0 deletions lib/output-boxes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,4 @@ h4.red() { h4bg "${@}"; }
hdr() {
h1 "$@"
}

1 change: 1 addition & 0 deletions lib/output-repeat-char.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ export LibOutput__RepeatCharImplementation="product"
local width="${2}"
printf "%s%d" "${width}" "$(text.ord "${char}")"
}

1 change: 1 addition & 0 deletions lib/output-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ function dbgf() {
return ${code}
}


1 change: 1 addition & 0 deletions lib/output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,4 @@ ui.closer.kind-of-ok:() {
ui.closer.kind-of-ok $@
echo
}

1 change: 1 addition & 0 deletions lib/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ function package.ensure.commmand-available() {
error "After installing package ${package}, binary ${binary} still is not found."
}


1 change: 1 addition & 0 deletions lib/path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,4 @@ function path.absolute() {
return 127
fi
}

1 change: 1 addition & 0 deletions lib/pdf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ function pdf.combine() {

return ${LibRun__LastExitCode}
}

1 change: 1 addition & 0 deletions lib/pg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ pg.server-in-path.version() {
is.command postgres || return 1
$(which postgres) -V | sed -E 's/[^0-9.]//g;s/\..*$//g'
}

1 change: 1 addition & 0 deletions lib/pids.sh
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,4 @@ pstop() {
pall() {
pids.all "$@"
}

1 change: 1 addition & 0 deletions lib/pipe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ pipe.remove-hash-comments() {
pipe.remove-blank-lines() {
sedx '/^$/D'
}

1 change: 1 addition & 0 deletions lib/progress-bar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,4 @@ progress.bar.configure.symbol-bar() {
progress.bar.config BarChar=""
}


1 change: 1 addition & 0 deletions lib/repositories.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ repos.init-interrupt() {
repos.was-interrupted() {
[[ ${LibRepo__Interrupted} == true ]]
}

1 change: 1 addition & 0 deletions lib/ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,4 @@ alias b="bundle exec"
alias brake="rbenv exec bundl exec rake"
alias bcap="rbenv exec bundle exec cap"
##——————————————————————————————————————————————————————————————————————————————————

1 change: 1 addition & 0 deletions lib/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@ run.ui.ask() {
eval "${func} 1"
fi
}

1 change: 1 addition & 0 deletions lib/runtime-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,4 @@ ____run.list-options() {
#eval ${func} | tr '\n' ',' | sedx 's/,$//g' | sedx "s/,/\\n${prefix}${bldpur}/g"
echo
}

1 change: 1 addition & 0 deletions lib/runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,4 @@ run.on-error.ask-is-enabled() {
run.was-successful() {
[[ ${LibRun__LastExitCode} -eq 0 ]]
}

1 change: 1 addition & 0 deletions lib/sedx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ function sedx() {
${bashmatic__sed_command} -E "$@"
}


1 change: 1 addition & 0 deletions lib/serial.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ function serial.console {
echo "No USB modem device found in /dev"
fi
}

1 change: 1 addition & 0 deletions lib/set.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ set-e-restore() {
set -o errexit ${status}
rm -f ${__bash_set_errexit_status} 2>/dev/null
}

1 change: 1 addition & 0 deletions lib/settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ declare -a AppBrewPackages=(

export AppBrewPackages
export AppDefaultBackupDir='tmp/pgdump'

1 change: 1 addition & 0 deletions lib/shasum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ function sha() {
fi
}


1 change: 1 addition & 0 deletions lib/shdoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ function gawk.install() {
local gawk_path="$(command -v gawk 2>/dev/null)"
[[ -n "${gawk_path}" && -x "${gawk_path}" ]] || brew.install.package gawk
}

1 change: 1 addition & 0 deletions lib/shell-set.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ save-set-x() { shell-set.push-stack x; }
save-restore-x() { shell-set.pop-stack x; }

[[ -z "${SetOptsStack[*]}" ]] && shell-set.init-stack

1 change: 1 addition & 0 deletions lib/ssh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ function ssh.keys.generate() {
run "ssh-keygen -t rsa -b 4096 -C ${email}"
}


1 change: 1 addition & 0 deletions lib/subshell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ function bashmatic.run-if-subshell() {
return 1
fi
}

1 change: 1 addition & 0 deletions lib/sym.sh
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,4 @@ decrypt.secrets() {
exit ${code}
}
}

2 changes: 1 addition & 1 deletion lib/text.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ text.ord() {
text.chr() {
[ "$1" -lt 256 ] || return 1
printf "\\$(printf '%03o' "$1")"
}
}
Loading

0 comments on commit d54d265

Please sign in to comment.