FergusFettes / typer-shell

Simple wrapper around the Typer library for making beautiful shells/REPLs for fast command-line prototyping with Python.
GNU General Public License v3.0
9 stars 2 forks source link

allow parent shell commands to be ran in the typer_shell #4

Closed nia-potato closed 3 months ago

nia-potato commented 12 months ago

Hi, thanks for the great project.

I just discovered typer and interactive shells a few weeks ago so please excuse me if this is something obvious.

I currently converted my existing cli to a interactive shell so that data structures that needed to be pre-loaded in the background can be utilized better in a interactive shell session.

however my cli program relied on commands/binaries in the parent shell to work such as gcloud kubectl, etc is there anyway that make_typer_shell will allow the creation of the current user shell configs as a new shell with the interactive components?

nia-potato commented 11 months ago

hey @FergusFettes feel free to take a look at this whenever you have time, but i've tried to modify your shell() to


def shell(ctx: Context):
    """Drop into an ipython shell"""
    import IPython
    env = os.environ.copy()
    IPython.embed(user_ns=env)

and other similar tests to inherit the parent shell behaviors but still had no avail.

FergusFettes commented 7 months ago

@nia-potato hmm, im not sure if this will work-- you cant use bash binaries directly in python shells in general i think.

but I can still use the bash elements in the parent environment like so:

p/txt/typer-shell> export TEST='asdf'
p/txt/typer-shell> poetry run python demo.py

 Welcome to typer-shell! Type help to see commands.

🔥: shell
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.2 -- An enhanced Interactive Python. Type '?' for help.

In [1]: !echo $TEST
asdf

In [2]:

If that isn't what you are looking for, please clarify.