diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2013-10-06 21:02:23 +0100 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2013-10-06 21:02:23 +0100 |
commit | 4538c269d0b366a770a5a5ebfe0c5007569edbc1 (patch) | |
tree | 9fac1bc826683d2187e69c3e748da92a7db6a225 /cmd-save-buffer.c | |
parent | 446eb11cdeba97a24996cee36ba331491aba6211 (diff) | |
download | rtmux-4538c269d0b366a770a5a5ebfe0c5007569edbc1.tar.gz rtmux-4538c269d0b366a770a5a5ebfe0c5007569edbc1.tar.bz2 rtmux-4538c269d0b366a770a5a5ebfe0c5007569edbc1.zip |
Alter how tmux handles the working directory to internally use file descriptors
rather than strings.
- Each session still has a current working directory.
- New sessions still get their working directory from the client that created
them or its attached session if any.
- New windows are created by default in the session working directory.
- The -c flag to new, neww, splitw allows the working directory to be
overridden.
- The -c flag to attach let's the session working directory be changed.
- The default-path option has been removed.
To get the equivalent to default-path '.', do:
bind c neww -c $PWD
To get the equivalent of default-path '', do:
bind c neww -c '#{pane_current_path}'
The equivalent of default-path '~' is left as an exercise for the reader.
This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.
Diffstat (limited to 'cmd-save-buffer.c')
-rw-r--r-- | cmd-save-buffer.c | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c index c6c54019..3788fc22 100644 --- a/cmd-save-buffer.c +++ b/cmd-save-buffer.c @@ -20,8 +20,10 @@ #include <sys/stat.h> #include <errno.h> +#include <fcntl.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include "tmux.h" @@ -53,17 +55,14 @@ enum cmd_retval cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; - struct client *c; + struct client *c = cmdq->client; struct session *s; struct paste_buffer *pb; - const char *path, *newpath, *wd; - char *cause, *start, *end; - size_t size, used; - int buffer; - mode_t mask; + const char *path; + char *cause, *start, *end, *msg; + size_t size, used, msglen; + int cwd, fd, buffer; FILE *f; - char *msg; - size_t msglen; if (!args_has(args, 'b')) { if ((pb = paste_get_top(&global_buffers)) == NULL) { @@ -90,7 +89,6 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) else path = args->argv[0]; if (strcmp(path, "-") == 0) { - c = cmdq->client; if (c == NULL) { cmdq_error(cmdq, "can't write to stdout"); return (CMD_RETURN_ERROR); @@ -100,28 +98,26 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) goto do_print; } - c = cmdq->client; - if (c != NULL) - wd = c->cwd; - else if ((s = cmd_current_session(cmdq, 0)) != NULL) { - wd = options_get_string(&s->options, "default-path"); - if (*wd == '\0') - wd = s->cwd; - } else - wd = NULL; - if (wd != NULL && *wd != '\0') { - newpath = get_full_path(wd, path); - if (newpath != NULL) - path = newpath; - } - - mask = umask(S_IRWXG | S_IRWXO); - if (args_has(self->args, 'a')) - f = fopen(path, "ab"); + if (c != NULL && c->session == NULL) + cwd = c->cwd; + else if ((s = cmd_current_session(cmdq, 0)) != NULL) + cwd = s->cwd; else - f = fopen(path, "wb"); - umask(mask); + cwd = AT_FDCWD; + + f = NULL; + if (args_has(self->args, 'a')) { + fd = openat(cwd, path, O_CREAT|O_RDWR|O_APPEND, 0600); + if (fd != -1) + f = fdopen(fd, "ab"); + } else { + fd = openat(cwd, path, O_CREAT|O_RDWR, 0600); + if (fd != -1) + f = fdopen(fd, "wb"); + } if (f == NULL) { + if (fd != -1) + close(fd); cmdq_error(cmdq, "%s: %s", path, strerror(errno)); return (CMD_RETURN_ERROR); } |