powerlevel9k icon indicating copy to clipboard operation
powerlevel9k copied to clipboard

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

Open spencerwooo opened this issue 5 years ago • 5 comments

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.

  • What version of ZSH are you using? You can use zsh --version to see this. zsh 5.6.2 (x86_64-pc-linux-gnu)
  • Do you use a ZSH framework (e.g., Oh-My-ZSH, Antigen)? OH-MY-ZSH
  • How did you install P9k (cloning the repo, by tarball, a package from your OS, etc.,)? Via the Install for OH-MY-ZSH section's instructions
  • What version of P9k are you using? The latest. (I just installed P9k 2 days ago.)
  • Which terminal emulator do you use? Fluent Terminal.

spencerwooo avatar Dec 28 '18 02:12 spencerwooo

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):

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

Syphdias avatar Dec 29 '18 11:12 Syphdias

@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.

spencerwooo avatar Dec 29 '18 12:12 spencerwooo

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)

Syphdias avatar Dec 29 '18 13:12 Syphdias

@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.

romkatv avatar May 22 '19 10:05 romkatv

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

spencerwooo avatar May 22 '19 12:05 spencerwooo