LazoCoder / Pokemon-Terminal

Pokemon terminal themes.
GNU General Public License v3.0
4.2k stars 225 forks source link

Does this support Windows Terminal + WSL2 Ubuntu? #187

Open inductor opened 4 years ago

inductor commented 4 years ago
$ /home/kela/.local/bin/pokemon
Traceback (most recent call last):
  File "/home/kela/.local/bin/pokemon", line 8, in <module>
    sys.exit(main())
  File "/home/kela/.local/lib/python3.8/site-packages/pokemonterminal/main.py", line 113, in main
    scripter.change_terminal(target.get_path())
  File "/home/kela/.local/lib/python3.8/site-packages/pokemonterminal/scripter.py", line 81, in change_terminal
    TERMINAL_PROVIDER.change_terminal(image_file_path)
  File "/home/kela/.local/lib/python3.8/site-packages/pokemonterminal/terminal/adapters/windowsterminal.py", line 54, in change_terminal
    WindowsTerminalProvider.set_background_image(path)
  File "/home/kela/.local/lib/python3.8/site-packages/pokemonterminal/terminal/adapters/windowsterminal.py", line 10, in set_background_image
    profiles_path = os.environ['LOCALAPPDATA'] + '\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\settings.json'
  File "/usr/lib/python3.8/os.py", line 675, in __getitem__
    raise KeyError(key) from None
KeyError: 'LOCALAPPDATA'

It seems like it tried to read the Windows env variable. So I tried adding it as a variable on Linux

$ LOCALAPPDATA="/mnt/c/Users/kela/AppData/Local/" /home/kela/.local/bin/pokemon
Traceback (most recent call last):
  File "/home/kela/.local/bin/pokemon", line 8, in <module>
    sys.exit(main())
  File "/home/kela/.local/lib/python3.8/site-packages/pokemonterminal/main.py", line 113, in main
    scripter.change_terminal(target.get_path())
  File "/home/kela/.local/lib/python3.8/site-packages/pokemonterminal/scripter.py", line 81, in change_terminal
    TERMINAL_PROVIDER.change_terminal(image_file_path)
  File "/home/kela/.local/lib/python3.8/site-packages/pokemonterminal/terminal/adapters/windowsterminal.py", line 54, in change_terminal
    WindowsTerminalProvider.set_background_image(path)
  File "/home/kela/.local/lib/python3.8/site-packages/pokemonterminal/terminal/adapters/windowsterminal.py", line 11, in set_background_image
    with open(profiles_path, 'r+', encoding='utf8') as json_file:
FileNotFoundError: [Errno 2] No such file or directory: '/mnt/c/Users/kela/AppData/Local/\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\settings.json'

So it assumes you are using Windows when you're on Windows Terminal. I guess you need to read the OS type?

sylveon commented 4 years ago

Correct, the script assumes Windows, and I don't think it's worth the effort supporting its use through WSL, so if WSL/Linux is detected this should be excluded from the candidate adapters (it isn't currently)

chardskarth commented 4 years ago

@inductor sharing how I made this work in my WSL. I changed a couple of lines directly in my installation.

First, I changed this line to:

        profiles_path = os.environ['LOCALAPPDATA'] + '/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json'

Then, added this line

                wsl_path = os.environ['WSLPATH']
                profile['backgroundImage'] = wsl_path + path

I just added another environment variable: WSLPATH.

WSLPATH="C:/Users/user/AppData/Local/Packages/CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc/LocalState/rootfs" LOCALAPPDATA="/mnt/c/Users/user/AppData/Local" pokemon

chardskarth commented 4 years ago

I had to change my WSLPATH variable to \\\\wsl$\\Ubuntu-18.04 after updating to WSL2.

gunzf0x commented 2 years ago

Hi, I know this issue was posted a long time ago, but I had exactly the same issue and was able to fix it in a very similar way with the reply given above, but slightly different.

Here I will try to explain it in a detailed way if someone has the same problem as I just did.


Instead of working with enviroment variables you can change the following in windowsterminal.py (path to this file is given explicitly by the error printed in console):

Change line number #10, which was: profiles_path = os.environ['LOCALAPPDATA'] + '\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\settings.json' by its direct path: profiles_path = "/mnt/c/Users/Panchito/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json"

in this case, "Panchito" is my Windows (not WSL) username in my configuration. You have to change that for your Windows username.

Next, in line #29 you will find the following original line: profile['backgroundImage'] = path and simply replace that line for the following 2 lines: wsl_path = "\\\\wsl$\\Ubuntu-20.04" profile['backgroundImage'] = wsl_path + path

Change "20.04" for your current WSL2 system version; in my case is Ubuntu 20.04.

If you do not know how to see you Root directory in WSL just go to root directory in WSL (type .. until you cannot go back in more directories) and then type explorer.exe .. This will open GUI Windows interface so you can easily see where your root is located in your Windows OS.

In other words, reply given by @chardskarth was really good! However, for WSL you must specify explicitly where Windows AppData (Windows Terminal json setting file) is in a way that WSL can easily understand it (which is /mnt/c/Users/...)

Cheers!