#!/bin/bash
# dev/package/env - package development enviroment support

set -e

lib_load 'dev/package/load'


######
# Package development environment

package_env_bash() {
	local deactivate="${PKG}_env_deactivate"
	local helpcmd="${PKG}_help"
	local ide_cmds="${PKG}_cmds"
	local ide_help="${PKG}_cmds_usage"
	local path="$EXEC_PREFIX/bin"
	local PATH="${PATH/$path:/}"
	local PS1=$(bash -i -c 'echo $PS1')
	local PS2=$(bash -i -c 'echo $PS2')

	cat <<ENV
# Use this function to restore the old PATH and prompts
$deactivate() {
	export PATH='$PATH'
	export PS1='$PS1 '
	export PS2='$PS2 '
	unalias mcenv mcgrep mcsed mcfake mcloud mcdebug mcinstall
	unset -f mcrepair mctest mcfunc mcalias
	echo "$PKG environment deactivated.  Thank you, come again!"
}

# Add the installed scripts to the PATH and set the prompts
export PATH='$path:$PATH'
export PS1='($PKG) $PS1 '
export PS2='($PKG) $PS2 '

declare -ga $ide_cmds=()
declare -gA $ide_help=()

$helpcmd() {
	echo "Development Environment Commands:"
	local i
	for i in "\${$ide_cmds[@]}"; do
		echo "	\$i			\${$ide_help[\$i]}"
	done
}

mcfunc() {
	$ide_cmds+=( \$1 )
	$ide_help[\$1]=\$2
}
mcalias() {
	alias \$1="\$2"
	mcfunc "\$1" "\$3"
}


# Useful aliases:
mcalias mcenv 'eval "\$(make env)"' "Reload this environment"
mcalias mcgrep 'd12 grep' "Run 'd12 grep'"
mcalias mcsed 'd12 sed' "Run 'd12 sed'"
mcalias mcfake 'mctest env pretend=true' 'Simulate a command'
mcalias mcloud 'mctest env verbose=true' 'Run a verbose command'
mcalias mcdebug 'mctest env debug=true' 'Debug a command'
mcalias mcinstall 'make -s install' "Run 'make install'"

mcfunc mcrepair 'Repair a broken script library'
mcrepair() { cp -av "libs/\$1.in" "install/share/$PKG/\$1.sh"; }

mcfunc mctest 'Repair a broken script library'
mctest() { mcinstall && "\$@"; }

echo "$PKG environment is now active.  Run '$deactivate' to deactivate it."
echo "For help using this development environment, run '$helpcmd'."

# If you can see this comment, trying running the command again, as the
# argument to 'eval' (e.g. 'eval "\$(make env)"' or 'eval "\$(i7 env)"').
ENV
}

package_env_python() { error "not implemented"; }

View the Developer Guide Index

View the Reference Manual Index


Generated on Fri Jul 28 14:35:22 PDT 2017 by mcsh d14 v0.23.0.