terminal: trim CWD slash #11762

Trailing CWD slash in term:// buffer name breaks the BufReadCmd
handler.

Before:
    term://~///25232:/bin/bash
After:
    term://~//25232:/bin/bash

ref c6ff23d7a0
ref #11289
This commit is contained in:
Justin M. Keyes 2020-01-26 02:13:37 -08:00 committed by GitHub
parent c6ff23d7a0
commit 07a105f0cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18386,7 +18386,12 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
// "./…" => "/home/foo/…"
vim_FullName(cwd, (char *)NameBuff, sizeof(NameBuff), false);
// "/home/foo/…" => "~/…"
home_replace(NULL, NameBuff, IObuff, sizeof(IObuff), true);
size_t len = home_replace(NULL, NameBuff, IObuff, sizeof(IObuff), true);
// Trim slash.
if (IObuff[len - 1] == '\\' || IObuff[len - 1] == '/') {
IObuff[len - 1] = '\0';
}
// Terminal URI: "term://$CWD//$PID:$CMD"
snprintf((char *)NameBuff, sizeof(NameBuff), "term://%s//%d:%s",
(char *)IObuff, pid, cmd);