midipix / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone
Blob Blame History Raw
#
# set -o errexit -o noglob are assumed.
#

EXP_IFS_NL="
";

ex_basename() { echo "${1##*/}"; };
ex_date() { command date "+${1:-${TIMESTAMP_FMT}}"; };
ex_dirname() { echo "${1%/*}"; };
ex_get_var_unsafe() { eval echo \${${1}}; };
ex_set_var_unsafe() { [ -n "${2}" ] && eval ${1}=\"${2}\" || return 0; };
ex_pop_IFS() { IFS="${EXP_OLDIFS}"; };
ex_push_IFS() { EXP_OLDIFS="${IFS}"; IFS="${1}"; };
ex_push_IFS_nl() { ex_push_IFS "${EXP_IFS_NL}"; };
ex_test_cmd() { command -v "${1}" >/dev/null; };
ex_toupper() { echo "${1}" | tr a-z A-Z; };

ex_lfilter() {
	local _list="${1}" _filter="${2}" _lnew _litem _litem_filter;
	if [ -z "${_filter}" ]; then
		echo "${_list}"; return 0;
	else for _litem in ${_list}; do
		for _litem_filter in ${_filter}; do
			if [ "${_litem_filter}" = "${_litem}" ]; then
				_lnew="${_lnew:+${_lnew} }${_litem}";
				break;
			fi;
		done;
	done; fi;
	echo "${_lnew}";
};

ex_lfilter_not() {
	local _list="${1}" _filter="${2}" _lnew _litem _litem_filter _filterfl;
	if [ -z "${_filter}" ]; then
		echo "${_list}"; return 0;
	else for _litem in ${_list}; do
		_filterfl=0;
		for _litem_filter in ${_filter}; do
			if [ "${_litem_filter}" = "${_litem}" ]; then
				_filterfl=1; break;
			fi;
		done;
		if [ "${_filterfl:-0}" -eq 0 ]; then
			_lnew="${_lnew:+${_lnew} }${_litem}";
		fi;
	done; fi;
	echo "${_lnew}";
};

ex_lmatch() {
	local _cmp="${3}" IFS="${2}"; set -- ${1};
	while [ ${#} -gt 0 ]; do
		if [ "${1}" = "${_cmp}" ]; then
			return 0;
		fi; shift;
	done; return 1;
};

ex_run_cmd_unsplit() {
	local _cmd="${1}" _cmdline _rc IFS; shift;
	while [ ${#} -gt 0 ]; do
		[ -n "${1}" ] &&\
			_cmdline="${_cmdline:+${_cmdline}:}${1}";
		shift;
	done;
	IFS=:; ${_cmd} ${_cmdline}; _rc=$?;
	return ${_rc};
};

# vim:filetype=sh