MSYS2 home folder: show ~

5

1

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?

ps: Reputation too low, so I couldn't tag it msys2

tacospice

Posted 2014-09-10T20:53:34.497

Reputation: 81

1What if you type ~/ and then Tab? (It shouldn't expand with the contents of your home directory if you type ~ and then Tab; it sounds like it's doing the right thing.) – G-Man Says 'Reinstate Monica' – 2014-09-10T21:02:02.060

oh, I didn't know that. ~/ and tab doesn't expand at all. – tacospice – 2014-09-10T21:17:41.113

How about ~/ta and then Tab, where you have a file in your home directory whose name begins with ta? – G-Man Says 'Reinstate Monica' – 2014-09-10T21:19:26.953

Same there, doesn't expand. – tacospice – 2014-09-10T21:50:48.180

is your username tacospice? what if you type ~tac<tab>... does that expand to a full "~tacospice"? To expand that, put it in an 'echo'. This reminds me of the issue of whether or not bach should expand variables when doing prompt completion. Some think yes, some think not... I think it became an obscure option. Might be similar for ~, but don't think it is usually expanded. What does "echo ~" print out? – Astara – 2014-09-10T23:03:30.680

Ahh! That brought me to the answer. Naturally, $USERPROFILE contains the path to the home directory in Windows format, and for some reason, MSYS2's cd still accepts Windows style paths, but then brings me to the mounted location. So I was essentially doing "cd C:\Users<user>" and then getting redirected to /c/Users/<user>. Setting $HOME with the proper path makes everything work normally (~ in the prompt, ~/ expansion). Feel free to post it in the form of an answer and I'll accept it. – tacospice – 2014-09-11T00:59:51.957

A working value for $HOME is HOME=/c/Users/$USER in bashrc (at least on Windows 8). – tacospice – 2014-09-11T01:02:38.180

Answers

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

Posted 2014-09-10T20:53:34.497

Reputation: 81

You may still be able to make $USERPROFILE work. Try this: HOME=$(cd "$USERPROFILE" && pwd). – jpmc26 – 2016-04-28T00:24:19.130

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.*'"

Rafael Kitover

Posted 2014-09-10T20:53:34.497

Reputation: 203

In my corporate environment, this put it on a network drive for me, not the local C:\Users, which is what I wanted. – dsz – 2018-01-22T21:05:31.240

4

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

Bahman M.

Posted 2014-09-10T20:53:34.497

Reputation: 213

After reading about the format referenced at Cygwin(https://cygwin.com/cygwin-ug-net/using.html#mount-table), I am curious about the choices on the third column here. binary is fine, auto is ignored so can be omitted. What's the advantage of noacl over acl? It seems cygwin is able to construct POSIX permissions from NTFS ones. Is it just to keep in line with default cygdrive settings?

– FRIdSUN – 2016-03-23T08:48:24.737

Well, that was a while ago when I had to write some code in a Win64 environment; honestly, I can't recall the reason :-) – Bahman M. – 2016-03-23T15:42:01.150

2Upon further reading, apparently the conversion done with acl is not good. I guess it's good enough to use binary,noacl. – FRIdSUN – 2016-03-28T11:47:47.120

1@FRIdSUN acl is bad if you have mixed cygwin (or msys)/windows uses of files and directories. Msys by default mounts drives noacl, cygwin acl This is, presumably, because the cygwin crew, mistakenly, assume that people stay in the cygwin environment all the time and do not use Windows tools in the same directories where they use cygwin. cygwin manipulates the access control lists in non-standard ways in order to emulate POSIX permissions on files (there is no 1:1 relation to NTFS file attributes). Bottom line is, for typical mixed use mount noacl. – Peter - Reinstate Monica – 2017-09-05T10:23:48.603