mirror of
https://github.com/tmux/tmux.git
synced 2025-01-12 03:08:46 +00:00
Remove now unused cmd_get_default_path.
This commit is contained in:
parent
9e0d7bddc0
commit
5ea6148362
71
cmd.c
71
cmd.c
@ -1276,74 +1276,3 @@ cmd_template_replace(const char *template, const char *s, int idx)
|
|||||||
|
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the default path for a new pane. Several special values are accepted:
|
|
||||||
* the empty string or relative path for the current working directory,
|
|
||||||
* ~ for the user's home, - for the base working directory, . for the server
|
|
||||||
* working directory.
|
|
||||||
*/
|
|
||||||
const char *
|
|
||||||
cmd_default_path(const char *base, const char *current, const char *in)
|
|
||||||
{
|
|
||||||
const char *root;
|
|
||||||
struct environ_entry *envent;
|
|
||||||
char tmp[MAXPATHLEN];
|
|
||||||
struct passwd *pw;
|
|
||||||
int n;
|
|
||||||
size_t skip;
|
|
||||||
static char path[MAXPATHLEN];
|
|
||||||
|
|
||||||
skip = 1;
|
|
||||||
if (strcmp(in, "$HOME") == 0 || strncmp(in, "$HOME/", 6) == 0) {
|
|
||||||
/* User's home directory - $HOME. */
|
|
||||||
skip = 5;
|
|
||||||
goto find_home;
|
|
||||||
} else if (in[0] == '~' && (in[1] == '\0' || in[1] == '/')) {
|
|
||||||
/* User's home directory - ~. */
|
|
||||||
goto find_home;
|
|
||||||
} else if (in[0] == '-' && (in[1] == '\0' || in[1] == '/')) {
|
|
||||||
/* Base working directory. */
|
|
||||||
root = base;
|
|
||||||
goto complete_path;
|
|
||||||
} else if (in[0] == '.' && (in[1] == '\0' || in[1] == '/')) {
|
|
||||||
/* Server working directory. */
|
|
||||||
if (getcwd(tmp, sizeof tmp) != NULL) {
|
|
||||||
root = tmp;
|
|
||||||
goto complete_path;
|
|
||||||
}
|
|
||||||
return ("/");
|
|
||||||
} else if (*in == '/') {
|
|
||||||
/* Absolute path. */
|
|
||||||
return (in);
|
|
||||||
} else {
|
|
||||||
/* Empty or relative path. */
|
|
||||||
if (current != NULL)
|
|
||||||
root = current;
|
|
||||||
else
|
|
||||||
return (base);
|
|
||||||
skip = 0;
|
|
||||||
goto complete_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (base);
|
|
||||||
|
|
||||||
find_home:
|
|
||||||
envent = environ_find(&global_environ, "HOME");
|
|
||||||
if (envent != NULL && *envent->value != '\0')
|
|
||||||
root = envent->value;
|
|
||||||
else if ((pw = getpwuid(getuid())) != NULL)
|
|
||||||
root = pw->pw_dir;
|
|
||||||
else
|
|
||||||
return (base);
|
|
||||||
|
|
||||||
complete_path:
|
|
||||||
if (root[skip] == '\0') {
|
|
||||||
strlcpy(path, root, sizeof path);
|
|
||||||
return (path);
|
|
||||||
}
|
|
||||||
n = snprintf(path, sizeof path, "%s/%s", root, in + skip);
|
|
||||||
if (n > 0 && (size_t)n < sizeof path)
|
|
||||||
return (path);
|
|
||||||
return (base);
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user