Improved devmode
* Added --init option to generate a new configuration file * Improved prompt * Added support for generating a dynamic .env.local file
This commit is contained in:
@ -32,6 +32,15 @@ class DevMode
|
||||
passthru('xtitle '.escapeshellarg($title));
|
||||
}
|
||||
|
||||
$localenv = $conf['localenv'];
|
||||
$envlocal = $this->env->getProjectDirectory()."/.env.local";
|
||||
if (is_array($localenv) && !file_exists($envlocal)) {
|
||||
printf("* Creating temporary %s\n", $envlocal);
|
||||
file_put_contents($envlocal, join("\n", $localenv));
|
||||
} else {
|
||||
$localenv = null;
|
||||
}
|
||||
|
||||
$shell = $conf['shell'];
|
||||
if (!$shell) {
|
||||
$this->runDefaultShell();
|
||||
@ -43,6 +52,10 @@ class DevMode
|
||||
passthru('xtitle '.escapeshellarg("stopping: ".$title));
|
||||
}
|
||||
|
||||
if ($localenv) {
|
||||
unlink($envlocal);
|
||||
}
|
||||
|
||||
$shutdown = $conf['shutdown'];
|
||||
if ($shutdown) {
|
||||
$script->evaluate($shutdown);
|
||||
@ -56,16 +69,16 @@ class DevMode
|
||||
private function runDefaultShell()
|
||||
{
|
||||
$init = $this->env->getProjectDirectory() . "/.devmoderc~";
|
||||
$initrc = [
|
||||
//"source \$HOME/.bashrc",
|
||||
"test -f .spark/devmode.rc && source .spark/devmode.rc",
|
||||
];
|
||||
$initrc = [];
|
||||
foreach ($_ENV as $e=>$v) {
|
||||
$initrc[] = sprintf("export %s=%s", $e, escapeshellarg($v));
|
||||
}
|
||||
|
||||
//"source \$HOME/.bashrc",
|
||||
$initrc[] = "test -f .spark/devmode.rc && source .spark/devmode.rc";
|
||||
$proj = basename($this->env->getProjectDirectory());
|
||||
$initrc[] = "function _dev_prompt {";
|
||||
$initrc[] = " export PS1=\"\[\e[44;3m\] \[\e[1m\]dev\[\e[22;23m\] \[\e[36m\]{$proj}\[\e[39m\] \[\e[49m\] \w \$ \"";
|
||||
$initrc[] = " export PS1=\"\[\e[40;37m\] \u{26a1} \[\e[44;37m\] {$proj} \[\e[0m\] \w \$ \"";
|
||||
$initrc[] = "}";
|
||||
$initrc[] = "export PROMPT_COMMAND=_dev_prompt";
|
||||
file_put_contents($init, join("\n", $initrc));
|
||||
@ -82,6 +95,7 @@ class DevMode
|
||||
'triggers' => [],
|
||||
'startup' => null,
|
||||
'shutdown' => null,
|
||||
'localenv' => null,
|
||||
'shell' => null,
|
||||
];
|
||||
|
||||
|
Reference in New Issue
Block a user