Support use as a Windows program outside of Cygwin

If `getenv("SHELL")` is `NULL`, use the function `win32_setenv_shell()`
added to `osdep-win32-cpp.cpp` to set it using the command line of the
parent process, which is retrieved using WMI WIN32 API.

This is a C++ file because the OLE/WMI API is only available for C++.
Adjust the autotools code to add this file and link the necessary
Windows DLLs.

Include some fixed/missing MINGW headers necessary to compile this file.
This will be fixed in the relevant places and they will be removed.

Add a new macro WIN32_PLATFORM for Windows specific functionality, currently
Cygwin and MSYS2, in the future for the native port as well.

When spawning commands using the shell, check for cmd.exe on Windows and
use the `/c` switch, otherwise use `-c` which works for PowerShell,
MSYS2, Cygwin and Git Bash etc..

Adjust code that uses `/tmp/` to use
`$env:USERPROFILE/AppData/Local/Temp/` outside of a Cygwin virtual
filesystem when `/tmp/` is not available, add the function
`win32_get_tmpdir()` and related functions to `osdep-win32.c` for this.

Use `getenv("USERPROFILE")` when `getenv("HOME")` is `NULL`.

When outside of a Cygwin virtual filesystem, use
`C:\ProgramData\tmux\tmux.conf:$USERPROFILE\.tmux.conf:$LOCALAPPDATA\tmux\tmux.conf`
as the config search order.

Use the ncurses term-driver with `TERM="#win32con"` when a terminfo
database is not available. This will require patches to ncurses as well
as MSYS2 and Cygwin to work.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover
2024-08-24 05:44:45 +00:00
parent 1e303b6a9d
commit 37b27d2eef
12 changed files with 1683 additions and 139 deletions

6
tmux.c
View File

@ -65,7 +65,7 @@ getshell(void)
struct passwd *pw;
const char *shell;
shell = getenv("SHELL");
shell = GETENV_SHELL();
if (checkshell(shell))
return (shell);
@ -328,7 +328,7 @@ find_home(void)
if (home != NULL)
return (home);
home = getenv("HOME");
home = GETENV_HOME();
if (home == NULL || *home == '\0') {
pw = getpwuid(getuid());
if (pw != NULL)
@ -377,7 +377,7 @@ main(int argc, char **argv)
environ_put(global_environ, *var, 0);
if ((cwd = find_cwd()) != NULL)
environ_set(global_environ, "PWD", 0, "%s", cwd);
expand_paths(TMUX_CONF, &cfg_files, &cfg_nfiles, 1);
expand_paths(TMUX_CONF_SEARCH_PATH(), &cfg_files, &cfg_nfiles, 1);
while ((opt = getopt(argc, argv, "2c:CDdf:lL:NqS:T:uUvV")) != -1) {
switch (opt) {