MCPEx.Utils.CommandUtils (MCPEx v0.1.0)

Utility functions for finding executables and executing commands through the shell. Used by various parts of the library that need to interact with the system shell.

Summary

Functions

Executes a command through the user's shell to ensure it has access to the full shell environment, including PATH from startup files (.zshrc, .bashrc, etc).

Find an executable in the PATH using the user's shell environment. Returns the full path to the executable or nil if not found. Falls back to system PATH search if shell environment fails.

Gets the user's shell executable path and name. Returns a tuple of {shell_path, shell_name} where shell_path is the full path to the shell executable and shell_name is the base name (zsh, bash, etc). Falls back to /bin/bash if SHELL is not set.

Convert string to charlist for Port.open, returns nil if input is nil

Functions

execute_through_shell(command)

Executes a command through the user's shell to ensure it has access to the full shell environment, including PATH from startup files (.zshrc, .bashrc, etc).

Returns {output, exit_code}

find_executable(command)

Find an executable in the PATH using the user's shell environment. Returns the full path to the executable or nil if not found. Falls back to system PATH search if shell environment fails.

get_user_shell()

Gets the user's shell executable path and name. Returns a tuple of {shell_path, shell_name} where shell_path is the full path to the shell executable and shell_name is the base name (zsh, bash, etc). Falls back to /bin/bash if SHELL is not set.

to_charlist_if_found(path)

Convert string to charlist for Port.open, returns nil if input is nil