30 Commits
Author SHA1 Message Date
Nicolas Viennot 80f9e84b83 Release 1.8.3 2013-06-14 22:39:28 -04:00
Nicolas Viennot 53355a0b92 Bug fix: $TMUX wasn't being reused properly 2013-06-14 22:39:21 -04:00
Nicolas Viennot 16dd13979e Ubuntu complains without the README 2013-06-14 22:11:13 -04:00
Nicolas Viennot 12d681d8cc Change connection string tmate.io -> master.tmate.io 2013-06-14 22:11:12 -04:00
Nicolas Viennot 5d847fb0aa Random socket path (we don't support multi sessions) 2013-06-14 15:35:39 -04:00
Nicolas Viennot a50dcb09b5 Notification messages 2013-06-13 05:15:08 -04:00
Nicolas Viennot edd194c23c Synchronize copy-mode 2013-06-13 02:34:59 -04:00
Nicolas Viennot fc4eaeb89f TERM defaults to screen-256color 2013-06-13 02:34:58 -04:00
Nicolas Viennot e52312ec3c Report failed commands to slave
which will in turn notify the proper client
2013-06-12 20:33:58 -04:00
Nicolas Viennot 844451c6ce Show tmate messages in the status bar 2013-06-12 19:47:36 -04:00
Nicolas Viennot a1d7bf7dc0 No reconnection for now 2013-06-12 18:02:29 -04:00
Nicolas Viennot 2dca2c0fd5 Synching winlinks idx instead of window ids 2013-06-12 17:58:31 -04:00
Nicolas Viennot e70a5f8b7f Add strack trace debug function 2013-06-12 17:57:53 -04:00
Nicolas Viennot a4e196366e Quick README 2013-06-12 16:30:04 -04:00
Nicolas Viennot 69bc1bfde5 Sync all session windows 2013-06-12 03:19:42 -04:00
Nicolas Viennot bf4edb4056 Authenticating the server 2013-06-12 01:28:01 -04:00
Nicolas Viennot 141428691e Status bar sync 2013-06-11 23:50:16 -04:00
Nicolas Viennot 35daf6d805 Replication of bind/unbind commands 2013-06-11 22:52:21 -04:00
Nicolas Viennot 839c4e3dd9 Replicate remote client commands 2013-06-11 22:32:49 -04:00
Nicolas Viennot b7371802bf Developer Environement setup 2013-06-11 17:00:50 -04:00
Nicolas Viennot f89b98e1c3 Use tmate.io 2013-06-11 13:30:25 -04:00
Nicolas Viennot 6988b99fb4 Enable compression 2013-06-10 05:59:59 -04:00
Nicolas Viennot 56cee30ee8 [libssh] fix server side compression 2013-06-10 05:59:59 -04:00
Nicolas Viennot 7cdb1e2016 [libssh] bug fix in channel_open() 2013-06-10 04:30:12 -04:00
Nicolas Viennot 8131143fa8 gitignore update 2013-06-10 04:30:12 -04:00
Nicolas Viennot a75e70f86b Fix error message 2013-06-10 04:30:12 -04:00
Nicolas Viennot 864124f4c0 Public key auth no longer need to be blocking (libssh 0.6) 2013-06-10 02:50:07 -04:00
Nicolas Viennot 05de59d106 Adding msgpack 2013-06-10 02:50:07 -04:00
Nicolas Viennot 0f7ccda4fb Adding libssh 2013-06-10 02:50:07 -04:00
Nicolas Viennot 220b2afb3c Client side first shot 2013-06-10 01:54:57 -04:00
488 changed files with 80152 additions and 8107 deletions
+4 -2
View File
@@ -6,7 +6,6 @@
core
tags
.deps/
compat/.dirstamp
aclocal.m4
autom4te.cache/
config.log
@@ -16,4 +15,7 @@ tmux
Makefile
Makefile.in
configure
tmux.1.*
tmate
cscope.*
ctags
*.log
+8 -69
View File
@@ -1,69 +1,3 @@
CHANGES FROM 1.9 to 1.9a 22 February 2014
NOTE: This is a bug-fix release to address some important bugs which just
missed the 1.9 deadline, but were found afterwards.
Normal Changes
==============
* Fix crash due to uninitialized lastwp member of layout_cell
* Fix -fg/-bg/-style with 256 colour terminals.
CHANGES FROM 1.8 to 1.9, 20 February 2014
NOTE: This release has bumped the tmux protocol version. It is therefore
advised that the prior tmux server is restarted when this version of tmux is
installed, to avoid protocol mismatch errors for newer clients trying to
talk to an older running tmux server.
Incompatible Changes
====================
* 88 colour support has been removed.
* 'default-path' has been removed. The new-window command accepts '-c' to
cater for this. The previous value of "." can be replaced with: 'neww -c
$PWD', the previous value of '' which meant current path of the pane can
be specified as: 'neww -c "#{pane_current_path}"'
Deprecated Changes
==================
* The single format specifiers: #A -> #Z (where defined) have been
deprecated and replaced with longer-named equivalents, as listed in the
FORMATS section of the tmux manpage.
* The various foo-{fg,bg,attr} commands have been deprecated and replaced
with equivalent foo-style option instead. Currently this is still
backwards-compatible, but will be removed over time.
Normal Changes
==============
* A new environment variable TMUX_TMPDIR is now honoured, allowing the
socket directory to be set outside of TMPDIR (/tmp/ if not set).
* If -s not given to swap-pane the current pane is assumed.
* A #{pane_syncronized} format specifier has been added to be a conditional
format if a pane is in a syncronised mode (c.f. syncronize-panes)
* Tmux now runs under Cygwin natively.
* Formats can now be nested within each other and expanded accordingly.
* Added 'automatic-rename-format' option to allow the automatic rename
mechanism to use something other than the default of
#{pane_current_command}.
* new-session learnt '-c' to specify the starting directory for that session
and all subsequent windows therein.
* The session name is now shown in the message printed to the terminal when
a session is detached.
* Lots more format specifiers have been added.
* Server race conditions have been fixed; in particular commands are not run
until after the configuration file is read completely.
* Case insensitive searching in tmux's copy-mode is now possible.
* attach-session and switch-client learnt the '-t' option to accept a window
and/or a pane to use.
* Copy-mode is only exited if no selection is in progress.
* Paste key in copy-mode is now possible to enter text from the clipboard.
* status-interval set to '0' now works as intended.
* tmux now supports 256 colours running under fbterm.
* Many bug fixes!
CHANGES FROM 1.7 to 1.8, 26 March 2013
Incompatible Changes
@@ -83,7 +17,7 @@ Normal Changes
* run-shell learnt '-t' to specify the pane to use when displaying output.
* Support for middle-click pasting.
* choose-tree learns '-u' to start uncollapsed.
* select-window learnt '-T' to toggle to the last window if it's already
* select-window learnt '-T; to toggle to the last window if it's already
current.
* New session option 'assume-paste-time' for pasting text versus key-binding
actions.
@@ -103,9 +37,9 @@ Normal Changes
the 'source-file' command.
* 'copy-pipe' mode command to copy selection and pipe the selection to a
command.
* Panes can now emit focus notifications for certain applications
* Changes panes can now emit focus notifications for certain applications
which use those.
* run-shell and if-shell now accept formats.
* run-shell and if-shell now accept format placeholders.
* resize-pane learnt '-Z' for zooming a pane temporarily.
* new-session learnt '-A' to make it behave like attach-session.
* set-option learnt '-o' to prevent setting an option which is already set.
@@ -1867,3 +1801,8 @@ The list of older changes is below.
customisation.
$Id$
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
LocalWords: dstidx srcname srcidx winlink lsw nabc sabc Exp Tiago Cunha dch
LocalWords: setw Chisnall renamew merdely eg Maier newname selectw neww Gass
-21
View File
@@ -1,21 +0,0 @@
THIS IS FOR INFORMATION ONLY, CODE IS UNDER THE LICENCE AT THE TOP OF ITS FILE.
The README, CHANGES, FAQ and TODO files are licensed under the ISC
license. Files under examples/ remain copyright their authors unless otherwise
stated in the file but permission has been received to distribute them with
tmux. All other files have a license and copyright notice at their start,
typically:
Copyright (c) <author>
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.
+4 -69
View File
@@ -95,6 +95,9 @@ aware of are (bearing in mind I haven't used screen for a few years now):
- screen has builtin serial and telnet support; this is bloat and is unlikely
to be added to tmux.
- screen has support for updating utmp. Nobody has really come up with a clean,
portable way to do this without making tmux setuid or setgid yet.
- Environment handling is different.
- tmux tends to be more demanding on the terminal so tends to show up terminal
@@ -104,10 +107,6 @@ aware of are (bearing in mind I haven't used screen for a few years now):
* I found a bug! What do I do?
Check the latest version of tmux from Git to see if the problem is still
reproducible. Sometimes the length of time between releases means a lot of
fixes can be sitting in Git and the problem might already be fixed.
Please send bug reports by email to nicm@users.sourceforge.net or
tmux-users@lists.sourceforge.net. Please include as much of the following
information as possible:
@@ -239,31 +238,6 @@ would be welcome.
vim users may also want to set the "ttyfast" option inside tmux.
* How do I make ctrl and shift arrow keys work in emacs?
The terminal-init-screen function in term/screen.el is called for new frames,
but it doesn't configure any function keys.
If the tmux xterm-keys option is on, it is enough to define the same keys as
xterm. Add the following to init.el or .emacs to do this:
(defadvice terminal-init-screen
;; The advice is named `tmux', and is run before `terminal-init-screen' runs.
(before tmux activate)
;; Docstring. This describes the advice and is made available inside emacs;
;; for example when doing C-h f terminal-init-screen RET
"Apply xterm keymap, allowing use of keys passed through tmux."
;; This is the elisp code that is run before `terminal-init-screen'.
(if (getenv "TMUX")
(let ((map (copy-keymap xterm-function-map)))
(set-keymap-parent map (keymap-parent input-decode-map))
(set-keymap-parent input-decode-map map))))
And ensure .tmux.conf contains "set -g xterm-keys on".
Alternatively, the screen.el file can be copied to the load path and
customized.
* Why doesn't elinks set the window title inside tmux?
There isn't a way to detect if a terminal supports setting the window title, so
@@ -403,7 +377,7 @@ always (or ever) be added to the scrollback.
You can make tmux use the normal screen by telling it that your terminal does
not have an alternate screen. Put the following in ~/.tmux.conf:
set -ga terminal-overrides ',xterm*:smcup@:rmcup@'
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
Adjust if your $TERM does not start with xterm.
@@ -422,44 +396,5 @@ configuration file:
Or the default window options:
$ tmux -Lfoo -f/dev/null start\; show -gw
* How do I copy a selection from tmux to the system's clipboard?
When running in xterm(1), tmux can automatically send copied text to the
clipboard. This is controlled by the set-clipboard option and also needs this
X resource to be set:
XTerm*disallowedWindowOps: 20,21,SetXprop
For rxvt-unicode (urxvt), there is an unofficial Perl extension here:
http://anti.teamidiot.de/static/nei/*/Code/urxvt/
Otherwise a key binding for copy mode using xclip (or xsel) works:
bind -temacs-copy C-y copy-pipe "xclip -i >/dev/null"
Or for inside and outside copy mode with the prefix key:
bind C-y run -b "tmux save-buffer - | xclip -i"
On OS X, reattach-to-usernamespace lets pbcopy/pbpaste work:
https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
* Why do I see dots around a session when I attach to it?
tmux limits the size of the window to the smallest attached session. If
it didn't do this then it would be impossible to see the entire window.
The dots mark the size of the window tmux can display.
To avoid this, detach all other clients when attaching:
$ tmux attach -d
Or from inside tmux by detaching individual clients with C-b D or all
using:
C-b : attach -d
$Id$
+63 -68
View File
@@ -1,20 +1,19 @@
# $Id$
# Obvious program stuff.
bin_PROGRAMS = tmux
CLEANFILES = tmux.1.mdoc tmux.1.man
bin_PROGRAMS = tmate
dist_man1_MANS = tmate.1
# Distribution tarball options.
EXTRA_DIST = \
CHANGES FAQ README TODO COPYING examples compat \
array.h compat.h tmux.h osdep-*.c mdoc2man.awk tmux.1
CHANGES FAQ README TODO examples compat \
array.h compat.h tmux.h osdep-*.c
dist-hook:
make clean
grep "^#found_debug=" configure
find $(distdir) -name .svn -type d|xargs rm -Rf
# Preprocessor flags.
CPPFLAGS += @XOPEN_DEFINES@ -DTMUX_CONF="\"$(sysconfdir)/tmux.conf\""
CPPFLAGS += @XOPEN_DEFINES@
# glibc as usual does things ass-backwards and hides useful things by default,
# so everyone has to add this.
@@ -22,37 +21,41 @@ if IS_GLIBC
CFLAGS += -D_GNU_SOURCE
endif
CFLAGS += -Wno-unused-parameter -Wno-unused-variable
CFLAGS += -Ilibssh/include/ -Imsgpack/src
if IS_DEVENV
CFLAGS += -DDEVENV
endif
# Set flags for gcc. gcc4 whines abouts silly stuff so it needs slightly
# different flags.
if IS_GCC
CFLAGS += -std=gnu99 -O2
CFLAGS += -std=gnu99
if IS_DEBUG
CFLAGS += -g
CFLAGS += -O0 -g
CFLAGS += -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
CFLAGS += -Wdeclaration-after-statement
CFLAGS += -Wbad-function-cast -Winline -Wcast-align
CPPFLAGS += -DDEBUG
else
CFLAGS += -O2
endif
if IS_GCC4
CPPFLAGS += -iquote.
CPPFLAGS += -iquote. -I/usr/local/include
if IS_DEBUG
CFLAGS += -Wno-pointer-sign
endif
else
CPPFLAGS += -I. -I-
CPPFLAGS += -I. -I- -I/usr/local/include
endif
endif
# Set flags for Solaris.
if IS_SUNOS
if IS_GCC
CPPFLAGS += -D_XPG6 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
else
CPPFLAGS += -D_XPG4_2 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
endif
endif
# Set flags for Sun CC.
if IS_SUNCC
@@ -60,19 +63,22 @@ CFLAGS += -erroff=E_EMPTY_DECLARATION
endif
# List of sources.
dist_tmux_SOURCES = \
dist_tmate_SOURCES = \
arguments.c \
attributes.c \
cfg.c \
client.c \
clock.c \
cmd-attach-session.c \
cmd-bind-key.c \
cmd-break-pane.c \
cmd-capture-pane.c \
cmd-choose-buffer.c \
cmd-choose-client.c \
cmd-choose-list.c \
cmd-choose-tree.c \
cmd-clear-history.c \
cmd-clock-mode.c \
cmd-command-prompt.c \
cmd-confirm-before.c \
cmd-copy-mode.c \
@@ -81,14 +87,17 @@ dist_tmux_SOURCES = \
cmd-display-message.c \
cmd-display-panes.c \
cmd-find-window.c \
cmd-has-session.c \
cmd-if-shell.c \
cmd-join-pane.c \
cmd-kill-pane.c \
cmd-kill-server.c \
cmd-kill-session.c \
cmd-kill-window.c \
cmd-link-window.c \
cmd-list-buffers.c \
cmd-list-clients.c \
cmd-list-commands.c \
cmd-list-keys.c \
cmd-list-panes.c \
cmd-list-sessions.c \
@@ -115,6 +124,7 @@ dist_tmux_SOURCES = \
cmd-select-pane.c \
cmd-select-window.c \
cmd-send-keys.c \
cmd-server-info.c \
cmd-set-buffer.c \
cmd-set-environment.c \
cmd-set-option.c \
@@ -123,11 +133,14 @@ dist_tmux_SOURCES = \
cmd-show-options.c \
cmd-source-file.c \
cmd-split-window.c \
cmd-start-server.c \
cmd-string.c \
cmd-suspend-client.c \
cmd-swap-pane.c \
cmd-swap-window.c \
cmd-switch-client.c \
cmd-unbind-key.c \
cmd-unlink-window.c \
cmd-wait-for.c \
cmd.c \
colour.c \
@@ -164,7 +177,12 @@ dist_tmux_SOURCES = \
session.c \
signal.c \
status.c \
style.c \
tmate-debug.c \
tmate-ssh-client.c \
tmate-encoder.c \
tmate-decoder.c \
tmate-msg.c \
tmate.c \
tmux.c \
tty-acs.c \
tty-keys.c \
@@ -177,88 +195,65 @@ dist_tmux_SOURCES = \
window.c \
xmalloc.c \
xterm-keys.c
nodist_tmux_SOURCES = osdep-@PLATFORM@.c
nodist_tmate_SOURCES = osdep-@PLATFORM@.c
# Pile in all the compat/ stuff that is needed.
if NO_FORKPTY
nodist_tmux_SOURCES += compat/forkpty-@PLATFORM@.c
nodist_tmate_SOURCES += compat/forkpty-@PLATFORM@.c
endif
if NO_IMSG
nodist_tmux_SOURCES += compat/imsg.c compat/imsg-buffer.c
nodist_tmate_SOURCES += compat/imsg.c compat/imsg-buffer.c
endif
if NO_CLOSEFROM
nodist_tmux_SOURCES += compat/closefrom.c
nodist_tmate_SOURCES += compat/closefrom.c
endif
if NO_DAEMON
nodist_tmux_SOURCES += compat/daemon.c
nodist_tmate_SOURCES += compat/daemon.c
endif
if NO_SETENV
nodist_tmux_SOURCES += compat/setenv.c
nodist_tmate_SOURCES += compat/setenv.c
endif
if NO_STRLCAT
nodist_tmux_SOURCES += compat/strlcat.c
nodist_tmate_SOURCES += compat/strlcat.c
endif
if NO_STRLCPY
nodist_tmux_SOURCES += compat/strlcpy.c
nodist_tmate_SOURCES += compat/strlcpy.c
endif
if NO_ASPRINTF
nodist_tmux_SOURCES += compat/asprintf.c
nodist_tmate_SOURCES += compat/asprintf.c
endif
if NO_FGETLN
nodist_tmux_SOURCES += compat/fgetln.c
endif
if NO_FPARSELN
nodist_tmux_SOURCES += compat/fparseln.c
nodist_tmate_SOURCES += compat/fgetln.c
endif
if NO_GETOPT
nodist_tmux_SOURCES += compat/getopt.c
nodist_tmate_SOURCES += compat/getopt.c
endif
if NO_STRCASESTR
nodist_tmux_SOURCES += compat/strcasestr.c
nodist_tmate_SOURCES += compat/strcasestr.c
endif
if NO_STRSEP
nodist_tmux_SOURCES += compat/strsep.c
nodist_tmate_SOURCES += compat/strsep.c
endif
if NO_VIS
nodist_tmux_SOURCES += compat/vis.c compat/unvis.c
nodist_tmate_SOURCES += compat/vis.c compat/unvis.c
endif
if NO_STRTONUM
nodist_tmux_SOURCES += compat/strtonum.c
nodist_tmate_SOURCES += compat/strtonum.c
endif
if NO_B64_NTOP
nodist_tmux_SOURCES += compat/b64_ntop.c
endif
if NO_CFMAKERAW
nodist_tmux_SOURCES += compat/cfmakeraw.c
endif
if NO_OPENAT
nodist_tmux_SOURCES += compat/openat.c
nodist_tmate_SOURCES += compat/b64_ntop.c
endif
# Install tmux.1 in the right format.
install-exec-hook:
if test x@MANFORMAT@ = xmdoc; then \
sed -e "s|@SYSCONFDIR@|$(sysconfdir)|g" $(srcdir)/tmux.1 \
>$(srcdir)/tmux.1.mdoc; \
else \
sed -e "s|@SYSCONFDIR@|$(sysconfdir)|g" $(srcdir)/tmux.1| \
$(AWK) -f$(srcdir)/mdoc2man.awk >$(srcdir)/tmux.1.man; \
fi
$(mkdir_p) $(DESTDIR)$(mandir)/man1
$(INSTALL_DATA) $(srcdir)/tmux.1.@MANFORMAT@ \
$(DESTDIR)$(mandir)/man1/tmux.1
tmate_LDADD = \
libssh/build/src/libssh.a \
msgpack/src/.libs/libmsgpackc.a
# Update SF web site.
upload-index.html: update-index.html
scp www/index.html www/main.css www/images/*.png \
${USER},tmux@web.sf.net:/home/groups/t/tm/tmux/htdocs
rm -f www/index.html www/images/small-*
*.c: $(tmate_LDADD)
update-index.html:
(cd www/images && \
rm -f small-* && \
for i in *.png; do \
convert "$$i" -resize 200x150 "small-$$i"; \
done \
)
sed "s/%%RELEASE%%/${RELEASE}/g" www/index.html.in >www/index.html
libssh/build/src/libssh.a:
cd libssh/build && cmake .. -DWITH_SFTP=OFF -DWITH_SERVER=OFF -DWITH_PCAP=OFF -DWITH_STATIC_LIB=ON
+make -C libssh/build ssh_static
msgpack/src/.libs/libmsgpackc.a:
cd msgpack && ./bootstrap && ./configure
+make -C msgpack/src libmsgpackc.la
-60
View File
@@ -1,60 +0,0 @@
Welcome to tmux!
tmux is a "terminal multiplexer", it enables a number of terminals (or windows)
to be accessed and controlled from a single terminal. tmux is intended to be a
simple, modern, BSD-licensed alternative to programs such as GNU screen.
This release runs on OpenBSD, FreeBSD, NetBSD, Linux and OS X and may still
run on Solaris and AIX (although they haven't been tested in a while).
tmux depends on libevent 2.x. Download it from:
http://www.monkey.org/~provos/libevent/
To build tmux from a release tarball, do:
$ ./configure && make
$ sudo make install
To get and build the latest from version control:
$ git clone git://git.code.sf.net/p/tmux/tmux-code tmux
$ cd tmux
$ sh autogen.sh
$ ./configure && make
For more information see https://sourceforge.net/scm/?type=git&group_id=200378
and http://git-scm.com. Patches should be sent by email to the mailing list at
tmux-users@lists.sourceforge.net.
For documentation on using tmux, see the tmux.1 manpage. It can be viewed from
the source tree with:
$ nroff -mdoc tmux.1|less
Some common questions are answered in the FAQ file and a more extensive (but
slightly out of date) guide is available in the OpenBSD FAQ at
http://www.openbsd.org/faq/faq7.html#tmux. A rough todo list is in the TODO
file and some example configurations and a Vim syntax file are in the examples
directory.
For debugging, running tmux with -v or -vv will generate server and client log
files in the current directory.
tmux mailing lists are available. Visit:
https://sourceforge.net/mail/?group_id=200378
Bug reports, feature suggestions and especially code contributions are most
welcome. Please send by email to:
tmux-users@lists.sourceforge.net
This file and the CHANGES, FAQ and TODO files are licensed under the ISC
license. Files under examples/ remain copyright their authors unless otherwise
stated in the file but permission has been received to distribute them with
tmux. All other files have a license and copyright notice at their start.
-- Nicholas Marriott <nicm@users.sf.net>
$Id$
Symlink
+1
View File
@@ -0,0 +1 @@
README.md
+60
View File
@@ -0,0 +1,60 @@
Welcome to tmux!
tmux is a "terminal multiplexer", it enables a number of terminals (or windows)
to be accessed and controlled from a single terminal. tmux is intended to be a
simple, modern, BSD-licensed alternative to programs such as GNU screen.
This release runs on OpenBSD, FreeBSD, NetBSD, Linux and OS X and may still
run on Solaris and AIX (although they haven't been tested in a while).
Since the 1.2 release tmux depends on libevent. Download it from:
http://www.monkey.org/~provos/libevent/
To build tmux from a release tarball, do:
$ ./configure && make
$ sudo make install
To get and build the latest from version control:
$ git clone git://git.code.sf.net/p/tmux/tmux-code tmux
$ cd tmux
$ sh autogen.sh
$ ./configure && make
For more information see https://sourceforge.net/scm/?type=git&group_id=200378
and http://git-scm.com. Patches should be sent by email to the mailing list at
tmux-users@lists.sourceforge.net.
For documentation on using tmux, see the tmux.1 manpage. It can be viewed from
the source tree with:
$ nroff -mdoc tmux.1|less
Some common questions are answered in the FAQ file and a more extensive (but
slightly out of date) guide is available in the OpenBSD FAQ at
http://www.openbsd.org/faq/faq7.html#tmux. A rough todo list is in the TODO
file and some example configurations and a Vim syntax file are in the examples
directory.
For debugging, running tmux with -v or -vv will generate server and client log
files in the current directory.
tmux mailing lists are available. Visit:
https://sourceforge.net/mail/?group_id=200378
Bug reports, feature suggestions and especially code contributions are most
welcome. Please send by email to:
tmux-users@lists.sourceforge.net
This file and the CHANGES, FAQ and TODO files are licensed under the ISC
license. Files under examples/ remain copyright their authors unless otherwise
stated in the file but permission has been received to distribute them with
tmux. All other files have a license and copyright notice at their start.
-- Nicholas Marriott <nicm@users.sf.net>
$Id$
+33
View File
@@ -0,0 +1,33 @@
tmate
=====
What is it?
-----------
Tmate is a fork of tmux. It provides an instant pairing solution.
License
-------
tmate is built on top of tmux, libssh and msgpack. Their respective licenses are
in the sources. tmate is MIT licensed.
Copyright (c) 2013 Nicolas Viennot
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-9
View File
@@ -131,15 +131,6 @@ And if happy:
% git push origin master
Keeping an eye on libutil in OpenBSD
====================================
A lot of the compat/ code in tmux comes from libutil, especially imsg.
Sometimes the API can change, etc., which might cause interesting problems
trying to run the portable version of tmux. It's worth checking
periodically for any changes to libutil in OpenBSD and syncing those files
to compat/ as and when appropriate.
Release tmux for next version
=============================
+147 -147
View File
@@ -1,155 +1,155 @@
- command bits and pieces:
* why doesn't command-prompt work if made read-only?
* allow multiple targets: fnmatch for -t/-c, for example detach all
clients with -t*
* add -c for new-session like new-window
* attach should take a pane and select it as well as attaching
* ' and " should be parsed the same (eg "\e" vs '\e') in config
and command prompt
* last-pane across sessions
* exact match operator for targets (or break the substring match
and require eg x* instead of just x)
NOTES
=====
- make command sequences more usable
* don't require space after ;
* options for error handling: && and ||?
This file describes rough notes regarding ideas for potential future tmux
development. It's not necessarily guaranteed that items in this TODO file
will ever get implemented.
- options bits and pieces:
* set-remain-on-exit is a complete hack
* way to set socket path from config file
It is asked therefore, that anyone thinking of undertaking a task in this
TODO file, email tmux-users@lists.sf.net to discuss the feature.
- format improvements:
* last bits of status_replace into formats?
* option to quote format (#{session_name:quoted})
* formats need conditions for >0 (for #P)
* some way to pad # stuff with spaces, #!2T maybe
* last window update time and format for it
* formats to show if a window is linked into multiple sessions, into
multiple attached sessions, and is the active window in multiple
attached sessions?
Thie file is split up between tmux user interface (UI) issues, and terminal
compatibility issues.
- choose mode improvements:
* choose-pane command (augment choose-tree to do this?)
* choose-mode and copy-mode are very similar, make choose-mode a subset?
* flag to choose-* for sort order
* choose mode would be better per client than per window?
* two choices (first one then second, for swap-pane and join-pane)
- improve monitor-*:
* straighten out rules for multiple clients
* think about what happens across sessions
* monitor changes within a region
* perhaps monitor /all/ panes in the window not just one
- improve mouse support:
* bind commands to mouse in different areas?
* more fine-grained options?
* commands executed when clicking on a pattern (URL)
* mouse-select-pane will screw up with !MODE_MOUSE_STANDARD (it sets
the flag on w/o checking the others before calling tty_update_mode)
* mouse can be like normal key bindings?
- {button-{1,2,3},wheel-{up,down}}-{status,pane,border} and
drag-{start,end}-{status,pane,border} plus the modifiers
- resize and copy can be special cases - once you call something
like copy-mode -M or resize-pane -M to start the drag, it tracks
mouse until you call -m to stop the drag. or just keep drags
entirely special?
- what happens with stuff that wants mouse inside? especially for
pane clicks which need to run command AND pass event through
(like mouse-select-pane). maybe just a flag to say whether it
always runs or only if pane hasn't taken mouse? or it could be
eg bind Button1Pane "select-pane -t=; send-keys -Mt='
- also need a) some way to tell commands bound to key which
window or pane the mouse key binding applies to (maybe a new
special char in target, or pass targets through formats?) b) a
way to bind repeat count to mode keys so that wheel up/down can
do multiple lines c) send-keys -M to pass a mouse event through?
- what does the mouse->KEYC_* conversion and find-the-pane bit?
server_client_handle_key?
- hooks!
TMUX UI ISSUES
==============
- implicitly add exec to the commands for new windows (switch to disable it)?
- bring back detach-session to detach all clients on a session?
- allow fnmatch for -c, so that you can, eg, detach all clients
- garbage collect window history (100 lines at a time?) if it hasn't been used
in $x time
- flags to centre screen in window
- activity/bell should be per-window not per-link? what if it is cur win in
session not being watched?
- should be able to move to a hidden pane and it would be moved into view. pane
number in status line/top-right would be cool for this
- support other mouse modes (highlight etc) and use it in copy mode
- set-remain-on-exit is a bit of a hack, some way to do it generically?
- would be nice to be able to use "--" to mark start of command w/ neww etc
to avoid quoting
- make command sequences more usable: don't require space after ;, handle
errors better
- choice and more mode would be better per client than per window?
- hooks to which commands may be attached, for example: tmux add-hook
"new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file
$HOME/.tmux-session.conf
- way to set socket path from config file
- warts on current naming:
* display-time but message-fg/bg/attr
* list-* vs show-*
* split-window -> split-pane??
- display-time but message-fg/bg/attr
- list-* vs show-*
- server-info
- up-pane/down-pane/swap-pane -U/swap-pane -D vs next-*/previous-*
- split-window -> split-pane??
- some way to force a screen to use the entire terminal even if it is forced
to be smaller by other clients. pan smaller terminal? (like screen F)
-- idea of a "view" onto a window, need base x/y offsets for redraw
- commands should be able to succeed or fail and have || or && for command
lists
- some way to keep a command running continually and just use its last line of
output
- UTF-8 to a non-UTF-8 terminal should not be able to balls up
the terminal - www/ruby-addressable; make regress
- support esc-esc to quit in modes
- fix ctrl+F1-F4 output. to what?
- better utf8 support: window names, prompt input, message display
- option to move copy mode indicator into status line
- selection behaviour closer to vi in vi mode
- live update: server started with -U connects to server, requests sessions and
windows, receives fds
- sort out inheriting config from shell on new sessions/windows:
should pick up default-path/termios/etc from client if possible,
else leave empty/default
- link panes into multiple windows
- bells should be passed between sessions with visual-bell etc
sequence until its shell exits, to allow them to be used from the config file
- better session sharing: create-socket command to create socket somewhere (-r
flag for readonly)
- multiline status line (no?)
- support title stack, both internally and externally
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=1149299+0+archive/2010/freebsd-questions/20100207.freebsd-questions
- some way to pad # stuff with spaces, #!2T maybe
- a binding to "scroll down and exit at bottom" copy mode
- some way to pass keystrokes in copy mode through to underlying window. why?
- last window update time and # replacement for it for display-message
- find-window across sessions - other ways to make session handling easier?
- ' and " should be parsed the same (eg "\e" vs '\e') in config and command
prompt?
- command to toggle selection not to move it in copy-mode
- audit of escape sequence support vs xterm
- support binding keys to mouse (mouse-select-pane -> mouse-keys or something,
mouse click == select-pane -t %%, mouse scroll up == copy-mode)
- bind commands to key sequences? -- make it so ALL keys go through a table,
first an implicit table in which C-b is the only default binding to a
command that says "next key from $othertable" and so on. means -n can
go away as well
- monitor, bell etc should monitor /all/ panes in the window not just one
- a history of commands that can be reversed (reverse member of each command,
and a buffer)
- info() when changing to same window
- way to add dest for break-pane; maybe some easier way to unbreak-pane
- case insensitive searching
- incremental searching in copy mode.
- configurable borders and empty space filler for when panes < window?
- mouse-select-pane will screw up with !MODE_MOUSE_STANDARD (it sets the
flag on w/o checking the others before calling tty_update_mode)
- pass shell commands as argv rather than strings, allow them to be specified
in commands without quotes
- named buffers and allow gaps in the stack
- monitor-activity is broken in several ways with multiple clients
- monitor-activity should be more powerful (eg set a region)
- maybe a way to put pane names instead of window names in status line
- support for borderless panes
- wait-for command 20130222153957.GY6782@yelena.nicm.ath.cx
- last-pane across sessions
- panes should have names like windows
- command-prompt doesn't work if made read-only. why?
- option to quote format eg #{session_name:quoted}
- formats need conditions for >0 (for #P)
- fetch full command line on !Linux, and add option to strip prefixes
such as "sh " "/bin/sh " etc etc
- synchronize-windows option
- append to buffer in copy mode
- way to paste w/o trailing whitespace
- flag to switch-client to switch all clients
- history of layouts and undo/redo flags to selectl
- way to tag a layout as a number/name
- optimize pane redraws, 20120318184853.GK10965@yelena.nicm.ath.cx
- support multibyte key strings
- allow commands to be executed when certain patterns in a screen
are clicked on with the mouse
- flag to make next/previous commands skip a window
- way to do tmux command/run-shell from mode keys
- send command to all windows
- choose-pane command (augment choose-tree to do this?)
- choose-mode and copy-mode are very similar. Perhaps make choose-mode a subset
of copy-mode in that it inherits key-bindings and other traits but not all
- add -c for new-session like new-window
- flag to choose-* for sort order (eg sort windows/sessions/clients by last
used time) - perhaps using formats (but what about numeric sort)?
- instead of separate window and session options, just one master options list
with each option having a type (window or session), then options on window,
on session, and global. for window options we look window->session->global,
and for session we look session->global
- maybe keep last layout + size around and if size reverts just put it back
- way to set hints/limits about pane size for resizing
- revamp layouts: they are too complicated, should be more closely integrated,
should support hints, layout sets should just be a special case of custom
layouts, and we should support panes that are not attached to a cell at
all. this could be the time to introduce panelink to replace layout_cell
- run-shell/if-shell should support formats
- attach should take a pane and select it as well as attaching
- attach should have a flag to create session if it doesn't exist. or better
new a flag to attach it
- better UTF-8 support:
* window names and titles
* message display
* prompt input
* multibyte key input
TERMINAL ISSUES
================
- copy/paste improvements:
* incremental searching
* append to buffer
* paste w/o trailing whitespace
* command to toggle selection not to move it in copy-mode
- layout stuff
* way to tag a layout as a number/name
* maybe keep last layout + size around and if size reverts just put it
back
* revamp layouts: they are too complicated, should be more closely
integrated, should support hints, layout sets should just be a
special case of custom layouts, and we should support panes that are
not attached to a cell at all. this could be the time to introduce
panelink to replace layout_cell
* way to set hints/limits about pane size for resizing
* panning over window (window larger than visible)
* a mode where one application can cross two panes (ie x|y, width =
COLUMNS/2 but height = ROWS * 2)
* general key to space cells out evenly (horiz or vert) within their
parent cell (could replace even-vert/even-horiz layouts)
- terminfo bits
* use a better termcap internally instead of screen, perhaps xterm
* use screen-256color when started on 256 colour terminal?
* need a tmux terminfo entry to document the extensions we are using in
upstream terminfo
- code cleanup
* instead of separate window and session options, just one master
options list with each option having a type (window or session), then
options on window, on session, and global. for window options we look
window->session->global, and for session we look session->global
* the way pane, window, session destroy is handled is too complicated
and the distinction between session.c, window.c and server-fn.c
functions is not clear. could we just have kill_pane(),
kill_window(), unlink_window(), kill_session() that fix up all data
structures (flagging sessions as dead) and return a value to say
whether clients need to be checked for dead sessions? sort of like
session_detach now but more so. or some other scheme to make it
simpler and clearer? also would be nice to remove/rename server-fn.c
* more readable way to work out the various things commands need to
know about the client, notably:
- is this the config file? (cmdq->c == NULL)
- is this a command client? (cmdq->c != NULL &&
cmdq->c->session == NULL)
- is this a control client?
- can i do stdin or stdout to this client?
or even guarantee that cmdq->c != NULL and provide a better way to
tell when in the config file - then we use cmdq->c if we need a
client w/o a session else cmd_current_client
* optimize pane redraws, 20120318184853.GK10965@yelena.nicm.ath.cx
* cmd_find_* could be much simpler - parse everything the same, only
difference is what to choose when not given a ":" or "." (such as a
plain "0" could be session, window or pane). So just cmd_find_target
with a type (session, window, or pane)..
- miscellaneous
* way to keep a job running just read its last line of output for #()
* link panes into multiple windows
* live update: server started with -U connects to server, requests
sessions and windows, receives file descriptors
* there are inconsistencies in what we get from old shell and what
comes from config for new sessions and windows. likewise, panes and
jobs and run-shell and lock command all start with slightly different
environments
* multiline status line?
* bind commands to key sequences -- make it so ALL keys go through a
table, first an implicit table in which C-b is the only default
binding to a command that says "next key from $othertable" and so
on. means -n can go away as well
* customizable command aliases
* any remaining clients in wait-for should be woken when server exits
- use a better termcap internally instead of screen, perhaps xterm
- clear window title on exit (see using xterm title stack)
- get it passing all the vttest tests that don't require resizing the terminal
- support for bce
- use screen-256color when started on 256 colour terminal?
* We need a tmux terminfo entry to document the extensions we are using in
upstream terminfo. Must NOT change (only add or remove) anything from
TERM=screen so we can fallback!
+46 -86
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,28 +18,11 @@
#include <sys/types.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "tmux.h"
/*
* Manipulate command arguments.
*/
struct args_entry *args_find(struct args *, u_char);
RB_GENERATE(args_tree, args_entry, entry, args_cmp);
/* Arguments tree comparison function. */
int
args_cmp(struct args_entry *a1, struct args_entry *a2)
{
return (a1->flag - a2->flag);
}
/* Create an arguments set with no flags. */
struct args *
args_create(int argc, ...)
@@ -49,6 +32,8 @@ args_create(int argc, ...)
int i;
args = xcalloc(1, sizeof *args);
if ((args->flags = bit_alloc(SCHAR_MAX)) == NULL)
fatal("bit_alloc failed");
args->argc = argc;
if (argc == 0)
@@ -64,36 +49,35 @@ args_create(int argc, ...)
return (args);
}
/* Find a flag in the arguments tree. */
struct args_entry *
args_find(struct args *args, u_char ch)
{
struct args_entry entry;
entry.flag = ch;
return (RB_FIND(args_tree, &args->tree, &entry));
}
/* Parse an argv and argc into a new argument set. */
struct args *
args_parse(const char *template, int argc, char **argv)
{
struct args *args;
char *ptr;
int opt;
args = xcalloc(1, sizeof *args);
if ((args->flags = bit_alloc(SCHAR_MAX)) == NULL)
fatal("bit_alloc failed");
optreset = 1;
optind = 1;
while ((opt = getopt(argc, argv, template)) != -1) {
if (opt < 0)
if (opt < 0 || opt >= SCHAR_MAX)
continue;
if (opt == '?' || strchr(template, opt) == NULL) {
args_free(args);
if (opt == '?' || (ptr = strchr(template, opt)) == NULL) {
free(args->flags);
free(args);
return (NULL);
}
args_set(args, opt, optarg);
bit_set(args->flags, opt);
if (ptr[1] == ':') {
free(args->values[opt]);
args->values[opt] = xstrdup(optarg);
}
}
argc -= optind;
argv += optind;
@@ -108,17 +92,14 @@ args_parse(const char *template, int argc, char **argv)
void
args_free(struct args *args)
{
struct args_entry *entry;
struct args_entry *entry1;
u_int i;
cmd_free_argv(args->argc, args->argv);
RB_FOREACH_SAFE(entry, args_tree, &args->tree, entry1) {
RB_REMOVE(args_tree, &args->tree, entry);
free(entry->value);
free(entry);
}
for (i = 0; i < SCHAR_MAX; i++)
free(args->values[i]);
free(args->flags);
free(args);
}
@@ -126,10 +107,9 @@ args_free(struct args *args)
size_t
args_print(struct args *args, char *buf, size_t len)
{
size_t off, used;
int i;
const char *quotes;
struct args_entry *entry;
size_t off;
int i;
const char *quotes;
/* There must be at least one byte at the start. */
if (len == 0)
@@ -138,23 +118,23 @@ args_print(struct args *args, char *buf, size_t len)
/* Process the flags first. */
buf[off++] = '-';
RB_FOREACH(entry, args_tree, &args->tree) {
if (entry->value != NULL)
for (i = 0; i < SCHAR_MAX; i++) {
if (!bit_test(args->flags, i) || args->values[i] != NULL)
continue;
if (off == len - 1) {
buf[off] = '\0';
return (len);
}
buf[off++] = entry->flag;
buf[off++] = i;
buf[off] = '\0';
}
if (off == 1)
buf[--off] = '\0';
/* Then the flags with arguments. */
RB_FOREACH(entry, args_tree, &args->tree) {
if (entry->value == NULL)
for (i = 0; i < SCHAR_MAX; i++) {
if (!bit_test(args->flags, i) || args->values[i] == NULL)
continue;
if (off >= len) {
@@ -162,16 +142,12 @@ args_print(struct args *args, char *buf, size_t len)
return (len);
}
if (strchr(entry->value, ' ') != NULL)
if (strchr(args->values[i], ' ') != NULL)
quotes = "\"";
else
quotes = "";
used = xsnprintf(buf + off, len - off, "%s-%c %s%s%s",
off != 0 ? " " : "", entry->flag, quotes, entry->value,
quotes);
if (used > len - off)
used = len - off;
off += used;
off += xsnprintf(buf + off, len - off, "%s-%c %s%s%s",
off != 0 ? " " : "", i, quotes, args->values[i], quotes);
}
/* And finally the argument vector. */
@@ -185,11 +161,8 @@ args_print(struct args *args, char *buf, size_t len)
quotes = "\"";
else
quotes = "";
used = xsnprintf(buf + off, len - off, "%s%s%s%s",
off += xsnprintf(buf + off, len - off, "%s%s%s%s",
off != 0 ? " " : "", quotes, args->argv[i], quotes);
if (used > len - off)
used = len - off;
off += used;
}
return (off);
@@ -199,55 +172,42 @@ args_print(struct args *args, char *buf, size_t len)
int
args_has(struct args *args, u_char ch)
{
return (args_find(args, ch) == NULL ? 0 : 1);
return (bit_test(args->flags, ch));
}
/* Set argument value in the arguments tree. */
/* Set argument value. */
void
args_set(struct args *args, u_char ch, const char *value)
{
struct args_entry *entry;
/* Replace existing argument. */
if ((entry = args_find(args, ch)) != NULL) {
free(entry->value);
entry->value = NULL;
} else {
entry = xcalloc(1, sizeof *entry);
entry->flag = ch;
RB_INSERT(args_tree, &args->tree, entry);
}
free(args->values[ch]);
if (value != NULL)
entry->value = xstrdup(value);
args->values[ch] = xstrdup(value);
else
args->values[ch] = NULL;
bit_set(args->flags, ch);
}
/* Get argument value. Will be NULL if it isn't present. */
const char *
args_get(struct args *args, u_char ch)
{
struct args_entry *entry;
if ((entry = args_find(args, ch)) == NULL)
return (NULL);
return (entry->value);
return (args->values[ch]);
}
/* Convert an argument value to a number. */
long long
args_strtonum(struct args *args, u_char ch, long long minval, long long maxval,
char **cause)
args_strtonum(struct args *args,
u_char ch, long long minval, long long maxval, char **cause)
{
const char *errstr;
long long ll;
struct args_entry *entry;
const char *errstr;
long long ll;
if ((entry = args_find(args, ch)) == NULL) {
if (!args_has(args, ch)) {
*cause = xstrdup("missing");
return (0);
}
ll = strtonum(entry->value, minval, maxval, &errstr);
ll = strtonum(args->values[ch], minval, maxval, &errstr);
if (errstr != NULL) {
*cause = xstrdup(errstr);
return (0);
+2 -2
View File
@@ -39,10 +39,10 @@
fatalx("size too big"); \
if ((a)->space == 0) { \
(a)->space = ARRAY_INITIALSPACE(a); \
(a)->list = xrealloc((a)->list, (a)->space); \
(a)->list = xrealloc((a)->list, 1, (a)->space); \
} \
while ((a)->space <= ((a)->num + (n)) * ARRAY_ITEMSIZE(a)) { \
(a)->list = xreallocarray((a)->list, 2, (a)->space); \
(a)->list = xrealloc((a)->list, 2, (a)->space); \
(a)->space *= 2; \
} \
} while (0)
+1 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
+51 -60
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -17,6 +17,7 @@
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <errno.h>
@@ -29,17 +30,15 @@
struct cmd_q *cfg_cmd_q;
int cfg_finished;
int cfg_references;
ARRAY_DECL (, char *) cfg_causes = ARRAY_INITIALIZER;
struct client *cfg_client;
struct causelist cfg_causes;
int
load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
{
FILE *f;
char delim[3] = { '\\', '\\', '\0' };
u_int found;
size_t line = 0;
char *buf, *cause1, *p;
u_int n, found;
char *buf, *copy, *line, *cause1, *msg;
size_t len, oldlen;
struct cmd_list *cmdlist;
log_debug("loading %s", path);
@@ -48,29 +47,60 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
return (-1);
}
found = 0;
while ((buf = fparseln(f, NULL, &line, delim, 0))) {
log_debug("%s: %s", path, buf);
n = found = 0;
line = NULL;
while ((buf = fgetln(f, &len))) {
/* Trim \n. */
if (buf[len - 1] == '\n')
len--;
log_debug("%s: %.*s", path, (int)len, buf);
/* Current line is the continuation of the previous one. */
if (line != NULL) {
oldlen = strlen(line);
line = xrealloc(line, 1, oldlen + len + 1);
} else {
oldlen = 0;
line = xmalloc(len + 1);
}
/* Append current line to the previous. */
memcpy(line + oldlen, buf, len);
line[oldlen + len] = '\0';
n++;
/* Continuation: get next line? */
len = strlen(line);
if (len > 0 && line[len - 1] == '\\') {
line[len - 1] = '\0';
/* Ignore escaped backslash at EOL. */
if (len > 1 && line[len - 2] != '\\')
continue;
}
copy = line;
line = NULL;
/* Skip empty lines. */
p = buf;
while (isspace((u_char) *p))
p++;
if (*p == '\0') {
free(buf);
buf = copy;
while (isspace((u_char)*buf))
buf++;
if (*buf == '\0') {
free(copy);
continue;
}
/* Parse and run the command. */
if (cmd_string_parse(p, &cmdlist, path, line, &cause1) != 0) {
free(buf);
if (cmd_string_parse(buf, &cmdlist, path, n, &cause1) != 0) {
free(copy);
if (cause1 == NULL)
continue;
cfg_add_cause("%s:%zu: %s", path, line, cause1);
xasprintf(&msg, "%s:%u: %s", path, n, cause1);
ARRAY_ADD(&cfg_causes, msg);
free(cause1);
continue;
}
free(buf);
free(copy);
if (cmdlist == NULL)
continue;
@@ -78,6 +108,8 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
cmd_list_free(cmdlist);
found++;
}
if (line != NULL)
free(line);
fclose(f);
return (found);
@@ -95,47 +127,6 @@ cfg_default_done(unused struct cmd_q *cmdq)
cmdq_free(cfg_cmd_q);
cfg_cmd_q = NULL;
if (cfg_client != NULL) {
/*
* The client command queue starts with client_exit set to 1 so
* only continue if not empty (that is, we have been delayed
* during configuration parsing for long enough that the
* MSG_COMMAND has arrived), else the client will exit before
* the MSG_COMMAND which might tell it not to.
*/
if (!TAILQ_EMPTY(&cfg_client->cmdq->queue))
cmdq_continue(cfg_client->cmdq);
cfg_client->references--;
cfg_client = NULL;
}
}
void
cfg_add_cause(const char* fmt, ...)
{
va_list ap;
char* msg;
va_start(ap, fmt);
xvasprintf(&msg, fmt, ap);
va_end (ap);
ARRAY_ADD(&cfg_causes, msg);
}
void
cfg_print_causes(struct cmd_q *cmdq)
{
char *cause;
u_int i;
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
cause = ARRAY_ITEM(&cfg_causes, i);
cmdq_print(cmdq, "%s", cause);
free(cause);
}
ARRAY_FREE(&cfg_causes);
}
void
+116 -167
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -26,7 +26,7 @@
#include <errno.h>
#include <event.h>
#include <fcntl.h>
#include <signal.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -48,14 +48,13 @@ enum {
} client_exitreason = CLIENT_EXIT_NONE;
int client_exitval;
enum msgtype client_exittype;
const char *client_exitsession;
int client_attached;
int client_get_lock(char *);
int client_connect(char *, int);
void client_send_identify(int);
int client_write_one(enum msgtype, int, const void *, size_t);
int client_write_server(enum msgtype, const void *, size_t);
void client_send_environ(void);
void client_write_server(enum msgtype, void *, size_t);
void client_update_event(void);
void client_signal(int, short, void *);
void client_stdin_callback(int, short, void *);
@@ -78,18 +77,13 @@ client_get_lock(char *lockfile)
if ((lockfd = open(lockfile, O_WRONLY|O_CREAT, 0600)) == -1)
fatal("open failed");
log_debug("lock file is %s", lockfile);
if (flock(lockfd, LOCK_EX|LOCK_NB) == -1) {
log_debug("flock failed: %s", strerror(errno));
if (errno != EAGAIN)
return (lockfd);
if (flock(lockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) {
while (flock(lockfd, LOCK_EX) == -1 && errno == EINTR)
/* nothing */;
close(lockfd);
return (-1);
}
log_debug("flock succeeded");
return (lockfd);
}
@@ -100,8 +94,8 @@ client_connect(char *path, int start_server)
{
struct sockaddr_un sa;
size_t size;
int fd, lockfd = -1, locked = 0;
char *lockfile = NULL;
int fd, lockfd;
char *lockfile;
memset(&sa, 0, sizeof sa);
sa.sun_family = AF_UNIX;
@@ -110,48 +104,24 @@ client_connect(char *path, int start_server)
errno = ENAMETOOLONG;
return (-1);
}
log_debug("socket is %s", path);
retry:
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
fatal("socket failed");
log_debug("trying connect");
if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
log_debug("connect failed: %s", strerror(errno));
if (errno != ECONNREFUSED && errno != ENOENT)
goto failed;
if (!start_server)
goto failed;
close(fd);
if (!locked) {
xasprintf(&lockfile, "%s.lock", path);
if ((lockfd = client_get_lock(lockfile)) == -1) {
log_debug("didn't get lock");
free(lockfile);
goto retry;
}
log_debug("got lock");
/*
* Always retry at least once, even if we got the lock,
* because another client could have taken the lock,
* started the server and released the lock between our
* connect() and flock().
*/
locked = 1;
xasprintf(&lockfile, "%s.lock", path);
if ((lockfd = client_get_lock(lockfile)) == -1)
goto retry;
}
if (unlink(path) != 0 && errno != ENOENT) {
free(lockfile);
close(lockfd);
if (unlink(path) != 0 && errno != ENOENT)
return (-1);
}
fd = server_start(lockfd, lockfile);
}
if (locked) {
free(lockfile);
close(lockfd);
}
@@ -168,24 +138,12 @@ failed:
const char *
client_exit_message(void)
{
static char msg[256];
switch (client_exitreason) {
case CLIENT_EXIT_NONE:
break;
case CLIENT_EXIT_DETACHED:
if (client_exitsession != NULL) {
xsnprintf(msg, sizeof msg, "detached "
"(from session %s)", client_exitsession);
return (msg);
}
return ("detached");
case CLIENT_EXIT_DETACHED_HUP:
if (client_exitsession != NULL) {
xsnprintf(msg, sizeof msg, "detached and SIGHUP "
"(from session %s)", client_exitsession);
return (msg);
}
return ("detached and SIGHUP");
case CLIENT_EXIT_LOST_TTY:
return ("lost tty");
@@ -207,13 +165,12 @@ client_main(int argc, char **argv, int flags)
{
struct cmd *cmd;
struct cmd_list *cmdlist;
struct msg_command_data *data;
int cmdflags, fd, i;
struct msg_command_data cmddata;
int cmdflags, fd;
pid_t ppid;
enum msgtype msg;
char *cause;
struct termios tio, saved_tio;
size_t size;
/* Set up the initial command. */
cmdflags = 0;
@@ -222,7 +179,7 @@ client_main(int argc, char **argv, int flags)
cmdflags = CMD_STARTSERVER;
} else if (argc == 0) {
msg = MSG_COMMAND;
cmdflags = CMD_STARTSERVER|CMD_CANTNEST;
cmdflags = CMD_STARTSERVER|CMD_SENDENVIRON|CMD_CANTNEST;
} else {
msg = MSG_COMMAND;
@@ -240,6 +197,8 @@ client_main(int argc, char **argv, int flags)
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
if (cmd->entry->flags & CMD_STARTSERVER)
cmdflags |= CMD_STARTSERVER;
if (cmd->entry->flags & CMD_SENDENVIRON)
cmdflags |= CMD_SENDENVIRON;
if (cmd->entry->flags & CMD_CANTNEST)
cmdflags |= CMD_CANTNEST;
}
@@ -258,11 +217,10 @@ client_main(int argc, char **argv, int flags)
return (1);
}
/* Initialize the client socket and start the server. */
/* Initialise the client socket and start the server. */
fd = client_connect(socket_path, cmdflags & CMD_STARTSERVER);
if (fd == -1) {
fprintf(stderr, "failed to connect to server: %s\n",
strerror(errno));
fprintf(stderr, "failed to connect to server\n");
return (1);
}
@@ -280,7 +238,7 @@ client_main(int argc, char **argv, int flags)
setblocking(STDIN_FILENO, 0);
event_set(&client_stdin, STDIN_FILENO, EV_READ|EV_PERSIST,
client_stdin_callback, NULL);
if (flags & CLIENT_CONTROLCONTROL) {
if (flags & IDENTIFY_TERMIOS) {
if (tcgetattr(STDIN_FILENO, &saved_tio) != 0) {
fprintf(stderr, "tcgetattr failed: %s\n",
strerror(errno));
@@ -303,33 +261,26 @@ client_main(int argc, char **argv, int flags)
/* Establish signal handlers. */
set_signals(client_signal);
/* Send identify messages. */
/* Send initial environment. */
if (cmdflags & CMD_SENDENVIRON)
client_send_environ();
client_send_identify(flags);
/* Send first command. */
if (msg == MSG_COMMAND) {
/* How big is the command? */
size = 0;
for (i = 0; i < argc; i++)
size += strlen(argv[i]) + 1;
data = xmalloc((sizeof *data) + size);
/* Fill in command line arguments. */
cmddata.pid = environ_pid;
cmddata.session_id = environ_session_id;
/* Prepare command for server. */
data->argc = argc;
if (cmd_pack_argv(argc, argv, (char *)(data + 1), size) != 0) {
cmddata.argc = argc;
if (cmd_pack_argv(
argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
fprintf(stderr, "command too long\n");
free(data);
return (1);
}
size += sizeof *data;
/* Send the command. */
if (client_write_server(msg, data, size) != 0) {
fprintf(stderr, "failed to send command\n");
free(data);
return (1);
}
free(data);
client_write_server(msg, &cmddata, sizeof cmddata);
} else if (msg == MSG_SHELL)
client_write_server(msg, NULL, 0);
@@ -345,75 +296,65 @@ client_main(int argc, char **argv, int flags)
ppid = getppid();
if (client_exittype == MSG_DETACHKILL && ppid > 1)
kill(ppid, SIGHUP);
} else if (flags & CLIENT_CONTROLCONTROL) {
if (client_exitreason != CLIENT_EXIT_NONE)
printf("%%exit %s\n", client_exit_message());
else
printf("%%exit\n");
printf("\033\\");
} else if (flags & IDENTIFY_TERMIOS) {
if (flags & IDENTIFY_CONTROL) {
if (client_exitreason != CLIENT_EXIT_NONE)
printf("%%exit %s\n", client_exit_message());
else
printf("%%exit\n");
printf("\033\\");
}
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
}
setblocking(STDIN_FILENO, 1);
return (client_exitval);
}
/* Send identify messages to server. */
/* Send identify message to server with the file descriptors. */
void
client_send_identify(int flags)
{
const char *s;
char **ss;
int fd;
struct msg_identify_data data;
char *term;
int fd;
client_write_one(MSG_IDENTIFY_FLAGS, -1, &flags, sizeof flags);
data.flags = flags;
if ((s = getenv("TERM")) == NULL)
s = "";
client_write_one(MSG_IDENTIFY_TERM, -1, s, strlen(s) + 1);
if (getcwd(data.cwd, sizeof data.cwd) == NULL)
*data.cwd = '\0';
if ((s = ttyname(STDIN_FILENO)) == NULL)
s = "";
client_write_one(MSG_IDENTIFY_TTYNAME, -1, s, strlen(s) + 1);
if ((fd = open(".", O_RDONLY)) == -1)
fd = open("/", O_RDONLY);
client_write_one(MSG_IDENTIFY_CWD, fd, NULL, 0);
term = getenv("TERM");
if (term == NULL ||
strlcpy(data.term, term, sizeof data.term) >= sizeof data.term)
*data.term = '\0';
if ((fd = dup(STDIN_FILENO)) == -1)
fatal("dup failed");
client_write_one(MSG_IDENTIFY_STDIN, fd, NULL, 0);
for (ss = environ; *ss != NULL; ss++)
client_write_one(MSG_IDENTIFY_ENVIRON, -1, *ss, strlen(*ss) + 1);
client_write_one(MSG_IDENTIFY_DONE, -1, NULL, 0);
imsg_compose(&client_ibuf,
MSG_IDENTIFY, PROTOCOL_VERSION, -1, fd, &data, sizeof data);
client_update_event();
}
/* Helper to send one message. */
int
client_write_one(enum msgtype type, int fd, const void *buf, size_t len)
/* Forward entire environment to server. */
void
client_send_environ(void)
{
int retval;
struct msg_environ_data data;
char **var;
retval = imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, fd,
(void *)buf, len);
if (retval != 1)
return (-1);
return (0);
for (var = environ; *var != NULL; var++) {
if (strlcpy(data.var, *var, sizeof data.var) >= sizeof data.var)
continue;
client_write_server(MSG_ENVIRON, &data, sizeof data);
}
}
/* Write a message to the server without a file descriptor. */
int
client_write_server(enum msgtype type, const void *buf, size_t len)
void
client_write_server(enum msgtype type, void *buf, size_t len)
{
int retval;
retval = client_write_one(type, -1, buf, len);
if (retval == 0)
client_update_event();
return (retval);
imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
client_update_event();
}
/* Update client event based on whether it needs to read or read and write. */
@@ -438,11 +379,15 @@ client_signal(int sig, unused short events, unused void *data)
struct sigaction sigact;
int status;
if (sig == SIGCHLD)
waitpid(WAIT_ANY, &status, WNOHANG);
else if (!client_attached) {
if (sig == SIGTERM)
if (!client_attached) {
switch (sig) {
case SIGCHLD:
waitpid(WAIT_ANY, &status, WNOHANG);
break;
case SIGTERM:
event_loopexit(NULL);
break;
}
} else {
switch (sig) {
case SIGHUP:
@@ -494,7 +439,7 @@ client_callback(unused int fd, short events, void *data)
}
if (events & EV_WRITE) {
if (msgbuf_write(&client_ibuf.w) <= 0 && errno != EAGAIN)
if (msgbuf_write(&client_ibuf.w) < 0)
goto lost_server;
}
@@ -543,33 +488,33 @@ client_write(int fd, const char *data, size_t size)
/* Dispatch imsgs when in wait state (before MSG_READY). */
int
client_dispatch_wait(void *data0)
client_dispatch_wait(void *data)
{
struct imsg imsg;
char *data;
ssize_t n, datalen;
struct msg_stdout_data stdoutdata;
struct msg_stderr_data stderrdata;
int retval;
struct imsg imsg;
ssize_t n, datalen;
struct msg_shell_data shelldata;
struct msg_exit_data exitdata;
struct msg_stdout_data stdoutdata;
struct msg_stderr_data stderrdata;
const char *shellcmd = data;
for (;;) {
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
fatalx("imsg_get failed");
if (n == 0)
return (0);
data = imsg.data;
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
log_debug("got %d from server", imsg.hdr.type);
switch (imsg.hdr.type) {
case MSG_EXIT:
case MSG_SHUTDOWN:
if (datalen != sizeof retval && datalen != 0)
fatalx("bad MSG_EXIT size");
if (datalen == sizeof retval) {
memcpy(&retval, data, sizeof retval);
client_exitval = retval;
if (datalen != sizeof exitdata) {
if (datalen != 0)
fatalx("bad MSG_EXIT size");
} else {
memcpy(&exitdata, imsg.data, sizeof exitdata);
client_exitval = exitdata.retcode;
}
imsg_free(&imsg);
return (-1);
@@ -589,19 +534,17 @@ client_dispatch_wait(void *data0)
break;
case MSG_STDOUT:
if (datalen != sizeof stdoutdata)
fatalx("bad MSG_STDOUT size");
memcpy(&stdoutdata, data, sizeof stdoutdata);
fatalx("bad MSG_STDOUT");
memcpy(&stdoutdata, imsg.data, sizeof stdoutdata);
client_write(STDOUT_FILENO, stdoutdata.data,
stdoutdata.size);
client_write(STDOUT_FILENO, stdoutdata.data, stdoutdata.size);
break;
case MSG_STDERR:
if (datalen != sizeof stderrdata)
fatalx("bad MSG_STDERR size");
memcpy(&stderrdata, data, sizeof stderrdata);
fatalx("bad MSG_STDERR");
memcpy(&stderrdata, imsg.data, sizeof stderrdata);
client_write(STDERR_FILENO, stderrdata.data,
stderrdata.size);
client_write(STDERR_FILENO, stderrdata.data, stderrdata.size);
break;
case MSG_VERSION:
if (datalen != 0)
@@ -615,19 +558,23 @@ client_dispatch_wait(void *data0)
imsg_free(&imsg);
return (-1);
case MSG_SHELL:
if (datalen == 0 || data[datalen - 1] != '\0')
fatalx("bad MSG_SHELL string");
if (datalen != sizeof shelldata)
fatalx("bad MSG_SHELL size");
memcpy(&shelldata, imsg.data, sizeof shelldata);
shelldata.shell[(sizeof shelldata.shell) - 1] = '\0';
clear_signals(0);
shell_exec(data, data0);
shell_exec(shelldata.shell, shellcmd);
/* NOTREACHED */
case MSG_DETACH:
case MSG_DETACHKILL:
client_write_server(MSG_EXITING, NULL, 0);
break;
case MSG_EXITED:
imsg_free(&imsg);
return (-1);
default:
fatalx("unexpected message");
}
imsg_free(&imsg);
@@ -638,28 +585,25 @@ client_dispatch_wait(void *data0)
int
client_dispatch_attached(void)
{
struct imsg imsg;
struct sigaction sigact;
char *data;
ssize_t n, datalen;
struct imsg imsg;
struct msg_lock_data lockdata;
struct sigaction sigact;
ssize_t n, datalen;
for (;;) {
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
fatalx("imsg_get failed");
if (n == 0)
return (0);
data = imsg.data;
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
log_debug("got %d from server", imsg.hdr.type);
switch (imsg.hdr.type) {
case MSG_DETACH:
case MSG_DETACHKILL:
if (datalen == 0 || data[datalen - 1] != '\0')
fatalx("bad MSG_DETACH string");
case MSG_DETACH:
if (datalen != 0)
fatalx("bad MSG_DETACH size");
client_exitsession = xstrdup(data);
client_exittype = imsg.hdr.type;
if (imsg.hdr.type == MSG_DETACHKILL)
client_exitreason = CLIENT_EXIT_DETACHED_HUP;
@@ -668,7 +612,8 @@ client_dispatch_attached(void)
client_write_server(MSG_EXITING, NULL, 0);
break;
case MSG_EXIT:
if (datalen != 0 && datalen != sizeof (int))
if (datalen != 0 &&
datalen != sizeof (struct msg_exit_data))
fatalx("bad MSG_EXIT size");
client_write_server(MSG_EXITING, NULL, 0);
@@ -701,12 +646,16 @@ client_dispatch_attached(void)
kill(getpid(), SIGTSTP);
break;
case MSG_LOCK:
if (datalen == 0 || data[datalen - 1] != '\0')
fatalx("bad MSG_LOCK string");
if (datalen != sizeof lockdata)
fatalx("bad MSG_LOCK size");
memcpy(&lockdata, imsg.data, sizeof lockdata);
system(data);
lockdata.cmd[(sizeof lockdata.cmd) - 1] = '\0';
system(lockdata.cmd);
client_write_server(MSG_UNLOCK, NULL, 0);
break;
default:
fatalx("unexpected message");
}
imsg_free(&imsg);
+159
View File
@@ -0,0 +1,159 @@
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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.
*/
#include <sys/types.h>
#include <string.h>
#include <time.h>
#include "tmux.h"
const char clock_table[14][5][5] = {
{ { 1,1,1,1,1 }, /* 0 */
{ 1,0,0,0,1 },
{ 1,0,0,0,1 },
{ 1,0,0,0,1 },
{ 1,1,1,1,1 } },
{ { 0,0,0,0,1 }, /* 1 */
{ 0,0,0,0,1 },
{ 0,0,0,0,1 },
{ 0,0,0,0,1 },
{ 0,0,0,0,1 } },
{ { 1,1,1,1,1 }, /* 2 */
{ 0,0,0,0,1 },
{ 1,1,1,1,1 },
{ 1,0,0,0,0 },
{ 1,1,1,1,1 } },
{ { 1,1,1,1,1 }, /* 3 */
{ 0,0,0,0,1 },
{ 1,1,1,1,1 },
{ 0,0,0,0,1 },
{ 1,1,1,1,1 } },
{ { 1,0,0,0,1 }, /* 4 */
{ 1,0,0,0,1 },
{ 1,1,1,1,1 },
{ 0,0,0,0,1 },
{ 0,0,0,0,1 } },
{ { 1,1,1,1,1 }, /* 5 */
{ 1,0,0,0,0 },
{ 1,1,1,1,1 },
{ 0,0,0,0,1 },
{ 1,1,1,1,1 } },
{ { 1,1,1,1,1 }, /* 6 */
{ 1,0,0,0,0 },
{ 1,1,1,1,1 },
{ 1,0,0,0,1 },
{ 1,1,1,1,1 } },
{ { 1,1,1,1,1 }, /* 7 */
{ 0,0,0,0,1 },
{ 0,0,0,0,1 },
{ 0,0,0,0,1 },
{ 0,0,0,0,1 } },
{ { 1,1,1,1,1 }, /* 8 */
{ 1,0,0,0,1 },
{ 1,1,1,1,1 },
{ 1,0,0,0,1 },
{ 1,1,1,1,1 } },
{ { 1,1,1,1,1 }, /* 9 */
{ 1,0,0,0,1 },
{ 1,1,1,1,1 },
{ 0,0,0,0,1 },
{ 1,1,1,1,1 } },
{ { 0,0,0,0,0 }, /* : */
{ 0,0,1,0,0 },
{ 0,0,0,0,0 },
{ 0,0,1,0,0 },
{ 0,0,0,0,0 } },
{ { 1,1,1,1,1 }, /* A */
{ 1,0,0,0,1 },
{ 1,1,1,1,1 },
{ 1,0,0,0,1 },
{ 1,0,0,0,1 } },
{ { 1,1,1,1,1 }, /* P */
{ 1,0,0,0,1 },
{ 1,1,1,1,1 },
{ 1,0,0,0,0 },
{ 1,0,0,0,0 } },
{ { 1,0,0,0,1 }, /* M */
{ 1,1,0,1,1 },
{ 1,0,1,0,1 },
{ 1,0,0,0,1 },
{ 1,0,0,0,1 } },
};
void
clock_draw(struct screen_write_ctx *ctx, int colour, int style)
{
struct screen *s = ctx->s;
struct grid_cell gc;
char tim[64], *ptr;
time_t t;
u_int i, j, x, y, idx;
t = time(NULL);
if (style == 0)
strftime(tim, sizeof tim, "%l:%M %p", localtime(&t));
else
strftime(tim, sizeof tim, "%H:%M", localtime(&t));
screen_write_clearscreen(ctx);
if (screen_size_x(s) < 6 * strlen(tim) || screen_size_y(s) < 6) {
if (screen_size_x(s) >= strlen(tim) && screen_size_y(s) != 0) {
x = (screen_size_x(s) / 2) - (strlen(tim) / 2);
y = screen_size_y(s) / 2;
screen_write_cursormove(ctx, x, y);
memcpy(&gc, &grid_default_cell, sizeof gc);
colour_set_fg(&gc, colour);
screen_write_puts(ctx, &gc, "%s", tim);
}
return;
}
x = (screen_size_x(s) / 2) - 3 * strlen(tim);
y = (screen_size_y(s) / 2) - 3;
memcpy(&gc, &grid_default_cell, sizeof gc);
colour_set_bg(&gc, colour);
for (ptr = tim; *ptr != '\0'; ptr++) {
if (*ptr >= '0' && *ptr <= '9')
idx = *ptr - '0';
else if (*ptr == ':')
idx = 10;
else if (*ptr == 'A')
idx = 11;
else if (*ptr == 'P')
idx = 12;
else if (*ptr == 'M')
idx = 13;
else {
x += 6;
continue;
}
for (j = 0; j < 5; j++) {
for (i = 0; i < 5; i++) {
screen_write_cursormove(ctx, x + i, y + j);
if (clock_table[idx][j][i])
screen_write_putc(ctx, &gc, ' ');
}
}
x += 6;
}
}
+19 -87
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,11 +18,7 @@
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "tmux.h"
@@ -34,58 +30,34 @@ enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_attach_session_entry = {
"attach-session", "attach",
"c:drt:", 0, 0,
"[-dr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
CMD_CANTNEST|CMD_STARTSERVER,
"drt:", 0, 0,
"[-dr] " CMD_TARGET_SESSION_USAGE,
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON,
NULL,
NULL,
cmd_attach_session_exec
};
enum cmd_retval
cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
const char *cflag)
cmd_attach_session(struct cmd_q *cmdq, const char* tflag, int dflag, int rflag)
{
struct session *s;
struct client *c;
struct winlink *wl = NULL;
struct window *w = NULL;
struct window_pane *wp = NULL;
const char *update;
char *cause;
u_int i;
int fd;
struct format_tree *ft;
char *cp;
struct session *s;
struct client *c;
const char *update;
char *cause;
u_int i;
if (RB_EMPTY(&sessions)) {
cmdq_error(cmdq, "no sessions");
return (CMD_RETURN_ERROR);
}
if (tflag == NULL) {
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
} else if (tflag[strcspn(tflag, ":.")] != '\0') {
if ((wl = cmd_find_pane(cmdq, tflag, &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
} else {
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
w = cmd_lookup_windowid(tflag);
if (w == NULL && (wp = cmd_lookup_paneid(tflag)) != NULL)
w = wp->window;
if (w != NULL)
wl = winlink_find_by_window(&s->windows, w);
}
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
if (cmdq->client == NULL)
return (CMD_RETURN_NORMAL);
if (wl != NULL) {
if (wp != NULL)
window_set_active_pane(wp->window, wp);
session_set_current(s, wl);
}
if (cmdq->client->session != NULL) {
if (dflag) {
/*
@@ -98,67 +70,27 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
continue;
if (c == cmdq->client)
continue;
server_write_client(c, MSG_DETACH,
c->session->name,
strlen(c->session->name) + 1);
server_write_client(c, MSG_DETACH, NULL, 0);
}
}
if (cflag != NULL) {
ft = format_create();
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
NULL, NULL);
cp = format_expand(ft, cflag);
format_free(ft);
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
cmdq_error(cmdq, "bad working directory: %s",
strerror(errno));
return (CMD_RETURN_ERROR);
}
close(s->cwd);
s->cwd = fd;
}
cmdq->client->session = s;
notify_attached_session_changed(cmdq->client);
session_update_activity(s);
server_redraw_client(cmdq->client);
s->curw->flags &= ~WINLINK_ALERTFLAGS;
} else {
if (server_client_open(cmdq->client, &cause) != 0) {
if (server_client_open(cmdq->client, s, &cause) != 0) {
cmdq_error(cmdq, "open terminal failed: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
if (cflag != NULL) {
ft = format_create();
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
NULL, NULL);
cp = format_expand(ft, cflag);
format_free(ft);
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
cmdq_error(cmdq, "bad working directory: %s",
strerror(errno));
return (CMD_RETURN_ERROR);
}
close(s->cwd);
s->cwd = fd;
}
if (rflag)
cmdq->client->flags |= CLIENT_READONLY;
if (dflag) {
server_write_session(s, MSG_DETACH, s->name,
strlen(s->name) + 1);
}
if (dflag)
server_write_session(s, MSG_DETACH, NULL, 0);
update = options_get_string(&s->options, "update-environment");
environ_update(update, &cmdq->client->environ, &s->environ);
@@ -184,5 +116,5 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args;
return (cmd_attach_session(cmdq, args_get(args, 't'),
args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c')));
args_has(args, 'd'), args_has(args, 'r')));
}
+21 -17
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,18 +27,34 @@
* Bind a key to a command, this recurses through cmd_*.
*/
enum cmd_retval cmd_bind_key_check(struct args *);
enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_q *);
enum cmd_retval cmd_bind_key_mode_table(struct cmd *, struct cmd_q *, int);
enum cmd_retval cmd_bind_key_table(struct cmd *, struct cmd_q *, int);
const struct cmd_entry cmd_bind_key_entry = {
"bind-key", "bind",
"cnrt:", 1, -1,
"[-cnr] [-t mode-table] key command [arguments]",
"[-cnr] [-t key-table] key command [arguments]",
0,
NULL,
cmd_bind_key_check,
cmd_bind_key_exec
};
enum cmd_retval
cmd_bind_key_check(struct args *args)
{
if (args_has(args, 't')) {
if (args->argc != 2 && args->argc != 3)
return (CMD_RETURN_ERROR);
} else {
if (args->argc < 2)
return (CMD_RETURN_ERROR);
}
return (CMD_RETURN_NORMAL);
}
enum cmd_retval
cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
{
@@ -47,18 +63,6 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
struct cmd_list *cmdlist;
int key;
if (args_has(args, 't')) {
if (args->argc != 2 && args->argc != 3) {
cmdq_error(cmdq, "not enough arguments");
return (CMD_RETURN_ERROR);
}
} else {
if (args->argc < 2) {
cmdq_error(cmdq, "not enough arguments");
return (CMD_RETURN_ERROR);
}
}
key = key_string_lookup_string(args->argv[0]);
if (key == KEYC_NONE) {
cmdq_error(cmdq, "unknown key: %s", args->argv[0]);
@@ -66,7 +70,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
}
if (args_has(args, 't'))
return (cmd_bind_key_mode_table(self, cmdq, key));
return (cmd_bind_key_table(self, cmdq, key));
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0,
&cause);
@@ -83,7 +87,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
}
enum cmd_retval
cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, int key)
cmd_bind_key_table(struct cmd *self, struct cmd_q *cmdq, int key)
{
struct args *args = self->args;
const char *tablename;
+24 -5
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -26,8 +26,6 @@
* Break pane off into a window.
*/
#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_break_pane_entry = {
@@ -35,12 +33,18 @@ const struct cmd_entry cmd_break_pane_entry = {
"dPF:t:", 0, 0,
"[-dP] [-F format] " CMD_TARGET_PANE_USAGE,
0,
NULL,
NULL,
cmd_break_pane_exec
};
enum cmd_retval
cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
#ifdef TMATE
cmdq_error(cmdq, "break pane is not supported with tmate");
return (CMD_RETURN_ERROR);
#else
struct args *args = self->args;
struct winlink *wl;
struct session *s;
@@ -49,6 +53,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
char *name;
char *cause;
int base_idx;
struct client *c;
struct format_tree *ft;
const char *template;
char *cp;
@@ -65,7 +70,16 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
server_unzoom_window(w);
TAILQ_REMOVE(&w->panes, wp, entry);
window_lost_pane(w, wp);
if (wp == w->active) {
w->active = w->last;
w->last = NULL;
if (w->active == NULL) {
w->active = TAILQ_PREV(wp, window_panes, entry);
if (w->active == NULL)
w->active = TAILQ_NEXT(wp, entry);
}
} else if (wp == w->last)
w->last = NULL;
layout_close_pane(wp);
w = wp->window = window_create1(s->sx, s->sy);
@@ -89,7 +103,11 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
template = BREAK_PANE_TEMPLATE;
ft = format_create();
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, wl, wp);
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
format_client(ft, c);
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, wp);
cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp);
@@ -98,4 +116,5 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
format_free(ft);
}
return (CMD_RETURN_NORMAL);
#endif
}
+39 -39
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
@@ -38,16 +38,18 @@ char *cmd_capture_pane_history(struct args *, struct cmd_q *,
const struct cmd_entry cmd_capture_pane_entry = {
"capture-pane", "capturep",
"ab:CeE:JpPqS:t:", 0, 0,
"[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] [-S start-line]"
"[-aCeJpPq] [-b buffer-index] [-E end-line] [-S start-line]"
CMD_TARGET_PANE_USAGE,
0,
NULL,
NULL,
cmd_capture_pane_exec
};
char *
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
{
buf = xrealloc(buf, *len + linelen + 1);
buf = xrealloc(buf, 1, *len + linelen + 1);
memcpy(buf + *len, line, linelen);
*len += linelen;
return (buf);
@@ -93,7 +95,6 @@ cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq,
int n, with_codes, escape_c0, join_lines;
u_int i, sx, top, bottom, tmp;
char *cause, *buf, *line;
const char *Sflag, *Eflag;
size_t linelen;
sx = screen_size_x(&wp->base);
@@ -109,37 +110,27 @@ cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq,
} else
gd = wp->base.grid;
Sflag = args_get(args, 'S');
if (Sflag != NULL && strcmp(Sflag, "-") == 0)
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
if (cause != NULL) {
top = gd->hsize;
free(cause);
} else if (n < 0 && (u_int) -n > gd->hsize)
top = 0;
else {
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
if (cause != NULL) {
top = gd->hsize;
free(cause);
} else if (n < 0 && (u_int) -n > gd->hsize)
top = 0;
else
top = gd->hsize + n;
if (top > gd->hsize + gd->sy - 1)
top = gd->hsize + gd->sy - 1;
}
else
top = gd->hsize + n;
if (top > gd->hsize + gd->sy - 1)
top = gd->hsize + gd->sy - 1;
Eflag = args_get(args, 'E');
if (Eflag != NULL && strcmp(Eflag, "-") == 0)
n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause);
if (cause != NULL) {
bottom = gd->hsize + gd->sy - 1;
free(cause);
} else if (n < 0 && (u_int) -n > gd->hsize)
bottom = 0;
else
bottom = gd->hsize + n;
if (bottom > gd->hsize + gd->sy - 1)
bottom = gd->hsize + gd->sy - 1;
else {
n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause);
if (cause != NULL) {
bottom = gd->hsize + gd->sy - 1;
free(cause);
} else if (n < 0 && (u_int) -n > gd->hsize)
bottom = 0;
else
bottom = gd->hsize + n;
if (bottom > gd->hsize + gd->sy - 1)
bottom = gd->hsize + gd->sy - 1;
}
if (bottom < top) {
tmp = bottom;
@@ -175,7 +166,8 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
struct client *c;
struct window_pane *wp;
char *buf, *cause;
const char *bufname;
int buffer;
u_int limit;
size_t len;
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
@@ -201,17 +193,25 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);
} else {
limit = options_get_number(&global_options, "buffer-limit");
if (!args_has(args, 'b')) {
paste_add(&global_buffers, buf, len, limit);
return (CMD_RETURN_NORMAL);
}
bufname = NULL;
if (args_has(args, 'b'))
bufname = args_get(args, 'b');
if (paste_set(buf, len, bufname, &cause) != 0) {
cmdq_error(cmdq, "%s", cause);
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
cmdq_error(cmdq, "buffer %s", cause);
free(buf);
free(cause);
return (CMD_RETURN_ERROR);
}
if (paste_replace(&global_buffers, buffer, buf, len) != 0) {
cmdq_error(cmdq, "no buffer %d", buffer);
free(buf);
return (CMD_RETURN_ERROR);
}
}
return (CMD_RETURN_NORMAL);
+9 -13
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,9 +27,6 @@
* Enter choice mode to choose a buffer.
*/
#define CHOOSE_BUFFER_TEMPLATE \
"#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}"
enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_choose_buffer_entry = {
@@ -37,6 +34,8 @@ const struct cmd_entry cmd_choose_buffer_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
0,
NULL,
NULL,
cmd_choose_buffer_exec
};
@@ -51,7 +50,6 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
char *action, *action_data;
const char *template;
u_int idx;
int utf8flag;
if ((c = cmd_current_client(cmdq)) == NULL) {
cmdq_error(cmdq, "no client available");
@@ -63,9 +61,8 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
utf8flag = options_get_number(&wl->window->options, "utf8");
if (paste_get_top() == NULL)
if (paste_get_top(&global_buffers) == NULL)
return (CMD_RETURN_NORMAL);
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
@@ -77,20 +74,19 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
action = xstrdup("paste-buffer -b '%%'");
idx = 0;
pb = NULL;
while ((pb = paste_walk(pb)) != NULL) {
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
cdata->idx = idx;
cdata->idx = idx - 1;
cdata->ft_template = xstrdup(template);
format_defaults_paste_buffer(cdata->ft, pb, utf8flag);
format_add(cdata->ft, "line", "%u", idx - 1);
format_paste_buffer(cdata->ft, pb);
xasprintf(&action_data, "%s", pb->name);
xasprintf(&action_data, "%u", idx - 1);
cdata->command = cmd_template_replace(action, action_data, 1);
free(action_data);
window_choose_add(wl->window->active, cdata);
idx++;
}
free(action);
+5 -8
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,12 +27,6 @@
* Enter choice mode to choose a client.
*/
#define CHOOSE_CLIENT_TEMPLATE \
"#{client_tty}: #{session_name} " \
"[#{client_width}x#{client_height} #{client_termname}]" \
"#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \
"(last used #{client_activity_string})"
enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_q *);
void cmd_choose_client_callback(struct window_choose_data *);
@@ -42,6 +36,8 @@ const struct cmd_entry cmd_choose_client_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
0,
NULL,
NULL,
cmd_choose_client_exec
};
@@ -94,7 +90,8 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq)
cdata->ft_template = xstrdup(template);
format_add(cdata->ft, "line", "%u", i);
format_defaults(cdata->ft, c1, NULL, NULL, NULL);
format_session(cdata->ft, c1->session);
format_client(cdata->ft, c1);
cdata->command = cmd_template_replace(action, c1->tty.path, 1);
+98
View File
@@ -0,0 +1,98 @@
/* $Id$ */
/*
* Copyright (c) 2012 Thomas Adam <thomas@xteddy.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.
*/
#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
#define CMD_CHOOSE_LIST_DEFAULT_TEMPLATE "run-shell '%%'"
/*
* Enter choose mode to choose a custom list.
*/
enum cmd_retval cmd_choose_list_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_choose_list_entry = {
"choose-list", NULL,
"l:t:", 0, 1,
"[-l items] " CMD_TARGET_WINDOW_USAGE "[template]",
0,
NULL,
NULL,
cmd_choose_list_exec
};
enum cmd_retval
cmd_choose_list_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
struct winlink *wl;
const char *list1;
char *template, *item, *copy, *list;
u_int idx;
if ((c = cmd_current_client(cmdq)) == NULL) {
cmdq_error(cmdq, "no client available");
return (CMD_RETURN_ERROR);
}
if ((list1 = args_get(args, 'l')) == NULL)
return (CMD_RETURN_ERROR);
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
return (CMD_RETURN_NORMAL);
if (args->argc != 0)
template = xstrdup(args->argv[0]);
else
template = xstrdup(CMD_CHOOSE_LIST_DEFAULT_TEMPLATE);
copy = list = xstrdup(list1);
idx = 0;
while ((item = strsep(&list, ",")) != NULL)
{
if (*item == '\0') /* no empty entries */
continue;
window_choose_add_item(wl->window->active, c, wl, item,
template, idx);
idx++;
}
free(copy);
if (idx == 0) {
free(template);
window_pane_reset_mode(wl->window->active);
return (CMD_RETURN_ERROR);
}
window_choose_ready(wl->window->active, 0, NULL);
free(template);
return (CMD_RETURN_NORMAL);
}
+12 -14
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
@@ -32,15 +32,6 @@
* Enter choice mode to choose a session and/or window.
*/
#define CHOOSE_TREE_SESSION_TEMPLATE \
"#{session_name}: #{session_windows} windows" \
"#{?session_grouped, (group ,}" \
"#{session_group}#{?session_grouped,),}" \
"#{?session_attached, (attached),}"
#define CHOOSE_TREE_WINDOW_TEMPLATE \
"#{window_index}: #{window_name}#{window_flags} " \
"\"#{pane_title}\""
enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_choose_tree_entry = {
@@ -49,6 +40,8 @@ const struct cmd_entry cmd_choose_tree_entry = {
"[-suw] [-b session-template] [-c window template] [-S format] " \
"[-W format] " CMD_TARGET_WINDOW_USAGE,
0,
NULL,
NULL,
cmd_choose_tree_exec
};
@@ -57,6 +50,8 @@ const struct cmd_entry cmd_choose_session_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
0,
NULL,
NULL,
cmd_choose_tree_exec
};
@@ -65,6 +60,8 @@ const struct cmd_entry cmd_choose_window_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE "[-F format] [template]",
0,
NULL,
NULL,
cmd_choose_tree_exec
};
@@ -92,7 +89,10 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
if ((s = c->session) == NULL)
return (CMD_RETURN_ERROR);
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
@@ -232,10 +232,8 @@ windows_only:
window_choose_ready(wl->window->active, cur_win, NULL);
if (args_has(args, 'u')) {
if (args_has(args, 'u'))
window_choose_expand_all(wl->window->active);
window_choose_set_current(wl->window->active, cur_win);
}
return (CMD_RETURN_NORMAL);
}
+3 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -31,6 +31,8 @@ const struct cmd_entry cmd_clear_history_entry = {
"t:", 0, 0,
CMD_TARGET_PANE_USAGE,
0,
NULL,
NULL,
cmd_clear_history_exec
};
+28 -38
View File
@@ -1,5 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -14,48 +16,36 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include "tmux.h"
int
openat(int fd, const char *path, int flags, ...)
/*
* Enter clock mode.
*/
enum cmd_retval cmd_clock_mode_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_clock_mode_entry = {
"clock-mode", NULL,
"t:", 0, 0,
CMD_TARGET_PANE_USAGE,
0,
NULL,
NULL,
cmd_clock_mode_exec
};
enum cmd_retval
cmd_clock_mode_exec(struct cmd *self, struct cmd_q *cmdq)
{
mode_t mode;
va_list ap;
int dotfd, retval, saved_errno;
struct args *args = self->args;
struct window_pane *wp;
if (flags & O_CREAT) {
va_start(ap, flags);
mode = va_arg(ap, mode_t);
va_end(ap);
} else
mode = 0;
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
dotfd = -1;
if (fd != AT_FDCWD) {
dotfd = open(".", O_RDONLY);
if (dotfd == -1)
return (-1);
if (fchdir(fd) != 0)
return (-1);
}
window_pane_set_mode(wp, &window_clock_mode);
retval = open(path, flags, mode);
if (dotfd != -1) {
if (fchdir(dotfd) != 0) {
saved_errno = errno;
close(retval);
close(dotfd);
errno = saved_errno;
return (-1);
}
close(dotfd);
}
return (retval);
return (CMD_RETURN_NORMAL);
}
+33 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,6 +29,8 @@
* Prompt for command in client.
*/
void cmd_command_prompt_key_binding(struct cmd *, int);
int cmd_command_prompt_check(struct args *);
enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *);
int cmd_command_prompt_callback(void *, const char *);
@@ -39,6 +41,8 @@ const struct cmd_entry cmd_command_prompt_entry = {
"I:p:t:", 0, 1,
"[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " [template]",
0,
cmd_command_prompt_key_binding,
NULL,
cmd_command_prompt_exec
};
@@ -52,6 +56,34 @@ struct cmd_command_prompt_cdata {
int idx;
};
void
cmd_command_prompt_key_binding(struct cmd *self, int key)
{
switch (key) {
case '$':
self->args = args_create(1, "rename-session '%%'");
args_set(self->args, 'I', "#S");
break;
case ',':
self->args = args_create(1, "rename-window '%%'");
args_set(self->args, 'I', "#W");
break;
case '.':
self->args = args_create(1, "move-window -t '%%'");
break;
case 'f':
self->args = args_create(1, "find-window '%%'");
break;
case '\'':
self->args = args_create(1, "select-window -t ':%%'");
args_set(self->args, 'p', "index");
break;
default:
self->args = args_create(0);
break;
}
}
enum cmd_retval
cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
{
+22 -3
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -16,8 +16,6 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@@ -28,6 +26,7 @@
* Asks for confirmation before executing a command.
*/
void cmd_confirm_before_key_binding(struct cmd *, int);
enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *);
int cmd_confirm_before_callback(void *, const char *);
@@ -38,6 +37,8 @@ const struct cmd_entry cmd_confirm_before_entry = {
"p:t:", 1, 1,
"[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
0,
cmd_confirm_before_key_binding,
NULL,
cmd_confirm_before_exec
};
@@ -46,6 +47,24 @@ struct cmd_confirm_before_data {
struct client *client;
};
void
cmd_confirm_before_key_binding(struct cmd *self, int key)
{
switch (key) {
case '&':
self->args = args_create(1, "kill-window");
args_set(self->args, 'p', "kill-window #W? (y/n)");
break;
case 'x':
self->args = args_create(1, "kill-pane");
args_set(self->args, 'p', "kill-pane #P? (y/n)");
break;
default:
self->args = args_create(0);
break;
}
}
enum cmd_retval
cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
{
+14 -18
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -21,9 +21,10 @@
#include "tmux.h"
/*
* Enter copy or clock mode.
* Enter copy mode.
*/
void cmd_copy_mode_key_binding(struct cmd *, int);
enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_copy_mode_entry = {
@@ -31,16 +32,18 @@ const struct cmd_entry cmd_copy_mode_entry = {
"t:u", 0, 0,
"[-u] " CMD_TARGET_PANE_USAGE,
0,
cmd_copy_mode_key_binding,
NULL,
cmd_copy_mode_exec
};
const struct cmd_entry cmd_clock_mode_entry = {
"clock-mode", NULL,
"t:", 0, 0,
CMD_TARGET_PANE_USAGE,
0,
cmd_copy_mode_exec
};
void
cmd_copy_mode_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
if (key == KEYC_PPAGE)
args_set(self->args, 'u', NULL);
}
enum cmd_retval
cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq)
@@ -51,16 +54,9 @@ cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq)
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
if (self->entry == &cmd_clock_mode_entry) {
window_pane_set_mode(wp, &window_clock_mode);
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
return (CMD_RETURN_NORMAL);
}
if (wp->mode != &window_copy_mode) {
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
return (CMD_RETURN_NORMAL);
window_copy_init_from_pane(wp);
}
window_copy_init_from_pane(wp);
if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
window_copy_pageup(wp);
+15 -6
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -33,6 +33,8 @@ const struct cmd_entry cmd_delete_buffer_entry = {
"b:", 0, 0,
CMD_BUFFER_USAGE,
0,
NULL,
NULL,
cmd_delete_buffer_exec
};
@@ -40,16 +42,23 @@ enum cmd_retval
cmd_delete_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
const char *bufname;
char *cause;
int buffer;
if (!args_has(args, 'b')) {
paste_free_top();
paste_free_top(&global_buffers);
return (CMD_RETURN_NORMAL);
}
bufname = args_get(args, 'b');
if (paste_free_name(bufname) != 0) {
cmdq_error(cmdq, "no buffer %s", bufname);
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
cmdq_error(cmdq, "buffer %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
if (paste_free_index(&global_buffers, buffer) != 0) {
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
}
+23 -50
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,8 +18,6 @@
#include <sys/types.h>
#include <string.h>
#include "tmux.h"
/*
@@ -33,14 +31,8 @@ const struct cmd_entry cmd_detach_client_entry = {
"as:t:P", 0, 0,
"[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
CMD_READONLY,
cmd_detach_client_exec
};
const struct cmd_entry cmd_suspend_client_entry = {
"suspend-client", "suspendc",
"t:", 0, 0,
CMD_TARGET_CLIENT_USAGE,
0,
NULL,
NULL,
cmd_detach_client_exec
};
@@ -48,20 +40,11 @@ enum cmd_retval
cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c, *cloop;
struct session *s;
enum msgtype msgtype;
struct client *c, *c2;
struct session *s;
enum msgtype msgtype;
u_int i;
if (self->entry == &cmd_suspend_client_entry) {
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
tty_stop_tty(&c->tty);
c->flags |= CLIENT_SUSPENDED;
server_write_client(c, MSG_SUSPEND, NULL, 0);
return (CMD_RETURN_NORMAL);
}
if (args_has(args, 'P'))
msgtype = MSG_DETACHKILL;
else
@@ -73,35 +56,25 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
cloop = ARRAY_ITEM(&clients, i);
if (cloop == NULL || cloop->session != s)
continue;
server_write_client(cloop, msgtype,
cloop->session->name,
strlen(cloop->session->name) + 1);
c = ARRAY_ITEM(&clients, i);
if (c != NULL && c->session == s)
server_write_client(c, msgtype, NULL, 0);
}
return (CMD_RETURN_STOP);
} else {
c = cmd_find_client(cmdq, args_get(args, 't'), 0);
if (c == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 'a')) {
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c2 = ARRAY_ITEM(&clients, i);
if (c2 == NULL || c == c2)
continue;
server_write_client(c2, msgtype, NULL, 0);
}
} else
server_write_client(c, msgtype, NULL, 0);
}
c = cmd_find_client(cmdq, args_get(args, 't'), 0);
if (c == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 'a')) {
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
cloop = ARRAY_ITEM(&clients, i);
if (cloop == NULL || cloop->session == NULL)
continue;
if (cloop == c)
continue;
server_write_client(cloop, msgtype,
cloop->session->name,
strlen(cloop->session->name) + 1);
}
return (CMD_RETURN_NORMAL);
}
server_write_client(c, msgtype, c->session->name,
strlen(c->session->name) + 1);
return (CMD_RETURN_STOP);
}
+11 -10
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -27,11 +27,6 @@
* Displays a message in the status line.
*/
#define DISPLAY_MESSAGE_TEMPLATE \
"[#{session_name}] #{window_index}:" \
"#{window_name}, current pane #{pane_index} " \
"- (%H:%M %d-%b-%y)"
enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_display_message_entry = {
@@ -40,6 +35,8 @@ const struct cmd_entry cmd_display_message_entry = {
"[-p] [-c target-client] [-F format] " CMD_TARGET_PANE_USAGE
" [message]",
0,
NULL,
NULL,
cmd_display_message_exec
};
@@ -74,9 +71,9 @@ cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq)
}
if (args_has(args, 'c')) {
c = cmd_find_client(cmdq, args_get(args, 'c'), 0);
if (c == NULL)
return (CMD_RETURN_ERROR);
c = cmd_find_client(cmdq, args_get(args, 'c'), 0);
if (c == NULL)
return (CMD_RETURN_ERROR);
} else {
c = cmd_current_client(cmdq);
if (c == NULL && !args_has(self->args, 'p')) {
@@ -92,7 +89,11 @@ cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq)
template = DISPLAY_MESSAGE_TEMPLATE;
ft = format_create();
format_defaults(ft, c, s, wl, wp);
if (c != NULL)
format_client(ft, c);
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, wp);
t = time(NULL);
len = strftime(out, sizeof out, template, localtime(&t));
+3 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -31,6 +31,8 @@ const struct cmd_entry cmd_display_panes_entry = {
"t:", 0, 0,
CMD_TARGET_CLIENT_USAGE,
0,
NULL,
NULL,
cmd_display_panes_exec
};
+8 -12
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -28,11 +28,6 @@
* Find window containing text.
*/
#define FIND_WINDOW_TEMPLATE \
"#{window_index}: #{window_name} " \
"[#{window_width}x#{window_height}] " \
"(#{window_panes} panes) #{window_find_matches}"
enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_q *);
void cmd_find_window_callback(struct window_choose_data *);
@@ -52,6 +47,8 @@ const struct cmd_entry cmd_find_window_entry = {
"F:CNt:T", 1, 4,
"[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string",
0,
NULL,
NULL,
cmd_find_window_exec
};
@@ -88,8 +85,7 @@ cmd_find_window_match_flags(struct args *args)
void
cmd_find_window_match(struct cmd_find_window_data_list *find_list,
int match_flags, struct winlink *wl, const char *str,
const char *searchstr)
int match_flags, struct winlink *wl, const char *str, const char *searchstr)
{
struct cmd_find_window_data find_data;
struct window_pane *wp;
@@ -162,7 +158,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
xasprintf(&searchstr, "*%s*", str);
RB_FOREACH(wm, winlinks, &s->windows)
cmd_find_window_match(&find_list, match_flags, wm, str, searchstr);
cmd_find_window_match (&find_list, match_flags, wm, str, searchstr);
free(searchstr);
if (ARRAY_LENGTH(&find_list) == 0) {
@@ -194,7 +190,9 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
format_add(cdata->ft, "line", "%u", i);
format_add(cdata->ft, "window_find_matches", "%s",
ARRAY_ITEM(&find_list, i).list_ctx);
format_defaults(cdata->ft, NULL, s, wm, NULL);
format_session(cdata->ft, s);
format_winlink(cdata->ft, s, wm);
format_window_pane(cdata->ft, wm->window->active);
window_choose_add(wl->window->active, cdata);
}
@@ -202,8 +200,6 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
window_choose_ready(wl->window->active, 0, cmd_find_window_callback);
out:
for (i = 0; i < ARRAY_LENGTH(&find_list); i++)
free(ARRAY_ITEM(&find_list, i).list_ctx);
ARRAY_FREE(&find_list);
return (CMD_RETURN_NORMAL);
}
+48
View File
@@ -0,0 +1,48 @@
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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.
*/
#include <sys/types.h>
#include "tmux.h"
/*
* Cause client to report an error and exit with 1 if session doesn't exist.
*/
enum cmd_retval cmd_has_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_has_session_entry = {
"has-session", "has",
"t:", 0, 0,
CMD_TARGET_SESSION_USAGE,
0,
NULL,
NULL,
cmd_has_session_exec
};
enum cmd_retval
cmd_has_session_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
if (cmd_find_session(cmdq, args_get(args, 't'), 0) == NULL)
return (CMD_RETURN_ERROR);
return (CMD_RETURN_NORMAL);
}
+12 -29
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -37,9 +37,11 @@ void cmd_if_shell_free(void *);
const struct cmd_entry cmd_if_shell_entry = {
"if-shell", "if",
"bFt:", 2, 3,
"[-bF] " CMD_TARGET_PANE_USAGE " shell-command command [command]",
"bt:", 2, 3,
"[-b] " CMD_TARGET_PANE_USAGE " shell-command command [command]",
0,
NULL,
NULL,
cmd_if_shell_exec
};
@@ -56,8 +58,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct cmd_if_shell_data *cdata;
char *shellcmd, *cmd, *cause;
struct cmd_list *cmdlist;
char *shellcmd;
struct client *c;
struct session *s = NULL;
struct winlink *wl = NULL;
@@ -76,30 +77,15 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
}
ft = format_create();
format_defaults(ft, NULL, s, wl, wp);
if (s != NULL)
format_session(ft, s);
if (s != NULL && wl != NULL)
format_winlink(ft, s, wl);
if (wp != NULL)
format_window_pane(ft, wp);
shellcmd = format_expand(ft, args->argv[0]);
format_free(ft);
if (args_has(args, 'F')) {
cmd = NULL;
if (*shellcmd != '0' && *shellcmd != '\0')
cmd = args->argv[1];
else if (args->argc == 3)
cmd = args->argv[2];
if (cmd == NULL)
return (CMD_RETURN_NORMAL);
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) {
cmdq_error(cmdq, "%s", cause);
free(cause);
}
return (CMD_RETURN_ERROR);
}
cmdq_run(cmdq, cmdlist);
cmd_list_free(cmdlist);
return (CMD_RETURN_NORMAL);
}
cdata = xmalloc(sizeof *cdata);
cdata->cmd_if = xstrdup(args->argv[1]);
if (args->argc == 3)
@@ -162,9 +148,6 @@ cmd_if_shell_done(struct cmd_q *cmdq1)
struct cmd_if_shell_data *cdata = cmdq1->data;
struct cmd_q *cmdq = cdata->cmdq;
if (cmdq1->client_exit >= 0)
cmdq->client_exit = cmdq1->client_exit;
if (!cmdq_free(cmdq) && !cdata->bflag)
cmdq_continue(cmdq);
+30 -2
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
@@ -28,6 +28,7 @@
* Join or move a pane into another (like split/swap/kill).
*/
void cmd_join_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *);
enum cmd_retval join_pane(struct cmd *, struct cmd_q *, int);
@@ -37,6 +38,8 @@ const struct cmd_entry cmd_join_pane_entry = {
"bdhvp:l:s:t:", 0, 0,
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
0,
cmd_join_pane_key_binding,
NULL,
cmd_join_pane_exec
};
@@ -45,9 +48,25 @@ const struct cmd_entry cmd_move_pane_entry = {
"bdhvp:l:s:t:", 0, 0,
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
0,
NULL,
NULL,
cmd_join_pane_exec
};
void
cmd_join_pane_key_binding(struct cmd *self, int key)
{
switch (key) {
case '%':
self->args = args_create(0);
args_set(self->args, 'h', NULL);
break;
default:
self->args = args_create(0);
break;
}
}
enum cmd_retval
cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
@@ -57,6 +76,10 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
enum cmd_retval
join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
{
#ifdef TMATE
cmdq_error(cmdq, "join pane is not supported with tmate");
return (CMD_RETURN_ERROR);
#else
struct args *args = self->args;
struct session *dst_s;
struct winlink *src_wl, *dst_wl;
@@ -121,7 +144,11 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
layout_close_pane(src_wp);
window_lost_pane(src_w, src_wp);
if (src_w->active == src_wp) {
src_w->active = TAILQ_PREV(src_wp, window_panes, entry);
if (src_w->active == NULL)
src_w->active = TAILQ_NEXT(src_wp, entry);
}
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
if (window_count_panes(src_w) == 0)
@@ -147,4 +174,5 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
notify_window_layout_changed(dst_w);
return (CMD_RETURN_NORMAL);
#endif
}
+3 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -33,6 +33,8 @@ const struct cmd_entry cmd_kill_pane_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_PANE_USAGE,
0,
NULL,
NULL,
cmd_kill_pane_exec
};
+5 -12
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,22 +34,15 @@ const struct cmd_entry cmd_kill_server_entry = {
"", 0, 0,
"",
0,
cmd_kill_server_exec
};
const struct cmd_entry cmd_start_server_entry = {
"start-server", "start",
"", 0, 0,
"",
CMD_STARTSERVER,
NULL,
NULL,
cmd_kill_server_exec
};
enum cmd_retval
cmd_kill_server_exec(struct cmd *self, unused struct cmd_q *cmdq)
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_q *cmdq)
{
if (self->entry == &cmd_kill_server_entry)
kill(getpid(), SIGTERM);
kill(getpid(), SIGTERM);
return (CMD_RETURN_NORMAL);
}
+3 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,6 +34,8 @@ const struct cmd_entry cmd_kill_session_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_SESSION_USAGE,
0,
NULL,
NULL,
cmd_kill_session_exec
};
+12 -35
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -31,51 +31,28 @@ const struct cmd_entry cmd_kill_window_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_WINDOW_USAGE,
0,
cmd_kill_window_exec
};
const struct cmd_entry cmd_unlink_window_entry = {
"unlink-window", "unlinkw",
"kt:", 0, 0,
"[-k] " CMD_TARGET_WINDOW_USAGE,
0,
NULL,
NULL,
cmd_kill_window_exec
};
enum cmd_retval
cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl, *wl2, *wl3;
struct window *w;
struct session *s;
struct session_group *sg;
u_int references;
struct args *args = self->args;
struct winlink *wl, *wl2, *wl3;
struct session *s;
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
w = wl->window;
if (self->entry == &cmd_unlink_window_entry) {
sg = session_group_find(s);
if (sg != NULL)
references = session_group_count(sg);
else
references = 1;
if (!args_has(self->args, 'k') && w->references == references) {
cmdq_error(cmdq, "window only linked to one session");
return (CMD_RETURN_ERROR);
if (args_has(args, 'a')) {
RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) {
if (wl != wl2)
server_kill_window(wl2->window);
}
server_unlink_window(s, wl);
} else {
if (args_has(args, 'a')) {
RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) {
if (wl != wl2)
server_kill_window(wl2->window);
}
} else
server_kill_window(wl->window);
}
} else
server_kill_window(wl->window);
recalculate_sizes();
return (CMD_RETURN_NORMAL);
+70
View File
@@ -0,0 +1,70 @@
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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.
*/
#include <sys/types.h>
#include <stdlib.h>
#include "tmux.h"
/*
* Link a window into another session.
*/
enum cmd_retval cmd_link_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_link_window_entry = {
"link-window", "linkw",
"dks:t:", 0, 0,
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
0,
NULL,
NULL,
cmd_link_window_exec
};
enum cmd_retval
cmd_link_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
#ifdef TMATE
cmdq_error(cmdq, "link window is not supported with tmate");
return (CMD_RETURN_ERROR);
#else
struct args *args = self->args;
struct session *src, *dst;
struct winlink *wl;
char *cause;
int idx, kflag, dflag;
if ((wl = cmd_find_window(cmdq, args_get(args, 's'), &src)) == NULL)
return (CMD_RETURN_ERROR);
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst)) == -2)
return (CMD_RETURN_ERROR);
kflag = args_has(self->args, 'k');
dflag = args_has(self->args, 'd');
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
cmdq_error(cmdq, "can't link window: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
recalculate_sizes();
return (CMD_RETURN_NORMAL);
#endif
}
+8 -7
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,9 +27,6 @@
* List paste buffers.
*/
#define LIST_BUFFERS_TEMPLATE \
"#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\""
enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_buffers_entry = {
@@ -37,6 +34,8 @@ const struct cmd_entry cmd_list_buffers_entry = {
"F:", 0, 0,
"[-F format]",
0,
NULL,
NULL,
cmd_list_buffers_exec
};
@@ -46,16 +45,18 @@ cmd_list_buffers_exec(unused struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args;
struct paste_buffer *pb;
struct format_tree *ft;
u_int idx;
char *line;
const char *template;
if ((template = args_get(args, 'F')) == NULL)
template = LIST_BUFFERS_TEMPLATE;
pb = NULL;
while ((pb = paste_walk(pb)) != NULL) {
idx = 0;
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
ft = format_create();
format_defaults_paste_buffer(ft, pb, 0);
format_add(ft, "line", "%u", idx - 1);
format_paste_buffer(ft, pb);
line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line);
+5 -7
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -28,11 +28,6 @@
* List all clients.
*/
#define LIST_CLIENTS_TEMPLATE \
"#{client_tty}: #{session_name} " \
"[#{client_width}x#{client_height} #{client_termname}]" \
"#{?client_utf8, (utf8),} #{?client_readonly, (ro),}"
enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_clients_entry = {
@@ -40,6 +35,8 @@ const struct cmd_entry cmd_list_clients_entry = {
"F:t:", 0, 0,
"[-F format] " CMD_TARGET_SESSION_USAGE,
CMD_READONLY,
NULL,
NULL,
cmd_list_clients_exec
};
@@ -74,7 +71,8 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq)
ft = format_create();
format_add(ft, "line", "%u", i);
format_defaults(ft, c, NULL, NULL, NULL);
format_session(ft, c->session);
format_client(ft, c);
line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line);
+55
View File
@@ -0,0 +1,55 @@
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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.
*/
#include <sys/types.h>
#include "tmux.h"
/*
* List all commands with usages.
*/
enum cmd_retval cmd_list_commands_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_commands_entry = {
"list-commands", "lscm",
"", 0, 0,
"",
0,
NULL,
NULL,
cmd_list_commands_exec
};
enum cmd_retval
cmd_list_commands_exec(unused struct cmd *self, struct cmd_q *cmdq)
{
const struct cmd_entry **entryp;
for (entryp = cmd_table; *entryp != NULL; entryp++) {
if ((*entryp)->alias != NULL) {
cmdq_print(cmdq, "%s (%s) %s", (*entryp)->name,
(*entryp)->alias, (*entryp)->usage);
} else {
cmdq_print(cmdq, "%s %s", (*entryp)->name,
(*entryp)->usage);
}
}
return (CMD_RETURN_NORMAL);
}
+3 -33
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,23 +27,15 @@
*/
enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *);
enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *);
enum cmd_retval cmd_list_keys_commands(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_keys_entry = {
"list-keys", "lsk",
"t:", 0, 0,
"[-t key-table]",
0,
cmd_list_keys_exec
};
const struct cmd_entry cmd_list_commands_entry = {
"list-commands", "lscm",
"", 0, 0,
"",
0,
NULL,
NULL,
cmd_list_keys_exec
};
@@ -57,9 +49,6 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
size_t used;
int width, keywidth;
if (self->entry == &cmd_list_commands_entry)
return (cmd_list_keys_commands(self, cmdq));
if (args_has(args, 't'))
return (cmd_list_keys_table(self, cmdq));
@@ -160,22 +149,3 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL);
}
enum cmd_retval
cmd_list_keys_commands(unused struct cmd *self, struct cmd_q *cmdq)
{
const struct cmd_entry **entryp;
const struct cmd_entry *entry;
for (entryp = cmd_table; *entryp != NULL; entryp++) {
entry = *entryp;
if (entry->alias == NULL) {
cmdq_print(cmdq, "%s %s", entry->name, entry->usage);
continue;
}
cmdq_print(cmdq, "%s (%s) %s", entry->name, entry->alias,
entry->usage);
}
return (CMD_RETURN_NORMAL);
}
+6 -2
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -40,6 +40,8 @@ const struct cmd_entry cmd_list_panes_entry = {
"asF:t:", 0, 0,
"[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
0,
NULL,
NULL,
cmd_list_panes_exec
};
@@ -128,7 +130,9 @@ cmd_list_panes_window(struct cmd *self,
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
ft = format_create();
format_add(ft, "line", "%u", n);
format_defaults(ft, NULL, s, wl, wp);
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, wp);
line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line);
+4 -10
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -28,14 +28,6 @@
* List all sessions.
*/
#define LIST_SESSIONS_TEMPLATE \
"#{session_name}: #{session_windows} windows " \
"(created #{session_created_string}) " \
"[#{session_width}x#{session_height}]" \
"#{?session_grouped, (group ,}" \
"#{session_group}#{?session_grouped,),}" \
"#{?session_attached, (attached),}"
enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_sessions_entry = {
@@ -43,6 +35,8 @@ const struct cmd_entry cmd_list_sessions_entry = {
"F:", 0, 0,
"[-F format]",
0,
NULL,
NULL,
cmd_list_sessions_exec
};
@@ -63,7 +57,7 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq)
RB_FOREACH(s, sessions, &sessions) {
ft = format_create();
format_add(ft, "line", "%u", n);
format_defaults(ft, NULL, s, NULL, NULL);
format_session(ft, s);
line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line);
+8 -16
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,29 +27,19 @@
* List windows on given session.
*/
#define LIST_WINDOWS_TEMPLATE \
"#{window_index}: #{window_name}#{window_flags} " \
"(#{window_panes} panes) " \
"[#{window_width}x#{window_height}] " \
"[layout #{window_layout}] #{window_id}" \
"#{?window_active, (active),}";
#define LIST_WINDOWS_WITH_SESSION_TEMPLATE \
"#{session_name}:" \
"#{window_index}: #{window_name}#{window_flags} " \
"(#{window_panes} panes) " \
"[#{window_width}x#{window_height}] "
enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_q *);
void cmd_list_windows_server(struct cmd *, struct cmd_q *);
void cmd_list_windows_session(struct cmd *, struct session *,
struct cmd_q *, int);
void cmd_list_windows_session(
struct cmd *, struct session *, struct cmd_q *, int);
const struct cmd_entry cmd_list_windows_entry = {
"list-windows", "lsw",
"F:at:", 0, 0,
"[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
0,
NULL,
NULL,
cmd_list_windows_exec
};
@@ -107,7 +97,9 @@ cmd_list_windows_session(
RB_FOREACH(wl, winlinks, &s->windows) {
ft = format_create();
format_add(ft, "line", "%u", n);
format_defaults(ft, NULL, s, wl, NULL);
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, wl->window->active);
line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line);
+5 -9
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,7 +24,7 @@
#include "tmux.h"
struct cmd_list *
cmd_list_parse(int argc, char **argv, const char *file, u_int line,
cmd_list_parse(int argc, char **argv, const char* file, u_int line,
char **cause)
{
struct cmd_list *cmdlist;
@@ -103,7 +103,7 @@ size_t
cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
{
struct cmd *cmd;
size_t off, used;
size_t off;
off = 0;
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
@@ -112,12 +112,8 @@ cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
off += cmd_print(cmd, buf + off, len - off);
if (off >= len)
break;
if (TAILQ_NEXT(cmd, qentry) != NULL) {
used = xsnprintf(buf + off, len - off, " ; ");
if (used > len - off)
used = len - off;
off += used;
}
if (TAILQ_NEXT(cmd, qentry) != NULL)
off += xsnprintf(buf + off, len - off, " ; ");
}
return (off);
}
+56 -32
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -19,7 +19,6 @@
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -39,6 +38,8 @@ const struct cmd_entry cmd_load_buffer_entry = {
"b:", 1, 1,
CMD_BUFFER_USAGE " path",
0,
NULL,
NULL,
cmd_load_buffer_exec
};
@@ -49,19 +50,30 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
struct client *c = cmdq->client;
struct session *s;
FILE *f;
const char *path, *bufname;
const char *path, *newpath, *wd;
char *pdata, *new_pdata, *cause;
size_t psize;
int ch, error, cwd, fd;
u_int limit;
int ch, error, buffer, *buffer_ptr;
bufname = NULL;
if (args_has(args, 'b'))
bufname = args_get(args, 'b');
if (!args_has(args, 'b'))
buffer = -1;
else {
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
cmdq_error(cmdq, "buffer %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
}
path = args->argv[0];
if (strcmp(path, "-") == 0) {
error = server_set_stdin_callback(c, cmd_load_buffer_callback,
(void *)bufname, &cause);
buffer_ptr = xmalloc(sizeof *buffer_ptr);
*buffer_ptr = buffer;
error = server_set_stdin_callback (c, cmd_load_buffer_callback,
buffer_ptr, &cause);
if (error != 0) {
cmdq_error(cmdq, "%s: %s", path, cause);
free(cause);
@@ -70,17 +82,20 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_WAIT);
}
if (c != NULL && c->session == NULL)
cwd = c->cwd;
else if ((s = cmd_current_session(cmdq, 0)) != NULL)
cwd = s->cwd;
else
cwd = AT_FDCWD;
if ((fd = openat(cwd, path, O_RDONLY)) == -1 ||
(f = fdopen(fd, "rb")) == NULL) {
if (fd != -1)
close(fd);
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;
}
if ((f = fopen(path, "rb")) == NULL) {
cmdq_error(cmdq, "%s: %s", path, strerror(errno));
return (CMD_RETURN_ERROR);
}
@@ -105,10 +120,14 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
fclose(f);
if (paste_set(pdata, psize, bufname, &cause) != 0) {
cmdq_error(cmdq, "%s", cause);
limit = options_get_number(&global_options, "buffer-limit");
if (buffer == -1) {
paste_add(&global_buffers, pdata, psize, limit);
return (CMD_RETURN_NORMAL);
}
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
cmdq_error(cmdq, "no buffer %d", buffer);
free(pdata);
free(cause);
return (CMD_RETURN_ERROR);
}
@@ -124,9 +143,10 @@ error:
void
cmd_load_buffer_callback(struct client *c, int closed, void *data)
{
const char *bufname = data;
char *pdata, *cause;
size_t psize;
int *buffer = data;
char *pdata;
size_t psize;
u_int limit;
if (!closed)
return;
@@ -137,21 +157,25 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
return;
psize = EVBUFFER_LENGTH(c->stdin_data);
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL)
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL) {
free(data);
goto out;
}
memcpy(pdata, EVBUFFER_DATA(c->stdin_data), psize);
pdata[psize] = '\0';
evbuffer_drain(c->stdin_data, psize);
if (paste_set(pdata, psize, bufname, &cause) != 0) {
limit = options_get_number(&global_options, "buffer-limit");
if (*buffer == -1)
paste_add(&global_buffers, pdata, psize, limit);
else if (paste_replace(&global_buffers, *buffer, pdata, psize) != 0) {
/* No context so can't use server_client_msg_error. */
evbuffer_add_printf(c->stderr_data, "%s", cause);
evbuffer_add_printf(c->stderr_data, "no buffer %d\n", *buffer);
server_push_stderr(c);
free(pdata);
free(cause);
}
free(data);
out:
cmdq_continue(c->cmdq);
}
+11 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,6 +18,10 @@
#include <sys/types.h>
#include <pwd.h>
#include <string.h>
#include <unistd.h>
#include "tmux.h"
/*
@@ -31,6 +35,8 @@ const struct cmd_entry cmd_lock_server_entry = {
"", 0, 0,
"",
0,
NULL,
NULL,
cmd_lock_server_exec
};
@@ -39,6 +45,8 @@ const struct cmd_entry cmd_lock_session_entry = {
"t:", 0, 0,
CMD_TARGET_SESSION_USAGE,
0,
NULL,
NULL,
cmd_lock_server_exec
};
@@ -47,6 +55,8 @@ const struct cmd_entry cmd_lock_client_entry = {
"t:", 0, 0,
CMD_TARGET_CLIENT_USAGE,
0,
NULL,
NULL,
cmd_lock_server_exec
};
+12 -16
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -33,20 +33,18 @@ const struct cmd_entry cmd_move_window_entry = {
"dkrs:t:", 0, 0,
"[-dkr] " CMD_SRCDST_WINDOW_USAGE,
0,
cmd_move_window_exec
};
const struct cmd_entry cmd_link_window_entry = {
"link-window", "linkw",
"dks:t:", 0, 0,
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
0,
NULL,
NULL,
cmd_move_window_exec
};
enum cmd_retval
cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
#ifdef TMATE
cmdq_error(cmdq, "move window is not supported with tmate");
return (CMD_RETURN_ERROR);
#else
struct args *args = self->args;
struct session *src, *dst, *s;
struct winlink *wl;
@@ -54,8 +52,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
int idx, kflag, dflag;
if (args_has(args, 'r')) {
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
session_renumber_windows(s);
@@ -71,15 +68,14 @@ cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
kflag = args_has(self->args, 'k');
dflag = args_has(self->args, 'd');
if (server_link_window(src, wl, dst, idx, kflag, !dflag,
&cause) != 0) {
cmdq_error(cmdq, "can't link window: %s", cause);
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
cmdq_error(cmdq, "can't move window: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
if (self->entry == &cmd_move_window_entry)
server_unlink_window(src, wl);
server_unlink_window(src, wl);
recalculate_sizes();
return (CMD_RETURN_NORMAL);
#endif
}
+50 -104
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,8 +18,7 @@
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
@@ -31,56 +30,45 @@
* Create a new session and attach to the current terminal unless -d is given.
*/
#define NEW_SESSION_TEMPLATE "#{session_name}:"
enum cmd_retval cmd_new_session_check(struct args *);
enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_new_session_entry = {
"new-session", "new",
"Ac:dDF:n:Ps:t:x:y:", 0, -1,
"[-AdDP] [-c start-directory] [-F format] [-n window-name] "
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
"[-y height] [command]",
CMD_STARTSERVER|CMD_CANTNEST,
"AdDF:n:Ps:t:x:y:", 0, 1,
"[-AdDP] [-F format] [-n window-name] [-s session-name] "
CMD_TARGET_SESSION_USAGE " [-x width] [-y height] [command]",
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
NULL,
cmd_new_session_check,
cmd_new_session_exec
};
const struct cmd_entry cmd_has_session_entry = {
"has-session", "has",
"t:", 0, 0,
CMD_TARGET_SESSION_USAGE,
0,
cmd_new_session_exec
};
enum cmd_retval
cmd_new_session_check(struct args *args)
{
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n')))
return (CMD_RETURN_ERROR);
return (CMD_RETURN_NORMAL);
}
enum cmd_retval
cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c = cmdq->client, *c0;
struct client *c = cmdq->client;
struct session *s, *groupwith;
struct window *w;
struct environ env;
struct termios tio, *tiop;
const char *newname, *target, *update, *errstr, *template;
const char *path;
char **argv, *cmd, *cause, *cp;
int detached, already_attached, idx, cwd, fd = -1;
int argc;
struct passwd *pw;
const char *newname, *target, *update, *cwd, *errstr;
const char *template;
char *cmd, *cause, *cp;
int detached, idx;
u_int sx, sy;
int already_attached;
struct format_tree *ft;
struct environ_entry *envent;
if (self->entry == &cmd_has_session_entry) {
if (cmd_find_session(cmdq, args_get(args, 't'), 0) == NULL)
return (CMD_RETURN_ERROR);
return (CMD_RETURN_NORMAL);
}
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) {
cmdq_error(cmdq, "command or window name given with target");
return (CMD_RETURN_ERROR);
}
newname = args_get(args, 's');
if (newname != NULL) {
@@ -91,7 +79,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
if (session_find(newname) != NULL) {
if (args_has(args, 'A')) {
return (cmd_attach_session(cmdq, newname,
args_has(args, 'D'), 0, NULL));
args_has(args, 'D'), 0));
}
cmdq_error(cmdq, "duplicate session: %s", newname);
return (CMD_RETURN_ERROR);
@@ -116,34 +104,6 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
if (c != NULL && c->session != NULL)
already_attached = 1;
/* Get the new session working directory. */
if (args_has(args, 'c')) {
ft = format_create();
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), NULL, NULL,
NULL);
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
if (cp != NULL && *cp != '\0') {
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
cmdq_error(cmdq, "bad working directory: %s",
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
free(cp);
cwd = fd;
} else if (c != NULL && c->session == NULL)
cwd = c->cwd;
else if ((c0 = cmd_current_client(cmdq)) != NULL)
cwd = c0->session->cwd;
else {
fd = open(".", O_RDONLY);
cwd = fd;
}
/*
* Save the termios settings, part of which is used for new windows in
* this session.
@@ -162,13 +122,24 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
/* Open the terminal if necessary. */
if (!detached && !already_attached) {
if (server_client_open(c, &cause) != 0) {
if (server_client_open(c, NULL, &cause) != 0) {
cmdq_error(cmdq, "open terminal failed: %s", cause);
free(cause);
goto error;
return (CMD_RETURN_ERROR);
}
}
/* Get the new session working directory. */
if (c != NULL && c->cwd != NULL)
cwd = c->cwd;
else {
pw = getpwuid(getuid());
if (pw->pw_dir != NULL && *pw->pw_dir != '\0')
cwd = pw->pw_dir;
else
cwd = "/";
}
/* Find new session size. */
if (c != NULL) {
sx = c->tty.sx;
@@ -181,14 +152,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr);
if (errstr != NULL) {
cmdq_error(cmdq, "width %s", errstr);
goto error;
return (CMD_RETURN_ERROR);
}
}
if (detached && args_has(args, 'y')) {
sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr);
if (errstr != NULL) {
cmdq_error(cmdq, "height %s", errstr);
goto error;
return (CMD_RETURN_ERROR);
}
}
if (sy > 0 && options_get_number(&global_s_options, "status"))
@@ -199,29 +170,12 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
sy = 1;
/* Figure out the command for the new window. */
argc = -1;
argv = NULL;
if (target == NULL && args->argc != 0) {
argc = args->argc;
argv = args->argv;
} else if (target == NULL) {
cmd = options_get_string(&global_s_options, "default-command");
if (cmd != NULL && *cmd != '\0') {
argc = 1;
argv = &cmd;
} else {
argc = 0;
argv = NULL;
}
}
path = NULL;
if (c != NULL && c->session == NULL)
envent = environ_find(&c->environ, "PATH");
if (target != NULL)
cmd = NULL;
else if (args->argc != 0)
cmd = args->argv[0];
else
envent = environ_find(&global_environ, "PATH");
if (envent != NULL)
path = envent->value;
cmd = options_get_string(&global_s_options, "default-command");
/* Construct the environment. */
environ_init(&env);
@@ -231,17 +185,16 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
/* Create the new session. */
idx = -1 - options_get_number(&global_s_options, "base-index");
s = session_create(newname, argc, argv, path, cwd, &env, tiop, idx, sx,
sy, &cause);
s = session_create(newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
if (s == NULL) {
cmdq_error(cmdq, "create session failed: %s", cause);
free(cause);
goto error;
return (CMD_RETURN_ERROR);
}
environ_free(&env);
/* Set the initial window name if one given. */
if (argc >= 0 && args_has(args, 'n')) {
if (cmd != NULL && args_has(args, 'n')) {
w = s->curw->window;
window_set_name(w, args_get(args, 'n'));
options_set_number(&w->options, "automatic-rename", 0);
@@ -287,8 +240,9 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
template = NEW_SESSION_TEMPLATE;
ft = format_create();
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL,
NULL);
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
format_client(ft, c);
format_session(ft, s);
cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp);
@@ -299,13 +253,5 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
if (!detached)
cmdq->client_exit = 0;
if (fd != -1)
close(fd);
return (CMD_RETURN_NORMAL);
error:
if (fd != -1)
close(fd);
return (CMD_RETURN_ERROR);
}
+22 -71
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,11 +18,7 @@
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "tmux.h"
@@ -30,16 +26,16 @@
* Create a new window.
*/
#define NEW_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_new_window_entry = {
"new-window", "neww",
"ac:dF:kn:Pt:", 0, -1,
"ac:dF:kn:Pt:", 0, 1,
"[-adkP] [-c start-directory] [-F format] [-n window-name] "
CMD_TARGET_WINDOW_USAGE " [command]",
0,
NULL,
NULL,
cmd_new_window_exec
};
@@ -49,11 +45,11 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args;
struct session *s;
struct winlink *wl;
const char *cmd, *path, *template;
char **argv, *cause, *cp;
int argc, idx, last, detached, cwd, fd = -1;
struct client *c;
const char *cmd, *cwd, *template;
char *cause, *cp;
int idx, last, detached;
struct format_tree *ft;
struct environ_entry *envent;
if (args_has(args, 'a')) {
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
@@ -78,57 +74,11 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
server_unlink_window(s, wl);
}
} else {
idx = cmd_find_index(cmdq, args_get(args, 't'), &s);
if (idx == -2)
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &s)) == -2)
return (CMD_RETURN_ERROR);
}
detached = args_has(args, 'd');
if (args->argc == 0) {
cmd = options_get_string(&s->options, "default-command");
if (cmd != NULL && *cmd != '\0') {
argc = 1;
argv = (char **)&cmd;
} else {
argc = 0;
argv = NULL;
}
} else {
argc = args->argc;
argv = args->argv;
}
path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL)
envent = environ_find(&cmdq->client->environ, "PATH");
else
envent = environ_find(&s->environ, "PATH");
if (envent != NULL)
path = envent->value;
if (args_has(args, 'c')) {
ft = format_create();
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL,
NULL);
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
if (cp != NULL && *cp != '\0') {
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
cmdq_error(cmdq, "bad working directory: %s",
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
free(cp);
cwd = fd;
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
cwd = cmdq->client->cwd;
else
cwd = s->cwd;
wl = NULL;
if (idx != -1)
wl = winlink_find_by_index(&s->windows, idx);
@@ -149,14 +99,19 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
}
}
if (args->argc == 0)
cmd = options_get_string(&s->options, "default-command");
else
cmd = args->argv[0];
cwd = cmd_get_default_path(cmdq, args_get(args, 'c'));
if (idx == -1)
idx = -1 - options_get_number(&s->options, "base-index");
wl = session_new(s, args_get(args, 'n'), argc, argv, path, cwd, idx,
&cause);
wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause);
if (wl == NULL) {
cmdq_error(cmdq, "create window failed: %s", cause);
free(cause);
goto error;
return (CMD_RETURN_ERROR);
}
if (!detached) {
session_select(s, wl->idx);
@@ -169,8 +124,11 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
template = NEW_WINDOW_TEMPLATE;
ft = format_create();
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, wl,
NULL);
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
format_client(ft, c);
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, wl->window->active);
cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp);
@@ -179,12 +137,5 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
format_free(ft);
}
if (fd != -1)
close(fd);
return (CMD_RETURN_NORMAL);
error:
if (fd != -1)
close(fd);
return (CMD_RETURN_ERROR);
}
+28 -15
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -35,8 +35,10 @@ void cmd_paste_buffer_filter(struct window_pane *,
const struct cmd_entry cmd_paste_buffer_entry = {
"paste-buffer", "pasteb",
"db:prs:t:", 0, 0,
"[-dpr] [-s separator] " CMD_BUFFER_USAGE " " CMD_TARGET_PANE_USAGE,
"[-dpr] [-s separator] [-b buffer-index] " CMD_TARGET_PANE_USAGE,
0,
NULL,
NULL,
cmd_paste_buffer_exec
};
@@ -47,21 +49,31 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
struct window_pane *wp;
struct session *s;
struct paste_buffer *pb;
const char *sepstr, *bufname;
const char *sepstr;
char *cause;
int buffer;
int pflag;
if (cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp) == NULL)
return (CMD_RETURN_ERROR);
bufname = NULL;
if (args_has(args, 'b'))
bufname = args_get(args, 'b');
if (bufname == NULL)
pb = paste_get_top();
if (!args_has(args, 'b'))
buffer = -1;
else {
pb = paste_get_name(bufname);
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
cmdq_error(cmdq, "buffer %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
}
if (buffer == -1)
pb = paste_get_top(&global_buffers);
else {
pb = paste_get_index(&global_buffers, buffer);
if (pb == NULL) {
cmdq_error(cmdq, "no buffer %s", bufname);
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
}
}
@@ -74,15 +86,16 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
else
sepstr = "\r";
}
paste_send_pane(pb, wp, sepstr, args_has(args, 'p'));
pflag = (wp->screen->mode & MODE_BRACKETPASTE);
paste_send_pane(pb, wp, sepstr, args_has(args, 'p') && pflag);
}
/* Delete the buffer if -d. */
if (args_has(args, 'd')) {
if (bufname == NULL)
paste_free_top();
if (buffer == -1)
paste_free_top(&global_buffers);
else
paste_free_name(bufname);
paste_free_index(&global_buffers, buffer);
}
return (CMD_RETURN_NORMAL);
+8 -18
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -21,7 +21,6 @@
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
@@ -41,6 +40,8 @@ const struct cmd_entry cmd_pipe_pane_entry = {
"ot:", 0, 1,
"[-o] " CMD_TARGET_PANE_USAGE " [command]",
0,
NULL,
NULL,
cmd_pipe_pane_exec
};
@@ -49,14 +50,11 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
struct session *s;
struct winlink *wl;
struct window_pane *wp;
char *cmd;
char *command;
int old_fd, pipe_fd[2], null_fd;
struct format_tree *ft;
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
c = cmd_find_client(cmdq, NULL, 1);
@@ -87,18 +85,10 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
/* Expand the command. */
ft = format_create();
format_defaults(ft, c, s, wl, wp);
cmd = format_expand_time(ft, args->argv[0], time(NULL));
format_free(ft);
/* Fork the child. */
switch (fork()) {
case -1:
cmdq_error(cmdq, "fork error: %s", strerror(errno));
free(cmd);
return (CMD_RETURN_ERROR);
case 0:
/* Child process. */
@@ -120,7 +110,9 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
closefrom(STDERR_FILENO + 1);
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
command = status_replace(
c, NULL, NULL, NULL, args->argv[0], time(NULL), 0);
execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL);
_exit(1);
default:
/* Parent process. */
@@ -134,8 +126,6 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
bufferevent_enable(wp->pipe_event, EV_WRITE);
setblocking(wp->pipe_fd, 0);
free(cmd);
return (CMD_RETURN_NORMAL);
}
}
+78 -29
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -23,6 +23,7 @@
#include <time.h>
#include "tmux.h"
#include "tmate.h"
/* Create new command queue. */
struct cmd_q *
@@ -35,7 +36,7 @@ cmdq_new(struct client *c)
cmdq->dead = 0;
cmdq->client = c;
cmdq->client_exit = -1;
cmdq->client_exit = 0;
TAILQ_INIT(&cmdq->queue);
cmdq->item = NULL;
@@ -57,7 +58,7 @@ cmdq_free(struct cmd_q *cmdq)
}
/* Show message from command. */
void
void printflike2
cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
{
struct client *c = cmdq->client;
@@ -69,7 +70,9 @@ cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
if (c == NULL)
/* nothing */;
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
va_start(ap, fmt);
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
va_end(ap);
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);
@@ -86,28 +89,69 @@ cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
va_end(ap);
}
/* Show info from command. */
void printflike2
cmdq_info(struct cmd_q *cmdq, const char *fmt, ...)
{
struct client *c = cmdq->client;
va_list ap;
char *msg;
if (options_get_number(&global_options, "quiet"))
return;
va_start(ap, fmt);
if (c == NULL)
/* nothing */;
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
va_start(ap, fmt);
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
va_end(ap);
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);
} else {
xvasprintf(&msg, fmt, ap);
*msg = toupper((u_char) *msg);
status_message_set(c, "%s", msg);
free(msg);
}
va_end(ap);
}
/* Show error from command. */
void
void printflike2
cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
{
struct client *c = cmdq->client;
struct cmd *cmd = cmdq->cmd;
va_list ap;
char *msg;
char *msg, *cause;
size_t msglen;
va_start(ap, fmt);
msglen = xvasprintf(&msg, fmt, ap);
va_end(ap);
if (c == NULL)
cfg_add_cause("%s:%u: %s", cmd->file, cmd->line, msg);
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
if (c == NULL) {
#ifdef TMATE
if (cmd->file && cmd->line)
xasprintf(&cause, "%s:%u: %s", cmd->file, cmd->line, msg);
else
xasprintf(&cause, "%s", msg);
#else
xasprintf(&cause, "%s:%u: %s", cmd->file, cmd->line, msg);
#endif
ARRAY_ADD(&cfg_causes, cause);
} else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
evbuffer_add(c->stderr_data, msg, msglen);
evbuffer_add(c->stderr_data, "\n", 1);
server_push_stderr(c);
c->retval = 1;
c->retcode = 1;
} else {
*msg = toupper((u_char) *msg);
status_message_set(c, "%s", msg);
@@ -117,17 +161,20 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
}
/* Print a guard line. */
void
cmdq_guard(struct cmd_q *cmdq, const char *guard, int flags)
int
cmdq_guard(struct cmd_q *cmdq, const char *guard)
{
struct client *c = cmdq->client;
if (c == NULL || !(c->flags & CLIENT_CONTROL))
return;
if (c == NULL || c->session == NULL)
return 0;
if (!(c->flags & CLIENT_CONTROL))
return 0;
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard,
(long) cmdq->time, cmdq->number, flags);
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u\n", guard,
(long) cmdq->time, cmdq->number);
server_push_stdout(c);
return 1;
}
/* Add command list to queue and begin processing if needed. */
@@ -160,10 +207,9 @@ cmdq_continue(struct cmd_q *cmdq)
{
struct cmd_q_item *next;
enum cmd_retval retval;
int empty, flags;
int empty, guard;
char s[1024];
cmdq->references++;
notify_disable();
empty = TAILQ_EMPTY(&cmdq->queue);
@@ -177,6 +223,8 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
do {
next = TAILQ_NEXT(cmdq->item, qentry);
while (cmdq->cmd != NULL) {
cmd_print(cmdq->cmd, s, sizeof s);
log_debug("cmdq %p: %s (client %d)", cmdq, s,
@@ -185,15 +233,19 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->time = time(NULL);
cmdq->number++;
flags = !!(cmdq->cmd->flags & CMD_CONTROL);
cmdq_guard(cmdq, "begin", flags);
#ifdef TMATE
if (tmate_should_replicate_cmd(cmdq->cmd->entry))
tmate_exec_cmd(s);
#endif
guard = cmdq_guard(cmdq, "begin");
retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq);
if (retval == CMD_RETURN_ERROR)
cmdq_guard(cmdq, "error", flags);
else
cmdq_guard(cmdq, "end", flags);
if (guard) {
if (retval == CMD_RETURN_ERROR)
cmdq_guard(cmdq, "error");
else
cmdq_guard(cmdq, "end");
}
if (retval == CMD_RETURN_ERROR)
break;
@@ -206,7 +258,6 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
}
next = TAILQ_NEXT(cmdq->item, qentry);
TAILQ_REMOVE(&cmdq->queue, cmdq->item, qentry);
cmd_list_free(cmdq->item->cmdlist);
@@ -218,16 +269,14 @@ cmdq_continue(struct cmd_q *cmdq)
} while (cmdq->item != NULL);
empty:
if (cmdq->client_exit > 0)
if (cmdq->client_exit)
cmdq->client->flags |= CLIENT_EXIT;
if (cmdq->emptyfn != NULL)
cmdq->emptyfn(cmdq);
cmdq->emptyfn(cmdq); /* may free cmdq */
empty = 1;
out:
notify_enable();
cmdq_free(cmdq);
return (empty);
}
+4 -2
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,8 +29,10 @@ enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_refresh_client_entry = {
"refresh-client", "refresh",
"C:St:", 0, 0,
"[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
"[-S] [-C size]" CMD_TARGET_CLIENT_USAGE,
0,
NULL,
NULL,
cmd_refresh_client_exec
};
+3 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -33,6 +33,8 @@ const struct cmd_entry cmd_rename_session_entry = {
"t:", 1, 1,
CMD_TARGET_SESSION_USAGE " new-name",
0,
NULL,
NULL,
cmd_rename_session_exec
};
+3 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -33,6 +33,8 @@ const struct cmd_entry cmd_rename_window_entry = {
"t:", 1, 1,
CMD_TARGET_WINDOW_USAGE " new-name",
0,
NULL,
NULL,
cmd_rename_window_exec
};
+50 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -26,6 +26,7 @@
* Increase or decrease pane size.
*/
void cmd_resize_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_resize_pane_entry = {
@@ -33,9 +34,57 @@ const struct cmd_entry cmd_resize_pane_entry = {
"DLRt:Ux:y:Z", 0, 1,
"[-DLRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]",
0,
cmd_resize_pane_key_binding,
NULL,
cmd_resize_pane_exec
};
void
cmd_resize_pane_key_binding(struct cmd *self, int key)
{
switch (key) {
case KEYC_UP | KEYC_CTRL:
self->args = args_create(0);
args_set(self->args, 'U', NULL);
break;
case KEYC_DOWN | KEYC_CTRL:
self->args = args_create(0);
args_set(self->args, 'D', NULL);
break;
case KEYC_LEFT | KEYC_CTRL:
self->args = args_create(0);
args_set(self->args, 'L', NULL);
break;
case KEYC_RIGHT | KEYC_CTRL:
self->args = args_create(0);
args_set(self->args, 'R', NULL);
break;
case KEYC_UP | KEYC_ESCAPE:
self->args = args_create(1, "5");
args_set(self->args, 'U', NULL);
break;
case KEYC_DOWN | KEYC_ESCAPE:
self->args = args_create(1, "5");
args_set(self->args, 'D', NULL);
break;
case KEYC_LEFT | KEYC_ESCAPE:
self->args = args_create(1, "5");
args_set(self->args, 'L', NULL);
break;
case KEYC_RIGHT | KEYC_ESCAPE:
self->args = args_create(1, "5");
args_set(self->args, 'R', NULL);
break;
case 'z':
self->args = args_create(0);
args_set(self->args, 'Z', NULL);
break;
default:
self->args = args_create(0);
break;
}
}
enum cmd_retval
cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
+9 -13
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -32,9 +32,11 @@ enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_respawn_pane_entry = {
"respawn-pane", "respawnp",
"kt:", 0, -1,
"kt:", 0, 1,
"[-k] " CMD_TARGET_PANE_USAGE " [command]",
0,
NULL,
NULL,
cmd_respawn_pane_exec
};
@@ -47,10 +49,9 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
struct window_pane *wp;
struct session *s;
struct environ env;
const char *path;
const char *cmd;
char *cause;
u_int idx;
struct environ_entry *envent;
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
@@ -73,16 +74,11 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
screen_reinit(&wp->base);
input_init(wp);
path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL)
envent = environ_find(&cmdq->client->environ, "PATH");
if (args->argc != 0)
cmd = args->argv[0];
else
envent = environ_find(&s->environ, "PATH");
if (envent != NULL)
path = envent->value;
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, -1, &env,
s->tio, &cause) != 0) {
cmd = NULL;
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
cmdq_error(cmdq, "respawn pane failed: %s", cause);
free(cause);
environ_free(&env);
+9 -14
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -31,9 +31,11 @@ enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_respawn_window_entry = {
"respawn-window", "respawnw",
"kt:", 0, -1,
"kt:", 0, 1,
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
0,
NULL,
NULL,
cmd_respawn_window_exec
};
@@ -46,9 +48,8 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
struct window_pane *wp;
struct session *s;
struct environ env;
const char *path;
const char *cmd;
char *cause;
struct environ_entry *envent;
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
@@ -75,17 +76,11 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
window_destroy_panes(w);
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
window_pane_resize(wp, w->sx, w->sy);
path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL)
envent = environ_find(&cmdq->client->environ, "PATH");
if (args->argc != 0)
cmd = args->argv[0];
else
envent = environ_find(&s->environ, "PATH");
if (envent != NULL)
path = envent->value;
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, -1, &env,
s->tio, &cause) != 0) {
cmd = NULL;
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
cmdq_error(cmdq, "respawn window failed: %s", cause);
free(cause);
environ_free(&env);
+12 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,6 +24,7 @@
* Rotate the panes in a window.
*/
void cmd_rotate_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_rotate_window_entry = {
@@ -31,9 +32,19 @@ const struct cmd_entry cmd_rotate_window_entry = {
"Dt:U", 0, 0,
"[-DU] " CMD_TARGET_WINDOW_USAGE,
0,
cmd_rotate_window_key_binding,
NULL,
cmd_rotate_window_exec
};
void
cmd_rotate_window_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
if (key == ('o' | KEYC_ESCAPE))
args_set(self->args, 'D', NULL);
}
enum cmd_retval
cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
+16 -5
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -40,6 +40,8 @@ const struct cmd_entry cmd_run_shell_entry = {
"bt:", 1, 1,
"[-b] " CMD_TARGET_PANE_USAGE " shell-command",
0,
NULL,
NULL,
cmd_run_shell_exec
};
@@ -93,7 +95,12 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
}
ft = format_create();
format_defaults(ft, NULL, s, wl, wp);
if (s != NULL)
format_session(ft, s);
if (s != NULL && wl != NULL)
format_winlink(ft, s, wl);
if (wp != NULL)
format_window_pane(ft, wp);
shellcmd = format_expand(ft, args->argv[0]);
format_free(ft);
@@ -155,9 +162,13 @@ cmd_run_shell_callback(struct job *job)
retcode = WTERMSIG(job->status);
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
}
if (msg != NULL)
cmd_run_shell_print(job, msg);
free(msg);
if (msg != NULL) {
if (lines == 0)
cmdq_info(cmdq, "%s", msg);
else
cmd_run_shell_print(job, msg);
free(msg);
}
}
void
+46 -31
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -20,10 +20,8 @@
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "tmux.h"
@@ -38,6 +36,8 @@ const struct cmd_entry cmd_save_buffer_entry = {
"ab:", 1, 1,
"[-a] " CMD_BUFFER_USAGE " path",
0,
NULL,
NULL,
cmd_save_buffer_exec
};
@@ -46,6 +46,8 @@ const struct cmd_entry cmd_show_buffer_entry = {
"b:", 0, 0,
CMD_BUFFER_USAGE,
0,
NULL,
NULL,
cmd_save_buffer_exec
};
@@ -53,25 +55,34 @@ enum cmd_retval
cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c = cmdq->client;
struct client *c;
struct session *s;
struct paste_buffer *pb;
const char *path, *bufname;
char *start, *end, *msg;
size_t size, used, msglen;
int cwd, fd;
const char *path, *newpath, *wd;
char *cause, *start, *end;
size_t size, used;
int buffer;
mode_t mask;
FILE *f;
char *msg;
size_t msglen;
if (!args_has(args, 'b')) {
if ((pb = paste_get_top()) == NULL) {
if ((pb = paste_get_top(&global_buffers)) == NULL) {
cmdq_error(cmdq, "no buffers");
return (CMD_RETURN_ERROR);
}
} else {
bufname = args_get(args, 'b');
pb = paste_get_name(bufname);
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
cmdq_error(cmdq, "buffer %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
pb = paste_get_index(&global_buffers, buffer);
if (pb == NULL) {
cmdq_error(cmdq, "no buffer %s", bufname);
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
}
}
@@ -81,6 +92,7 @@ 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);
@@ -90,26 +102,28 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
goto do_print;
}
if (c != NULL && c->session == NULL)
cwd = c->cwd;
else if ((s = cmd_current_session(cmdq, 0)) != NULL)
cwd = s->cwd;
else
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|O_TRUNC, 0600);
if (fd != -1)
f = fdopen(fd, "wb");
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");
else
f = fopen(path, "wb");
umask(mask);
if (f == NULL) {
if (fd != -1)
close(fd);
cmdq_error(cmdq, "%s: %s", path, strerror(errno));
return (CMD_RETURN_ERROR);
}
@@ -133,6 +147,7 @@ do_print:
return (CMD_RETURN_ERROR);
}
msg = NULL;
msglen = 0;
used = 0;
while (used != pb->size) {
@@ -144,7 +159,7 @@ do_print:
size = pb->size - used;
msglen = size * 4 + 1;
msg = xrealloc(msg, msglen);
msg = xrealloc(msg, 1, msglen);
strvisx(msg, start, size, VIS_OCTAL|VIS_TAB);
cmdq_print(cmdq, "%s", msg);
+36 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,6 +24,7 @@
* Switch window to selected layout.
*/
void cmd_select_layout_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_layout_entry = {
@@ -31,6 +32,8 @@ const struct cmd_entry cmd_select_layout_entry = {
"npt:", 0, 1,
"[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
0,
cmd_select_layout_key_binding,
NULL,
cmd_select_layout_exec
};
@@ -39,6 +42,8 @@ const struct cmd_entry cmd_next_layout_entry = {
"t:", 0, 0,
CMD_TARGET_WINDOW_USAGE,
0,
NULL,
NULL,
cmd_select_layout_exec
};
@@ -47,9 +52,36 @@ const struct cmd_entry cmd_previous_layout_entry = {
"t:", 0, 0,
CMD_TARGET_WINDOW_USAGE,
0,
NULL,
NULL,
cmd_select_layout_exec
};
void
cmd_select_layout_key_binding(struct cmd *self, int key)
{
switch (key) {
case '1' | KEYC_ESCAPE:
self->args = args_create(1, "even-horizontal");
break;
case '2' | KEYC_ESCAPE:
self->args = args_create(1, "even-vertical");
break;
case '3' | KEYC_ESCAPE:
self->args = args_create(1, "main-horizontal");
break;
case '4' | KEYC_ESCAPE:
self->args = args_create(1, "main-vertical");
break;
case '5' | KEYC_ESCAPE:
self->args = args_create(1, "tiled");
break;
default:
self->args = args_create(0);
break;
}
}
enum cmd_retval
cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
{
@@ -75,6 +107,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
else
layout = layout_set_previous(wl->window);
server_redraw_window(wl->window);
cmdq_info(cmdq, "arranging in: %s", layout_set_name(layout));
return (CMD_RETURN_NORMAL);
}
@@ -85,6 +118,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
if (layout != -1) {
layout = layout_set_select(wl->window, layout);
server_redraw_window(wl->window);
cmdq_info(cmdq, "arranging in: %s", layout_set_name(layout));
return (CMD_RETURN_NORMAL);
}
@@ -95,6 +129,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
server_redraw_window(wl->window);
cmdq_info(cmdq, "arranging in: %s", layoutname);
}
return (CMD_RETURN_NORMAL);
}
+33 -23
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,24 +24,45 @@
* Select pane.
*/
void cmd_select_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_pane_entry = {
"select-pane", "selectp",
"DdeLlRt:U", 0, 0,
"[-DdeLlRU] " CMD_TARGET_PANE_USAGE,
"lDLRt:U", 0, 0,
"[-lDLRU] " CMD_TARGET_PANE_USAGE,
0,
cmd_select_pane_key_binding,
NULL,
cmd_select_pane_exec
};
const struct cmd_entry cmd_last_pane_entry = {
"last-pane", "lastp",
"det:", 0, 0,
"[-de] " CMD_TARGET_WINDOW_USAGE,
"t:", 0, 0,
CMD_TARGET_WINDOW_USAGE,
0,
NULL,
NULL,
cmd_select_pane_exec
};
void
cmd_select_pane_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
if (key == KEYC_UP)
args_set(self->args, 'U', NULL);
if (key == KEYC_DOWN)
args_set(self->args, 'D', NULL);
if (key == KEYC_LEFT)
args_set(self->args, 'L', NULL);
if (key == KEYC_RIGHT)
args_set(self->args, 'R', NULL);
if (key == 'o')
args_set(self->args, 't', ":.+");
}
enum cmd_retval
cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
@@ -59,16 +80,10 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
if (args_has(self->args, 'e'))
wl->window->last->flags &= ~PANE_INPUTOFF;
else if (args_has(self->args, 'd'))
wl->window->last->flags |= PANE_INPUTOFF;
else {
server_unzoom_window(wl->window);
window_set_active_pane(wl->window, wl->window->last);
server_status_window(wl->window);
server_redraw_window_borders(wl->window);
}
server_unzoom_window(wl->window);
window_set_active_pane(wl->window, wl->window->last);
server_status_window(wl->window);
server_redraw_window_borders(wl->window);
return (CMD_RETURN_NORMAL);
}
@@ -95,14 +110,9 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
if (args_has(self->args, 'e'))
wp->flags &= ~PANE_INPUTOFF;
else if (args_has(self->args, 'd'))
wp->flags |= PANE_INPUTOFF;
else if (window_set_active_pane(wl->window, wp)) {
server_status_window(wl->window);
server_redraw_window_borders(wl->window);
}
window_set_active_pane(wl->window, wp);
server_status_window(wl->window);
server_redraw_window_borders(wl->window);
return (CMD_RETURN_NORMAL);
}
+24 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -26,6 +26,7 @@
* Select window by index.
*/
void cmd_select_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_window_entry = {
@@ -33,6 +34,8 @@ const struct cmd_entry cmd_select_window_entry = {
"lnpTt:", 0, 0,
"[-lnpT] " CMD_TARGET_WINDOW_USAGE,
0,
cmd_select_window_key_binding,
NULL,
cmd_select_window_exec
};
@@ -41,6 +44,8 @@ const struct cmd_entry cmd_next_window_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_SESSION_USAGE,
0,
cmd_select_window_key_binding,
NULL,
cmd_select_window_exec
};
@@ -49,6 +54,8 @@ const struct cmd_entry cmd_previous_window_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_SESSION_USAGE,
0,
cmd_select_window_key_binding,
NULL,
cmd_select_window_exec
};
@@ -57,9 +64,25 @@ const struct cmd_entry cmd_last_window_entry = {
"t:", 0, 0,
CMD_TARGET_SESSION_USAGE,
0,
NULL,
NULL,
cmd_select_window_exec
};
void
cmd_select_window_key_binding(struct cmd *self, int key)
{
char tmp[16];
self->args = args_create(0);
if (key >= '0' && key <= '9') {
xsnprintf(tmp, sizeof tmp, ":%d", key - '0');
args_set(self->args, 't', tmp);
}
if (key == ('n' | KEYC_ESCAPE) || key == ('p' | KEYC_ESCAPE))
args_set(self->args, 'a', NULL);
}
enum cmd_retval
cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
+6 -2
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,6 +34,8 @@ const struct cmd_entry cmd_send_keys_entry = {
"lRt:", 0, -1,
"[-lR] " CMD_TARGET_PANE_USAGE " key ...",
0,
NULL,
NULL,
cmd_send_keys_exec
};
@@ -42,6 +44,8 @@ const struct cmd_entry cmd_send_prefix_entry = {
"2t:", 0, 0,
"[-2] " CMD_TARGET_PANE_USAGE,
0,
NULL,
NULL,
cmd_send_keys_exec
};
@@ -52,7 +56,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
struct window_pane *wp;
struct session *s;
struct input_ctx *ictx;
const u_char *str;
const char *str;
int i, key;
if (cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp) == NULL)
+174
View File
@@ -0,0 +1,174 @@
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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.
*/
#include <sys/types.h>
#include <sys/utsname.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "tmux.h"
/*
* Show various information about server.
*/
enum cmd_retval cmd_server_info_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_server_info_entry = {
"server-info", "info",
"", 0, 0,
"",
0,
NULL,
NULL,
cmd_server_info_exec
};
enum cmd_retval
cmd_server_info_exec(unused struct cmd *self, struct cmd_q *cmdq)
{
struct tty_term *term;
struct client *c;
struct session *s;
struct winlink *wl;
struct window *w;
struct window_pane *wp;
struct tty_code *code;
const struct tty_term_code_entry *ent;
struct utsname un;
struct job *job;
struct grid *gd;
struct grid_line *gl;
u_int i, j, k, lines;
size_t size;
char out[80];
char *tim;
time_t t;
tim = ctime(&start_time);
*strchr(tim, '\n') = '\0';
cmdq_print(cmdq,
"tmux " VERSION ", pid %ld, started %s", (long) getpid(), tim);
cmdq_print(cmdq, "socket path %s, debug level %d", socket_path,
debug_level);
if (uname(&un) >= 0) {
cmdq_print(cmdq, "system is %s %s %s %s",
un.sysname, un.release, un.version, un.machine);
}
if (cfg_file != NULL)
cmdq_print(cmdq, "configuration file is %s", cfg_file);
else
cmdq_print(cmdq, "configuration file not specified");
cmdq_print(cmdq, "protocol version is %d", PROTOCOL_VERSION);
cmdq_print(cmdq, "%s", "");
cmdq_print(cmdq, "Clients:");
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue;
cmdq_print(cmdq,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho "
"class=%u] [flags=0x%x/0x%x, references=%u]", i,
c->tty.path, c->ibuf.fd, c->tty.fd, c->session->name,
c->tty.sx, c->tty.sy, c->tty.termname,
c->tty.tio.c_cc[VERASE], c->tty.class,
c->flags, c->tty.flags, c->references);
}
cmdq_print(cmdq, "%s", "");
cmdq_print(cmdq, "Sessions: [%zu]", sizeof (struct grid_cell));
RB_FOREACH(s, sessions, &sessions) {
t = s->creation_time.tv_sec;
tim = ctime(&t);
*strchr(tim, '\n') = '\0';
cmdq_print(cmdq, "%2u: %s: %u windows (created %s) [%ux%u] "
"[flags=0x%x]", s->id, s->name,
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
RB_FOREACH(wl, winlinks, &s->windows) {
w = wl->window;
cmdq_print(cmdq, "%4u: %s [%ux%u] [flags=0x%x, "
"references=%u, last layout=%d]", wl->idx, w->name,
w->sx, w->sy, w->flags, w->references,
w->lastlayout);
j = 0;
TAILQ_FOREACH(wp, &w->panes, entry) {
lines = size = 0;
gd = wp->base.grid;
for (k = 0; k < gd->hsize + gd->sy; k++) {
gl = &gd->linedata[k];
if (gl->celldata == NULL)
continue;
lines++;
size += gl->cellsize *
sizeof *gl->celldata;
}
cmdq_print(cmdq,
"%6u: %s %lu %d %u/%u, %zu bytes", j,
wp->tty, (u_long) wp->pid, wp->fd, lines,
gd->hsize + gd->sy, size);
j++;
}
}
}
cmdq_print(cmdq, "%s", "");
cmdq_print(cmdq, "Terminals:");
LIST_FOREACH(term, &tty_terms, entry) {
cmdq_print(cmdq, "%s [references=%u, flags=0x%x]:",
term->name, term->references, term->flags);
for (i = 0; i < NTTYCODE; i++) {
ent = &tty_term_codes[i];
code = &term->codes[ent->code];
switch (code->type) {
case TTYCODE_NONE:
cmdq_print(cmdq, "%2u: %s: [missing]",
ent->code, ent->name);
break;
case TTYCODE_STRING:
strnvis(out, code->value.string, sizeof out,
VIS_OCTAL|VIS_TAB|VIS_NL);
cmdq_print(cmdq, "%2u: %s: (string) %s",
ent->code, ent->name, out);
break;
case TTYCODE_NUMBER:
cmdq_print(cmdq, "%2u: %s: (number) %d",
ent->code, ent->name, code->value.number);
break;
case TTYCODE_FLAG:
cmdq_print(cmdq, "%2u: %s: (flag) %s",
ent->code, ent->name,
code->value.flag ? "true" : "false");
break;
}
}
}
cmdq_print(cmdq, "%s", "");
cmdq_print(cmdq, "Jobs:");
LIST_FOREACH(job, &all_jobs, lentry) {
cmdq_print(cmdq, "%s [fd=%d, pid=%d, status=%d]",
job->cmd, job->fd, job->pid, job->status);
}
return (CMD_RETURN_NORMAL);
}
+23 -65
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,93 +24,51 @@
#include "tmux.h"
/*
* Add, set, or append to a paste buffer.
* Add or set a paste buffer.
*/
enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_set_buffer_entry = {
"set-buffer", "setb",
"ab:n:", 0, 1,
"[-a] " CMD_BUFFER_USAGE " [-n new-buffer-name] data",
"b:", 1, 1,
CMD_BUFFER_USAGE " data",
0,
NULL,
NULL,
cmd_set_buffer_exec
};
enum cmd_retval
cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct paste_buffer *pb;
char *pdata, *cause;
const char *bufname;
size_t psize, newsize;
struct args *args = self->args;
u_int limit;
char *pdata, *cause;
size_t psize;
int buffer;
bufname = NULL;
limit = options_get_number(&global_options, "buffer-limit");
if (args_has(args, 'n')) {
if (args->argc > 0) {
cmdq_error(cmdq, "don't provide data with n flag");
return (CMD_RETURN_ERROR);
}
if (args_has(args, 'b'))
bufname = args_get(args, 'b');
if (bufname == NULL) {
pb = paste_get_top();
if (pb == NULL) {
cmdq_error(cmdq, "no buffer");
return (CMD_RETURN_ERROR);
}
bufname = pb->name;
}
if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) {
cmdq_error(cmdq, "%s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
pdata = xstrdup(args->argv[0]);
psize = strlen(pdata);
if (!args_has(args, 'b')) {
paste_add(&global_buffers, pdata, psize, limit);
return (CMD_RETURN_NORMAL);
}
if (args->argc != 1) {
cmdq_error(cmdq, "no data specified");
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
cmdq_error(cmdq, "buffer %s", cause);
free(cause);
free(pdata);
return (CMD_RETURN_ERROR);
}
psize = 0;
pdata = NULL;
pb = NULL;
if ((newsize = strlen(args->argv[0])) == 0)
return (CMD_RETURN_NORMAL);
if (args_has(args, 'b')) {
bufname = args_get(args, 'b');
pb = paste_get_name(bufname);
} else if (args_has(args, 'a')) {
pb = paste_get_top();
if (pb != NULL)
bufname = pb->name;
}
if (args_has(args, 'a') && pb != NULL) {
psize = pb->size;
pdata = xmalloc(psize);
memcpy(pdata, pb->data, psize);
}
pdata = xrealloc(pdata, psize + newsize);
memcpy(pdata + psize, args->argv[0], newsize);
psize += newsize;
if (paste_set(pdata, psize, bufname, &cause) != 0) {
cmdq_error(cmdq, "%s", cause);
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
cmdq_error(cmdq, "no buffer %d", buffer);
free(pdata);
free(cause);
return (CMD_RETURN_ERROR);
}
+3 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,6 +34,8 @@ const struct cmd_entry cmd_set_environment_entry = {
"grt:u", 1, 2,
"[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
0,
NULL,
NULL,
cmd_set_environment_exec
};
+37 -79
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -60,15 +60,14 @@ struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_q *,
struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
struct options_entry *cmd_set_option_style(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
const struct cmd_entry cmd_set_option_entry = {
"set-option", "set",
"agoqst:uw", 1, 2,
"[-agosquw] [-t target-session|target-window] option [value]",
0,
NULL,
NULL,
cmd_set_option_exec
};
@@ -77,6 +76,8 @@ const struct cmd_entry cmd_set_window_option_entry = {
"agoqt:u", 1, 2,
"[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
0,
NULL,
NULL,
cmd_set_option_exec
};
@@ -115,11 +116,8 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
if (oe == NULL) {
if (!args_has(args, 'q')) {
cmdq_error(cmdq, "unknown option: %s", optstr);
return (CMD_RETURN_ERROR);
}
return (CMD_RETURN_NORMAL);
cmdq_error(cmdq, "unknown option: %s", optstr);
return (CMD_RETURN_ERROR);
}
/* Work out the tree from the table. */
@@ -130,13 +128,8 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
oo = &global_w_options;
else {
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
if (wl == NULL) {
cmdq_error(cmdq,
"couldn't set '%s'%s", optstr,
(!args_has(args, 't') && !args_has(args,
'g')) ? " need target window or -g" : "");
if (wl == NULL)
return (CMD_RETURN_ERROR);
}
oo = &wl->window->options;
}
} else if (table == session_options_table) {
@@ -144,13 +137,8 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
oo = &global_s_options;
else {
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL) {
cmdq_error(cmdq,
"couldn't set '%s'%s", optstr,
(!args_has(args, 't') && !args_has(args,
'g')) ? " need target session or -g" : "");
if (s == NULL)
return (CMD_RETURN_ERROR);
}
oo = &s->options;
}
} else {
@@ -164,10 +152,8 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
} else {
if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
if (!args_has(args, 'q')) {
cmdq_error(cmdq, "already set: %s", optstr);
return (CMD_RETURN_ERROR);
}
if (!args_has(args, 'q'))
cmdq_print(cmdq, "already set: %s", optstr);
return (CMD_RETURN_NORMAL);
}
if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0)
@@ -175,7 +161,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
}
/* Start or stop timers when automatic-rename changed. */
if (strcmp(oe->name, "automatic-rename") == 0) {
if (strcmp (oe->name, "automatic-rename") == 0) {
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
if ((w = ARRAY_ITEM(&windows, i)) == NULL)
continue;
@@ -199,7 +185,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
/* Set user option. */
enum cmd_retval
cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,
cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char* optstr,
const char *valstr)
{
struct args *args = self->args;
@@ -232,11 +218,8 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,
if (args_has(args, 'u')) {
if (options_find1(oo, optstr) == NULL) {
if (!args_has(args, 'q')) {
cmdq_error(cmdq, "unknown option: %s", optstr);
return (CMD_RETURN_ERROR);
}
return (CMD_RETURN_NORMAL);
cmdq_error(cmdq, "unknown option: %s", optstr);
return (CMD_RETURN_ERROR);
}
if (valstr != NULL) {
cmdq_error(cmdq, "value passed to unset option: %s",
@@ -250,13 +233,15 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,
return (CMD_RETURN_ERROR);
}
if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
if (!args_has(args, 'q')) {
cmdq_error(cmdq, "already set: %s", optstr);
return (CMD_RETURN_ERROR);
}
if (!args_has(args, 'q'))
cmdq_print(cmdq, "already set: %s", optstr);
return (CMD_RETURN_NORMAL);
}
options_set_string(oo, optstr, "%s", valstr);
if (!args_has(args, 'q')) {
cmdq_info(cmdq, "set option: %s -> %s", optstr,
valstr);
}
}
return (CMD_RETURN_NORMAL);
}
@@ -265,8 +250,7 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,
/* Unset an option. */
int
cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo,
const char *value)
const struct options_table_entry *oe, struct options *oo, const char *value)
{
struct args *args = self->args;
@@ -280,16 +264,19 @@ cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq,
}
options_remove(oo, oe->name);
if (!args_has(args, 'q'))
cmdq_info(cmdq, "unset option: %s", oe->name);
return (0);
}
/* Set an option. */
int
cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo,
const char *value)
const struct options_table_entry *oe, struct options *oo, const char *value)
{
struct args *args = self->args;
struct options_entry *o;
const char *s;
if (oe->type != OPTIONS_TABLE_FLAG && value == NULL) {
cmdq_error(cmdq, "empty value");
@@ -309,13 +296,9 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
break;
case OPTIONS_TABLE_COLOUR:
o = cmd_set_option_colour(self, cmdq, oe, oo, value);
if (o != NULL)
style_update_new(oo, o->name, oe->style);
break;
case OPTIONS_TABLE_ATTRIBUTES:
o = cmd_set_option_attributes(self, cmdq, oe, oo, value);
if (o != NULL)
style_update_new(oo, o->name, oe->style);
break;
case OPTIONS_TABLE_FLAG:
o = cmd_set_option_flag(self, cmdq, oe, oo, value);
@@ -323,20 +306,20 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
case OPTIONS_TABLE_CHOICE:
o = cmd_set_option_choice(self, cmdq, oe, oo, value);
break;
case OPTIONS_TABLE_STYLE:
o = cmd_set_option_style(self, cmdq, oe, oo, value);
break;
}
if (o == NULL)
return (-1);
s = options_table_print_entry(oe, o, 0);
if (!args_has(args, 'q'))
cmdq_info(cmdq, "set option: %s -> %s", oe->name, s);
return (0);
}
/* Set a string option. */
struct options_entry *
cmd_set_option_string(struct cmd *self, unused struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo,
const char *value)
const struct options_table_entry *oe, struct options *oo, const char *value)
{
struct args *args = self->args;
struct options_entry *o;
@@ -357,8 +340,7 @@ cmd_set_option_string(struct cmd *self, unused struct cmd_q *cmdq,
/* Set a number option. */
struct options_entry *
cmd_set_option_number(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo,
const char *value)
const struct options_table_entry *oe, struct options *oo, const char *value)
{
long long ll;
const char *errstr;
@@ -375,8 +357,7 @@ cmd_set_option_number(unused struct cmd *self, struct cmd_q *cmdq,
/* Set a key option. */
struct options_entry *
cmd_set_option_key(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo,
const char *value)
const struct options_table_entry *oe, struct options *oo, const char *value)
{
int key;
@@ -391,8 +372,7 @@ cmd_set_option_key(unused struct cmd *self, struct cmd_q *cmdq,
/* Set a colour option. */
struct options_entry *
cmd_set_option_colour(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo,
const char *value)
const struct options_table_entry *oe, struct options *oo, const char *value)
{
int colour;
@@ -407,8 +387,7 @@ cmd_set_option_colour(unused struct cmd *self, struct cmd_q *cmdq,
/* Set an attributes option. */
struct options_entry *
cmd_set_option_attributes(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo,
const char *value)
const struct options_table_entry *oe, struct options *oo, const char *value)
{
int attr;
@@ -423,8 +402,7 @@ cmd_set_option_attributes(unused struct cmd *self, struct cmd_q *cmdq,
/* Set a flag option. */
struct options_entry *
cmd_set_option_flag(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo,
const char *value)
const struct options_table_entry *oe, struct options *oo, const char *value)
{
int flag;
@@ -476,23 +454,3 @@ cmd_set_option_choice(unused struct cmd *self, struct cmd_q *cmdq,
return (options_set_number(oo, oe->name, choice));
}
/* Set a style option. */
struct options_entry *
cmd_set_option_style(struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo,
const char *value)
{
struct args *args = self->args;
struct options_entry *o;
int append;
append = args_has(args, 'a');
if ((o = options_set_style(oo, oe->name, value, append)) == NULL) {
cmdq_error(cmdq, "bad style: %s", value);
return (NULL);
}
style_update_old(oo, oe->name, &o->style);
return (o);
}
+3 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,6 +34,8 @@ const struct cmd_entry cmd_show_environment_entry = {
"gt:", 0, 1,
"[-g] " CMD_TARGET_SESSION_USAGE " [name]",
0,
NULL,
NULL,
cmd_show_environment_exec
};
+5 -109
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -20,7 +20,6 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "tmux.h"
@@ -32,96 +31,14 @@ enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_show_messages_entry = {
"show-messages", "showmsgs",
"IJTt:", 0, 0,
"[-IJT] " CMD_TARGET_CLIENT_USAGE,
"t:", 0, 0,
CMD_TARGET_CLIENT_USAGE,
0,
NULL,
NULL,
cmd_show_messages_exec
};
const struct cmd_entry cmd_server_info_entry = {
"server-info", "info",
"", 0, 0,
"",
0,
cmd_show_messages_exec
};
void cmd_show_messages_server(struct cmd_q *);
void cmd_show_messages_terminals(struct cmd_q *);
void cmd_show_messages_jobs(struct cmd_q *);
void
cmd_show_messages_server(struct cmd_q *cmdq)
{
char *tim;
tim = ctime(&start_time);
*strchr(tim, '\n') = '\0';
cmdq_print(cmdq, "started %s", tim);
cmdq_print(cmdq, "socket path %s", socket_path);
cmdq_print(cmdq, "debug level %d", debug_level);
cmdq_print(cmdq, "protocol version %d", PROTOCOL_VERSION);
}
void
cmd_show_messages_terminals(struct cmd_q *cmdq)
{
struct tty_term *term;
const struct tty_term_code_entry *ent;
struct tty_code *code;
u_int i, n;
char out[80];
n = 0;
LIST_FOREACH(term, &tty_terms, entry) {
cmdq_print(cmdq,
"Terminal %u: %s [references=%u, flags=0x%x]:",
n, term->name, term->references, term->flags);
n++;
for (i = 0; i < NTTYCODE; i++) {
ent = &tty_term_codes[i];
code = &term->codes[ent->code];
switch (code->type) {
case TTYCODE_NONE:
cmdq_print(cmdq, "%4u: %s: [missing]",
ent->code, ent->name);
break;
case TTYCODE_STRING:
strnvis(out, code->value.string, sizeof out,
VIS_OCTAL|VIS_TAB|VIS_NL);
cmdq_print(cmdq, "%4u: %s: (string) %s",
ent->code, ent->name, out);
break;
case TTYCODE_NUMBER:
cmdq_print(cmdq, "%4u: %s: (number) %d",
ent->code, ent->name, code->value.number);
break;
case TTYCODE_FLAG:
cmdq_print(cmdq, "%4u: %s: (flag) %s",
ent->code, ent->name,
code->value.flag ? "true" : "false");
break;
}
}
}
}
void
cmd_show_messages_jobs(struct cmd_q *cmdq)
{
struct job *job;
u_int n;
n = 0;
LIST_FOREACH(job, &all_jobs, lentry) {
cmdq_print(cmdq,
"Job %u: %s [fd=%d, pid=%d, status=%d]",
n, job->cmd, job->fd, job->pid, job->status);
n++;
}
}
enum cmd_retval
cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
{
@@ -130,27 +47,6 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
struct message_entry *msg;
char *tim;
u_int i;
int done;
done = 0;
if (args_has(args, 'I') || self->entry == &cmd_server_info_entry) {
cmd_show_messages_server(cmdq);
done = 1;
}
if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) {
if (done)
cmdq_print(cmdq, "%s", "");
cmd_show_messages_terminals(cmdq);
done = 1;
}
if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) {
if (done)
cmdq_print(cmdq, "%s", "");
cmd_show_messages_jobs(cmdq);
done = 1;
}
if (done)
return (CMD_RETURN_NORMAL);
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
+11 -15
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -39,6 +39,8 @@ const struct cmd_entry cmd_show_options_entry = {
"gqst:vw", 0, 1,
"[-gqsvw] [-t target-session|target-window] [option]",
0,
NULL,
NULL,
cmd_show_options_exec
};
@@ -47,6 +49,8 @@ const struct cmd_entry cmd_show_window_options_entry = {
"gvt:", 0, 1,
"[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
0,
NULL,
NULL,
cmd_show_options_exec
};
@@ -98,17 +102,15 @@ cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq,
struct options *oo, int quiet)
{
struct args *args = self->args;
const char *name = args->argv[0];
const struct options_table_entry *table, *oe;
struct options_entry *o;
const char *optval;
retry:
if (*name == '@') {
if ((o = options_find1(oo, name)) == NULL) {
if (*args->argv[0] == '@') {
if ((o = options_find1(oo, args->argv[0])) == NULL) {
if (quiet)
return (CMD_RETURN_NORMAL);
cmdq_error(cmdq, "unknown option: %s", name);
cmdq_error(cmdq, "unknown option: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
if (args_has(self->args, 'v'))
@@ -119,20 +121,16 @@ retry:
}
table = oe = NULL;
if (options_table_find(name, &table, &oe) != 0) {
cmdq_error(cmdq, "ambiguous option: %s", name);
if (options_table_find(args->argv[0], &table, &oe) != 0) {
cmdq_error(cmdq, "ambiguous option: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
if (oe == NULL) {
if (quiet)
return (CMD_RETURN_NORMAL);
cmdq_error(cmdq, "unknown option: %s", name);
cmdq_error(cmdq, "unknown option: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
if (oe->style != NULL) {
name = oe->style;
goto retry;
}
if ((o = options_find1(oo, oe->name)) == NULL)
return (CMD_RETURN_NORMAL);
optval = options_table_print_entry(oe, o, args_has(self->args, 'v'));
@@ -161,8 +159,6 @@ cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq,
}
for (oe = table; oe->name != NULL; oe++) {
if (oe->style != NULL)
continue;
if ((o = options_find1(oo, oe->name)) == NULL)
continue;
optval = options_table_print_entry(oe, o,
+21 -9
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
@@ -28,6 +28,7 @@
enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *);
void cmd_source_file_show(struct cmd_q *);
void cmd_source_file_done(struct cmd_q *);
const struct cmd_entry cmd_source_file_entry = {
@@ -35,6 +36,8 @@ const struct cmd_entry cmd_source_file_entry = {
"", 1, 1,
"path",
0,
NULL,
NULL,
cmd_source_file_exec
};
@@ -46,7 +49,6 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
char *cause;
cmdq1 = cmdq_new(NULL);
cmdq1->client = cmdq->client;
cmdq1->emptyfn = cmd_source_file_done;
cmdq1->data = cmdq;
@@ -58,12 +60,11 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
free(cause);
return (CMD_RETURN_ERROR);
}
cfg_add_cause("%s", cause);
free(cause);
ARRAY_ADD(&cfg_causes, cause);
/* FALLTHROUGH */
case 0:
if (cfg_references == 0)
cfg_print_causes(cmdq);
cmd_source_file_show(cmdq);
cmdq_free(cmdq1);
return (CMD_RETURN_NORMAL);
}
@@ -75,14 +76,25 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_WAIT);
}
void
cmd_source_file_show(struct cmd_q *cmdq)
{
u_int i;
char *cause;
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
cause = ARRAY_ITEM(&cfg_causes, i);
cmdq_print(cmdq, "%s", cause);
free(cause);
}
ARRAY_FREE(&cfg_causes);
}
void
cmd_source_file_done(struct cmd_q *cmdq1)
{
struct cmd_q *cmdq = cmdq1->data;
if (cmdq1->client_exit >= 0)
cmdq->client_exit = cmdq1->client_exit;
cmdq_free(cmdq1);
cfg_references--;
@@ -91,6 +103,6 @@ cmd_source_file_done(struct cmd_q *cmdq1)
return;
if (cfg_references == 0)
cfg_print_causes(cmdq);
cmd_source_file_show(cmdq);
cmdq_continue(cmdq);
}
+31 -66
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,10 +18,7 @@
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "tmux.h"
@@ -30,19 +27,28 @@
* Split a window (add a new pane).
*/
#define SPLIT_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
void cmd_split_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_split_window_entry = {
"split-window", "splitw",
"bc:dF:l:hp:Pt:v", 0, -1,
"[-bdhvP] [-c start-directory] [-F format] [-p percentage|-l size] "
"c:dF:l:hp:Pt:v", 0, 1,
"[-dhvP] [-c start-directory] [-F format] [-p percentage|-l size] "
CMD_TARGET_PANE_USAGE " [command]",
0,
cmd_split_window_key_binding,
NULL,
cmd_split_window_exec
};
void
cmd_split_window_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
if (key == '%')
args_set(self->args, 'h', NULL);
}
enum cmd_retval
cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
@@ -52,14 +58,16 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
struct window *w;
struct window_pane *wp, *new_wp = NULL;
struct environ env;
const char *cmd, *path, *shell, *template;
char **argv, *cause, *new_cause, *cp;
const char *cmd, *cwd, *shell;
char *cause, *new_cause;
u_int hlimit;
int argc, size, percentage, cwd, fd = -1;
int size, percentage;
enum layout_type type;
struct layout_cell *lc;
const char *template;
struct client *c;
struct format_tree *ft;
struct environ_entry *envent;
char *cp;
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
@@ -71,42 +79,11 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
environ_copy(&s->environ, &env);
server_fill_environ(s, &env);
if (args->argc == 0) {
if (args->argc == 0)
cmd = options_get_string(&s->options, "default-command");
if (cmd != NULL && *cmd != '\0') {
argc = 1;
argv = (char **)&cmd;
} else {
argc = 0;
argv = NULL;
}
} else {
argc = args->argc;
argv = args->argv;
}
if (args_has(args, 'c')) {
ft = format_create();
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL,
NULL);
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
if (cp != NULL && *cp != '\0') {
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
cmdq_error(cmdq, "bad working directory: %s",
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
free(cp);
cwd = fd;
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
cwd = cmdq->client->cwd;
else
cwd = s->cwd;
cmd = args->argv[0];
cwd = cmd_get_default_path(cmdq, args_get(args, 'c'));
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
@@ -140,23 +117,13 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
if (*shell == '\0' || areshell(shell))
shell = _PATH_BSHELL;
lc = layout_split_pane(wp, type, size, args_has(args, 'b'));
if (lc == NULL) {
if ((lc = layout_split_pane(wp, type, size, 0)) == NULL) {
cause = xstrdup("pane too small");
goto error;
}
new_wp = window_add_pane(w, hlimit);
path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL)
envent = environ_find(&cmdq->client->environ, "PATH");
else
envent = environ_find(&s->environ, "PATH");
if (envent != NULL)
path = envent->value;
if (window_pane_spawn(new_wp, argc, argv, path, shell, cwd, &env,
s->tio, &cause) != 0)
if (window_pane_spawn(
new_wp, cmd, shell, cwd, &env, s->tio, &cause) != 0)
goto error;
layout_assign_pane(lc, new_wp);
@@ -176,8 +143,11 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
template = SPLIT_WINDOW_TEMPLATE;
ft = format_create();
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, wl,
new_wp);
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
format_client(ft, c);
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, new_wp);
cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp);
@@ -186,9 +156,6 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
format_free(ft);
}
notify_window_layout_changed(w);
if (fd != -1)
close(fd);
return (CMD_RETURN_NORMAL);
error:
@@ -197,7 +164,5 @@ error:
window_remove_pane(w, new_wp);
cmdq_error(cmdq, "create pane failed: %s", cause);
free(cause);
if (fd != -1)
close(fd);
return (CMD_RETURN_ERROR);
}
+23 -10
View File
@@ -1,6 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2013 Dagobert Michelsen
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -15,16 +16,28 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <string.h>
#include <sys/types.h>
#include "tmux.h"
void
cfmakeraw(struct termios *tio)
/*
* Start the server and do nothing else.
*/
enum cmd_retval cmd_start_server_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_start_server_entry = {
"start-server", "start",
"", 0, 0,
"",
CMD_STARTSERVER,
NULL,
NULL,
cmd_start_server_exec
};
enum cmd_retval
cmd_start_server_exec(unused struct cmd *self, unused struct cmd_q *cmdq)
{
tio->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
tio->c_oflag &= ~OPOST;
tio->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
tio->c_cflag &= ~(CSIZE|PARENB);
tio->c_cflag |= CS8;
return (CMD_RETURN_NORMAL);
}
+17 -33
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -107,11 +107,10 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
case ' ':
case '\t':
if (buf != NULL) {
buf = xrealloc(buf, len + 1);
buf = xrealloc(buf, 1, len + 1);
buf[len] = '\0';
argv = xreallocarray(argv, argc + 1,
sizeof *argv);
argv = xrealloc(argv, argc + 1, sizeof *argv);
argv[argc++] = buf;
buf = NULL;
@@ -152,7 +151,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
if (len >= SIZE_MAX - 2)
goto error;
buf = xrealloc(buf, len + 1);
buf = xrealloc(buf, 1, len + 1);
buf[len++] = ch;
break;
}
@@ -180,7 +179,7 @@ cmd_string_copy(char **dst, char *src, size_t *len)
srclen = strlen(src);
*dst = xrealloc(*dst, *len + srclen + 1);
*dst = xrealloc(*dst, 1, *len + srclen + 1);
strlcpy(*dst + *len, src, srclen + 1);
*len += srclen;
@@ -232,11 +231,11 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
if (len >= SIZE_MAX - 2)
goto error;
buf = xrealloc(buf, len + 1);
buf = xrealloc(buf, 1, len + 1);
buf[len++] = ch;
}
buf = xrealloc(buf, len + 1);
buf = xrealloc(buf, 1, len + 1);
buf[len] = '\0';
return (buf);
@@ -279,7 +278,7 @@ cmd_string_variable(const char *s, size_t *p)
return (t);
}
buf = xrealloc(buf, len + 1);
buf = xrealloc(buf, 1, len + 1);
buf[len++] = ch;
for (;;) {
@@ -289,7 +288,7 @@ cmd_string_variable(const char *s, size_t *p)
else {
if (len >= SIZE_MAX - 3)
goto error;
buf = xrealloc(buf, len + 1);
buf = xrealloc(buf, 1, len + 1);
buf[len++] = ch;
}
}
@@ -300,7 +299,7 @@ cmd_string_variable(const char *s, size_t *p)
if (ch != EOF && fch != '{')
cmd_string_ungetc(p); /* ch */
buf = xrealloc(buf, len + 1);
buf = xrealloc(buf, 1, len + 1);
buf[len] = '\0';
envent = environ_find(&global_environ, buf);
@@ -319,13 +318,10 @@ cmd_string_expand_tilde(const char *s, size_t *p)
{
struct passwd *pw;
struct environ_entry *envent;
char *home, *path, *user, *cp;
int last;
char *home, *path, *username;
home = NULL;
last = cmd_string_getc(s, p);
if (last == EOF || last == '/' || last == ' '|| last == '\t') {
if (cmd_string_getc(s, p) == '/') {
envent = environ_find(&global_environ, "HOME");
if (envent != NULL && *envent->value != '\0')
home = envent->value;
@@ -333,27 +329,15 @@ cmd_string_expand_tilde(const char *s, size_t *p)
home = pw->pw_dir;
} else {
cmd_string_ungetc(p);
cp = user = xmalloc(strlen(s));
for (;;) {
last = cmd_string_getc(s, p);
if (last == EOF || last == '/' || last == ' '|| last == '\t')
break;
*cp++ = last;
}
*cp = '\0';
if ((pw = getpwnam(user)) != NULL)
if ((username = cmd_string_string(s, p, '/', 0)) == NULL)
return (NULL);
if ((pw = getpwnam(username)) != NULL)
home = pw->pw_dir;
free(user);
free(username);
}
if (home == NULL)
return (NULL);
if (last != EOF)
xasprintf(&path, "%s%c", home, last);
else
xasprintf(&path, "%s", home);
xasprintf(&path, "%s/", home);
return (path);
}
+56
View File
@@ -0,0 +1,56 @@
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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.
*/
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
/*
* Suspend client with SIGTSTP.
*/
enum cmd_retval cmd_suspend_client_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_suspend_client_entry = {
"suspend-client", "suspendc",
"t:", 0, 0,
CMD_TARGET_CLIENT_USAGE,
0,
NULL,
NULL,
cmd_suspend_client_exec
};
enum cmd_retval
cmd_suspend_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
tty_stop_tty(&c->tty);
c->flags |= CLIENT_SUSPENDED;
server_write_client(c, MSG_SUSPEND, NULL, 0);
return (CMD_RETURN_NORMAL);
}
+23 -7
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -26,6 +26,7 @@
* Swap two panes.
*/
void cmd_swap_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_swap_pane_entry = {
@@ -33,9 +34,21 @@ const struct cmd_entry cmd_swap_pane_entry = {
"dDs:t:U", 0, 0,
"[-dDU] " CMD_SRCDST_PANE_USAGE,
0,
cmd_swap_pane_key_binding,
NULL,
cmd_swap_pane_exec
};
void
cmd_swap_pane_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
if (key == '{')
args_set(self->args, 'U', NULL);
else if (key == '}')
args_set(self->args, 'D', NULL);
}
enum cmd_retval
cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
@@ -62,12 +75,8 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
src_wp = TAILQ_PREV(dst_wp, window_panes, entry);
if (src_wp == NULL)
src_wp = TAILQ_LAST(&dst_w->panes, window_panes);
} else {
src_wl = cmd_find_pane(cmdq, NULL, NULL, &src_wp);
if (src_wl == NULL)
return (CMD_RETURN_ERROR);
src_w = src_wl->window;
}
} else
return (CMD_RETURN_NORMAL);
} else {
src_wl = cmd_find_pane(cmdq, args_get(args, 's'), NULL, &src_wp);
if (src_wl == NULL)
@@ -76,6 +85,13 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
}
server_unzoom_window(src_w);
#ifdef TMATE
if (src_w != dst_w) {
cmdq_error(cmdq, "swap pane on different window is not supported with tmate");
return (CMD_RETURN_ERROR);
}
#endif
if (src_wp == dst_wp)
return (CMD_RETURN_NORMAL);
+8 -1
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -33,12 +33,18 @@ const struct cmd_entry cmd_swap_window_entry = {
"ds:t:", 0, 0,
"[-d] " CMD_SRCDST_WINDOW_USAGE,
0,
NULL,
NULL,
cmd_swap_window_exec
};
enum cmd_retval
cmd_swap_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
#ifdef TMATE
cmdq_error(cmdq, "swap window is not supported with tmate");
return (CMD_RETURN_ERROR);
#else
struct args *args = self->args;
const char *target_src, *target_dst;
struct session *src, *dst;
@@ -82,4 +88,5 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_q *cmdq)
recalculate_sizes();
return (CMD_RETURN_NORMAL);
#endif
}
+34 -38
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,6 +27,7 @@
* Switch client to a different session.
*/
void cmd_switch_client_key_binding(struct cmd *, int);
enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_switch_client_entry = {
@@ -34,31 +35,49 @@ const struct cmd_entry cmd_switch_client_entry = {
"lc:npt:r", 0, 0,
"[-lnpr] [-c target-client] [-t target-session]",
CMD_READONLY,
cmd_switch_client_key_binding,
NULL,
cmd_switch_client_exec
};
void
cmd_switch_client_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
switch (key) {
case '(':
args_set(self->args, 'p', NULL);
break;
case ')':
args_set(self->args, 'n', NULL);
break;
case 'L':
args_set(self->args, 'l', NULL);
break;
}
}
enum cmd_retval
cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
struct session *s = NULL;
struct winlink *wl = NULL;
struct window *w = NULL;
struct window_pane *wp = NULL;
const char *tflag;
struct args *args = self->args;
struct client *c;
struct session *s;
if ((c = cmd_find_client(cmdq, args_get(args, 'c'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 'r')) {
if (c->flags & CLIENT_READONLY)
if (c->flags & CLIENT_READONLY) {
c->flags &= ~CLIENT_READONLY;
else
cmdq_info(cmdq, "made client writable");
} else {
c->flags |= CLIENT_READONLY;
cmdq_info(cmdq, "made client read-only");
}
}
tflag = args_get(args, 't');
s = NULL;
if (args_has(args, 'n')) {
if ((s = session_next_session(c->session)) == NULL) {
cmdq_error(cmdq, "can't find next session");
@@ -76,33 +95,10 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
cmdq_error(cmdq, "can't find last session");
return (CMD_RETURN_ERROR);
}
} else {
if (tflag == NULL) {
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
} else if (tflag[strcspn(tflag, ":.")] != '\0') {
if ((wl = cmd_find_pane(cmdq, tflag, &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
} else {
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
w = cmd_lookup_windowid(tflag);
if (w == NULL &&
(wp = cmd_lookup_paneid(tflag)) != NULL)
w = wp->window;
if (w != NULL)
wl = winlink_find_by_window(&s->windows, w);
}
if (cmdq->client == NULL)
return (CMD_RETURN_NORMAL);
if (wl != NULL) {
if (wp != NULL)
window_set_active_pane(wp->window, wp);
session_set_current(s, wl);
}
}
} else
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
if (c->session != NULL)
c->last_session = c->session;
+19 -15
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -26,17 +26,30 @@
* Unbind key from command.
*/
enum cmd_retval cmd_unbind_key_check(struct args *);
enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_q *);
enum cmd_retval cmd_unbind_key_mode_table(struct cmd *, struct cmd_q *, int);
enum cmd_retval cmd_unbind_key_table(struct cmd *, struct cmd_q *, int);
const struct cmd_entry cmd_unbind_key_entry = {
"unbind-key", "unbind",
"acnt:", 0, 1,
"[-acn] [-t mode-table] key",
"[-acn] [-t key-table] key",
0,
NULL,
cmd_unbind_key_check,
cmd_unbind_key_exec
};
enum cmd_retval
cmd_unbind_key_check(struct args *args)
{
if (args_has(args, 'a') && args->argc != 0)
return (CMD_RETURN_ERROR);
if (!args_has(args, 'a') && args->argc != 1)
return (CMD_RETURN_ERROR);
return (CMD_RETURN_NORMAL);
}
enum cmd_retval
cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
{
@@ -45,25 +58,16 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
int key;
if (!args_has(args, 'a')) {
if (args->argc != 1) {
cmdq_error(cmdq, "missing key");
return (CMD_RETURN_ERROR);
}
key = key_string_lookup_string(args->argv[0]);
if (key == KEYC_NONE) {
cmdq_error(cmdq, "unknown key: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
} else {
if (args->argc != 0) {
cmdq_error(cmdq, "key given with -a");
return (CMD_RETURN_ERROR);
}
} else
key = KEYC_NONE;
}
if (args_has(args, 't'))
return (cmd_unbind_key_mode_table(self, cmdq, key));
return (cmd_unbind_key_table(self, cmdq, key));
if (key == KEYC_NONE) {
while (!RB_EMPTY(&key_bindings)) {
@@ -80,7 +84,7 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
}
enum cmd_retval
cmd_unbind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, int key)
cmd_unbind_key_table(struct cmd *self, struct cmd_q *cmdq, int key)
{
struct args *args = self->args;
const char *tablename;
+75
View File
@@ -0,0 +1,75 @@
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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.
*/
#include <sys/types.h>
#include "tmux.h"
/*
* Unlink a window, unless it would be destroyed by doing so (only one link).
*/
enum cmd_retval cmd_unlink_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_unlink_window_entry = {
"unlink-window", "unlinkw",
"kt:", 0, 0,
"[-k] " CMD_TARGET_WINDOW_USAGE,
0,
NULL,
NULL,
cmd_unlink_window_exec
};
enum cmd_retval
cmd_unlink_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
#ifdef TMATE
cmdq_error(cmdq, "unlink window is not supported with tmate");
return (CMD_RETURN_ERROR);
#else
struct args *args = self->args;
struct winlink *wl;
struct window *w;
struct session *s, *s2;
struct session_group *sg;
u_int references;
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
w = wl->window;
sg = session_group_find(s);
if (sg != NULL) {
references = 0;
TAILQ_FOREACH(s2, &sg->sessions, gentry)
references++;
} else
references = 1;
if (!args_has(self->args, 'k') && w->references == references) {
cmdq_error(cmdq, "window is only linked to one session");
return (CMD_RETURN_ERROR);
}
server_unlink_window(s, wl);
recalculate_sizes();
return (CMD_RETURN_NORMAL);
#endif
}
+6 -26
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -33,8 +33,10 @@ enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_wait_for_entry = {
"wait-for", "wait",
"LSU", 1, 1,
"[-L|-S|-U] channel",
"[-LSU] channel",
0,
NULL,
NULL,
cmd_wait_for_exec
};
@@ -107,7 +109,7 @@ cmd_wait_for_signal(struct cmd_q *cmdq, const char *name,
if (!wc->locked) {
RB_REMOVE(wait_channels, &wait_channels, wc);
free((void *)wc->name);
free((void*) wc->name);
free(wc);
}
@@ -185,7 +187,7 @@ cmd_wait_for_unlock(struct cmd_q *cmdq, const char *name,
wc->locked = 0;
if (TAILQ_EMPTY(&wc->waiters)) {
RB_REMOVE(wait_channels, &wait_channels, wc);
free((void *)wc->name);
free((void*) wc->name);
free(wc);
}
}
@@ -193,25 +195,3 @@ cmd_wait_for_unlock(struct cmd_q *cmdq, const char *name,
return (CMD_RETURN_NORMAL);
}
void
cmd_wait_for_flush(void)
{
struct wait_channel *wc, *wc1;
struct cmd_q *wq, *wq1;
RB_FOREACH_SAFE(wc, wait_channels, &wait_channels, wc1) {
TAILQ_FOREACH_SAFE(wq, &wc->waiters, waitentry, wq1) {
TAILQ_REMOVE(&wc->waiters, wq, waitentry);
if (!cmdq_free(wq))
cmdq_continue(wq);
}
while ((wq = TAILQ_FIRST(&wc->lockers)) != NULL) {
TAILQ_REMOVE(&wc->lockers, wq, waitentry);
if (!cmdq_free(wq))
cmdq_continue(wq);
}
RB_REMOVE(wait_channels, &wait_channels, wc);
free((void *)wc->name);
free(wc);
}
}
+147 -97
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,6 +34,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_capture_pane_entry,
&cmd_choose_buffer_entry,
&cmd_choose_client_entry,
&cmd_choose_list_entry,
&cmd_choose_session_entry,
&cmd_choose_tree_entry,
&cmd_choose_window_entry,
@@ -120,11 +121,13 @@ struct session *cmd_choose_session_list(struct sessionslist *);
struct session *cmd_choose_session(int);
struct client *cmd_choose_client(struct clients *);
struct client *cmd_lookup_client(const char *);
struct session *cmd_lookup_session(struct cmd_q *, const char *, int *);
struct session *cmd_lookup_session(const char *, int *);
struct session *cmd_lookup_session_id(const char *);
struct winlink *cmd_lookup_window(struct session *, const char *, int *);
int cmd_lookup_index(struct session *, const char *, int *);
struct window_pane *cmd_lookup_paneid(const char *);
struct winlink *cmd_lookup_winlink_windowid(struct session *, const char *);
struct window *cmd_lookup_windowid(const char *);
struct session *cmd_window_session(struct cmd_q *, struct window *,
struct winlink **);
struct winlink *cmd_find_window_offset(const char *, struct session *, int *);
@@ -137,9 +140,6 @@ cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
size_t arglen;
int i;
if (argc == 0)
return (0);
*buf = '\0';
for (i = 0; i < argc; i++) {
if (strlcpy(buf, argv[i], len) >= len)
@@ -179,14 +179,14 @@ cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
}
char **
cmd_copy_argv(int argc, char **argv)
cmd_copy_argv(int argc, char *const *argv)
{
char **new_argv;
int i;
if (argc == 0)
return (NULL);
new_argv = xcalloc(argc + 1, sizeof *new_argv);
new_argv = xcalloc(argc, sizeof *new_argv);
for (i = 0; i < argc; i++) {
if (argv[i] != NULL)
new_argv[i] = xstrdup(argv[i]);
@@ -206,32 +206,6 @@ cmd_free_argv(int argc, char **argv)
free(argv);
}
char *
cmd_stringify_argv(int argc, char **argv)
{
char *buf;
int i;
size_t len;
if (argc == 0)
return (xstrdup(""));
len = 0;
buf = NULL;
for (i = 0; i < argc; i++) {
len += strlen(argv[i]) + 1;
buf = xrealloc(buf, len);
if (i == 0)
*buf = '\0';
else
strlcat(buf, " ", len);
strlcat(buf, argv[i], len);
}
return (buf);
}
struct cmd *
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
{
@@ -280,6 +254,8 @@ cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
goto usage;
if (entry->args_upper != -1 && args->argc > entry->args_upper)
goto usage;
if (entry->check != NULL && entry->check(args) != 0)
goto usage;
cmd = xcalloc(1, sizeof *cmd);
cmd->entry = entry;
@@ -318,8 +294,8 @@ cmd_print(struct cmd *cmd, char *buf, size_t len)
size_t off, used;
off = xsnprintf(buf, len, "%s ", cmd->entry->name);
if (off + 1 < len) {
used = args_print(cmd->args, buf + off, len - off - 1);
if (off < len) {
used = args_print(cmd->args, buf + off, len - off);
if (used == 0)
off--;
else
@@ -339,6 +315,7 @@ cmd_print(struct cmd *cmd, char *buf, size_t len)
struct session *
cmd_current_session(struct cmd_q *cmdq, int prefer_unattached)
{
struct msg_command_data *data = cmdq->msgdata;
struct client *c = cmdq->client;
struct session *s;
struct sessionslist ss;
@@ -380,6 +357,13 @@ cmd_current_session(struct cmd_q *cmdq, int prefer_unattached)
return (s);
}
/* Use the session from the TMUX environment variable. */
if (data != NULL && data->pid == getpid() && data->session_id != -1) {
s = session_find_by_id(data->session_id);
if (s != NULL)
return (s);
}
return (cmd_choose_session(prefer_unattached));
}
@@ -584,11 +568,9 @@ cmd_lookup_session_id(const char *arg)
/* Lookup a session by name. If no session is found, NULL is returned. */
struct session *
cmd_lookup_session(struct cmd_q *cmdq, const char *name, int *ambiguous)
cmd_lookup_session(const char *name, int *ambiguous)
{
struct session *s, *sfound;
struct window *w;
struct window_pane *wp;
struct session *s, *sfound;
*ambiguous = 0;
@@ -596,12 +578,6 @@ cmd_lookup_session(struct cmd_q *cmdq, const char *name, int *ambiguous)
if ((s = cmd_lookup_session_id(name)) != NULL)
return (s);
/* Try as pane or window id. */
if ((wp = cmd_lookup_paneid(name)) != NULL)
return (cmd_window_session(cmdq, wp->window, NULL));
if ((w = cmd_lookup_windowid(name)) != NULL)
return (cmd_window_session(cmdq, w, NULL));
/*
* Look for matches. First look for exact matches - session names must
* be unique so an exact match can't be ambigious and can just be
@@ -637,30 +613,16 @@ cmd_lookup_session(struct cmd_q *cmdq, const char *name, int *ambiguous)
struct winlink *
cmd_lookup_window(struct session *s, const char *name, int *ambiguous)
{
struct winlink *wl, *wlfound;
struct window *w;
struct window_pane *wp;
const char *errstr;
u_int idx;
struct winlink *wl, *wlfound;
const char *errstr;
u_int idx;
*ambiguous = 0;
/* Try as pane or window id. */
/* Try as a window id. */
if ((wl = cmd_lookup_winlink_windowid(s, name)) != NULL)
return (wl);
/* Lookup as pane or window id. */
if ((wp = cmd_lookup_paneid(name)) != NULL) {
wl = winlink_find_by_window(&s->windows, wp->window);
if (wl != NULL)
return (wl);
}
if ((w = cmd_lookup_windowid(name)) != NULL) {
wl = winlink_find_by_window(&s->windows, w);
if (wl != NULL)
return (wl);
}
/* First see if this is a valid window index in this session. */
idx = strtonum(name, 0, INT_MAX, &errstr);
if (errstr == NULL) {
@@ -807,18 +769,23 @@ cmd_window_session(struct cmd_q *cmdq, struct window *w, struct winlink **wlp)
struct session *
cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached)
{
struct session *s;
struct client *c;
char *tmparg;
size_t arglen;
int ambiguous;
struct session *s;
struct window_pane *wp;
struct window *w;
struct client *c;
char *tmparg;
size_t arglen;
int ambiguous;
/* A NULL argument means the current session. */
if (arg == NULL) {
if ((s = cmd_current_session(cmdq, prefer_unattached)) == NULL)
cmdq_error(cmdq, "can't establish current session");
return (s);
}
if (arg == NULL)
return (cmd_current_session(cmdq, prefer_unattached));
/* Lookup as pane id or window id. */
if ((wp = cmd_lookup_paneid(arg)) != NULL)
return (cmd_window_session(cmdq, wp->window, NULL));
if ((w = cmd_lookup_windowid(arg)) != NULL)
return (cmd_window_session(cmdq, w, NULL));
/* Trim a single trailing colon if any. */
tmparg = xstrdup(arg);
@@ -829,13 +796,11 @@ cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached)
/* An empty session name is the current session. */
if (*tmparg == '\0') {
free(tmparg);
if ((s = cmd_current_session(cmdq, prefer_unattached)) == NULL)
cmdq_error(cmdq, "can't establish current session");
return (s);
return (cmd_current_session(cmdq, prefer_unattached));
}
/* Find the session, if any. */
s = cmd_lookup_session(cmdq, tmparg, &ambiguous);
s = cmd_lookup_session(tmparg, &ambiguous);
/* If it doesn't, try to match it as a client. */
if (s == NULL && (c = cmd_lookup_client(tmparg)) != NULL)
@@ -857,11 +822,12 @@ cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached)
struct winlink *
cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp)
{
struct session *s;
struct winlink *wl;
const char *winptr;
char *sessptr = NULL;
int ambiguous = 0;
struct session *s;
struct winlink *wl;
struct window_pane *wp;
const char *winptr;
char *sessptr = NULL;
int ambiguous = 0;
/*
* Find the current session. There must always be a current session, if
@@ -879,6 +845,14 @@ cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp)
return (s->curw);
}
/* Lookup as pane id. */
if ((wp = cmd_lookup_paneid(arg)) != NULL) {
s = cmd_window_session(cmdq, wp->window, &wl);
if (sp != NULL)
*sp = s;
return (wl);
}
/* Time to look at the argument. If it is empty, that is an error. */
if (*arg == '\0')
goto not_found;
@@ -893,7 +867,7 @@ cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp)
/* Try to lookup the session if present. */
if (*sessptr != '\0') {
if ((s = cmd_lookup_session(cmdq, sessptr, &ambiguous)) == NULL)
if ((s = cmd_lookup_session(sessptr, &ambiguous)) == NULL)
goto no_session;
}
if (sp != NULL)
@@ -944,8 +918,7 @@ no_colon:
lookup_session:
if (ambiguous)
goto not_found;
if (*arg != '\0' &&
(s = cmd_lookup_session(cmdq, arg, &ambiguous)) == NULL)
if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL)
goto no_session;
if (sp != NULL)
@@ -1035,7 +1008,7 @@ cmd_find_index(struct cmd_q *cmdq, const char *arg, struct session **sp)
/* Try to lookup the session if present. */
if (sessptr != NULL && *sessptr != '\0') {
if ((s = cmd_lookup_session(cmdq, sessptr, &ambiguous)) == NULL)
if ((s = cmd_lookup_session(sessptr, &ambiguous)) == NULL)
goto no_session;
}
if (sp != NULL)
@@ -1083,8 +1056,7 @@ no_colon:
lookup_session:
if (ambiguous)
goto not_found;
if (*arg != '\0' &&
(s = cmd_lookup_session(cmdq, arg, &ambiguous)) == NULL)
if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL)
goto no_session;
if (sp != NULL)
@@ -1198,13 +1170,7 @@ cmd_find_pane(struct cmd_q *cmdq,
*wpp = wl->window->active;
else if (paneptr[0] == '+' || paneptr[0] == '-')
*wpp = cmd_find_pane_offset(paneptr, wl);
else if (paneptr[0] == '!' && paneptr[1] == '\0') {
if (wl->window->last == NULL) {
cmdq_error(cmdq, "no last pane");
goto error;
}
*wpp = wl->window->last;
} else {
else {
idx = strtonum(paneptr, 0, INT_MAX, &errstr);
if (errstr != NULL)
goto lookup_string;
@@ -1301,14 +1267,98 @@ cmd_template_replace(const char *template, const char *s, int idx)
ptr++;
len += strlen(s);
buf = xrealloc(buf, len + 1);
buf = xrealloc(buf, 1, len + 1);
strlcat(buf, s, len + 1);
continue;
}
buf = xrealloc(buf, len + 2);
buf = xrealloc(buf, 1, len + 2);
buf[len++] = ch;
buf[len] = '\0';
}
return (buf);
}
/*
* Return the default path for a new pane, using the given path or the
* default-path option if it is NULL. Several special values are accepted: the
* empty string or relative path for the current pane's working directory, ~
* for the user's home, - for the session working directory, . for the tmux
* server's working directory. The default on failure is the session's working
* directory.
*/
const char *
cmd_get_default_path(struct cmd_q *cmdq, const char *cwd)
{
struct client *c = cmdq->client;
struct session *s;
struct environ_entry *envent;
const char *root;
char tmp[MAXPATHLEN];
struct passwd *pw;
int n;
size_t skip;
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;
if (strcmp(cwd, "$HOME") == 0 || strncmp(cwd, "$HOME/", 6) == 0) {
/* User's home directory - $HOME. */
skip = 5;
goto find_home;
} else if (cwd[0] == '~' && (cwd[1] == '\0' || cwd[1] == '/')) {
/* User's home directory - ~. */
goto find_home;
} else if (cwd[0] == '-' && (cwd[1] == '\0' || cwd[1] == '/')) {
/* Session working directory. */
root = s->cwd;
goto complete_path;
} else if (cwd[0] == '.' && (cwd[1] == '\0' || cwd[1] == '/')) {
/* Server working directory. */
if (getcwd(tmp, sizeof tmp) != NULL) {
root = tmp;
goto complete_path;
}
return (s->cwd);
} else if (*cwd == '/') {
/* Absolute path. */
return (cwd);
} else {
/* Empty or relative path. */
if (c != NULL && c->session == NULL && c->cwd != NULL)
root = c->cwd;
else if (s->curw != NULL)
root = osdep_get_cwd(s->curw->window->active->fd);
else
return (s->cwd);
skip = 0;
if (root != NULL)
goto complete_path;
}
return (s->cwd);
find_home:
envent = environ_find(&global_environ, "HOME");
if (envent != NULL && *envent->value != '\0')
root = envent->value;
else if ((pw = getpwuid(getuid())) != NULL)
root = pw->pw_dir;
else
return (s->cwd);
complete_path:
if (root[skip] == '\0') {
strlcpy(path, root, sizeof path);
return (path);
}
n = snprintf(path, sizeof path, "%s/%s", root, cwd + skip);
if (n > 0 && (size_t)n < sizeof path)
return (path);
return (s->cwd);
}
+35 -9
View File
@@ -1,4 +1,4 @@
/* $OpenBSD$ */
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -236,28 +236,28 @@ colour_fromstring(const char *s)
if (strcasecmp(s, "default") == 0 || (s[0] == '8' && s[1] == '\0'))
return (8);
if (strcasecmp(s, "brightblack") == 0 ||
(s[0] == '9' && s[1] == '0' && s[2] == '\0'))
(s[0] == '9' && s[1] == '0' && s[1] == '\0'))
return (90);
if (strcasecmp(s, "brightred") == 0 ||
(s[0] == '9' && s[1] == '1' && s[2] == '\0'))
(s[0] == '9' && s[1] == '1' && s[1] == '\0'))
return (91);
if (strcasecmp(s, "brightgreen") == 0 ||
(s[0] == '9' && s[1] == '2' && s[2] == '\0'))
(s[0] == '9' && s[1] == '2' && s[1] == '\0'))
return (92);
if (strcasecmp(s, "brightyellow") == 0 ||
(s[0] == '9' && s[1] == '3' && s[2] == '\0'))
(s[0] == '9' && s[1] == '3' && s[1] == '\0'))
return (93);
if (strcasecmp(s, "brightblue") == 0 ||
(s[0] == '9' && s[1] == '4' && s[2] == '\0'))
(s[0] == '9' && s[1] == '4' && s[1] == '\0'))
return (94);
if (strcasecmp(s, "brightmagenta") == 0 ||
(s[0] == '9' && s[1] == '5' && s[2] == '\0'))
(s[0] == '9' && s[1] == '5' && s[1] == '\0'))
return (95);
if (strcasecmp(s, "brightcyan") == 0 ||
(s[0] == '9' && s[1] == '6' && s[2] == '\0'))
(s[0] == '9' && s[1] == '6' && s[1] == '\0'))
return (96);
if (strcasecmp(s, "brightwhite") == 0 ||
(s[0] == '9' && s[1] == '7' && s[2] == '\0'))
(s[0] == '9' && s[1] == '7' && s[1] == '\0'))
return (97);
return (-1);
}
@@ -287,3 +287,29 @@ colour_256to16(u_char c)
return (table[c]);
}
/* Convert 256 colour palette to 88. */
u_char
colour_256to88(u_char c)
{
static const u_char table[256] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 17, 18, 18, 19, 20, 21, 21, 22, 22, 23, 20, 21, 21, 22,
22, 23, 24, 25, 25, 26, 26, 27, 24, 25, 25, 26, 26, 27, 28, 29,
29, 30, 30, 31, 32, 33, 33, 34, 34, 35, 36, 37, 37, 38, 38, 39,
36, 37, 37, 38, 38, 39, 40, 41, 41, 42, 42, 43, 40, 41, 41, 42,
42, 43, 44, 45, 45, 46, 46, 47, 32, 33, 33, 34, 34, 35, 36, 37,
37, 38, 38, 39, 36, 37, 37, 38, 38, 39, 40, 41, 41, 42, 42, 43,
40, 41, 41, 42, 42, 43, 44, 45, 45, 46, 46, 47, 48, 49, 49, 50,
50, 51, 52, 53, 53, 54, 54, 55, 52, 53, 53, 54, 54, 55, 56, 57,
57, 58, 58, 59, 56, 57, 57, 58, 58, 59, 60, 61, 61, 62, 62, 63,
48, 49, 49, 50, 50, 51, 52, 53, 53, 54, 54, 55, 52, 53, 53, 54,
54, 55, 56, 57, 57, 58, 58, 59, 56, 57, 57, 58, 58, 59, 60, 61,
61, 62, 62, 63, 64, 65, 65, 66, 66, 67, 68, 69, 69, 70, 70, 71,
68, 69, 69, 70, 70, 71, 72, 73, 73, 74, 74, 75, 72, 73, 73, 74,
74, 75, 76, 77, 77, 78, 78, 79, 0, 0, 80, 80, 80, 81, 81, 81,
82, 82, 82, 83, 83, 83, 84, 84, 84, 85, 85, 85, 86, 86, 86, 87
};
return (table[c]);
}
-47
View File
@@ -30,10 +30,6 @@
#define __packed __attribute__ ((__packed__))
#endif
#ifndef ECHOPRT
#define ECHOPRT 0
#endif
#ifndef HAVE_BSD_TYPES
typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
@@ -125,10 +121,6 @@ typedef uint64_t u_int64_t;
#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
#endif
#ifndef O_DIRECTORY
#define O_DIRECTORY 0
#endif
#ifndef INFTIM
#define INFTIM -1
#endif
@@ -160,33 +152,10 @@ typedef uint64_t u_int64_t;
} while (0)
#endif
#ifndef timersub
#define timersub(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
if ((vvp)->tv_usec < 0) { \
(vvp)->tv_sec--; \
(vvp)->tv_usec += 1000000; \
} \
} while (0)
#endif
#ifndef TTY_NAME_MAX
#define TTY_NAME_MAX 32
#endif
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 255
#endif
#ifndef HAVE_FLOCK
#define LOCK_SH 0
#define LOCK_EX 0
#define LOCK_NB 0
#define flock(fd, op) (0)
#endif
#ifndef HAVE_BZERO
#undef bzero
#define bzero(buf, len) memset(buf, 0, len);
@@ -229,7 +198,6 @@ int daemon(int, int);
#ifndef HAVE_B64_NTOP
/* b64_ntop.c */
#undef b64_ntop /* for Cygwin */
int b64_ntop(const char *, size_t, char *, size_t);
#endif
@@ -250,27 +218,12 @@ int vasprintf(char **, const char *, va_list);
char *fgetln(FILE *, size_t *);
#endif
#ifndef HAVE_FPARSELN
char *fparseln(FILE *, size_t *, size_t *, const char *, int);
#endif
#ifndef HAVE_SETENV
/* setenv.c */
int setenv(const char *, const char *, int);
int unsetenv(const char *);
#endif
#ifndef HAVE_CFMAKERAW
/* cfmakeraw.c */
void cfmakeraw(struct termios *);
#endif
#ifndef HAVE_OPENAT
/* openat.c */
#define AT_FDCWD -100
int openat(int, const char *, int, ...);
#endif
#ifdef HAVE_GETOPT
#include <getopt.h>
#else
+2 -2
View File
@@ -1,3 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
*
@@ -54,12 +56,10 @@ vasprintf(char **ret, const char *fmt, va_list ap)
free(*ret);
goto error;
}
va_end(ap2);
return (n);
error:
va_end(ap2);
*ret = NULL;
return (-1);
}
+1
View File
@@ -1,3 +1,4 @@
/* $Id$ */
/* $OpenBSD: bitstring.h,v 1.5 2003/06/02 19:34:12 millert Exp $ */
/* $NetBSD: bitstring.h,v 1.5 1997/05/14 15:49:55 pk Exp $ */
+2
View File
@@ -1,3 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2004-2005 Todd C. Miller <Todd.Miller@courtesan.com>
*
+1
View File
@@ -1,3 +1,4 @@
/* $Id$ */
/* $OpenBSD: daemon.c,v 1.6 2005/08/08 08:05:33 espie Exp $ */
/*-
* Copyright (c) 1990, 1993
+1
View File
@@ -1,3 +1,4 @@
/* $Id$ */
/* $NetBSD: fgetln.c,v 1.3 2007/08/07 02:06:58 lukem Exp $ */
/*-
+5 -21
View File
@@ -1,3 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
@@ -21,22 +23,18 @@
#include <stdlib.h>
#include <stropts.h>
#include <unistd.h>
#include <errno.h>
#include "tmux.h"
pid_t
forkpty(int *master, unused char *name, struct termios *tio, struct winsize *ws)
{
int slave = -1, fd, pipe_fd[2];
char *path, dummy;
int slave, fd;
char *path;
pid_t pid;
if (pipe(pipe_fd) == -1)
return (-1);
if ((*master = open("/dev/ptc", O_RDWR|O_NOCTTY)) == -1)
goto out;
return (-1);
if ((path = ttyname(*master)) == NULL)
goto out;
@@ -49,13 +47,6 @@ forkpty(int *master, unused char *name, struct termios *tio, struct winsize *ws)
case 0:
close(*master);
close(pipe_fd[1]);
while (read(pipe_fd[0], &dummy, 1) == -1) {
if (errno != EINTR)
break;
}
close(pipe_fd[0]);
fd = open(_PATH_TTY, O_RDWR|O_NOCTTY);
if (fd >= 0) {
ioctl(fd, TIOCNOTTY, NULL);
@@ -89,14 +80,10 @@ forkpty(int *master, unused char *name, struct termios *tio, struct winsize *ws)
dup2(slave, 2);
if (slave > 2)
close(slave);
return (0);
}
close(slave);
close(pipe_fd[0]);
close(pipe_fd[1]);
return (pid);
out:
@@ -104,8 +91,5 @@ out:
close(*master);
if (slave != -1)
close(slave);
close(pipe_fd[0]);
close(pipe_fd[1]);
return (-1);
}
+3 -1
View File
@@ -1,3 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
*
@@ -27,7 +29,7 @@
pid_t
forkpty(int *master, char *name, struct termios *tio, struct winsize *ws)
{
int slave = -1;
int slave;
char *path;
pid_t pid;

Some files were not shown because too many files have changed in this diff Show More