Bash Environment

class oscopilot.environments.bash_env.Shell[source]

Bases: SubprocessEnv

A class representing a shell environment for executing shell scripts.

This class inherits from SubprocessEnv, which provides a general environment for executing code in subprocesses.

aliases = ['bash', 'sh', 'zsh']
detect_active_line(line)[source]

Detects the active line indicator in the output.

Parameters:

line (str) – A line from the output.

Returns:

The line number indicated by the active line indicator, or None if not found.

Return type:

int

detect_end_of_execution(line)[source]

Detects the end of execution marker in the output.

Parameters:

line (str) – A line from the output.

Returns:

True if the end of execution marker is found, False otherwise.

Return type:

bool

file_extension = 'sh'
line_postprocessor(line)[source]

Postprocesses each line of output from the shell execution.

Parameters:

line (str) – A line from the output of the shell script execution.

Returns:

The processed line.

Return type:

str

name = 'Shell'
preprocess_code(code)[source]

Preprocesses the shell script code before execution.

Parameters:

code (str) – The shell script code to preprocess.

Returns:

The preprocessed shell script code.

Return type:

str

oscopilot.environments.bash_env.add_active_line_prints(code)[source]

Adds echo statements indicating line numbers to a shell script.

Parameters:

code (str) – The shell script code to add active line indicators to.

Returns:

The modified shell script code with active line indicators.

Return type:

str

oscopilot.environments.bash_env.has_multiline_commands(script_text)[source]

Checks if a shell script contains multiline commands.

Parameters:

script_text (str) – The shell script code to check.

Returns:

True if the script contains multiline commands, False otherwise.

Return type:

bool

oscopilot.environments.bash_env.preprocess_shell(code)[source]

Preprocesses the shell script code before execution.

Adds active line markers, wraps in a try-except block (trap in shell), and adds an end of execution marker.

Parameters:

code (str) – The shell script code to preprocess.

Returns:

The preprocessed shell script code.

Return type:

str