forked from facebookarchive/phpsh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc.example.php
42 lines (35 loc) · 832 Bytes
/
rc.example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
# Copy this file to ~/.phpsh/rc.php via:
# mkdir -p ~/.phpsh && cp rc.example.php ~/.phpsh/rc.php
# Load any system defaults / codebase-modes.
require_once '/etc/phpsh/rc.php';
# The examples here are for easy IO with the outside world.
define('DEFAULT_IO_FILE', getenv('HOME').'/o');
/**
* Append array or var to ~/o.
* @author dcorson
*/
function o($x, $fn=DEFAULT_IO_FILE) {
$f = fopen($fn, 'a');
if (is_array($x)) {
fwrite($f, implode("\n", $x)."\n");
} else {
fwrite($f, $x."\n");
}
fclose($f);
return true;
}
/**
* Strip last char (typically used to kill "\n") from line.
* @author dcorson
*/
function _rstrip($l) {
return substr($l, 0, strlen($l) - 1);
}
/**
* Read array from ~/o.
* @author dcorson
*/
function i($fn=DEFAULT_IO_FILE) {
return array_map('_rstrip', file($fn));
}