Blame subr/ex_rtl.subr

Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
#
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
# set -o errexit -o noglob are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
#
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 64cbaf
EXP_IFS_NL="
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_basename() { echo "${1##*/}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_date() { command date "+${1:-${TIMESTAMP_FMT}}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_dirname() { echo "${1%/*}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_get_var_unsafe() { eval echo \${${1}}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_set_var_unsafe() { [ -n "${2}" ] && eval ${1}=\"${2}\" || return 0; };
Lucio Andrés Illanes Albornoz (arab, vxp) 64cbaf
ex_pop_IFS() { IFS="${EXP_OLDIFS}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 64cbaf
ex_push_IFS() { EXP_OLDIFS="${IFS}"; IFS="${1}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 64cbaf
ex_push_IFS_nl() { ex_push_IFS "${EXP_IFS_NL}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_test_cmd() { command -v "${1}" >/dev/null; };
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_toupper() { echo "${1}" | tr a-z A-Z; };
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_lfilter() {
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	[ "x${1}" = "x-not" ] && { local _notfl=1; shift; }
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	local _list="${1}" _filter="${2}" _lnew _litem _ex_lfilter _filterfl;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	[ -z "${_filter}" ] && { echo "${_list}"; return 0; };
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	for _litem in ${_list}; do
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		_filterfl=0;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		for _ex_lfilter in ${_filter}; do
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			if [ "${_notfl:-0}" -eq 0 ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			&& [ "${_ex_lfilter}" = "${_litem}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
				_lnew="${_lnew:+${_lnew} }${_litem}"; break;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			elif [ "${_notfl:-0}" -eq 1 ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			&& [ "${_ex_lfilter}" = "${_litem}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
				_filterfl=1; break;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		done;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		if [ "${_notfl:-0}" -eq 1 ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		&& [ "${_filterfl:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			_lnew="${_lnew:+${_lnew} }${_litem}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	echo "${_lnew}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_lmatch() {
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	local _cmp="${3}" IFS="${2}"; set -- ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		if [ "${1}" = "${_cmp}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	done; return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_run_cmd_unsplit() {
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	local _cmd="${1}" _cmdline _rc IFS; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		[ -n "${1}" ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			_cmdline="${_cmdline:+${_cmdline}:}${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	IFS=:; ${_cmd} ${_cmdline}; _rc=$?;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	return ${_rc};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
# vim:filetype=sh