mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
main/client: use $PWD for cwd, when $PWD is valid
If $PWD is set, and its resolved path matches the *actual* working directory, use $PWD for cwd when instantiating the terminal. This makes a difference when $PWD refers to a symlink; before this patch, we’d instantiate the terminal in the *resolved* path. Now it’ll use the symlink instead.
This commit is contained in:
parent
9e58661093
commit
90ce4f3008
2 changed files with 44 additions and 0 deletions
22
client.c
22
client.c
|
|
@ -408,6 +408,28 @@ main(int argc, char *const *argv)
|
|||
cwd = _cwd;
|
||||
}
|
||||
|
||||
const char *pwd = getenv("PWD");
|
||||
if (pwd != NULL) {
|
||||
char *resolved_path_cwd = realpath(cwd, NULL);
|
||||
char *resolved_path_pwd = realpath(pwd, NULL);
|
||||
|
||||
if (resolved_path_cwd != NULL &&
|
||||
resolved_path_pwd != NULL &&
|
||||
strcmp(resolved_path_cwd, resolved_path_pwd) == 0)
|
||||
{
|
||||
/*
|
||||
* The resolved path of $PWD matches the resolved path of
|
||||
* the *actual* working directory - use $PWD.
|
||||
*
|
||||
* This makes a difference when $PWD refers to a symlink.
|
||||
*/
|
||||
cwd = pwd;
|
||||
}
|
||||
|
||||
free(resolved_path_cwd);
|
||||
free(resolved_path_pwd);
|
||||
}
|
||||
|
||||
if (client_environment) {
|
||||
for (char **e = environ; *e != NULL; e++) {
|
||||
if (!push_string(&envp, *e, &total_len))
|
||||
|
|
|
|||
22
main.c
22
main.c
|
|
@ -594,6 +594,28 @@ main(int argc, char *const *argv)
|
|||
cwd = _cwd;
|
||||
}
|
||||
|
||||
const char *pwd = getenv("PWD");
|
||||
if (pwd != NULL) {
|
||||
char *resolved_path_cwd = realpath(cwd, NULL);
|
||||
char *resolved_path_pwd = realpath(pwd, NULL);
|
||||
|
||||
if (resolved_path_cwd != NULL &&
|
||||
resolved_path_pwd != NULL &&
|
||||
strcmp(resolved_path_cwd, resolved_path_pwd) == 0)
|
||||
{
|
||||
/*
|
||||
* The resolved path of $PWD matches the resolved path of
|
||||
* the *actual* working directory - use $PWD.
|
||||
*
|
||||
* This makes a difference when $PWD refers to a symlink.
|
||||
*/
|
||||
cwd = pwd;
|
||||
}
|
||||
|
||||
free(resolved_path_cwd);
|
||||
free(resolved_path_pwd);
|
||||
}
|
||||
|
||||
shm_set_max_pool_size(conf.tweak.max_shm_pool_size);
|
||||
|
||||
if ((fdm = fdm_init()) == NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue