Skip to content

Instantly share code, notes, and snippets.

@noahduncan
Last active January 18, 2017 19:56
Show Gist options
  • Save noahduncan/bcb50a48fbea4d0067079b3cce67cc76 to your computer and use it in GitHub Desktop.
Save noahduncan/bcb50a48fbea4d0067079b3cce67cc76 to your computer and use it in GitHub Desktop.
Autoload Interactive PHP Shell
alias iphp="php -d auto_prepend_file=~/.phpinitscript.php -a"
<?php
/**
* This file lives in my home directory.
*/
$projects_root = "/home/noah/projects";
$dircount = count(explode('/', $projects_root));
$curpath = trim(`pwd`);
if (false === strpos($projects_root, $curpath)) {
die('Not in a project directory.');
}
$dirs = explode('/', $curpath);
// /home/noah/projects/<project>
$project = $dirs[$dircount];
$proj_root = implode('/', array_slice($dirs,0,$dircount+1));
switch ($project) {
case 'eminutes':
$bootstrap_file = '/inc/bootstrap.php';
break;
case 'sketchup':
$bootstrap_file = '/lib/app.php';
break;
default:
die('Unknown project ' . $project);
break;
}
$err = fopen('php://stderr','w');
fwrite($err, "Loaded bootstrap file '$proj_root$bootstrap_file'.\n");
fclose($err);
require_once $proj_root . $bootstrap_file;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment