I did a toy patch to fix this, it removes any slashes at the end of $HOME during the compact_path and handles multiple slashes in the way @andreyorst said it should (won’t strip just one at the end, but as many as are there).
diff --git i/src/file.cc w/src/file.cc
index 52a0f288..0be76e58 100644
--- i/src/file.cc
+++ w/src/file.cc
@@ -86,7 +86,7 @@ String real_path(StringView filename)
return res;
StringView dir = res;
- if (dir.substr(dir.length()-1_byte, 1_byte) == "/")
+ while (dir.substr(dir.length()-1_byte, 1_byte) == "/")
dir = dir.substr(0_byte, dir.length()-1_byte);
return format("{}/{}", dir, non_existing);
}
@@ -115,9 +115,13 @@ String compact_path(StringView filename)
if (prefix_match(real_filename, real_cwd))
return real_filename.substr(real_cwd.length()).str();
- const StringView home = homedir();
+ StringView home = homedir();
+
if (not home.empty())
{
+ while (home.substr(home.length()-1_byte, 1_byte) == "/")
+ home = home.substr(0_byte, home.length()-1_byte);
+
ByteCount home_len = home.length();
if (real_filename.substr(0, home_len) == home)
return "~" + real_filename.substr(home_len);
@@ -405,7 +409,7 @@ String find_file(StringView filename, StringView buf_dir, ConstArrayView<String>
{
if (stat(filename.zstr(), &buf) == 0 and S_ISREG(buf.st_mode))
return filename.str();
- return "";
+ return "";
}
if (filename.substr(0_byte, 2_byte) == "~/")
{