/* Paths as people write them. * * `~` is a shell thing: by the time a path reaches us from a config or layout * file no shell has touched it, so `cwd="~/dev/api"` was being handed to * chdir() literally, failing, and leaving the pane in whatever directory the * session happened to be in. Silently \u2014 which is the worst way for a path to * be wrong, because the pane still starts and still works. */ #include "sl0ppty.h" #include #include #include const char *path_expand(const char *path, char *buf, size_t cap) { if (!path) return NULL; /* `~` and `~/...` only. `~user` needs the password database and is not * worth linking it in for; it is returned unchanged, which is exactly what * it did before, rather than being half-expanded into something wrong. */ if (path[0] != '~' || (path[1] && path[1] != '/')) return path; const char *home = getenv("HOME"); if (!home || !*home) return path; snprintf(buf, cap, "%s%s", home, path + 1); return buf; }