[BACK]Return to cmd.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/cmd.c between version 1.86 and 1.87

version 1.86, 2013/10/10 12:00:24 version 1.87, 2013/10/10 12:07:36
Line 1279 
Line 1279 
 }  }
   
 /*  /*
  * Return the default path for a new pane, using the given path or the   * Return the default path for a new pane. Several special values are accepted:
  * default-path option if it is NULL. Several special values are accepted: the   * the empty string or relative path for the current working directory,
  * empty string or relative path for the current pane's working directory, ~   * ~ for the user's home, - for the base working directory, . for the server
  * for the user's home, - for the session working directory, . for the tmux   * working directory.
  * server's working directory. The default on failure is the session's working  
  * directory.  
  */   */
 const char *  const char *
 cmd_get_default_path(struct cmd_q *cmdq, const char *cwd)  cmd_default_path(const char *base, const char *current, const char *in)
 {  {
         struct client           *c = cmdq->client;  
         struct session          *s;  
         struct environ_entry    *envent;  
         const char              *root;          const char              *root;
           struct environ_entry    *envent;
         char                     tmp[MAXPATHLEN];          char                     tmp[MAXPATHLEN];
         struct passwd           *pw;          struct passwd           *pw;
         int                      n;          int                      n;
         size_t                   skip;          size_t                   skip;
         static char              path[MAXPATHLEN];          static char              path[MAXPATHLEN];
   
         if ((s = cmd_current_session(cmdq, 0)) == NULL)  
                 return (NULL);  
   
         if (cwd == NULL)  
                 cwd = options_get_string(&s->options, "default-path");  
   
         skip = 1;          skip = 1;
         if (strcmp(cwd, "$HOME") == 0 || strncmp(cwd, "$HOME/", 6) == 0) {          if (strcmp(in, "$HOME") == 0 || strncmp(in, "$HOME/", 6) == 0) {
                 /* User's home directory - $HOME. */                  /* User's home directory - $HOME. */
                 skip = 5;                  skip = 5;
                 goto find_home;                  goto find_home;
         } else if (cwd[0] == '~' && (cwd[1] == '\0' || cwd[1] == '/')) {          } else if (in[0] == '~' && (in[1] == '\0' || in[1] == '/')) {
                 /* User's home directory - ~. */                  /* User's home directory - ~. */
                 goto find_home;                  goto find_home;
         } else if (cwd[0] == '-' && (cwd[1] == '\0' || cwd[1] == '/')) {          } else if (in[0] == '-' && (in[1] == '\0' || in[1] == '/')) {
                 /* Session working directory. */                  /* Base working directory. */
                 root = s->cwd;                  root = base;
                 goto complete_path;                  goto complete_path;
         } else if (cwd[0] == '.' && (cwd[1] == '\0' || cwd[1] == '/')) {          } else if (in[0] == '.' && (in[1] == '\0' || in[1] == '/')) {
                 /* Server working directory. */                  /* Server working directory. */
                 if (getcwd(tmp, sizeof tmp) != NULL) {                  if (getcwd(tmp, sizeof tmp) != NULL) {
                         root = tmp;                          root = tmp;
                         goto complete_path;                          goto complete_path;
                 }                  }
                 return (s->cwd);                  return ("/");
         } else if (*cwd == '/') {          } else if (*in == '/') {
                 /* Absolute path. */                  /* Absolute path. */
                 return (cwd);                  return (in);
         } else {          } else {
                 /* Empty or relative path. */                  /* Empty or relative path. */
                 if (c != NULL && c->session == NULL && c->cwd != NULL)                  if (current != NULL)
                         root = c->cwd;                          root = current;
                 else if (s->curw != NULL)  
                         root = get_proc_cwd(s->curw->window->active->fd);  
                 else                  else
                         return (s->cwd);                          return (base);
                 skip = 0;                  skip = 0;
                 if (root != NULL)                  goto complete_path;
                         goto complete_path;  
         }          }
   
         return (s->cwd);          return (base);
   
 find_home:  find_home:
         envent = environ_find(&global_environ, "HOME");          envent = environ_find(&global_environ, "HOME");
Line 1349 
Line 1336 
         else if ((pw = getpwuid(getuid())) != NULL)          else if ((pw = getpwuid(getuid())) != NULL)
                 root = pw->pw_dir;                  root = pw->pw_dir;
         else          else
                 return (s->cwd);                  return (base);
   
 complete_path:  complete_path:
         if (root[skip] == '\0') {          if (root[skip] == '\0') {
                 strlcpy(path, root, sizeof path);                  strlcpy(path, root, sizeof path);
                 return (path);                  return (path);
         }          }
         n = snprintf(path, sizeof path, "%s/%s", root, cwd + skip);          n = snprintf(path, sizeof path, "%s/%s", root, in + skip);
         if (n > 0 && (size_t)n < sizeof path)          if (n > 0 && (size_t)n < sizeof path)
                 return (path);                  return (path);
         return (s->cwd);          return (base);
 }  }

Legend:
Removed from v.1.86  
changed lines
  Added in v.1.87