Re: [PATCH] New option to get cwd of new windows from active window
Hi Matthias, Matthias Lederhofer mat...@gmx.net writes: Is it easily possible to disable this feature for new sessions, i.e. by putting something in the tmux.conf? I'm not sure what you're asking. If you want to disable the feature for any sessions created in your config file, then you can just set default-path explicitly for those sessions. Or you can use set -g, which will set the same default-path for all sessions and disable the feature globally. Additionally, I think it would be nice to be able to create windows either with the path of the current window or with the path of the session. Can this be accomplished yet? Hmm. I guess the new-session command could take an option to automatically set default-path to the session cwd at creation time. That would work, but it's not very clean. -- Romain Francoise rfranco...@debian.org http://people.debian.org/~rfrancoise/ -- Systems Optimization Self Assessment Improve efficiency and utilization of IT resources. Drive out cost and improve service delivery. Take 5 minutes to use this Systems Optimization Self Assessment. http://www.accelacomm.com/jaw/sdnl/114/51450054/ ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
Nicholas Marriott nicholas.marri...@gmail.com wrote: Thanks for this. The OpenBSD kernel bits are in so I've applied your diff with some minor tweaks and the required bits for osdep-openbsd.c. I really like this feature, currently I'm using a shell function to change the directory and additionally set the default-path. Maybe this will render this function unnecessary. However, I'm not too sure yet if I always like this feature. Is it easily possible to disable this feature for new sessions, i.e. by putting something in the tmux.conf? Additionally, I think it would be nice to be able to create windows either with the path of the current window or with the path of the session. Can this be accomplished yet? -- Learn Windows Azure Live! Tuesday, Dec 13, 2011 Microsoft is holding a special Learn Windows Azure training event for developers. It will provide a great way to learn Windows Azure and what it provides. You can attend the event by watching it streamed LIVE online. Learn more at http://p.sf.net/sfu/ms-windowsazure ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
Thanks for this. The OpenBSD kernel bits are in so I've applied your diff with some minor tweaks and the required bits for osdep-openbsd.c. Anyone wants to do AIX, Darwin, DFLY, HP/UX, or NetBSD send the code :-). On Tue, Dec 06, 2011 at 07:35:18PM +0100, Romain Francoise wrote: Nicholas Marriott nicholas.marri...@gmail.com writes: Ok, so OpenBSD should have a way to do this soon, either a new second-level sysctl KERN_PROC_CWD or a new third-level under KERN_PROC_ARGS. Don't worry about that though, let's move forward with your diff and I'll add OpenBSD when my code goes in. Awesome, thanks. Here's a v2 patch with the following changes: - logic updated as per your suggestion (note, default-path already defaults to ) - support for FreeBSD, tested on FreeBSD 8.2 - support for Solaris, untested but it's similar to Linux - doc updated for 'default-path' diff --git a/cmd-new-window.c b/cmd-new-window.c index 065e2b1..30ddd64 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -98,13 +98,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd = options_get_string(s-options, default-command); else cmd = args-argv[0]; - cwd = options_get_string(s-options, default-path); - if (*cwd == '\0') { - if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) - cwd = ctx-cmdclient-cwd; - else - cwd = s-cwd; - } + cwd = cmd_get_default_path(ctx); if (idx == -1) idx = -1 - options_get_number(s-options, base-index); diff --git a/cmd-split-window.c b/cmd-split-window.c index 258c632..7089193 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -77,13 +77,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd = options_get_string(s-options, default-command); else cmd = args-argv[0]; - cwd = options_get_string(s-options, default-path); - if (*cwd == '\0') { - if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) - cwd = ctx-cmdclient-cwd; - else - cwd = s-cwd; - } + cwd = cmd_get_default_path(ctx); type = LAYOUT_TOPBOTTOM; if (args_has(args, 'h')) diff --git a/cmd.c b/cmd.c index 2027f75..a1b96c3 100644 --- a/cmd.c +++ b/cmd.c @@ -1212,3 +1212,31 @@ cmd_template_replace(char *template, const char *s, int idx) return (buf); } + +/* + * Return a default path for new windows appropriate for this command + * context. + */ +char * +cmd_get_default_path(struct cmd_ctx *ctx) +{ + char*cwd; + struct session *s; + struct window_pane *wp; + + if ((s = cmd_current_session(ctx, 0)) == NULL) + return (NULL); + + cwd = options_get_string(s-options, default-path); + if (*cwd == '\0') { + if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) + return (ctx-cmdclient-cwd); + if (ctx-curclient != NULL) { + wp = s-curw-window-active; + if ((cwd = osdep_get_pid_cwd(wp-pid)) != NULL) + return (cwd); + } + return (s-cwd); + } + return (cwd); +} diff --git a/osdep-aix.c b/osdep-aix.c index 0dc07d6..02a650d 100644 --- a/osdep-aix.c +++ b/osdep-aix.c @@ -28,6 +28,12 @@ osdep_get_name(unused int fd, unused char *tty) return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-darwin.c b/osdep-darwin.c index 229a493..092adde 100644 --- a/osdep-darwin.c +++ b/osdep-darwin.c @@ -48,6 +48,12 @@ osdep_get_name(int fd, unused char *tty) return (strdup(kp.kp_proc.p_comm)); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-dragonfly.c b/osdep-dragonfly.c index b15abf9..6cb656f 100644 --- a/osdep-dragonfly.c +++ b/osdep-dragonfly.c @@ -119,6 +119,12 @@ error: return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-freebsd.c b/osdep-freebsd.c index 6b0c888..077a2c0 100644 --- a/osdep-freebsd.c +++ b/osdep-freebsd.c @@ -29,9 +29,11 @@ #include stdlib.h #include string.h #include unistd.h +#include libutil.h struct kinfo_proc*cmp_procs(struct kinfo_proc *, struct kinfo_proc *); char *osdep_get_name(int, char *); +char *osdep_get_pid_cwd(pid_t); struct event_base*osdep_event_init(void); #ifndef nitems @@ -130,6 +132,28 @@ error: return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + static char
Re: [PATCH] New option to get cwd of new windows from active window
This looks good apart from minor things, I'll take a better look later today hopefully. Thanks On Tue, Dec 06, 2011 at 07:35:18PM +0100, Romain Francoise wrote: Nicholas Marriott nicholas.marri...@gmail.com writes: Ok, so OpenBSD should have a way to do this soon, either a new second-level sysctl KERN_PROC_CWD or a new third-level under KERN_PROC_ARGS. Don't worry about that though, let's move forward with your diff and I'll add OpenBSD when my code goes in. Awesome, thanks. Here's a v2 patch with the following changes: - logic updated as per your suggestion (note, default-path already defaults to ) - support for FreeBSD, tested on FreeBSD 8.2 - support for Solaris, untested but it's similar to Linux - doc updated for 'default-path' diff --git a/cmd-new-window.c b/cmd-new-window.c index 065e2b1..30ddd64 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -98,13 +98,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd = options_get_string(s-options, default-command); else cmd = args-argv[0]; - cwd = options_get_string(s-options, default-path); - if (*cwd == '\0') { - if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) - cwd = ctx-cmdclient-cwd; - else - cwd = s-cwd; - } + cwd = cmd_get_default_path(ctx); if (idx == -1) idx = -1 - options_get_number(s-options, base-index); diff --git a/cmd-split-window.c b/cmd-split-window.c index 258c632..7089193 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -77,13 +77,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd = options_get_string(s-options, default-command); else cmd = args-argv[0]; - cwd = options_get_string(s-options, default-path); - if (*cwd == '\0') { - if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) - cwd = ctx-cmdclient-cwd; - else - cwd = s-cwd; - } + cwd = cmd_get_default_path(ctx); type = LAYOUT_TOPBOTTOM; if (args_has(args, 'h')) diff --git a/cmd.c b/cmd.c index 2027f75..a1b96c3 100644 --- a/cmd.c +++ b/cmd.c @@ -1212,3 +1212,31 @@ cmd_template_replace(char *template, const char *s, int idx) return (buf); } + +/* + * Return a default path for new windows appropriate for this command + * context. + */ +char * +cmd_get_default_path(struct cmd_ctx *ctx) +{ + char*cwd; + struct session *s; + struct window_pane *wp; + + if ((s = cmd_current_session(ctx, 0)) == NULL) + return (NULL); + + cwd = options_get_string(s-options, default-path); + if (*cwd == '\0') { + if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) + return (ctx-cmdclient-cwd); + if (ctx-curclient != NULL) { + wp = s-curw-window-active; + if ((cwd = osdep_get_pid_cwd(wp-pid)) != NULL) + return (cwd); + } + return (s-cwd); + } + return (cwd); +} diff --git a/osdep-aix.c b/osdep-aix.c index 0dc07d6..02a650d 100644 --- a/osdep-aix.c +++ b/osdep-aix.c @@ -28,6 +28,12 @@ osdep_get_name(unused int fd, unused char *tty) return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-darwin.c b/osdep-darwin.c index 229a493..092adde 100644 --- a/osdep-darwin.c +++ b/osdep-darwin.c @@ -48,6 +48,12 @@ osdep_get_name(int fd, unused char *tty) return (strdup(kp.kp_proc.p_comm)); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-dragonfly.c b/osdep-dragonfly.c index b15abf9..6cb656f 100644 --- a/osdep-dragonfly.c +++ b/osdep-dragonfly.c @@ -119,6 +119,12 @@ error: return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-freebsd.c b/osdep-freebsd.c index 6b0c888..077a2c0 100644 --- a/osdep-freebsd.c +++ b/osdep-freebsd.c @@ -29,9 +29,11 @@ #include stdlib.h #include string.h #include unistd.h +#include libutil.h struct kinfo_proc*cmp_procs(struct kinfo_proc *, struct kinfo_proc *); char *osdep_get_name(int, char *); +char *osdep_get_pid_cwd(pid_t); struct event_base*osdep_event_init(void); #ifndef nitems @@ -130,6 +132,28 @@ error: return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + static char wd[PATH_MAX]; + struct kinfo_file *info = NULL; + int nrecords, i; + + if ((info =
Re: [PATCH] New option to get cwd of new windows from active window
Nicholas Marriott nicholas.marri...@gmail.com writes: Ok, so OpenBSD should have a way to do this soon, either a new second-level sysctl KERN_PROC_CWD or a new third-level under KERN_PROC_ARGS. Don't worry about that though, let's move forward with your diff and I'll add OpenBSD when my code goes in. Awesome, thanks. Here's a v2 patch with the following changes: - logic updated as per your suggestion (note, default-path already defaults to ) - support for FreeBSD, tested on FreeBSD 8.2 - support for Solaris, untested but it's similar to Linux - doc updated for 'default-path' diff --git a/cmd-new-window.c b/cmd-new-window.c index 065e2b1..30ddd64 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -98,13 +98,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd = options_get_string(s-options, default-command); else cmd = args-argv[0]; - cwd = options_get_string(s-options, default-path); - if (*cwd == '\0') { - if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) - cwd = ctx-cmdclient-cwd; - else - cwd = s-cwd; - } + cwd = cmd_get_default_path(ctx); if (idx == -1) idx = -1 - options_get_number(s-options, base-index); diff --git a/cmd-split-window.c b/cmd-split-window.c index 258c632..7089193 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -77,13 +77,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd = options_get_string(s-options, default-command); else cmd = args-argv[0]; - cwd = options_get_string(s-options, default-path); - if (*cwd == '\0') { - if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) - cwd = ctx-cmdclient-cwd; - else - cwd = s-cwd; - } + cwd = cmd_get_default_path(ctx); type = LAYOUT_TOPBOTTOM; if (args_has(args, 'h')) diff --git a/cmd.c b/cmd.c index 2027f75..a1b96c3 100644 --- a/cmd.c +++ b/cmd.c @@ -1212,3 +1212,31 @@ cmd_template_replace(char *template, const char *s, int idx) return (buf); } + +/* + * Return a default path for new windows appropriate for this command + * context. + */ +char * +cmd_get_default_path(struct cmd_ctx *ctx) +{ + char*cwd; + struct session *s; + struct window_pane *wp; + + if ((s = cmd_current_session(ctx, 0)) == NULL) + return (NULL); + + cwd = options_get_string(s-options, default-path); + if (*cwd == '\0') { + if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) + return (ctx-cmdclient-cwd); + if (ctx-curclient != NULL) { + wp = s-curw-window-active; + if ((cwd = osdep_get_pid_cwd(wp-pid)) != NULL) + return (cwd); + } + return (s-cwd); + } + return (cwd); +} diff --git a/osdep-aix.c b/osdep-aix.c index 0dc07d6..02a650d 100644 --- a/osdep-aix.c +++ b/osdep-aix.c @@ -28,6 +28,12 @@ osdep_get_name(unused int fd, unused char *tty) return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-darwin.c b/osdep-darwin.c index 229a493..092adde 100644 --- a/osdep-darwin.c +++ b/osdep-darwin.c @@ -48,6 +48,12 @@ osdep_get_name(int fd, unused char *tty) return (strdup(kp.kp_proc.p_comm)); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-dragonfly.c b/osdep-dragonfly.c index b15abf9..6cb656f 100644 --- a/osdep-dragonfly.c +++ b/osdep-dragonfly.c @@ -119,6 +119,12 @@ error: return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-freebsd.c b/osdep-freebsd.c index 6b0c888..077a2c0 100644 --- a/osdep-freebsd.c +++ b/osdep-freebsd.c @@ -29,9 +29,11 @@ #include stdlib.h #include string.h #include unistd.h +#include libutil.h struct kinfo_proc *cmp_procs(struct kinfo_proc *, struct kinfo_proc *); char *osdep_get_name(int, char *); +char *osdep_get_pid_cwd(pid_t); struct event_base *osdep_event_init(void); #ifndef nitems @@ -130,6 +132,28 @@ error: return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + static char wd[PATH_MAX]; + struct kinfo_file *info = NULL; + int nrecords, i; + + if ((info = kinfo_getfile(pid, nrecords)) == NULL) + return (NULL); + + for (i = 0; i nrecords; i++) { + if (info[i].kf_fd == KF_FD_TYPE_CWD) { + strlcpy(wd, info[i].kf_path,
Re: [PATCH] New option to get cwd of new windows from active window
marcel partap mpar...@gmx.net writes: ..just for reference, from konsole/src/ProcessInfo.cpp, includes omitted: [...] Thanks, that was useful. -- Romain Francoise rfranco...@debian.org http://people.debian.org/~rfrancoise/ -- Cloud Services Checklist: Pricing and Packaging Optimization This white paper is intended to serve as a reference, checklist and point of discussion for anyone considering optimizing the pricing and packaging model of a cloud services business. Read Now! http://www.accelacomm.com/jaw/sfnl/114/51491232/ ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
..just for reference, from konsole/src/ProcessInfo.cpp, includes omitted: virtual bool LinuxProcessInfo::readCurrentDir(int pid) { QFileInfo info( QString(/proc/%1/cwd).arg(pid) ); const bool readable = info.isReadable(); if ( readable info.isSymLink() ) { setCurrentDir( info.symLinkTarget() ); return true; } else { if ( !readable ) setError( PermissionsError ); else setError( UnknownError ); return false; } } virtual bool FreeBSDProcessInfo::readCurrentDir(int pid) { #if defined(__DragonFly__) char buf[PATH_MAX]; int managementInfoBase[4]; size_t len; managementInfoBase[0] = CTL_KERN; managementInfoBase[1] = KERN_PROC; managementInfoBase[2] = KERN_PROC_CWD; managementInfoBase[3] = pid; len = sizeof(buf); if (sysctl(managementInfoBase, 4, buf, len, NULL, 0) == -1) return false; setCurrentDir(buf); return true; #else int numrecords; struct kinfo_file* info = 0; info = kinfo_getfile(pid, numrecords); if (!info) return false; for (int i = 0; i numrecords; ++i) { if (info[i].kf_fd == KF_FD_TYPE_CWD) { setCurrentDir(info[i].kf_path); free(info); return true; } } free(info); return false; #endif } virtual bool SolarisProcessInfo::readCurrentDir(int pid) { QFileInfo info( QString(/proc/%1/path/cwd).arg(pid) ); const bool readable = info.isReadable(); if ( readable info.isSymLink() ) { setCurrentDir( info.symLinkTarget() ); return true; } else { if ( !readable ) setError( PermissionsError ); else setError( UnknownError ); return false; } } virtual bool MacProcessInfo::readCurrentDir(int pid) { struct proc_vnodepathinfo vpi; int nb = proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0, vpi, sizeof(vpi)); if (nb == sizeof(vpi)) { setCurrentDir(QString(vpi.pvi_cdir.vip_path)); return true; } return false; } virtual bool readEnvironment(int pid) { Q_UNUSED(pid); return false; } ...cross platform FAiL ^^ #regards|marcel C; -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
Cool. So basically we need to implement KERN_PROC_CWD on OpenBSD, although I don't think I would do it the way DragonFly does, I would probably add a new level 3 sysctl like KERN_PROC_ARGS. Lemme see if I have time to look at it this week. On Mon, Dec 05, 2011 at 10:08:55AM +0100, marcel partap wrote: ..just for reference, from konsole/src/ProcessInfo.cpp, includes omitted: virtual bool LinuxProcessInfo::readCurrentDir(int pid) { QFileInfo info( QString(/proc/%1/cwd).arg(pid) ); const bool readable = info.isReadable(); if ( readable info.isSymLink() ) { setCurrentDir( info.symLinkTarget() ); return true; } else { if ( !readable ) setError( PermissionsError ); else setError( UnknownError ); return false; } } virtual bool FreeBSDProcessInfo::readCurrentDir(int pid) { #if defined(__DragonFly__) char buf[PATH_MAX]; int managementInfoBase[4]; size_t len; managementInfoBase[0] = CTL_KERN; managementInfoBase[1] = KERN_PROC; managementInfoBase[2] = KERN_PROC_CWD; managementInfoBase[3] = pid; len = sizeof(buf); if (sysctl(managementInfoBase, 4, buf, len, NULL, 0) == -1) return false; setCurrentDir(buf); return true; #else int numrecords; struct kinfo_file* info = 0; info = kinfo_getfile(pid, numrecords); if (!info) return false; for (int i = 0; i numrecords; ++i) { if (info[i].kf_fd == KF_FD_TYPE_CWD) { setCurrentDir(info[i].kf_path); free(info); return true; } } free(info); return false; #endif } virtual bool SolarisProcessInfo::readCurrentDir(int pid) { QFileInfo info( QString(/proc/%1/path/cwd).arg(pid) ); const bool readable = info.isReadable(); if ( readable info.isSymLink() ) { setCurrentDir( info.symLinkTarget() ); return true; } else { if ( !readable ) setError( PermissionsError ); else setError( UnknownError ); return false; } } virtual bool MacProcessInfo::readCurrentDir(int pid) { struct proc_vnodepathinfo vpi; int nb = proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0, vpi, sizeof(vpi)); if (nb == sizeof(vpi)) { setCurrentDir(QString(vpi.pvi_cdir.vip_path)); return true; } return false; } virtual bool readEnvironment(int pid) { Q_UNUSED(pid); return false; } ...cross platform FAiL ^^ #regards|marcel C; -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
I think I spoke too fast. KERN_FILE_BYPID only gives you the inode number of the cwd and the mountpoint of the filesystem where it's located. Finding the name of the directory from that requires walking the entire filesystem, which is obviously out of the question... So I guess we're back to square one. -- Romain Francoise rfranco...@debian.org http://people.debian.org/~rfrancoise/ -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
Nicholas Marriott nicholas.marri...@gmail.com writes: Can we do this on ANY platform apart from Linux? Solaris, with procfs. That's about it, I think. -- Romain Francoise rfranco...@debian.org http://people.debian.org/~rfrancoise/ -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
On Sun, Dec 04, 2011 at 03:58:36PM +0100, Romain Francoise wrote: I think I spoke too fast. KERN_FILE_BYPID only gives you the inode number of the cwd and the mountpoint of the filesystem where it's located. Hm. That sucks... looks like getcwd() works by walking each vnode on the way up to build a path. Can we do this on ANY platform apart from Linux? On OS X you can get the pwd of a process you own like this: struct proc_vnodepathinfo vpi; int ret; ret = proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0, vpi, sizeof(vpi)); if (ret == sizeof(vpi)) { return vpi.pvi_cdir.vip_path; } -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
I figured this would be controversial... First some context: this was originally filed a wishlist request in the Debian BTS. I replied that the only way to keep the cwd is to use the client, and that achieving this from keys would involve non-portable ways of getting the working directory and so wasn't possible. But after thinking about it some more I decided to try it out anyway, and found that it's quite useful in contexts where you're working on something in one window, the window gets blocked by something long-running (like make, tig, or whatever) and you want to run something else in the meantime. It's more convenient to quickly create/destroy a pane than to background or interrupt whatever you're running in the first pane and when you do that, not having to cd back to where you were working is very convenient. It seems that this is often requested by users, it's in the FAQ and also mentioned in various places: http://unix.stackexchange.com/questions/12032/ https://wiki.archlinux.org/index.php/Tmux#Split_window_and_retain_current_directory so I think that the potential benefits to users outweigh the relative ugliness of having non-portable code (and platform-differentiated features) in tmux. I'm not interested in workarounds which involve running the client from a key via run-shell, tmux can do that efficiently by itself as the patch shows. Anyway, I looked at the various BSDs and FreeBSD exports the required info via KERN_PROC_PGRP (that probably covers Dragonfly as well). For NetBSD and OpenBSD I didn't find anything, the kinfo_proc interface is different. But maybe I'm wrong. Is it really a hard requirement to have it work on all BSDs even if it's not enabled by default? I'd really like to avoid having to carry this feature as a Debian patch. Thanks, -- Romain Francoise rfranco...@debian.org http://people.debian.org/~rfrancoise/ -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
Yeah it has to work on OpenBSD and preferably FreeBSD too.I think you can probably use sysctl KERN_FILE, KERN_FILE_BYPID and look for KERN_FILE_CDIR in fd_fd on OpenBSD at least. I don't think we need a new option, why not make default-path default to and override the automatic inheriting if it's changed to something else? On Thu, Dec 01, 2011 at 08:32:38PM +0100, Romain Francoise wrote: I figured this would be controversial... First some context: this was originally filed a wishlist request in the Debian BTS. I replied that the only way to keep the cwd is to use the client, and that achieving this from keys would involve non-portable ways of getting the working directory and so wasn't possible. But after thinking about it some more I decided to try it out anyway, and found that it's quite useful in contexts where you're working on something in one window, the window gets blocked by something long-running (like make, tig, or whatever) and you want to run something else in the meantime. It's more convenient to quickly create/destroy a pane than to background or interrupt whatever you're running in the first pane and when you do that, not having to cd back to where you were working is very convenient. It seems that this is often requested by users, it's in the FAQ and also mentioned in various places: http://unix.stackexchange.com/questions/12032/ https://wiki.archlinux.org/index.php/Tmux#Split_window_and_retain_current_directory so I think that the potential benefits to users outweigh the relative ugliness of having non-portable code (and platform-differentiated features) in tmux. I'm not interested in workarounds which involve running the client from a key via run-shell, tmux can do that efficiently by itself as the patch shows. Anyway, I looked at the various BSDs and FreeBSD exports the required info via KERN_PROC_PGRP (that probably covers Dragonfly as well). For NetBSD and OpenBSD I didn't find anything, the kinfo_proc interface is different. But maybe I'm wrong. Is it really a hard requirement to have it work on all BSDs even if it's not enabled by default? I'd really like to avoid having to carry this feature as a Debian patch. Thanks, -- Romain Francoise rfranco...@debian.org http://people.debian.org/~rfrancoise/ -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
On Wed, Nov 30, 2011 at 09:48:31PM +0100, Romain Francoise wrote: Hi, This patch adds a new session option 'inherit-default-path' and the associated machinery to create new windows/panes in the same working directory as the active window instead of using the value of default-path. It affects only windows created from keys or the command prompt. Why, when this is in the tmux FAQ? How can I open a new window in the same directory as the current window? -- Thomas Adam -- Deep in my heart I wish I was wrong. But deep in my heart I know I am not. -- Morrissey (Girl Least Likely To -- off of Viva Hate.) -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
Thomas Adam tho...@xteddy.org writes: Why, when this is in the tmux FAQ? The solution in the FAQ is ugly. -- Romain Francoise rfranco...@debian.org http://people.debian.org/~rfrancoise/ -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: [PATCH] New option to get cwd of new windows from active window
I'm genuinely not delighted about more OS-dependent code. Is there no portable solution to this? Even if it isn't quite as good. Otherwise, what's the use case here? I love that you sent code but how inconvenient is it to have more OS-dependent code verses the actual issue? And how inconvenient the solution in the FAQ is? If this is to be supported it is going to need to work on at least *BSD without procfs, which is a more unportable code... On Wed, Nov 30, 2011 at 09:48:31PM +0100, Romain Francoise wrote: Hi, This patch adds a new session option 'inherit-default-path' and the associated machinery to create new windows/panes in the same working directory as the active window instead of using the value of default-path. It affects only windows created from keys or the command prompt. Note that only Linux is supported for now, Solaris and FreeBSD (with linprocfs) may be added later. Not sure if the others have the required interface. Comments welcome, diff --git a/cmd-new-window.c b/cmd-new-window.c index 065e2b1..30ddd64 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -98,13 +98,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd = options_get_string(s-options, default-command); else cmd = args-argv[0]; - cwd = options_get_string(s-options, default-path); - if (*cwd == '\0') { - if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) - cwd = ctx-cmdclient-cwd; - else - cwd = s-cwd; - } + cwd = cmd_get_default_path(ctx); if (idx == -1) idx = -1 - options_get_number(s-options, base-index); diff --git a/cmd-split-window.c b/cmd-split-window.c index 258c632..7089193 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -77,13 +77,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd = options_get_string(s-options, default-command); else cmd = args-argv[0]; - cwd = options_get_string(s-options, default-path); - if (*cwd == '\0') { - if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) - cwd = ctx-cmdclient-cwd; - else - cwd = s-cwd; - } + cwd = cmd_get_default_path(ctx); type = LAYOUT_TOPBOTTOM; if (args_has(args, 'h')) diff --git a/cmd.c b/cmd.c index 2027f75..c67dbed 100644 --- a/cmd.c +++ b/cmd.c @@ -1212,3 +1212,35 @@ cmd_template_replace(char *template, const char *s, int idx) return (buf); } + +/* + * Return a default path for new windows appropriate for this command + * context. + */ +char * +cmd_get_default_path(struct cmd_ctx *ctx) +{ + char*cwd; + struct session *s; + struct window_pane *wp; + + if ((s = cmd_current_session(ctx, 0)) == NULL) + return (NULL); + wp = s-curw-window-active; + + if (ctx-curclient != NULL + options_get_number(s-options, inherit-default-path)) { + if ((cwd = osdep_get_pid_cwd(wp-pid)) != NULL) + return (cwd); + } + + cwd = options_get_string(s-options, default-path); + if (*cwd == '\0') { + if (ctx-cmdclient != NULL ctx-cmdclient-cwd != NULL) + cwd = ctx-cmdclient-cwd; + else + cwd = s-cwd; + } + + return (cwd); +} diff --git a/options-table.c b/options-table.c index 2700536..4bc2805 100644 --- a/options-table.c +++ b/options-table.c @@ -166,6 +166,11 @@ const struct options_table_entry session_options_table[] = { .default_num = 2000 }, + { .name = inherit-default-path, + .type = OPTIONS_TABLE_FLAG, + .default_num = 0 + }, + { .name = lock-after-time, .type = OPTIONS_TABLE_NUMBER, .minimum = 0, diff --git a/osdep-aix.c b/osdep-aix.c index 0dc07d6..02a650d 100644 --- a/osdep-aix.c +++ b/osdep-aix.c @@ -28,6 +28,12 @@ osdep_get_name(unused int fd, unused char *tty) return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-darwin.c b/osdep-darwin.c index 229a493..092adde 100644 --- a/osdep-darwin.c +++ b/osdep-darwin.c @@ -48,6 +48,12 @@ osdep_get_name(int fd, unused char *tty) return (strdup(kp.kp_proc.p_comm)); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git a/osdep-dragonfly.c b/osdep-dragonfly.c index b15abf9..6cb656f 100644 --- a/osdep-dragonfly.c +++ b/osdep-dragonfly.c @@ -119,6 +119,12 @@ error: return (NULL); } +char * +osdep_get_pid_cwd(pid_t pid) +{ + return (NULL); +} + struct event_base * osdep_event_init(void) { diff --git