opensouls / terminal-copilot

A smart terminal assistant that helps you find the right command.
Apache License 2.0
573 stars 43 forks source link

Make explainshell work in WSL #42

Open Ry-DS opened 1 year ago

Ry-DS commented 1 year ago

When you ask terminal-copilot to explain a shell command, it crashes with the following:

> explainshell: https://explainshell.com/explain?cmd=tar%20-xzvf%20%3Cfilename%3E.tar.gz
Traceback (most recent call last):
  File "/home/ryan/.local/bin/copilot", line 8, in <module>
    sys.exit(main())
  File "/home/ryan/.local/lib/python3.8/site-packages/copilot/main.py", line 116, in main
    show_command_options(prompt, cmd)
  File "/home/ryan/.local/lib/python3.8/site-packages/copilot/main.py", line 149, in show_command_options
    show_more_cmd_options(prompt)
  File "/home/ryan/.local/lib/python3.8/site-packages/copilot/main.py", line 179, in show_more_cmd_options
    show_command_options(prompt, cmds[cmd_menu_entry_index])
  File "/home/ryan/.local/lib/python3.8/site-packages/copilot/main.py", line 147, in show_command_options
    subprocess.run(["open", "https://explainshell.com/explain?cmd=" + quote(cmd)])
  File "/usr/lib/python3.8/subprocess.py", line 493, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'open'

This is expected, as a WSL instance doesn't have the open ability.

I plan to make a PR to fix this, which will check if the VM is a WSL instance, and if so, use wslview or another command instead to open the URL. ETA for the PR is about a month once I find the time.

No longer use this in preference of github copilot's ai shell: https://githubnext.com/projects/copilot-cli Probably won't have the time to contribute this, but I'll keep this open for anyone else who runs into this

github-actions[bot] commented 1 year ago

Hey! Thanks for sharing feedback with the community!

2mawi2 commented 1 year ago

I am wondering how the browser on WSL can be opened anyway ? You would probably open the browser of the host system. Which is pretty difficult and therefore I am not sure I we want to support this at all ?

Ry-DS commented 1 year ago

It's very easy, and built into wsl. It's a matter of checking if the OS is running in WSL, and calling wslview <url>

e.g: wslview http://google.com

Check: https://manpages.ubuntu.com/manpages/impish/man1/wslview.1.html

Ry-DS commented 1 year ago

fun fact you can open exe's even in wsl. powershell.exe -C "wsl --help" > wsl_help.txt is a valid command which will work inside of wsl