Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: use LocalAppData environment variable to get path to Windows Terminal #13

Open
QWp6t opened this issue Sep 19, 2021 · 3 comments

Comments

@QWp6t
Copy link

QWp6t commented Sep 19, 2021

First of all, thanks for all the effort you've put into your dotfiles. I've been using them for a little while now. I'm actually in the process of cherry-picking your latest stuff when I noticed a line in your set-theme script, figured I'd offer a suggestion.

Why?

This avoids several assumptions about the user's environment, particularly the location of the user's profile folder as well as the the root path for accessing Windows filesystem from WSL (i.e., / vs /mnt/)

How?

Windows has an environment variable called LocalAppData that you can use to get the current user's local application data path.

Terminal

Here's how you would do it in the terminal:

wslpath $(cmd.exe /c echo %LocalAppData% 2>/dev/null)
# => /c/Users/Me/AppData/Local
Explanation

Screenshot below illustrates what's going on

image

Python

I'm not very fluent in Python, which is why I didn't open a PR.

I think it would look something like this:

from subprocess import run, PIPE, DEVNULL

def get_windows_app_data_path():
    windows_path = run(['cmd.exe', '/c', 'echo', '%LocalAppData%'], stderr=DEVNULL, stdout=PIPE, universal_newlines=True).stdout.rstrip()
    return run(['wslpath', windows_path], stderr=DEVNULL, stdout=PIPE, universal_newlines=True).stdout.rstrip()

TERMINAL_CONFIG = f'{get_windows_app_data_path()}/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json'  # noqa: E501

Anyway, just a suggestion. Have a good one. 👋🏼

@nickjj
Copy link
Owner

nickjj commented Sep 19, 2021

Hi,

Thanks. Your solution is definitely better for the reasons you specified.

Do you happen to know offhand if wslpath is available with WSL 1 and works the same as what you specified in that screenshot?

@QWp6t
Copy link
Author

QWp6t commented Sep 19, 2021

Looks like it was available with WSL1 after an update (1803), but perhaps if someone hasn't updated Windows 10 since 2017, they won't have it?

https://devblogs.microsoft.com/commandline/windows10v1803/#interoperability

@nickjj
Copy link
Owner

nickjj commented Sep 19, 2021

Sounds good, I'm ok with using your solution in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants