shell_utils package

Submodules

shell_utils.cli module

Usage: [OPTIONS] COMMAND [ARGS]…

A cli for shell-utils.
Options:
--help Show this message and exit.
shell_utils.cli.add_dev_command(root_cmd)[source]

Add development commands to package cli, if installed in editable mode.

Parameters:root_cmd – the root cli command group
shell_utils.cli.main(root_cmd=<click.core.Group object>)[source]

shell_utils.shell_utils module

Main module.

shell_utils.shell_utils.cd(path_: Union[os.PathLike, str])[source]

Change the current working directory.

shell_utils.shell_utils.env(**kwargs) → Iterator[os._Environ][source]

Set environment variables and yield new environment dict.

shell_utils.shell_utils.notify(message: str, title='run.py')[source]

Mac os pop-up notification.

shell_utils.shell_utils.path(*paths, prepend=False, expand_user=True) → Iterator[List[str]][source]

Add the paths to $PATH and yield the new $PATH as a list.

Parameters:
  • prepend – prepend paths to $PATH else append
  • expand_user – expands home if ~ is used in path strings
shell_utils.shell_utils.quiet()[source]

Suppress stdout and stderr.

https://stackoverflow.com/questions/11130156/suppress-stdout-stderr-print-from-python-functions

shell_utils.shell_utils.shell(command: str, check=True, capture=False, show_command=True) → subprocess.CompletedProcess[source]

Run the command in a shell.

!!! Make sure you trust the input to this command !!!

Parameters:
  • command – the command to be run
  • check – raise exception if return code not zero
  • capture

    if set to True, captures stdout and stderr, making them available as stdout and stderr attributes on the returned CompletedProcess.

    This also means the command’s stdout and stderr won’t be piped to FD 1 and 2 by default

  • show_command – show command being run prefixed by user

Returns: Completed Process

Module contents

Top-level package for shell-utils.

shell_utils.shell(command: str, check=True, capture=False, show_command=True) → subprocess.CompletedProcess[source]

Run the command in a shell.

!!! Make sure you trust the input to this command !!!

Parameters:
  • command – the command to be run
  • check – raise exception if return code not zero
  • capture

    if set to True, captures stdout and stderr, making them available as stdout and stderr attributes on the returned CompletedProcess.

    This also means the command’s stdout and stderr won’t be piped to FD 1 and 2 by default

  • show_command – show command being run prefixed by user

Returns: Completed Process

shell_utils.env(**kwargs) → Iterator[os._Environ][source]

Set environment variables and yield new environment dict.

shell_utils.path(*paths, prepend=False, expand_user=True) → Iterator[List[str]][source]

Add the paths to $PATH and yield the new $PATH as a list.

Parameters:
  • prepend – prepend paths to $PATH else append
  • expand_user – expands home if ~ is used in path strings
shell_utils.cd(path_: Union[os.PathLike, str])[source]

Change the current working directory.

shell_utils.quiet()[source]

Suppress stdout and stderr.

https://stackoverflow.com/questions/11130156/suppress-stdout-stderr-print-from-python-functions