Darwin support for automatic-rename, from joshe.

pull/1/head
Nicholas Marriott 2009-01-20 22:17:53 +00:00
parent caa93f0e02
commit 8c259f562b
7 changed files with 67 additions and 11 deletions

View File

@ -1,5 +1,8 @@
20 January 2009
* Darwin support for automatic-rename from joshe; Darwin doesn't seem to have
a sane method of getting argv[0] and searching for the precise insane way
is too frustrating, so this just uses the executable name.
* Try to change the window title to match the command running it in. This is
done by reading argv[0] from the process group leader of the group that owns
the tty (tcgetpgrp()). This can't be done portably so some OS-dependent code
@ -983,7 +986,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.225 2009-01-20 19:35:03 nicm Exp $
$Id: CHANGES,v 1.226 2009-01-20 22:17:53 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms

View File

@ -1,4 +1,4 @@
# $Id: GNUmakefile,v 1.64 2009-01-20 20:00:39 nicm Exp $
# $Id: GNUmakefile,v 1.65 2009-01-20 22:17:53 nicm Exp $
.PHONY: clean
@ -41,7 +41,8 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
window-choose.c \
options.c options-cmd.c paste.c colour.c utf8.c clock.c \
tty.c tty-term.c tty-keys.c tty-write.c util.c names.c \
osdep-unknown.c osdep-openbsd.c osdep-freebsd.c osdep-linux.c
osdep-unknown.c osdep-openbsd.c osdep-freebsd.c osdep-linux.c \
osdep-darwin.c
CC?= gcc
INCDIRS+= -I. -I-

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.103 2009-01-20 19:35:03 nicm Exp $
# $Id: Makefile,v 1.104 2009-01-20 22:17:53 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean update-index.html upload-index.html
@ -45,7 +45,8 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
window-choose.c \
options.c options-cmd.c paste.c colour.c utf8.c clock.c \
tty.c tty-term.c tty-keys.c tty-write.c util.c names.c \
osdep-unknown.c osdep-openbsd.c osdep-freebsd.c osdep-linux.c
osdep-unknown.c osdep-openbsd.c osdep-freebsd.c osdep-linux.c \
osdep-darwin.c
CC?= cc
INCDIRS+= -I. -I- -I/usr/local/include

50
osdep-darwin.c Normal file
View File

@ -0,0 +1,50 @@
/* $Id: osdep-darwin.c,v 1.1 2009-01-20 22:17:53 nicm Exp $ */
/*
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
#include <stdlib.h>
char *get_argv0(pid_t);
/*
* XXX This actually returns the executable path, not the process's argv[0].
* Anyone who wishes to complain about this is welcome to grab a copy of
* Apple's 'ps' source and start digging.
*/
char *
get_argv0(pid_t pgrp)
{
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 };
size_t size;
struct kinfo_proc kp;
mib[3] = pgrp;
size = sizeof kp;
if (sysctl(mib, 4, &kp, &size, NULL, 0) == -1 ||
kp.kp_proc.p_comm[0] == '\0')
return (NULL);
return (strdup(kp.kp_proc.p_comm));
}
#endif

View File

@ -1,4 +1,4 @@
/* $Id: osdep-freebsd.c,v 1.1 2009-01-20 19:35:03 nicm Exp $ */
/* $Id: osdep-freebsd.c,v 1.2 2009-01-20 22:17:53 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -45,7 +45,7 @@ get_argv0(pid_t pgrp)
size = 128;
while (size < SIZE_MAX / 2) {
size *= 2;
if ((args2 = realloc(args, 2 * size)) == NULL)
if ((args2 = realloc(args, size)) == NULL)
break;
args = args2;
if (sysctl(mib, 4, args, &size, NULL, 0) == -1) {

View File

@ -1,4 +1,4 @@
/* $Id: osdep-openbsd.c,v 1.1 2009-01-20 19:35:03 nicm Exp $ */
/* $Id: osdep-openbsd.c,v 1.2 2009-01-20 22:17:53 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -44,7 +44,7 @@ get_argv0(pid_t pgrp)
size = 128;
while (size < SIZE_MAX / 2) {
size *= 2;
if ((args2 = realloc(args, 2 * size)) == NULL)
if ((args2 = realloc(args, size)) == NULL)
break;
args = args2;
if (sysctl(mib, 4, args, &size, NULL, 0) == -1) {

View File

@ -1,4 +1,4 @@
/* $Id: osdep-unknown.c,v 1.1 2009-01-20 19:35:03 nicm Exp $ */
/* $Id: osdep-unknown.c,v 1.2 2009-01-20 22:17:53 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -16,7 +16,8 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__linux__)
#if !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__linux__) && \
!defined(__APPLE__)
#include <sys/types.h>