5

I've just installed MSYS2, and to have it use my Windows user folder as $HOME, I put this in /etc/bash.bashrc:

HOME=$USERPROFILE

And that works fine when I just run cd, except the prompt doesn't show ~ anymore as the current path when I'm there. Another problem is that

cd ~

takes me to my home dir, but pressing tab after ~ doesn't expand it with the contents of my home directory; intead I get a list of my computer's users prefixed by ~, and trying to access one of those makes it try to cd to /home/(username).

How can I get ~ to play nice with a home directory that doesn't reside in /home?

Huluvu424242
  • 103
  • 5
tacospice
  • 181

3 Answers3

8

The correct way to do this is to put this into /etc/nssswitch.conf :

db_home: windows

See here for docs.

Also to make my homedir ls output more readable, I put this in ~/.bashrc :

alias ls="ls -h --color=auto --hide='ntuser.*' --hide='NTUSER.*'"
5

Edit /etc/fstab to mount C:\Users as /home and voila! For example, append the following at the end of fstab:

C:/Users /home ntfs binary,noacl,auto 1 1
BahmanM
  • 223
3

$USERPROFILE points to the user's home folder in Windows format, but obviously MSYS would expect a UNIX style path. I'd read the suggestion in another post, possibly on here, which is why I tried it.

For some reason, cd:ing to a Windows path in MSYS's bash will bring you to the correct mounted location of that folder, but then you will no longer be in the path specified by $HOME, which I believe is why the suggestion works, but still doesn't substitute the path for ~ in the prompt.

After that situtation dawned on me (thanks in part to Astara), I came up with this instead:

HOME=/c/Users/$USER

in /etc/bash.bashrc, or whichever bashrc file applies, in case you're not using MSYS2.

Of course, this requires your users folder to be C:\Users, as is the case on at least Windows 7 and 8.

tacospice
  • 181