mirror of
https://github.com/tmux/tmux.git
synced 2026-03-12 11:35:46 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2365b09d6a |
12
.gitignore
vendored
12
.gitignore
vendored
@@ -1,12 +0,0 @@
|
|||||||
*.o
|
|
||||||
*~
|
|
||||||
.deps/
|
|
||||||
aclocal.m4
|
|
||||||
autom4te.cache/
|
|
||||||
config.log
|
|
||||||
config.status
|
|
||||||
etc/
|
|
||||||
tmux
|
|
||||||
Makefile
|
|
||||||
Makefile.in
|
|
||||||
configure
|
|
||||||
197
CHANGES
197
CHANGES
@@ -1,198 +1,3 @@
|
|||||||
CHANGES FROM 1.6 to 1.7, 13 October 2012
|
|
||||||
|
|
||||||
* tmux configuration files now support line-continuation with a "\" at the
|
|
||||||
end of a line.
|
|
||||||
* New option status-position to move the status line to the top or bottom of
|
|
||||||
the screen.
|
|
||||||
* Enforce history-limit option when clearing the screen.
|
|
||||||
* Give each window a unique id, like panes but prefixed with @.
|
|
||||||
* Add pane id to each pane in layout description (while still accepting
|
|
||||||
the old form).
|
|
||||||
* Provide defined ways to set the various default-path possibilities: ~
|
|
||||||
for home directory, . for server start directory, - for session start
|
|
||||||
directory and empty for the pane's working directory (the default). All
|
|
||||||
can also be used as part of a relative path (eg -/foo). Also provide -c
|
|
||||||
flags to neww and splitw to override default-path setting.
|
|
||||||
* Add -l flag to send-keys to send input literally (without translating
|
|
||||||
key names).
|
|
||||||
* Allow a single option to be specified to show-options to show just that
|
|
||||||
option.
|
|
||||||
* New command "move-pane" (like join-pane but allows the same window).
|
|
||||||
* join-pane and move-pane commands learn "-b" option to place the pane to
|
|
||||||
the left or above.
|
|
||||||
* Support for bracketed-paste mode.
|
|
||||||
* Allow send-keys command to accept hex values.
|
|
||||||
* Add locking around "start-server" to avoid race-conditions.
|
|
||||||
* break-pane learns -P/-F arguments for display formatting.
|
|
||||||
* set-option learns "-q" to make it quiet, and not print out anything.
|
|
||||||
* copy mode learns "wrap-search" option.
|
|
||||||
* Add a simple form of output rate limiting by counting the number of
|
|
||||||
certain C0 sequences (linefeeds, backspaces, carriage returns) and if it
|
|
||||||
exceeds a threshold (current default 250/millisecond), start to redraw
|
|
||||||
the pane every 100 milliseconds instead of making each change as it
|
|
||||||
comes. Two configuration options - c0-change-trigger and
|
|
||||||
c0-change-interval.
|
|
||||||
* find-window learns new flags: "-C", "-N", "-T" to match against either or
|
|
||||||
all of a window's content, name, or title. Defaults to all three options
|
|
||||||
if none specified.
|
|
||||||
* find-window automatically selects the appropriate pane for the found
|
|
||||||
matches.
|
|
||||||
* show-environment can now accept one option to show that environment value.
|
|
||||||
* Exit mouse mode when end-of-screen reached when scrolling with the mouse
|
|
||||||
wheel.
|
|
||||||
* select-layout learns -u and -U for layout history stacks.
|
|
||||||
* kill-window, detach-client, kill-session all learn "-a" option for
|
|
||||||
killing all but the current thing specified.
|
|
||||||
* move-window learns "-r" option to renumber window sequentially in a
|
|
||||||
session.
|
|
||||||
* New session option "renumber-windows" to automatically renumber windows in
|
|
||||||
a session when a window is closed. (see "move-window -r").
|
|
||||||
* Only enter copy-mode on scroll up.
|
|
||||||
* choose-* and list-* commands all use "-F" for format specifiers.
|
|
||||||
* When spawning external commands, the value from the "default-shell" option
|
|
||||||
is now used, rather than assuming /bin/sh.
|
|
||||||
* New choose-tree command to render window/sessions as a tree for selection.
|
|
||||||
* display-message learns new format options.
|
|
||||||
* For linked-windows across sessions, all flags for that window are now
|
|
||||||
cleared across sessions.
|
|
||||||
* Lots and lots of bug fixes, fixing memory-leaks, etc.
|
|
||||||
* Various manpage improvements.
|
|
||||||
|
|
||||||
CHANGES FROM 1.5 TO 1.6, 23 January 2012
|
|
||||||
|
|
||||||
* Extend the mode-mouse option to add a third choice which means the mouse
|
|
||||||
does not enter copy mode.
|
|
||||||
* Add a -r flag to switch-client to toggle the client read-only flag.
|
|
||||||
* Add pane-base-index option.
|
|
||||||
* Support \ for line continuation in the configuration file.
|
|
||||||
* Framework for more powerful formatting of command output and use it for
|
|
||||||
list-{panes,windows,sessions}. This allows more descriptive replacements
|
|
||||||
(such as #{session_name}) and conditionals.
|
|
||||||
* Mark dead panes with some text saying they are dead.
|
|
||||||
* Reject $SHELL if it is not a full path.
|
|
||||||
* Add -S option to refresh-client to redraw status line.
|
|
||||||
* Add an else clause for if-shell.
|
|
||||||
* Try to resolve relative paths for loadb and saveb (first, using client
|
|
||||||
working directory, if any, then default-path or session working directory).
|
|
||||||
* Support for \e[3J to clear the history and send the corresponding
|
|
||||||
terminfo code (E3) before locking.
|
|
||||||
* When in copy mode, make repeat count indicate buffer to replace, if used.
|
|
||||||
* Add screen*:XT to terminal-overrides for tmux-in-tmux.
|
|
||||||
* Status-line message attributes added.
|
|
||||||
* Move word-separators to be a session rather than window option.
|
|
||||||
* Change the way the working directory for new processes is discovered. If
|
|
||||||
default-path isn't empty, it is used. Otherwise, if a new window is created
|
|
||||||
from the command-line, the working directory of the client is used. If not,
|
|
||||||
platform specific code is used to retrieve the current working directory
|
|
||||||
of the process in the active pane. If that fails, the directory where the
|
|
||||||
session was created is used, instead.
|
|
||||||
* Do not change the current pane if both mouse-select-{pane,window} are
|
|
||||||
enabled.
|
|
||||||
* Add \033[s and \033[u to save and restore cursor position.
|
|
||||||
* Allow $HOME to be used as default-path.
|
|
||||||
* Add CNL and CPL escape sequences.
|
|
||||||
* Calculate last position correctly for UTF-8 wide characters.
|
|
||||||
* Add an option allow-rename to disable the window rename escape sequence.
|
|
||||||
* Attributes for each type of status-line alert (ie bell, content and
|
|
||||||
activity) added. Therefore, remove the superfluous options
|
|
||||||
window-status-alert-{attr,bg,fg}.
|
|
||||||
* Add a -R flag to send-keys to reset the terminal.
|
|
||||||
* Add strings to allow the aixterm bright colours to be used when
|
|
||||||
configuring colours.
|
|
||||||
* Drop the ability to have a list of keys in the prefix in favour of two
|
|
||||||
separate options, prefix and prefix2.
|
|
||||||
* Flag -2 added to send-prefix to send the secondary prefix key.
|
|
||||||
* Show pane size in top right of display panes mode.
|
|
||||||
* Some memory leaks plugged.
|
|
||||||
* More command-prompt editing improvements.
|
|
||||||
* Various manpage improvements.
|
|
||||||
* More Vi mode improvements.
|
|
||||||
|
|
||||||
CHANGES FROM 1.4 TO 1.5, 09 July 2011
|
|
||||||
|
|
||||||
* Support xterm mouse modes 1002 and 1003.
|
|
||||||
* Change from a per-session stack of buffers to one global stack. This renders
|
|
||||||
copy-buffer useless and makes buffer-limit now a server option.
|
|
||||||
* Fix most-recently-used choice by avoiding reset the activity timer for
|
|
||||||
unattached sessions every second.
|
|
||||||
* Add a -P option to new-window and split-window to print the new window or
|
|
||||||
pane index in target form (useful to pass it into other commands).
|
|
||||||
* Handle a # at the end of a replacement string (such as status-left)
|
|
||||||
correctly.
|
|
||||||
* Support for UTF-8 mouse input (\033[1005h) which was added in xterm 262.
|
|
||||||
If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
|
|
||||||
UTF-8 terminals. The option defaults to on if LANG etc are set in the same
|
|
||||||
manner as the utf8 option.
|
|
||||||
* Support for HP-UX.
|
|
||||||
* Accept colours of the hex form #ffffff and translate to the nearest from the
|
|
||||||
xterm(1) 256-colour set.
|
|
||||||
* Clear the non-blocking IO flag (O_NONBLOCK) on the stdio file descriptors
|
|
||||||
before closing them (fixes things like "tmux ls && cat").
|
|
||||||
* Use TMPDIR if set.
|
|
||||||
* Fix next and previous session functions to actually work.
|
|
||||||
* Support -x and -y for new-session to specify the initial size of the window
|
|
||||||
if created detached with -d.
|
|
||||||
* Make bind-key accept characters with the top-bit-set and print them as octal.
|
|
||||||
* Set $TMUX without the session when background jobs are run.
|
|
||||||
* Simplify the way jobs work and drop the persist type, so all jobs are
|
|
||||||
fire-and-forget.
|
|
||||||
* Accept tcgetattr/tcsetattr(3) failure, fixes problems with fatal() if the
|
|
||||||
terminal disappears while locked.
|
|
||||||
* Add a -P option to detach to HUP the client's parent process (usually causing
|
|
||||||
it to exit as well).
|
|
||||||
* Support passing through escape sequences to the underlying terminal by using
|
|
||||||
DCS with a "tmux;" prefix.
|
|
||||||
* Prevent tiled producing a corrupt layout when only one column is needed.
|
|
||||||
* Give each pane created in a tmux server a unique id (starting from 0), put it
|
|
||||||
in the TMUX_PANE environment variable and accept it as a target.
|
|
||||||
* Allow a start and end line to be specified for capture-pane which may be
|
|
||||||
negative to capture part of the history.
|
|
||||||
* Add -a and -s options to lsp to list all panes in the server or session
|
|
||||||
respectively. Likewise add -s to lsw.
|
|
||||||
* Change -t on display-message to be target-pane for the #[A-Z] replacements
|
|
||||||
and add -c as target-client.
|
|
||||||
* The attach-session command now prefers the most recently used unattached
|
|
||||||
session.
|
|
||||||
* Add -s option to detach-client to detach all clients attached to a session.
|
|
||||||
* Add -t to list-clients.
|
|
||||||
* Change window with mouse wheel over status line if mouse-select-window is on.
|
|
||||||
* When mode-mouse is on, automatically enter copy mode when the mouse is
|
|
||||||
dragged or the mouse wheel is used. Also exit copy mode when the mouse wheel
|
|
||||||
is scrolled off the bottom.
|
|
||||||
* Provide #h character pair for short hostname (no domain).
|
|
||||||
* Don't use strnvis(3) for the title as it breaks UTF-8.
|
|
||||||
* Use the tsl and fsl terminfo(5) capabilities to update terminal title and
|
|
||||||
automatically fill them in on terminals with the XT capability (which means
|
|
||||||
their title setting is xterm-compatible).
|
|
||||||
* Add a new option, mouse-resize-pane. When on, panes may be resized by
|
|
||||||
dragging their borders.
|
|
||||||
* Fix crash by resetting last pane on {break,swap}-pane across windows.
|
|
||||||
* Add three new copy-mode commands - select-line, copy-line, copy-end-of-line.
|
|
||||||
* Support setting the xterm clipboard when copying from copy mode using the
|
|
||||||
xterm escape sequence for the purpose (if xterm is configured to allow it).
|
|
||||||
* Support xterm(1) cursor colour change sequences through terminfo(5) Cc
|
|
||||||
(set) and Cr (reset) extensions.
|
|
||||||
* Support DECSCUSR sequence to set the cursor style with two new terminfo(5)
|
|
||||||
extensions, Cs and Csr.
|
|
||||||
* Make the command-prompt custom prompts recognize the status-left option
|
|
||||||
character pairs.
|
|
||||||
* Add a respawn-pane command.
|
|
||||||
* Add a couple of extra xterm-style keys that gnome terminal provides.
|
|
||||||
* Allow the initial context on prompts to be set with the new -I option to
|
|
||||||
command-prompt. Include the current window and session name in the prompt
|
|
||||||
when renaming and add a new key binding ($) for rename session.
|
|
||||||
* Option bell-on-alert added to trigger the terminal bell when there is an
|
|
||||||
alert.
|
|
||||||
* Change the list-keys format so that it shows the keys using actual tmux
|
|
||||||
commands which should be able to be directly copied into the config file.
|
|
||||||
* Show full targets for lsp/lsw -a.
|
|
||||||
* Make confirm-before prompt customizable with -p option like command-prompt
|
|
||||||
and add the character pairs #W and #P to the default kill-{pane,window}
|
|
||||||
prompts.
|
|
||||||
* Avoid sending data to suspended/locked clients.
|
|
||||||
* Small memory leaks in error paths plugged.
|
|
||||||
* Vi mode improvements.
|
|
||||||
|
|
||||||
CHANGES FROM 1.3 TO 1.4, 27 December 2010
|
CHANGES FROM 1.3 TO 1.4, 27 December 2010
|
||||||
|
|
||||||
* Window bell reporting fixed.
|
* Window bell reporting fixed.
|
||||||
@@ -1749,7 +1554,7 @@ The list of older changes is below.
|
|||||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||||
customisation.
|
customisation.
|
||||||
|
|
||||||
$Id$
|
$Id: CHANGES,v 1.304 2010-12-27 21:37:42 tcunha Exp $
|
||||||
|
|
||||||
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
|
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: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
|
||||||
|
|||||||
76
FAQ
76
FAQ
@@ -103,7 +103,8 @@ aware of are (bearing in mind I haven't used screen for a few years now):
|
|||||||
- tmux tends to be more demanding on the terminal so tends to show up terminal
|
- tmux tends to be more demanding on the terminal so tends to show up terminal
|
||||||
and application bugs which screen does not.
|
and application bugs which screen does not.
|
||||||
|
|
||||||
- screen has wider platform support, for example IRIX, and for odd terminals.
|
- screen has wider platform support, for example IRIX and HP-UX, and for odd
|
||||||
|
terminals.
|
||||||
|
|
||||||
* I found a bug! What do I do?
|
* I found a bug! What do I do?
|
||||||
|
|
||||||
@@ -370,76 +371,5 @@ If it is not a character device or has incorrect permissions, it can typically
|
|||||||
be recreated with:
|
be recreated with:
|
||||||
|
|
||||||
cd /dev && rm null && ./MAKEDEV null
|
cd /dev && rm null && ./MAKEDEV null
|
||||||
|
|
||||||
* vim displays reverse video instead of italics, while less displays italics
|
|
||||||
(or just regular text) instead of reverse. What's wrong?
|
|
||||||
|
|
||||||
Screen's terminfo description lacks italics mode and has standout mode in its
|
|
||||||
place, but using the same escape sequence that urxvt uses for italics. This
|
|
||||||
means applications (like vim) looking for italics will not find it and might
|
|
||||||
turn to reverse in its place, while applications (like less) asking for
|
|
||||||
standout will end up with italics instead of reverse. To make applications
|
|
||||||
aware that tmux supports italics and to use a proper escape sequence for
|
|
||||||
standout, you'll need to create a new terminfo file with modified sgr, smso,
|
|
||||||
rmso, sitm and ritm entries:
|
|
||||||
|
|
||||||
$ mkdir $HOME/.terminfo/
|
|
||||||
$ screen_terminfo="screen"
|
|
||||||
$ infocmp "$screen_terminfo" | sed \
|
|
||||||
-e 's/^screen[^|]*|[^,]*,/screen-it|screen with italics support,/' \
|
|
||||||
-e 's/%?%p1%t;3%/%?%p1%t;7%/' \
|
|
||||||
-e 's/smso=[^,]*,/smso=\\E[7m,/' \
|
|
||||||
-e 's/rmso=[^,]*,/rmso=\\E[27m,/' \
|
|
||||||
-e '$s/$/ sitm=\\E[3m, ritm=\\E[23m,/' > /tmp/screen.terminfo
|
|
||||||
$ tic /tmp/screen.terminfo
|
|
||||||
|
|
||||||
And tell tmux to use it in ~/.tmux.conf:
|
|
||||||
|
|
||||||
set -g default-terminal "screen-it"
|
|
||||||
|
|
||||||
If your terminal supports 256 colors, use:
|
|
||||||
|
|
||||||
$ screen_terminfo="screen-256color"
|
|
||||||
|
|
||||||
instead of "screen". See the FAQ entry about 256 colors support for more info.
|
|
||||||
Also note that tmux will still display reverse video on terminals that do not
|
|
||||||
support italics.
|
|
||||||
|
|
||||||
If your urxvt cannot display italics at all, make sure you have an italics
|
|
||||||
capable font enabled, for example, add to ~/.Xdefaults:
|
|
||||||
|
|
||||||
urxvt.italicFont: xft:Bitstream Vera Sans Mono:italic:autohint=true
|
|
||||||
|
|
||||||
* How can I make tmux use my terminal's scrollback buffer?
|
|
||||||
|
|
||||||
Normally, tmux enables the terminal's "alternate screen". Most terminals (such
|
|
||||||
as xterm) do not save scrollback for the alternate screen. You might prefer
|
|
||||||
tmux to use the normal screen, so it uses your terminal's scrollback
|
|
||||||
buffer. This way, you can access the scrollback buffer as usual, for example
|
|
||||||
using the mouse wheel - although there is no guarantee output inside tmux will
|
|
||||||
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 -g terminal-overrides 'xterm*:smcup@:rmcup@'
|
|
||||||
|
|
||||||
Adjust if your $TERM does not start with xterm.
|
|
||||||
|
|
||||||
tmux will still emulate the alternate screen for applications run under tmux,
|
|
||||||
so you don't really lose anything with this setting. The only disadvantage is
|
|
||||||
that when you exit tmux, it will not restore whatever was there before you
|
|
||||||
started.
|
|
||||||
|
|
||||||
* How do I see the default configuration?
|
|
||||||
|
|
||||||
Show the default session options by starting a new tmux server with no
|
|
||||||
configuration file:
|
|
||||||
|
|
||||||
$ tmux -Lfoo -f/dev/null start\; show -g
|
|
||||||
|
|
||||||
Or the default window options:
|
|
||||||
|
|
||||||
$ tmux -Lfoo -f/dev/null start\; show -gw
|
|
||||||
|
|
||||||
$Id$
|
$Id: FAQ,v 1.41 2010-12-15 23:31:30 nicm Exp $
|
||||||
|
|||||||
87
GNUmakefile
Normal file
87
GNUmakefile
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
# $Id: GNUmakefile,v 1.130 2010-12-27 21:32:16 tcunha Exp $
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
VERSION= 1.4
|
||||||
|
|
||||||
|
#FDEBUG= 1
|
||||||
|
|
||||||
|
CC?= cc
|
||||||
|
CFLAGS+= -DBUILD="\"$(VERSION)\""
|
||||||
|
LDFLAGS+= -L/usr/local/lib
|
||||||
|
LIBS+=
|
||||||
|
|
||||||
|
# Sun CC
|
||||||
|
ifneq ($(shell ($(CC) -V 2>&1|awk '/Sun C/' || true)), )
|
||||||
|
CFLAGS+= -erroff=E_EMPTY_DECLARATION
|
||||||
|
FDEBUG=
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef FDEBUG
|
||||||
|
CFLAGS+= -g -ggdb -DDEBUG
|
||||||
|
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
|
||||||
|
endif
|
||||||
|
|
||||||
|
# This sort of sucks but gets rid of the stupid warning and should work on
|
||||||
|
# most platforms...
|
||||||
|
ifeq ($(shell (LC_ALL=C $(CC) -v 2>&1|awk '/gcc version 4|clang/') || true), )
|
||||||
|
CPPFLAGS:= -I. -I- $(CPPFLAGS)
|
||||||
|
else
|
||||||
|
CPPFLAGS:= -iquote. $(CPPFLAGS)
|
||||||
|
ifdef FDEBUG
|
||||||
|
CFLAGS+= -Wno-pointer-sign
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
PREFIX?= /usr/local
|
||||||
|
INSTALL?= install
|
||||||
|
INSTALLDIR= $(INSTALL) -d
|
||||||
|
INSTALLBIN= $(INSTALL) -m 555
|
||||||
|
INSTALLMAN= $(INSTALL) -m 444
|
||||||
|
|
||||||
|
SRCS= $(shell echo *.c|LC_ALL=C sed 's|osdep-[a-z0-9]*.c||g')
|
||||||
|
include config.mk
|
||||||
|
OBJS= $(patsubst %.c,%.o,$(SRCS))
|
||||||
|
|
||||||
|
all: tmux
|
||||||
|
|
||||||
|
tmux: $(OBJS)
|
||||||
|
$(CC) $(LDFLAGS) -o tmux $+ $(LIBS)
|
||||||
|
|
||||||
|
depend: $(SRCS)
|
||||||
|
$(CC) $(CPPFLAGS) $(CFLAGS) -MM $(SRCS) > .depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f tmux *.o *~ *.core *.log compat/*.o compat/*~
|
||||||
|
|
||||||
|
clean-depend:
|
||||||
|
rm -f .depend
|
||||||
|
|
||||||
|
clean-all: clean clean-depend
|
||||||
|
rm -f config.h config.mk
|
||||||
|
|
||||||
|
install: all
|
||||||
|
$(INSTALLDIR) $(DESTDIR)$(PREFIX)/bin
|
||||||
|
$(INSTALLBIN) tmux $(DESTDIR)$(PREFIX)/bin/tmux
|
||||||
|
$(INSTALLDIR) $(DESTDIR)$(PREFIX)/man/man1
|
||||||
|
$(INSTALLMAN) tmux.1 $(DESTDIR)$(PREFIX)/man/man1/tmux.1
|
||||||
|
|
||||||
|
-include .depend
|
||||||
84
Makefile
Normal file
84
Makefile
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# $Id: Makefile,v 1.162 2010-12-27 21:32:16 tcunha Exp $
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
.SUFFIXES: .c .o
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
VERSION= 1.4
|
||||||
|
|
||||||
|
#FDEBUG= 1
|
||||||
|
|
||||||
|
CC?= cc
|
||||||
|
CFLAGS+= -DBUILD="\"$(VERSION)\""
|
||||||
|
LDFLAGS+= -L/usr/local/lib
|
||||||
|
LIBS+=
|
||||||
|
|
||||||
|
.ifdef FDEBUG
|
||||||
|
CFLAGS+= -g -ggdb -DDEBUG
|
||||||
|
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
|
||||||
|
.endif
|
||||||
|
|
||||||
|
# This sort of sucks but gets rid of the stupid warning and should work on
|
||||||
|
# most platforms...
|
||||||
|
CCV!= (LC_ALL=C ${CC} -v 2>&1|awk '/gcc version 4|clang/') || true
|
||||||
|
.if empty(CCV)
|
||||||
|
CPPFLAGS:= -I. -I- -I/usr/local/include ${CPPFLAGS}
|
||||||
|
.else
|
||||||
|
CPPFLAGS:= -iquote. -I/usr/local/include ${CPPFLAGS}
|
||||||
|
.ifdef FDEBUG
|
||||||
|
CFLAGS+= -Wno-pointer-sign
|
||||||
|
.endif
|
||||||
|
.endif
|
||||||
|
|
||||||
|
PREFIX?= /usr/local
|
||||||
|
INSTALL?= install
|
||||||
|
INSTALLDIR= ${INSTALL} -d
|
||||||
|
INSTALLBIN= ${INSTALL} -m 555
|
||||||
|
INSTALLMAN= ${INSTALL} -m 444
|
||||||
|
|
||||||
|
SRCS!= echo *.c|LC_ALL=C sed 's|osdep-[a-z0-9]*.c||g'
|
||||||
|
.include "config.mk"
|
||||||
|
OBJS= ${SRCS:S/.c/.o/}
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CPPFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
|
||||||
|
|
||||||
|
all: tmux
|
||||||
|
|
||||||
|
tmux: ${OBJS}
|
||||||
|
${CC} ${LDFLAGS} -o tmux ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
depend:
|
||||||
|
mkdep ${CPPFLAGS} ${CFLAGS} ${SRCS:M*.c}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f tmux *.o *~ *.core *.log compat/*.o compat/*~
|
||||||
|
|
||||||
|
clean-depend:
|
||||||
|
rm -f .depend
|
||||||
|
|
||||||
|
clean-all: clean clean-depend
|
||||||
|
rm -f config.h config.mk
|
||||||
|
|
||||||
|
install: all
|
||||||
|
${INSTALLDIR} ${DESTDIR}${PREFIX}/bin
|
||||||
|
${INSTALLBIN} tmux ${DESTDIR}${PREFIX}/bin/
|
||||||
|
${INSTALLDIR} ${DESTDIR}${PREFIX}/man/man1
|
||||||
|
${INSTALLMAN} tmux.1 ${DESTDIR}${PREFIX}/man/man1/
|
||||||
245
Makefile.am
245
Makefile.am
@@ -1,245 +0,0 @@
|
|||||||
# $Id$
|
|
||||||
|
|
||||||
# Obvious program stuff.
|
|
||||||
bin_PROGRAMS = tmux
|
|
||||||
dist_man1_MANS = tmux.1
|
|
||||||
|
|
||||||
# Distribution tarball options.
|
|
||||||
EXTRA_DIST = \
|
|
||||||
CHANGES FAQ NOTES TODO examples compat \
|
|
||||||
array.h compat.h tmux.h osdep-*.c
|
|
||||||
dist-hook:
|
|
||||||
grep "^#found_debug=" configure
|
|
||||||
find $(distdir) -name .svn -type d|xargs rm -Rf
|
|
||||||
|
|
||||||
# Preprocessor flags.
|
|
||||||
CPPFLAGS += @XOPEN_DEFINES@
|
|
||||||
|
|
||||||
# glibc as usual does things ass-backwards and hides useful things by default,
|
|
||||||
# so everyone has to add this.
|
|
||||||
if IS_GLIBC
|
|
||||||
CFLAGS += -D_GNU_SOURCE
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Set flags for gcc. gcc4 whines abouts silly stuff so it needs slightly
|
|
||||||
# different flags.
|
|
||||||
if IS_GCC
|
|
||||||
CFLAGS += -std=c99
|
|
||||||
if IS_DEBUG
|
|
||||||
CFLAGS += -g -ggdb -O0
|
|
||||||
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
|
|
||||||
CPPFLAGS += -DDEBUG
|
|
||||||
endif
|
|
||||||
if IS_GCC4
|
|
||||||
CPPFLAGS += -iquote. -I/usr/local/include
|
|
||||||
if IS_DEBUG
|
|
||||||
CFLAGS += -Wno-pointer-sign
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
CPPFLAGS += -I. -I- -I/usr/local/include
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Set flags for Solaris.
|
|
||||||
if IS_SUNOS
|
|
||||||
CPPFLAGS += -D_XPG4_2 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Set flags for Sun CC.
|
|
||||||
if IS_SUNCC
|
|
||||||
CFLAGS += -erroff=E_EMPTY_DECLARATION
|
|
||||||
endif
|
|
||||||
|
|
||||||
# List of sources.
|
|
||||||
dist_tmux_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 \
|
|
||||||
cmd-delete-buffer.c \
|
|
||||||
cmd-detach-client.c \
|
|
||||||
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 \
|
|
||||||
cmd-list-windows.c \
|
|
||||||
cmd-list.c \
|
|
||||||
cmd-load-buffer.c \
|
|
||||||
cmd-lock-server.c \
|
|
||||||
cmd-move-window.c \
|
|
||||||
cmd-new-session.c \
|
|
||||||
cmd-new-window.c \
|
|
||||||
cmd-paste-buffer.c \
|
|
||||||
cmd-pipe-pane.c \
|
|
||||||
cmd-refresh-client.c \
|
|
||||||
cmd-rename-session.c \
|
|
||||||
cmd-rename-window.c \
|
|
||||||
cmd-resize-pane.c \
|
|
||||||
cmd-respawn-pane.c \
|
|
||||||
cmd-respawn-window.c \
|
|
||||||
cmd-rotate-window.c \
|
|
||||||
cmd-run-shell.c \
|
|
||||||
cmd-save-buffer.c \
|
|
||||||
cmd-select-layout.c \
|
|
||||||
cmd-select-pane.c \
|
|
||||||
cmd-select-window.c \
|
|
||||||
cmd-send-keys.c \
|
|
||||||
cmd-send-prefix.c \
|
|
||||||
cmd-server-info.c \
|
|
||||||
cmd-set-buffer.c \
|
|
||||||
cmd-set-environment.c \
|
|
||||||
cmd-set-option.c \
|
|
||||||
cmd-show-buffer.c \
|
|
||||||
cmd-show-environment.c \
|
|
||||||
cmd-show-messages.c \
|
|
||||||
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.c \
|
|
||||||
colour.c \
|
|
||||||
control.c \
|
|
||||||
control-notify.c \
|
|
||||||
environ.c \
|
|
||||||
format.c \
|
|
||||||
grid-utf8.c \
|
|
||||||
grid-view.c \
|
|
||||||
grid.c \
|
|
||||||
input-keys.c \
|
|
||||||
input.c \
|
|
||||||
job.c \
|
|
||||||
key-bindings.c \
|
|
||||||
key-string.c \
|
|
||||||
layout-custom.c \
|
|
||||||
layout-set.c \
|
|
||||||
layout.c \
|
|
||||||
log.c \
|
|
||||||
mode-key.c \
|
|
||||||
names.c \
|
|
||||||
notify.c \
|
|
||||||
options-table.c \
|
|
||||||
options.c \
|
|
||||||
paste.c \
|
|
||||||
resize.c \
|
|
||||||
screen-redraw.c \
|
|
||||||
screen-write.c \
|
|
||||||
screen.c \
|
|
||||||
server-client.c \
|
|
||||||
server-fn.c \
|
|
||||||
server-window.c \
|
|
||||||
server.c \
|
|
||||||
session.c \
|
|
||||||
signal.c \
|
|
||||||
status.c \
|
|
||||||
tmux.c \
|
|
||||||
tty-acs.c \
|
|
||||||
tty-keys.c \
|
|
||||||
tty-term.c \
|
|
||||||
tty.c \
|
|
||||||
utf8.c \
|
|
||||||
window-choose.c \
|
|
||||||
window-clock.c \
|
|
||||||
window-copy.c \
|
|
||||||
window.c \
|
|
||||||
xmalloc.c \
|
|
||||||
xterm-keys.c
|
|
||||||
nodist_tmux_SOURCES = osdep-@PLATFORM@.c
|
|
||||||
|
|
||||||
# Pile in all the compat/ stuff that is needed.
|
|
||||||
if NO_FORKPTY
|
|
||||||
nodist_tmux_SOURCES += compat/forkpty-@PLATFORM@.c
|
|
||||||
endif
|
|
||||||
if NO_IMSG
|
|
||||||
nodist_tmux_SOURCES += compat/imsg.c compat/imsg-buffer.c
|
|
||||||
endif
|
|
||||||
if NO_CLOSEFROM
|
|
||||||
nodist_tmux_SOURCES += compat/closefrom.c
|
|
||||||
endif
|
|
||||||
if NO_DAEMON
|
|
||||||
nodist_tmux_SOURCES += compat/daemon.c
|
|
||||||
endif
|
|
||||||
if NO_SETENV
|
|
||||||
nodist_tmux_SOURCES += compat/setenv.c
|
|
||||||
endif
|
|
||||||
if NO_STRLCAT
|
|
||||||
nodist_tmux_SOURCES += compat/strlcat.c
|
|
||||||
endif
|
|
||||||
if NO_STRLCPY
|
|
||||||
nodist_tmux_SOURCES += compat/strlcpy.c
|
|
||||||
endif
|
|
||||||
if NO_ASPRINTF
|
|
||||||
nodist_tmux_SOURCES += compat/asprintf.c
|
|
||||||
endif
|
|
||||||
if NO_FGETLN
|
|
||||||
nodist_tmux_SOURCES += compat/fgetln.c
|
|
||||||
endif
|
|
||||||
if NO_GETOPT
|
|
||||||
nodist_tmux_SOURCES += compat/getopt.c
|
|
||||||
endif
|
|
||||||
if NO_STRCASESTR
|
|
||||||
nodist_tmux_SOURCES += compat/strcasestr.c
|
|
||||||
endif
|
|
||||||
if NO_STRSEP
|
|
||||||
nodist_tmux_SOURCES += compat/strsep.c
|
|
||||||
endif
|
|
||||||
if NO_VIS
|
|
||||||
nodist_tmux_SOURCES += compat/vis.c compat/unvis.c
|
|
||||||
endif
|
|
||||||
if NO_STRTONUM
|
|
||||||
nodist_tmux_SOURCES += compat/strtonum.c
|
|
||||||
endif
|
|
||||||
if NO_B64_NTOP
|
|
||||||
nodist_tmux_SOURCES += compat/b64_ntop.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
# 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-*
|
|
||||||
|
|
||||||
update-index.html:
|
|
||||||
(cd www/images && \
|
|
||||||
rm -f small-* && \
|
|
||||||
for i in *.png; do \
|
|
||||||
convert "$$i" -resize 200x150 "small-$$i"; \
|
|
||||||
done \
|
|
||||||
)
|
|
||||||
sed "s/%%VERSION%%/${VERSION}/g" www/index.html.in >www/index.html
|
|
||||||
56
NOTES
56
NOTES
@@ -5,68 +5,62 @@ 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.
|
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
|
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).
|
run on Solaris and AIX (although they haven't been tested in a while). It is
|
||||||
|
usable, although there remain a number of missing features and some remaining
|
||||||
|
bugs are expected.
|
||||||
|
|
||||||
Since the 1.2 release tmux depends on libevent. Download it from:
|
Since the 1.2 release that tmux depends on libevent. Download the stable
|
||||||
|
version from:
|
||||||
|
|
||||||
http://www.monkey.org/~provos/libevent/
|
http://www.monkey.org/~provos/libevent/
|
||||||
|
|
||||||
To build tmux from a release tarball, do:
|
tmux consists of a server part and multiple clients. The server is created when
|
||||||
|
required and runs continuously unless killed by the user. Clients access the
|
||||||
|
server through a socket in /tmp. Multiple sessions may be created on a single
|
||||||
|
server and attached to a number of clients. Each session may then have a number
|
||||||
|
of windows and windows may be linked to a number of sessions. Commands are
|
||||||
|
available to create, rename and destroy windows and sessions; to attach and
|
||||||
|
detach sessions from client terminals; to set configuration options; to split
|
||||||
|
windows into several simultaneously displayed panes; and to bind and unbind
|
||||||
|
command keys (invoked preceded by a prefix key, by default ctrl-b). Please see
|
||||||
|
the tmux(1) man page for further information.
|
||||||
|
|
||||||
$ ./configure && make
|
A more extensive, but rough, todo list is included in the TODO file.
|
||||||
$ sudo make install
|
|
||||||
|
|
||||||
To get and build the latest version control checkout:
|
tmux also depends on several features of the client terminal (TERM), if these
|
||||||
|
are missing it may refuse to run, or not behave correctly.
|
||||||
$ git clone git://tmux.git.sourceforge.net/gitroot/tmux/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.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
A Vim syntax file is available in the examples directory. To install it:
|
A Vim syntax file is available in the examples directory. To install it:
|
||||||
|
|
||||||
- Drop the file in the syntax directory into runtimepath (such as
|
- Drop the file in the syntax directory in your runtimepath (such as
|
||||||
~/.vim/syntax/tmux.vim).
|
~/.vim/syntax/tmux.vim).
|
||||||
- Make the filetype recognisable by adding the following to filetype.vim
|
- Make the filetype recognisable by adding the following to filetype.vim
|
||||||
(~/.vim/filetype.vim):
|
in your runtimepath (~/.vim/filetype.vim):
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
|
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
- Switch on syntax highlighting by adding "syntax enable" to .vimrc.
|
- Switch on syntax highlighting by adding "syntax enable" to your vimrc file.
|
||||||
|
|
||||||
For debugging, running tmux with -v or -vv will generate server and client log
|
For debugging, running tmux with -v or -vv will generate server and client log
|
||||||
files in the current directory.
|
files in the current directory.
|
||||||
|
|
||||||
tmux mailing lists are available. The visit:
|
tmux mailing lists are available; visit:
|
||||||
|
|
||||||
https://sourceforge.net/mail/?group_id=200378
|
https://sourceforge.net/mail/?group_id=200378
|
||||||
|
|
||||||
Bug reports, feature suggestions and especially code contributions are most
|
Bug reports, feature suggestions and especially code contributions are most
|
||||||
welcome. Please send by email to:
|
welcome. Please send by email to:
|
||||||
|
|
||||||
tmux-users@lists.sourceforge.net
|
nicm@users.sf.net
|
||||||
|
|
||||||
This file and the CHANGES, FAQ and TODO files are licensed under the ISC
|
This file and the CHANGES, FAQ and TODO files are licensed under the ISC
|
||||||
license. Files under examples/ remain copyright their authors unless otherwise
|
license. Files under examples/ remain copyright their authors unless otherwise
|
||||||
stated in the file but permission has been received to distribute them with
|
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
|
tmux. All other files have a license and copyright notice at their
|
||||||
start.
|
start. Please contact me with any queries.
|
||||||
|
|
||||||
-- Nicholas Marriott <nicm@users.sf.net>
|
-- Nicholas Marriott <nicm@users.sf.net>
|
||||||
|
|
||||||
$Id$
|
$Id: NOTES,v 1.54 2010-12-27 21:36:37 tcunha Exp $
|
||||||
|
|||||||
173
SYNCING
173
SYNCING
@@ -1,173 +0,0 @@
|
|||||||
Preamble
|
|
||||||
========
|
|
||||||
|
|
||||||
Tmux on SourceForge has two git repositories [1] "tmux" and "tmux-openbsd".
|
|
||||||
Here's a description of them:
|
|
||||||
|
|
||||||
* "tmux" is the portable version, the one which contains code for other
|
|
||||||
operating systems, and autotools, etc., which isn't found or needed in the
|
|
||||||
OpenBSD base system.
|
|
||||||
|
|
||||||
* "tmux-openbsd" is the version of tmux in OpenBSD base system which provides
|
|
||||||
the basis of the portable tmux version.
|
|
||||||
|
|
||||||
Note: The "tmux-openbsd" repository is actually handled by "git cvsimport"
|
|
||||||
running at 15 minute intervals, so a commit made to OpenBSD's tmux CVS
|
|
||||||
repository will take that long to appear in this git repository.
|
|
||||||
|
|
||||||
It is assumed that the person doing the sync has read/write access to the
|
|
||||||
tmux repository on SourceForge already.
|
|
||||||
|
|
||||||
If you've never used git before, git tracks meta-data about the committer
|
|
||||||
and the author, as part of a commit, hence:
|
|
||||||
|
|
||||||
% git config [--global] user.name "Your name"
|
|
||||||
% git config [--global] user.email "you@yourdomain.com"
|
|
||||||
|
|
||||||
Note that, if you already have this in the global ~/.gitconfig option, then
|
|
||||||
this will be used. Setting this per-repository would involve not using the
|
|
||||||
"--global" flag above. If you wish to use the same credentials always,
|
|
||||||
pass the "--global" option, as shown.
|
|
||||||
|
|
||||||
This is a one-off operation once the repository has been cloned, assuming
|
|
||||||
this information has ever been set before.
|
|
||||||
|
|
||||||
Cloning repositories
|
|
||||||
====================
|
|
||||||
|
|
||||||
This involves having both tmux and tmux-openbsd cloned, as in:
|
|
||||||
|
|
||||||
% cd /some/where/useful
|
|
||||||
% git clone ssh://${USER}@tmux.git.sf.net/gitroot/tmux/tmux
|
|
||||||
% git clone ssh://${USER}@tmux.git.sf.net/gitroot/tmux/tmux-openbsd
|
|
||||||
|
|
||||||
Note that you do not need additoinal checkouts to manage the sync -- an
|
|
||||||
existing clone of either repositories will suffice. So if you already have
|
|
||||||
these checkouts existing, skip that.
|
|
||||||
|
|
||||||
Adding in git-remotes
|
|
||||||
=====================
|
|
||||||
|
|
||||||
Because the portable "tmux" git repository and the "tmux-openbsd" repository do
|
|
||||||
not inherently share any history between each other, the history has been
|
|
||||||
faked between them. This "faking of history" is something which has to be
|
|
||||||
told to git for the purposes of comparing the "tmux" and "tmux-openbsd"
|
|
||||||
repositories for syncing. To do this, we must reference the clone of the
|
|
||||||
"tmux-openbsd" repository from the "tmux" repository, as shown by the
|
|
||||||
following command:
|
|
||||||
|
|
||||||
% cd /path/to/tmux
|
|
||||||
% git remote add obsd-tmux file:///path/to/tmux-openbsd
|
|
||||||
|
|
||||||
So that now, the remote "obsd-tmux" can be used to reference branches and
|
|
||||||
commits from the "tmux-openbsd" repository, but from the context of the
|
|
||||||
portable "tmux" repository, which makes sense because it's the "tmux"
|
|
||||||
repository which will have the updates applied to them.
|
|
||||||
|
|
||||||
Fetching updates
|
|
||||||
================
|
|
||||||
|
|
||||||
To ensure the latest commits from "tmux-openbsd" can be found from within
|
|
||||||
"tmux", we have to ensure the "master" branch from "tmux-openbsd" is
|
|
||||||
up-to-date first, and then reference that update in "tmux", as in:
|
|
||||||
|
|
||||||
% cd /path/to/tmux-openbsd
|
|
||||||
% git checkout master
|
|
||||||
% git pull
|
|
||||||
|
|
||||||
Then back in "tmux":
|
|
||||||
|
|
||||||
% cd /path/to/tmux
|
|
||||||
% git fetch obsd-tmux
|
|
||||||
|
|
||||||
Creating the necessary branches
|
|
||||||
===============================
|
|
||||||
|
|
||||||
Now that "tmux" can see commits and branches from "tmux-openbsd" by way of
|
|
||||||
the remote name "obsd-tmux", we can now create the master branch from
|
|
||||||
"tmux-openbsd" in the "tmux" repository:
|
|
||||||
|
|
||||||
% git checkout -b obsd-master obsd-tmux/master
|
|
||||||
|
|
||||||
Adding in the fake history points
|
|
||||||
=================================
|
|
||||||
|
|
||||||
To tie both the "master" branch from "tmux" and the "obsd-master" branch
|
|
||||||
from "tmux-openbsd" together, the fake history points added to the "tmux"
|
|
||||||
repository need to be added. To do this, we must add an additional refspec
|
|
||||||
line, as in:
|
|
||||||
|
|
||||||
% cd /path/to/tmux
|
|
||||||
% git config --add remote.origin.fetch '+refs/replace/*:refs/replace/*'
|
|
||||||
% git fetch origin
|
|
||||||
|
|
||||||
Performing the Sync
|
|
||||||
===================
|
|
||||||
|
|
||||||
Make sure the "master" branch is checked out:
|
|
||||||
|
|
||||||
% git checkout master
|
|
||||||
|
|
||||||
The following will show commits on OpenBSD not yet synched with tmux
|
|
||||||
portable:
|
|
||||||
|
|
||||||
% git log master..obsd-master
|
|
||||||
|
|
||||||
From there, merge the result in, fixing up any conflicts which might arise.
|
|
||||||
|
|
||||||
% git merge obsd-master
|
|
||||||
|
|
||||||
Then ensure things look correct by BULDING the result of that sync:
|
|
||||||
|
|
||||||
% make clean && ./autogen.sh && ./configure && make
|
|
||||||
|
|
||||||
Compare the git merge result with what's on origin/master -- that is, check
|
|
||||||
which commits you're about to push:
|
|
||||||
|
|
||||||
% git log origin/master..master
|
|
||||||
|
|
||||||
And if happy:
|
|
||||||
|
|
||||||
% git push origin master
|
|
||||||
|
|
||||||
Release tmux for next version
|
|
||||||
=============================
|
|
||||||
|
|
||||||
1. Comment the "found_debug=yes" line in configure.ac, since releases
|
|
||||||
don't have debugging enabled, otherwise make(1) aborts when
|
|
||||||
preparing the distribution.
|
|
||||||
|
|
||||||
2. Update and commit NOTES and CHANGES. The former should be checked for
|
|
||||||
anything outdated and updated with a list of things that might break
|
|
||||||
upgrades and the latter should mention all the major changes since
|
|
||||||
the last version.
|
|
||||||
|
|
||||||
3. Tag with:
|
|
||||||
|
|
||||||
% git tag -a 1.X
|
|
||||||
|
|
||||||
Where "1.X" is the next version.
|
|
||||||
|
|
||||||
Push the tag out with:
|
|
||||||
|
|
||||||
% git push --tags
|
|
||||||
|
|
||||||
4. Build the tarball with make dist. Now that it's using autoconf there
|
|
||||||
shouldn't be any weird files (such as the original and rejection files
|
|
||||||
from patch(1)) but it doesn't hurt taking a quick look at it.
|
|
||||||
|
|
||||||
5. Split the release changes into a new file. This should be named
|
|
||||||
tmux-$VERSION-readme to make sourceforge show it automagically in specific
|
|
||||||
parts of the project page.
|
|
||||||
|
|
||||||
6. Upload the tarball and the above file. Make the tarball the default
|
|
||||||
download by selecting all operating systems under the file details.
|
|
||||||
|
|
||||||
7. Run make update-index.html upload-index.html to replace %%VERSION%%.
|
|
||||||
|
|
||||||
8. Bump version in configure.ac and uncomment "found_debug=yes" to create
|
|
||||||
a debug build by default.
|
|
||||||
|
|
||||||
9. Update freshmeat.
|
|
||||||
|
|
||||||
[1] http://tmux.git.sourceforge.net/git/gitweb-index.cgi
|
|
||||||
124
TODO
124
TODO
@@ -1,31 +1,23 @@
|
|||||||
NOTES
|
- better errors when creating new windows/sessions (how?)
|
||||||
=====
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
Thie file is split up between tmux user interface (UI) issues, and terminal
|
|
||||||
compatibility issues.
|
|
||||||
|
|
||||||
TMUX UI ISSUES
|
|
||||||
==============
|
|
||||||
|
|
||||||
- implicitly add exec to the commands for new windows (switch to disable it)?
|
- implicitly add exec to the commands for new windows (switch to disable it)?
|
||||||
- bring back detach-session to detach all clients on a session?
|
- it would be nice to have multichar commands eg C-b K K
|
||||||
|
- commands:
|
||||||
|
extend list-clients to list clients attached to a session (-a for all?)
|
||||||
|
bring back detach-session to detach all clients on a session?
|
||||||
- allow fnmatch for -c, so that you can, eg, detach all clients
|
- 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
|
- garbage collect window history (100 lines at a time?) if it hasn't been used
|
||||||
in $x time
|
in $x time
|
||||||
|
- lift SHRT_MAX limits for history?
|
||||||
- flags to centre screen in window
|
- flags to centre screen in window
|
||||||
- activity/bell should be per-window not per-link? what if it is cur win in
|
- activity/bell should be per-window not per-link? what if it is cur win in
|
||||||
session not being watched?
|
session not being watched?
|
||||||
|
- next prev word etc in command prompt
|
||||||
|
- use a better termcap internally instead of screen, perhaps xterm
|
||||||
- should be able to move to a hidden pane and it would be moved into view. pane
|
- 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
|
number in status line/top-right would be cool for this
|
||||||
- support other mouse modes (highlight etc) and use it in copy mode
|
- 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?
|
- set-remain-on-exit is a bit of a hack, some way to do it generically?
|
||||||
|
- clear window title on exit
|
||||||
- would be nice to be able to use "--" to mark start of command w/ neww etc
|
- would be nice to be able to use "--" to mark start of command w/ neww etc
|
||||||
to avoid quoting
|
to avoid quoting
|
||||||
- make command sequences more usable: don't require space after ;, handle
|
- make command sequences more usable: don't require space after ;, handle
|
||||||
@@ -35,6 +27,7 @@ TMUX UI ISSUES
|
|||||||
- hooks to which commands may be attached, for example: tmux add-hook
|
- hooks to which commands may be attached, for example: tmux add-hook
|
||||||
"new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file
|
"new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file
|
||||||
$HOME/.tmux-session.conf
|
$HOME/.tmux-session.conf
|
||||||
|
- get it passing all the vttest tests that don't require resizing the terminal
|
||||||
- way to set socket path from config file
|
- way to set socket path from config file
|
||||||
- what about utmp etc? can tmux update it like screen? setgid?
|
- what about utmp etc? can tmux update it like screen? setgid?
|
||||||
- warts on current naming:
|
- warts on current naming:
|
||||||
@@ -46,6 +39,7 @@ TMUX UI ISSUES
|
|||||||
- a way for force-width/height to apply to only one pane (how?)
|
- a way for force-width/height to apply to only one pane (how?)
|
||||||
- command to list what is actually running in each window with command line,
|
- command to list what is actually running in each window with command line,
|
||||||
pid (need some adaption of the osdep code)
|
pid (need some adaption of the osdep code)
|
||||||
|
- support for bce
|
||||||
- some way to force a screen to use the entire terminal even if it is forced
|
- 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)
|
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
|
-- idea of a "view" onto a window, need base x/y offsets for redraw
|
||||||
@@ -55,10 +49,16 @@ TMUX UI ISSUES
|
|||||||
lists
|
lists
|
||||||
- some way to KEEP a command running continually and just use its LAST line of
|
- some way to KEEP a command running continually and just use its LAST line of
|
||||||
output
|
output
|
||||||
|
- bind commands to mouse buttons
|
||||||
- UTF-8 to a non-UTF-8 terminal should not be able to balls up
|
- UTF-8 to a non-UTF-8 terminal should not be able to balls up
|
||||||
the terminal - www/ruby-addressable; make regress
|
the terminal - www/ruby-addressable; make regress
|
||||||
|
- multiple keys could be done with tables, ie have prefixes go and instead
|
||||||
|
bind -n ^A prefix-table "default"
|
||||||
|
where prefix-table sets command lookup table and sets prefix flag, then next
|
||||||
|
key is looked up in that table
|
||||||
- support esc-esc to quit in modes
|
- support esc-esc to quit in modes
|
||||||
- fix ctrl+F1-F4 output. to what?
|
- fix ctrl+F1-F4 output. to what?
|
||||||
|
- look into xterm clearing its selection when scrolling etc
|
||||||
- better utf8 support: window names, prompt input, message display
|
- better utf8 support: window names, prompt input, message display
|
||||||
- session history for client and last-session command
|
- session history for client and last-session command
|
||||||
- option to change status line colour when current window is in a mode?
|
- option to change status line colour when current window is in a mode?
|
||||||
@@ -67,21 +67,30 @@ TMUX UI ISSUES
|
|||||||
- selection behaviour closer to vi in vi mode
|
- selection behaviour closer to vi in vi mode
|
||||||
- live update: server started with -U connects to server, requests sessions and
|
- live update: server started with -U connects to server, requests sessions and
|
||||||
windows, receives fds
|
windows, receives fds
|
||||||
|
- command to show a tree of sessions-windows-panes (active marked with *)
|
||||||
- sort out inheriting config from shell on new sessions/windows:
|
- sort out inheriting config from shell on new sessions/windows:
|
||||||
should pick up default-path/termios/etc from client if possible,
|
should pick up default-path/termios/etc from client if possible,
|
||||||
else leave empty/default
|
else leave empty/default
|
||||||
- link panes into multiple windows
|
- link panes into multiple windows
|
||||||
|
- -h option to capture-pane to capture the history as well
|
||||||
- bells should be passed between sessions with visual-bell etc
|
- bells should be passed between sessions with visual-bell etc
|
||||||
|
- use screen-256color when started on 256 colour terminal??
|
||||||
|
- if-shell/run-shell should block further command execution in the same command
|
||||||
sequence until its shell exits, to allow them to be used from the config file
|
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
|
- better session sharing: create-socket command to create socket somewhere (-r
|
||||||
flag for readonly)
|
flag for readonly)
|
||||||
|
- allow buffer to be specified when copying in copy mode
|
||||||
- multiline status line (no?)
|
- multiline status line (no?)
|
||||||
- flag for absolute pane size to resize-pane
|
- flag for absolute pane size to resize-pane
|
||||||
- sanity check input to socket
|
- sanity check input to socket
|
||||||
|
- select-buffer command
|
||||||
- support title stack, both internally and externally
|
- support title stack, both internally and externally
|
||||||
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=1149299+0+archive/2010/freebsd-questions/20100207.freebsd-questions
|
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=1149299+0+archive/2010/freebsd-questions/20100207.freebsd-questions
|
||||||
|
- copy buffers should be global, limit can be server option, nuke copy-buffer
|
||||||
|
command
|
||||||
- command to show status line information briefly when it is off
|
- command to show status line information briefly when it is off
|
||||||
- some way to pad # stuff with spaces, #!2T maybe
|
- some way to pad # stuff with spaces, #!2T maybe
|
||||||
|
- FreeBSD console problems
|
||||||
- a binding to "scroll down and exit at bottom" copy mode
|
- a binding to "scroll down and exit at bottom" copy mode
|
||||||
- some way to pass keystrokes in copy mode through to underlying window
|
- some way to pass keystrokes in copy mode through to underlying window
|
||||||
- last window update time and # replacement for it for display-message
|
- last window update time and # replacement for it for display-message
|
||||||
@@ -89,6 +98,7 @@ TMUX UI ISSUES
|
|||||||
- ' and " should be parsed the same (eg "\e" vs '\e') in config and command
|
- ' and " should be parsed the same (eg "\e" vs '\e') in config and command
|
||||||
prompt?
|
prompt?
|
||||||
- command to toggle selection not to move it in copy-mode
|
- command to toggle selection not to move it in copy-mode
|
||||||
|
- why are alerts per-winlink? try per window?
|
||||||
- audit of escape sequence support vs xterm
|
- audit of escape sequence support vs xterm
|
||||||
- support binding keys to mouse (mouse-select-pane -> mouse-keys or something,
|
- support binding keys to mouse (mouse-select-pane -> mouse-keys or something,
|
||||||
mouse click == select-pane -t %%, mouse scroll up == copy-mode)
|
mouse click == select-pane -t %%, mouse scroll up == copy-mode)
|
||||||
@@ -96,75 +106,25 @@ TMUX UI ISSUES
|
|||||||
- synchronous commands - client sends cmd and blocks, neww/splitw saves client
|
- synchronous commands - client sends cmd and blocks, neww/splitw saves client
|
||||||
ptr then when program inside died, sends MSG_SOMETHING with wait status to
|
ptr then when program inside died, sends MSG_SOMETHING with wait status to
|
||||||
client
|
client
|
||||||
- bind commands to key sequences? -- make it so ALL keys go through a table,
|
- documentation improvements - rlpowell's tutorial - build instructions
|
||||||
first an implicit table in which C-b is the only default binding to a
|
- better configure? with-libevent
|
||||||
command that says "next key from $othertable" and so on. means -n can
|
- bind commands to key sequences?
|
||||||
go away as well
|
|
||||||
- monitor, bell etc should monitor /all/ panes in the window not just one
|
- 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,
|
- a history of commands that can be reversed (reverse member of each command,
|
||||||
and a buffer) info() when changing to same window
|
and a buffer) info() when changing to same window
|
||||||
|
- don't pass UTF-8 through vis for titles
|
||||||
|
- clearing screen should push lines into history
|
||||||
|
- add a unique ever-increasing pane id to each pane, export it in $TMUX_PANE
|
||||||
|
(as %1, %2 etc) and allow it to be used as a target
|
||||||
- way to add dest for break-pane; maybe some easier way to unbreak-pane
|
- way to add dest for break-pane; maybe some easier way to unbreak-pane
|
||||||
- case insensitive searching
|
- case insensitive searching
|
||||||
|
- dynamically generated jobs (eg "date ...") do not work well because
|
||||||
|
their entries are never collected, should either store status jobs in
|
||||||
|
a different tree or flush all unused persist jobs every update rather
|
||||||
|
than just updating them
|
||||||
|
- pane-index option like base-index
|
||||||
|
- option to move status line to top
|
||||||
|
- support "xterm2" mouse mode
|
||||||
|
- respawn-pane command
|
||||||
- configurable borders and empty space filler for when panes < window?
|
- 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)
|
|
||||||
- multiple keys could be done with tables, ie have prefixes go and instead
|
|
||||||
bind -n ^A prefix-table "default"
|
|
||||||
where prefix-table sets command lookup table and sets prefix flag, then next
|
|
||||||
key is looked up in that table
|
|
||||||
- pass shell commands as argv rather than strings, allow them to be specified
|
|
||||||
in commands without quotes
|
|
||||||
- numeric prefix in copy mode should be paste buffer for C-w
|
|
||||||
- named buffers and allow gaps in the stack
|
|
||||||
- get rid of separate UTF-8 cell stuff: add 1 byte to cell and store BMP as
|
|
||||||
uint16_t+3 bits of flags. anything <=0xffff is Unicode, higher are used to
|
|
||||||
build tree of combined characters/non-BMP (LRU dropped when full)
|
|
||||||
- entry in FAQ about what to do when someone does mkdir /tmp/tmux-1000
|
|
||||||
- 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
|
|
||||||
- run-shell/if-shell should support status_replace stuff
|
|
||||||
- wait-pane command or another way to make it synchronous/wait for command to
|
|
||||||
finish
|
|
||||||
- last-pane across sessions
|
|
||||||
- attach should take a pane and select it as well as attaching
|
|
||||||
- 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 certaing 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? TA to investigate.
|
|
||||||
- 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.
|
|
||||||
|
|
||||||
TERMINAL ISSUES
|
|
||||||
================
|
|
||||||
|
|
||||||
- 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??
|
|
||||||
- if-shell/run-shell should block further command execution in the same command
|
|
||||||
- possibly support rxvt-unicode extended mouse input (1015)
|
|
||||||
- wrap/no wrap esc seq DEC CSI ? 7 h/l
|
|
||||||
* 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!
|
|
||||||
|
|||||||
218
arguments.c
218
arguments.c
@@ -1,218 +0,0 @@
|
|||||||
/* $Id$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2010 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"
|
|
||||||
|
|
||||||
/* Create an arguments set with no flags. */
|
|
||||||
struct args *
|
|
||||||
args_create(int argc, ...)
|
|
||||||
{
|
|
||||||
struct args *args;
|
|
||||||
va_list ap;
|
|
||||||
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)
|
|
||||||
args->argv = NULL;
|
|
||||||
else
|
|
||||||
args->argv = xcalloc(argc, sizeof *args->argv);
|
|
||||||
|
|
||||||
va_start(ap, argc);
|
|
||||||
for (i = 0; i < argc; i++)
|
|
||||||
args->argv[i] = xstrdup(va_arg(ap, char *));
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
return (args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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 || opt >= SCHAR_MAX)
|
|
||||||
continue;
|
|
||||||
if (opt == '?' || (ptr = strchr(template, opt)) == NULL) {
|
|
||||||
free(args->flags);
|
|
||||||
free(args);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
bit_set(args->flags, opt);
|
|
||||||
if (ptr[1] == ':') {
|
|
||||||
free(args->values[opt]);
|
|
||||||
args->values[opt] = xstrdup(optarg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
argc -= optind;
|
|
||||||
argv += optind;
|
|
||||||
|
|
||||||
args->argc = argc;
|
|
||||||
args->argv = cmd_copy_argv(argc, argv);
|
|
||||||
|
|
||||||
return (args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Free an arguments set. */
|
|
||||||
void
|
|
||||||
args_free(struct args *args)
|
|
||||||
{
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
cmd_free_argv(args->argc, args->argv);
|
|
||||||
|
|
||||||
for (i = 0; i < SCHAR_MAX; i++)
|
|
||||||
free(args->values[i]);
|
|
||||||
|
|
||||||
free(args->flags);
|
|
||||||
free(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print a set of arguments. */
|
|
||||||
size_t
|
|
||||||
args_print(struct args *args, char *buf, size_t len)
|
|
||||||
{
|
|
||||||
size_t off;
|
|
||||||
int i;
|
|
||||||
const char *quotes;
|
|
||||||
|
|
||||||
/* There must be at least one byte at the start. */
|
|
||||||
if (len == 0)
|
|
||||||
return (0);
|
|
||||||
off = 0;
|
|
||||||
|
|
||||||
/* Process the flags first. */
|
|
||||||
buf[off++] = '-';
|
|
||||||
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++] = i;
|
|
||||||
buf[off] = '\0';
|
|
||||||
}
|
|
||||||
if (off == 1)
|
|
||||||
buf[--off] = '\0';
|
|
||||||
|
|
||||||
/* Then the flags with arguments. */
|
|
||||||
for (i = 0; i < SCHAR_MAX; i++) {
|
|
||||||
if (!bit_test(args->flags, i) || args->values[i] == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (off >= len) {
|
|
||||||
/* snprintf will have zero terminated. */
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strchr(args->values[i], ' ') != NULL)
|
|
||||||
quotes = "\"";
|
|
||||||
else
|
|
||||||
quotes = "";
|
|
||||||
off += xsnprintf(buf + off, len - off, "%s-%c %s%s%s",
|
|
||||||
off != 0 ? " " : "", i, quotes, args->values[i], quotes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* And finally the argument vector. */
|
|
||||||
for (i = 0; i < args->argc; i++) {
|
|
||||||
if (off >= len) {
|
|
||||||
/* snprintf will have zero terminated. */
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strchr(args->argv[i], ' ') != NULL)
|
|
||||||
quotes = "\"";
|
|
||||||
else
|
|
||||||
quotes = "";
|
|
||||||
off += xsnprintf(buf + off, len - off, "%s%s%s%s",
|
|
||||||
off != 0 ? " " : "", quotes, args->argv[i], quotes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (off);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return if an argument is present. */
|
|
||||||
int
|
|
||||||
args_has(struct args *args, u_char ch)
|
|
||||||
{
|
|
||||||
return (bit_test(args->flags, ch));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set argument value. */
|
|
||||||
void
|
|
||||||
args_set(struct args *args, u_char ch, const char *value)
|
|
||||||
{
|
|
||||||
free(args->values[ch]);
|
|
||||||
if (value != NULL)
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
const char *errstr;
|
|
||||||
long long ll;
|
|
||||||
|
|
||||||
if (!args_has(args, ch)) {
|
|
||||||
*cause = xstrdup("missing");
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ll = strtonum(args->values[ch], minval, maxval, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
*cause = xstrdup(errstr);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
*cause = NULL;
|
|
||||||
return (ll);
|
|
||||||
}
|
|
||||||
7
array.h
7
array.h
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: array.h,v 1.11 2010-06-06 00:27:08 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -109,12 +109,13 @@
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ARRAY_FREE(a) do { \
|
#define ARRAY_FREE(a) do { \
|
||||||
free((a)->list); \
|
if ((a)->list != NULL) \
|
||||||
|
xfree((a)->list); \
|
||||||
ARRAY_INIT(a); \
|
ARRAY_INIT(a); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define ARRAY_FREEALL(a) do { \
|
#define ARRAY_FREEALL(a) do { \
|
||||||
ARRAY_FREE(a); \
|
ARRAY_FREE(a); \
|
||||||
free(a); \
|
xfree(a); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
30
attributes.c
30
attributes.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: attributes.c,v 1.4 2010-06-05 23:54:51 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
||||||
@@ -26,21 +26,27 @@ const char *
|
|||||||
attributes_tostring(u_char attr)
|
attributes_tostring(u_char attr)
|
||||||
{
|
{
|
||||||
static char buf[128];
|
static char buf[128];
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (attr == 0)
|
if (attr == 0)
|
||||||
return ("none");
|
return ("none");
|
||||||
|
|
||||||
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s",
|
buf[0] = '\0';
|
||||||
attr & GRID_ATTR_BRIGHT ? "bright," : "",
|
if (attr & GRID_ATTR_BRIGHT)
|
||||||
attr & GRID_ATTR_DIM ? "dim," : "",
|
strlcat(buf, "bright,", sizeof (buf));
|
||||||
attr & GRID_ATTR_UNDERSCORE ? "underscore," : "",
|
if (attr & GRID_ATTR_DIM)
|
||||||
attr & GRID_ATTR_BLINK ? "blink," : "",
|
strlcat(buf, "dim,", sizeof (buf));
|
||||||
attr & GRID_ATTR_REVERSE ? "reverse," : "",
|
if (attr & GRID_ATTR_UNDERSCORE)
|
||||||
attr & GRID_ATTR_HIDDEN ? "hidden," : "",
|
strlcat(buf, "underscore,", sizeof (buf));
|
||||||
attr & GRID_ATTR_ITALICS ? "italics," : "");
|
if (attr & GRID_ATTR_BLINK)
|
||||||
if (len > 0)
|
strlcat(buf, "blink,", sizeof (buf));
|
||||||
buf[len - 1] = '\0';
|
if (attr & GRID_ATTR_REVERSE)
|
||||||
|
strlcat(buf, "reverse,", sizeof (buf));
|
||||||
|
if (attr & GRID_ATTR_HIDDEN)
|
||||||
|
strlcat(buf, "hidden,", sizeof (buf));
|
||||||
|
if (attr & GRID_ATTR_ITALICS)
|
||||||
|
strlcat(buf, "italics,", sizeof (buf));
|
||||||
|
if (*buf != '\0')
|
||||||
|
*(strrchr(buf, ',')) = '\0';
|
||||||
|
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|||||||
16
autogen.sh
16
autogen.sh
@@ -1,16 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# $Id$
|
|
||||||
|
|
||||||
[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.10
|
|
||||||
[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.65
|
|
||||||
|
|
||||||
die()
|
|
||||||
{
|
|
||||||
echo "$@" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
mkdir -p etc
|
|
||||||
aclocal || die "aclocal failed"
|
|
||||||
automake --add-missing --force-missing --copy --foreign || die "automake failed"
|
|
||||||
autoreconf || die "autoreconf failed"
|
|
||||||
66
cfg.c
66
cfg.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cfg.c,v 1.27 2010-06-06 00:04:18 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -81,7 +80,6 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
|||||||
size_t len;
|
size_t len;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
struct cmd_ctx ctx;
|
struct cmd_ctx ctx;
|
||||||
enum cmd_retval retval;
|
|
||||||
|
|
||||||
if ((f = fopen(path, "rb")) == NULL) {
|
if ((f = fopen(path, "rb")) == NULL) {
|
||||||
cfg_add_cause(causes, "%s: %s", path, strerror(errno));
|
cfg_add_cause(causes, "%s: %s", path, strerror(errno));
|
||||||
@@ -90,42 +88,24 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
|||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
line = NULL;
|
line = NULL;
|
||||||
retval = CMD_RETURN_NORMAL;
|
|
||||||
while ((buf = fgetln(f, &len))) {
|
while ((buf = fgetln(f, &len))) {
|
||||||
if (buf[len - 1] == '\n')
|
if (buf[len - 1] == '\n')
|
||||||
len--;
|
buf[len - 1] = '\0';
|
||||||
|
|
||||||
if (line != NULL)
|
|
||||||
line = xrealloc(line, 1, strlen(line) + len + 1);
|
|
||||||
else {
|
else {
|
||||||
line = xmalloc(len + 1);
|
line = xrealloc(line, 1, len + 1);
|
||||||
*line = '\0';
|
memcpy(line, buf, len);
|
||||||
|
line[len] = '\0';
|
||||||
|
buf = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append buffer to line. strncat will terminate. */
|
|
||||||
strncat(line, buf, len);
|
|
||||||
n++;
|
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;
|
|
||||||
}
|
|
||||||
buf = line;
|
|
||||||
line = NULL;
|
|
||||||
|
|
||||||
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
|
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
|
||||||
free(buf);
|
|
||||||
if (cause == NULL)
|
if (cause == NULL)
|
||||||
continue;
|
continue;
|
||||||
cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
|
cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
continue;
|
continue;
|
||||||
} else
|
}
|
||||||
free(buf);
|
|
||||||
if (cmdlist == NULL)
|
if (cmdlist == NULL)
|
||||||
continue;
|
continue;
|
||||||
cfg_cause = NULL;
|
cfg_cause = NULL;
|
||||||
@@ -145,31 +125,19 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
|||||||
ctx.info = cfg_print;
|
ctx.info = cfg_print;
|
||||||
|
|
||||||
cfg_cause = NULL;
|
cfg_cause = NULL;
|
||||||
switch (cmd_list_exec(cmdlist, &ctx)) {
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
case CMD_RETURN_YIELD:
|
|
||||||
if (retval != CMD_RETURN_ATTACH)
|
|
||||||
retval = CMD_RETURN_YIELD;
|
|
||||||
break;
|
|
||||||
case CMD_RETURN_ATTACH:
|
|
||||||
retval = CMD_RETURN_ATTACH;
|
|
||||||
break;
|
|
||||||
case CMD_RETURN_ERROR:
|
|
||||||
case CMD_RETURN_NORMAL:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cmd_list_free(cmdlist);
|
cmd_list_free(cmdlist);
|
||||||
if (cfg_cause != NULL) {
|
if (cfg_cause != NULL) {
|
||||||
cfg_add_cause(
|
cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
|
||||||
causes, "%s: %d: %s", path, n, cfg_cause);
|
xfree(cfg_cause);
|
||||||
free(cfg_cause);
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (line != NULL) {
|
if (line != NULL)
|
||||||
cfg_add_cause(causes,
|
xfree(line);
|
||||||
"%s: %d: line continuation at end of file", path, n);
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
return (retval);
|
if (ARRAY_LENGTH(causes) != 0)
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
257
client.c
257
client.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: client.c,v 1.100 2010-10-24 19:54:41 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/file.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
@@ -35,58 +34,19 @@
|
|||||||
|
|
||||||
struct imsgbuf client_ibuf;
|
struct imsgbuf client_ibuf;
|
||||||
struct event client_event;
|
struct event client_event;
|
||||||
struct event client_stdin;
|
const char *client_exitmsg;
|
||||||
enum {
|
|
||||||
CLIENT_EXIT_NONE,
|
|
||||||
CLIENT_EXIT_DETACHED,
|
|
||||||
CLIENT_EXIT_DETACHED_HUP,
|
|
||||||
CLIENT_EXIT_LOST_TTY,
|
|
||||||
CLIENT_EXIT_TERMINATED,
|
|
||||||
CLIENT_EXIT_LOST_SERVER,
|
|
||||||
CLIENT_EXIT_EXITED,
|
|
||||||
CLIENT_EXIT_SERVER_EXITED,
|
|
||||||
} client_exitreason = CLIENT_EXIT_NONE;
|
|
||||||
int client_exitval;
|
int client_exitval;
|
||||||
enum msgtype client_exittype;
|
|
||||||
int client_attached;
|
int client_attached;
|
||||||
|
|
||||||
int client_get_lock(char *);
|
|
||||||
int client_connect(char *, int);
|
int client_connect(char *, int);
|
||||||
void client_send_identify(int);
|
void client_send_identify(int);
|
||||||
void client_send_environ(void);
|
void client_send_environ(void);
|
||||||
void client_write_server(enum msgtype, void *, size_t);
|
void client_write_server(enum msgtype, void *, size_t);
|
||||||
void client_update_event(void);
|
void client_update_event(void);
|
||||||
void client_signal(int, short, void *);
|
void client_signal(int, short, void *);
|
||||||
void client_stdin_callback(int, short, void *);
|
|
||||||
void client_write(int, const char *, size_t);
|
|
||||||
void client_callback(int, short, void *);
|
void client_callback(int, short, void *);
|
||||||
int client_dispatch_attached(void);
|
int client_dispatch_attached(void);
|
||||||
int client_dispatch_wait(void *);
|
int client_dispatch_wait(void *);
|
||||||
const char *client_exit_message(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get server create lock. If already held then server start is happening in
|
|
||||||
* another client, so block until the lock is released and return -1 to
|
|
||||||
* retry. Ignore other errors - just continue and start the server without the
|
|
||||||
* lock.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
client_get_lock(char *lockfile)
|
|
||||||
{
|
|
||||||
int lockfd;
|
|
||||||
|
|
||||||
if ((lockfd = open(lockfile, O_WRONLY|O_CREAT, 0600)) == -1)
|
|
||||||
fatal("open failed");
|
|
||||||
|
|
||||||
if (flock(lockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) {
|
|
||||||
while (flock(lockfd, LOCK_EX) == -1 && errno == EINTR)
|
|
||||||
/* nothing */;
|
|
||||||
close(lockfd);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (lockfd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Connect client to server. */
|
/* Connect client to server. */
|
||||||
int
|
int
|
||||||
@@ -94,8 +54,7 @@ client_connect(char *path, int start_server)
|
|||||||
{
|
{
|
||||||
struct sockaddr_un sa;
|
struct sockaddr_un sa;
|
||||||
size_t size;
|
size_t size;
|
||||||
int fd, lockfd;
|
int fd, mode;
|
||||||
char *lockfile;
|
|
||||||
|
|
||||||
memset(&sa, 0, sizeof sa);
|
memset(&sa, 0, sizeof sa);
|
||||||
sa.sun_family = AF_UNIX;
|
sa.sun_family = AF_UNIX;
|
||||||
@@ -105,28 +64,30 @@ client_connect(char *path, int start_server)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
retry:
|
|
||||||
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||||
fatal("socket failed");
|
fatal("socket failed");
|
||||||
|
|
||||||
if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
|
if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
|
||||||
if (errno != ECONNREFUSED && errno != ENOENT)
|
|
||||||
goto failed;
|
|
||||||
if (!start_server)
|
if (!start_server)
|
||||||
goto failed;
|
goto failed;
|
||||||
close(fd);
|
switch (errno) {
|
||||||
|
case ECONNREFUSED:
|
||||||
xasprintf(&lockfile, "%s.lock", path);
|
if (unlink(path) != 0)
|
||||||
if ((lockfd = client_get_lock(lockfile)) == -1)
|
goto failed;
|
||||||
goto retry;
|
/* FALLTHROUGH */
|
||||||
if (unlink(path) != 0 && errno != ENOENT)
|
case ENOENT:
|
||||||
return (-1);
|
if ((fd = server_start()) == -1)
|
||||||
fd = server_start(lockfd, lockfile);
|
goto failed;
|
||||||
free(lockfile);
|
break;
|
||||||
close(lockfd);
|
default:
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setblocking(fd, 0);
|
if ((mode = fcntl(fd, F_GETFL)) == -1)
|
||||||
|
fatal("fcntl failed");
|
||||||
|
if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||||
|
fatal("fcntl failed");
|
||||||
return (fd);
|
return (fd);
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
@@ -134,31 +95,6 @@ failed:
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get exit string from reason number. */
|
|
||||||
const char *
|
|
||||||
client_exit_message(void)
|
|
||||||
{
|
|
||||||
switch (client_exitreason) {
|
|
||||||
case CLIENT_EXIT_NONE:
|
|
||||||
break;
|
|
||||||
case CLIENT_EXIT_DETACHED:
|
|
||||||
return ("detached");
|
|
||||||
case CLIENT_EXIT_DETACHED_HUP:
|
|
||||||
return ("detached and SIGHUP");
|
|
||||||
case CLIENT_EXIT_LOST_TTY:
|
|
||||||
return ("lost tty");
|
|
||||||
case CLIENT_EXIT_TERMINATED:
|
|
||||||
return ("terminated");
|
|
||||||
case CLIENT_EXIT_LOST_SERVER:
|
|
||||||
return ("lost server");
|
|
||||||
case CLIENT_EXIT_EXITED:
|
|
||||||
return ("exited");
|
|
||||||
case CLIENT_EXIT_SERVER_EXITED:
|
|
||||||
return ("server exited");
|
|
||||||
}
|
|
||||||
return ("unknown reason");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Client main loop. */
|
/* Client main loop. */
|
||||||
int
|
int
|
||||||
client_main(int argc, char **argv, int flags)
|
client_main(int argc, char **argv, int flags)
|
||||||
@@ -167,10 +103,8 @@ client_main(int argc, char **argv, int flags)
|
|||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
struct msg_command_data cmddata;
|
struct msg_command_data cmddata;
|
||||||
int cmdflags, fd;
|
int cmdflags, fd;
|
||||||
pid_t ppid;
|
|
||||||
enum msgtype msg;
|
enum msgtype msg;
|
||||||
char *cause;
|
char *cause;
|
||||||
struct termios tio, saved_tio;
|
|
||||||
|
|
||||||
/* Set up the initial command. */
|
/* Set up the initial command. */
|
||||||
cmdflags = 0;
|
cmdflags = 0;
|
||||||
@@ -189,7 +123,7 @@ client_main(int argc, char **argv, int flags)
|
|||||||
* flag.
|
* flag.
|
||||||
*/
|
*/
|
||||||
if ((cmdlist = cmd_list_parse(argc, argv, &cause)) == NULL) {
|
if ((cmdlist = cmd_list_parse(argc, argv, &cause)) == NULL) {
|
||||||
fprintf(stderr, "%s\n", cause);
|
log_warnx("%s", cause);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
cmdflags &= ~CMD_STARTSERVER;
|
cmdflags &= ~CMD_STARTSERVER;
|
||||||
@@ -209,17 +143,16 @@ client_main(int argc, char **argv, int flags)
|
|||||||
* if the socket path matches $TMUX, this is probably the same server.
|
* if the socket path matches $TMUX, this is probably the same server.
|
||||||
*/
|
*/
|
||||||
if (shell_cmd == NULL && environ_path != NULL &&
|
if (shell_cmd == NULL && environ_path != NULL &&
|
||||||
(cmdflags & CMD_CANTNEST) &&
|
cmdflags & CMD_CANTNEST && strcmp(socket_path, environ_path) == 0) {
|
||||||
strcmp(socket_path, environ_path) == 0) {
|
log_warnx("sessions should be nested with care. "
|
||||||
fprintf(stderr, "sessions should be nested with care, "
|
"unset $TMUX to force.");
|
||||||
"unset $TMUX to force\n");
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialise the client socket and start the server. */
|
/* Initialise the client socket and start the server. */
|
||||||
fd = client_connect(socket_path, cmdflags & CMD_STARTSERVER);
|
fd = client_connect(socket_path, cmdflags & CMD_STARTSERVER);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
fprintf(stderr, "failed to connect to server\n");
|
log_warn("failed to connect to server");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,30 +166,6 @@ client_main(int argc, char **argv, int flags)
|
|||||||
imsg_init(&client_ibuf, fd);
|
imsg_init(&client_ibuf, fd);
|
||||||
event_set(&client_event, fd, EV_READ, client_callback, shell_cmd);
|
event_set(&client_event, fd, EV_READ, client_callback, shell_cmd);
|
||||||
|
|
||||||
/* Create stdin handler. */
|
|
||||||
setblocking(STDIN_FILENO, 0);
|
|
||||||
event_set(&client_stdin, STDIN_FILENO, EV_READ|EV_PERSIST,
|
|
||||||
client_stdin_callback, NULL);
|
|
||||||
if (flags & IDENTIFY_TERMIOS) {
|
|
||||||
if (tcgetattr(STDIN_FILENO, &saved_tio) != 0) {
|
|
||||||
fprintf(stderr, "tcgetattr failed: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
cfmakeraw(&tio);
|
|
||||||
tio.c_iflag = ICRNL|IXANY;
|
|
||||||
tio.c_oflag = OPOST|ONLCR;
|
|
||||||
#ifdef NOKERNINFO
|
|
||||||
tio.c_lflag = NOKERNINFO;
|
|
||||||
#endif
|
|
||||||
tio.c_cflag = CREAD|CS8|HUPCL;
|
|
||||||
tio.c_cc[VMIN] = 1;
|
|
||||||
tio.c_cc[VTIME] = 0;
|
|
||||||
cfsetispeed(&tio, cfgetispeed(&saved_tio));
|
|
||||||
cfsetospeed(&tio, cfgetospeed(&saved_tio));
|
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &tio);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Establish signal handlers. */
|
/* Establish signal handlers. */
|
||||||
set_signals(client_signal);
|
set_signals(client_signal);
|
||||||
|
|
||||||
@@ -275,7 +184,7 @@ client_main(int argc, char **argv, int flags)
|
|||||||
cmddata.argc = argc;
|
cmddata.argc = argc;
|
||||||
if (cmd_pack_argv(
|
if (cmd_pack_argv(
|
||||||
argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
|
argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
|
||||||
fprintf(stderr, "command too long\n");
|
log_warnx("command too long");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,16 +197,8 @@ client_main(int argc, char **argv, int flags)
|
|||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
/* Print the exit message, if any, and exit. */
|
/* Print the exit message, if any, and exit. */
|
||||||
if (client_attached) {
|
if (client_attached && client_exitmsg != NULL && !login_shell)
|
||||||
if (client_exitreason != CLIENT_EXIT_NONE && !login_shell)
|
printf("[%s]\n", client_exitmsg);
|
||||||
printf("[%s]\n", client_exit_message());
|
|
||||||
|
|
||||||
ppid = getppid();
|
|
||||||
if (client_exittype == MSG_DETACHKILL && ppid > 1)
|
|
||||||
kill(ppid, SIGHUP);
|
|
||||||
} else if (flags & IDENTIFY_TERMIOS)
|
|
||||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
|
|
||||||
setblocking(STDIN_FILENO, 1);
|
|
||||||
return (client_exitval);
|
return (client_exitval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +224,16 @@ client_send_identify(int flags)
|
|||||||
fatal("dup failed");
|
fatal("dup failed");
|
||||||
imsg_compose(&client_ibuf,
|
imsg_compose(&client_ibuf,
|
||||||
MSG_IDENTIFY, PROTOCOL_VERSION, -1, fd, &data, sizeof data);
|
MSG_IDENTIFY, PROTOCOL_VERSION, -1, fd, &data, sizeof data);
|
||||||
client_update_event();
|
|
||||||
|
if ((fd = dup(STDOUT_FILENO)) == -1)
|
||||||
|
fatal("dup failed");
|
||||||
|
imsg_compose(&client_ibuf,
|
||||||
|
MSG_STDOUT, PROTOCOL_VERSION, -1, fd, NULL, 0);
|
||||||
|
|
||||||
|
if ((fd = dup(STDERR_FILENO)) == -1)
|
||||||
|
fatal("dup failed");
|
||||||
|
imsg_compose(&client_ibuf,
|
||||||
|
MSG_STDERR, PROTOCOL_VERSION, -1, fd, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Forward entire environment to server. */
|
/* Forward entire environment to server. */
|
||||||
@@ -345,7 +255,6 @@ void
|
|||||||
client_write_server(enum msgtype type, void *buf, size_t len)
|
client_write_server(enum msgtype type, void *buf, size_t len)
|
||||||
{
|
{
|
||||||
imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
|
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. */
|
/* Update client event based on whether it needs to read or read and write. */
|
||||||
@@ -383,12 +292,12 @@ client_signal(int sig, unused short events, unused void *data)
|
|||||||
} else {
|
} else {
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
client_exitreason = CLIENT_EXIT_LOST_TTY;
|
client_exitmsg = "lost tty";
|
||||||
client_exitval = 1;
|
client_exitval = 1;
|
||||||
client_write_server(MSG_EXITING, NULL, 0);
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
break;
|
break;
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
client_exitreason = CLIENT_EXIT_TERMINATED;
|
client_exitmsg = "terminated";
|
||||||
client_exitval = 1;
|
client_exitval = 1;
|
||||||
client_write_server(MSG_EXITING, NULL, 0);
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
break;
|
break;
|
||||||
@@ -440,46 +349,11 @@ client_callback(unused int fd, short events, void *data)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
lost_server:
|
lost_server:
|
||||||
client_exitreason = CLIENT_EXIT_LOST_SERVER;
|
client_exitmsg = "lost server";
|
||||||
client_exitval = 1;
|
client_exitval = 1;
|
||||||
event_loopexit(NULL);
|
event_loopexit(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback for client stdin read events. */
|
|
||||||
/* ARGSUSED */
|
|
||||||
void
|
|
||||||
client_stdin_callback(unused int fd, unused short events, unused void *data1)
|
|
||||||
{
|
|
||||||
struct msg_stdin_data data;
|
|
||||||
|
|
||||||
data.size = read(STDIN_FILENO, data.data, sizeof data.data);
|
|
||||||
if (data.size < 0 && (errno == EINTR || errno == EAGAIN))
|
|
||||||
return;
|
|
||||||
|
|
||||||
client_write_server(MSG_STDIN, &data, sizeof data);
|
|
||||||
if (data.size <= 0)
|
|
||||||
event_del(&client_stdin);
|
|
||||||
client_update_event();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Force write to file descriptor. */
|
|
||||||
void
|
|
||||||
client_write(int fd, const char *data, size_t size)
|
|
||||||
{
|
|
||||||
ssize_t used;
|
|
||||||
|
|
||||||
while (size != 0) {
|
|
||||||
used = write(fd, data, size);
|
|
||||||
if (used == -1) {
|
|
||||||
if (errno == EINTR || errno == EAGAIN)
|
|
||||||
continue;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
data += used;
|
|
||||||
size -= used;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
||||||
int
|
int
|
||||||
client_dispatch_wait(void *data)
|
client_dispatch_wait(void *data)
|
||||||
@@ -488,10 +362,11 @@ client_dispatch_wait(void *data)
|
|||||||
ssize_t n, datalen;
|
ssize_t n, datalen;
|
||||||
struct msg_shell_data shelldata;
|
struct msg_shell_data shelldata;
|
||||||
struct msg_exit_data exitdata;
|
struct msg_exit_data exitdata;
|
||||||
struct msg_stdout_data stdoutdata;
|
|
||||||
struct msg_stderr_data stderrdata;
|
|
||||||
const char *shellcmd = data;
|
const char *shellcmd = data;
|
||||||
|
|
||||||
|
if ((n = imsg_read(&client_ibuf)) == -1 || n == 0)
|
||||||
|
fatalx("imsg_read failed");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
||||||
fatalx("imsg_get failed");
|
fatalx("imsg_get failed");
|
||||||
@@ -499,7 +374,6 @@ client_dispatch_wait(void *data)
|
|||||||
return (0);
|
return (0);
|
||||||
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
|
||||||
log_debug("got %d from server", imsg.hdr.type);
|
|
||||||
switch (imsg.hdr.type) {
|
switch (imsg.hdr.type) {
|
||||||
case MSG_EXIT:
|
case MSG_EXIT:
|
||||||
case MSG_SHUTDOWN:
|
case MSG_SHUTDOWN:
|
||||||
@@ -516,36 +390,14 @@ client_dispatch_wait(void *data)
|
|||||||
if (datalen != 0)
|
if (datalen != 0)
|
||||||
fatalx("bad MSG_READY size");
|
fatalx("bad MSG_READY size");
|
||||||
|
|
||||||
event_del(&client_stdin);
|
|
||||||
client_attached = 1;
|
client_attached = 1;
|
||||||
break;
|
break;
|
||||||
case MSG_STDIN:
|
|
||||||
if (datalen != 0)
|
|
||||||
fatalx("bad MSG_STDIN size");
|
|
||||||
|
|
||||||
event_add(&client_stdin, NULL);
|
|
||||||
break;
|
|
||||||
case MSG_STDOUT:
|
|
||||||
if (datalen != sizeof stdoutdata)
|
|
||||||
fatalx("bad MSG_STDOUT");
|
|
||||||
memcpy(&stdoutdata, imsg.data, sizeof stdoutdata);
|
|
||||||
|
|
||||||
client_write(STDOUT_FILENO, stdoutdata.data, stdoutdata.size);
|
|
||||||
break;
|
|
||||||
case MSG_STDERR:
|
|
||||||
if (datalen != sizeof stderrdata)
|
|
||||||
fatalx("bad MSG_STDERR");
|
|
||||||
memcpy(&stderrdata, imsg.data, sizeof stderrdata);
|
|
||||||
|
|
||||||
client_write(STDERR_FILENO, stderrdata.data, stderrdata.size);
|
|
||||||
break;
|
|
||||||
case MSG_VERSION:
|
case MSG_VERSION:
|
||||||
if (datalen != 0)
|
if (datalen != 0)
|
||||||
fatalx("bad MSG_VERSION size");
|
fatalx("bad MSG_VERSION size");
|
||||||
|
|
||||||
fprintf(stderr, "protocol version mismatch "
|
log_warnx("protocol version mismatch (client %u, "
|
||||||
"(client %u, server %u)\n", PROTOCOL_VERSION,
|
"server %u)", PROTOCOL_VERSION, imsg.hdr.peerid);
|
||||||
imsg.hdr.peerid);
|
|
||||||
client_exitval = 1;
|
client_exitval = 1;
|
||||||
|
|
||||||
imsg_free(&imsg);
|
imsg_free(&imsg);
|
||||||
@@ -560,12 +412,6 @@ client_dispatch_wait(void *data)
|
|||||||
|
|
||||||
shell_exec(shelldata.shell, shellcmd);
|
shell_exec(shelldata.shell, shellcmd);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
case MSG_DETACH:
|
|
||||||
client_write_server(MSG_EXITING, NULL, 0);
|
|
||||||
break;
|
|
||||||
case MSG_EXITED:
|
|
||||||
imsg_free(&imsg);
|
|
||||||
return (-1);
|
|
||||||
default:
|
default:
|
||||||
fatalx("unexpected message");
|
fatalx("unexpected message");
|
||||||
}
|
}
|
||||||
@@ -591,19 +437,14 @@ client_dispatch_attached(void)
|
|||||||
return (0);
|
return (0);
|
||||||
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
|
||||||
log_debug("got %d from server", imsg.hdr.type);
|
log_debug("client got %d", imsg.hdr.type);
|
||||||
switch (imsg.hdr.type) {
|
switch (imsg.hdr.type) {
|
||||||
case MSG_DETACHKILL:
|
|
||||||
case MSG_DETACH:
|
case MSG_DETACH:
|
||||||
if (datalen != 0)
|
if (datalen != 0)
|
||||||
fatalx("bad MSG_DETACH size");
|
fatalx("bad MSG_DETACH size");
|
||||||
|
|
||||||
client_exittype = imsg.hdr.type;
|
|
||||||
if (imsg.hdr.type == MSG_DETACHKILL)
|
|
||||||
client_exitreason = CLIENT_EXIT_DETACHED_HUP;
|
|
||||||
else
|
|
||||||
client_exitreason = CLIENT_EXIT_DETACHED;
|
|
||||||
client_write_server(MSG_EXITING, NULL, 0);
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
|
client_exitmsg = "detached";
|
||||||
break;
|
break;
|
||||||
case MSG_EXIT:
|
case MSG_EXIT:
|
||||||
if (datalen != 0 &&
|
if (datalen != 0 &&
|
||||||
@@ -611,7 +452,7 @@ client_dispatch_attached(void)
|
|||||||
fatalx("bad MSG_EXIT size");
|
fatalx("bad MSG_EXIT size");
|
||||||
|
|
||||||
client_write_server(MSG_EXITING, NULL, 0);
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
client_exitreason = CLIENT_EXIT_EXITED;
|
client_exitmsg = "exited";
|
||||||
break;
|
break;
|
||||||
case MSG_EXITED:
|
case MSG_EXITED:
|
||||||
if (datalen != 0)
|
if (datalen != 0)
|
||||||
@@ -624,7 +465,7 @@ client_dispatch_attached(void)
|
|||||||
fatalx("bad MSG_SHUTDOWN size");
|
fatalx("bad MSG_SHUTDOWN size");
|
||||||
|
|
||||||
client_write_server(MSG_EXITING, NULL, 0);
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
client_exitreason = CLIENT_EXIT_SERVER_EXITED;
|
client_exitmsg = "server exited";
|
||||||
client_exitval = 1;
|
client_exitval = 1;
|
||||||
break;
|
break;
|
||||||
case MSG_SUSPEND:
|
case MSG_SUSPEND:
|
||||||
|
|||||||
2
clock.c
2
clock.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: clock.c,v 1.9 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-attach-session.c,v 1.37 2010-12-22 15:36:44 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,49 +18,47 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attach existing session to the current terminal.
|
* Attach existing session to the current terminal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_attach_session_entry = {
|
const struct cmd_entry cmd_attach_session_entry = {
|
||||||
"attach-session", "attach",
|
"attach-session", "attach",
|
||||||
"drt:", 0, 0,
|
|
||||||
"[-dr] " CMD_TARGET_SESSION_USAGE,
|
"[-dr] " CMD_TARGET_SESSION_USAGE,
|
||||||
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON,
|
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, "dr",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_attach_session_exec
|
cmd_attach_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
const char *update;
|
const char *update;
|
||||||
char *cause;
|
char *overrides, *cause;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
if (RB_EMPTY(&sessions)) {
|
if (RB_EMPTY(&sessions)) {
|
||||||
ctx->error(ctx, "no sessions");
|
ctx->error(ctx, "no sessions");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
if (ctx->cmdclient == NULL) {
|
if (ctx->cmdclient == NULL) {
|
||||||
if (args_has(self->args, 'd')) {
|
if (cmd_check_flag(data->chflags, 'd')) {
|
||||||
/*
|
/*
|
||||||
* Can't use server_write_session in case attaching to
|
* Can't use server_write_session in case attaching to
|
||||||
* the same session as currently attached to.
|
* the same session as currently attached to.
|
||||||
@@ -76,36 +74,37 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx->curclient->session = s;
|
ctx->curclient->session = s;
|
||||||
notify_attached_session_changed(ctx->curclient);
|
|
||||||
session_update_activity(s);
|
|
||||||
server_redraw_client(ctx->curclient);
|
server_redraw_client(ctx->curclient);
|
||||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
|
||||||
} else {
|
} else {
|
||||||
if (server_client_open(ctx->cmdclient, s, &cause) != 0) {
|
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||||
ctx->error(ctx, "open terminal failed: %s", cause);
|
ctx->error(ctx, "not a terminal");
|
||||||
free(cause);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(self->args, 'r'))
|
overrides =
|
||||||
|
options_get_string(&s->options, "terminal-overrides");
|
||||||
|
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "terminal open failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd_check_flag(data->chflags, 'r'))
|
||||||
ctx->cmdclient->flags |= CLIENT_READONLY;
|
ctx->cmdclient->flags |= CLIENT_READONLY;
|
||||||
|
|
||||||
if (args_has(self->args, 'd'))
|
if (cmd_check_flag(data->chflags, 'd'))
|
||||||
server_write_session(s, MSG_DETACH, NULL, 0);
|
server_write_session(s, MSG_DETACH, NULL, 0);
|
||||||
|
|
||||||
ctx->cmdclient->session = s;
|
ctx->cmdclient->session = s;
|
||||||
notify_attached_session_changed(ctx->cmdclient);
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
session_update_activity(s);
|
|
||||||
server_write_ready(ctx->cmdclient);
|
|
||||||
|
|
||||||
update = options_get_string(&s->options, "update-environment");
|
update = options_get_string(&s->options, "update-environment");
|
||||||
environ_update(update, &ctx->cmdclient->environ, &s->environ);
|
environ_update(update, &ctx->cmdclient->environ, &s->environ);
|
||||||
|
|
||||||
server_redraw_client(ctx->cmdclient);
|
server_redraw_client(ctx->cmdclient);
|
||||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
|
||||||
}
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
server_update_socket();
|
server_update_socket();
|
||||||
|
|
||||||
return (CMD_RETURN_ATTACH);
|
return (1); /* 1 means don't tell command client to exit */
|
||||||
}
|
}
|
||||||
|
|||||||
206
cmd-bind-key.c
206
cmd-bind-key.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-bind-key.c,v 1.29 2010-07-02 02:43:01 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,95 +26,186 @@
|
|||||||
* Bind a key to a command, this recurses through cmd_*.
|
* Bind a key to a command, this recurses through cmd_*.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_bind_key_check(struct args *);
|
int cmd_bind_key_parse(struct cmd *, int, char **, char **);
|
||||||
enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_bind_key_free(struct cmd *);
|
||||||
|
size_t cmd_bind_key_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
enum cmd_retval cmd_bind_key_table(struct cmd *, struct cmd_ctx *, int);
|
int cmd_bind_key_table(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
struct cmd_bind_key_data {
|
||||||
|
int key;
|
||||||
|
int can_repeat;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
|
||||||
|
int command_key;
|
||||||
|
char *tablename;
|
||||||
|
char *modecmd;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_bind_key_entry = {
|
const struct cmd_entry cmd_bind_key_entry = {
|
||||||
"bind-key", "bind",
|
"bind-key", "bind",
|
||||||
"cnrt:", 1, -1,
|
|
||||||
"[-cnr] [-t key-table] key command [arguments]",
|
"[-cnr] [-t key-table] key command [arguments]",
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
NULL,
|
||||||
cmd_bind_key_check,
|
cmd_bind_key_parse,
|
||||||
cmd_bind_key_exec
|
cmd_bind_key_exec,
|
||||||
|
cmd_bind_key_free,
|
||||||
|
cmd_bind_key_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_bind_key_check(struct args *args)
|
cmd_bind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
{
|
{
|
||||||
if (args_has(args, 't')) {
|
struct cmd_bind_key_data *data;
|
||||||
if (args->argc != 2)
|
int opt, no_prefix = 0;
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->can_repeat = 0;
|
||||||
|
data->cmdlist = NULL;
|
||||||
|
data->command_key = 0;
|
||||||
|
data->tablename = NULL;
|
||||||
|
data->modecmd = NULL;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "cnrt:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'c':
|
||||||
|
data->command_key = 1;
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
no_prefix = 1;
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
data->can_repeat = 1;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->tablename == NULL)
|
||||||
|
data->tablename = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc < 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
if ((data->key = key_string_lookup_string(argv[0])) == KEYC_NONE) {
|
||||||
|
xasprintf(cause, "unknown key: %s", argv[0]);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (!no_prefix)
|
||||||
|
data->key |= KEYC_PREFIX;
|
||||||
|
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
if (data->tablename != NULL) {
|
||||||
|
if (argc != 1)
|
||||||
|
goto usage;
|
||||||
|
data->modecmd = xstrdup(argv[0]);
|
||||||
} else {
|
} else {
|
||||||
if (args->argc < 2)
|
if ((data->cmdlist = cmd_list_parse(argc, argv, cause)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
goto error;
|
||||||
}
|
}
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_bind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_bind_key_data *data = self->data;
|
||||||
char *cause;
|
|
||||||
struct cmd_list *cmdlist;
|
|
||||||
int key;
|
|
||||||
|
|
||||||
key = key_string_lookup_string(args->argv[0]);
|
if (data == NULL)
|
||||||
if (key == KEYC_NONE) {
|
return (0);
|
||||||
ctx->error(ctx, "unknown key: %s", args->argv[0]);
|
if (data->tablename != NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (cmd_bind_key_table(self, ctx));
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 't'))
|
key_bindings_add(data->key, data->can_repeat, data->cmdlist);
|
||||||
return (cmd_bind_key_table(self, ctx, key));
|
data->cmdlist->references++;
|
||||||
|
|
||||||
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, &cause);
|
return (0);
|
||||||
if (cmdlist == NULL) {
|
|
||||||
ctx->error(ctx, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!args_has(args, 'n'))
|
|
||||||
key |= KEYC_PREFIX;
|
|
||||||
key_bindings_add(key, args_has(args, 'r'), cmdlist);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
|
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_bind_key_data *data = self->data;
|
||||||
const char *tablename;
|
|
||||||
const struct mode_key_table *mtab;
|
const struct mode_key_table *mtab;
|
||||||
struct mode_key_binding *mbind, mtmp;
|
struct mode_key_binding *mbind, mtmp;
|
||||||
enum mode_key_cmd cmd;
|
enum mode_key_cmd cmd;
|
||||||
|
|
||||||
tablename = args_get(args, 't');
|
if ((mtab = mode_key_findtable(data->tablename)) == NULL) {
|
||||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
ctx->error(ctx, "unknown key table: %s", data->tablename);
|
||||||
ctx->error(ctx, "unknown key table: %s", tablename);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
|
cmd = mode_key_fromstring(mtab->cmdstr, data->modecmd);
|
||||||
if (cmd == MODEKEY_NONE) {
|
if (cmd == MODEKEY_NONE) {
|
||||||
ctx->error(ctx, "unknown command: %s", args->argv[1]);
|
ctx->error(ctx, "unknown command: %s", data->modecmd);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
mtmp.key = key;
|
mtmp.key = data->key & ~KEYC_PREFIX;
|
||||||
mtmp.mode = !!args_has(args, 'c');
|
mtmp.mode = data->command_key ? 1 : 0;
|
||||||
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||||
mbind->cmd = cmd;
|
mbind->cmd = cmd;
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
mbind = xmalloc(sizeof *mbind);
|
mbind = xmalloc(sizeof *mbind);
|
||||||
mbind->key = mtmp.key;
|
mbind->key = mtmp.key;
|
||||||
mbind->mode = mtmp.mode;
|
mbind->mode = mtmp.mode;
|
||||||
mbind->cmd = cmd;
|
mbind->cmd = cmd;
|
||||||
RB_INSERT(mode_key_tree, mtab->tree, mbind);
|
SPLAY_INSERT(mode_key_tree, mtab->tree, mbind);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_bind_key_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_bind_key_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->cmdlist != NULL)
|
||||||
|
cmd_list_free(data->cmdlist);
|
||||||
|
if (data->tablename != NULL)
|
||||||
|
xfree(data->tablename);
|
||||||
|
if (data->modecmd != NULL)
|
||||||
|
xfree(data->modecmd);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_bind_key_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_bind_key_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
const char *skey;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
|
||||||
|
if (off < len && data->command_key)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -c");
|
||||||
|
if (off < len && !(data->key & KEYC_PREFIX))
|
||||||
|
off += xsnprintf(buf + off, len - off, " -n");
|
||||||
|
if (off < len && data->can_repeat)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -r");
|
||||||
|
if (off < len && data->tablename != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->tablename);
|
||||||
|
if (off < len) {
|
||||||
|
skey = key_string_lookup_key(data->key & ~KEYC_PREFIX);
|
||||||
|
off += xsnprintf(buf + off, len - off, " %s ", skey);
|
||||||
|
}
|
||||||
|
if (off < len)
|
||||||
|
off += cmd_list_print(data->cmdlist, buf + off, len - off);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-break-pane.c,v 1.11 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,89 +26,59 @@
|
|||||||
* Break pane off into a window.
|
* Break pane off into a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_break_pane_entry = {
|
const struct cmd_entry cmd_break_pane_entry = {
|
||||||
"break-pane", "breakp",
|
"break-pane", "breakp",
|
||||||
"dPF:t:", 0, 0,
|
CMD_TARGET_PANE_USAGE " [-d]",
|
||||||
"[-dP] [-F format] " CMD_TARGET_PANE_USAGE,
|
0, "d",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_break_pane_exec,
|
||||||
cmd_break_pane_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
char *name;
|
|
||||||
char *cause;
|
char *cause;
|
||||||
int base_idx;
|
int base_idx;
|
||||||
struct client *c;
|
|
||||||
struct format_tree *ft;
|
|
||||||
const char *template;
|
|
||||||
char *cp;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
if ((wl = cmd_find_pane(ctx, data->target, &s, &wp)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (window_count_panes(wl->window) == 1) {
|
if (window_count_panes(wl->window) == 1) {
|
||||||
ctx->error(ctx, "can't break with only one pane");
|
ctx->error(ctx, "can't break with only one pane");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
w = wl->window;
|
TAILQ_REMOVE(&wl->window->panes, wp, entry);
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
if (wl->window->active == wp) {
|
||||||
if (wp == w->active) {
|
wl->window->active = TAILQ_PREV(wp, window_panes, entry);
|
||||||
w->active = w->last;
|
if (wl->window->active == NULL)
|
||||||
w->last = NULL;
|
wl->window->active = TAILQ_NEXT(wp, entry);
|
||||||
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);
|
layout_close_pane(wp);
|
||||||
|
|
||||||
w = wp->window = window_create1(s->sx, s->sy);
|
w = wp->window = window_create1(s->sx, s->sy);
|
||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
w->active = wp;
|
w->active = wp;
|
||||||
name = default_window_name(w);
|
w->name = default_window_name(w);
|
||||||
window_set_name(w, name);
|
|
||||||
free(name);
|
|
||||||
layout_init(w);
|
layout_init(w);
|
||||||
|
|
||||||
base_idx = options_get_number(&s->options, "base-index");
|
base_idx = options_get_number(&s->options, "base-index");
|
||||||
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
|
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
|
||||||
if (!args_has(self->args, 'd'))
|
if (!cmd_check_flag(data->chflags, 'd'))
|
||||||
session_select(s, wl->idx);
|
session_select(s, wl->idx);
|
||||||
|
|
||||||
server_redraw_session(s);
|
server_redraw_session(s);
|
||||||
server_status_session_group(s);
|
server_status_session_group(s);
|
||||||
|
|
||||||
if (args_has(args, 'P')) {
|
return (0);
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = BREAK_PANE_TEMPLATE;
|
|
||||||
|
|
||||||
ft = format_create();
|
|
||||||
if ((c = cmd_find_client(ctx, NULL)) != NULL)
|
|
||||||
format_client(ft, c);
|
|
||||||
format_session(ft, s);
|
|
||||||
format_winlink(ft, s, wl);
|
|
||||||
format_window_pane(ft, wp);
|
|
||||||
|
|
||||||
cp = format_expand(ft, template);
|
|
||||||
ctx->print(ctx, "%s", cp);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-capture-pane.c,v 1.3 2010-01-22 17:29:19 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
|
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,68 +26,39 @@
|
|||||||
* Write the entire contents of a pane to a buffer.
|
* Write the entire contents of a pane to a buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_capture_pane_entry = {
|
const struct cmd_entry cmd_capture_pane_entry = {
|
||||||
"capture-pane", "capturep",
|
"capture-pane", "capturep",
|
||||||
"b:E:S:t:", 0, 0,
|
CMD_BUFFER_PANE_USAGE,
|
||||||
"[-b buffer-index] [-E end-line] [-S start-line] [-t target-pane]",
|
0, "",
|
||||||
0,
|
cmd_buffer_init,
|
||||||
NULL,
|
cmd_buffer_parse,
|
||||||
NULL,
|
cmd_capture_pane_exec,
|
||||||
cmd_capture_pane_exec
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
char *buf, *line, *cause;
|
char *buf, *line;
|
||||||
struct screen *s;
|
struct screen *s;
|
||||||
struct grid *gd;
|
struct session *sess;
|
||||||
int buffer, n;
|
u_int i, limit;
|
||||||
u_int i, limit, top, bottom, tmp;
|
|
||||||
size_t len, linelen;
|
size_t len, linelen;
|
||||||
|
|
||||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
if (cmd_find_pane(ctx, data->target, &sess, &wp) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
s = &wp->base;
|
s = &wp->base;
|
||||||
gd = s->grid;
|
|
||||||
|
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|
||||||
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
|
for (i = 0; i < screen_size_y(s); i++) {
|
||||||
if (cause != NULL) {
|
line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
|
||||||
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;
|
|
||||||
|
|
||||||
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;
|
|
||||||
bottom = top;
|
|
||||||
top = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = top; i <= bottom; i++) {
|
|
||||||
line = grid_string_cells(s->grid, 0, i, screen_size_x(s));
|
|
||||||
linelen = strlen(line);
|
linelen = strlen(line);
|
||||||
|
|
||||||
buf = xrealloc(buf, 1, len + linelen + 1);
|
buf = xrealloc(buf, 1, len + linelen + 1);
|
||||||
@@ -96,29 +66,18 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
len += linelen;
|
len += linelen;
|
||||||
buf[len++] = '\n';
|
buf[len++] = '\n';
|
||||||
|
|
||||||
free(line);
|
xfree(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
limit = options_get_number(&global_options, "buffer-limit");
|
limit = options_get_number(&sess->options, "buffer-limit");
|
||||||
|
if (data->buffer == -1) {
|
||||||
if (!args_has(args, 'b')) {
|
paste_add(&sess->buffers, buf, len, limit);
|
||||||
paste_add(&global_buffers, buf, len, limit);
|
return (0);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
if (paste_replace(&sess->buffers, data->buffer, buf, len) != 0) {
|
||||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
if (cause != NULL) {
|
xfree(buf);
|
||||||
ctx->error(ctx, "buffer %s", cause);
|
return (-1);
|
||||||
free(buf);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
if (paste_replace(&global_buffers, buffer, buf, len) != 0) {
|
|
||||||
ctx->error(ctx, "no buffer %d", buffer);
|
|
||||||
free(buf);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-choose-buffer.c,v 1.1 2010-06-22 23:35:20 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -27,100 +26,121 @@
|
|||||||
* Enter choice mode to choose a buffer.
|
* Enter choice mode to choose a buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
void cmd_choose_buffer_callback(struct window_choose_data *);
|
void cmd_choose_buffer_callback(void *, int);
|
||||||
void cmd_choose_buffer_free(struct window_choose_data *);
|
void cmd_choose_buffer_free(void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_buffer_entry = {
|
const struct cmd_entry cmd_choose_buffer_entry = {
|
||||||
"choose-buffer", NULL,
|
"choose-buffer", NULL,
|
||||||
"F:t:", 0, 1,
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
CMD_ARG01, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_choose_buffer_exec,
|
||||||
cmd_choose_buffer_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
struct cmd_choose_buffer_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_choose_data *cdata;
|
struct cmd_choose_buffer_data *cdata;
|
||||||
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
char *action, *action_data;
|
|
||||||
const char *template;
|
|
||||||
u_int idx;
|
u_int idx;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
if (ctx->curclient == NULL) {
|
if (ctx->curclient == NULL) {
|
||||||
ctx->error(ctx, "must be run interactively");
|
ctx->error(ctx, "must be run interactively");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
template = CHOOSE_BUFFER_TEMPLATE;
|
return (-1);
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
if (paste_get_top(&s->buffers) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (0);
|
||||||
|
|
||||||
if (paste_get_top(&global_buffers) == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
if (args->argc != 0)
|
|
||||||
action = xstrdup(args->argv[0]);
|
|
||||||
else
|
|
||||||
action = xstrdup("paste-buffer -b '%%'");
|
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
|
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
||||||
cdata = window_choose_data_create(ctx);
|
tmp = paste_print(pb, 50);
|
||||||
cdata->idx = idx - 1;
|
window_choose_add(wl->window->active, idx - 1,
|
||||||
cdata->client->references++;
|
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||||
|
xfree(tmp);
|
||||||
cdata->ft_template = xstrdup(template);
|
|
||||||
format_add(cdata->ft, "line", "%u", idx - 1);
|
|
||||||
format_paste_buffer(cdata->ft, pb);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
free(action);
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
cdata->template = xstrdup(data->arg);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("paste-buffer -b '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
window_choose_ready(wl->window->active,
|
window_choose_ready(wl->window->active,
|
||||||
0, cmd_choose_buffer_callback, cmd_choose_buffer_free);
|
0, cmd_choose_buffer_callback, cmd_choose_buffer_free, cdata);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_choose_buffer_callback(struct window_choose_data *cdata)
|
cmd_choose_buffer_callback(void *data, int idx)
|
||||||
{
|
{
|
||||||
if (cdata == NULL)
|
struct cmd_choose_buffer_data *cdata = data;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause, tmp[16];
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
if (cdata->client->flags & CLIENT_DEAD)
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
window_choose_ctx(cdata);
|
xsnprintf(tmp, sizeof tmp, "%u", idx);
|
||||||
|
template = cmd_template_replace(cdata->template, tmp, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_choose_buffer_free(struct window_choose_data *data)
|
cmd_choose_buffer_free(void *data)
|
||||||
{
|
{
|
||||||
struct window_choose_data *cdata = data;
|
struct cmd_choose_buffer_data *cdata = data;
|
||||||
|
|
||||||
if (cdata == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
cdata->client->references--;
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
free(cdata->command);
|
xfree(cdata);
|
||||||
free(cdata->ft_template);
|
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-choose-client.c,v 1.4 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -27,19 +26,20 @@
|
|||||||
* Enter choice mode to choose a client.
|
* Enter choice mode to choose a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_choose_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
void cmd_choose_client_callback(struct window_choose_data *);
|
void cmd_choose_client_callback(void *, int);
|
||||||
void cmd_choose_client_free(struct window_choose_data *);
|
void cmd_choose_client_free(void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_client_entry = {
|
const struct cmd_entry cmd_choose_client_entry = {
|
||||||
"choose-client", NULL,
|
"choose-client", NULL,
|
||||||
"F:t:", 0, 1,
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
CMD_ARG01, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_choose_client_exec,
|
||||||
cmd_choose_client_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_choose_client_data {
|
struct cmd_choose_client_data {
|
||||||
@@ -47,35 +47,25 @@ struct cmd_choose_client_data {
|
|||||||
char *template;
|
char *template;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_choose_data *cdata;
|
struct cmd_choose_client_data *cdata;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
const char *template;
|
|
||||||
char *action;
|
|
||||||
u_int i, idx, cur;
|
u_int i, idx, cur;
|
||||||
|
|
||||||
if (ctx->curclient == NULL) {
|
if (ctx->curclient == NULL) {
|
||||||
ctx->error(ctx, "must be run interactively");
|
ctx->error(ctx, "must be run interactively");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = CHOOSE_CLIENT_TEMPLATE;
|
|
||||||
|
|
||||||
if (args->argc != 0)
|
|
||||||
action = xstrdup(args->argv[0]);
|
|
||||||
else
|
|
||||||
action = xstrdup("detach-client -t '%%'");
|
|
||||||
|
|
||||||
cur = idx = 0;
|
cur = idx = 0;
|
||||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
@@ -86,56 +76,77 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
cur = idx;
|
cur = idx;
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
cdata = window_choose_data_create(ctx);
|
window_choose_add(wl->window->active, i,
|
||||||
cdata->idx = i;
|
"%s: %s [%ux%u %s]%s", c->tty.path,
|
||||||
cdata->client->references++;
|
c->session->name, c->tty.sx, c->tty.sy,
|
||||||
|
c->tty.termname, c->tty.flags & TTY_UTF8 ? " (utf8)" : "");
|
||||||
cdata->ft_template = xstrdup(template);
|
|
||||||
format_add(cdata->ft, "line", "%u", i);
|
|
||||||
format_session(cdata->ft, c->session);
|
|
||||||
format_client(cdata->ft, c);
|
|
||||||
|
|
||||||
cdata->command = cmd_template_replace(action, c->tty.path, 1);
|
|
||||||
|
|
||||||
window_choose_add(wl->window->active, cdata);
|
|
||||||
}
|
}
|
||||||
free(action);
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
cdata->template = xstrdup(data->arg);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("detach-client -t '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
window_choose_ready(wl->window->active,
|
window_choose_ready(wl->window->active,
|
||||||
cur, cmd_choose_client_callback, cmd_choose_client_free);
|
cur, cmd_choose_client_callback, cmd_choose_client_free, cdata);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_choose_client_callback(struct window_choose_data *cdata)
|
cmd_choose_client_callback(void *data, int idx)
|
||||||
{
|
{
|
||||||
struct client *c;
|
struct cmd_choose_client_data *cdata = data;
|
||||||
|
struct client *c;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause;
|
||||||
|
|
||||||
if (cdata == NULL)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
if (cdata->client->flags & CLIENT_DEAD)
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cdata->idx > ARRAY_LENGTH(&clients) - 1)
|
if ((u_int) idx > ARRAY_LENGTH(&clients) - 1)
|
||||||
return;
|
return;
|
||||||
c = ARRAY_ITEM(&clients, cdata->idx);
|
c = ARRAY_ITEM(&clients, idx);
|
||||||
if (c == NULL || c->session == NULL)
|
if (c == NULL || c->session == NULL)
|
||||||
return;
|
return;
|
||||||
|
template = cmd_template_replace(cdata->template, c->tty.path, 1);
|
||||||
|
|
||||||
window_choose_ctx(cdata);
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(c, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_choose_client_free(struct window_choose_data *cdata)
|
cmd_choose_client_free(void *data)
|
||||||
{
|
{
|
||||||
if (cdata == NULL)
|
struct cmd_choose_client_data *cdata = data;
|
||||||
return;
|
|
||||||
|
|
||||||
cdata->client->references--;
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
free(cdata->ft_template);
|
xfree(cdata);
|
||||||
free(cdata->command);
|
|
||||||
format_free(cdata->ft);
|
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
/* $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_ctx *);
|
|
||||||
|
|
||||||
void cmd_choose_list_callback(struct window_choose_data *);
|
|
||||||
void cmd_choose_list_free(struct window_choose_data *);
|
|
||||||
|
|
||||||
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_ctx *ctx)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct winlink *wl;
|
|
||||||
const char *list1;
|
|
||||||
char *template, *item, *copy, *list;
|
|
||||||
u_int idx;
|
|
||||||
|
|
||||||
if (ctx->curclient == NULL) {
|
|
||||||
ctx->error(ctx, "must be run interactively");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((list1 = args_get(args, 'l')) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, 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, ctx, 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, cmd_choose_list_callback,
|
|
||||||
cmd_choose_list_free);
|
|
||||||
|
|
||||||
free(template);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_choose_list_callback(struct window_choose_data *cdata)
|
|
||||||
{
|
|
||||||
if (cdata == NULL || (cdata->client->flags & CLIENT_DEAD))
|
|
||||||
return;
|
|
||||||
|
|
||||||
window_choose_ctx(cdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_choose_list_free(struct window_choose_data *cdata)
|
|
||||||
{
|
|
||||||
cdata->session->references--;
|
|
||||||
cdata->client->references--;
|
|
||||||
|
|
||||||
free(cdata->ft_template);
|
|
||||||
free(cdata->command);
|
|
||||||
format_free(cdata->ft);
|
|
||||||
free(cdata);
|
|
||||||
|
|
||||||
}
|
|
||||||
157
cmd-choose-session.c
Normal file
157
cmd-choose-session.c
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
/* $Id: cmd-choose-session.c,v 1.17 2010-12-22 15:36:44 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_session_callback(void *, int);
|
||||||
|
void cmd_choose_session_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_session_entry = {
|
||||||
|
"choose-session", NULL,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
CMD_ARG01, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_choose_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_session_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct cmd_choose_session_data *cdata;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct session *s;
|
||||||
|
struct session_group *sg;
|
||||||
|
u_int idx, sgidx, cur;
|
||||||
|
char tmp[64];
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
cur = idx = 0;
|
||||||
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
|
if (s == ctx->curclient->session)
|
||||||
|
cur = idx;
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
sg = session_group_find(s);
|
||||||
|
if (sg == NULL)
|
||||||
|
*tmp = '\0';
|
||||||
|
else {
|
||||||
|
sgidx = session_group_index(sg);
|
||||||
|
xsnprintf(tmp, sizeof tmp, " (group %u)", sgidx);
|
||||||
|
}
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active, s->idx,
|
||||||
|
"%s: %u windows [%ux%u]%s%s", s->name,
|
||||||
|
winlink_count(&s->windows), s->sx, s->sy,
|
||||||
|
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
cdata->template = xstrdup(data->arg);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("switch-client -t '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_session_callback, cmd_choose_session_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_session_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_session_data *cdata = data;
|
||||||
|
struct session *s;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
s = session_find_by_index(idx);
|
||||||
|
if (s == NULL)
|
||||||
|
return;
|
||||||
|
template = cmd_template_replace(cdata->template, s->name, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_session_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_session_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
@@ -1,261 +0,0 @@
|
|||||||
/* $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_TREE_WINDOW_ACTION "select-window -t '%%'"
|
|
||||||
#define CMD_CHOOSE_TREE_SESSION_ACTION "switch-client -t '%%'"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Enter choice mode to choose a session and/or window.
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_ctx *);
|
|
||||||
|
|
||||||
void cmd_choose_tree_callback(struct window_choose_data *);
|
|
||||||
void cmd_choose_tree_free(struct window_choose_data *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_tree_entry = {
|
|
||||||
"choose-tree", NULL,
|
|
||||||
"S:W:swb:c:t:", 0, 1,
|
|
||||||
"[-sw] [-b session-template] [-c window template] [-S format] " \
|
|
||||||
"[-W format] " CMD_TARGET_WINDOW_USAGE,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
cmd_choose_tree_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_session_entry = {
|
|
||||||
"choose-session", NULL,
|
|
||||||
"F:t:", 0, 1,
|
|
||||||
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
cmd_choose_tree_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_window_entry = {
|
|
||||||
"choose-window", NULL,
|
|
||||||
"F:t:", 0, 1,
|
|
||||||
CMD_TARGET_WINDOW_USAGE "[-F format] [template]",
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
cmd_choose_tree_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct winlink *wl, *wm;
|
|
||||||
struct session *s, *s2;
|
|
||||||
struct window_choose_data *wcd = NULL;
|
|
||||||
const char *ses_template, *win_template;
|
|
||||||
char *final_win_action, *cur_win_template;
|
|
||||||
char *final_win_template_middle;
|
|
||||||
char *final_win_template_last;
|
|
||||||
const char *ses_action, *win_action;
|
|
||||||
u_int cur_win, idx_ses, win_ses, win_max;
|
|
||||||
u_int wflag, sflag;
|
|
||||||
|
|
||||||
ses_template = win_template = NULL;
|
|
||||||
ses_action = win_action = NULL;
|
|
||||||
|
|
||||||
if (ctx->curclient == NULL) {
|
|
||||||
ctx->error(ctx, "must be run interactively");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
s = ctx->curclient->session;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, 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);
|
|
||||||
|
|
||||||
/* Sort out which command this is. */
|
|
||||||
wflag = sflag = 0;
|
|
||||||
if (self->entry == &cmd_choose_session_entry) {
|
|
||||||
sflag = 1;
|
|
||||||
if ((ses_template = args_get(args, 'F')) == NULL)
|
|
||||||
ses_template = CHOOSE_TREE_SESSION_TEMPLATE;
|
|
||||||
|
|
||||||
if (args->argc != 0)
|
|
||||||
ses_action = args->argv[0];
|
|
||||||
else
|
|
||||||
ses_action = CMD_CHOOSE_TREE_SESSION_ACTION;
|
|
||||||
} else if (self->entry == &cmd_choose_window_entry) {
|
|
||||||
wflag = 1;
|
|
||||||
if ((win_template = args_get(args, 'F')) == NULL)
|
|
||||||
win_template = CHOOSE_TREE_WINDOW_TEMPLATE;
|
|
||||||
|
|
||||||
if (args->argc != 0)
|
|
||||||
win_action = args->argv[0];
|
|
||||||
else
|
|
||||||
win_action = CMD_CHOOSE_TREE_WINDOW_ACTION;
|
|
||||||
} else {
|
|
||||||
wflag = args_has(args, 'w');
|
|
||||||
sflag = args_has(args, 's');
|
|
||||||
|
|
||||||
if ((ses_action = args_get(args, 'b')) == NULL)
|
|
||||||
ses_action = CMD_CHOOSE_TREE_SESSION_ACTION;
|
|
||||||
|
|
||||||
if ((win_action = args_get(args, 'c')) == NULL)
|
|
||||||
win_action = CMD_CHOOSE_TREE_WINDOW_ACTION;
|
|
||||||
|
|
||||||
if ((ses_template = args_get(args, 'S')) == NULL)
|
|
||||||
ses_template = CHOOSE_TREE_SESSION_TEMPLATE;
|
|
||||||
|
|
||||||
if ((win_template = args_get(args, 'W')) == NULL)
|
|
||||||
win_template = CHOOSE_TREE_WINDOW_TEMPLATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If not asking for windows and sessions, assume no "-ws" given and
|
|
||||||
* hence display the entire tree outright.
|
|
||||||
*/
|
|
||||||
if (!wflag && !sflag)
|
|
||||||
wflag = sflag = 1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If we're drawing in tree mode, including sessions, then pad the
|
|
||||||
* window template, otherwise just render the windows as a flat list
|
|
||||||
* without any padding.
|
|
||||||
*/
|
|
||||||
if (wflag && sflag) {
|
|
||||||
xasprintf(&final_win_template_middle,
|
|
||||||
" \001tq\001> %s", win_template);
|
|
||||||
xasprintf(&final_win_template_last,
|
|
||||||
" \001mq\001> %s", win_template);
|
|
||||||
} else if (wflag) {
|
|
||||||
final_win_template_middle = xstrdup(win_template);
|
|
||||||
final_win_template_last = xstrdup(win_template);
|
|
||||||
} else
|
|
||||||
final_win_template_middle = final_win_template_last = NULL;
|
|
||||||
|
|
||||||
idx_ses = cur_win = -1;
|
|
||||||
RB_FOREACH(s2, sessions, &sessions) {
|
|
||||||
idx_ses++;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If we're just choosing windows, jump straight there. Note
|
|
||||||
* that this implies the current session, so only choose
|
|
||||||
* windows when the session matches this one.
|
|
||||||
*/
|
|
||||||
if (wflag && !sflag) {
|
|
||||||
if (s != s2)
|
|
||||||
continue;
|
|
||||||
goto windows_only;
|
|
||||||
}
|
|
||||||
|
|
||||||
wcd = window_choose_add_session(wl->window->active,
|
|
||||||
ctx, s2, ses_template, (char *)ses_action, idx_ses);
|
|
||||||
|
|
||||||
/* If we're just choosing sessions, skip choosing windows. */
|
|
||||||
if (sflag && !wflag) {
|
|
||||||
if (s == s2)
|
|
||||||
cur_win = idx_ses;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
windows_only:
|
|
||||||
win_ses = win_max = -1;
|
|
||||||
RB_FOREACH(wm, winlinks, &s2->windows)
|
|
||||||
win_max++;
|
|
||||||
RB_FOREACH(wm, winlinks, &s2->windows) {
|
|
||||||
win_ses++;
|
|
||||||
if (sflag && wflag)
|
|
||||||
idx_ses++;
|
|
||||||
|
|
||||||
if (wm == s2->curw && s == s2) {
|
|
||||||
if (wflag && !sflag) {
|
|
||||||
/*
|
|
||||||
* Then we're only counting windows.
|
|
||||||
* So remember which is the current
|
|
||||||
* window in the list.
|
|
||||||
*/
|
|
||||||
cur_win = win_ses;
|
|
||||||
} else
|
|
||||||
cur_win = idx_ses;
|
|
||||||
}
|
|
||||||
|
|
||||||
xasprintf(&final_win_action, "%s ; %s", win_action,
|
|
||||||
wcd ? wcd->command : "");
|
|
||||||
|
|
||||||
if (win_ses != win_max)
|
|
||||||
cur_win_template = final_win_template_middle;
|
|
||||||
else
|
|
||||||
cur_win_template = final_win_template_last;
|
|
||||||
|
|
||||||
window_choose_add_window(wl->window->active,
|
|
||||||
ctx, s2, wm, cur_win_template,
|
|
||||||
final_win_action,
|
|
||||||
(wflag && !sflag) ? win_ses : idx_ses);
|
|
||||||
|
|
||||||
free(final_win_action);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* If we're just drawing windows, don't consider moving on to
|
|
||||||
* other sessions as we only list windows in this session.
|
|
||||||
*/
|
|
||||||
if (wflag && !sflag)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
free(final_win_template_middle);
|
|
||||||
free(final_win_template_last);
|
|
||||||
|
|
||||||
window_choose_ready(wl->window->active, cur_win,
|
|
||||||
cmd_choose_tree_callback, cmd_choose_tree_free);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_choose_tree_callback(struct window_choose_data *cdata)
|
|
||||||
{
|
|
||||||
if (cdata == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (cdata->client->flags & CLIENT_DEAD)
|
|
||||||
return;
|
|
||||||
|
|
||||||
window_choose_ctx(cdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_choose_tree_free(struct window_choose_data *cdata)
|
|
||||||
{
|
|
||||||
cdata->session->references--;
|
|
||||||
cdata->client->references--;
|
|
||||||
|
|
||||||
free(cdata->ft_template);
|
|
||||||
free(cdata->command);
|
|
||||||
format_free(cdata->ft);
|
|
||||||
free(cdata);
|
|
||||||
|
|
||||||
}
|
|
||||||
181
cmd-choose-window.c
Normal file
181
cmd-choose-window.c
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
/* $Id: cmd-choose-window.c,v 1.24 2010-12-22 15:28:50 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_window_callback(void *, int);
|
||||||
|
void cmd_choose_window_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_window_entry = {
|
||||||
|
"choose-window", NULL,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
CMD_ARG01, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_choose_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_window_data {
|
||||||
|
struct client *client;
|
||||||
|
struct session *session;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct cmd_choose_window_data *cdata;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl, *wm;
|
||||||
|
struct window *w;
|
||||||
|
u_int idx, cur;
|
||||||
|
char flag, *title;
|
||||||
|
const char *left, *right;
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
cur = idx = 0;
|
||||||
|
RB_FOREACH(wm, winlinks, &s->windows) {
|
||||||
|
w = wm->window;
|
||||||
|
|
||||||
|
if (wm == s->curw)
|
||||||
|
cur = idx;
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
flag = ' ';
|
||||||
|
if (wm->flags & WINLINK_ACTIVITY)
|
||||||
|
flag = '#';
|
||||||
|
else if (wm->flags & WINLINK_BELL)
|
||||||
|
flag = '!';
|
||||||
|
else if (wm->flags & WINLINK_CONTENT)
|
||||||
|
flag = '+';
|
||||||
|
else if (wm->flags & WINLINK_SILENCE)
|
||||||
|
flag = '~';
|
||||||
|
else if (wm == s->curw)
|
||||||
|
flag = '*';
|
||||||
|
else if (wm == TAILQ_FIRST(&s->lastw))
|
||||||
|
flag = '-';
|
||||||
|
|
||||||
|
title = w->active->screen->title;
|
||||||
|
if (wm == wl)
|
||||||
|
title = w->active->base.title;
|
||||||
|
left = " \"";
|
||||||
|
right = "\"";
|
||||||
|
if (*title == '\0')
|
||||||
|
left = right = "";
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active,
|
||||||
|
wm->idx, "%3d: %s%c [%ux%u] (%u panes%s)%s%s%s",
|
||||||
|
wm->idx, w->name, flag, w->sx, w->sy, window_count_panes(w),
|
||||||
|
w->active->fd == -1 ? ", dead" : "",
|
||||||
|
left, title, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
cdata->template = xstrdup(data->arg);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("select-window -t '%%'");
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_window_callback, cmd_choose_window_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_window_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_window_data *cdata = data;
|
||||||
|
struct session *s = cdata->session;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *target, *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (!session_alive(s))
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xasprintf(&target, "%s:%d", s->name, idx);
|
||||||
|
template = cmd_template_replace(cdata->template, target, 1);
|
||||||
|
xfree(target);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_window_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_window_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->session->references--;
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-clear-history.c,v 1.8 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,31 +24,32 @@
|
|||||||
* Clear pane history.
|
* Clear pane history.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_clear_history_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_clear_history_entry = {
|
const struct cmd_entry cmd_clear_history_entry = {
|
||||||
"clear-history", "clearhist",
|
"clear-history", "clearhist",
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_PANE_USAGE,
|
CMD_TARGET_PANE_USAGE,
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_clear_history_exec
|
cmd_clear_history_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct grid *gd;
|
struct grid *gd;
|
||||||
|
|
||||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
gd = wp->base.grid;
|
gd = wp->base.grid;
|
||||||
|
|
||||||
grid_move_lines(gd, 0, gd->hsize, gd->sy);
|
grid_move_lines(gd, 0, gd->hsize, gd->sy);
|
||||||
gd->hsize = 0;
|
gd->hsize = 0;
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-clock-mode.c,v 1.7 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,28 +24,29 @@
|
|||||||
* Enter clock mode.
|
* Enter clock mode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_clock_mode_entry = {
|
const struct cmd_entry cmd_clock_mode_entry = {
|
||||||
"clock-mode", NULL,
|
"clock-mode", NULL,
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_PANE_USAGE,
|
CMD_TARGET_PANE_USAGE,
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_clock_mode_exec
|
cmd_clock_mode_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
|
|
||||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
window_pane_set_mode(wp, &window_clock_mode);
|
window_pane_set_mode(wp, &window_clock_mode);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-command-prompt.c,v 1.28 2010-05-14 14:33:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -19,9 +19,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -29,27 +27,34 @@
|
|||||||
* Prompt for command in client.
|
* Prompt for command in client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_command_prompt_key_binding(struct cmd *, int);
|
void cmd_command_prompt_init(struct cmd *, int);
|
||||||
int cmd_command_prompt_check(struct args *);
|
int cmd_command_prompt_parse(struct cmd *, int, char **, char **);
|
||||||
enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_command_prompt_free(struct cmd *);
|
||||||
|
size_t cmd_command_prompt_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
int cmd_command_prompt_callback(void *, const char *);
|
int cmd_command_prompt_callback(void *, const char *);
|
||||||
void cmd_command_prompt_free(void *);
|
void cmd_command_prompt_cfree(void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_command_prompt_entry = {
|
const struct cmd_entry cmd_command_prompt_entry = {
|
||||||
"command-prompt", NULL,
|
"command-prompt", NULL,
|
||||||
"I:p:t:", 0, 1,
|
CMD_TARGET_CLIENT_USAGE " [-p prompts] [template]",
|
||||||
"[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " [template]",
|
0, "",
|
||||||
0,
|
cmd_command_prompt_init,
|
||||||
cmd_command_prompt_key_binding,
|
cmd_command_prompt_parse,
|
||||||
NULL,
|
cmd_command_prompt_exec,
|
||||||
cmd_command_prompt_exec
|
cmd_command_prompt_free,
|
||||||
|
cmd_command_prompt_print
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_command_prompt_data {
|
||||||
|
char *prompts;
|
||||||
|
char *target;
|
||||||
|
char *template;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_command_prompt_cdata {
|
struct cmd_command_prompt_cdata {
|
||||||
struct client *c;
|
struct client *c;
|
||||||
char *inputs;
|
|
||||||
char *next_input;
|
|
||||||
char *next_prompt;
|
char *next_prompt;
|
||||||
char *prompts;
|
char *prompts;
|
||||||
char *template;
|
char *template;
|
||||||
@@ -57,91 +62,149 @@ struct cmd_command_prompt_cdata {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_command_prompt_key_binding(struct cmd *self, int key)
|
cmd_command_prompt_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
|
struct cmd_command_prompt_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->prompts = NULL;
|
||||||
|
data->target = NULL;
|
||||||
|
data->template = NULL;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case '$':
|
|
||||||
self->args = args_create(1, "rename-session '%%'");
|
|
||||||
args_set(self->args, 'I', "#S");
|
|
||||||
break;
|
|
||||||
case ',':
|
case ',':
|
||||||
self->args = args_create(1, "rename-window '%%'");
|
data->template = xstrdup("rename-window '%%'");
|
||||||
args_set(self->args, 'I', "#W");
|
|
||||||
break;
|
break;
|
||||||
case '.':
|
case '.':
|
||||||
self->args = args_create(1, "move-window -t '%%'");
|
data->template = xstrdup("move-window -t '%%'");
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
self->args = args_create(1, "find-window '%%'");
|
data->template = xstrdup("find-window '%%'");
|
||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
self->args = args_create(1, "select-window -t ':%%'");
|
data->template = xstrdup("select-window -t ':%%'");
|
||||||
args_set(self->args, 'p', "index");
|
data->prompts = xstrdup("index");
|
||||||
break;
|
|
||||||
default:
|
|
||||||
self->args = args_create(0);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
|
cmd_command_prompt_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_command_prompt_data *data;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "p:t:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'p':
|
||||||
|
if (data->prompts == NULL)
|
||||||
|
data->prompts = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 0 && argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
data->template = xstrdup(argv[0]);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_command_prompt_data *data = self->data;
|
||||||
const char *inputs, *prompts;
|
|
||||||
struct cmd_command_prompt_cdata *cdata;
|
struct cmd_command_prompt_cdata *cdata;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
char *prompt, *ptr, *input = NULL;
|
char *prompt, *ptr;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (c->prompt_string != NULL)
|
if (c->prompt_string != NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
cdata->c = c;
|
cdata->c = c;
|
||||||
cdata->idx = 1;
|
cdata->idx = 1;
|
||||||
cdata->inputs = NULL;
|
|
||||||
cdata->next_input = NULL;
|
|
||||||
cdata->next_prompt = NULL;
|
cdata->next_prompt = NULL;
|
||||||
cdata->prompts = NULL;
|
cdata->prompts = NULL;
|
||||||
cdata->template = NULL;
|
cdata->template = NULL;
|
||||||
|
|
||||||
if (args->argc != 0)
|
if (data->template != NULL)
|
||||||
cdata->template = xstrdup(args->argv[0]);
|
cdata->template = xstrdup(data->template);
|
||||||
else
|
else
|
||||||
cdata->template = xstrdup("%1");
|
cdata->template = xstrdup("%1");
|
||||||
|
if (data->prompts != NULL)
|
||||||
if ((prompts = args_get(args, 'p')) != NULL)
|
cdata->prompts = xstrdup(data->prompts);
|
||||||
cdata->prompts = xstrdup(prompts);
|
else if (data->template != NULL) {
|
||||||
else if (args->argc != 0) {
|
n = strcspn(data->template, " ,");
|
||||||
n = strcspn(cdata->template, " ,");
|
xasprintf(&cdata->prompts, "(%.*s) ", (int) n, data->template);
|
||||||
xasprintf(&cdata->prompts, "(%.*s) ", (int) n, cdata->template);
|
|
||||||
} else
|
} else
|
||||||
cdata->prompts = xstrdup(":");
|
cdata->prompts = xstrdup(":");
|
||||||
|
|
||||||
/* Get first prompt. */
|
|
||||||
cdata->next_prompt = cdata->prompts;
|
cdata->next_prompt = cdata->prompts;
|
||||||
ptr = strsep(&cdata->next_prompt, ",");
|
ptr = strsep(&cdata->next_prompt, ",");
|
||||||
if (prompts == NULL)
|
if (data->prompts == NULL)
|
||||||
prompt = xstrdup(ptr);
|
prompt = xstrdup(ptr);
|
||||||
else
|
else
|
||||||
xasprintf(&prompt, "%s ", ptr);
|
xasprintf(&prompt, "%s ", ptr);
|
||||||
|
status_prompt_set(c, prompt, cmd_command_prompt_callback,
|
||||||
|
cmd_command_prompt_cfree, cdata, 0);
|
||||||
|
xfree(prompt);
|
||||||
|
|
||||||
/* Get initial prompt input. */
|
return (0);
|
||||||
if ((inputs = args_get(args, 'I')) != NULL) {
|
}
|
||||||
cdata->inputs = xstrdup(inputs);
|
|
||||||
cdata->next_input = cdata->inputs;
|
|
||||||
input = strsep(&cdata->next_input, ",");
|
|
||||||
}
|
|
||||||
|
|
||||||
status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
|
void
|
||||||
cmd_command_prompt_free, cdata, 0);
|
cmd_command_prompt_free(struct cmd *self)
|
||||||
free(prompt);
|
{
|
||||||
|
struct cmd_command_prompt_data *data = self->data;
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
if (data->prompts != NULL)
|
||||||
|
xfree(data->prompts);
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
if (data->template != NULL)
|
||||||
|
xfree(data->template);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_command_prompt_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_command_prompt_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->prompts != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -p ", data->prompts);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->template != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->template);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -151,35 +214,28 @@ cmd_command_prompt_callback(void *data, const char *s)
|
|||||||
struct client *c = cdata->c;
|
struct client *c = cdata->c;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
struct cmd_ctx ctx;
|
struct cmd_ctx ctx;
|
||||||
char *cause, *new_template, *prompt, *ptr;
|
char *cause, *newtempl, *prompt, *ptr;
|
||||||
char *input = NULL;
|
|
||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
new_template = cmd_template_replace(cdata->template, s, cdata->idx);
|
newtempl = cmd_template_replace(cdata->template, s, cdata->idx);
|
||||||
free(cdata->template);
|
xfree(cdata->template);
|
||||||
cdata->template = new_template;
|
cdata->template = newtempl;
|
||||||
|
|
||||||
/*
|
|
||||||
* Check if there are more prompts; if so, get its respective input
|
|
||||||
* and update the prompt data.
|
|
||||||
*/
|
|
||||||
if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
|
if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
|
||||||
xasprintf(&prompt, "%s ", ptr);
|
xasprintf(&prompt, "%s ", ptr);
|
||||||
input = strsep(&cdata->next_input, ",");
|
status_prompt_update(c, prompt);
|
||||||
status_prompt_update(c, prompt, input);
|
xfree(prompt);
|
||||||
|
|
||||||
free(prompt);
|
|
||||||
cdata->idx++;
|
cdata->idx++;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd_string_parse(new_template, &cmdlist, &cause) != 0) {
|
if (cmd_string_parse(newtempl, &cmdlist, &cause) != 0) {
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
*cause = toupper((u_char) *cause);
|
*cause = toupper((u_char) *cause);
|
||||||
status_message_set(c, "%s", cause);
|
status_message_set(c, "%s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -202,12 +258,13 @@ cmd_command_prompt_callback(void *data, const char *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_command_prompt_free(void *data)
|
cmd_command_prompt_cfree(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_command_prompt_cdata *cdata = data;
|
struct cmd_command_prompt_cdata *cdata = data;
|
||||||
|
|
||||||
free(cdata->inputs);
|
if (cdata->prompts != NULL)
|
||||||
free(cdata->prompts);
|
xfree(cdata->prompts);
|
||||||
free(cdata->template);
|
if (cdata->template != NULL)
|
||||||
free(cdata);
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-confirm-before.c,v 1.12 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -26,20 +25,21 @@
|
|||||||
* Asks for confirmation before executing a command.
|
* Asks for confirmation before executing a command.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_confirm_before_key_binding(struct cmd *, int);
|
int cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *);
|
||||||
enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *);
|
void cmd_confirm_before_init(struct cmd *, int);
|
||||||
|
|
||||||
int cmd_confirm_before_callback(void *, const char *);
|
int cmd_confirm_before_callback(void *, const char *);
|
||||||
void cmd_confirm_before_free(void *);
|
void cmd_confirm_before_free(void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_confirm_before_entry = {
|
const struct cmd_entry cmd_confirm_before_entry = {
|
||||||
"confirm-before", "confirm",
|
"confirm-before", "confirm",
|
||||||
"p:t:", 1, 1,
|
CMD_TARGET_CLIENT_USAGE " command",
|
||||||
"[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
|
CMD_ARG1, "",
|
||||||
0,
|
cmd_confirm_before_init,
|
||||||
cmd_confirm_before_key_binding,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_confirm_before_exec,
|
||||||
cmd_confirm_before_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_confirm_before_data {
|
struct cmd_confirm_before_data {
|
||||||
@@ -48,58 +48,54 @@ struct cmd_confirm_before_data {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_confirm_before_key_binding(struct cmd *self, int key)
|
cmd_confirm_before_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case '&':
|
case '&':
|
||||||
self->args = args_create(1, "kill-window");
|
data->arg = xstrdup("kill-window");
|
||||||
args_set(self->args, 'p', "kill-window #W? (y/n)");
|
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
self->args = args_create(1, "kill-pane");
|
data->arg = xstrdup("kill-pane");
|
||||||
args_set(self->args, 'p', "kill-pane #P? (y/n)");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
self->args = args_create(0);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct cmd_confirm_before_data *cdata;
|
struct cmd_confirm_before_data *cdata;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
char *cmd, *copy, *new_prompt, *ptr;
|
char *buf, *cmd, *ptr;
|
||||||
const char *prompt;
|
|
||||||
|
|
||||||
if (ctx->curclient == NULL) {
|
if (ctx->curclient == NULL) {
|
||||||
ctx->error(ctx, "must be run interactively");
|
ctx->error(ctx, "must be run interactively");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if ((prompt = args_get(args, 'p')) != NULL)
|
ptr = xstrdup(data->arg);
|
||||||
xasprintf(&new_prompt, "%s ", prompt);
|
if ((cmd = strtok(ptr, " \t")) == NULL)
|
||||||
else {
|
cmd = ptr;
|
||||||
ptr = copy = xstrdup(args->argv[0]);
|
xasprintf(&buf, "Confirm '%s'? (y/n) ", cmd);
|
||||||
cmd = strsep(&ptr, " \t");
|
xfree(ptr);
|
||||||
xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
|
|
||||||
free(copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
cdata->cmd = xstrdup(args->argv[0]);
|
cdata->cmd = xstrdup(data->arg);
|
||||||
cdata->c = c;
|
cdata->c = c;
|
||||||
status_prompt_set(cdata->c, new_prompt, NULL,
|
status_prompt_set(cdata->c, buf,
|
||||||
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
||||||
PROMPT_SINGLE);
|
PROMPT_SINGLE);
|
||||||
|
|
||||||
free(new_prompt);
|
xfree(buf);
|
||||||
return (CMD_RETURN_YIELD);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -120,7 +116,7 @@ cmd_confirm_before_callback(void *data, const char *s)
|
|||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
*cause = toupper((u_char) *cause);
|
*cause = toupper((u_char) *cause);
|
||||||
status_message_set(c, "%s", cause);
|
status_message_set(c, "%s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -145,6 +141,7 @@ cmd_confirm_before_free(void *data)
|
|||||||
{
|
{
|
||||||
struct cmd_confirm_before_data *cdata = data;
|
struct cmd_confirm_before_data *cdata = data;
|
||||||
|
|
||||||
free(cdata->cmd);
|
if (cdata->cmd != NULL)
|
||||||
free(cdata);
|
xfree(cdata->cmd);
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
205
cmd-copy-buffer.c
Normal file
205
cmd-copy-buffer.c
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
/* $Id: cmd-copy-buffer.c,v 1.7 2009-11-28 14:50:36 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copies a session paste buffer to another session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_copy_buffer_parse(struct cmd *, int, char **, char **);
|
||||||
|
int cmd_copy_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_copy_buffer_free(struct cmd *);
|
||||||
|
void cmd_copy_buffer_init(struct cmd *, int);
|
||||||
|
size_t cmd_copy_buffer_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
|
struct cmd_copy_buffer_data {
|
||||||
|
char *dst_session;
|
||||||
|
char *src_session;
|
||||||
|
int dst_idx;
|
||||||
|
int src_idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_copy_buffer_entry = {
|
||||||
|
"copy-buffer", "copyb",
|
||||||
|
"[-a src-index] [-b dst-index] [-s src-session] [-t dst-session]",
|
||||||
|
0, "",
|
||||||
|
cmd_copy_buffer_init,
|
||||||
|
cmd_copy_buffer_parse,
|
||||||
|
cmd_copy_buffer_exec,
|
||||||
|
cmd_copy_buffer_free,
|
||||||
|
cmd_copy_buffer_print
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_copy_buffer_init(struct cmd *self, unused int arg)
|
||||||
|
{
|
||||||
|
struct cmd_copy_buffer_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->dst_session = NULL;
|
||||||
|
data->src_session = NULL;
|
||||||
|
data->dst_idx = -1;
|
||||||
|
data->src_idx = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_copy_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_copy_buffer_data *data;
|
||||||
|
const char *errstr;
|
||||||
|
int n, opt;
|
||||||
|
|
||||||
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "a:b:s:t:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'a':
|
||||||
|
if (data->src_idx == -1) {
|
||||||
|
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "buffer %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
data->src_idx = n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
if (data->dst_idx == -1) {
|
||||||
|
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "buffer %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
data->dst_idx = n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
if (data->src_session == NULL)
|
||||||
|
data->src_session = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->dst_session == NULL)
|
||||||
|
data->dst_session = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_copy_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_copy_buffer_data *data = self->data;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
struct paste_stack *dst_ps, *src_ps;
|
||||||
|
u_char *pdata;
|
||||||
|
struct session *dst_session, *src_session;
|
||||||
|
u_int limit;
|
||||||
|
|
||||||
|
if ((dst_session = cmd_find_session(ctx, data->dst_session)) == NULL ||
|
||||||
|
(src_session = cmd_find_session(ctx, data->src_session)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
dst_ps = &dst_session->buffers;
|
||||||
|
src_ps = &src_session->buffers;
|
||||||
|
|
||||||
|
if (data->src_idx == -1) {
|
||||||
|
if ((pb = paste_get_top(src_ps)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffers");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((pb = paste_get_index(src_ps, data->src_idx)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->src_idx);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
limit = options_get_number(&dst_session->options, "buffer-limit");
|
||||||
|
|
||||||
|
pdata = xmalloc(pb->size);
|
||||||
|
memcpy(pdata, pb->data, pb->size);
|
||||||
|
|
||||||
|
if (data->dst_idx == -1)
|
||||||
|
paste_add(dst_ps, pdata, pb->size, limit);
|
||||||
|
else if (paste_replace(dst_ps, data->dst_idx, pdata, pb->size) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->dst_idx);
|
||||||
|
xfree(pdata);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_copy_buffer_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_copy_buffer_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->dst_session != NULL)
|
||||||
|
xfree(data->dst_session);
|
||||||
|
if (data->src_session != NULL)
|
||||||
|
xfree(data->src_session);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_copy_buffer_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_copy_buffer_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->src_idx != -1) {
|
||||||
|
off += xsnprintf(buf + off, len - off, " -a %d",
|
||||||
|
data->src_idx);
|
||||||
|
}
|
||||||
|
if (off < len && data->dst_idx != -1) {
|
||||||
|
off += xsnprintf(buf + off, len - off, " -b %d",
|
||||||
|
data->dst_idx);
|
||||||
|
}
|
||||||
|
if (off < len && data->src_session != NULL) {
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -s ",
|
||||||
|
data->src_session);
|
||||||
|
}
|
||||||
|
if (off < len && data->dst_session != NULL) {
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ",
|
||||||
|
data->dst_session);
|
||||||
|
}
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-copy-mode.c,v 1.28 2010-08-11 22:18:28 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,41 +24,49 @@
|
|||||||
* Enter copy mode.
|
* Enter copy mode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_copy_mode_key_binding(struct cmd *, int);
|
void cmd_copy_mode_init(struct cmd *, int);
|
||||||
enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_copy_mode_entry = {
|
const struct cmd_entry cmd_copy_mode_entry = {
|
||||||
"copy-mode", NULL,
|
"copy-mode", NULL,
|
||||||
"t:u", 0, 0,
|
|
||||||
"[-u] " CMD_TARGET_PANE_USAGE,
|
"[-u] " CMD_TARGET_PANE_USAGE,
|
||||||
0,
|
0, "u",
|
||||||
cmd_copy_mode_key_binding,
|
cmd_copy_mode_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_copy_mode_exec
|
cmd_copy_mode_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_copy_mode_key_binding(struct cmd *self, int key)
|
cmd_copy_mode_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
self->args = args_create(0);
|
struct cmd_target_data *data;
|
||||||
if (key == KEYC_PPAGE)
|
|
||||||
args_set(self->args, 'u', NULL);
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case KEYC_PPAGE:
|
||||||
|
cmd_set_flag(&data->chflags, 'u');
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
|
|
||||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
|
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
window_copy_init_from_pane(wp);
|
window_copy_init_from_pane(wp);
|
||||||
if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
|
if (wp->mode == &window_copy_mode && cmd_check_flag(data->chflags, 'u'))
|
||||||
window_copy_pageup(wp);
|
window_copy_pageup(wp);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-delete-buffer.c,v 1.8 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,41 +26,34 @@
|
|||||||
* Delete a paste buffer.
|
* Delete a paste buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_delete_buffer_entry = {
|
const struct cmd_entry cmd_delete_buffer_entry = {
|
||||||
"delete-buffer", "deleteb",
|
"delete-buffer", "deleteb",
|
||||||
"b:", 0, 0,
|
CMD_BUFFER_SESSION_USAGE,
|
||||||
CMD_BUFFER_USAGE,
|
0, "",
|
||||||
0,
|
cmd_buffer_init,
|
||||||
NULL,
|
cmd_buffer_parse,
|
||||||
NULL,
|
cmd_delete_buffer_exec,
|
||||||
cmd_delete_buffer_exec
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
char *cause;
|
struct session *s;
|
||||||
int buffer;
|
|
||||||
|
|
||||||
if (!args_has(args, 'b')) {
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
paste_free_top(&global_buffers);
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
if (data->buffer == -1)
|
||||||
|
paste_free_top(&s->buffers);
|
||||||
|
else if (paste_free_index(&s->buffers, data->buffer) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
return (0);
|
||||||
if (cause != NULL) {
|
|
||||||
ctx->error(ctx, "buffer %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (paste_free_index(&global_buffers, buffer) != 0) {
|
|
||||||
ctx->error(ctx, "no buffer %d", buffer);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-detach-client.c,v 1.11 2010-02-08 18:27:34 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,57 +24,29 @@
|
|||||||
* Detach a client.
|
* Detach a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_detach_client_entry = {
|
const struct cmd_entry cmd_detach_client_entry = {
|
||||||
"detach-client", "detach",
|
"detach-client", "detach",
|
||||||
"as:t:P", 0, 0,
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
"[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
CMD_READONLY, "",
|
||||||
CMD_READONLY,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_detach_client_exec,
|
||||||
cmd_detach_client_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct client *c, *c2;
|
struct client *c;
|
||||||
struct session *s;
|
|
||||||
enum msgtype msgtype;
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
if (args_has(args, 'P'))
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
msgtype = MSG_DETACHKILL;
|
return (-1);
|
||||||
else
|
|
||||||
msgtype = MSG_DETACH;
|
|
||||||
|
|
||||||
if (args_has(args, 's')) {
|
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||||
s = cmd_find_session(ctx, args_get(args, 's'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
return (0);
|
||||||
c = ARRAY_ITEM(&clients, i);
|
|
||||||
if (c != NULL && c->session == s)
|
|
||||||
server_write_client(c, msgtype, NULL, 0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
c = cmd_find_client(ctx, args_get(args, 't'));
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-display-message.c,v 1.7 2009-11-28 14:39:53 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,74 +26,41 @@
|
|||||||
* Displays a message in the status line.
|
* Displays a message in the status line.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_display_message_entry = {
|
const struct cmd_entry cmd_display_message_entry = {
|
||||||
"display-message", "display",
|
"display-message", "display",
|
||||||
"c:pt:F:", 0, 1,
|
"[-p] " CMD_TARGET_CLIENT_USAGE " [message]",
|
||||||
"[-p] [-c target-client] [-t target-pane] [-F format] [message]",
|
CMD_ARG01, "p",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_display_message_exec,
|
||||||
cmd_display_message_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct session *s;
|
|
||||||
struct winlink *wl;
|
|
||||||
struct window_pane *wp;
|
|
||||||
const char *template;
|
const char *template;
|
||||||
char *msg;
|
char *msg;
|
||||||
struct format_tree *ft;
|
|
||||||
char out[BUFSIZ];
|
|
||||||
time_t t;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (args_has(args, 't')) {
|
if (data->arg == NULL)
|
||||||
wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
|
template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)";
|
||||||
if (wl == NULL)
|
else
|
||||||
return (CMD_RETURN_ERROR);
|
template = data->arg;
|
||||||
} else {
|
|
||||||
wl = cmd_find_pane(ctx, NULL, &s, &wp);
|
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'F') && args->argc != 0) {
|
msg = status_replace(c, NULL, template, time(NULL), 0);
|
||||||
ctx->error(ctx, "only one of -F or argument must be given");
|
if (cmd_check_flag(data->chflags, 'p'))
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
|
||||||
if (args->argc != 0)
|
|
||||||
template = args->argv[0];
|
|
||||||
if (template == NULL)
|
|
||||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
|
||||||
|
|
||||||
ft = format_create();
|
|
||||||
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));
|
|
||||||
out[len] = '\0';
|
|
||||||
|
|
||||||
msg = format_expand(ft, out);
|
|
||||||
if (args_has(self->args, 'p'))
|
|
||||||
ctx->print(ctx, "%s", msg);
|
ctx->print(ctx, "%s", msg);
|
||||||
else
|
else
|
||||||
status_message_set(c, "%s", msg);
|
status_message_set(c, "%s", msg);
|
||||||
|
xfree(msg);
|
||||||
|
|
||||||
free(msg);
|
return (0);
|
||||||
format_free(ft);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-display-panes.c,v 1.2 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,28 +24,29 @@
|
|||||||
* Display panes on a client.
|
* Display panes on a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_display_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_display_panes_entry = {
|
const struct cmd_entry cmd_display_panes_entry = {
|
||||||
"display-panes", "displayp",
|
"display-panes", "displayp",
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_CLIENT_USAGE,
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_display_panes_exec
|
cmd_display_panes_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
|
|
||||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
server_set_identify(c);
|
server_set_identify(c);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-find-window.c,v 1.15 2010-12-22 15:28:50 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -28,147 +27,93 @@
|
|||||||
* Find window containing text.
|
* Find window containing text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
void cmd_find_window_callback(struct window_choose_data *);
|
void cmd_find_window_callback(void *, int);
|
||||||
void cmd_find_window_free(struct window_choose_data *);
|
void cmd_find_window_free(void *);
|
||||||
|
|
||||||
/* Flags for determining matching behavior. */
|
|
||||||
#define CMD_FIND_WINDOW_BY_TITLE 0x1
|
|
||||||
#define CMD_FIND_WINDOW_BY_CONTENT 0x2
|
|
||||||
#define CMD_FIND_WINDOW_BY_NAME 0x4
|
|
||||||
|
|
||||||
#define CMD_FIND_WINDOW_ALL \
|
|
||||||
(CMD_FIND_WINDOW_BY_TITLE | \
|
|
||||||
CMD_FIND_WINDOW_BY_CONTENT | \
|
|
||||||
CMD_FIND_WINDOW_BY_NAME)
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_find_window_entry = {
|
const struct cmd_entry cmd_find_window_entry = {
|
||||||
"find-window", "findw",
|
"find-window", "findw",
|
||||||
"F:CNt:T", 1, 4,
|
CMD_TARGET_WINDOW_USAGE " match-string",
|
||||||
"[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string",
|
CMD_ARG1, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_find_window_exec,
|
||||||
cmd_find_window_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_find_window_data {
|
struct cmd_find_window_data {
|
||||||
struct winlink *wl;
|
struct session *session;
|
||||||
char *list_ctx;
|
|
||||||
u_int pane_id;
|
|
||||||
};
|
};
|
||||||
ARRAY_DECL(cmd_find_window_data_list, struct cmd_find_window_data);
|
|
||||||
|
|
||||||
u_int cmd_find_window_match_flags(struct args *);
|
int
|
||||||
void cmd_find_window_match(struct cmd_find_window_data_list *, int,
|
|
||||||
struct winlink *, const char *, const char *);
|
|
||||||
|
|
||||||
u_int
|
|
||||||
cmd_find_window_match_flags(struct args *args)
|
|
||||||
{
|
|
||||||
u_int match_flags = 0;
|
|
||||||
|
|
||||||
/* Turn on flags based on the options. */
|
|
||||||
if (args_has(args, 'T'))
|
|
||||||
match_flags |= CMD_FIND_WINDOW_BY_TITLE;
|
|
||||||
if (args_has(args, 'C'))
|
|
||||||
match_flags |= CMD_FIND_WINDOW_BY_CONTENT;
|
|
||||||
if (args_has(args, 'N'))
|
|
||||||
match_flags |= CMD_FIND_WINDOW_BY_NAME;
|
|
||||||
|
|
||||||
/* If none of the flags were set, default to matching anything. */
|
|
||||||
if (match_flags == 0)
|
|
||||||
match_flags = CMD_FIND_WINDOW_ALL;
|
|
||||||
|
|
||||||
return (match_flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
struct cmd_find_window_data find_data;
|
|
||||||
struct window_pane *wp;
|
|
||||||
u_int i, line;
|
|
||||||
char *sres;
|
|
||||||
|
|
||||||
memset(&find_data, 0, sizeof find_data);
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
|
||||||
i++;
|
|
||||||
|
|
||||||
if ((match_flags & CMD_FIND_WINDOW_BY_NAME) &&
|
|
||||||
fnmatch(searchstr, wl->window->name, 0) == 0) {
|
|
||||||
find_data.list_ctx = xstrdup("");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((match_flags & CMD_FIND_WINDOW_BY_TITLE) &&
|
|
||||||
fnmatch(searchstr, wp->base.title, 0) == 0) {
|
|
||||||
xasprintf(&find_data.list_ctx,
|
|
||||||
"pane %u title: \"%s\"", i - 1, wp->base.title);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match_flags & CMD_FIND_WINDOW_BY_CONTENT &&
|
|
||||||
(sres = window_pane_search(wp, str, &line)) != NULL) {
|
|
||||||
xasprintf(&find_data.list_ctx,
|
|
||||||
"pane %u line %u: \"%s\"", i - 1, line + 1, sres);
|
|
||||||
free(sres);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (find_data.list_ctx != NULL) {
|
|
||||||
find_data.wl = wl;
|
|
||||||
find_data.pane_id = i - 1;
|
|
||||||
ARRAY_ADD(find_list, find_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_choose_data *cdata;
|
struct cmd_find_window_data *cdata;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl, *wm;
|
struct winlink *wl, *wm;
|
||||||
struct cmd_find_window_data_list find_list;
|
struct window *w;
|
||||||
char *str, *searchstr;
|
struct window_pane *wp;
|
||||||
const char *template;
|
ARRAY_DECL(, u_int) list_idx;
|
||||||
u_int i, match_flags;
|
ARRAY_DECL(, char *) list_ctx;
|
||||||
|
char *sres, *sctx, *searchstr;
|
||||||
|
u_int i, line;
|
||||||
|
|
||||||
if (ctx->curclient == NULL) {
|
if (ctx->curclient == NULL) {
|
||||||
ctx->error(ctx, "must be run interactively");
|
ctx->error(ctx, "must be run interactively");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
s = ctx->curclient->session;
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
ARRAY_INIT(&list_idx);
|
||||||
template = FIND_WINDOW_TEMPLATE;
|
ARRAY_INIT(&list_ctx);
|
||||||
|
|
||||||
match_flags = cmd_find_window_match_flags(args);
|
xasprintf(&searchstr, "*%s*", data->arg);
|
||||||
str = args->argv[0];
|
RB_FOREACH(wm, winlinks, &s->windows) {
|
||||||
|
i = 0;
|
||||||
|
TAILQ_FOREACH(wp, &wm->window->panes, entry) {
|
||||||
|
i++;
|
||||||
|
|
||||||
ARRAY_INIT(&find_list);
|
if (fnmatch(searchstr, wm->window->name, 0) == 0)
|
||||||
|
sctx = xstrdup("");
|
||||||
|
else {
|
||||||
|
sres = window_pane_search(wp, data->arg, &line);
|
||||||
|
if (sres == NULL &&
|
||||||
|
fnmatch(searchstr, wp->base.title, 0) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
xasprintf(&searchstr, "*%s*", str);
|
if (sres == NULL) {
|
||||||
RB_FOREACH(wm, winlinks, &s->windows)
|
xasprintf(&sctx,
|
||||||
cmd_find_window_match (&find_list, match_flags, wm, str, searchstr);
|
"pane %u title: \"%s\"", i - 1,
|
||||||
free(searchstr);
|
wp->base.title);
|
||||||
|
} else {
|
||||||
|
xasprintf(&sctx,
|
||||||
|
"pane %u line %u: \"%s\"", i - 1,
|
||||||
|
line + 1, sres);
|
||||||
|
xfree(sres);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ARRAY_LENGTH(&find_list) == 0) {
|
ARRAY_ADD(&list_idx, wm->idx);
|
||||||
ctx->error(ctx, "no windows matching: %s", str);
|
ARRAY_ADD(&list_ctx, sctx);
|
||||||
ARRAY_FREE(&find_list);
|
}
|
||||||
return (CMD_RETURN_ERROR);
|
}
|
||||||
|
xfree(searchstr);
|
||||||
|
|
||||||
|
if (ARRAY_LENGTH(&list_idx) == 0) {
|
||||||
|
ctx->error(ctx, "no windows matching: %s", data->arg);
|
||||||
|
ARRAY_FREE(&list_idx);
|
||||||
|
ARRAY_FREE(&list_ctx);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ARRAY_LENGTH(&find_list) == 1) {
|
if (ARRAY_LENGTH(&list_idx) == 1) {
|
||||||
if (session_select(s, ARRAY_FIRST(&find_list).wl->idx) == 0)
|
if (session_select(s, ARRAY_FIRST(&list_idx)) == 0)
|
||||||
server_redraw_session(s);
|
server_redraw_session(s);
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
goto out;
|
goto out;
|
||||||
@@ -177,66 +122,54 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&find_list); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&list_idx); i++) {
|
||||||
wm = ARRAY_ITEM(&find_list, i).wl;
|
wm = winlink_find_by_index(
|
||||||
|
&s->windows, ARRAY_ITEM(&list_idx, i));
|
||||||
|
w = wm->window;
|
||||||
|
|
||||||
cdata = window_choose_data_create(ctx);
|
sctx = ARRAY_ITEM(&list_ctx, i);
|
||||||
cdata->idx = wm->idx;
|
window_choose_add(wl->window->active,
|
||||||
cdata->client->references++;
|
wm->idx, "%3d: %s [%ux%u] (%u panes) %s", wm->idx, w->name,
|
||||||
cdata->wl = wm;
|
w->sx, w->sy, window_count_panes(w), sctx);
|
||||||
|
xfree(sctx);
|
||||||
cdata->ft_template = xstrdup(template);
|
|
||||||
cdata->pane_id = ARRAY_ITEM(&find_list, i).pane_id;
|
|
||||||
|
|
||||||
format_add(cdata->ft, "line", "%u", i);
|
|
||||||
format_add(cdata->ft, "window_find_matches", "%s",
|
|
||||||
ARRAY_ITEM(&find_list, i).list_ctx);
|
|
||||||
format_session(cdata->ft, s);
|
|
||||||
format_winlink(cdata->ft, s, wm);
|
|
||||||
|
|
||||||
window_choose_add(wl->window->active, cdata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
|
||||||
window_choose_ready(wl->window->active,
|
window_choose_ready(wl->window->active,
|
||||||
0, cmd_find_window_callback, cmd_find_window_free);
|
0, cmd_find_window_callback, cmd_find_window_free, cdata);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
ARRAY_FREE(&find_list);
|
ARRAY_FREE(&list_idx);
|
||||||
return (CMD_RETURN_NORMAL);
|
ARRAY_FREE(&list_ctx);
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_find_window_callback(struct window_choose_data *cdata)
|
cmd_find_window_callback(void *data, int idx)
|
||||||
{
|
{
|
||||||
struct session *s;
|
struct cmd_find_window_data *cdata = data;
|
||||||
struct window_pane *wp;
|
struct session *s = cdata->session;
|
||||||
|
|
||||||
if (cdata == NULL)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
s = cdata->session;
|
|
||||||
if (!session_alive(s))
|
if (!session_alive(s))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wp = window_pane_at_index(cdata->wl->window, cdata->pane_id);
|
if (session_select(s, idx) == 0) {
|
||||||
if (wp != NULL && window_pane_visible(wp))
|
|
||||||
window_set_active_pane(cdata->wl->window, wp);
|
|
||||||
|
|
||||||
if (session_select(s, cdata->idx) == 0) {
|
|
||||||
server_redraw_session(s);
|
server_redraw_session(s);
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_find_window_free(struct window_choose_data *cdata)
|
cmd_find_window_free(void *data)
|
||||||
{
|
{
|
||||||
if (cdata == NULL)
|
struct cmd_find_window_data *cdata = data;
|
||||||
return;
|
|
||||||
|
|
||||||
cdata->session->references--;
|
cdata->session->references--;
|
||||||
|
xfree(cdata);
|
||||||
free(cdata->ft_template);
|
|
||||||
format_free(cdata->ft);
|
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|||||||
423
cmd-generic.c
Normal file
423
cmd-generic.c
Normal file
@@ -0,0 +1,423 @@
|
|||||||
|
/* $Id: cmd-generic.c,v 1.38 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
int cmd_getopt(int, char **, const char *, const char *);
|
||||||
|
int cmd_parse_flags(int, const char *, uint64_t *);
|
||||||
|
size_t cmd_print_flags(char *, size_t, size_t, uint64_t);
|
||||||
|
int cmd_fill_argument(int, char **, char **, int, char **);
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_prarg(char *buf, size_t len, const char *prefix, char *arg)
|
||||||
|
{
|
||||||
|
if (strchr(arg, ' ') != NULL)
|
||||||
|
return (xsnprintf(buf, len, "%s\"%s\"", prefix, arg));
|
||||||
|
return (xsnprintf(buf, len, "%s%s", prefix, arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Append two flag strings together and call getopt. */
|
||||||
|
int
|
||||||
|
cmd_getopt(int argc, char **argv, const char *flagstr, const char *chflagstr)
|
||||||
|
{
|
||||||
|
char tmp[BUFSIZ];
|
||||||
|
|
||||||
|
if (strlcpy(tmp, flagstr, sizeof tmp) >= sizeof tmp)
|
||||||
|
fatalx("strlcpy overflow");
|
||||||
|
if (strlcat(tmp, chflagstr, sizeof tmp) >= sizeof tmp)
|
||||||
|
fatalx("strlcat overflow");
|
||||||
|
return (getopt(argc, argv, tmp));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return if flag character is set. */
|
||||||
|
int
|
||||||
|
cmd_check_flag(uint64_t chflags, int flag)
|
||||||
|
{
|
||||||
|
if (flag >= 'A' && flag <= 'Z')
|
||||||
|
flag = 26 + flag - 'A';
|
||||||
|
else if (flag >= 'a' && flag <= 'z')
|
||||||
|
flag = flag - 'a';
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
return ((chflags & (1ULL << flag)) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set flag character. */
|
||||||
|
void
|
||||||
|
cmd_set_flag(uint64_t *chflags, int flag)
|
||||||
|
{
|
||||||
|
if (flag >= 'A' && flag <= 'Z')
|
||||||
|
flag = 26 + flag - 'A';
|
||||||
|
else if (flag >= 'a' && flag <= 'z')
|
||||||
|
flag = flag - 'a';
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
(*chflags) |= (1ULL << flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If this option is expected, set it in chflags, otherwise return -1. */
|
||||||
|
int
|
||||||
|
cmd_parse_flags(int opt, const char *chflagstr, uint64_t *chflags)
|
||||||
|
{
|
||||||
|
if (strchr(chflagstr, opt) == NULL)
|
||||||
|
return (-1);
|
||||||
|
cmd_set_flag(chflags, opt);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the flags present in chflags. */
|
||||||
|
size_t
|
||||||
|
cmd_print_flags(char *buf, size_t len, size_t off, uint64_t chflags)
|
||||||
|
{
|
||||||
|
u_char ch;
|
||||||
|
size_t boff = off;
|
||||||
|
|
||||||
|
if (chflags == 0)
|
||||||
|
return (0);
|
||||||
|
off += xsnprintf(buf + off, len - off, " -");
|
||||||
|
|
||||||
|
for (ch = 0; ch < 26; ch++) {
|
||||||
|
if (cmd_check_flag(chflags, 'a' + ch))
|
||||||
|
off += xsnprintf(buf + off, len - off, "%c", 'a' + ch);
|
||||||
|
if (cmd_check_flag(chflags, 'A' + ch))
|
||||||
|
off += xsnprintf(buf + off, len - off, "%c", 'A' + ch);
|
||||||
|
}
|
||||||
|
return (off - boff);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_fill_argument(int flags, char **arg, char **arg2, int argc, char **argv)
|
||||||
|
{
|
||||||
|
*arg = NULL;
|
||||||
|
*arg2 = NULL;
|
||||||
|
|
||||||
|
if (flags & CMD_ARG1) {
|
||||||
|
if (argc != 1)
|
||||||
|
return (-1);
|
||||||
|
*arg = xstrdup(argv[0]);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & CMD_ARG01) {
|
||||||
|
if (argc != 0 && argc != 1)
|
||||||
|
return (-1);
|
||||||
|
if (argc == 1)
|
||||||
|
*arg = xstrdup(argv[0]);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & CMD_ARG2) {
|
||||||
|
if (argc != 2)
|
||||||
|
return (-1);
|
||||||
|
*arg = xstrdup(argv[0]);
|
||||||
|
*arg2 = xstrdup(argv[1]);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & CMD_ARG12) {
|
||||||
|
if (argc != 1 && argc != 2)
|
||||||
|
return (-1);
|
||||||
|
*arg = xstrdup(argv[0]);
|
||||||
|
if (argc == 2)
|
||||||
|
*arg2 = xstrdup(argv[1]);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc != 0)
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_target_init(struct cmd *self, unused int key)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->chflags = 0;
|
||||||
|
data->target = NULL;
|
||||||
|
data->arg = NULL;
|
||||||
|
data->arg2 = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
const struct cmd_entry *entry = self->entry;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
/* Don't use the entry version since it may be dependent on key. */
|
||||||
|
cmd_target_init(self, 0);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = cmd_getopt(argc, argv, "t:", entry->chflags)) != -1) {
|
||||||
|
if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
|
||||||
|
continue;
|
||||||
|
switch (opt) {
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (cmd_fill_argument(
|
||||||
|
self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
|
||||||
|
goto usage;
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_target_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
xfree(data->arg);
|
||||||
|
if (data->arg2 != NULL)
|
||||||
|
xfree(data->arg2);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_target_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
off += cmd_print_flags(buf, len, off, data->chflags);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->arg != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||||
|
if (off < len && data->arg2 != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_srcdst_init(struct cmd *self, unused int key)
|
||||||
|
{
|
||||||
|
struct cmd_srcdst_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->chflags = 0;
|
||||||
|
data->src = NULL;
|
||||||
|
data->dst = NULL;
|
||||||
|
data->arg = NULL;
|
||||||
|
data->arg2 = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_srcdst_data *data;
|
||||||
|
const struct cmd_entry *entry = self->entry;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
cmd_srcdst_init(self, 0);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = cmd_getopt(argc, argv, "s:t:", entry->chflags)) != -1) {
|
||||||
|
if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
|
||||||
|
continue;
|
||||||
|
switch (opt) {
|
||||||
|
case 's':
|
||||||
|
if (data->src == NULL)
|
||||||
|
data->src = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->dst == NULL)
|
||||||
|
data->dst = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (cmd_fill_argument(
|
||||||
|
self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
|
||||||
|
goto usage;
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_srcdst_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_srcdst_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->src != NULL)
|
||||||
|
xfree(data->src);
|
||||||
|
if (data->dst != NULL)
|
||||||
|
xfree(data->dst);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
xfree(data->arg);
|
||||||
|
if (data->arg2 != NULL)
|
||||||
|
xfree(data->arg2);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_srcdst_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_srcdst_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
off += cmd_print_flags(buf, len, off, data->chflags);
|
||||||
|
if (off < len && data->src != NULL)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -s %s", data->src);
|
||||||
|
if (off < len && data->dst != NULL)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -t %s", data->dst);
|
||||||
|
if (off < len && data->arg != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||||
|
if (off < len && data->arg2 != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_buffer_init(struct cmd *self, unused int key)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->chflags = 0;
|
||||||
|
data->target = NULL;
|
||||||
|
data->buffer = -1;
|
||||||
|
data->arg = NULL;
|
||||||
|
data->arg2 = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data;
|
||||||
|
const struct cmd_entry *entry = self->entry;
|
||||||
|
int opt, n;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
|
cmd_buffer_init(self, 0);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = cmd_getopt(argc, argv, "b:t:", entry->chflags)) != -1) {
|
||||||
|
if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
|
||||||
|
continue;
|
||||||
|
switch (opt) {
|
||||||
|
case 'b':
|
||||||
|
if (data->buffer == -1) {
|
||||||
|
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "buffer %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
data->buffer = n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (cmd_fill_argument(
|
||||||
|
self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
|
||||||
|
goto usage;
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_buffer_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
xfree(data->arg);
|
||||||
|
if (data->arg2 != NULL)
|
||||||
|
xfree(data->arg2);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_buffer_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
off += cmd_print_flags(buf, len, off, data->chflags);
|
||||||
|
if (off < len && data->buffer != -1)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -b %d", data->buffer);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->arg != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||||
|
if (off < len && data->arg2 != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-has-session.c,v 1.15 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,25 +24,26 @@
|
|||||||
* Cause client to report an error and exit with 1 if session doesn't exist.
|
* 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_ctx *);
|
int cmd_has_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_has_session_entry = {
|
const struct cmd_entry cmd_has_session_entry = {
|
||||||
"has-session", "has",
|
"has-session", "has",
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_SESSION_USAGE,
|
CMD_TARGET_SESSION_USAGE,
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_has_session_exec
|
cmd_has_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
|
|
||||||
if (cmd_find_session(ctx, args_get(args, 't'), 0) == NULL)
|
if (cmd_find_session(ctx, data->target) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-if-shell.c,v 1.10 2010-08-09 21:44:25 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -20,49 +20,44 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Executes a tmux command if a shell command returns true or false.
|
* Executes a tmux command if a shell command returns true.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
void cmd_if_shell_callback(struct job *);
|
void cmd_if_shell_callback(struct job *);
|
||||||
void cmd_if_shell_free(void *);
|
void cmd_if_shell_free(void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_if_shell_entry = {
|
const struct cmd_entry cmd_if_shell_entry = {
|
||||||
"if-shell", "if",
|
"if-shell", "if",
|
||||||
"", 2, 3,
|
"shell-command command",
|
||||||
"shell-command command [command]",
|
CMD_ARG2, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_if_shell_exec,
|
||||||
cmd_if_shell_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_if_shell_data {
|
struct cmd_if_shell_data {
|
||||||
char *cmd_if;
|
char *cmd;
|
||||||
char *cmd_else;
|
|
||||||
struct cmd_ctx ctx;
|
struct cmd_ctx ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct cmd_if_shell_data *cdata;
|
struct cmd_if_shell_data *cdata;
|
||||||
const char *shellcmd = args->argv[0];
|
struct job *job;
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
cdata->cmd_if = xstrdup(args->argv[1]);
|
cdata->cmd = xstrdup(data->arg2);
|
||||||
if (args->argc == 3)
|
|
||||||
cdata->cmd_else = xstrdup(args->argv[2]);
|
|
||||||
else
|
|
||||||
cdata->cmd_else = NULL;
|
|
||||||
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||||
|
|
||||||
if (ctx->cmdclient != NULL)
|
if (ctx->cmdclient != NULL)
|
||||||
@@ -70,9 +65,11 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
if (ctx->curclient != NULL)
|
if (ctx->curclient != NULL)
|
||||||
ctx->curclient->references++;
|
ctx->curclient->references++;
|
||||||
|
|
||||||
job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata);
|
job = job_add(NULL, 0, NULL,
|
||||||
|
data->arg, cmd_if_shell_callback, cmd_if_shell_free, cdata);
|
||||||
|
job_run(job);
|
||||||
|
|
||||||
return (CMD_RETURN_YIELD); /* don't let client exit */
|
return (1); /* don't let client exit */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -81,23 +78,24 @@ cmd_if_shell_callback(struct job *job)
|
|||||||
struct cmd_if_shell_data *cdata = job->data;
|
struct cmd_if_shell_data *cdata = job->data;
|
||||||
struct cmd_ctx *ctx = &cdata->ctx;
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
char *cause, *cmd;
|
char *cause;
|
||||||
|
|
||||||
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0) {
|
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
||||||
cmd = cdata->cmd_else;
|
return;
|
||||||
if (cmd == NULL)
|
|
||||||
return;
|
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||||
} else
|
|
||||||
cmd = cdata->cmd_if;
|
|
||||||
if (cmd_string_parse(cmd, &cmdlist, &cause) != 0) {
|
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
ctx->error(ctx, "%s", cause);
|
ctx->error(ctx, "%s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_list_exec(cmdlist, ctx);
|
if (cmd_list_exec(cmdlist, ctx) < 0) {
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cmd_list_free(cmdlist);
|
cmd_list_free(cmdlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,15 +104,16 @@ cmd_if_shell_free(void *data)
|
|||||||
{
|
{
|
||||||
struct cmd_if_shell_data *cdata = data;
|
struct cmd_if_shell_data *cdata = data;
|
||||||
struct cmd_ctx *ctx = &cdata->ctx;
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
struct msg_exit_data exitdata;
|
||||||
|
|
||||||
if (ctx->cmdclient != NULL) {
|
if (ctx->cmdclient != NULL) {
|
||||||
ctx->cmdclient->references--;
|
ctx->cmdclient->references--;
|
||||||
|
exitdata.retcode = ctx->cmdclient->retcode;
|
||||||
ctx->cmdclient->flags |= CLIENT_EXIT;
|
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||||
}
|
}
|
||||||
if (ctx->curclient != NULL)
|
if (ctx->curclient != NULL)
|
||||||
ctx->curclient->references--;
|
ctx->curclient->references--;
|
||||||
|
|
||||||
free(cdata->cmd_else);
|
xfree(cdata->cmd);
|
||||||
free(cdata->cmd_if);
|
xfree(cdata);
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|||||||
242
cmd-join-pane.c
242
cmd-join-pane.c
@@ -1,7 +1,6 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-join-pane.c,v 1.5 2010-08-11 22:17:32 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
|
|
||||||
* Copyright (c) 2009 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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -25,115 +24,167 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Join or move a pane into another (like split/swap/kill).
|
* Join a pane into another (like split/swap/kill).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_join_pane_key_binding(struct cmd *, int);
|
int cmd_join_pane_parse(struct cmd *, int, char **, char **);
|
||||||
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_join_pane_free(struct cmd *);
|
||||||
|
void cmd_join_pane_init(struct cmd *, int);
|
||||||
|
size_t cmd_join_pane_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
enum cmd_retval join_pane(struct cmd *, struct cmd_ctx *, int);
|
struct cmd_join_pane_data {
|
||||||
|
char *src;
|
||||||
|
char *dst;
|
||||||
|
int flag_detached;
|
||||||
|
int flag_horizontal;
|
||||||
|
int percentage;
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_join_pane_entry = {
|
const struct cmd_entry cmd_join_pane_entry = {
|
||||||
"join-pane", "joinp",
|
"join-pane", "joinp",
|
||||||
"bdhvp:l:s:t:", 0, 0,
|
"[-dhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
|
||||||
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
|
0, "",
|
||||||
0,
|
cmd_join_pane_init,
|
||||||
cmd_join_pane_key_binding,
|
cmd_join_pane_parse,
|
||||||
NULL,
|
cmd_join_pane_exec,
|
||||||
cmd_join_pane_exec
|
cmd_join_pane_free,
|
||||||
};
|
cmd_join_pane_print
|
||||||
|
|
||||||
const struct cmd_entry cmd_move_pane_entry = {
|
|
||||||
"move-pane", "movep",
|
|
||||||
"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
|
void
|
||||||
cmd_join_pane_key_binding(struct cmd *self, int key)
|
cmd_join_pane_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
|
struct cmd_join_pane_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->src = NULL;
|
||||||
|
data->dst = NULL;
|
||||||
|
data->flag_detached = 0;
|
||||||
|
data->flag_horizontal = 0;
|
||||||
|
data->percentage = -1;
|
||||||
|
data->size = -1;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case '%':
|
case '%':
|
||||||
self->args = args_create(0);
|
data->flag_horizontal = 1;
|
||||||
args_set(self->args, 'h', NULL);
|
|
||||||
break;
|
break;
|
||||||
default:
|
case '"':
|
||||||
self->args = args_create(0);
|
data->flag_horizontal = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_join_pane_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
{
|
{
|
||||||
return (join_pane(self, ctx, self->entry == &cmd_join_pane_entry));
|
struct cmd_join_pane_data *data;
|
||||||
|
int opt;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "dhl:p:s:t:v")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'd':
|
||||||
|
data->flag_detached = 1;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
data->flag_horizontal = 1;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
if (data->src == NULL)
|
||||||
|
data->src = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->dst == NULL)
|
||||||
|
data->dst = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
if (data->percentage != -1 || data->size != -1)
|
||||||
|
break;
|
||||||
|
data->size = strtonum(optarg, 1, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "size %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
if (data->size != -1 || data->percentage != -1)
|
||||||
|
break;
|
||||||
|
data->percentage = strtonum(optarg, 1, 100, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "percentage %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
data->flag_horizontal = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 0)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
|
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_join_pane_data *data = self->data;
|
||||||
struct session *dst_s;
|
struct session *dst_s;
|
||||||
struct winlink *src_wl, *dst_wl;
|
struct winlink *src_wl, *dst_wl;
|
||||||
struct window *src_w, *dst_w;
|
struct window *src_w, *dst_w;
|
||||||
struct window_pane *src_wp, *dst_wp;
|
struct window_pane *src_wp, *dst_wp;
|
||||||
char *cause;
|
int size, dst_idx;
|
||||||
int size, percentage, dst_idx;
|
enum layout_type type;
|
||||||
enum layout_type type;
|
struct layout_cell *lc;
|
||||||
struct layout_cell *lc;
|
|
||||||
|
|
||||||
dst_wl = cmd_find_pane(ctx, args_get(args, 't'), &dst_s, &dst_wp);
|
if ((dst_wl = cmd_find_pane(ctx, data->dst, &dst_s, &dst_wp)) == NULL)
|
||||||
if (dst_wl == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
dst_w = dst_wl->window;
|
dst_w = dst_wl->window;
|
||||||
dst_idx = dst_wl->idx;
|
dst_idx = dst_wl->idx;
|
||||||
|
|
||||||
src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp);
|
if ((src_wl = cmd_find_pane(ctx, data->src, NULL, &src_wp)) == NULL)
|
||||||
if (src_wl == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
src_w = src_wl->window;
|
src_w = src_wl->window;
|
||||||
|
|
||||||
if (not_same_window && src_w == dst_w) {
|
if (src_w == dst_w) {
|
||||||
ctx->error(ctx, "can't join a pane to its own window");
|
ctx->error(ctx, "can't join a pane to its own window");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
|
||||||
if (!not_same_window && src_wp == dst_wp) {
|
|
||||||
ctx->error(ctx, "source and target panes must be different");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type = LAYOUT_TOPBOTTOM;
|
type = LAYOUT_TOPBOTTOM;
|
||||||
if (args_has(args, 'h'))
|
if (data->flag_horizontal)
|
||||||
type = LAYOUT_LEFTRIGHT;
|
type = LAYOUT_LEFTRIGHT;
|
||||||
|
|
||||||
size = -1;
|
size = -1;
|
||||||
if (args_has(args, 'l')) {
|
if (data->size != -1)
|
||||||
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
size = data->size;
|
||||||
if (cause != NULL) {
|
else if (data->percentage != -1) {
|
||||||
ctx->error(ctx, "size %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
} else if (args_has(args, 'p')) {
|
|
||||||
percentage = args_strtonum(args, 'p', 0, 100, &cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
ctx->error(ctx, "percentage %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (type == LAYOUT_TOPBOTTOM)
|
if (type == LAYOUT_TOPBOTTOM)
|
||||||
size = (dst_wp->sy * percentage) / 100;
|
size = (dst_wp->sy * data->percentage) / 100;
|
||||||
else
|
else
|
||||||
size = (dst_wp->sx * percentage) / 100;
|
size = (dst_wp->sx * data->percentage) / 100;
|
||||||
}
|
}
|
||||||
lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'));
|
|
||||||
if (lc == NULL) {
|
if ((lc = layout_split_pane(dst_wp, type, size)) == NULL) {
|
||||||
ctx->error(ctx, "create pane failed: pane too small");
|
ctx->error(ctx, "create pane failed: pane too small");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
layout_close_pane(src_wp);
|
layout_close_pane(src_wp);
|
||||||
@@ -147,8 +198,6 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
|
|||||||
|
|
||||||
if (window_count_panes(src_w) == 0)
|
if (window_count_panes(src_w) == 0)
|
||||||
server_kill_window(src_w);
|
server_kill_window(src_w);
|
||||||
else
|
|
||||||
notify_window_layout_changed(src_w);
|
|
||||||
|
|
||||||
src_wp->window = dst_w;
|
src_wp->window = dst_w;
|
||||||
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
||||||
@@ -159,13 +208,50 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
|
|||||||
server_redraw_window(src_w);
|
server_redraw_window(src_w);
|
||||||
server_redraw_window(dst_w);
|
server_redraw_window(dst_w);
|
||||||
|
|
||||||
if (!args_has(args, 'd')) {
|
if (!data->flag_detached) {
|
||||||
window_set_active_pane(dst_w, src_wp);
|
window_set_active_pane(dst_w, src_wp);
|
||||||
session_select(dst_s, dst_idx);
|
session_select(dst_s, dst_idx);
|
||||||
server_redraw_session(dst_s);
|
server_redraw_session(dst_s);
|
||||||
} else
|
} else
|
||||||
server_status_session(dst_s);
|
server_status_session(dst_s);
|
||||||
|
|
||||||
notify_window_layout_changed(dst_w);
|
return (0);
|
||||||
return (CMD_RETURN_NORMAL);
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_join_pane_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_join_pane_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->src != NULL)
|
||||||
|
xfree(data->src);
|
||||||
|
if (data->dst != NULL)
|
||||||
|
xfree(data->dst);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_join_pane_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_join_pane_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->flag_detached)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && data->flag_horizontal)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -h");
|
||||||
|
if (off < len && data->size > 0)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -l %d", data->size);
|
||||||
|
if (off < len && data->percentage > 0) {
|
||||||
|
off += xsnprintf(
|
||||||
|
buf + off, len - off, " -p %d", data->percentage);
|
||||||
|
}
|
||||||
|
if (off < len && data->src != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -s ", data->src);
|
||||||
|
if (off < len && data->dst != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->dst);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-kill-pane.c,v 1.15 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,41 +26,45 @@
|
|||||||
* Kill pane.
|
* Kill pane.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_kill_pane_entry = {
|
const struct cmd_entry cmd_kill_pane_entry = {
|
||||||
"kill-pane", "killp",
|
"kill-pane", "killp",
|
||||||
"at:", 0, 0,
|
|
||||||
"[-a] " CMD_TARGET_PANE_USAGE,
|
"[-a] " CMD_TARGET_PANE_USAGE,
|
||||||
0,
|
0, "a",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_kill_pane_exec
|
cmd_kill_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct window_pane *loopwp, *tmpwp, *wp;
|
struct window_pane *loopwp, *nextwp, *wp;
|
||||||
|
|
||||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (window_count_panes(wl->window) == 1) {
|
if (window_count_panes(wl->window) == 1) {
|
||||||
/* Only one pane, kill the window. */
|
/* Only one pane, kill the window. */
|
||||||
server_kill_window(wl->window);
|
server_kill_window(wl->window);
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(self->args, 'a')) {
|
if (cmd_check_flag(data->chflags, 'a')) {
|
||||||
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
|
loopwp = TAILQ_FIRST(&wl->window->panes);
|
||||||
if (loopwp == wp)
|
while (loopwp != NULL) {
|
||||||
continue;
|
nextwp = TAILQ_NEXT(loopwp, entry);
|
||||||
layout_close_pane(loopwp);
|
if (loopwp != wp) {
|
||||||
window_remove_pane(wl->window, loopwp);
|
layout_close_pane(loopwp);
|
||||||
|
window_remove_pane(wl->window, loopwp);
|
||||||
|
}
|
||||||
|
loopwp = nextwp;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
layout_close_pane(wp);
|
layout_close_pane(wp);
|
||||||
@@ -68,5 +72,5 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
server_redraw_window(wl->window);
|
server_redraw_window(wl->window);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-kill-server.c,v 1.11 2009-11-28 14:50:36 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -27,23 +27,24 @@
|
|||||||
* Kill the server and do nothing else.
|
* Kill the server and do nothing else.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_kill_server_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_kill_server_entry = {
|
const struct cmd_entry cmd_kill_server_entry = {
|
||||||
"kill-server", NULL,
|
"kill-server", NULL,
|
||||||
"", 0, 0,
|
|
||||||
"",
|
"",
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
cmd_kill_server_exec
|
cmd_kill_server_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
kill(getpid(), SIGTERM);
|
kill(getpid(), SIGTERM);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-kill-session.c,v 1.18 2010-07-02 02:43:50 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -27,37 +27,30 @@
|
|||||||
* Note this deliberately has no alias to make it hard to hit by accident.
|
* Note this deliberately has no alias to make it hard to hit by accident.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_kill_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_kill_session_entry = {
|
const struct cmd_entry cmd_kill_session_entry = {
|
||||||
"kill-session", NULL,
|
"kill-session", NULL,
|
||||||
"at:", 0, 0,
|
CMD_TARGET_SESSION_USAGE,
|
||||||
"[-a] " CMD_TARGET_SESSION_USAGE,
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_kill_session_exec,
|
||||||
cmd_kill_session_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s, *s2, *s3;
|
struct session *s;
|
||||||
|
|
||||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
server_destroy_session(s);
|
||||||
RB_FOREACH_SAFE(s2, sessions, &sessions, s3) {
|
session_destroy(s);
|
||||||
if (s != s2) {
|
|
||||||
server_destroy_session(s2);
|
return (0);
|
||||||
session_destroy(s2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
server_destroy_session(s);
|
|
||||||
session_destroy(s);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-kill-window.c,v 1.21 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,36 +24,30 @@
|
|||||||
* Destroy window.
|
* Destroy window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_kill_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_kill_window_entry = {
|
const struct cmd_entry cmd_kill_window_entry = {
|
||||||
"kill-window", "killw",
|
"kill-window", "killw",
|
||||||
"at:", 0, 0,
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
"[-a] " CMD_TARGET_WINDOW_USAGE,
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_kill_window_exec,
|
||||||
cmd_kill_window_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl, *wl2, *wl3;
|
struct winlink *wl;
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
server_kill_window(wl->window);
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
58
cmd-last-pane.c
Normal file
58
cmd-last-pane.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/* $Id: cmd-last-pane.c,v 1.1 2010-10-24 01:34:30 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move to last pane.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_last_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_last_pane_entry = {
|
||||||
|
"last-pane", "lastp",
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_last_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_last_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
|
if (w->last == NULL) {
|
||||||
|
ctx->error(ctx, "no last pane");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
window_set_active_pane(w, w->last);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
58
cmd-last-window.c
Normal file
58
cmd-last-window.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/* $Id: cmd-last-window.c,v 1.19 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move to last window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_last_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_last_window_entry = {
|
||||||
|
"last-window", "last",
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_last_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_last_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (session_last(s) == 0)
|
||||||
|
server_redraw_session(s);
|
||||||
|
else {
|
||||||
|
ctx->error(ctx, "no last window");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-link-window.c,v 1.36 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,40 +26,41 @@
|
|||||||
* Link a window into another session.
|
* Link a window into another session.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_link_window_entry = {
|
const struct cmd_entry cmd_link_window_entry = {
|
||||||
"link-window", "linkw",
|
"link-window", "linkw",
|
||||||
"dks:t:", 0, 0,
|
|
||||||
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
0,
|
0, "dk",
|
||||||
NULL,
|
cmd_srcdst_init,
|
||||||
NULL,
|
cmd_srcdst_parse,
|
||||||
cmd_link_window_exec
|
cmd_link_window_exec,
|
||||||
|
cmd_srcdst_free,
|
||||||
|
cmd_srcdst_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_srcdst_data *data = self->data;
|
||||||
struct session *src, *dst;
|
struct session *src, *dst;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
char *cause;
|
char *cause;
|
||||||
int idx, kflag, dflag;
|
int idx, kflag, dflag;
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2)
|
if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
kflag = args_has(self->args, 'k');
|
kflag = cmd_check_flag(data->chflags, 'k');
|
||||||
dflag = args_has(self->args, 'd');
|
dflag = cmd_check_flag(data->chflags, 'd');
|
||||||
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||||
ctx->error(ctx, "can't link window: %s", cause);
|
ctx->error(ctx, "can't link window: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-list-buffers.c,v 1.16 2010-06-22 23:35:20 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,44 +26,38 @@
|
|||||||
* List paste buffers.
|
* List paste buffers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_buffers_entry = {
|
const struct cmd_entry cmd_list_buffers_entry = {
|
||||||
"list-buffers", "lsb",
|
"list-buffers", "lsb",
|
||||||
"F:", 0, 0,
|
CMD_TARGET_SESSION_USAGE,
|
||||||
"[-F format]",
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_list_buffers_exec,
|
||||||
cmd_list_buffers_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ARGSUSED */
|
int
|
||||||
enum cmd_retval
|
cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
struct format_tree *ft;
|
|
||||||
u_int idx;
|
u_int idx;
|
||||||
char *line;
|
char *tmp;
|
||||||
const char *template;
|
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
template = LIST_BUFFERS_TEMPLATE;
|
return (-1);
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
|
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
||||||
ft = format_create();
|
tmp = paste_print(pb, 50);
|
||||||
format_add(ft, "line", "%u", idx - 1);
|
ctx->print(ctx,
|
||||||
format_paste_buffer(ft, pb);
|
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||||
|
xfree(tmp);
|
||||||
line = format_expand(ft, template);
|
|
||||||
ctx->print(ctx, "%s", line);
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-list-clients.c,v 1.20 2009-11-28 14:50:36 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@@ -32,55 +31,36 @@ int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
|
|||||||
|
|
||||||
const struct cmd_entry cmd_list_clients_entry = {
|
const struct cmd_entry cmd_list_clients_entry = {
|
||||||
"list-clients", "lsc",
|
"list-clients", "lsc",
|
||||||
"F:t:", 0, 0,
|
"",
|
||||||
"[-F format] " CMD_TARGET_SESSION_USAGE,
|
0, "",
|
||||||
CMD_READONLY,
|
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
cmd_list_clients_exec
|
cmd_list_clients_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_list_clients_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct client *c;
|
||||||
struct client *c;
|
u_int i;
|
||||||
struct session *s;
|
const char *s_utf8;
|
||||||
struct format_tree *ft;
|
|
||||||
const char *template;
|
|
||||||
u_int i;
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
if (args_has(args, 't')) {
|
|
||||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
} else
|
|
||||||
s = NULL;
|
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = LIST_CLIENTS_TEMPLATE;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
c = ARRAY_ITEM(&clients, i);
|
c = ARRAY_ITEM(&clients, i);
|
||||||
if (c == NULL || c->session == NULL)
|
if (c == NULL || c->session == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (s != NULL && s != c->session)
|
if (c->tty.flags & TTY_UTF8)
|
||||||
continue;
|
s_utf8 = " (utf8)";
|
||||||
|
else
|
||||||
ft = format_create();
|
s_utf8 = "";
|
||||||
format_add(ft, "line", "%u", i);
|
ctx->print(ctx, "%s: %s [%ux%u %s]%s", c->tty.path,
|
||||||
format_session(ft, c->session);
|
c->session->name, c->tty.sx, c->tty.sy,
|
||||||
format_client(ft, c);
|
c->tty.termname, s_utf8);
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
|
||||||
ctx->print(ctx, "%s", line);
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-list-commands.c,v 1.7 2009-11-28 14:50:36 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,20 +24,21 @@
|
|||||||
* List all commands with usages.
|
* List all commands with usages.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_commands_entry = {
|
const struct cmd_entry cmd_list_commands_entry = {
|
||||||
"list-commands", "lscm",
|
"list-commands", "lscm",
|
||||||
"", 0, 0,
|
|
||||||
"",
|
"",
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
cmd_list_commands_exec
|
cmd_list_commands_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
const struct cmd_entry **entryp;
|
const struct cmd_entry **entryp;
|
||||||
@@ -45,5 +46,5 @@ cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
for (entryp = cmd_table; *entryp != NULL; entryp++)
|
for (entryp = cmd_table; *entryp != NULL; entryp++)
|
||||||
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
|
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
102
cmd-list-keys.c
102
cmd-list-keys.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-list-keys.c,v 1.25 2010-10-24 01:31:57 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,123 +26,109 @@
|
|||||||
* List key bindings.
|
* List key bindings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||||
enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_ctx *);
|
|
||||||
|
int cmd_list_keys_table(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_keys_entry = {
|
const struct cmd_entry cmd_list_keys_entry = {
|
||||||
"list-keys", "lsk",
|
"list-keys", "lsk",
|
||||||
"t:", 0, 0,
|
|
||||||
"[-t key-table]",
|
"[-t key-table]",
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_list_keys_exec
|
cmd_list_keys_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct key_binding *bd;
|
struct key_binding *bd;
|
||||||
const char *key;
|
const char *key;
|
||||||
char tmp[BUFSIZ], flags[8];
|
char tmp[BUFSIZ];
|
||||||
size_t used;
|
size_t used;
|
||||||
int width, keywidth;
|
int width, keywidth;
|
||||||
|
|
||||||
if (args_has(args, 't'))
|
if (data->target != NULL)
|
||||||
return (cmd_list_keys_table(self, ctx));
|
return (cmd_list_keys_table(self, ctx));
|
||||||
|
|
||||||
width = 0;
|
width = 0;
|
||||||
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
RB_FOREACH(bd, key_bindings, &key_bindings) {
|
|
||||||
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
keywidth = strlen(key);
|
keywidth = strlen(key) + 1;
|
||||||
if (!(bd->key & KEYC_PREFIX)) {
|
if (!(bd->key & KEYC_PREFIX))
|
||||||
if (bd->can_repeat)
|
keywidth += 2;
|
||||||
keywidth += 4;
|
|
||||||
else
|
|
||||||
keywidth += 3;
|
|
||||||
} else if (bd->can_repeat)
|
|
||||||
keywidth += 3;
|
|
||||||
if (keywidth > width)
|
if (keywidth > width)
|
||||||
width = keywidth;
|
width = keywidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_FOREACH(bd, key_bindings, &key_bindings) {
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
used = xsnprintf(tmp, sizeof tmp, "%*s: ", width, key);
|
||||||
*flags = '\0';
|
|
||||||
if (!(bd->key & KEYC_PREFIX)) {
|
|
||||||
if (bd->can_repeat)
|
|
||||||
xsnprintf(flags, sizeof flags, "-rn ");
|
|
||||||
else
|
|
||||||
xsnprintf(flags, sizeof flags, "-n ");
|
|
||||||
} else if (bd->can_repeat)
|
|
||||||
xsnprintf(flags, sizeof flags, "-r ");
|
|
||||||
|
|
||||||
used = xsnprintf(tmp, sizeof tmp, "%s%*s ",
|
|
||||||
flags, (int) (width - strlen(flags)), key);
|
|
||||||
if (used >= sizeof tmp)
|
if (used >= sizeof tmp)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (!(bd->key & KEYC_PREFIX)) {
|
||||||
|
used = strlcat(tmp, "(no prefix) ", sizeof tmp);
|
||||||
|
if (used >= sizeof tmp)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (bd->can_repeat) {
|
||||||
|
used = strlcat(tmp, "(repeat) ", sizeof tmp);
|
||||||
|
if (used >= sizeof tmp)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used);
|
cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used);
|
||||||
ctx->print(ctx, "bind-key %s", tmp);
|
ctx->print(ctx, "%s", tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
const char *tablename;
|
|
||||||
const struct mode_key_table *mtab;
|
const struct mode_key_table *mtab;
|
||||||
struct mode_key_binding *mbind;
|
struct mode_key_binding *mbind;
|
||||||
const char *key, *cmdstr, *mode;
|
const char *key, *cmdstr, *mode;
|
||||||
int width, keywidth, any_mode;
|
int width, keywidth;
|
||||||
|
|
||||||
tablename = args_get(args, 't');
|
if ((mtab = mode_key_findtable(data->target)) == NULL) {
|
||||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
ctx->error(ctx, "unknown key table: %s", data->target);
|
||||||
ctx->error(ctx, "unknown key table: %s", tablename);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
width = 0;
|
width = 0;
|
||||||
any_mode = 0;
|
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
|
||||||
key = key_string_lookup_key(mbind->key);
|
key = key_string_lookup_key(mbind->key);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (mbind->mode != 0)
|
keywidth = strlen(key) + 1;
|
||||||
any_mode = 1;
|
|
||||||
|
|
||||||
keywidth = strlen(key);
|
|
||||||
if (keywidth > width)
|
if (keywidth > width)
|
||||||
width = keywidth;
|
width = keywidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
key = key_string_lookup_key(mbind->key);
|
key = key_string_lookup_key(mbind->key);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mode = "";
|
mode = "";
|
||||||
if (mbind->mode != 0)
|
if (mbind->mode != 0)
|
||||||
mode = "c";
|
mode = "(command mode) ";
|
||||||
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
|
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
|
||||||
if (cmdstr != NULL) {
|
if (cmdstr != NULL)
|
||||||
ctx->print(ctx, "bind-key -%st %s%s %*s %s",
|
ctx->print(ctx, "%*s: %s%s", width, key, mode, cmdstr);
|
||||||
mode, any_mode && *mode == '\0' ? " " : "",
|
|
||||||
mtab->name, (int) width, key, cmdstr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
132
cmd-list-panes.c
132
cmd-list-panes.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-list-panes.c,v 1.6 2010-12-06 21:56:32 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,118 +26,51 @@
|
|||||||
* List panes on given window.
|
* List panes on given window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
void cmd_list_panes_server(struct cmd *, struct cmd_ctx *);
|
|
||||||
void cmd_list_panes_session(
|
|
||||||
struct cmd *, struct session *, struct cmd_ctx *, int);
|
|
||||||
void cmd_list_panes_window(struct cmd *,
|
|
||||||
struct session *, struct winlink *, struct cmd_ctx *, int);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_panes_entry = {
|
const struct cmd_entry cmd_list_panes_entry = {
|
||||||
"list-panes", "lsp",
|
"list-panes", "lsp",
|
||||||
"asF:t:", 0, 0,
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
"[-as] [-F format] [-t target]",
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_list_panes_exec,
|
||||||
cmd_list_panes_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
struct winlink *wl;
|
||||||
struct winlink *wl;
|
|
||||||
|
|
||||||
if (args_has(args, 'a'))
|
|
||||||
cmd_list_panes_server(self, ctx);
|
|
||||||
else if (args_has(args, 's')) {
|
|
||||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
cmd_list_panes_session(self, s, ctx, 1);
|
|
||||||
} else {
|
|
||||||
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
cmd_list_panes_window(self, s, wl, ctx, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_list_panes_server(struct cmd *self, struct cmd_ctx *ctx)
|
|
||||||
{
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions)
|
|
||||||
cmd_list_panes_session(self, s, ctx, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_list_panes_session(
|
|
||||||
struct cmd *self, struct session *s, struct cmd_ctx *ctx, int type)
|
|
||||||
{
|
|
||||||
struct winlink *wl;
|
|
||||||
|
|
||||||
RB_FOREACH(wl, winlinks, &s->windows)
|
|
||||||
cmd_list_panes_window(self, s, wl, ctx, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_list_panes_window(struct cmd *self,
|
|
||||||
struct session *s, struct winlink *wl, struct cmd_ctx *ctx, int type)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int n;
|
struct grid *gd;
|
||||||
struct format_tree *ft;
|
struct grid_line *gl;
|
||||||
const char *template;
|
u_int i, n;
|
||||||
char *line;
|
unsigned long long size;
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
if (template == NULL) {
|
return (-1);
|
||||||
switch (type) {
|
|
||||||
case 0:
|
|
||||||
template = "#{pane_index}: "
|
|
||||||
"[#{pane_width}x#{pane_height}] [history "
|
|
||||||
"#{history_size}/#{history_limit}, "
|
|
||||||
"#{history_bytes} bytes] #{pane_id}"
|
|
||||||
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
template = "#{window_index}.#{pane_index}: "
|
|
||||||
"[#{pane_width}x#{pane_height}] [history "
|
|
||||||
"#{history_size}/#{history_limit}, "
|
|
||||||
"#{history_bytes} bytes] #{pane_id}"
|
|
||||||
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
template = "#{session_name}:#{window_index}.#{pane_index}: "
|
|
||||||
"[#{pane_width}x#{pane_height}] [history "
|
|
||||||
"#{history_size}/#{history_limit}, "
|
|
||||||
"#{history_bytes} bytes] #{pane_id}"
|
|
||||||
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||||
ft = format_create();
|
gd = wp->base.grid;
|
||||||
format_add(ft, "line", "%u", n);
|
|
||||||
format_session(ft, s);
|
|
||||||
format_winlink(ft, s, wl);
|
|
||||||
format_window_pane(ft, wp);
|
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
size = 0;
|
||||||
ctx->print(ctx, "%s", line);
|
for (i = 0; i < gd->hsize; i++) {
|
||||||
free(line);
|
gl = &gd->linedata[i];
|
||||||
|
size += gl->cellsize * sizeof *gl->celldata;
|
||||||
|
size += gl->utf8size * sizeof *gl->utf8data;
|
||||||
|
}
|
||||||
|
size += gd->hsize * sizeof *gd->linedata;
|
||||||
|
|
||||||
format_free(ft);
|
ctx->print(ctx, "%u: [%ux%u] [history %u/%u, %llu bytes]%s%s",
|
||||||
|
n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size,
|
||||||
|
wp == wp->window->active ? " (active)" : "",
|
||||||
|
wp->fd == -1 ? " (dead)" : "");
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-list-sessions.c,v 1.26 2010-12-22 15:36:44 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@@ -28,44 +27,45 @@
|
|||||||
* List all sessions.
|
* List all sessions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_sessions_entry = {
|
const struct cmd_entry cmd_list_sessions_entry = {
|
||||||
"list-sessions", "ls",
|
"list-sessions", "ls", "",
|
||||||
"F:", 0, 0,
|
0, "",
|
||||||
"[-F format]",
|
|
||||||
0,
|
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
cmd_list_sessions_exec
|
cmd_list_sessions_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx)
|
int
|
||||||
|
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
|
||||||
struct session *s;
|
struct session *s;
|
||||||
u_int n;
|
struct session_group *sg;
|
||||||
struct format_tree *ft;
|
char *tim, tmp[64];
|
||||||
const char *template;
|
u_int idx;
|
||||||
char *line;
|
time_t t;
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = LIST_SESSIONS_TEMPLATE;
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
ft = format_create();
|
sg = session_group_find(s);
|
||||||
format_add(ft, "line", "%u", n);
|
if (sg == NULL)
|
||||||
format_session(ft, s);
|
*tmp = '\0';
|
||||||
|
else {
|
||||||
|
idx = session_group_index(sg);
|
||||||
|
xsnprintf(tmp, sizeof tmp, " (group %u)", idx);
|
||||||
|
}
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
t = s->creation_time.tv_sec;
|
||||||
ctx->print(ctx, "%s", line);
|
tim = ctime(&t);
|
||||||
free(line);
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
format_free(ft);
|
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s",
|
||||||
n++;
|
s->name, winlink_count(&s->windows), tim, s->sx, s->sy,
|
||||||
|
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-list-windows.c,v 1.44 2010-12-06 21:56:32 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,84 +26,37 @@
|
|||||||
* List windows on given session.
|
* List windows on given session.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
void cmd_list_windows_server(struct cmd *, struct cmd_ctx *);
|
|
||||||
void cmd_list_windows_session(
|
|
||||||
struct cmd *, struct session *, struct cmd_ctx *, int);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_windows_entry = {
|
const struct cmd_entry cmd_list_windows_entry = {
|
||||||
"list-windows", "lsw",
|
"list-windows", "lsw",
|
||||||
"F:at:", 0, 0,
|
CMD_TARGET_SESSION_USAGE,
|
||||||
"[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_list_windows_exec,
|
||||||
cmd_list_windows_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
|
|
||||||
if (args_has(args, 'a'))
|
|
||||||
cmd_list_windows_server(self, ctx);
|
|
||||||
else {
|
|
||||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
cmd_list_windows_session(self, s, ctx, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_list_windows_server(struct cmd *self, struct cmd_ctx *ctx)
|
|
||||||
{
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions)
|
|
||||||
cmd_list_windows_session(self, s, ctx, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_list_windows_session(
|
|
||||||
struct cmd *self, struct session *s, struct cmd_ctx *ctx, int type)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
u_int n;
|
char *layout;
|
||||||
struct format_tree *ft;
|
|
||||||
const char *template;
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
if (template == NULL) {
|
return (-1);
|
||||||
switch (type) {
|
|
||||||
case 0:
|
|
||||||
template = LIST_WINDOWS_TEMPLATE;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
template = LIST_WINDOWS_WITH_SESSION_TEMPLATE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
ft = format_create();
|
layout = layout_dump(wl->window);
|
||||||
format_add(ft, "line", "%u", n);
|
ctx->print(ctx, "%d: %s [%ux%u] [layout %s]%s",
|
||||||
format_session(ft, s);
|
wl->idx, wl->window->name, wl->window->sx, wl->window->sy,
|
||||||
format_winlink(ft, s, wl);
|
layout, wl == s->curw ? " (active)" : "");
|
||||||
|
xfree(layout);
|
||||||
line = format_expand(ft, template);
|
|
||||||
ctx->print(ctx, "%s", line);
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
n++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
51
cmd-list.c
51
cmd-list.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-list.c,v 1.10 2010-12-06 21:48:56 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -79,39 +78,28 @@ bad:
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct client *c = ctx->curclient;
|
|
||||||
struct cmd *cmd;
|
struct cmd *cmd;
|
||||||
enum cmd_retval retval;
|
int n, retval;
|
||||||
int guards, n;
|
|
||||||
|
|
||||||
guards = 0;
|
|
||||||
if (c != NULL && c->session != NULL)
|
|
||||||
guards = c->flags & CLIENT_CONTROL;
|
|
||||||
|
|
||||||
notify_disable();
|
|
||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
if (guards)
|
if ((n = cmd_exec(cmd, ctx)) == -1)
|
||||||
ctx->print(ctx, "%%begin");
|
return (-1);
|
||||||
n = cmd_exec(cmd, ctx);
|
|
||||||
if (guards)
|
|
||||||
ctx->print(ctx, "%%end");
|
|
||||||
|
|
||||||
switch (n)
|
/*
|
||||||
{
|
* A 1 return value means the command client is being attached
|
||||||
case CMD_RETURN_ERROR:
|
* (sent MSG_READY).
|
||||||
return (CMD_RETURN_ERROR);
|
*/
|
||||||
case CMD_RETURN_ATTACH:
|
if (n == 1) {
|
||||||
/* Client is being attached (send MSG_READY). */
|
retval = 1;
|
||||||
retval = CMD_RETURN_ATTACH;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mangle the context to treat any following commands
|
* The command client has been attached, so mangle the
|
||||||
* as if they were called from inside.
|
* context to treat any following commands as if they
|
||||||
|
* were called from inside.
|
||||||
*/
|
*/
|
||||||
if (ctx->curclient == NULL) {
|
if (ctx->curclient == NULL) {
|
||||||
ctx->curclient = ctx->cmdclient;
|
ctx->curclient = ctx->cmdclient;
|
||||||
@@ -121,17 +109,8 @@ cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
|||||||
ctx->print = key_bindings_print;
|
ctx->print = key_bindings_print;
|
||||||
ctx->info = key_bindings_info;
|
ctx->info = key_bindings_info;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case CMD_RETURN_YIELD:
|
|
||||||
if (retval == CMD_RETURN_NORMAL)
|
|
||||||
retval = CMD_RETURN_YIELD;
|
|
||||||
break;
|
|
||||||
case CMD_RETURN_NORMAL:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notify_enable();
|
|
||||||
return (retval);
|
return (retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +127,7 @@ cmd_list_free(struct cmd_list *cmdlist)
|
|||||||
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
||||||
cmd_free(cmd);
|
cmd_free(cmd);
|
||||||
}
|
}
|
||||||
free(cmdlist);
|
xfree(cmdlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-load-buffer.c,v 1.18 2010-12-22 15:28:50 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -27,77 +27,73 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Loads a paste buffer from a file.
|
* Loads a session paste buffer from a file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
void cmd_load_buffer_callback(struct client *, int, void *);
|
void cmd_load_buffer_callback(struct client *, void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_load_buffer_entry = {
|
const struct cmd_entry cmd_load_buffer_entry = {
|
||||||
"load-buffer", "loadb",
|
"load-buffer", "loadb",
|
||||||
"b:", 1, 1,
|
CMD_BUFFER_SESSION_USAGE " path",
|
||||||
CMD_BUFFER_USAGE " path",
|
CMD_ARG1, "",
|
||||||
0,
|
cmd_buffer_init,
|
||||||
NULL,
|
cmd_buffer_parse,
|
||||||
NULL,
|
cmd_load_buffer_exec,
|
||||||
cmd_load_buffer_exec
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
struct cmd_load_buffer_cdata {
|
||||||
|
struct session *session;
|
||||||
|
int buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct client *c = ctx->cmdclient;
|
struct cmd_load_buffer_cdata *cdata;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
FILE *f;
|
struct client *c = ctx->cmdclient;
|
||||||
const char *path, *newpath, *wd;
|
FILE *f;
|
||||||
char *pdata, *new_pdata, *cause;
|
char *pdata, *new_pdata;
|
||||||
size_t psize;
|
size_t psize;
|
||||||
u_int limit;
|
u_int limit;
|
||||||
int ch, error, buffer, *buffer_ptr;
|
int ch;
|
||||||
|
|
||||||
if (!args_has(args, 'b'))
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
buffer = -1;
|
return (-1);
|
||||||
else {
|
|
||||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
if (strcmp(data->arg, "-") == 0) {
|
||||||
if (cause != NULL) {
|
if (c == NULL) {
|
||||||
ctx->error(ctx, "buffer %s", cause);
|
ctx->error(ctx, "%s: can't read from stdin", data->arg);
|
||||||
free(cause);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
if (c->flags & CLIENT_TERMINAL) {
|
||||||
|
ctx->error(ctx, "%s: stdin is a tty", data->arg);
|
||||||
path = args->argv[0];
|
return (-1);
|
||||||
if (strcmp(path, "-") == 0) {
|
|
||||||
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) {
|
|
||||||
ctx->error(ctx, "%s: %s", path, cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
return (CMD_RETURN_YIELD);
|
if (c->stdin_fd == -1) {
|
||||||
|
ctx->error(ctx, "%s: can't read from stdin", data->arg);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
cdata->buffer = data->buffer;
|
||||||
|
c->stdin_data = cdata;
|
||||||
|
c->stdin_callback = cmd_load_buffer_callback;
|
||||||
|
|
||||||
|
c->references++;
|
||||||
|
bufferevent_enable(c->stdin_event, EV_READ);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c != NULL)
|
if ((f = fopen(data->arg, "rb")) == NULL) {
|
||||||
wd = c->cwd;
|
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||||
else if ((s = cmd_current_session(ctx, 0)) != NULL) {
|
return (-1);
|
||||||
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) {
|
|
||||||
ctx->error(ctx, "%s: %s", path, strerror(errno));
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pdata = NULL;
|
pdata = NULL;
|
||||||
@@ -112,66 +108,78 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
pdata[psize++] = ch;
|
pdata[psize++] = ch;
|
||||||
}
|
}
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
ctx->error(ctx, "%s: read error", path);
|
ctx->error(ctx, "%s: read error", data->arg);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (pdata != NULL)
|
if (pdata != NULL)
|
||||||
pdata[psize] = '\0';
|
pdata[psize] = '\0';
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
f = NULL;
|
||||||
|
|
||||||
limit = options_get_number(&global_options, "buffer-limit");
|
limit = options_get_number(&s->options, "buffer-limit");
|
||||||
if (buffer == -1) {
|
if (data->buffer == -1) {
|
||||||
paste_add(&global_buffers, pdata, psize, limit);
|
paste_add(&s->buffers, pdata, psize, limit);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
|
if (paste_replace(&s->buffers, data->buffer, pdata, psize) != 0) {
|
||||||
ctx->error(ctx, "no buffer %d", buffer);
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
free(pdata);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(pdata);
|
if (pdata != NULL)
|
||||||
|
xfree(pdata);
|
||||||
if (f != NULL)
|
if (f != NULL)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_load_buffer_callback(struct client *c, int closed, void *data)
|
cmd_load_buffer_callback(struct client *c, void *data)
|
||||||
{
|
{
|
||||||
int *buffer = data;
|
struct cmd_load_buffer_cdata *cdata = data;
|
||||||
char *pdata;
|
struct session *s = cdata->session;
|
||||||
size_t psize;
|
char *pdata;
|
||||||
u_int limit;
|
size_t psize;
|
||||||
|
u_int limit;
|
||||||
|
|
||||||
if (!closed)
|
/*
|
||||||
return;
|
* Event callback has already checked client is not dead and reduced
|
||||||
c->stdin_callback = NULL;
|
* its reference count. But tell it to exit.
|
||||||
|
*/
|
||||||
c->references--;
|
|
||||||
c->flags |= CLIENT_EXIT;
|
c->flags |= CLIENT_EXIT;
|
||||||
|
|
||||||
psize = EVBUFFER_LENGTH(c->stdin_data);
|
/* Does the target session still exist? */
|
||||||
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL) {
|
if (!session_alive(s))
|
||||||
free(data);
|
goto out;
|
||||||
return;
|
|
||||||
}
|
psize = EVBUFFER_LENGTH(c->stdin_event->input);
|
||||||
memcpy(pdata, EVBUFFER_DATA(c->stdin_data), psize);
|
if (psize == 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
pdata = malloc(psize + 1);
|
||||||
|
if (pdata == NULL)
|
||||||
|
goto out;
|
||||||
|
bufferevent_read(c->stdin_event, pdata, psize);
|
||||||
pdata[psize] = '\0';
|
pdata[psize] = '\0';
|
||||||
evbuffer_drain(c->stdin_data, psize);
|
|
||||||
|
|
||||||
limit = options_get_number(&global_options, "buffer-limit");
|
limit = options_get_number(&s->options, "buffer-limit");
|
||||||
if (*buffer == -1)
|
if (cdata->buffer == -1) {
|
||||||
paste_add(&global_buffers, pdata, psize, limit);
|
paste_add(&s->buffers, pdata, psize, limit);
|
||||||
else if (paste_replace(&global_buffers, *buffer, pdata, psize) != 0) {
|
goto out;
|
||||||
|
}
|
||||||
|
if (paste_replace(&s->buffers, cdata->buffer, pdata, psize) != 0) {
|
||||||
/* No context so can't use server_client_msg_error. */
|
/* No context so can't use server_client_msg_error. */
|
||||||
evbuffer_add_printf(c->stderr_data, "no buffer %d\n", *buffer);
|
evbuffer_add_printf(
|
||||||
server_push_stderr(c);
|
c->stderr_event->output, "no buffer %d\n", cdata->buffer);
|
||||||
|
bufferevent_enable(c->stderr_event, EV_WRITE);
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(data);
|
out:
|
||||||
|
cdata->session->references--;
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-lock-client.c,v 1.2 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,24 +18,36 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <event.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
char *
|
/*
|
||||||
osdep_get_name(unused int fd, unused char *tty)
|
* Lock a single client.
|
||||||
{
|
*/
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
int cmd_lock_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
osdep_get_cwd(unused int fd)
|
|
||||||
{
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct event_base *
|
const struct cmd_entry cmd_lock_client_entry = {
|
||||||
osdep_event_init(void)
|
"lock-client", "lockc",
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_lock_client_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_lock_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
return (event_init());
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct client *c;
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
server_lock_client(c);
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-lock-server.c,v 1.9 2009-11-28 14:50:36 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -25,61 +25,28 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lock commands.
|
* Lock server.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_lock_server_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_lock_server_entry = {
|
const struct cmd_entry cmd_lock_server_entry = {
|
||||||
"lock-server", "lock",
|
"lock-server", "lock",
|
||||||
"", 0, 0,
|
|
||||||
"",
|
"",
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
cmd_lock_server_exec
|
cmd_lock_server_exec,
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_lock_session_entry = {
|
|
||||||
"lock-session", "locks",
|
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_SESSION_USAGE,
|
|
||||||
0,
|
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
cmd_lock_server_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_lock_client_entry = {
|
|
||||||
"lock-client", "lockc",
|
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_CLIENT_USAGE,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
cmd_lock_server_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
cmd_lock_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
server_lock();
|
||||||
struct client *c;
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_lock_server_entry)
|
|
||||||
server_lock();
|
|
||||||
else if (self->entry == &cmd_lock_session_entry) {
|
|
||||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
server_lock_session(s);
|
|
||||||
} else {
|
|
||||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
server_lock_client(c);
|
|
||||||
}
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-lock-session.c,v 1.2 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,24 +18,36 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <event.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
char *
|
/*
|
||||||
osdep_get_name(unused int fd, unused char *tty)
|
* Lock all clients attached to a session.
|
||||||
{
|
*/
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
int cmd_lock_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
osdep_get_cwd(unused int fd)
|
|
||||||
{
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct event_base *
|
const struct cmd_entry cmd_lock_session_entry = {
|
||||||
osdep_event_init(void)
|
"lock-session", "locks",
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_lock_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_lock_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
return (event_init());
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
server_lock_session(s);
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-move-window.c,v 1.13 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,51 +26,42 @@
|
|||||||
* Move a window.
|
* Move a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_move_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_move_window_entry = {
|
const struct cmd_entry cmd_move_window_entry = {
|
||||||
"move-window", "movew",
|
"move-window", "movew",
|
||||||
"dkrs:t:", 0, 0,
|
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
"[-dkr] " CMD_SRCDST_WINDOW_USAGE,
|
0, "dk",
|
||||||
0,
|
cmd_srcdst_init,
|
||||||
NULL,
|
cmd_srcdst_parse,
|
||||||
NULL,
|
cmd_move_window_exec,
|
||||||
cmd_move_window_exec
|
cmd_srcdst_free,
|
||||||
|
cmd_srcdst_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_srcdst_data *data = self->data;
|
||||||
struct session *src, *dst, *s;
|
struct session *src, *dst;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
char *cause;
|
char *cause;
|
||||||
int idx, kflag, dflag;
|
int idx, kflag, dflag;
|
||||||
|
|
||||||
if (args_has(args, 'r')) {
|
if ((wl = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
session_renumber_windows(s);
|
kflag = cmd_check_flag(data->chflags, 'k');
|
||||||
recalculate_sizes();
|
dflag = cmd_check_flag(data->chflags, 'd');
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
if ((idx = cmd_find_index(ctx, 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) {
|
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||||
ctx->error(ctx, "can't move window: %s", cause);
|
ctx->error(ctx, "can't move window: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
server_unlink_window(src, wl);
|
server_unlink_window(src, wl);
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-new-session.c,v 1.80 2010-12-22 15:31:00 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -30,62 +29,119 @@
|
|||||||
* Create a new session and attach to the current terminal unless -d is given.
|
* Create a new session and attach to the current terminal unless -d is given.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_new_session_check(struct args *);
|
int cmd_new_session_parse(struct cmd *, int, char **, char **);
|
||||||
enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_new_session_free(struct cmd *);
|
||||||
|
void cmd_new_session_init(struct cmd *, int);
|
||||||
|
size_t cmd_new_session_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
|
struct cmd_new_session_data {
|
||||||
|
char *target;
|
||||||
|
char *newname;
|
||||||
|
char *winname;
|
||||||
|
char *cmd;
|
||||||
|
int flag_detached;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_new_session_entry = {
|
const struct cmd_entry cmd_new_session_entry = {
|
||||||
"new-session", "new",
|
"new-session", "new",
|
||||||
"dn:s:t:x:y:", 0, 1,
|
"[-d] [-n window-name] [-s session-name] [-t target-session] [command]",
|
||||||
"[-d] [-n window-name] [-s session-name] [-t target-session] "
|
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON, "",
|
||||||
"[-x width] [-y height] [command]",
|
cmd_new_session_init,
|
||||||
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
|
cmd_new_session_parse,
|
||||||
NULL,
|
cmd_new_session_exec,
|
||||||
cmd_new_session_check,
|
cmd_new_session_free,
|
||||||
cmd_new_session_exec
|
cmd_new_session_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_new_session_check(struct args *args)
|
void
|
||||||
|
cmd_new_session_init(struct cmd *self, unused int arg)
|
||||||
{
|
{
|
||||||
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n')))
|
struct cmd_new_session_data *data;
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->flag_detached = 0;
|
||||||
|
data->target = NULL;
|
||||||
|
data->newname = NULL;
|
||||||
|
data->winname = NULL;
|
||||||
|
data->cmd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_new_session_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_new_session_data *data;
|
||||||
struct session *s, *old_s, *groupwith;
|
int opt;
|
||||||
struct window *w;
|
|
||||||
struct window_pane *wp;
|
|
||||||
struct environ env;
|
|
||||||
struct termios tio, *tiop;
|
|
||||||
struct passwd *pw;
|
|
||||||
const char *newname, *target, *update, *cwd, *errstr;
|
|
||||||
char *cmd, *cause;
|
|
||||||
int detached, idx;
|
|
||||||
u_int sx, sy, i;
|
|
||||||
|
|
||||||
newname = args_get(args, 's');
|
self->entry->init(self, KEYC_NONE);
|
||||||
if (newname != NULL) {
|
data = self->data;
|
||||||
if (!session_check_name(newname)) {
|
|
||||||
ctx->error(ctx, "bad session name: %s", newname);
|
while ((opt = getopt(argc, argv, "ds:t:n:")) != -1) {
|
||||||
return (CMD_RETURN_ERROR);
|
switch (opt) {
|
||||||
}
|
case 'd':
|
||||||
if (session_find(newname) != NULL) {
|
data->flag_detached = 1;
|
||||||
ctx->error(ctx, "duplicate session: %s", newname);
|
break;
|
||||||
return (CMD_RETURN_ERROR);
|
case 's':
|
||||||
|
if (data->newname == NULL)
|
||||||
|
data->newname = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
if (data->winname == NULL)
|
||||||
|
data->winname = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 0 && argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
target = args_get(args, 't');
|
if (data->target != NULL && (argc == 1 || data->winname != NULL))
|
||||||
if (target != NULL) {
|
goto usage;
|
||||||
groupwith = cmd_find_session(ctx, target, 0);
|
|
||||||
if (groupwith == NULL)
|
if (argc == 1)
|
||||||
return (CMD_RETURN_ERROR);
|
data->cmd = xstrdup(argv[0]);
|
||||||
} else
|
|
||||||
groupwith = NULL;
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_new_session_data *data = self->data;
|
||||||
|
struct session *s, *old_s, *groupwith;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct environ env;
|
||||||
|
struct termios tio, *tiop;
|
||||||
|
struct passwd *pw;
|
||||||
|
const char *update, *cwd;
|
||||||
|
char *overrides, *cmd, *cause;
|
||||||
|
int detached, idx;
|
||||||
|
u_int sx, sy, i;
|
||||||
|
|
||||||
|
if (data->newname != NULL && session_find(data->newname) != NULL) {
|
||||||
|
ctx->error(ctx, "duplicate session: %s", data->newname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
groupwith = NULL;
|
||||||
|
if (data->target != NULL &&
|
||||||
|
(groupwith = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There are three cases:
|
* There are three cases:
|
||||||
@@ -106,7 +162,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Set -d if no client. */
|
/* Set -d if no client. */
|
||||||
detached = args_has(args, 'd');
|
detached = data->flag_detached;
|
||||||
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||||
detached = 1;
|
detached = 1;
|
||||||
|
|
||||||
@@ -128,10 +184,17 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
|
|
||||||
/* Open the terminal if necessary. */
|
/* Open the terminal if necessary. */
|
||||||
if (!detached && ctx->cmdclient != NULL) {
|
if (!detached && ctx->cmdclient != NULL) {
|
||||||
if (server_client_open(ctx->cmdclient, NULL, &cause) != 0) {
|
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||||
|
ctx->error(ctx, "not a terminal");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
overrides =
|
||||||
|
options_get_string(&global_s_options, "terminal-overrides");
|
||||||
|
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||||
ctx->error(ctx, "open terminal failed: %s", cause);
|
ctx->error(ctx, "open terminal failed: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,33 +210,15 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Find new session size. */
|
/* Find new session size. */
|
||||||
if (ctx->cmdclient != NULL) {
|
if (detached) {
|
||||||
sx = ctx->cmdclient->tty.sx;
|
|
||||||
sy = ctx->cmdclient->tty.sy;
|
|
||||||
} else if (ctx->curclient != NULL) {
|
|
||||||
sx = ctx->curclient->tty.sx;
|
|
||||||
sy = ctx->curclient->tty.sy;
|
|
||||||
} else {
|
|
||||||
sx = 80;
|
sx = 80;
|
||||||
sy = 24;
|
sy = 24;
|
||||||
}
|
} else if (ctx->cmdclient != NULL) {
|
||||||
if (detached) {
|
sx = ctx->cmdclient->tty.sx;
|
||||||
if (args_has(args, 'x')) {
|
sy = ctx->cmdclient->tty.sy;
|
||||||
sx = strtonum(
|
} else {
|
||||||
args_get(args, 'x'), 1, USHRT_MAX, &errstr);
|
sx = ctx->curclient->tty.sx;
|
||||||
if (errstr != NULL) {
|
sy = ctx->curclient->tty.sy;
|
||||||
ctx->error(ctx, "width %s", errstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (args_has(args, 'y')) {
|
|
||||||
sy = strtonum(
|
|
||||||
args_get(args, 'y'), 1, USHRT_MAX, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
ctx->error(ctx, "height %s", errstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (sy > 0 && options_get_number(&global_s_options, "status"))
|
if (sy > 0 && options_get_number(&global_s_options, "status"))
|
||||||
sy--;
|
sy--;
|
||||||
@@ -183,10 +228,10 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
sy = 1;
|
sy = 1;
|
||||||
|
|
||||||
/* Figure out the command for the new window. */
|
/* Figure out the command for the new window. */
|
||||||
if (target != NULL)
|
if (data->target != NULL)
|
||||||
cmd = NULL;
|
cmd = NULL;
|
||||||
else if (args->argc != 0)
|
else if (data->cmd != NULL)
|
||||||
cmd = args->argv[0];
|
cmd = data->cmd;
|
||||||
else
|
else
|
||||||
cmd = options_get_string(&global_s_options, "default-command");
|
cmd = options_get_string(&global_s_options, "default-command");
|
||||||
|
|
||||||
@@ -198,19 +243,21 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
|
|
||||||
/* Create the new session. */
|
/* Create the new session. */
|
||||||
idx = -1 - options_get_number(&global_s_options, "base-index");
|
idx = -1 - options_get_number(&global_s_options, "base-index");
|
||||||
s = session_create(newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
s = session_create(
|
||||||
|
data->newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
ctx->error(ctx, "create session failed: %s", cause);
|
ctx->error(ctx, "create session failed: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
environ_free(&env);
|
environ_free(&env);
|
||||||
|
|
||||||
/* Set the initial window name if one given. */
|
/* Set the initial window name if one given. */
|
||||||
if (cmd != NULL && args_has(args, 'n')) {
|
if (cmd != NULL && data->winname != NULL) {
|
||||||
w = s->curw->window;
|
w = s->curw->window;
|
||||||
|
|
||||||
window_set_name(w, args_get(args, 'n'));
|
xfree(w->name);
|
||||||
|
w->name = xstrdup(data->winname);
|
||||||
|
|
||||||
options_set_number(&w->options, "automatic-rename", 0);
|
options_set_number(&w->options, "automatic-rename", 0);
|
||||||
}
|
}
|
||||||
@@ -231,22 +278,18 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
*/
|
*/
|
||||||
if (!detached) {
|
if (!detached) {
|
||||||
if (ctx->cmdclient != NULL) {
|
if (ctx->cmdclient != NULL) {
|
||||||
server_write_ready(ctx->cmdclient);
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
|
|
||||||
old_s = ctx->cmdclient->session;
|
old_s = ctx->cmdclient->session;
|
||||||
if (old_s != NULL)
|
if (old_s != NULL)
|
||||||
ctx->cmdclient->last_session = old_s;
|
ctx->cmdclient->last_session = old_s;
|
||||||
ctx->cmdclient->session = s;
|
ctx->cmdclient->session = s;
|
||||||
notify_attached_session_changed(ctx->cmdclient);
|
|
||||||
session_update_activity(s);
|
|
||||||
server_redraw_client(ctx->cmdclient);
|
server_redraw_client(ctx->cmdclient);
|
||||||
} else {
|
} else {
|
||||||
old_s = ctx->curclient->session;
|
old_s = ctx->curclient->session;
|
||||||
if (old_s != NULL)
|
if (old_s != NULL)
|
||||||
ctx->curclient->last_session = old_s;
|
ctx->curclient->last_session = old_s;
|
||||||
ctx->curclient->session = s;
|
ctx->curclient->session = s;
|
||||||
notify_attached_session_changed(ctx->curclient);
|
|
||||||
session_update_activity(s);
|
|
||||||
server_redraw_client(ctx->curclient);
|
server_redraw_client(ctx->curclient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,10 +307,46 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
|
||||||
cause = ARRAY_ITEM(&cfg_causes, i);
|
cause = ARRAY_ITEM(&cfg_causes, i);
|
||||||
window_copy_add(wp, "%s", cause);
|
window_copy_add(wp, "%s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
}
|
}
|
||||||
ARRAY_FREE(&cfg_causes);
|
ARRAY_FREE(&cfg_causes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (detached ? CMD_RETURN_NORMAL : CMD_RETURN_ATTACH);
|
return (!detached); /* 1 means don't tell command client to exit */
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_new_session_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_new_session_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->newname != NULL)
|
||||||
|
xfree(data->newname);
|
||||||
|
if (data->winname != NULL)
|
||||||
|
xfree(data->winname);
|
||||||
|
if (data->cmd != NULL)
|
||||||
|
xfree(data->cmd);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_new_session_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_new_session_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->flag_detached)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && data->winname != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -n ", data->winname);
|
||||||
|
if (off < len && data->newname != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -s ", data->newname);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->cmd != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
207
cmd-new-window.c
207
cmd-new-window.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-new-window.c,v 1.47 2010-07-02 02:49:19 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,37 +26,111 @@
|
|||||||
* Create a new window.
|
* Create a new window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int cmd_new_window_parse(struct cmd *, int, char **, char **);
|
||||||
int cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_new_window_free(struct cmd *);
|
||||||
|
void cmd_new_window_init(struct cmd *, int);
|
||||||
|
size_t cmd_new_window_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
|
struct cmd_new_window_data {
|
||||||
|
char *target;
|
||||||
|
char *name;
|
||||||
|
char *cmd;
|
||||||
|
int flag_insert_after;
|
||||||
|
int flag_detached;
|
||||||
|
int flag_kill;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_new_window_entry = {
|
const struct cmd_entry cmd_new_window_entry = {
|
||||||
"new-window", "neww",
|
"new-window", "neww",
|
||||||
"ac:dF:kn:Pt:", 0, 1,
|
"[-adk] [-n window-name] [-t target-window] [command]",
|
||||||
"[-adkP] [-c start-directory] [-F format] [-n window-name] "
|
0, "",
|
||||||
"[-t target-window] [command]",
|
cmd_new_window_init,
|
||||||
0,
|
cmd_new_window_parse,
|
||||||
NULL,
|
cmd_new_window_exec,
|
||||||
NULL,
|
cmd_new_window_free,
|
||||||
cmd_new_window_exec
|
cmd_new_window_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_new_window_init(struct cmd *self, unused int arg)
|
||||||
|
{
|
||||||
|
struct cmd_new_window_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->target = NULL;
|
||||||
|
data->name = NULL;
|
||||||
|
data->cmd = NULL;
|
||||||
|
data->flag_insert_after = 0;
|
||||||
|
data->flag_detached = 0;
|
||||||
|
data->flag_kill = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_new_window_data *data;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "adkt:n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'a':
|
||||||
|
data->flag_insert_after = 1;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
data->flag_detached = 1;
|
||||||
|
break;
|
||||||
|
case 'k':
|
||||||
|
data->flag_kill = 1;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
if (data->name == NULL)
|
||||||
|
data->name = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 0 && argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
data->cmd = xstrdup(argv[0]);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_new_window_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct client *c;
|
char *cmd, *cwd, *cause;
|
||||||
const char *cmd, *cwd;
|
int idx, last;
|
||||||
const char *template;
|
|
||||||
char *cause;
|
|
||||||
int idx, last, detached;
|
|
||||||
struct format_tree *ft;
|
|
||||||
char *cp;
|
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
if (data == NULL)
|
||||||
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
return (0);
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
if (data->flag_insert_after) {
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
|
return (-1);
|
||||||
idx = wl->idx + 1;
|
idx = wl->idx + 1;
|
||||||
|
|
||||||
/* Find the next free index. */
|
/* Find the next free index. */
|
||||||
@@ -66,7 +140,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
if (last == INT_MAX) {
|
if (last == INT_MAX) {
|
||||||
ctx->error(ctx, "no free window indexes");
|
ctx->error(ctx, "no free window indexes");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move everything from last - 1 to idx up a bit. */
|
/* Move everything from last - 1 to idx up a bit. */
|
||||||
@@ -76,68 +150,87 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
server_unlink_window(s, wl);
|
server_unlink_window(s, wl);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &s)) == -2)
|
if ((idx = cmd_find_index(ctx, data->target, &s)) == -2)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
detached = args_has(args, 'd');
|
|
||||||
|
|
||||||
wl = NULL;
|
wl = NULL;
|
||||||
if (idx != -1)
|
if (idx != -1)
|
||||||
wl = winlink_find_by_index(&s->windows, idx);
|
wl = winlink_find_by_index(&s->windows, idx);
|
||||||
if (wl != NULL && args_has(args, 'k')) {
|
if (wl != NULL && data->flag_kill) {
|
||||||
/*
|
/*
|
||||||
* Can't use session_detach as it will destroy session if this
|
* Can't use session_detach as it will destroy session if this
|
||||||
* makes it empty.
|
* makes it empty.
|
||||||
*/
|
*/
|
||||||
notify_window_unlinked(s, wl->window);
|
|
||||||
wl->flags &= ~WINLINK_ALERTFLAGS;
|
wl->flags &= ~WINLINK_ALERTFLAGS;
|
||||||
winlink_stack_remove(&s->lastw, wl);
|
winlink_stack_remove(&s->lastw, wl);
|
||||||
winlink_remove(&s->windows, wl);
|
winlink_remove(&s->windows, wl);
|
||||||
|
|
||||||
/* Force select/redraw if current. */
|
/* Force select/redraw if current. */
|
||||||
if (wl == s->curw) {
|
if (wl == s->curw) {
|
||||||
detached = 0;
|
data->flag_detached = 0;
|
||||||
s->curw = NULL;
|
s->curw = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc == 0)
|
cmd = data->cmd;
|
||||||
|
if (cmd == NULL)
|
||||||
cmd = options_get_string(&s->options, "default-command");
|
cmd = options_get_string(&s->options, "default-command");
|
||||||
else
|
cwd = options_get_string(&s->options, "default-path");
|
||||||
cmd = args->argv[0];
|
if (*cwd == '\0') {
|
||||||
cwd = cmd_get_default_path(ctx, args_get(args, 'c'));
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
|
cwd = ctx->cmdclient->cwd;
|
||||||
|
else
|
||||||
|
cwd = s->cwd;
|
||||||
|
}
|
||||||
|
|
||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
idx = -1 - options_get_number(&s->options, "base-index");
|
idx = -1 - options_get_number(&s->options, "base-index");
|
||||||
wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause);
|
wl = session_new(s, data->name, cmd, cwd, idx, &cause);
|
||||||
if (wl == NULL) {
|
if (wl == NULL) {
|
||||||
ctx->error(ctx, "create window failed: %s", cause);
|
ctx->error(ctx, "create window failed: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (!detached) {
|
if (!data->flag_detached) {
|
||||||
session_select(s, wl->idx);
|
session_select(s, wl->idx);
|
||||||
server_redraw_session_group(s);
|
server_redraw_session_group(s);
|
||||||
} else
|
} else
|
||||||
server_status_session_group(s);
|
server_status_session_group(s);
|
||||||
|
|
||||||
if (args_has(args, 'P')) {
|
return (0);
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
}
|
||||||
template = NEW_WINDOW_TEMPLATE;
|
|
||||||
|
void
|
||||||
ft = format_create();
|
cmd_new_window_free(struct cmd *self)
|
||||||
if ((c = cmd_find_client(ctx, NULL)) != NULL)
|
{
|
||||||
format_client(ft, c);
|
struct cmd_new_window_data *data = self->data;
|
||||||
format_session(ft, s);
|
|
||||||
format_winlink(ft, s, wl);
|
if (data->target != NULL)
|
||||||
format_window_pane(ft, wl->window->active);
|
xfree(data->target);
|
||||||
|
if (data->name != NULL)
|
||||||
cp = format_expand(ft, template);
|
xfree(data->name);
|
||||||
ctx->print(ctx, "%s", cp);
|
if (data->cmd != NULL)
|
||||||
free(cp);
|
xfree(data->cmd);
|
||||||
|
xfree(data);
|
||||||
format_free(ft);
|
}
|
||||||
}
|
|
||||||
|
size_t
|
||||||
return (CMD_RETURN_NORMAL);
|
cmd_new_window_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_new_window_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->flag_detached)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->name != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -n ", data->name);
|
||||||
|
if (off < len && data->cmd != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
54
cmd-next-layout.c
Normal file
54
cmd-next-layout.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* $Id: cmd-next-layout.c,v 1.6 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Switch window to next layout.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_next_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_next_layout_entry = {
|
||||||
|
"next-layout", "nextl",
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_next_layout_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_next_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct winlink *wl;
|
||||||
|
u_int layout;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
layout = layout_set_next(wl->window);
|
||||||
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
76
cmd-next-window.c
Normal file
76
cmd-next-window.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/* $Id: cmd-next-window.c,v 1.21 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move to next window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_next_window_init(struct cmd *, int);
|
||||||
|
int cmd_next_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_next_window_entry = {
|
||||||
|
"next-window", "next",
|
||||||
|
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, "a",
|
||||||
|
cmd_next_window_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_next_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_next_window_init(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
if (key == ('n' | KEYC_ESCAPE))
|
||||||
|
cmd_set_flag(&data->chflags, 'a');
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
int activity;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
activity = 0;
|
||||||
|
if (cmd_check_flag(data->chflags, 'a'))
|
||||||
|
activity = 1;
|
||||||
|
|
||||||
|
if (session_next(s, activity) == 0)
|
||||||
|
server_redraw_session(s);
|
||||||
|
else {
|
||||||
|
ctx->error(ctx, "no next window");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-paste-buffer.c,v 1.29 2010-08-11 22:17:32 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -27,93 +27,145 @@
|
|||||||
* Paste paste buffer if present.
|
* Paste paste buffer if present.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
|
struct cmd_paste_buffer_data {
|
||||||
|
char *target;
|
||||||
|
int buffer;
|
||||||
|
|
||||||
void cmd_paste_buffer_filter(struct window_pane *,
|
int flag_delete;
|
||||||
const char *, size_t, const char *, int bracket);
|
char *sepstr;
|
||||||
|
};
|
||||||
|
|
||||||
|
void cmd_paste_buffer_init(struct cmd *, int);
|
||||||
|
int cmd_paste_buffer_parse(struct cmd *, int, char **, char **);
|
||||||
|
int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_paste_buffer_filter(
|
||||||
|
struct window_pane *, const char *, size_t, char *);
|
||||||
|
void cmd_paste_buffer_free(struct cmd *);
|
||||||
|
size_t cmd_paste_buffer_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
const struct cmd_entry cmd_paste_buffer_entry = {
|
const struct cmd_entry cmd_paste_buffer_entry = {
|
||||||
"paste-buffer", "pasteb",
|
"paste-buffer", "pasteb",
|
||||||
"db:prs:t:", 0, 0,
|
"[-dr] [-s separator] [-b buffer-index] [-t target-pane]",
|
||||||
"[-dpr] [-s separator] [-b buffer-index] [-t target-pane]",
|
0, "",
|
||||||
0,
|
cmd_paste_buffer_init,
|
||||||
NULL,
|
cmd_paste_buffer_parse,
|
||||||
NULL,
|
cmd_paste_buffer_exec,
|
||||||
cmd_paste_buffer_exec
|
cmd_paste_buffer_free,
|
||||||
|
cmd_paste_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_paste_buffer_init(struct cmd *self, unused int arg)
|
||||||
|
{
|
||||||
|
struct cmd_paste_buffer_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->target = NULL;
|
||||||
|
data->buffer = -1;
|
||||||
|
data->flag_delete = 0;
|
||||||
|
data->sepstr = xstrdup("\r");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_paste_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_paste_buffer_data *data;
|
||||||
|
int opt, n;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
|
cmd_paste_buffer_init(self, 0);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "b:ds:t:r")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'b':
|
||||||
|
if (data->buffer == -1) {
|
||||||
|
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "buffer %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
data->buffer = n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
data->flag_delete = 1;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
if (data->sepstr != NULL)
|
||||||
|
xfree(data->sepstr);
|
||||||
|
data->sepstr = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
if (data->sepstr != NULL)
|
||||||
|
xfree(data->sepstr);
|
||||||
|
data->sepstr = xstrdup("\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_paste_buffer_data *data = self->data;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
const char *sepstr;
|
|
||||||
char *cause;
|
|
||||||
int buffer;
|
|
||||||
int pflag;
|
|
||||||
|
|
||||||
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
if (cmd_find_pane(ctx, data->target, &s, &wp) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (!args_has(args, 'b'))
|
if (data->buffer == -1)
|
||||||
buffer = -1;
|
pb = paste_get_top(&s->buffers);
|
||||||
else {
|
else {
|
||||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
|
||||||
if (cause != NULL) {
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
ctx->error(ctx, "buffer %s", cause);
|
return (-1);
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer == -1)
|
if (pb != NULL)
|
||||||
pb = paste_get_top(&global_buffers);
|
cmd_paste_buffer_filter(wp, pb->data, pb->size, data->sepstr);
|
||||||
else {
|
|
||||||
pb = paste_get_index(&global_buffers, buffer);
|
|
||||||
if (pb == NULL) {
|
|
||||||
ctx->error(ctx, "no buffer %d", buffer);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pb != NULL) {
|
|
||||||
sepstr = args_get(args, 's');
|
|
||||||
if (sepstr == NULL) {
|
|
||||||
if (args_has(args, 'r'))
|
|
||||||
sepstr = "\n";
|
|
||||||
else
|
|
||||||
sepstr = "\r";
|
|
||||||
}
|
|
||||||
pflag = args_has(args, 'p') &&
|
|
||||||
(wp->screen->mode & MODE_BRACKETPASTE);
|
|
||||||
cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr, pflag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Delete the buffer if -d. */
|
/* Delete the buffer if -d. */
|
||||||
if (args_has(args, 'd')) {
|
if (data->flag_delete) {
|
||||||
if (buffer == -1)
|
if (data->buffer == -1)
|
||||||
paste_free_top(&global_buffers);
|
paste_free_top(&s->buffers);
|
||||||
else
|
else
|
||||||
paste_free_index(&global_buffers, buffer);
|
paste_free_index(&s->buffers, data->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add bytes to a buffer and filter '\n' according to separator. */
|
/* Add bytes to a buffer and filter '\n' according to separator. */
|
||||||
void
|
void
|
||||||
cmd_paste_buffer_filter(struct window_pane *wp,
|
cmd_paste_buffer_filter(
|
||||||
const char *data, size_t size, const char *sep, int bracket)
|
struct window_pane *wp, const char *data, size_t size, char *sep)
|
||||||
{
|
{
|
||||||
const char *end = data + size;
|
const char *end = data + size;
|
||||||
const char *lf;
|
const char *lf;
|
||||||
size_t seplen;
|
size_t seplen;
|
||||||
|
|
||||||
if (bracket)
|
|
||||||
bufferevent_write(wp->event, "\033[200~", 6);
|
|
||||||
|
|
||||||
seplen = strlen(sep);
|
seplen = strlen(sep);
|
||||||
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
||||||
if (lf != data)
|
if (lf != data)
|
||||||
@@ -124,7 +176,47 @@ cmd_paste_buffer_filter(struct window_pane *wp,
|
|||||||
|
|
||||||
if (end != data)
|
if (end != data)
|
||||||
bufferevent_write(wp->event, data, end - data);
|
bufferevent_write(wp->event, data, end - data);
|
||||||
|
}
|
||||||
if (bracket)
|
|
||||||
bufferevent_write(wp->event, "\033[201~", 6);
|
void
|
||||||
|
cmd_paste_buffer_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_paste_buffer_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
if (data->sepstr != NULL)
|
||||||
|
xfree(data->sepstr);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_paste_buffer_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_paste_buffer_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
char tmp[BUFSIZ];
|
||||||
|
int r_flag;
|
||||||
|
|
||||||
|
r_flag = 0;
|
||||||
|
if (data->sepstr != NULL)
|
||||||
|
r_flag = (data->sepstr[0] == '\n' && data->sepstr[1] == '\0');
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->flag_delete)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && r_flag)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -r");
|
||||||
|
if (off < len && data->buffer != -1)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -b %d", data->buffer);
|
||||||
|
if (off < len && data->sepstr != NULL && !r_flag) {
|
||||||
|
strnvis(
|
||||||
|
tmp, data->sepstr, sizeof tmp, VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -s ", tmp);
|
||||||
|
}
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-pipe-pane.c,v 1.15 2010-10-24 00:45:57 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -31,32 +31,35 @@
|
|||||||
* Open pipe to redirect pane output. If already open, close first.
|
* Open pipe to redirect pane output. If already open, close first.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_pipe_pane_entry = {
|
const struct cmd_entry cmd_pipe_pane_entry = {
|
||||||
"pipe-pane", "pipep",
|
"pipe-pane", "pipep",
|
||||||
"ot:", 0, 1,
|
CMD_TARGET_PANE_USAGE "[-o] [command]",
|
||||||
"[-o] " CMD_TARGET_PANE_USAGE " [command]",
|
CMD_ARG01, "o",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_pipe_pane_exec,
|
||||||
cmd_pipe_pane_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
char *command;
|
char *command;
|
||||||
int old_fd, pipe_fd[2], null_fd;
|
int old_fd, pipe_fd[2], null_fd, mode;
|
||||||
|
|
||||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
if ((c = cmd_find_client(ctx, NULL)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
c = cmd_find_client(ctx, NULL);
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
/* Destroy the old pipe. */
|
/* Destroy the old pipe. */
|
||||||
old_fd = wp->pipe_fd;
|
old_fd = wp->pipe_fd;
|
||||||
@@ -67,8 +70,8 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If no pipe command, that is enough. */
|
/* If no pipe command, that is enough. */
|
||||||
if (args->argc == 0 || *args->argv[0] == '\0')
|
if (data->arg == NULL || *data->arg == '\0')
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* With -o, only open the new pipe if there was no previous one. This
|
* With -o, only open the new pipe if there was no previous one. This
|
||||||
@@ -76,20 +79,20 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
*
|
*
|
||||||
* bind ^p pipep -o 'cat >>~/output'
|
* bind ^p pipep -o 'cat >>~/output'
|
||||||
*/
|
*/
|
||||||
if (args_has(self->args, 'o') && old_fd != -1)
|
if (cmd_check_flag(data->chflags, 'o') && old_fd != -1)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
/* Open the new pipe. */
|
/* Open the new pipe. */
|
||||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
||||||
ctx->error(ctx, "socketpair error: %s", strerror(errno));
|
ctx->error(ctx, "socketpair error: %s", strerror(errno));
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fork the child. */
|
/* Fork the child. */
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
ctx->error(ctx, "fork error: %s", strerror(errno));
|
ctx->error(ctx, "fork error: %s", strerror(errno));
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
case 0:
|
case 0:
|
||||||
/* Child process. */
|
/* Child process. */
|
||||||
close(pipe_fd[0]);
|
close(pipe_fd[0]);
|
||||||
@@ -110,8 +113,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
|
|
||||||
closefrom(STDERR_FILENO + 1);
|
closefrom(STDERR_FILENO + 1);
|
||||||
|
|
||||||
command = status_replace(
|
command = status_replace(c, NULL, data->arg, time(NULL), 0);
|
||||||
c, NULL, NULL, NULL, args->argv[0], time(NULL), 0);
|
|
||||||
execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL);
|
execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
default:
|
default:
|
||||||
@@ -125,8 +127,11 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
NULL, NULL, cmd_pipe_pane_error_callback, wp);
|
NULL, NULL, cmd_pipe_pane_error_callback, wp);
|
||||||
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
||||||
|
|
||||||
setblocking(wp->pipe_fd, 0);
|
if ((mode = fcntl(wp->pipe_fd, F_GETFL)) == -1)
|
||||||
return (CMD_RETURN_NORMAL);
|
fatal("fcntl failed");
|
||||||
|
if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||||
|
fatal("fcntl failed");
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
54
cmd-previous-layout.c
Normal file
54
cmd-previous-layout.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* $Id: cmd-previous-layout.c,v 1.6 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Switch window to previous layout.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_previous_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_previous_layout_entry = {
|
||||||
|
"previous-layout", "prevl",
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_previous_layout_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_previous_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct winlink *wl;
|
||||||
|
u_int layout;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
layout = layout_set_previous(wl->window);
|
||||||
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
76
cmd-previous-window.c
Normal file
76
cmd-previous-window.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/* $Id: cmd-previous-window.c,v 1.21 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move to previous window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_previous_window_init(struct cmd *, int);
|
||||||
|
int cmd_previous_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_previous_window_entry = {
|
||||||
|
"previous-window", "prev",
|
||||||
|
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, "a",
|
||||||
|
cmd_previous_window_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_previous_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_previous_window_init(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
if (key == ('p' | KEYC_ESCAPE))
|
||||||
|
cmd_set_flag(&data->chflags, 'a');
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
int activity;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
activity = 0;
|
||||||
|
if (cmd_check_flag(data->chflags, 'a'))
|
||||||
|
activity = 1;
|
||||||
|
|
||||||
|
if (session_previous(s, activity) == 0)
|
||||||
|
server_redraw_session(s);
|
||||||
|
else {
|
||||||
|
ctx->error(ctx, "no previous window");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-refresh-client.c,v 1.11 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,32 +24,29 @@
|
|||||||
* Refresh client.
|
* Refresh client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_refresh_client_entry = {
|
const struct cmd_entry cmd_refresh_client_entry = {
|
||||||
"refresh-client", "refresh",
|
"refresh-client", "refresh",
|
||||||
"St:", 0, 0,
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
"[-S] " CMD_TARGET_CLIENT_USAGE,
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_refresh_client_exec,
|
||||||
cmd_refresh_client_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
|
|
||||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (args_has(args, 'S')) {
|
server_redraw_client(c);
|
||||||
status_update_jobs(c);
|
|
||||||
server_status_client(c);
|
|
||||||
} else
|
|
||||||
server_redraw_client(c);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-rename-session.c,v 1.21 2010-12-22 15:36:44 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,45 +26,39 @@
|
|||||||
* Change session name.
|
* Change session name.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_rename_session_entry = {
|
const struct cmd_entry cmd_rename_session_entry = {
|
||||||
"rename-session", "rename",
|
"rename-session", "rename",
|
||||||
"t:", 1, 1,
|
|
||||||
CMD_TARGET_SESSION_USAGE " new-name",
|
CMD_TARGET_SESSION_USAGE " new-name",
|
||||||
0,
|
CMD_ARG1, "",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_rename_session_exec
|
cmd_rename_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
const char *newname;
|
|
||||||
|
|
||||||
newname = args->argv[0];
|
if (data->arg != NULL && session_find(data->arg) != NULL) {
|
||||||
if (!session_check_name(newname)) {
|
ctx->error(ctx, "duplicate session: %s", data->arg);
|
||||||
ctx->error(ctx, "bad session name: %s", newname);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (session_find(newname) != NULL) {
|
|
||||||
ctx->error(ctx, "duplicate session: %s", newname);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
RB_REMOVE(sessions, &sessions, s);
|
RB_REMOVE(sessions, &sessions, s);
|
||||||
free(s->name);
|
xfree(s->name);
|
||||||
s->name = xstrdup(newname);
|
s->name = xstrdup(data->arg);
|
||||||
RB_INSERT(sessions, &sessions, s);
|
RB_INSERT(sessions, &sessions, s);
|
||||||
|
|
||||||
server_status_session(s);
|
server_status_session(s);
|
||||||
notify_session_renamed(s);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-rename-window.c,v 1.31 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,32 +26,34 @@
|
|||||||
* Rename a window.
|
* Rename a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_rename_window_entry = {
|
const struct cmd_entry cmd_rename_window_entry = {
|
||||||
"rename-window", "renamew",
|
"rename-window", "renamew",
|
||||||
"t:", 1, 1,
|
|
||||||
CMD_TARGET_WINDOW_USAGE " new-name",
|
CMD_TARGET_WINDOW_USAGE " new-name",
|
||||||
0,
|
CMD_ARG1, "",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_rename_window_exec
|
cmd_rename_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
window_set_name(wl->window, args->argv[0]);
|
xfree(wl->window->name);
|
||||||
|
wl->window->name = xstrdup(data->arg);
|
||||||
options_set_number(&wl->window->options, "automatic-rename", 0);
|
options_set_number(&wl->window->options, "automatic-rename", 0);
|
||||||
|
|
||||||
server_status_window(wl->window);
|
server_status_window(wl->window);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-resize-pane.c,v 1.14 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,93 +26,86 @@
|
|||||||
* Increase or decrease pane size.
|
* Increase or decrease pane size.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_resize_pane_key_binding(struct cmd *, int);
|
void cmd_resize_pane_init(struct cmd *, int);
|
||||||
enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_resize_pane_entry = {
|
const struct cmd_entry cmd_resize_pane_entry = {
|
||||||
"resize-pane", "resizep",
|
"resize-pane", "resizep",
|
||||||
"DLRt:U", 0, 1,
|
|
||||||
"[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
"[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||||
0,
|
CMD_ARG01, "DLRU",
|
||||||
cmd_resize_pane_key_binding,
|
cmd_resize_pane_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_resize_pane_exec
|
cmd_resize_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_resize_pane_key_binding(struct cmd *self, int key)
|
cmd_resize_pane_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
switch (key) {
|
struct cmd_target_data *data;
|
||||||
case KEYC_UP | KEYC_CTRL:
|
|
||||||
self->args = args_create(0);
|
cmd_target_init(self, key);
|
||||||
args_set(self->args, 'U', NULL);
|
data = self->data;
|
||||||
break;
|
|
||||||
case KEYC_DOWN | KEYC_CTRL:
|
if (key == (KEYC_UP | KEYC_CTRL))
|
||||||
self->args = args_create(0);
|
cmd_set_flag(&data->chflags, 'U');
|
||||||
args_set(self->args, 'D', NULL);
|
if (key == (KEYC_DOWN | KEYC_CTRL))
|
||||||
break;
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
case KEYC_LEFT | KEYC_CTRL:
|
if (key == (KEYC_LEFT | KEYC_CTRL))
|
||||||
self->args = args_create(0);
|
cmd_set_flag(&data->chflags, 'L');
|
||||||
args_set(self->args, 'L', NULL);
|
if (key == (KEYC_RIGHT | KEYC_CTRL))
|
||||||
break;
|
cmd_set_flag(&data->chflags, 'R');
|
||||||
case KEYC_RIGHT | KEYC_CTRL:
|
|
||||||
self->args = args_create(0);
|
if (key == (KEYC_UP | KEYC_ESCAPE)) {
|
||||||
args_set(self->args, 'R', NULL);
|
cmd_set_flag(&data->chflags, 'U');
|
||||||
break;
|
data->arg = xstrdup("5");
|
||||||
case KEYC_UP | KEYC_ESCAPE:
|
}
|
||||||
self->args = args_create(1, "5");
|
if (key == (KEYC_DOWN | KEYC_ESCAPE)) {
|
||||||
args_set(self->args, 'U', NULL);
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
break;
|
data->arg = xstrdup("5");
|
||||||
case KEYC_DOWN | KEYC_ESCAPE:
|
}
|
||||||
self->args = args_create(1, "5");
|
if (key == (KEYC_LEFT | KEYC_ESCAPE)) {
|
||||||
args_set(self->args, 'D', NULL);
|
cmd_set_flag(&data->chflags, 'L');
|
||||||
break;
|
data->arg = xstrdup("5");
|
||||||
case KEYC_LEFT | KEYC_ESCAPE:
|
}
|
||||||
self->args = args_create(1, "5");
|
if (key == (KEYC_RIGHT | KEYC_ESCAPE)) {
|
||||||
args_set(self->args, 'L', NULL);
|
cmd_set_flag(&data->chflags, 'R');
|
||||||
break;
|
data->arg = xstrdup("5");
|
||||||
case KEYC_RIGHT | KEYC_ESCAPE:
|
|
||||||
self->args = args_create(1, "5");
|
|
||||||
args_set(self->args, 'R', NULL);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
self->args = args_create(0);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int adjust;
|
u_int adjust;
|
||||||
|
|
||||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (args->argc == 0)
|
if (data->arg == NULL)
|
||||||
adjust = 1;
|
adjust = 1;
|
||||||
else {
|
else {
|
||||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
adjust = strtonum(data->arg, 1, INT_MAX, &errstr);
|
||||||
if (errstr != NULL) {
|
if (errstr != NULL) {
|
||||||
ctx->error(ctx, "adjustment %s", errstr);
|
ctx->error(ctx, "adjustment %s: %s", errstr, data->arg);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layout_list_add(wp->window);
|
if (cmd_check_flag(data->chflags, 'L'))
|
||||||
if (args_has(self->args, 'L'))
|
|
||||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
|
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
|
||||||
else if (args_has(self->args, 'R'))
|
else if (cmd_check_flag(data->chflags, 'R'))
|
||||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
|
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
|
||||||
else if (args_has(self->args, 'U'))
|
else if (cmd_check_flag(data->chflags, 'U'))
|
||||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust);
|
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust);
|
||||||
else if (args_has(self->args, 'D'))
|
else if (cmd_check_flag(data->chflags, 'D'))
|
||||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
|
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
|
||||||
server_redraw_window(wl->window);
|
server_redraw_window(wl->window);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
/* $Id$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
||||||
* Copyright (c) 2011 Marcel P. Partap <mpartap@gmx.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 <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Respawn a pane (restart the command). Kill existing if -k given.
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_respawn_pane_entry = {
|
|
||||||
"respawn-pane", "respawnp",
|
|
||||||
"kt:", 0, 1,
|
|
||||||
"[-k] " CMD_TARGET_PANE_USAGE " [command]",
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
cmd_respawn_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct winlink *wl;
|
|
||||||
struct window *w;
|
|
||||||
struct window_pane *wp;
|
|
||||||
struct session *s;
|
|
||||||
struct environ env;
|
|
||||||
const char *cmd;
|
|
||||||
char *cause;
|
|
||||||
u_int idx;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
w = wl->window;
|
|
||||||
|
|
||||||
if (!args_has(self->args, 'k') && wp->fd != -1) {
|
|
||||||
if (window_pane_index(wp, &idx) != 0)
|
|
||||||
fatalx("index not found");
|
|
||||||
ctx->error(ctx, "pane still active: %s:%u.%u",
|
|
||||||
s->name, wl->idx, idx);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
environ_init(&env);
|
|
||||||
environ_copy(&global_environ, &env);
|
|
||||||
environ_copy(&s->environ, &env);
|
|
||||||
server_fill_environ(s, &env);
|
|
||||||
|
|
||||||
window_pane_reset_mode(wp);
|
|
||||||
screen_reinit(&wp->base);
|
|
||||||
input_init(wp);
|
|
||||||
|
|
||||||
if (args->argc != 0)
|
|
||||||
cmd = args->argv[0];
|
|
||||||
else
|
|
||||||
cmd = NULL;
|
|
||||||
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
|
|
||||||
ctx->error(ctx, "respawn pane failed: %s", cause);
|
|
||||||
free(cause);
|
|
||||||
environ_free(&env);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
wp->flags |= PANE_REDRAW;
|
|
||||||
server_status_window(w);
|
|
||||||
|
|
||||||
environ_free(&env);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-respawn-window.c,v 1.25 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,41 +26,41 @@
|
|||||||
* Respawn a window (restart the command). Kill existing if -k given.
|
* Respawn a window (restart the command). Kill existing if -k given.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_respawn_window_entry = {
|
const struct cmd_entry cmd_respawn_window_entry = {
|
||||||
"respawn-window", "respawnw",
|
"respawn-window", "respawnw",
|
||||||
"kt:", 0, 1,
|
|
||||||
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
|
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
|
||||||
0,
|
CMD_ARG01, "k",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_respawn_window_exec
|
cmd_respawn_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct environ env;
|
struct environ env;
|
||||||
const char *cmd;
|
|
||||||
char *cause;
|
char *cause;
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
w = wl->window;
|
w = wl->window;
|
||||||
|
|
||||||
if (!args_has(self->args, 'k')) {
|
if (!cmd_check_flag(data->chflags, 'k')) {
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
if (wp->fd == -1)
|
if (wp->fd == -1)
|
||||||
continue;
|
continue;
|
||||||
ctx->error(ctx,
|
ctx->error(ctx,
|
||||||
"window still active: %s:%d", s->name, wl->idx);
|
"window still active: %s:%d", s->name, wl->idx);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,26 +75,21 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
window_destroy_panes(w);
|
window_destroy_panes(w);
|
||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
window_pane_resize(wp, w->sx, w->sy);
|
window_pane_resize(wp, w->sx, w->sy);
|
||||||
if (args->argc != 0)
|
if (window_pane_spawn(
|
||||||
cmd = args->argv[0];
|
wp, data->arg, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||||
else
|
|
||||||
cmd = NULL;
|
|
||||||
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
|
|
||||||
ctx->error(ctx, "respawn window failed: %s", cause);
|
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
environ_free(&env);
|
environ_free(&env);
|
||||||
server_destroy_pane(wp);
|
server_destroy_pane(wp);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
layout_init(w);
|
layout_init(w);
|
||||||
window_pane_reset_mode(wp);
|
|
||||||
screen_reinit(&wp->base);
|
screen_reinit(&wp->base);
|
||||||
input_init(wp);
|
|
||||||
window_set_active_pane(w, wp);
|
window_set_active_pane(w, wp);
|
||||||
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
server_redraw_window(w);
|
server_redraw_window(w);
|
||||||
|
|
||||||
environ_free(&env);
|
environ_free(&env);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-rotate-window.c,v 1.10 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,42 +24,47 @@
|
|||||||
* Rotate the panes in a window.
|
* Rotate the panes in a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_rotate_window_key_binding(struct cmd *, int);
|
void cmd_rotate_window_init(struct cmd *, int);
|
||||||
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_rotate_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_rotate_window_entry = {
|
const struct cmd_entry cmd_rotate_window_entry = {
|
||||||
"rotate-window", "rotatew",
|
"rotate-window", "rotatew",
|
||||||
"Dt:U", 0, 0,
|
|
||||||
"[-DU] " CMD_TARGET_WINDOW_USAGE,
|
"[-DU] " CMD_TARGET_WINDOW_USAGE,
|
||||||
0,
|
0, "DU",
|
||||||
cmd_rotate_window_key_binding,
|
cmd_rotate_window_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_rotate_window_exec
|
cmd_rotate_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_rotate_window_key_binding(struct cmd *self, int key)
|
cmd_rotate_window_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
self->args = args_create(0);
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
if (key == ('o' | KEYC_ESCAPE))
|
if (key == ('o' | KEYC_ESCAPE))
|
||||||
args_set(self->args, 'D', NULL);
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
struct window_pane *wp, *wp2;
|
struct window_pane *wp, *wp2;
|
||||||
struct layout_cell *lc;
|
struct layout_cell *lc;
|
||||||
u_int sx, sy, xoff, yoff;
|
u_int sx, sy, xoff, yoff;
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
w = wl->window;
|
w = wl->window;
|
||||||
|
|
||||||
if (args_has(self->args, 'D')) {
|
if (cmd_check_flag(data->chflags, 'D')) {
|
||||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
@@ -115,5 +120,5 @@ cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
server_redraw_window(w);
|
server_redraw_window(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-run-shell.c,v 1.9 2010-08-09 21:44:25 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -29,18 +28,20 @@
|
|||||||
* Runs a command without a window.
|
* Runs a command without a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||||
void cmd_run_shell_callback(struct job *);
|
|
||||||
void cmd_run_shell_free(void *);
|
void cmd_run_shell_callback(struct job *);
|
||||||
|
void cmd_run_shell_free(void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_run_shell_entry = {
|
const struct cmd_entry cmd_run_shell_entry = {
|
||||||
"run-shell", "run",
|
"run-shell", "run",
|
||||||
"", 1, 1,
|
|
||||||
"command",
|
"command",
|
||||||
0,
|
CMD_ARG1, "",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_run_shell_exec
|
cmd_run_shell_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_run_shell_data {
|
struct cmd_run_shell_data {
|
||||||
@@ -48,15 +49,15 @@ struct cmd_run_shell_data {
|
|||||||
struct cmd_ctx ctx;
|
struct cmd_ctx ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct cmd_run_shell_data *cdata;
|
struct cmd_run_shell_data *cdata;
|
||||||
const char *shellcmd = args->argv[0];
|
struct job *job;
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
cdata->cmd = xstrdup(args->argv[0]);
|
cdata->cmd = xstrdup(data->arg);
|
||||||
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||||
|
|
||||||
if (ctx->cmdclient != NULL)
|
if (ctx->cmdclient != NULL)
|
||||||
@@ -64,9 +65,11 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
if (ctx->curclient != NULL)
|
if (ctx->curclient != NULL)
|
||||||
ctx->curclient->references++;
|
ctx->curclient->references++;
|
||||||
|
|
||||||
job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata);
|
job = job_add(NULL, 0, NULL,
|
||||||
|
data->arg, cmd_run_shell_callback, cmd_run_shell_free, cdata);
|
||||||
|
job_run(job);
|
||||||
|
|
||||||
return (CMD_RETURN_YIELD); /* don't let client exit */
|
return (1); /* don't let client exit */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -101,7 +104,7 @@ cmd_run_shell_callback(struct job *job)
|
|||||||
ctx->print(ctx, "%s", line);
|
ctx->print(ctx, "%s", line);
|
||||||
lines++;
|
lines++;
|
||||||
|
|
||||||
free(line);
|
xfree(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = cdata->cmd;
|
cmd = cdata->cmd;
|
||||||
@@ -119,7 +122,7 @@ cmd_run_shell_callback(struct job *job)
|
|||||||
ctx->print(ctx, "%s", msg);
|
ctx->print(ctx, "%s", msg);
|
||||||
else
|
else
|
||||||
ctx->info(ctx, "%s", msg);
|
ctx->info(ctx, "%s", msg);
|
||||||
free(msg);
|
xfree(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +139,6 @@ cmd_run_shell_free(void *data)
|
|||||||
if (ctx->curclient != NULL)
|
if (ctx->curclient != NULL)
|
||||||
ctx->curclient->references--;
|
ctx->curclient->references--;
|
||||||
|
|
||||||
free(cdata->cmd);
|
xfree(cdata->cmd);
|
||||||
free(cdata);
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-save-buffer.c,v 1.12 2010-08-09 21:44:25 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -20,100 +20,76 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Saves a paste buffer to a file.
|
* Saves a session paste buffer to a file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_save_buffer_entry = {
|
const struct cmd_entry cmd_save_buffer_entry = {
|
||||||
"save-buffer", "saveb",
|
"save-buffer", "saveb",
|
||||||
"ab:", 1, 1,
|
"[-a] " CMD_BUFFER_SESSION_USAGE " path",
|
||||||
"[-a] " CMD_BUFFER_USAGE " path",
|
CMD_ARG1, "a",
|
||||||
0,
|
cmd_buffer_init,
|
||||||
NULL,
|
cmd_buffer_parse,
|
||||||
NULL,
|
cmd_save_buffer_exec,
|
||||||
cmd_save_buffer_exec
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct client *c = ctx->cmdclient;
|
struct session *s;
|
||||||
struct session *s;
|
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
const char *path, *newpath, *wd;
|
|
||||||
char *cause;
|
|
||||||
int buffer;
|
|
||||||
mode_t mask;
|
mode_t mask;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if (!args_has(args, 'b')) {
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
if ((pb = paste_get_top(&global_buffers)) == NULL) {
|
return (-1);
|
||||||
|
|
||||||
|
if (data->buffer == -1) {
|
||||||
|
if ((pb = paste_get_top(&s->buffers)) == NULL) {
|
||||||
ctx->error(ctx, "no buffers");
|
ctx->error(ctx, "no buffers");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
|
||||||
if (cause != NULL) {
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
ctx->error(ctx, "buffer %s", cause);
|
return (-1);
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
pb = paste_get_index(&global_buffers, buffer);
|
|
||||||
if (pb == NULL) {
|
|
||||||
ctx->error(ctx, "no buffer %d", buffer);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
path = args->argv[0];
|
if (strcmp(data->arg, "-") == 0) {
|
||||||
if (strcmp(path, "-") == 0) {
|
if (ctx->cmdclient == NULL) {
|
||||||
if (c == NULL) {
|
ctx->error(ctx, "%s: can't write to stdout", data->arg);
|
||||||
ctx->error(ctx, "%s: can't write to stdout", path);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
evbuffer_add(c->stdout_data, pb->data, pb->size);
|
bufferevent_write(
|
||||||
server_push_stdout(c);
|
ctx->cmdclient->stdout_event, pb->data, pb->size);
|
||||||
} else {
|
} else {
|
||||||
if (c != NULL)
|
|
||||||
wd = c->cwd;
|
|
||||||
else if ((s = cmd_current_session(ctx, 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);
|
mask = umask(S_IRWXG | S_IRWXO);
|
||||||
if (args_has(self->args, 'a'))
|
if (cmd_check_flag(data->chflags, 'a'))
|
||||||
f = fopen(path, "ab");
|
f = fopen(data->arg, "ab");
|
||||||
else
|
else
|
||||||
f = fopen(path, "wb");
|
f = fopen(data->arg, "wb");
|
||||||
umask(mask);
|
umask(mask);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
ctx->error(ctx, "%s: %s", path, strerror(errno));
|
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
|
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
|
||||||
ctx->error(ctx, "%s: fwrite error", path);
|
ctx->error(ctx, "%s: fwrite error", data->arg);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-select-layout.c,v 1.12 2010-07-02 02:54:52 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,138 +24,71 @@
|
|||||||
* Switch window to selected layout.
|
* Switch window to selected layout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_select_layout_key_binding(struct cmd *, int);
|
void cmd_select_layout_init(struct cmd *, int);
|
||||||
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_select_layout_entry = {
|
const struct cmd_entry cmd_select_layout_entry = {
|
||||||
"select-layout", "selectl",
|
"select-layout", "selectl",
|
||||||
"nprut:", 0, 1,
|
CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
||||||
"[-npUu] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
CMD_ARG01, "",
|
||||||
0,
|
cmd_select_layout_init,
|
||||||
cmd_select_layout_key_binding,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_select_layout_exec,
|
||||||
cmd_select_layout_exec
|
cmd_target_free,
|
||||||
};
|
cmd_target_print
|
||||||
|
|
||||||
const struct cmd_entry cmd_next_layout_entry = {
|
|
||||||
"next-layout", "nextl",
|
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_WINDOW_USAGE,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
cmd_select_layout_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_previous_layout_entry = {
|
|
||||||
"previous-layout", "prevl",
|
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_WINDOW_USAGE,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
cmd_select_layout_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_select_layout_key_binding(struct cmd *self, int key)
|
cmd_select_layout_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case '1' | KEYC_ESCAPE:
|
case ('1' | KEYC_ESCAPE):
|
||||||
self->args = args_create(1, "even-horizontal");
|
data->arg = xstrdup("even-horizontal");
|
||||||
break;
|
break;
|
||||||
case '2' | KEYC_ESCAPE:
|
case ('2' | KEYC_ESCAPE):
|
||||||
self->args = args_create(1, "even-vertical");
|
data->arg = xstrdup("even-vertical");
|
||||||
break;
|
break;
|
||||||
case '3' | KEYC_ESCAPE:
|
case ('3' | KEYC_ESCAPE):
|
||||||
self->args = args_create(1, "main-horizontal");
|
data->arg = xstrdup("main-horizontal");
|
||||||
break;
|
break;
|
||||||
case '4' | KEYC_ESCAPE:
|
case ('4' | KEYC_ESCAPE):
|
||||||
self->args = args_create(1, "main-vertical");
|
data->arg = xstrdup("main-vertical");
|
||||||
break;
|
break;
|
||||||
case '5' | KEYC_ESCAPE:
|
case ('5' | KEYC_ESCAPE):
|
||||||
self->args = args_create(1, "tiled");
|
data->arg = xstrdup("tiled");
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
self->args = args_create(0);
|
|
||||||
args_set(self->args, 'u', NULL);
|
|
||||||
break;
|
|
||||||
case 'U':
|
|
||||||
self->args = args_create(0);
|
|
||||||
args_set(self->args, 'U', NULL);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
self->args = args_create(0);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct window *w;
|
int layout;
|
||||||
const char *layoutname;
|
|
||||||
int next, previous, layout;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
w = wl->window;
|
|
||||||
|
|
||||||
next = self->entry == &cmd_next_layout_entry;
|
if (data->arg == NULL) {
|
||||||
if (args_has(self->args, 'n'))
|
|
||||||
next = 1;
|
|
||||||
previous = self->entry == &cmd_previous_layout_entry;
|
|
||||||
if (args_has(self->args, 'p'))
|
|
||||||
previous = 1;
|
|
||||||
|
|
||||||
layout_list_add(w);
|
|
||||||
if (args_has(self->args, 'U')) {
|
|
||||||
if ((layoutname = layout_list_redo(w)) == NULL) {
|
|
||||||
ctx->info(ctx, "no more layout history");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
goto set_layout;
|
|
||||||
} else if (args_has(self->args, 'u')) {
|
|
||||||
if ((layoutname = layout_list_undo(w)) == NULL) {
|
|
||||||
ctx->info(ctx, "no more layout history");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
goto set_layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next || previous) {
|
|
||||||
if (next)
|
|
||||||
layout = layout_set_next(wl->window);
|
|
||||||
else
|
|
||||||
layout = layout_set_previous(wl->window);
|
|
||||||
server_redraw_window(wl->window);
|
|
||||||
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args->argc == 0)
|
|
||||||
layout = wl->window->lastlayout;
|
layout = wl->window->lastlayout;
|
||||||
else
|
if (layout == -1)
|
||||||
layout = layout_set_lookup(args->argv[0]);
|
return (0);
|
||||||
if (layout != -1) {
|
} else if ((layout = layout_set_lookup(data->arg)) != -1) {
|
||||||
layout = layout_set_select(wl->window, layout);
|
layout = layout_set_select(wl->window, layout);
|
||||||
server_redraw_window(wl->window);
|
|
||||||
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
return (CMD_RETURN_NORMAL);
|
} else {
|
||||||
|
if (layout_parse(wl->window, data->arg) == -1) {
|
||||||
|
ctx->error(ctx, "can't set layout: %s", data->arg);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
ctx->info(ctx, "arranging in: %s", data->arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc == 0)
|
return (0);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
layoutname = args->argv[0];
|
|
||||||
|
|
||||||
set_layout:
|
|
||||||
if (layout_parse(wl->window, layoutname) == -1) {
|
|
||||||
ctx->error(ctx, "can't set layout: %s", layoutname);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
server_redraw_window(wl->window);
|
|
||||||
ctx->info(ctx, "arranging in: %s", layoutname);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-select-pane.c,v 1.13 2010-03-15 22:03:38 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,93 +24,71 @@
|
|||||||
* Select pane.
|
* Select pane.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_select_pane_key_binding(struct cmd *, int);
|
void cmd_select_pane_init(struct cmd *, int);
|
||||||
enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_select_pane_entry = {
|
const struct cmd_entry cmd_select_pane_entry = {
|
||||||
"select-pane", "selectp",
|
"select-pane", "selectp",
|
||||||
"lDLRt:U", 0, 0,
|
"[-DLRU] " CMD_TARGET_PANE_USAGE,
|
||||||
"[-lDLRU] " CMD_TARGET_PANE_USAGE,
|
0, "DLRU",
|
||||||
0,
|
cmd_select_pane_init,
|
||||||
cmd_select_pane_key_binding,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_select_pane_exec,
|
||||||
cmd_select_pane_exec
|
cmd_target_free,
|
||||||
};
|
cmd_target_print
|
||||||
|
|
||||||
const struct cmd_entry cmd_last_pane_entry = {
|
|
||||||
"last-pane", "lastp",
|
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_WINDOW_USAGE,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
cmd_select_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_select_pane_key_binding(struct cmd *self, int key)
|
cmd_select_pane_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
self->args = args_create(0);
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
if (key == KEYC_UP)
|
if (key == KEYC_UP)
|
||||||
args_set(self->args, 'U', NULL);
|
cmd_set_flag(&data->chflags, 'U');
|
||||||
if (key == KEYC_DOWN)
|
if (key == KEYC_DOWN)
|
||||||
args_set(self->args, 'D', NULL);
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
if (key == KEYC_LEFT)
|
if (key == KEYC_LEFT)
|
||||||
args_set(self->args, 'L', NULL);
|
cmd_set_flag(&data->chflags, 'L');
|
||||||
if (key == KEYC_RIGHT)
|
if (key == KEYC_RIGHT)
|
||||||
args_set(self->args, 'R', NULL);
|
cmd_set_flag(&data->chflags, 'R');
|
||||||
if (key == 'o')
|
if (key == 'o')
|
||||||
args_set(self->args, 't', ":.+");
|
data->target = xstrdup(":.+");
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
|
|
||||||
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||||
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
return (-1);
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
if (wl->window->last == NULL) {
|
|
||||||
ctx->error(ctx, "no last pane");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
window_set_active_pane(wl->window, wl->window->last);
|
|
||||||
server_status_window(wl->window);
|
|
||||||
server_redraw_window_borders(wl->window);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
if (!window_pane_visible(wp)) {
|
if (!window_pane_visible(wp)) {
|
||||||
ctx->error(ctx, "pane not visible");
|
ctx->error(ctx, "pane not visible: %s", data->target);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(self->args, 'L'))
|
if (cmd_check_flag(data->chflags, 'L'))
|
||||||
wp = window_pane_find_left(wp);
|
wp = window_pane_find_left(wp);
|
||||||
else if (args_has(self->args, 'R'))
|
else if (cmd_check_flag(data->chflags, 'R'))
|
||||||
wp = window_pane_find_right(wp);
|
wp = window_pane_find_right(wp);
|
||||||
else if (args_has(self->args, 'U'))
|
else if (cmd_check_flag(data->chflags, 'U'))
|
||||||
wp = window_pane_find_up(wp);
|
wp = window_pane_find_up(wp);
|
||||||
else if (args_has(self->args, 'D'))
|
else if (cmd_check_flag(data->chflags, 'D'))
|
||||||
wp = window_pane_find_down(wp);
|
wp = window_pane_find_down(wp);
|
||||||
if (wp == NULL) {
|
if (wp == NULL) {
|
||||||
ctx->error(ctx, "pane not found");
|
ctx->error(ctx, "pane not found");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
window_set_active_pane(wl->window, wp);
|
window_set_active_pane(wl->window, wp);
|
||||||
server_status_window(wl->window);
|
server_status_window(wl->window);
|
||||||
server_redraw_window_borders(wl->window);
|
server_redraw_window_borders(wl->window);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-select-window.c,v 1.24 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,114 +26,44 @@
|
|||||||
* Select window by index.
|
* Select window by index.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_select_window_key_binding(struct cmd *, int);
|
void cmd_select_window_init(struct cmd *, int);
|
||||||
enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_select_window_entry = {
|
const struct cmd_entry cmd_select_window_entry = {
|
||||||
"select-window", "selectw",
|
"select-window", "selectw",
|
||||||
"lnpt:", 0, 0,
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
"[-lnp] " CMD_TARGET_WINDOW_USAGE,
|
0, "",
|
||||||
0,
|
cmd_select_window_init,
|
||||||
cmd_select_window_key_binding,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_select_window_exec,
|
||||||
cmd_select_window_exec
|
cmd_target_free,
|
||||||
};
|
cmd_target_print
|
||||||
|
|
||||||
const struct cmd_entry cmd_next_window_entry = {
|
|
||||||
"next-window", "next",
|
|
||||||
"at:", 0, 0,
|
|
||||||
"[-a] " CMD_TARGET_SESSION_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_select_window_key_binding,
|
|
||||||
NULL,
|
|
||||||
cmd_select_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_previous_window_entry = {
|
|
||||||
"previous-window", "prev",
|
|
||||||
"at:", 0, 0,
|
|
||||||
"[-a] " CMD_TARGET_SESSION_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_select_window_key_binding,
|
|
||||||
NULL,
|
|
||||||
cmd_select_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_last_window_entry = {
|
|
||||||
"last-window", "last",
|
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_SESSION_USAGE,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
cmd_select_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_select_window_key_binding(struct cmd *self, int key)
|
cmd_select_window_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
char tmp[16];
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
self->args = args_create(0);
|
cmd_target_init(self, key);
|
||||||
if (key >= '0' && key <= '9') {
|
data = self->data;
|
||||||
xsnprintf(tmp, sizeof tmp, ":%d", key - '0');
|
|
||||||
args_set(self->args, 't', tmp);
|
xasprintf(&data->target, ":%d", key - '0');
|
||||||
}
|
|
||||||
if (key == ('n' | KEYC_ESCAPE) || key == ('p' | KEYC_ESCAPE))
|
|
||||||
args_set(self->args, 'a', NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
int next, previous, last, activity;
|
|
||||||
|
|
||||||
next = self->entry == &cmd_next_window_entry;
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
if (args_has(self->args, 'n'))
|
return (-1);
|
||||||
next = 1;
|
|
||||||
previous = self->entry == &cmd_previous_window_entry;
|
|
||||||
if (args_has(self->args, 'p'))
|
|
||||||
previous = 1;
|
|
||||||
last = self->entry == &cmd_last_window_entry;
|
|
||||||
if (args_has(self->args, 'l'))
|
|
||||||
last = 1;
|
|
||||||
|
|
||||||
if (next || previous || last) {
|
|
||||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
activity = args_has(self->args, 'a');
|
|
||||||
if (next) {
|
|
||||||
if (session_next(s, activity) != 0) {
|
|
||||||
ctx->error(ctx, "no next window");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
} else if (previous) {
|
|
||||||
if (session_previous(s, activity) != 0) {
|
|
||||||
ctx->error(ctx, "no previous window");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (session_last(s) != 0) {
|
|
||||||
ctx->error(ctx, "no last window");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (session_select(s, wl->idx) == 0)
|
||||||
server_redraw_session(s);
|
server_redraw_session(s);
|
||||||
} else {
|
|
||||||
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
if (session_select(s, wl->idx) == 0)
|
|
||||||
server_redraw_session(s);
|
|
||||||
}
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
157
cmd-send-keys.c
157
cmd-send-keys.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-send-keys.c,v 1.25 2010-05-22 21:56:04 micahcowan Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -27,58 +26,128 @@
|
|||||||
* Send keys to client.
|
* Send keys to client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_send_keys_parse(struct cmd *, int, char **, char **);
|
||||||
|
int cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_send_keys_free(struct cmd *);
|
||||||
|
size_t cmd_send_keys_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
|
struct cmd_send_keys_data {
|
||||||
|
char *target;
|
||||||
|
u_int nkeys;
|
||||||
|
int *keys;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_send_keys_entry = {
|
const struct cmd_entry cmd_send_keys_entry = {
|
||||||
"send-keys", "send",
|
"send-keys", "send",
|
||||||
"lRt:", 0, -1,
|
"[-t target-pane] key ...",
|
||||||
"[-lR] [-t target-pane] key ...",
|
0, "",
|
||||||
0,
|
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
cmd_send_keys_parse,
|
||||||
cmd_send_keys_exec
|
cmd_send_keys_exec,
|
||||||
|
cmd_send_keys_free,
|
||||||
|
cmd_send_keys_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_send_keys_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_send_keys_data *data;
|
||||||
struct window_pane *wp;
|
int opt, key;
|
||||||
struct session *s;
|
char *s;
|
||||||
struct input_ctx *ictx;
|
|
||||||
const char *str;
|
|
||||||
int i, key;
|
|
||||||
|
|
||||||
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
self->data = data = xmalloc(sizeof *data);
|
||||||
return (CMD_RETURN_ERROR);
|
data->target = NULL;
|
||||||
|
data->nkeys = 0;
|
||||||
|
data->keys = NULL;
|
||||||
|
|
||||||
if (args_has(args, 'R')) {
|
while ((opt = getopt(argc, argv, "t:")) != -1) {
|
||||||
ictx = &wp->ictx;
|
switch (opt) {
|
||||||
|
case 't':
|
||||||
memcpy(&ictx->cell, &grid_default_cell, sizeof ictx->cell);
|
if (data->target == NULL)
|
||||||
memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell);
|
data->target = xstrdup(optarg);
|
||||||
ictx->old_cx = 0;
|
break;
|
||||||
ictx->old_cy = 0;
|
default:
|
||||||
|
goto usage;
|
||||||
if (wp->mode == NULL)
|
|
||||||
screen_write_start(&ictx->ctx, wp, &wp->base);
|
|
||||||
else
|
|
||||||
screen_write_start(&ictx->ctx, NULL, &wp->base);
|
|
||||||
screen_write_reset(&ictx->ctx);
|
|
||||||
screen_write_stop(&ictx->ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < args->argc; i++) {
|
|
||||||
str = args->argv[i];
|
|
||||||
|
|
||||||
if (!args_has(args, 'l') &&
|
|
||||||
(key = key_string_lookup_string(str)) != KEYC_NONE) {
|
|
||||||
window_pane_key(wp, s, key);
|
|
||||||
} else {
|
|
||||||
for (; *str != '\0'; str++)
|
|
||||||
window_pane_key(wp, s, *str);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc == 0)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
while (argc-- != 0) {
|
||||||
|
if ((key = key_string_lookup_string(*argv)) != KEYC_NONE) {
|
||||||
|
data->keys = xrealloc(
|
||||||
|
data->keys, data->nkeys + 1, sizeof *data->keys);
|
||||||
|
data->keys[data->nkeys++] = key;
|
||||||
|
} else {
|
||||||
|
for (s = *argv; *s != '\0'; s++) {
|
||||||
|
data->keys = xrealloc(data->keys,
|
||||||
|
data->nkeys + 1, sizeof *data->keys);
|
||||||
|
data->keys[data->nkeys++] = *s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_send_keys_data *data = self->data;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct session *s;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
if (data == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, &s, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
for (i = 0; i < data->nkeys; i++)
|
||||||
|
window_pane_key(wp, s, data->keys[i]);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_send_keys_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_send_keys_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_send_keys_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_send_keys_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
|
||||||
|
for (i = 0; i < data->nkeys; i++) {
|
||||||
|
if (off >= len)
|
||||||
|
break;
|
||||||
|
off += xsnprintf(buf + off,
|
||||||
|
len - off, " %s", key_string_lookup_key(data->keys[i]));
|
||||||
|
}
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-send-prefix.c,v 1.29 2010-05-22 21:56:04 micahcowan Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,34 +24,32 @@
|
|||||||
* Send prefix key as a key.
|
* Send prefix key as a key.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_send_prefix_entry = {
|
const struct cmd_entry cmd_send_prefix_entry = {
|
||||||
"send-prefix", NULL,
|
"send-prefix", NULL,
|
||||||
"2t:", 0, 0,
|
CMD_TARGET_PANE_USAGE,
|
||||||
"[-2] " CMD_TARGET_PANE_USAGE,
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_send_prefix_exec,
|
||||||
cmd_send_prefix_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
int key;
|
struct keylist *keylist;
|
||||||
|
|
||||||
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
if (cmd_find_pane(ctx, data->target, &s, &wp) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (args_has(args, '2'))
|
keylist = options_get_data(&s->options, "prefix");
|
||||||
key = options_get_number(&s->options, "prefix2");
|
window_pane_key(wp, s, ARRAY_FIRST(keylist));
|
||||||
else
|
|
||||||
key = options_get_number(&s->options, "prefix");
|
|
||||||
window_pane_key(wp, s, key);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-server-info.c,v 1.38 2010-12-22 15:36:44 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -30,48 +30,49 @@
|
|||||||
* Show various information about server.
|
* Show various information about server.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_server_info_entry = {
|
const struct cmd_entry cmd_server_info_entry = {
|
||||||
"server-info", "info",
|
"server-info", "info",
|
||||||
"", 0, 0,
|
|
||||||
"",
|
"",
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
cmd_server_info_exec
|
cmd_server_info_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct tty_term *term;
|
struct tty_term *term;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct tty_code *code;
|
struct tty_code *code;
|
||||||
const struct tty_term_code_entry *ent;
|
struct tty_term_code_entry *ent;
|
||||||
struct utsname un;
|
struct utsname un;
|
||||||
struct job *job;
|
struct job *job;
|
||||||
struct grid *gd;
|
struct grid *gd;
|
||||||
struct grid_line *gl;
|
struct grid_line *gl;
|
||||||
u_int i, j, k;
|
u_int i, j, k;
|
||||||
char out[80];
|
char out[80];
|
||||||
char *tim;
|
char *tim;
|
||||||
time_t t;
|
time_t t;
|
||||||
u_int lines, ulines;
|
u_int lines, ulines;
|
||||||
size_t size, usize;
|
size_t size, usize;
|
||||||
|
|
||||||
tim = ctime(&start_time);
|
tim = ctime(&start_time);
|
||||||
*strchr(tim, '\n') = '\0';
|
*strchr(tim, '\n') = '\0';
|
||||||
ctx->print(ctx,
|
ctx->print(ctx,
|
||||||
"tmux " VERSION ", pid %ld, started %s", (long) getpid(), tim);
|
"tmux " BUILD ", pid %ld, started %s", (long) getpid(), tim);
|
||||||
ctx->print(
|
ctx->print(
|
||||||
ctx, "socket path %s, debug level %d", socket_path, debug_level);
|
ctx, "socket path %s, debug level %d", socket_path, debug_level);
|
||||||
if (uname(&un) >= 0) {
|
if (uname(&un) == 0) {
|
||||||
ctx->print(ctx, "system is %s %s %s %s",
|
ctx->print(ctx, "system is %s %s %s %s",
|
||||||
un.sysname, un.release, un.version, un.machine);
|
un.sysname, un.release, un.version, un.machine);
|
||||||
}
|
}
|
||||||
@@ -88,12 +89,11 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
if (c == NULL || c->session == NULL)
|
if (c == NULL || c->session == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho "
|
ctx->print(ctx, "%2d: %s (%d, %d): %s [%ux%u %s] "
|
||||||
"xterm=%u] [flags=0x%x/0x%x, references=%u]", i,
|
"[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
|
||||||
c->tty.path, c->ibuf.fd, c->tty.fd, c->session->name,
|
c->ibuf.fd, c->tty.fd, c->session->name,
|
||||||
c->tty.sx, c->tty.sy, c->tty.termname,
|
c->tty.sx, c->tty.sy, c->tty.termname, c->flags,
|
||||||
c->tty.tio.c_cc[VERASE], c->tty.xterm_version,
|
c->tty.flags, c->references);
|
||||||
c->flags, c->tty.flags, c->references);
|
|
||||||
}
|
}
|
||||||
ctx->print(ctx, "%s", "");
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
ctx->print(ctx, "%s", "");
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
ctx->print(ctx, "Terminals:");
|
ctx->print(ctx, "Terminals:");
|
||||||
LIST_FOREACH(term, &tty_terms, entry) {
|
SLIST_FOREACH(term, &tty_terms, entry) {
|
||||||
ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
|
ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
|
||||||
term->name, term->references, term->flags);
|
term->name, term->references, term->flags);
|
||||||
for (i = 0; i < NTTYCODE; i++) {
|
for (i = 0; i < NTTYCODE; i++) {
|
||||||
@@ -174,10 +174,10 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
ctx->print(ctx, "%s", "");
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
ctx->print(ctx, "Jobs:");
|
ctx->print(ctx, "Jobs:");
|
||||||
LIST_FOREACH(job, &all_jobs, lentry) {
|
SLIST_FOREACH(job, &all_jobs, lentry) {
|
||||||
ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d]",
|
ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d, flags=0x%x]",
|
||||||
job->cmd, job->fd, job->pid, job->status);
|
job->cmd, job->fd, job->pid, job->status, job->flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-set-buffer.c,v 1.12 2009-11-28 14:54:12 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,59 +18,51 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add or set a paste buffer.
|
* Add or set a session paste buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_buffer_entry = {
|
const struct cmd_entry cmd_set_buffer_entry = {
|
||||||
"set-buffer", "setb",
|
"set-buffer", "setb",
|
||||||
"b:", 1, 1,
|
CMD_BUFFER_SESSION_USAGE " data",
|
||||||
CMD_BUFFER_USAGE " data",
|
CMD_ARG1, "",
|
||||||
0,
|
cmd_buffer_init,
|
||||||
NULL,
|
cmd_buffer_parse,
|
||||||
NULL,
|
cmd_set_buffer_exec,
|
||||||
cmd_set_buffer_exec
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
u_int limit;
|
struct session *s;
|
||||||
char *pdata, *cause;
|
u_int limit;
|
||||||
size_t psize;
|
char *pdata;
|
||||||
int buffer;
|
size_t psize;
|
||||||
|
|
||||||
limit = options_get_number(&global_options, "buffer-limit");
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
limit = options_get_number(&s->options, "buffer-limit");
|
||||||
|
|
||||||
pdata = xstrdup(args->argv[0]);
|
pdata = xstrdup(data->arg);
|
||||||
psize = strlen(pdata);
|
psize = strlen(pdata);
|
||||||
|
|
||||||
if (!args_has(args, 'b')) {
|
if (data->buffer == -1) {
|
||||||
paste_add(&global_buffers, pdata, psize, limit);
|
paste_add(&s->buffers, pdata, psize, limit);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
if (paste_replace(&s->buffers, data->buffer, pdata, psize) != 0) {
|
||||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
if (cause != NULL) {
|
xfree(pdata);
|
||||||
ctx->error(ctx, "buffer %s", cause);
|
return (-1);
|
||||||
free(cause);
|
|
||||||
free(pdata);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
|
|
||||||
ctx->error(ctx, "no buffer %d", buffer);
|
|
||||||
free(pdata);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-set-environment.c,v 1.3 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -27,68 +27,62 @@
|
|||||||
* Set an environment variable.
|
* Set an environment variable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_set_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_environment_entry = {
|
const struct cmd_entry cmd_set_environment_entry = {
|
||||||
"set-environment", "setenv",
|
"set-environment", "setenv",
|
||||||
"grt:u", 1, 2,
|
|
||||||
"[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
"[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
||||||
0,
|
CMD_ARG12, "gru",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_set_environment_exec
|
cmd_set_environment_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct environ *env;
|
struct environ *env;
|
||||||
const char *name, *value;
|
|
||||||
|
|
||||||
name = args->argv[0];
|
if (*data->arg == '\0') {
|
||||||
if (*name == '\0') {
|
|
||||||
ctx->error(ctx, "empty variable name");
|
ctx->error(ctx, "empty variable name");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (strchr(name, '=') != NULL) {
|
if (strchr(data->arg, '=') != NULL) {
|
||||||
ctx->error(ctx, "variable name contains =");
|
ctx->error(ctx, "variable name contains =");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc < 1)
|
if (cmd_check_flag(data->chflags, 'g'))
|
||||||
value = NULL;
|
|
||||||
else
|
|
||||||
value = args->argv[1];
|
|
||||||
|
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
env = &global_environ;
|
env = &global_environ;
|
||||||
else {
|
else {
|
||||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
env = &s->environ;
|
env = &s->environ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(self->args, 'u')) {
|
if (cmd_check_flag(data->chflags, 'u')) {
|
||||||
if (value != NULL) {
|
if (data->arg2 != NULL) {
|
||||||
ctx->error(ctx, "can't specify a value with -u");
|
ctx->error(ctx, "can't specify a value with -u");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
environ_unset(env, name);
|
environ_unset(env, data->arg);
|
||||||
} else if (args_has(self->args, 'r')) {
|
} else if (cmd_check_flag(data->chflags, 'r')) {
|
||||||
if (value != NULL) {
|
if (data->arg2 != NULL) {
|
||||||
ctx->error(ctx, "can't specify a value with -r");
|
ctx->error(ctx, "can't specify a value with -r");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
environ_set(env, name, NULL);
|
environ_set(env, data->arg, NULL);
|
||||||
} else {
|
} else {
|
||||||
if (value == NULL) {
|
if (data->arg2 == NULL) {
|
||||||
ctx->error(ctx, "no value specified");
|
ctx->error(ctx, "no value specified");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
environ_set(env, name, value);
|
environ_set(env, data->arg, data->arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
658
cmd-set-option.c
658
cmd-set-option.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-set-option.c,v 1.102 2010-12-22 15:23:59 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -27,140 +27,264 @@
|
|||||||
* Set an option.
|
* Set an option.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
int cmd_set_option_unset(struct cmd *, struct cmd_ctx *,
|
const char *cmd_set_option_print(
|
||||||
const struct options_table_entry *, struct options *,
|
const struct set_option_entry *, struct options_entry *);
|
||||||
const char *);
|
void cmd_set_option_string(struct cmd_ctx *,
|
||||||
int cmd_set_option_set(struct cmd *, struct cmd_ctx *,
|
struct options *, const struct set_option_entry *, char *, int);
|
||||||
const struct options_table_entry *, struct options *,
|
void cmd_set_option_number(struct cmd_ctx *,
|
||||||
const char *);
|
struct options *, const struct set_option_entry *, char *);
|
||||||
|
void cmd_set_option_keys(struct cmd_ctx *,
|
||||||
struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_ctx *,
|
struct options *, const struct set_option_entry *, char *);
|
||||||
const struct options_table_entry *, struct options *,
|
void cmd_set_option_colour(struct cmd_ctx *,
|
||||||
const char *);
|
struct options *, const struct set_option_entry *, char *);
|
||||||
struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_ctx *,
|
void cmd_set_option_attributes(struct cmd_ctx *,
|
||||||
const struct options_table_entry *, struct options *,
|
struct options *, const struct set_option_entry *, char *);
|
||||||
const char *);
|
void cmd_set_option_flag(struct cmd_ctx *,
|
||||||
struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_ctx *,
|
struct options *, const struct set_option_entry *, char *);
|
||||||
const struct options_table_entry *, struct options *,
|
void cmd_set_option_choice(struct cmd_ctx *,
|
||||||
const char *);
|
struct options *, const struct set_option_entry *, char *);
|
||||||
struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_ctx *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_ctx *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_ctx *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_ctx *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_option_entry = {
|
const struct cmd_entry cmd_set_option_entry = {
|
||||||
"set-option", "set",
|
"set-option", "set",
|
||||||
"agqst:uw", 1, 2,
|
"[-agsuw] [-t target-session|target-window] option [value]",
|
||||||
"[-agsquw] [-t target-session|target-window] option [value]",
|
CMD_ARG12, "agsuw",
|
||||||
0,
|
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_set_option_exec
|
cmd_set_option_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_window_option_entry = {
|
const char *set_option_mode_keys_list[] = {
|
||||||
"set-window-option", "setw",
|
"emacs", "vi", NULL
|
||||||
"agqt:u", 1, 2,
|
};
|
||||||
"[-agqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
const char *set_option_clock_mode_style_list[] = {
|
||||||
0,
|
"12", "24", NULL
|
||||||
NULL,
|
};
|
||||||
NULL,
|
const char *set_option_status_keys_list[] = {
|
||||||
cmd_set_option_exec
|
"emacs", "vi", NULL
|
||||||
|
};
|
||||||
|
const char *set_option_status_justify_list[] = {
|
||||||
|
"left", "centre", "right", NULL
|
||||||
|
};
|
||||||
|
const char *set_option_bell_action_list[] = {
|
||||||
|
"none", "any", "current", NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
const struct set_option_entry set_option_table[] = {
|
||||||
|
{ "escape-time", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||||
|
{ "exit-unattached", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "quiet", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ NULL, 0, 0, 0, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct set_option_entry set_session_option_table[] = {
|
||||||
|
{ "base-index", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||||
|
{ "bell-action", SET_OPTION_CHOICE, 0, 0, set_option_bell_action_list },
|
||||||
|
{ "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||||
|
{ "default-command", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "default-path", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "default-shell", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "default-terminal", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "destroy-unattached", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "detach-on-destroy", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "display-panes-colour", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "display-panes-active-colour", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "display-panes-time", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||||
|
{ "display-time", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||||
|
{ "history-limit", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||||
|
{ "lock-after-time", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||||
|
{ "lock-command", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "lock-server", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "message-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||||
|
{ "message-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "message-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "message-limit", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||||
|
{ "mouse-select-pane", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "pane-active-border-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "pane-active-border-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "pane-border-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "pane-border-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "prefix", SET_OPTION_KEYS, 0, 0, NULL },
|
||||||
|
{ "repeat-time", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
||||||
|
{ "set-remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "set-titles", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "set-titles-string", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "status", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "status-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||||
|
{ "status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "status-interval", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||||
|
{ "status-justify",
|
||||||
|
SET_OPTION_CHOICE, 0, 0, set_option_status_justify_list },
|
||||||
|
{ "status-keys", SET_OPTION_CHOICE, 0, 0, set_option_status_keys_list },
|
||||||
|
{ "status-left", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "status-left-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||||
|
{ "status-left-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "status-left-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "status-left-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
||||||
|
{ "status-right", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "status-right-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||||
|
{ "status-right-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "status-right-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "status-right-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
||||||
|
{ "status-utf8", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "terminal-overrides", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "update-environment", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "visual-activity", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "visual-bell", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "visual-content", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "visual-silence", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ NULL, 0, 0, 0, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct set_option_entry set_window_option_table[] = {
|
||||||
|
{ "aggressive-resize", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "alternate-screen", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "automatic-rename", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "clock-mode-colour", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "clock-mode-style",
|
||||||
|
SET_OPTION_CHOICE, 0, 0, set_option_clock_mode_style_list },
|
||||||
|
{ "force-height", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||||
|
{ "force-width", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||||
|
{ "main-pane-height", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||||
|
{ "main-pane-width", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||||
|
{ "mode-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||||
|
{ "mode-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "mode-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "mode-keys", SET_OPTION_CHOICE, 0, 0, set_option_mode_keys_list },
|
||||||
|
{ "mode-mouse", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "monitor-activity", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "monitor-content", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "monitor-silence",SET_OPTION_NUMBER, 0, INT_MAX, NULL},
|
||||||
|
{ "other-pane-height", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||||
|
{ "other-pane-width", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||||
|
{ "remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "synchronize-panes", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "utf8", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ "window-status-alert-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||||
|
{ "window-status-alert-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "window-status-alert-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "window-status-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||||
|
{ "window-status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "window-status-current-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||||
|
{ "window-status-current-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "window-status-current-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "window-status-current-format", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "window-status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "window-status-format", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "word-separators", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
|
{ "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ NULL, 0, 0, 0, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
const struct options_table_entry *table, *oe;
|
const struct set_option_entry *table;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
struct window *w;
|
const struct set_option_entry *entry, *opt;
|
||||||
const char *optstr, *valstr;
|
struct jobs *jobs;
|
||||||
u_int i;
|
struct job *job, *nextjob;
|
||||||
|
u_int i;
|
||||||
|
int try_again;
|
||||||
|
|
||||||
/* Get the option name and value. */
|
if (cmd_check_flag(data->chflags, 's')) {
|
||||||
optstr = args->argv[0];
|
|
||||||
if (*optstr == '\0') {
|
|
||||||
ctx->error(ctx, "invalid option");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (args->argc < 2)
|
|
||||||
valstr = NULL;
|
|
||||||
else
|
|
||||||
valstr = args->argv[1];
|
|
||||||
|
|
||||||
/* Find the option entry, try each table. */
|
|
||||||
table = oe = NULL;
|
|
||||||
if (options_table_find(optstr, &table, &oe) != 0) {
|
|
||||||
ctx->error(ctx, "ambiguous option: %s", optstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (oe == NULL) {
|
|
||||||
ctx->error(ctx, "unknown option: %s", optstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Work out the tree from the table. */
|
|
||||||
if (table == server_options_table)
|
|
||||||
oo = &global_options;
|
oo = &global_options;
|
||||||
else if (table == window_options_table) {
|
table = set_option_table;
|
||||||
if (args_has(self->args, 'g'))
|
} else if (cmd_check_flag(data->chflags, 'w')) {
|
||||||
|
table = set_window_option_table;
|
||||||
|
if (cmd_check_flag(data->chflags, 'g'))
|
||||||
oo = &global_w_options;
|
oo = &global_w_options;
|
||||||
else {
|
else {
|
||||||
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
wl = cmd_find_window(ctx, data->target, NULL);
|
||||||
if (wl == NULL)
|
if (wl == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
oo = &wl->window->options;
|
oo = &wl->window->options;
|
||||||
}
|
}
|
||||||
} else if (table == session_options_table) {
|
} else {
|
||||||
if (args_has(self->args, 'g'))
|
table = set_session_option_table;
|
||||||
|
if (cmd_check_flag(data->chflags, 'g'))
|
||||||
oo = &global_s_options;
|
oo = &global_s_options;
|
||||||
else {
|
else {
|
||||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
s = cmd_find_session(ctx, data->target);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
oo = &s->options;
|
oo = &s->options;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ctx->error(ctx, "unknown table");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unset or set the option. */
|
if (*data->arg == '\0') {
|
||||||
if (args_has(args, 'u')) {
|
ctx->error(ctx, "invalid option");
|
||||||
if (cmd_set_option_unset(self, ctx, oe, oo, valstr) != 0)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
} else {
|
|
||||||
if (cmd_set_option_set(self, ctx, oe, oo, valstr) != 0)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start or stop timers when automatic-rename changed. */
|
entry = NULL;
|
||||||
if (strcmp (oe->name, "automatic-rename") == 0) {
|
for (opt = table; opt->name != NULL; opt++) {
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
if (strncmp(opt->name, data->arg, strlen(data->arg)) != 0)
|
||||||
if ((w = ARRAY_ITEM(&windows, i)) == NULL)
|
continue;
|
||||||
continue;
|
if (entry != NULL) {
|
||||||
if (options_get_number(&w->options, "automatic-rename"))
|
ctx->error(ctx, "ambiguous option: %s", data->arg);
|
||||||
queue_window_name(w);
|
return (-1);
|
||||||
else if (event_initialized(&w->name_timer))
|
}
|
||||||
evtimer_del(&w->name_timer);
|
entry = opt;
|
||||||
|
|
||||||
|
/* Bail now if an exact match. */
|
||||||
|
if (strcmp(entry->name, data->arg) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (entry == NULL) {
|
||||||
|
ctx->error(ctx, "unknown option: %s", data->arg);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd_check_flag(data->chflags, 'u')) {
|
||||||
|
if (cmd_check_flag(data->chflags, 'g')) {
|
||||||
|
ctx->error(ctx,
|
||||||
|
"can't unset global option: %s", entry->name);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (data->arg2 != NULL) {
|
||||||
|
ctx->error(ctx,
|
||||||
|
"value passed to unset option: %s", entry->name);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
options_remove(oo, entry->name);
|
||||||
|
ctx->info(ctx, "unset option: %s", entry->name);
|
||||||
|
} else {
|
||||||
|
switch (entry->type) {
|
||||||
|
case SET_OPTION_STRING:
|
||||||
|
cmd_set_option_string(ctx, oo, entry,
|
||||||
|
data->arg2, cmd_check_flag(data->chflags, 'a'));
|
||||||
|
break;
|
||||||
|
case SET_OPTION_NUMBER:
|
||||||
|
cmd_set_option_number(ctx, oo, entry, data->arg2);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_KEYS:
|
||||||
|
cmd_set_option_keys(ctx, oo, entry, data->arg2);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_COLOUR:
|
||||||
|
cmd_set_option_colour(ctx, oo, entry, data->arg2);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_ATTRIBUTES:
|
||||||
|
cmd_set_option_attributes(ctx, oo, entry, data->arg2);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_FLAG:
|
||||||
|
cmd_set_option_flag(ctx, oo, entry, data->arg2);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_CHOICE:
|
||||||
|
cmd_set_option_choice(ctx, oo, entry, data->arg2);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update sizes and redraw. May not need it but meh. */
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
c = ARRAY_ITEM(&clients, i);
|
c = ARRAY_ITEM(&clients, i);
|
||||||
@@ -168,170 +292,227 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
server_redraw_client(c);
|
server_redraw_client(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
/*
|
||||||
}
|
* Special-case: kill all persistent jobs if status-left, status-right
|
||||||
|
* or set-titles-string have changed. Persistent jobs are only used by
|
||||||
|
* the status line at the moment so this works XXX.
|
||||||
|
*/
|
||||||
|
if (strcmp(entry->name, "status-left") == 0 ||
|
||||||
|
strcmp(entry->name, "status-right") == 0 ||
|
||||||
|
strcmp(entry->name, "status") == 0 ||
|
||||||
|
strcmp(entry->name, "set-titles-string") == 0 ||
|
||||||
|
strcmp(entry->name, "window-status-format") == 0) {
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
/* Unset an option. */
|
jobs = &c->status_jobs;
|
||||||
int
|
do {
|
||||||
cmd_set_option_unset(struct cmd *self, struct cmd_ctx *ctx,
|
try_again = 0;
|
||||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
job = RB_ROOT(jobs);
|
||||||
{
|
while (job != NULL) {
|
||||||
struct args *args = self->args;
|
nextjob = RB_NEXT(jobs, jobs, job);
|
||||||
|
if (job->flags & JOB_PERSIST) {
|
||||||
if (args_has(args, 'g')) {
|
job_remove(jobs, job);
|
||||||
ctx->error(ctx, "can't unset global option: %s", oe->name);
|
try_again = 1;
|
||||||
return (-1);
|
break;
|
||||||
}
|
}
|
||||||
if (value != NULL) {
|
job = nextjob;
|
||||||
ctx->error(ctx, "value passed to unset option: %s", oe->name);
|
}
|
||||||
return (-1);
|
} while (try_again);
|
||||||
|
server_redraw_client(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
options_remove(oo, oe->name);
|
|
||||||
if (!args_has(args, 'q'))
|
|
||||||
ctx->info(ctx, "unset option: %s", oe->name);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set an option. */
|
const char *
|
||||||
int
|
cmd_set_option_print(
|
||||||
cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx,
|
const struct set_option_entry *entry, struct options_entry *o)
|
||||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
static char out[BUFSIZ];
|
||||||
struct options_entry *o;
|
const char *s;
|
||||||
const char *s;
|
struct keylist *keylist;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
if (oe->type != OPTIONS_TABLE_FLAG && value == NULL) {
|
*out = '\0';
|
||||||
|
switch (entry->type) {
|
||||||
|
case SET_OPTION_STRING:
|
||||||
|
xsnprintf(out, sizeof out, "\"%s\"", o->str);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_NUMBER:
|
||||||
|
xsnprintf(out, sizeof out, "%lld", o->num);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_KEYS:
|
||||||
|
keylist = o->data;
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(keylist); i++) {
|
||||||
|
strlcat(out, key_string_lookup_key(
|
||||||
|
ARRAY_ITEM(keylist, i)), sizeof out);
|
||||||
|
if (i != ARRAY_LENGTH(keylist) - 1)
|
||||||
|
strlcat(out, ",", sizeof out);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SET_OPTION_COLOUR:
|
||||||
|
s = colour_tostring(o->num);
|
||||||
|
xsnprintf(out, sizeof out, "%s", s);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_ATTRIBUTES:
|
||||||
|
s = attributes_tostring(o->num);
|
||||||
|
xsnprintf(out, sizeof out, "%s", s);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_FLAG:
|
||||||
|
if (o->num)
|
||||||
|
strlcpy(out, "on", sizeof out);
|
||||||
|
else
|
||||||
|
strlcpy(out, "off", sizeof out);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_CHOICE:
|
||||||
|
s = entry->choices[o->num];
|
||||||
|
xsnprintf(out, sizeof out, "%s", s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_set_option_string(struct cmd_ctx *ctx, struct options *oo,
|
||||||
|
const struct set_option_entry *entry, char *value, int append)
|
||||||
|
{
|
||||||
|
struct options_entry *o;
|
||||||
|
char *oldvalue, *newvalue;
|
||||||
|
|
||||||
|
if (value == NULL) {
|
||||||
ctx->error(ctx, "empty value");
|
ctx->error(ctx, "empty value");
|
||||||
return (-1);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
o = NULL;
|
if (append) {
|
||||||
switch (oe->type) {
|
oldvalue = options_get_string(oo, entry->name);
|
||||||
case OPTIONS_TABLE_STRING:
|
xasprintf(&newvalue, "%s%s", oldvalue, value);
|
||||||
o = cmd_set_option_string(self, ctx, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_NUMBER:
|
|
||||||
o = cmd_set_option_number(self, ctx, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_KEY:
|
|
||||||
o = cmd_set_option_key(self, ctx, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_COLOUR:
|
|
||||||
o = cmd_set_option_colour(self, ctx, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_ATTRIBUTES:
|
|
||||||
o = cmd_set_option_attributes(self, ctx, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_FLAG:
|
|
||||||
o = cmd_set_option_flag(self, ctx, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_CHOICE:
|
|
||||||
o = cmd_set_option_choice(self, ctx, oe, oo, value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (o == NULL)
|
|
||||||
return (-1);
|
|
||||||
|
|
||||||
s = options_table_print_entry(oe, o);
|
|
||||||
if (!args_has(args, 'q'))
|
|
||||||
ctx->info(ctx, "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_ctx *ctx,
|
|
||||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct options_entry *o;
|
|
||||||
char *oldval, *newval;
|
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
|
||||||
oldval = options_get_string(oo, oe->name);
|
|
||||||
xasprintf(&newval, "%s%s", oldval, value);
|
|
||||||
} else
|
} else
|
||||||
newval = xstrdup(value);
|
newvalue = value;
|
||||||
|
|
||||||
o = options_set_string(oo, oe->name, "%s", newval);
|
o = options_set_string(oo, entry->name, "%s", newvalue);
|
||||||
|
ctx->info(ctx,
|
||||||
|
"set option: %s -> %s", o->name, cmd_set_option_print(entry, o));
|
||||||
|
|
||||||
free(newval);
|
if (newvalue != value)
|
||||||
return (o);
|
xfree(newvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set a number option. */
|
void
|
||||||
struct options_entry *
|
cmd_set_option_number(struct cmd_ctx *ctx, struct options *oo,
|
||||||
cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx,
|
const struct set_option_entry *entry, char *value)
|
||||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
|
||||||
{
|
{
|
||||||
long long ll;
|
struct options_entry *o;
|
||||||
const char *errstr;
|
long long number;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
ll = strtonum(value, oe->minimum, oe->maximum, &errstr);
|
if (value == NULL) {
|
||||||
|
ctx->error(ctx, "empty value");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
number = strtonum(value, entry->minimum, entry->maximum, &errstr);
|
||||||
if (errstr != NULL) {
|
if (errstr != NULL) {
|
||||||
ctx->error(ctx, "value is %s: %s", errstr, value);
|
ctx->error(ctx, "value is %s: %s", errstr, value);
|
||||||
return (NULL);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (options_set_number(oo, oe->name, ll));
|
o = options_set_number(oo, entry->name, number);
|
||||||
|
ctx->info(ctx,
|
||||||
|
"set option: %s -> %s", o->name, cmd_set_option_print(entry, o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set a key option. */
|
void
|
||||||
struct options_entry *
|
cmd_set_option_keys(struct cmd_ctx *ctx, struct options *oo,
|
||||||
cmd_set_option_key(unused struct cmd *self, struct cmd_ctx *ctx,
|
const struct set_option_entry *entry, char *value)
|
||||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
|
||||||
{
|
{
|
||||||
int key;
|
struct options_entry *o;
|
||||||
|
struct keylist *keylist;
|
||||||
|
char *copyvalue, *ptr, *str;
|
||||||
|
int key;
|
||||||
|
|
||||||
if ((key = key_string_lookup_string(value)) == KEYC_NONE) {
|
if (value == NULL) {
|
||||||
ctx->error(ctx, "bad key: %s", value);
|
ctx->error(ctx, "empty value");
|
||||||
return (NULL);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (options_set_number(oo, oe->name, key));
|
keylist = xmalloc(sizeof *keylist);
|
||||||
|
ARRAY_INIT(keylist);
|
||||||
|
|
||||||
|
ptr = copyvalue = xstrdup(value);
|
||||||
|
while ((str = strsep(&ptr, ",")) != NULL) {
|
||||||
|
if ((key = key_string_lookup_string(str)) == KEYC_NONE) {
|
||||||
|
xfree(keylist);
|
||||||
|
ctx->error(ctx, "unknown key: %s", str);
|
||||||
|
xfree(copyvalue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ARRAY_ADD(keylist, key);
|
||||||
|
}
|
||||||
|
xfree(copyvalue);
|
||||||
|
|
||||||
|
o = options_set_data(oo, entry->name, keylist, xfree);
|
||||||
|
ctx->info(ctx,
|
||||||
|
"set option: %s -> %s", o->name, cmd_set_option_print(entry, o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set a colour option. */
|
void
|
||||||
struct options_entry *
|
cmd_set_option_colour(struct cmd_ctx *ctx, struct options *oo,
|
||||||
cmd_set_option_colour(unused struct cmd *self, struct cmd_ctx *ctx,
|
const struct set_option_entry *entry, char *value)
|
||||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
|
||||||
{
|
{
|
||||||
int colour;
|
struct options_entry *o;
|
||||||
|
int colour;
|
||||||
|
|
||||||
|
if (value == NULL) {
|
||||||
|
ctx->error(ctx, "empty value");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((colour = colour_fromstring(value)) == -1) {
|
if ((colour = colour_fromstring(value)) == -1) {
|
||||||
ctx->error(ctx, "bad colour: %s", value);
|
ctx->error(ctx, "bad colour: %s", value);
|
||||||
return (NULL);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (options_set_number(oo, oe->name, colour));
|
o = options_set_number(oo, entry->name, colour);
|
||||||
|
ctx->info(ctx,
|
||||||
|
"set option: %s -> %s", o->name, cmd_set_option_print(entry, o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set an attributes option. */
|
void
|
||||||
struct options_entry *
|
cmd_set_option_attributes(struct cmd_ctx *ctx, struct options *oo,
|
||||||
cmd_set_option_attributes(unused struct cmd *self, struct cmd_ctx *ctx,
|
const struct set_option_entry *entry, char *value)
|
||||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
|
||||||
{
|
{
|
||||||
int attr;
|
struct options_entry *o;
|
||||||
|
int attr;
|
||||||
|
|
||||||
|
if (value == NULL) {
|
||||||
|
ctx->error(ctx, "empty value");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((attr = attributes_fromstring(value)) == -1) {
|
if ((attr = attributes_fromstring(value)) == -1) {
|
||||||
ctx->error(ctx, "bad attributes: %s", value);
|
ctx->error(ctx, "bad attributes: %s", value);
|
||||||
return (NULL);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (options_set_number(oo, oe->name, attr));
|
o = options_set_number(oo, entry->name, attr);
|
||||||
|
ctx->info(ctx,
|
||||||
|
"set option: %s -> %s", o->name, cmd_set_option_print(entry, o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set a flag option. */
|
void
|
||||||
struct options_entry *
|
cmd_set_option_flag(struct cmd_ctx *ctx, struct options *oo,
|
||||||
cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx,
|
const struct set_option_entry *entry, char *value)
|
||||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
|
||||||
{
|
{
|
||||||
int flag;
|
struct options_entry *o;
|
||||||
|
int flag;
|
||||||
|
|
||||||
if (value == NULL || *value == '\0')
|
if (value == NULL || *value == '\0')
|
||||||
flag = !options_get_number(oo, oe->name);
|
flag = !options_get_number(oo, entry->name);
|
||||||
else {
|
else {
|
||||||
if ((value[0] == '1' && value[1] == '\0') ||
|
if ((value[0] == '1' && value[1] == '\0') ||
|
||||||
strcasecmp(value, "on") == 0 ||
|
strcasecmp(value, "on") == 0 ||
|
||||||
@@ -343,37 +524,46 @@ cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx,
|
|||||||
flag = 0;
|
flag = 0;
|
||||||
else {
|
else {
|
||||||
ctx->error(ctx, "bad value: %s", value);
|
ctx->error(ctx, "bad value: %s", value);
|
||||||
return (NULL);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (options_set_number(oo, oe->name, flag));
|
o = options_set_number(oo, entry->name, flag);
|
||||||
|
ctx->info(ctx,
|
||||||
|
"set option: %s -> %s", o->name, cmd_set_option_print(entry, o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set a choice option. */
|
void
|
||||||
struct options_entry *
|
cmd_set_option_choice(struct cmd_ctx *ctx, struct options *oo,
|
||||||
cmd_set_option_choice(unused struct cmd *self, struct cmd_ctx *ctx,
|
const struct set_option_entry *entry, char *value)
|
||||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
|
||||||
{
|
{
|
||||||
const char **choicep;
|
struct options_entry *o;
|
||||||
int n, choice = -1;
|
const char **choicep;
|
||||||
|
int n, choice = -1;
|
||||||
|
|
||||||
|
if (value == NULL) {
|
||||||
|
ctx->error(ctx, "empty value");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
for (choicep = oe->choices; *choicep != NULL; choicep++) {
|
for (choicep = entry->choices; *choicep != NULL; choicep++) {
|
||||||
n++;
|
n++;
|
||||||
if (strncmp(*choicep, value, strlen(value)) != 0)
|
if (strncmp(*choicep, value, strlen(value)) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (choice != -1) {
|
if (choice != -1) {
|
||||||
ctx->error(ctx, "ambiguous value: %s", value);
|
ctx->error(ctx, "ambiguous option value: %s", value);
|
||||||
return (NULL);
|
return;
|
||||||
}
|
}
|
||||||
choice = n - 1;
|
choice = n - 1;
|
||||||
}
|
}
|
||||||
if (choice == -1) {
|
if (choice == -1) {
|
||||||
ctx->error(ctx, "unknown value: %s", value);
|
ctx->error(ctx, "unknown option value: %s", value);
|
||||||
return (NULL);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (options_set_number(oo, oe->name, choice));
|
o = options_set_number(oo, entry->name, choice);
|
||||||
|
ctx->info(ctx,
|
||||||
|
"set option: %s -> %s", o->name, cmd_set_option_print(entry, o));
|
||||||
}
|
}
|
||||||
|
|||||||
47
cmd-set-window-option.c
Normal file
47
cmd-set-window-option.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/* $Id: cmd-set-window-option.c,v 1.43 2009-12-04 22:11:23 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set a window option. This is just an alias for set-option -w.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_set_window_option_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_set_window_option_entry = {
|
||||||
|
"set-window-option", "setw",
|
||||||
|
"[-agu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||||
|
CMD_ARG12, "agu",
|
||||||
|
NULL,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_set_window_option_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
|
||||||
|
cmd_set_flag(&data->chflags, 'w');
|
||||||
|
return (cmd_set_option_entry.exec(self, ctx));
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-show-buffer.c,v 1.12 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -18,59 +18,49 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Show a paste buffer.
|
* Show a session paste buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_buffer_entry = {
|
const struct cmd_entry cmd_show_buffer_entry = {
|
||||||
"show-buffer", "showb",
|
"show-buffer", "showb",
|
||||||
"b:", 0, 0,
|
CMD_BUFFER_SESSION_USAGE,
|
||||||
CMD_BUFFER_USAGE,
|
0, "",
|
||||||
0,
|
cmd_buffer_init,
|
||||||
NULL,
|
cmd_buffer_parse,
|
||||||
NULL,
|
cmd_show_buffer_exec,
|
||||||
cmd_show_buffer_exec
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
int buffer;
|
char *in, *buf, *ptr;
|
||||||
char *in, *buf, *ptr, *cause;
|
|
||||||
size_t size, len;
|
size_t size, len;
|
||||||
u_int width;
|
u_int width;
|
||||||
|
|
||||||
if ((s = cmd_find_session(ctx, NULL, 0)) == NULL)
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (!args_has(args, 'b')) {
|
if (data->buffer == -1) {
|
||||||
if ((pb = paste_get_top(&global_buffers)) == NULL) {
|
if ((pb = paste_get_top(&s->buffers)) == NULL) {
|
||||||
ctx->error(ctx, "no buffers");
|
ctx->error(ctx, "no buffers");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
ctx->error(ctx, "buffer %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
pb = paste_get_index(&global_buffers, buffer);
|
|
||||||
if (pb == NULL) {
|
|
||||||
ctx->error(ctx, "no buffer %d", buffer);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
} else if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
if (pb == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
size = pb->size;
|
size = pb->size;
|
||||||
if (size > SIZE_MAX / 4 - 1)
|
if (size > SIZE_MAX / 4 - 1)
|
||||||
@@ -103,9 +93,9 @@ cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
ctx->print(ctx, "%s", buf);
|
ctx->print(ctx, "%s", buf);
|
||||||
}
|
}
|
||||||
free(buf);
|
xfree(buf);
|
||||||
|
|
||||||
free(in);
|
xfree(in);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-show-environment.c,v 1.2 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -27,47 +27,35 @@
|
|||||||
* Show environment.
|
* Show environment.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_show_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_environment_entry = {
|
const struct cmd_entry cmd_show_environment_entry = {
|
||||||
"show-environment", "showenv",
|
"show-environment", "showenv",
|
||||||
"gt:", 0, 1,
|
"[-g] " CMD_TARGET_SESSION_USAGE,
|
||||||
"[-g] " CMD_TARGET_SESSION_USAGE " [name]",
|
0, "g",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_show_environment_exec,
|
||||||
cmd_show_environment_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct environ *env;
|
struct environ *env;
|
||||||
struct environ_entry *envent;
|
struct environ_entry *envent;
|
||||||
|
|
||||||
if (args_has(self->args, 'g'))
|
if (cmd_check_flag(data->chflags, 'g'))
|
||||||
env = &global_environ;
|
env = &global_environ;
|
||||||
else {
|
else {
|
||||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
env = &s->environ;
|
env = &s->environ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc != 0) {
|
|
||||||
envent = environ_find(env, args->argv[0]);
|
|
||||||
if (envent == NULL) {
|
|
||||||
ctx->error(ctx, "unknown variable: %s", args->argv[0]);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (envent->value != NULL)
|
|
||||||
ctx->print(ctx, "%s=%s", envent->name, envent->value);
|
|
||||||
else
|
|
||||||
ctx->print(ctx, "-%s", envent->name);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
RB_FOREACH(envent, environ, env) {
|
RB_FOREACH(envent, environ, env) {
|
||||||
if (envent->value != NULL)
|
if (envent->value != NULL)
|
||||||
ctx->print(ctx, "%s=%s", envent->name, envent->value);
|
ctx->print(ctx, "%s=%s", envent->name, envent->value);
|
||||||
@@ -75,5 +63,5 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
ctx->print(ctx, "-%s", envent->name);
|
ctx->print(ctx, "-%s", envent->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-show-messages.c,v 1.2 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -27,29 +27,30 @@
|
|||||||
* Show client message log.
|
* Show client message log.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_show_messages_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_messages_entry = {
|
const struct cmd_entry cmd_show_messages_entry = {
|
||||||
"show-messages", "showmsgs",
|
"show-messages", "showmsgs",
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_CLIENT_USAGE,
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
cmd_show_messages_exec
|
cmd_show_messages_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct message_entry *msg;
|
struct message_entry *msg;
|
||||||
char *tim;
|
char *tim;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
|
||||||
msg = &ARRAY_ITEM(&c->message_log, i);
|
msg = &ARRAY_ITEM(&c->message_log, i);
|
||||||
@@ -60,5 +61,5 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
ctx->print(ctx, "%s %s", tim, msg->msg);
|
ctx->print(ctx, "%s %s", tim, msg->msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-show-options.c,v 1.21 2009-12-10 16:59:02 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -27,87 +27,62 @@
|
|||||||
* Show options.
|
* Show options.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_options_entry = {
|
const struct cmd_entry cmd_show_options_entry = {
|
||||||
"show-options", "show",
|
"show-options", "show",
|
||||||
"gst:w", 0, 1,
|
"[-gsw] [-t target-session|target-window]",
|
||||||
"[-gsw] [-t target-session|target-window] [option]",
|
0, "gsw",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_show_options_exec,
|
||||||
cmd_show_options_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_window_options_entry = {
|
int
|
||||||
"show-window-options", "showw",
|
|
||||||
"gt:", 0, 1,
|
|
||||||
"[-g] " CMD_TARGET_WINDOW_USAGE " [option]",
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
cmd_show_options_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
const struct options_table_entry *table, *oe;
|
const struct set_option_entry *table;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
const char *optval;
|
const struct set_option_entry *entry;
|
||||||
|
const char *optval;
|
||||||
|
|
||||||
if (args_has(self->args, 's')) {
|
if (cmd_check_flag(data->chflags, 's')) {
|
||||||
oo = &global_options;
|
oo = &global_options;
|
||||||
table = server_options_table;
|
table = set_option_table;
|
||||||
} else if (args_has(self->args, 'w') ||
|
} else if (cmd_check_flag(data->chflags, 'w')) {
|
||||||
self->entry == &cmd_show_window_options_entry) {
|
table = set_window_option_table;
|
||||||
table = window_options_table;
|
if (cmd_check_flag(data->chflags, 'g'))
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
oo = &global_w_options;
|
oo = &global_w_options;
|
||||||
else {
|
else {
|
||||||
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
wl = cmd_find_window(ctx, data->target, NULL);
|
||||||
if (wl == NULL)
|
if (wl == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
oo = &wl->window->options;
|
oo = &wl->window->options;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
table = session_options_table;
|
table = set_session_option_table;
|
||||||
if (args_has(self->args, 'g'))
|
if (cmd_check_flag(data->chflags, 'g'))
|
||||||
oo = &global_s_options;
|
oo = &global_s_options;
|
||||||
else {
|
else {
|
||||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
s = cmd_find_session(ctx, data->target);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
oo = &s->options;
|
oo = &s->options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc != 0) {
|
for (entry = table; entry->name != NULL; entry++) {
|
||||||
table = oe = NULL;
|
if ((o = options_find1(oo, entry->name)) == NULL)
|
||||||
if (options_table_find(args->argv[0], &table, &oe) != 0) {
|
continue;
|
||||||
ctx->error(ctx, "ambiguous option: %s", args->argv[0]);
|
optval = cmd_set_option_print(entry, o);
|
||||||
return (CMD_RETURN_ERROR);
|
ctx->print(ctx, "%s %s", entry->name, optval);
|
||||||
}
|
|
||||||
if (oe == NULL) {
|
|
||||||
ctx->error(ctx, "unknown option: %s", args->argv[0]);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if ((o = options_find1(oo, oe->name)) == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
optval = options_table_print_entry(oe, o);
|
|
||||||
ctx->print(ctx, "%s %s", oe->name, optval);
|
|
||||||
} else {
|
|
||||||
for (oe = table; oe->name != NULL; oe++) {
|
|
||||||
if ((o = options_find1(oo, oe->name)) == NULL)
|
|
||||||
continue;
|
|
||||||
optval = options_table_print_entry(oe, o);
|
|
||||||
ctx->print(ctx, "%s %s", oe->name, optval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
50
cmd-show-window-options.c
Normal file
50
cmd-show-window-options.c
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/* $Id: cmd-show-window-options.c,v 1.15 2009-12-04 22:11:23 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show window options. This is an alias for show-options -w.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_show_window_options_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_show_window_options_entry = {
|
||||||
|
"show-window-options", "showw",
|
||||||
|
"[-g] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, "g",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_show_window_options_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
|
||||||
|
cmd_set_flag(&data->chflags, 'w');
|
||||||
|
return (cmd_show_options_entry.exec(self, ctx));
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-source-file.c,v 1.13 2010-02-08 18:29:32 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -18,59 +18,114 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sources a configuration file.
|
* Sources a configuration file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_source_file_parse(struct cmd *, int, char **, char **);
|
||||||
|
int cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_source_file_free(struct cmd *);
|
||||||
|
void cmd_source_file_init(struct cmd *, int);
|
||||||
|
size_t cmd_source_file_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
|
struct cmd_source_file_data {
|
||||||
|
char *path;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_source_file_entry = {
|
const struct cmd_entry cmd_source_file_entry = {
|
||||||
"source-file", "source",
|
"source-file", "source",
|
||||||
"", 1, 1,
|
|
||||||
"path",
|
"path",
|
||||||
0,
|
0, "",
|
||||||
NULL,
|
cmd_source_file_init,
|
||||||
NULL,
|
cmd_source_file_parse,
|
||||||
cmd_source_file_exec
|
cmd_source_file_exec,
|
||||||
|
cmd_source_file_free,
|
||||||
|
cmd_source_file_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_source_file_init(struct cmd *self, unused int arg)
|
||||||
|
{
|
||||||
|
struct cmd_source_file_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->path = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_source_file_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_source_file_data *data;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
data->path = xstrdup(argv[0]);
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_source_file_data *data = self->data;
|
||||||
struct causelist causes;
|
struct causelist causes;
|
||||||
char *cause;
|
char *cause;
|
||||||
struct window_pane *wp;
|
u_int i;
|
||||||
int retval;
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
ARRAY_INIT(&causes);
|
ARRAY_INIT(&causes);
|
||||||
|
if (load_cfg(data->path, ctx, &causes) != 0) {
|
||||||
retval = load_cfg(args->argv[0], ctx, &causes);
|
|
||||||
if (ARRAY_EMPTY(&causes))
|
|
||||||
return (retval);
|
|
||||||
|
|
||||||
if (retval == 1 && !RB_EMPTY(&sessions) && ctx->cmdclient != NULL) {
|
|
||||||
wp = RB_MIN(sessions, &sessions)->curw->window->active;
|
|
||||||
window_pane_set_mode(wp, &window_copy_mode);
|
|
||||||
window_copy_init_for_output(wp);
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
|
|
||||||
cause = ARRAY_ITEM(&causes, i);
|
|
||||||
window_copy_add(wp, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
|
||||||
cause = ARRAY_ITEM(&causes, i);
|
cause = ARRAY_ITEM(&causes, i);
|
||||||
ctx->print(ctx, "%s", cause);
|
ctx->print(ctx, "%s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
}
|
}
|
||||||
|
ARRAY_FREE(&causes);
|
||||||
}
|
}
|
||||||
ARRAY_FREE(&causes);
|
|
||||||
|
|
||||||
return (retval);
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_source_file_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_source_file_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->path != NULL)
|
||||||
|
xfree(data->path);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_source_file_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_source_file_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->path != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->path);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-split-window.c,v 1.35 2010-07-02 02:49:19 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -27,50 +27,138 @@
|
|||||||
* Split a window (add a new pane).
|
* Split a window (add a new pane).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_split_window_key_binding(struct cmd *, int);
|
int cmd_split_window_parse(struct cmd *, int, char **, char **);
|
||||||
enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_split_window_free(struct cmd *);
|
||||||
|
void cmd_split_window_init(struct cmd *, int);
|
||||||
|
size_t cmd_split_window_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
|
struct cmd_split_window_data {
|
||||||
|
char *target;
|
||||||
|
char *cmd;
|
||||||
|
int flag_detached;
|
||||||
|
int flag_horizontal;
|
||||||
|
int percentage;
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_split_window_entry = {
|
const struct cmd_entry cmd_split_window_entry = {
|
||||||
"split-window", "splitw",
|
"split-window", "splitw",
|
||||||
"c:dF:l:hp:Pt:v", 0, 1,
|
"[-dhv] [-p percentage|-l size] [-t target-pane] [command]",
|
||||||
"[-dhvP] [-c start-directory] [-F format] [-p percentage|-l size] "
|
0, "",
|
||||||
"[-t target-pane] [command]",
|
cmd_split_window_init,
|
||||||
0,
|
cmd_split_window_parse,
|
||||||
cmd_split_window_key_binding,
|
cmd_split_window_exec,
|
||||||
NULL,
|
cmd_split_window_free,
|
||||||
cmd_split_window_exec
|
cmd_split_window_print
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_split_window_key_binding(struct cmd *self, int key)
|
cmd_split_window_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
self->args = args_create(0);
|
struct cmd_split_window_data *data;
|
||||||
if (key == '%')
|
|
||||||
args_set(self->args, 'h', NULL);
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->target = NULL;
|
||||||
|
data->cmd = NULL;
|
||||||
|
data->flag_detached = 0;
|
||||||
|
data->flag_horizontal = 0;
|
||||||
|
data->percentage = -1;
|
||||||
|
data->size = -1;
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case '%':
|
||||||
|
data->flag_horizontal = 1;
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
data->flag_horizontal = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
|
cmd_split_window_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_split_window_data *data;
|
||||||
|
int opt;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "dhl:p:t:v")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'd':
|
||||||
|
data->flag_detached = 1;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
data->flag_horizontal = 1;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
if (data->percentage != -1 || data->size != -1)
|
||||||
|
break;
|
||||||
|
data->size = strtonum(optarg, 1, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "size %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
if (data->size != -1 || data->percentage != -1)
|
||||||
|
break;
|
||||||
|
data->percentage = strtonum(optarg, 1, 100, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "percentage %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
data->flag_horizontal = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 0 && argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
data->cmd = xstrdup(argv[0]);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_split_window_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
struct window_pane *wp, *new_wp = NULL;
|
struct window_pane *wp, *new_wp = NULL;
|
||||||
struct environ env;
|
struct environ env;
|
||||||
const char *cmd, *cwd, *shell;
|
char *cmd, *cwd, *cause;
|
||||||
char *cause, *new_cause;
|
const char *shell;
|
||||||
u_int hlimit;
|
u_int hlimit;
|
||||||
int size, percentage;
|
int size;
|
||||||
enum layout_type type;
|
enum layout_type type;
|
||||||
struct layout_cell *lc;
|
struct layout_cell *lc;
|
||||||
const char *template;
|
|
||||||
struct client *c;
|
|
||||||
struct format_tree *ft;
|
|
||||||
char *cp;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
if ((wl = cmd_find_pane(ctx, data->target, &s, &wp)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
w = wl->window;
|
w = wl->window;
|
||||||
|
|
||||||
environ_init(&env);
|
environ_init(&env);
|
||||||
@@ -78,37 +166,29 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
environ_copy(&s->environ, &env);
|
environ_copy(&s->environ, &env);
|
||||||
server_fill_environ(s, &env);
|
server_fill_environ(s, &env);
|
||||||
|
|
||||||
if (args->argc == 0)
|
cmd = data->cmd;
|
||||||
|
if (cmd == NULL)
|
||||||
cmd = options_get_string(&s->options, "default-command");
|
cmd = options_get_string(&s->options, "default-command");
|
||||||
else
|
cwd = options_get_string(&s->options, "default-path");
|
||||||
cmd = args->argv[0];
|
if (*cwd == '\0') {
|
||||||
cwd = cmd_get_default_path(ctx, args_get(args, 'c'));
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
|
cwd = ctx->cmdclient->cwd;
|
||||||
|
else
|
||||||
|
cwd = s->cwd;
|
||||||
|
}
|
||||||
|
|
||||||
type = LAYOUT_TOPBOTTOM;
|
type = LAYOUT_TOPBOTTOM;
|
||||||
if (args_has(args, 'h'))
|
if (data->flag_horizontal)
|
||||||
type = LAYOUT_LEFTRIGHT;
|
type = LAYOUT_LEFTRIGHT;
|
||||||
|
|
||||||
size = -1;
|
size = -1;
|
||||||
if (args_has(args, 'l')) {
|
if (data->size != -1)
|
||||||
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
size = data->size;
|
||||||
if (cause != NULL) {
|
else if (data->percentage != -1) {
|
||||||
xasprintf(&new_cause, "size %s", cause);
|
|
||||||
free(cause);
|
|
||||||
cause = new_cause;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
} else if (args_has(args, 'p')) {
|
|
||||||
percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
xasprintf(&new_cause, "percentage %s", cause);
|
|
||||||
free(cause);
|
|
||||||
cause = new_cause;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (type == LAYOUT_TOPBOTTOM)
|
if (type == LAYOUT_TOPBOTTOM)
|
||||||
size = (wp->sy * percentage) / 100;
|
size = (wp->sy * data->percentage) / 100;
|
||||||
else
|
else
|
||||||
size = (wp->sx * percentage) / 100;
|
size = (wp->sx * data->percentage) / 100;
|
||||||
}
|
}
|
||||||
hlimit = options_get_number(&s->options, "history-limit");
|
hlimit = options_get_number(&s->options, "history-limit");
|
||||||
|
|
||||||
@@ -116,7 +196,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
if (*shell == '\0' || areshell(shell))
|
if (*shell == '\0' || areshell(shell))
|
||||||
shell = _PATH_BSHELL;
|
shell = _PATH_BSHELL;
|
||||||
|
|
||||||
if ((lc = layout_split_pane(wp, type, size, 0)) == NULL) {
|
if ((lc = layout_split_pane(wp, type, size)) == NULL) {
|
||||||
cause = xstrdup("pane too small");
|
cause = xstrdup("pane too small");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@@ -128,7 +208,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
|
|
||||||
server_redraw_window(w);
|
server_redraw_window(w);
|
||||||
|
|
||||||
if (!args_has(args, 'd')) {
|
if (!data->flag_detached) {
|
||||||
window_set_active_pane(w, new_wp);
|
window_set_active_pane(w, new_wp);
|
||||||
session_select(s, wl->idx);
|
session_select(s, wl->idx);
|
||||||
server_redraw_session(s);
|
server_redraw_session(s);
|
||||||
@@ -136,32 +216,51 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
server_status_session(s);
|
server_status_session(s);
|
||||||
|
|
||||||
environ_free(&env);
|
environ_free(&env);
|
||||||
|
return (0);
|
||||||
if (args_has(args, 'P')) {
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = SPLIT_WINDOW_TEMPLATE;
|
|
||||||
|
|
||||||
ft = format_create();
|
|
||||||
if ((c = cmd_find_client(ctx, NULL)) != 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);
|
|
||||||
ctx->print(ctx, "%s", cp);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
}
|
|
||||||
notify_window_layout_changed(w);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
error:
|
error:
|
||||||
environ_free(&env);
|
environ_free(&env);
|
||||||
if (new_wp != NULL)
|
if (new_wp != NULL)
|
||||||
window_remove_pane(w, new_wp);
|
window_remove_pane(w, new_wp);
|
||||||
ctx->error(ctx, "create pane failed: %s", cause);
|
ctx->error(ctx, "create pane failed: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_split_window_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_split_window_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
if (data->cmd != NULL)
|
||||||
|
xfree(data->cmd);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_split_window_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_split_window_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->flag_detached)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && data->flag_horizontal)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -h");
|
||||||
|
if (off < len && data->size > 0)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -l %d", data->size);
|
||||||
|
if (off < len && data->percentage > 0) {
|
||||||
|
off += xsnprintf(
|
||||||
|
buf + off, len - off, " -p %d", data->percentage);
|
||||||
|
}
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->cmd != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-start-server.c,v 1.10 2009-11-28 14:50:36 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -24,21 +24,22 @@
|
|||||||
* Start the server and do nothing else.
|
* Start the server and do nothing else.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_start_server_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_start_server_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_start_server_entry = {
|
const struct cmd_entry cmd_start_server_entry = {
|
||||||
"start-server", "start",
|
"start-server", "start",
|
||||||
"", 0, 0,
|
|
||||||
"",
|
"",
|
||||||
CMD_STARTSERVER,
|
CMD_STARTSERVER, "",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
cmd_start_server_exec
|
cmd_start_server_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_start_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
cmd_start_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
29
cmd-string.c
29
cmd-string.c
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-string.c,v 1.32 2010-12-13 22:53:56 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -87,7 +87,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
|||||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||||
strlcpy(buf + len, t, strlen(t) + 1);
|
strlcpy(buf + len, t, strlen(t) + 1);
|
||||||
len += strlen(t);
|
len += strlen(t);
|
||||||
free(t);
|
xfree(t);
|
||||||
break;
|
break;
|
||||||
case '"':
|
case '"':
|
||||||
if ((t = cmd_string_string(s, &p, '"', 1)) == NULL)
|
if ((t = cmd_string_string(s, &p, '"', 1)) == NULL)
|
||||||
@@ -95,7 +95,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
|||||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||||
strlcpy(buf + len, t, strlen(t) + 1);
|
strlcpy(buf + len, t, strlen(t) + 1);
|
||||||
len += strlen(t);
|
len += strlen(t);
|
||||||
free(t);
|
xfree(t);
|
||||||
break;
|
break;
|
||||||
case '$':
|
case '$':
|
||||||
if ((t = cmd_string_variable(s, &p)) == NULL)
|
if ((t = cmd_string_variable(s, &p)) == NULL)
|
||||||
@@ -103,7 +103,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
|||||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||||
strlcpy(buf + len, t, strlen(t) + 1);
|
strlcpy(buf + len, t, strlen(t) + 1);
|
||||||
len += strlen(t);
|
len += strlen(t);
|
||||||
free(t);
|
xfree(t);
|
||||||
break;
|
break;
|
||||||
case '#':
|
case '#':
|
||||||
/* Comment: discard rest of line. */
|
/* Comment: discard rest of line. */
|
||||||
@@ -152,7 +152,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
|||||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||||
strlcpy(buf + len, t, strlen(t) + 1);
|
strlcpy(buf + len, t, strlen(t) + 1);
|
||||||
len += strlen(t);
|
len += strlen(t);
|
||||||
free(t);
|
xfree(t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
@@ -170,12 +170,13 @@ error:
|
|||||||
xasprintf(cause, "invalid or unknown command: %s", s);
|
xasprintf(cause, "invalid or unknown command: %s", s);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(buf);
|
if (buf != NULL)
|
||||||
|
xfree(buf);
|
||||||
|
|
||||||
if (argv != NULL) {
|
if (argv != NULL) {
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
free(argv[i]);
|
xfree(argv[i]);
|
||||||
free(argv);
|
xfree(argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (rval);
|
return (rval);
|
||||||
@@ -223,7 +224,7 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
|
|||||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||||
strlcpy(buf + len, t, strlen(t) + 1);
|
strlcpy(buf + len, t, strlen(t) + 1);
|
||||||
len += strlen(t);
|
len += strlen(t);
|
||||||
free(t);
|
xfree(t);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +239,8 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
|
|||||||
return (buf);
|
return (buf);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(buf);
|
if (buf != NULL)
|
||||||
|
xfree(buf);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,13 +303,14 @@ cmd_string_variable(const char *s, size_t *p)
|
|||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
|
|
||||||
envent = environ_find(&global_environ, buf);
|
envent = environ_find(&global_environ, buf);
|
||||||
free(buf);
|
xfree(buf);
|
||||||
if (envent == NULL)
|
if (envent == NULL)
|
||||||
return (xstrdup(""));
|
return (xstrdup(""));
|
||||||
return (xstrdup(envent->value));
|
return (xstrdup(envent->value));
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(buf);
|
if (buf != NULL)
|
||||||
|
xfree(buf);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,7 +334,7 @@ cmd_string_expand_tilde(const char *s, size_t *p)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
if ((pw = getpwnam(username)) != NULL)
|
if ((pw = getpwnam(username)) != NULL)
|
||||||
home = pw->pw_dir;
|
home = pw->pw_dir;
|
||||||
free(username);
|
xfree(username);
|
||||||
}
|
}
|
||||||
if (home == NULL)
|
if (home == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-suspend-client.c,v 1.5 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -27,30 +27,36 @@
|
|||||||
* Suspend client with SIGTSTP.
|
* Suspend client with SIGTSTP.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_suspend_client_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_suspend_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
struct cmd_suspend_client_data {
|
||||||
|
char *name;
|
||||||
|
char *target;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_suspend_client_entry = {
|
const struct cmd_entry cmd_suspend_client_entry = {
|
||||||
"suspend-client", "suspendc",
|
"suspend-client", "suspendc",
|
||||||
"t:", 0, 0,
|
"[-c target-client]",
|
||||||
CMD_TARGET_CLIENT_USAGE,
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
NULL,
|
cmd_target_parse,
|
||||||
NULL,
|
cmd_suspend_client_exec,
|
||||||
cmd_suspend_client_exec
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
|
|
||||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
tty_stop_tty(&c->tty);
|
tty_stop_tty(&c->tty);
|
||||||
c->flags |= CLIENT_SUSPENDED;
|
c->flags |= CLIENT_SUSPENDED;
|
||||||
server_write_client(c, MSG_SUSPEND, NULL, 0);
|
server_write_client(c, MSG_SUSPEND, NULL, 0);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-swap-pane.c,v 1.15 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -26,65 +26,73 @@
|
|||||||
* Swap two panes.
|
* Swap two panes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmd_swap_pane_key_binding(struct cmd *, int);
|
void cmd_swap_pane_init(struct cmd *, int);
|
||||||
enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_swap_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_swap_pane_entry = {
|
const struct cmd_entry cmd_swap_pane_entry = {
|
||||||
"swap-pane", "swapp",
|
"swap-pane", "swapp",
|
||||||
"dDs:t:U", 0, 0,
|
|
||||||
"[-dDU] " CMD_SRCDST_PANE_USAGE,
|
"[-dDU] " CMD_SRCDST_PANE_USAGE,
|
||||||
0,
|
0, "dDU",
|
||||||
cmd_swap_pane_key_binding,
|
cmd_swap_pane_init,
|
||||||
NULL,
|
cmd_srcdst_parse,
|
||||||
cmd_swap_pane_exec
|
cmd_swap_pane_exec,
|
||||||
|
cmd_srcdst_free,
|
||||||
|
cmd_srcdst_print
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_swap_pane_key_binding(struct cmd *self, int key)
|
cmd_swap_pane_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
self->args = args_create(0);
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_srcdst_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
if (key == '{')
|
if (key == '{')
|
||||||
args_set(self->args, 'U', NULL);
|
cmd_set_flag(&data->chflags, 'U');
|
||||||
else if (key == '}')
|
else if (key == '}')
|
||||||
args_set(self->args, 'D', NULL);
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
|
int
|
||||||
cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_srcdst_data *data = self->data;
|
||||||
struct winlink *src_wl, *dst_wl;
|
struct winlink *src_wl, *dst_wl;
|
||||||
struct window *src_w, *dst_w;
|
struct window *src_w, *dst_w;
|
||||||
struct window_pane *tmp_wp, *src_wp, *dst_wp;
|
struct window_pane *tmp_wp, *src_wp, *dst_wp;
|
||||||
struct layout_cell *src_lc, *dst_lc;
|
struct layout_cell *src_lc, *dst_lc;
|
||||||
u_int sx, sy, xoff, yoff;
|
u_int sx, sy, xoff, yoff;
|
||||||
|
|
||||||
dst_wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &dst_wp);
|
if (data == NULL)
|
||||||
if (dst_wl == NULL)
|
return (0);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
if ((dst_wl = cmd_find_pane(ctx, data->dst, NULL, &dst_wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
dst_w = dst_wl->window;
|
dst_w = dst_wl->window;
|
||||||
|
|
||||||
if (!args_has(args, 's')) {
|
if (data->src == NULL) {
|
||||||
src_w = dst_w;
|
src_w = dst_w;
|
||||||
if (args_has(self->args, 'D')) {
|
if (cmd_check_flag(data->chflags, 'D')) {
|
||||||
src_wp = TAILQ_NEXT(dst_wp, entry);
|
src_wp = TAILQ_NEXT(dst_wp, entry);
|
||||||
if (src_wp == NULL)
|
if (src_wp == NULL)
|
||||||
src_wp = TAILQ_FIRST(&dst_w->panes);
|
src_wp = TAILQ_FIRST(&dst_w->panes);
|
||||||
} else if (args_has(self->args, 'U')) {
|
} else if (cmd_check_flag(data->chflags, 'U')) {
|
||||||
src_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
src_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
||||||
if (src_wp == NULL)
|
if (src_wp == NULL)
|
||||||
src_wp = TAILQ_LAST(&dst_w->panes, window_panes);
|
src_wp = TAILQ_LAST(&dst_w->panes, window_panes);
|
||||||
} else
|
} else
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
} else {
|
} else {
|
||||||
src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp);
|
src_wl = cmd_find_pane(ctx, data->src, NULL, &src_wp);
|
||||||
if (src_wl == NULL)
|
if (src_wl == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
src_w = src_wl->window;
|
src_w = src_wl->window;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src_wp == dst_wp)
|
if (src_wp == dst_wp)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
tmp_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
tmp_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
||||||
TAILQ_REMOVE(&dst_w->panes, dst_wp, entry);
|
TAILQ_REMOVE(&dst_w->panes, dst_wp, entry);
|
||||||
@@ -113,7 +121,7 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
dst_wp->xoff = xoff; dst_wp->yoff = yoff;
|
dst_wp->xoff = xoff; dst_wp->yoff = yoff;
|
||||||
window_pane_resize(dst_wp, sx, sy);
|
window_pane_resize(dst_wp, sx, sy);
|
||||||
|
|
||||||
if (!args_has(self->args, 'd')) {
|
if (!cmd_check_flag(data->chflags, 'd')) {
|
||||||
if (src_w != dst_w) {
|
if (src_w != dst_w) {
|
||||||
window_set_active_pane(src_w, dst_wp);
|
window_set_active_pane(src_w, dst_wp);
|
||||||
window_set_active_pane(dst_w, src_wp);
|
window_set_active_pane(dst_w, src_wp);
|
||||||
@@ -129,14 +137,8 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
if (dst_w->active == dst_wp)
|
if (dst_w->active == dst_wp)
|
||||||
window_set_active_pane(dst_w, src_wp);
|
window_set_active_pane(dst_w, src_wp);
|
||||||
}
|
}
|
||||||
if (src_w != dst_w) {
|
|
||||||
if (src_w->last == src_wp)
|
|
||||||
src_w->last = NULL;
|
|
||||||
if (dst_w->last == dst_wp)
|
|
||||||
dst_w->last = NULL;
|
|
||||||
}
|
|
||||||
server_redraw_window(src_w);
|
server_redraw_window(src_w);
|
||||||
server_redraw_window(dst_w);
|
server_redraw_window(dst_w);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id$ */
|
/* $Id: cmd-swap-window.c,v 1.19 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@@ -30,47 +30,45 @@ int cmd_swap_window_exec(struct cmd *, struct cmd_ctx *);
|
|||||||
|
|
||||||
const struct cmd_entry cmd_swap_window_entry = {
|
const struct cmd_entry cmd_swap_window_entry = {
|
||||||
"swap-window", "swapw",
|
"swap-window", "swapw",
|
||||||
"ds:t:", 0, 0,
|
|
||||||
"[-d] " CMD_SRCDST_WINDOW_USAGE,
|
"[-d] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
0,
|
0, "d",
|
||||||
NULL,
|
cmd_srcdst_init,
|
||||||
NULL,
|
cmd_srcdst_parse,
|
||||||
cmd_swap_window_exec
|
cmd_swap_window_exec,
|
||||||
|
cmd_srcdst_free,
|
||||||
|
cmd_srcdst_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_srcdst_data *data = self->data;
|
||||||
const char *target_src, *target_dst;
|
|
||||||
struct session *src, *dst;
|
struct session *src, *dst;
|
||||||
struct session_group *sg_src, *sg_dst;
|
struct session_group *sg_src, *sg_dst;
|
||||||
struct winlink *wl_src, *wl_dst;
|
struct winlink *wl_src, *wl_dst;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
|
|
||||||
target_src = args_get(args, 's');
|
if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||||
if ((wl_src = cmd_find_window(ctx, target_src, &src)) == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
if ((wl_dst = cmd_find_window(ctx, data->dst, &dst)) == NULL)
|
||||||
target_dst = args_get(args, 't');
|
return (-1);
|
||||||
if ((wl_dst = cmd_find_window(ctx, target_dst, &dst)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
sg_src = session_group_find(src);
|
sg_src = session_group_find(src);
|
||||||
sg_dst = session_group_find(dst);
|
sg_dst = session_group_find(dst);
|
||||||
if (src != dst &&
|
if (src != dst &&
|
||||||
sg_src != NULL && sg_dst != NULL && sg_src == sg_dst) {
|
sg_src != NULL && sg_dst != NULL && sg_src == sg_dst) {
|
||||||
ctx->error(ctx, "can't move window, sessions are grouped");
|
ctx->error(ctx, "can't move window, sessions are grouped");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wl_dst->window == wl_src->window)
|
if (wl_dst->window == wl_src->window)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
w = wl_dst->window;
|
w = wl_dst->window;
|
||||||
wl_dst->window = wl_src->window;
|
wl_dst->window = wl_src->window;
|
||||||
wl_src->window = w;
|
wl_src->window = w;
|
||||||
|
|
||||||
if (!args_has(self->args, 'd')) {
|
if (!cmd_check_flag(data->chflags, 'd')) {
|
||||||
session_select(dst, wl_dst->idx);
|
session_select(dst, wl_dst->idx);
|
||||||
if (src != dst)
|
if (src != dst)
|
||||||
session_select(src, wl_src->idx);
|
session_select(src, wl_src->idx);
|
||||||
@@ -83,5 +81,5 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user