-
Notifications
You must be signed in to change notification settings - Fork 314
Shell integration
Justin Hileman edited this page Jun 3, 2017
·
1 revision
It can be super useful to access a system shell from inside a REPL session. PsySH fully supports this โฆย but mostly because PHP supports this ๐.
To execute arbitrary shell commands, wrap the command in backticks.
>>> `pwd`
=> "/Projects/psysh\n"
>>> `ls`
=> """
CONTRIBUTING.md\n
LICENSE\n
README.md\n
bin\n
composer.json\n
composer.lock\n
phpunit.xml.dist\n
src\n
test\n
vendor\n
"""
>>>
PHP variables can be interpolated into shell commands as well.
>>> $readme = 'README.md'
=> "README.md"
>>> `ls -al $readme`
=> "-rw-r--r-- 1 justin staff 9649 May 28 13:34 README.md\n"
>>>
Some commandsโsuch as doc
, dump
, ls
and show
โupdate the $__file
, $__dir
and $__line
magic variables after they run. These variables are especially useful when interpolated into shell commands.
For example, after using doc
to show the documentation for a class or method, you can use the subl
shell command to open that file in Sublime Text and jump to the definition.
>>> doc Psy\Shell
class Psy\Shell extends Symfony\Component\Console\Application
Description:
The Psy Shell application.
Usage:
$shell = new Shell;
$shell->run();
Author: Justin Hileman <[email protected]>
>>> $__file
=> "/Projects/psysh/src/Psy/Shell.php"
>>> `subl $__file:$__line`
=> null
>>>
This. Is. So. Good.