Powerlevel9k / powerlevel9k

Powerlevel9k was a tool for building a beautiful and highly functional CLI, customized for you. P9k had a substantial impact on CLI UX, and its legacy is now continued by P10k.
https://github.com/romkatv/powerlevel10k
MIT License
13.47k stars 947 forks source link

[Feature request] Show Windows' WSL user home directory as '~' #1122

Open spencerwooo opened 5 years ago

spencerwooo commented 5 years ago

Describe Your Issue

What is happening?

This is not an issue, but more of a feature request.

WSL - Windows Subsystem on Linux, it's known that the two systems doesn't share the same home folder, but I usually setup my code in my Windows partition (and I can't get access to the Linux partition for file system compatibility issues, obviously), so I hope that powerlevel9k can support custom user home directories (or just show /mnt/c/Users/WINDOWS_USER_NAME as "~ plus a different icon" would be nice).

Screenshot below:

image

Have you tried to debug or fix it?

Have you tinkered with your settings, and what happened when you did? Did you find a bit of code that you think might be the culprit? Let us know what you've done so far!

I'm not that familiar with zsh or bash grammar, but I'm willing to give it a shot. I will need some time (a lot of time) to figure out how to implement this by myself ... Also it came to me that not all WSL users' home path are /mnt/c, so I really have no idea how to implement this ⊙﹏⊙∥

Environment Information

This information will help us understand your configuration.

Syphdias commented 5 years ago

Disclaimer: I'm not commenting on the feature idea, just what possibilities there are that might help you now.

WSL - Windows Subsystem on Linux, it's known that the two systems doesn't share the same home folder, but I usually setup my code in my Windows partition (and I can't get access to the Linux partition for file system compatibility issues, obviously), so I hope that powerlevel9k can support custom user home directories (or just show /mnt/c/Users/WINDOWS_USER_NAME as "~ plus a different icon" would be nice).

I'm not quite sure if you imply by "incompatibility issues" that your files are inaccessible/unreachable in your "Linux/WSL home" from your Windows system or if you have other worries like permissions, file corruptions, etc. If it is just the former, you can access it, e.g. for Ubuntu %LocalAppData%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home. I guess it's something similar for Arch. I am not sure if it is a good idea sure it is a bad idea to work with these directories directly from Windows, reading should be fine, but please read up on it. (More on WSL fs)

Some more (bad) ideas, that you should not quote me on and might want to try (or to avoid):

spencerwooo commented 5 years ago

@Syphdias Thank you for your suggestions. ♥

I am not sure if it is a good idea to work with these directories directly from Windows. (More on WSL fs)

Yes, it's definitely not recommended to access Linux files from Windows' side.

  • changing home in passwd file
  • export HOME="/mnt/c/Users/WINDOWS_USER_NAME"

I'm trying not to mess up my Windows environments with my Linux ones. And Linux can't chmod Windows' files, so for programs like ssh, I can't just use the keys on both sides. Thus I think simply changing the $HOME is not an option.

An update:

I configured p9k to truncate path to 2 words, so when I'm in Windows' home folder, it looks like this:

applicationframehost_7t2bhaoxuc

As a matter of fact, I am kind of satisfied. Do wish there's a better way implement this.

Syphdias commented 5 years ago

Yes, it's definitely not recommended to access Linux files from Windows' side.

I corrected that statement shortly before your answer ;)

I configured p9k to truncate path to 2 words, so when I'm in Windows' home folder, it looks like this:

applicationframehost_7t2bhaoxuc

As a matter of fact, I am kind of satisfied. Do wish there's a better way implement this.

You might want to play around with some dir shorten strategies, especially truncate_with_folder_marker:

touch "/mnt/c/Users/WINDOWS_USER_NAME/.shorten_folder_marker"
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker"
cd "/mnt/c/Users/WINDOWS_USER_NAME/Documents"

Another interesting one might be truncate_with_package_name, though currently, this needs a git repository which is a(nother) bad idea to have in your home directory. (This changes with ab6c1b779c3869d5792edbfbfa2e4f6576d219e4 which is currently only on the next branch)

romkatv commented 5 years ago

@spencerwooo This is a perfect use case for named directories. First, put this in your ~/.zshrc.

hash -d w=/mnt/c/Users/spenc

(You can use any name instead of w. I went with w as a shorthand for Windows.)

Now ZSH will automatically perform bidirectional mapping between ~w and /mnt/c/Users/spenc the same way and in the same context where it performs mapping between ~ and /home/spencer. That is, commands like cd ~w and ls -d ~w/* will work. File completion after ~w will work, too.

Unfortunately, there is a bug in Powerlevel9k that will prevent ~w being shown in your prompt. You can either switch to Powerlevel10k where this bug is fixed (it'll work with your existing config without any changes; you'll get the same prompt as before but it'll be much faster and with many bugs being fixed) or as a workaround you can set POWERLEVEL9K_SHORTEN_STRATEGY=default and POWERLEVEL9K_SHORTEN_DIR_LENGTH=9999.

spencerwooo commented 5 years ago

@romkatv Thank you so much, I've switched to Powerlevel10k for now and it's really faster. ❤️