ShellContext API Reference¶
hands_scaphoid.ShellContext(cwd=None, env=None, env_file='~/.env')
¶
Context manager that provides global shell functions.
This context manager creates a Shell instance and exposes its methods as global functions for convenient script-like usage. The functions are automatically cleaned up when exiting the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cwd
|
Optional[Union[str, Path]]
|
Working directory for command execution. |
None
|
env
|
Optional[dict[str, str]]
|
Environment variables dictionary. |
None
|
env_file
|
str
|
Path to environment file to load variables from. |
'~/.env'
|
Yields:
| Name | Type | Description |
|---|---|---|
Shell |
ShellExecutable
|
The Shell instance for advanced usage. |
Example
with ShellContext() as shell: allow("ls") allow("echo") result = run("ls -la") cd("/tmp") run("echo 'Hello World'")