mirror of
https://github.com/tmux/tmux.git
synced 2026-03-12 03:25:45 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2365b09d6a |
19
.gitignore
vendored
19
.gitignore
vendored
@@ -1,19 +0,0 @@
|
|||||||
*.o
|
|
||||||
*~
|
|
||||||
*.diff
|
|
||||||
*.patch
|
|
||||||
*.core
|
|
||||||
core
|
|
||||||
tags
|
|
||||||
.deps/
|
|
||||||
compat/.dirstamp
|
|
||||||
aclocal.m4
|
|
||||||
autom4te.cache/
|
|
||||||
config.log
|
|
||||||
config.status
|
|
||||||
etc/
|
|
||||||
tmux
|
|
||||||
Makefile
|
|
||||||
Makefile.in
|
|
||||||
configure
|
|
||||||
tmux.1.*
|
|
||||||
34
.mailmap
34
.mailmap
@@ -1,34 +0,0 @@
|
|||||||
Bob Beck <beck@openbsd.org> beck <beck>
|
|
||||||
Igor Sobrado <sobrado@openbsd.org> sobrado <sobrado>
|
|
||||||
Ingo Schwarze <schwarze@openbsd.org> schwarze <schwarze>
|
|
||||||
Jacek Masiulaniec <jacekm@openbsd.org> jacekm <jacekm>
|
|
||||||
Jason McIntyre <jmc@openbsd.org> jmc <jmc>
|
|
||||||
Jason McIntyre <jmc@openbsd.org> jcm <jcm>
|
|
||||||
Joel Sing <jsing@openbsd.org> jsing <jsing>
|
|
||||||
Jonathan Gray <jsg@openbsd.org> jsg <jsg>
|
|
||||||
Kenneth R Westerback <krw@openbsd.org> krw <krw>
|
|
||||||
Marc Espie <espie@openbsd.org> espie <espie>
|
|
||||||
Matthew Dempsky <matthew@openbsd.org> matthew <matthew>
|
|
||||||
Matthias Kilian <kili@openbsd.org> kili <kili>
|
|
||||||
Matthieu Herrb <matthieu@openbsd.org> matthieu <matthieu>
|
|
||||||
Miod Vallat <miod@openbsd.org> miod <miod>
|
|
||||||
Nicholas Marriott <nicholas.marriott@gmail.com> Nicholas Marriott <nicm@openbsd.org>
|
|
||||||
Nicholas Marriott <nicholas.marriott@gmail.com> nicm <nicm>
|
|
||||||
Nicholas Marriott <nicholas.marriott@gmail.com> no_author <no_author@example.org>
|
|
||||||
Okan Demirmen <okan@openbsd.org> okan <okan>
|
|
||||||
Philip Guenther <guenther@openbsd.org> guenther <guenther>
|
|
||||||
Pierre-Yves Ritschard <pyr@openbsd.org> pyr <pyr>
|
|
||||||
Ray Lai <ray@openbsd.org> ray <ray>
|
|
||||||
Ryan McBride <mcbride@openbsd.org> mcbride <mcbride>
|
|
||||||
Sebastian Benoit <benno@openbsd.org> benno <benno>
|
|
||||||
Stefan Sperling <stsp@openbsd.org> stsp <stsp>
|
|
||||||
Stuart Henderson <sthen@openbsd.org> sthen <sthen>
|
|
||||||
Ted Unangst <tedu@openbsd.org> tedu <tedu>
|
|
||||||
Theo de Raadt <deraadt@openbsd.org> deraadt <deraadt>
|
|
||||||
Theo de Raadt <deraadt@openbsd.org> Theo Deraadt <deraadt@openbsd.org>
|
|
||||||
Thomas Adam <thomas@xteddy.org> Thomas <thomas@xteddy.org>
|
|
||||||
Thomas Adam <thomas@xteddy.org> n6tadam <n6tadam@xteddy.org>
|
|
||||||
Thomas Adam <thomas@xteddy.org> Thomas Adam <thomas.adam@smoothwall.net>
|
|
||||||
Tobias Stoeckmann <tobias@openbsd.org> tobias <tobias>
|
|
||||||
Todd C Miller <millert@openbsd.org> millert <millert>
|
|
||||||
William Yodlowsky <william@openbsd.org> william <william>
|
|
||||||
10
.travis.yml
10
.travis.yml
@@ -1,10 +0,0 @@
|
|||||||
language: c
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- compiler: gcc
|
|
||||||
- compiler: clang
|
|
||||||
env: CFLAGS="-g -O2"
|
|
||||||
before_install:
|
|
||||||
- sudo apt-get update -qq
|
|
||||||
- sudo apt-get -y install debhelper autotools-dev dh-autoreconf file libncurses5-dev libevent-dev pkg-config libutempter-dev build-essential
|
|
||||||
script: (CFLAGS= ./autogen.sh) && ./configure --enable-debug && make
|
|
||||||
429
CHANGES
429
CHANGES
@@ -1,425 +1,3 @@
|
|||||||
CHANGES FROM 2.0 to 2.1 18 October 2015
|
|
||||||
|
|
||||||
Incompatible Changes
|
|
||||||
====================
|
|
||||||
|
|
||||||
* Mouse-mode has been rewritten. There's now no longer options for:
|
|
||||||
- mouse-resize-pane
|
|
||||||
- mouse-select-pane
|
|
||||||
- mouse-select-window
|
|
||||||
- mode-mouse
|
|
||||||
|
|
||||||
Instead there is just one option: 'mouse' which turns on mouse support
|
|
||||||
entirely.
|
|
||||||
* 'default-terminal' is now a session option. Furthermore, if this is set
|
|
||||||
to 'screen-*' then emulate what screen does. If italics are wanted, this
|
|
||||||
can be set to 'tmux' but this is still new and not necessarily supported
|
|
||||||
on all platforms with older ncurses installs.
|
|
||||||
* The c0-* options for rate-limiting have been removed. Instead, a backoff
|
|
||||||
approach is used.
|
|
||||||
|
|
||||||
Normal Changes
|
|
||||||
==============
|
|
||||||
|
|
||||||
* New formats:
|
|
||||||
- session_activity
|
|
||||||
- window_linked
|
|
||||||
- window_activity_format
|
|
||||||
- session_alerts
|
|
||||||
- session_last_attached
|
|
||||||
- client_pid
|
|
||||||
- pid
|
|
||||||
* 'copy-selection', 'append-selection', 'start-named-buffer' now understand
|
|
||||||
an '-x' flag to prevent it exiting copying mode.
|
|
||||||
* 'select-pane' now understands '-P' to set window/pane background colours.
|
|
||||||
* 'renumber-windows' now understands windows which are unlinked.
|
|
||||||
* 'bind' now understands multiple key tables. Allows for key-chaining.
|
|
||||||
* 'select-layout' understands '-o' to undo the last layout change.
|
|
||||||
* The environment is updated when switching sessions as well as attaching.
|
|
||||||
* 'select-pane' now understands '-M' for marking a pane. This marked pane
|
|
||||||
can then be used with commands which understand src-pane specifiers
|
|
||||||
automatically.
|
|
||||||
* If a session/window target is prefixed with '=' then only an exact match
|
|
||||||
is considered.
|
|
||||||
* 'move-window' understands '-a'.
|
|
||||||
* 'update-environment' understands '-E' when attach-session is used on an
|
|
||||||
already attached client.
|
|
||||||
* 'show-environment' understands '-s' to output Bourne-compatible commands.
|
|
||||||
* New option: 'history-file' to save/restore command prompt history.
|
|
||||||
* Copy mode is exited if the history is cleared whilst in copy-mode.
|
|
||||||
* 'copy-mode' learned '-e' to exit copy-mode when scrolling to end.
|
|
||||||
|
|
||||||
CHANGES FROM 1.9a to 2.0 6 March 2015
|
|
||||||
|
|
||||||
Incompatible Changes
|
|
||||||
====================
|
|
||||||
|
|
||||||
* The choose-list command has been removed.
|
|
||||||
* 'terminal-overrides' is now a server option, not a session option.
|
|
||||||
* 'message-limit' is now a server option, not a session option.
|
|
||||||
* 'monitor-content' option has been removed.
|
|
||||||
* 'pane_start_path' option has been removed.
|
|
||||||
* The "info" mechanism which used to (for some commands) provide feedback
|
|
||||||
has been removed, and like other commands, they now produce nothing on
|
|
||||||
success.
|
|
||||||
|
|
||||||
Normal Changes
|
|
||||||
==============
|
|
||||||
|
|
||||||
* tmux can now write an entry to utmp if the library 'utempter' is present
|
|
||||||
at compile time.
|
|
||||||
* set-buffer learned append mode (-a), and a corresponding
|
|
||||||
'append-selection' command has been added to copy-mode.
|
|
||||||
* choose-mode now has the following commands which can be bound:
|
|
||||||
- start-of-list
|
|
||||||
- end-of-list
|
|
||||||
- top-line
|
|
||||||
- bottom-line
|
|
||||||
|
|
||||||
* choose-buffer now understands UTF-8.
|
|
||||||
* Pane navigation has changed:
|
|
||||||
- The old way of always using the top or left if the choice is ambiguous.
|
|
||||||
- The new way of remembering the last used pane is annoying if the
|
|
||||||
layout is balanced and the leftmost is obvious to the user (because
|
|
||||||
clearly if we go right from the top-left in a tiled set of four we want
|
|
||||||
to end up in top-right, even if we were last using the bottom-right).
|
|
||||||
|
|
||||||
So instead, use a combination of both: if there is only one possible
|
|
||||||
pane alongside the current pane, move to it, otherwise choose the most
|
|
||||||
recently used of the choice.
|
|
||||||
* 'set-buffer' can now be told to give names to buffers.
|
|
||||||
* The 'new-session', 'new-window', 'split-window', and 'respawn-pane' commands
|
|
||||||
now understand multiple arguments and handle quoting problems correctly.
|
|
||||||
* 'capture-pane' understands '-S-' to mean the start of the pane, and '-E-' to
|
|
||||||
mean the end of the pane.
|
|
||||||
* Support for function keys beyond F12 has changed. The following explains:
|
|
||||||
- F13-F24 are S-F1 to S-F12
|
|
||||||
- F25-F36 are C-F1 to C-F12
|
|
||||||
- F37-F48 are C-S-F1 to C-S-F12
|
|
||||||
- F49-F60 are M-F1 to M-F12
|
|
||||||
- F61-F63 are M-S-F1 to M-S-F3
|
|
||||||
|
|
||||||
Therefore, F13 becomes a binding of S-F1, etc.
|
|
||||||
* Support using pane id as part of session or window specifier (so % means
|
|
||||||
session-of-%1 or window-of-%1) and window id as part of session
|
|
||||||
(so @1 means session-of-@1).
|
|
||||||
* 'copy-pipe' command now understands formats via -F
|
|
||||||
* 'if-shell' command now understands formats via -F
|
|
||||||
* 'split-window' and 'join-window' understand -b to create the pane to the left
|
|
||||||
or above the target pane.
|
|
||||||
|
|
||||||
CHANGES FROM 1.9 to 1.9a 22 February 2014
|
|
||||||
|
|
||||||
NOTE: This is a bug-fix release to address some important bugs which just
|
|
||||||
missed the 1.9 deadline, but were found afterwards.
|
|
||||||
|
|
||||||
Normal Changes
|
|
||||||
==============
|
|
||||||
|
|
||||||
* Fix crash due to uninitialized lastwp member of layout_cell
|
|
||||||
* Fix -fg/-bg/-style with 256 colour terminals.
|
|
||||||
|
|
||||||
CHANGES FROM 1.8 to 1.9, 20 February 2014
|
|
||||||
|
|
||||||
NOTE: This release has bumped the tmux protocol version. It is therefore
|
|
||||||
advised that the prior tmux server is restarted when this version of tmux is
|
|
||||||
installed, to avoid protocol mismatch errors for newer clients trying to
|
|
||||||
talk to an older running tmux server.
|
|
||||||
|
|
||||||
Incompatible Changes
|
|
||||||
====================
|
|
||||||
|
|
||||||
* 88 colour support has been removed.
|
|
||||||
* 'default-path' has been removed. The new-window command accepts '-c' to
|
|
||||||
cater for this. The previous value of "." can be replaced with: 'neww -c
|
|
||||||
$PWD', the previous value of '' which meant current path of the pane can
|
|
||||||
be specified as: 'neww -c "#{pane_current_path}"'
|
|
||||||
|
|
||||||
Deprecated Changes
|
|
||||||
==================
|
|
||||||
|
|
||||||
* The single format specifiers: #A -> #Z (where defined) have been
|
|
||||||
deprecated and replaced with longer-named equivalents, as listed in the
|
|
||||||
FORMATS section of the tmux manpage.
|
|
||||||
* The various foo-{fg,bg,attr} commands have been deprecated and replaced
|
|
||||||
with equivalent foo-style option instead. Currently this is still
|
|
||||||
backwards-compatible, but will be removed over time.
|
|
||||||
|
|
||||||
Normal Changes
|
|
||||||
==============
|
|
||||||
|
|
||||||
* A new environment variable TMUX_TMPDIR is now honoured, allowing the
|
|
||||||
socket directory to be set outside of TMPDIR (/tmp/ if not set).
|
|
||||||
* If -s not given to swap-pane the current pane is assumed.
|
|
||||||
* A #{pane_syncronized} format specifier has been added to be a conditional
|
|
||||||
format if a pane is in a syncronised mode (c.f. syncronize-panes)
|
|
||||||
* Tmux now runs under Cygwin natively.
|
|
||||||
* Formats can now be nested within each other and expanded accordingly.
|
|
||||||
* Added 'automatic-rename-format' option to allow the automatic rename
|
|
||||||
mechanism to use something other than the default of
|
|
||||||
#{pane_current_command}.
|
|
||||||
* new-session learnt '-c' to specify the starting directory for that session
|
|
||||||
and all subsequent windows therein.
|
|
||||||
* The session name is now shown in the message printed to the terminal when
|
|
||||||
a session is detached.
|
|
||||||
* Lots more format specifiers have been added.
|
|
||||||
* Server race conditions have been fixed; in particular commands are not run
|
|
||||||
until after the configuration file is read completely.
|
|
||||||
* Case insensitive searching in tmux's copy-mode is now possible.
|
|
||||||
* attach-session and switch-client learnt the '-t' option to accept a window
|
|
||||||
and/or a pane to use.
|
|
||||||
* Copy-mode is only exited if no selection is in progress.
|
|
||||||
* Paste key in copy-mode is now possible to enter text from the clipboard.
|
|
||||||
* status-interval set to '0' now works as intended.
|
|
||||||
* tmux now supports 256 colours running under fbterm.
|
|
||||||
* Many bug fixes!
|
|
||||||
|
|
||||||
CHANGES FROM 1.7 to 1.8, 26 March 2013
|
|
||||||
|
|
||||||
Incompatible Changes
|
|
||||||
====================
|
|
||||||
|
|
||||||
* layout redo/undo has been removed.
|
|
||||||
|
|
||||||
Normal Changes
|
|
||||||
==============
|
|
||||||
|
|
||||||
* Add halfpage up/down bindings to copy mode.
|
|
||||||
* Session choosing fixed to work with unattached sessions.
|
|
||||||
* New window options window-status-last-{attr,bg,fg} to denote the last
|
|
||||||
window which was active.
|
|
||||||
* Scrolling in copy-mode now scrolls the region without moving the mouse
|
|
||||||
cursor.
|
|
||||||
* run-shell learnt '-t' to specify the pane to use when displaying output.
|
|
||||||
* Support for middle-click pasting.
|
|
||||||
* choose-tree learns '-u' to start uncollapsed.
|
|
||||||
* select-window learnt '-T' to toggle to the last window if it's already
|
|
||||||
current.
|
|
||||||
* New session option 'assume-paste-time' for pasting text versus key-binding
|
|
||||||
actions.
|
|
||||||
* choose-* commands now work outside of an attached client.
|
|
||||||
* Aliases are now shown for list-commands command.
|
|
||||||
* Status learns about formats.
|
|
||||||
* Free-form options can be set with set-option if prepended with an '@'
|
|
||||||
sign.
|
|
||||||
* capture-pane learnt '-p' to send to stdout, and '-e' for capturing escape
|
|
||||||
sequences, and '-a' to capture the alternate screen, and '-P' to dump
|
|
||||||
pending output.
|
|
||||||
* Many new formats added (client_session, client_last_session, etc.)
|
|
||||||
* Control mode, which is a way for a client to send tmux commands.
|
|
||||||
Currently more useful to users of iterm2.
|
|
||||||
* resize-pane learnt '-x' and '-y' for absolute pane sizing.
|
|
||||||
* Config file loading now reports errors from all files which are loaded via
|
|
||||||
the 'source-file' command.
|
|
||||||
* 'copy-pipe' mode command to copy selection and pipe the selection to a
|
|
||||||
command.
|
|
||||||
* Panes can now emit focus notifications for certain applications
|
|
||||||
which use those.
|
|
||||||
* run-shell and if-shell now accept formats.
|
|
||||||
* resize-pane learnt '-Z' for zooming a pane temporarily.
|
|
||||||
* new-session learnt '-A' to make it behave like attach-session.
|
|
||||||
* set-option learnt '-o' to prevent setting an option which is already set.
|
|
||||||
* capture-pane and show-options learns '-q' to silence errors.
|
|
||||||
* New command 'wait-for' which blocks a client until woken up again.
|
|
||||||
* Resizing panes will now reflow the text inside them.
|
|
||||||
* Lots and lots of bug fixes, fixing memory-leaks, etc.
|
|
||||||
* Various manpage improvements.
|
|
||||||
|
|
||||||
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.
|
||||||
@@ -1975,3 +1553,10 @@ The list of older changes is below.
|
|||||||
emacs) that don't require scrolling regions (ESC[r) mostly work fine
|
emacs) that don't require scrolling regions (ESC[r) mostly work fine
|
||||||
(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: 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: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
|
||||||
|
LocalWords: dstidx srcname srcidx winlink lsw nabc sabc Exp Tiago Cunha dch
|
||||||
|
LocalWords: setw Chisnall renamew merdely eg Maier newname selectw neww Gass
|
||||||
|
|||||||
21
COPYING
21
COPYING
@@ -1,21 +0,0 @@
|
|||||||
THIS IS FOR INFORMATION ONLY, CODE IS UNDER THE LICENCE AT THE TOP OF ITS FILE.
|
|
||||||
|
|
||||||
The README, CHANGES, FAQ and TODO files are licensed under the ISC
|
|
||||||
license. Files under examples/ remain copyright their authors unless otherwise
|
|
||||||
stated in the file but permission has been received to distribute them with
|
|
||||||
tmux. All other files have a license and copyright notice at their start,
|
|
||||||
typically:
|
|
||||||
|
|
||||||
Copyright (c) <author>
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
||||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
||||||
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
153
FAQ
153
FAQ
@@ -95,21 +95,21 @@ aware of are (bearing in mind I haven't used screen for a few years now):
|
|||||||
- screen has builtin serial and telnet support; this is bloat and is unlikely
|
- screen has builtin serial and telnet support; this is bloat and is unlikely
|
||||||
to be added to tmux.
|
to be added to tmux.
|
||||||
|
|
||||||
|
- screen has support for updating utmp. Nobody has really come up with a clean,
|
||||||
|
portable way to do this without making tmux setuid or setgid yet.
|
||||||
|
|
||||||
- Environment handling is different.
|
- Environment handling is different.
|
||||||
|
|
||||||
- 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?
|
||||||
|
|
||||||
Check the latest version of tmux from Git to see if the problem is still
|
Please send bug reports by email to nicm@users.sourceforge.net or
|
||||||
reproducible. Sometimes the length of time between releases means a lot of
|
tmux-users@lists.sourceforge.net. Please include as much of the following
|
||||||
fixes can be sitting in Git and the problem might already be fixed.
|
|
||||||
|
|
||||||
Please send bug reports by email to nicholas.marriott@gmail.com or
|
|
||||||
tmux-users@googlegroups.com. Please include as much of the following
|
|
||||||
information as possible:
|
information as possible:
|
||||||
|
|
||||||
- the version of tmux you are running;
|
- the version of tmux you are running;
|
||||||
@@ -123,7 +123,7 @@ information as possible:
|
|||||||
|
|
||||||
* Why doesn't tmux do $x?
|
* Why doesn't tmux do $x?
|
||||||
|
|
||||||
Please send feature requests by email to tmux-users@googlegroups.com.
|
Please send feature requests by email to nicm@users.sourceforge.net.
|
||||||
|
|
||||||
* Why do you use the screen terminal description inside tmux? It sucks.
|
* Why do you use the screen terminal description inside tmux? It sucks.
|
||||||
|
|
||||||
@@ -239,31 +239,6 @@ would be welcome.
|
|||||||
|
|
||||||
vim users may also want to set the "ttyfast" option inside tmux.
|
vim users may also want to set the "ttyfast" option inside tmux.
|
||||||
|
|
||||||
* How do I make ctrl and shift arrow keys work in emacs?
|
|
||||||
|
|
||||||
The terminal-init-screen function in term/screen.el is called for new frames,
|
|
||||||
but it doesn't configure any function keys.
|
|
||||||
|
|
||||||
If the tmux xterm-keys option is on, it is enough to define the same keys as
|
|
||||||
xterm. Add the following to init.el or .emacs to do this:
|
|
||||||
|
|
||||||
(defadvice terminal-init-screen
|
|
||||||
;; The advice is named `tmux', and is run before `terminal-init-screen' runs.
|
|
||||||
(before tmux activate)
|
|
||||||
;; Docstring. This describes the advice and is made available inside emacs;
|
|
||||||
;; for example when doing C-h f terminal-init-screen RET
|
|
||||||
"Apply xterm keymap, allowing use of keys passed through tmux."
|
|
||||||
;; This is the elisp code that is run before `terminal-init-screen'.
|
|
||||||
(if (getenv "TMUX")
|
|
||||||
(let ((map (copy-keymap xterm-function-map)))
|
|
||||||
(set-keymap-parent map (keymap-parent input-decode-map))
|
|
||||||
(set-keymap-parent input-decode-map map))))
|
|
||||||
|
|
||||||
And ensure .tmux.conf contains "set -g xterm-keys on".
|
|
||||||
|
|
||||||
Alternatively, the screen.el file can be copied to the load path and
|
|
||||||
customized.
|
|
||||||
|
|
||||||
* Why doesn't elinks set the window title inside tmux?
|
* Why doesn't elinks set the window title inside tmux?
|
||||||
|
|
||||||
There isn't a way to detect if a terminal supports setting the window title, so
|
There isn't a way to detect if a terminal supports setting the window title, so
|
||||||
@@ -352,103 +327,49 @@ lock(1) or vlock(1)) by using the following:
|
|||||||
|
|
||||||
bind x set lock-command '/usr/bin/vlock' \; lock-client \; set lock-command 'tput civis && read -s -n1'
|
bind x set lock-command '/usr/bin/vlock' \; lock-client \; set lock-command 'tput civis && read -s -n1'
|
||||||
|
|
||||||
* I don't see italics! Or less and vim show italics and reverse the wrong way round!
|
* How can I open a new window in the same directory as the current window?
|
||||||
|
|
||||||
GNU screen does not support italics and the "screen" terminfo description uses
|
One option is to just run "TMUX= tmux" in the window. However, this only works if no
|
||||||
the italics escape sequence incorrectly.
|
command is running, so that you can input the command.
|
||||||
|
|
||||||
As of tmux 2.1, if default-terminal is set to "screen" or matches "screen-*",
|
A workaround is to let tmux know about the current path through an environment
|
||||||
tmux will behave like screen and italics will be disabled.
|
variable. To do so, use the following command:
|
||||||
|
|
||||||
To enable italics, create a new terminfo entry called "tmux" (some platforms
|
[ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD
|
||||||
may already have this, you can check with "infocmp tmux"):
|
|
||||||
|
|
||||||
$ cat <<EOF|tic -x -
|
Which sets TMUXPWD_i (where i is the number of the current window) to the path
|
||||||
tmux|tmux terminal multiplexer,
|
of the current directory. This command can be added to PS1, for example:
|
||||||
ritm=\E[23m, rmso=\E[27m, sitm=\E[3m, smso=\E[7m, Ms@,
|
|
||||||
use=xterm+tmux, use=screen,
|
|
||||||
|
|
||||||
tmux-256color|tmux with 256 colors,
|
PS1='$([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD)\h$ '
|
||||||
use=xterm+256setaf, use=tmux,
|
|
||||||
EOF
|
|
||||||
$
|
|
||||||
|
|
||||||
And tell tmux to use it in ~/.tmux.conf:
|
When a new window is created, the shell should be asked to change
|
||||||
|
directory. You can define a new binding (for example, if using GNU bash):
|
||||||
set -g default-terminal "tmux"
|
|
||||||
|
|
||||||
If using urxvt, make sure you have an italics capable font enabled. for
|
bind-key C-c run-shell 'tmux neww "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'
|
||||||
example, add to ~/.Xdefaults:
|
|
||||||
|
|
||||||
urxvt.italicFont: xft:Bitstream Vera Sans Mono:italic:autohint=true
|
This solution will work even if a command is currently running in the terminal,
|
||||||
|
but it will not work from a window that has just been swapped with another
|
||||||
|
because TMUXPWD_i will not be updated after a swap. However, once a new prompt
|
||||||
|
is displayed, TMUXPWD_i is updated properly.
|
||||||
|
|
||||||
* How can I make tmux use my terminal's scrollback buffer?
|
* tmux doesn't start with "daemon failed"
|
||||||
|
|
||||||
Normally, tmux enables the terminal's "alternate screen". Most terminals (such
|
tmux shows something similar to this when started:
|
||||||
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
|
fatal: server_start: daemon failed: No such file or directory
|
||||||
not have an alternate screen. Put the following in ~/.tmux.conf:
|
fatal: main_dispatch: imsg_read failed
|
||||||
|
|
||||||
set -ga terminal-overrides ',xterm*:smcup@:rmcup@'
|
A possible reason is that /dev/null is not a character device or is otherwise
|
||||||
|
inaccessible.
|
||||||
|
|
||||||
Adjust if your $TERM does not start with xterm.
|
Check with:
|
||||||
|
|
||||||
tmux will still emulate the alternate screen for applications run under tmux,
|
file /dev/null
|
||||||
so you don't really lose anything with this setting. The only disadvantage is
|
ls -l /dev/null
|
||||||
that when you exit tmux, it will not restore whatever was there before you
|
|
||||||
started.
|
|
||||||
|
|
||||||
* How do I see the default configuration?
|
If it is not a character device or has incorrect permissions, it can typically
|
||||||
|
be recreated with:
|
||||||
|
|
||||||
Show the default session options by starting a new tmux server with no
|
cd /dev && rm null && ./MAKEDEV null
|
||||||
configuration file:
|
|
||||||
|
|
||||||
$ tmux -Lfoo -f/dev/null start\; show -g
|
|
||||||
|
|
||||||
Or the default window options:
|
|
||||||
|
|
||||||
$ tmux -Lfoo -f/dev/null start\; show -gw
|
|
||||||
|
|
||||||
* How do I copy a selection from tmux to the system's clipboard?
|
|
||||||
|
|
||||||
When running in xterm(1), tmux can automatically send copied text to the
|
|
||||||
clipboard. This is controlled by the set-clipboard option and also needs this
|
|
||||||
X resource to be set:
|
|
||||||
|
|
||||||
XTerm*disallowedWindowOps: 20,21,SetXprop
|
|
||||||
|
|
||||||
For rxvt-unicode (urxvt), there is an unofficial Perl extension here:
|
|
||||||
|
|
||||||
http://anti.teamidiot.de/static/nei/*/Code/urxvt/
|
|
||||||
|
|
||||||
Otherwise a key binding for copy mode using xclip (or xsel) works:
|
|
||||||
|
|
||||||
bind -temacs-copy C-y copy-pipe "xclip -i >/dev/null"
|
|
||||||
|
|
||||||
Or for inside and outside copy mode with the prefix key:
|
|
||||||
|
|
||||||
bind C-y run -b "tmux save-buffer - | xclip -i"
|
|
||||||
|
|
||||||
On OS X, reattach-to-usernamespace lets pbcopy/pbpaste work:
|
|
||||||
|
|
||||||
https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
|
|
||||||
|
|
||||||
* Why do I see dots around a session when I attach to it?
|
$Id: FAQ,v 1.41 2010-12-15 23:31:30 nicm Exp $
|
||||||
|
|
||||||
tmux limits the size of the window to the smallest attached session. If
|
|
||||||
it didn't do this then it would be impossible to see the entire window.
|
|
||||||
The dots mark the size of the window tmux can display.
|
|
||||||
|
|
||||||
To avoid this, detach all other clients when attaching:
|
|
||||||
|
|
||||||
$ tmux attach -d
|
|
||||||
|
|
||||||
Or from inside tmux by detaching individual clients with C-b D or all
|
|
||||||
using:
|
|
||||||
|
|
||||||
C-b : attach -d
|
|
||||||
|
|||||||
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/
|
||||||
249
Makefile.am
249
Makefile.am
@@ -1,249 +0,0 @@
|
|||||||
# Makefile.am
|
|
||||||
|
|
||||||
# Obvious program stuff.
|
|
||||||
bin_PROGRAMS = tmux
|
|
||||||
CLEANFILES = tmux.1.mdoc tmux.1.man
|
|
||||||
|
|
||||||
# Distribution tarball options.
|
|
||||||
EXTRA_DIST = \
|
|
||||||
CHANGES FAQ README TODO COPYING examples compat/*.[ch] \
|
|
||||||
array.h compat.h tmux.h osdep-*.c mdoc2man.awk tmux.1
|
|
||||||
dist-hook:
|
|
||||||
make clean
|
|
||||||
grep "^#found_debug=" configure
|
|
||||||
|
|
||||||
# Preprocessor flags.
|
|
||||||
CPPFLAGS += @XOPEN_DEFINES@ -DTMUX_CONF="\"$(sysconfdir)/tmux.conf\""
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
if IS_GCC
|
|
||||||
CFLAGS += -std=gnu99 -O2
|
|
||||||
if IS_DEBUG
|
|
||||||
CFLAGS += -g
|
|
||||||
CFLAGS += -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
|
|
||||||
CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
|
|
||||||
CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
|
||||||
CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
|
|
||||||
CFLAGS += -Wdeclaration-after-statement -Wno-pointer-sign
|
|
||||||
CPPFLAGS += -DDEBUG
|
|
||||||
endif
|
|
||||||
if IS_COVERAGE
|
|
||||||
CFLAGS += -g -O0 --coverage
|
|
||||||
LDFLAGS += --coverage
|
|
||||||
endif
|
|
||||||
CPPFLAGS += -iquote.
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Set flags for Solaris.
|
|
||||||
if IS_SUNOS
|
|
||||||
if IS_GCC
|
|
||||||
CPPFLAGS += -D_XPG6 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
|
|
||||||
else
|
|
||||||
CPPFLAGS += -D_XPG4_2 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Set flags for Sun CC.
|
|
||||||
if IS_SUNCC
|
|
||||||
CFLAGS += -erroff=E_EMPTY_DECLARATION
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Set _LINUX_SOURCE_COMPAT for AIX for mallocing 0 bytes
|
|
||||||
if IS_AIX
|
|
||||||
DEFS += -D_LINUX_SOURCE_COMPAT=1
|
|
||||||
endif
|
|
||||||
|
|
||||||
# List of sources.
|
|
||||||
dist_tmux_SOURCES = \
|
|
||||||
alerts.c \
|
|
||||||
arguments.c \
|
|
||||||
attributes.c \
|
|
||||||
cfg.c \
|
|
||||||
client.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-tree.c \
|
|
||||||
cmd-clear-history.c \
|
|
||||||
cmd-command-prompt.c \
|
|
||||||
cmd-confirm-before.c \
|
|
||||||
cmd-copy-mode.c \
|
|
||||||
cmd-detach-client.c \
|
|
||||||
cmd-display-message.c \
|
|
||||||
cmd-display-panes.c \
|
|
||||||
cmd-find.c \
|
|
||||||
cmd-find-window.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-list-buffers.c \
|
|
||||||
cmd-list-clients.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-queue.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-set-buffer.c \
|
|
||||||
cmd-set-environment.c \
|
|
||||||
cmd-set-option.c \
|
|
||||||
cmd-show-environment.c \
|
|
||||||
cmd-show-messages.c \
|
|
||||||
cmd-show-options.c \
|
|
||||||
cmd-source-file.c \
|
|
||||||
cmd-split-window.c \
|
|
||||||
cmd-string.c \
|
|
||||||
cmd-swap-pane.c \
|
|
||||||
cmd-swap-window.c \
|
|
||||||
cmd-switch-client.c \
|
|
||||||
cmd-unbind-key.c \
|
|
||||||
cmd-wait-for.c \
|
|
||||||
cmd.c \
|
|
||||||
colour.c \
|
|
||||||
control.c \
|
|
||||||
control-notify.c \
|
|
||||||
environ.c \
|
|
||||||
format.c \
|
|
||||||
grid-cell.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.c \
|
|
||||||
session.c \
|
|
||||||
signal.c \
|
|
||||||
status.c \
|
|
||||||
style.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_FPARSELN
|
|
||||||
nodist_tmux_SOURCES += compat/fparseln.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
|
|
||||||
if NO_CFMAKERAW
|
|
||||||
nodist_tmux_SOURCES += compat/cfmakeraw.c
|
|
||||||
endif
|
|
||||||
if NO_OPENAT
|
|
||||||
nodist_tmux_SOURCES += compat/openat.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Install tmux.1 in the right format.
|
|
||||||
install-exec-hook:
|
|
||||||
if test x@MANFORMAT@ = xmdoc; then \
|
|
||||||
sed -e "s|@SYSCONFDIR@|$(sysconfdir)|g" $(srcdir)/tmux.1 \
|
|
||||||
>$(srcdir)/tmux.1.mdoc; \
|
|
||||||
else \
|
|
||||||
sed -e "s|@SYSCONFDIR@|$(sysconfdir)|g" $(srcdir)/tmux.1| \
|
|
||||||
$(AWK) -f$(srcdir)/mdoc2man.awk >$(srcdir)/tmux.1.man; \
|
|
||||||
fi
|
|
||||||
$(mkdir_p) $(DESTDIR)$(mandir)/man1
|
|
||||||
$(INSTALL_DATA) $(srcdir)/tmux.1.@MANFORMAT@ \
|
|
||||||
$(DESTDIR)$(mandir)/man1/tmux.1
|
|
||||||
66
NOTES
Normal file
66
NOTES
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
Welcome to tmux!
|
||||||
|
|
||||||
|
tmux is a "terminal multiplexer", it enables a number of terminals (or windows)
|
||||||
|
to be accessed and controlled from a single terminal. tmux is intended to be a
|
||||||
|
simple, modern, BSD-licensed alternative to programs such as GNU screen.
|
||||||
|
|
||||||
|
This release runs on OpenBSD, FreeBSD, NetBSD, Linux and OS X and may still
|
||||||
|
run on Solaris and AIX (although they haven't been tested in a while). It is
|
||||||
|
usable, although there remain a number of missing features and some remaining
|
||||||
|
bugs are expected.
|
||||||
|
|
||||||
|
Since the 1.2 release that tmux depends on libevent. Download the stable
|
||||||
|
version from:
|
||||||
|
|
||||||
|
http://www.monkey.org/~provos/libevent/
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
A more extensive, but rough, todo list is included in the TODO file.
|
||||||
|
|
||||||
|
tmux also depends on several features of the client terminal (TERM), if these
|
||||||
|
are missing it may refuse to run, or not behave correctly.
|
||||||
|
|
||||||
|
A Vim syntax file is available in the examples directory. To install it:
|
||||||
|
|
||||||
|
- Drop the file in the syntax directory in your runtimepath (such as
|
||||||
|
~/.vim/syntax/tmux.vim).
|
||||||
|
- Make the filetype recognisable by adding the following to filetype.vim
|
||||||
|
in your runtimepath (~/.vim/filetype.vim):
|
||||||
|
|
||||||
|
augroup filetypedetect
|
||||||
|
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
- 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
|
||||||
|
files in the current directory.
|
||||||
|
|
||||||
|
tmux mailing lists are available; visit:
|
||||||
|
|
||||||
|
https://sourceforge.net/mail/?group_id=200378
|
||||||
|
|
||||||
|
Bug reports, feature suggestions and especially code contributions are most
|
||||||
|
welcome. Please send by email to:
|
||||||
|
|
||||||
|
nicm@users.sf.net
|
||||||
|
|
||||||
|
This file and the CHANGES, FAQ and TODO files are licensed under the ISC
|
||||||
|
license. Files under examples/ remain copyright their authors unless otherwise
|
||||||
|
stated in the file but permission has been received to distribute them with
|
||||||
|
tmux. All other files have a license and copyright notice at their
|
||||||
|
start. Please contact me with any queries.
|
||||||
|
|
||||||
|
-- Nicholas Marriott <nicm@users.sf.net>
|
||||||
|
|
||||||
|
$Id: NOTES,v 1.54 2010-12-27 21:36:37 tcunha Exp $
|
||||||
61
README
61
README
@@ -1,61 +0,0 @@
|
|||||||
Welcome to tmux!
|
|
||||||
|
|
||||||
tmux is a "terminal multiplexer", it enables a number of terminals (or windows)
|
|
||||||
to be accessed and controlled from a single terminal. tmux is intended to be a
|
|
||||||
simple, modern, BSD-licensed alternative to programs such as GNU screen.
|
|
||||||
|
|
||||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, OS X and Solaris.
|
|
||||||
|
|
||||||
tmux depends on libevent 2.x. Download it from:
|
|
||||||
|
|
||||||
http://www.monkey.org/~provos/libevent/
|
|
||||||
|
|
||||||
To build tmux from a release tarball, do:
|
|
||||||
|
|
||||||
$ ./configure && make
|
|
||||||
$ sudo make install
|
|
||||||
|
|
||||||
To get and build the latest from version control:
|
|
||||||
|
|
||||||
$ git clone https://github.com/tmux/tmux.git
|
|
||||||
$ cd tmux
|
|
||||||
$ sh autogen.sh
|
|
||||||
$ ./configure && make
|
|
||||||
|
|
||||||
For more information see http://git-scm.com. Patches should be sent by email to
|
|
||||||
the mailing list at tmux-users@googlegroups.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 and some example configurations and a Vim syntax file are in the examples
|
|
||||||
directory.
|
|
||||||
|
|
||||||
For debugging, running tmux with -v or -vv will generate server and client log
|
|
||||||
files in the current directory.
|
|
||||||
|
|
||||||
tmux mailing lists are available. For general discussion and bug reports:
|
|
||||||
|
|
||||||
https://groups.google.com/forum/#!forum/tmux-users
|
|
||||||
|
|
||||||
And for Git commit emails:
|
|
||||||
|
|
||||||
https://groups.google.com/forum/#!forum/tmux-git
|
|
||||||
|
|
||||||
Bug reports, feature suggestions and especially code contributions are most
|
|
||||||
welcome. Please send by email to:
|
|
||||||
|
|
||||||
tmux-users@googlegroups.com
|
|
||||||
|
|
||||||
This file and the CHANGES, FAQ, SYNCING and TODO files are licensed under
|
|
||||||
the ISC license. Files under examples/ remain copyright their authors unless
|
|
||||||
otherwise stated in the file but permission has been received to distribute
|
|
||||||
them with tmux. All other files have a license and copyright notice at their
|
|
||||||
start.
|
|
||||||
|
|
||||||
-- Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
176
SYNCING
176
SYNCING
@@ -1,176 +0,0 @@
|
|||||||
Preamble
|
|
||||||
========
|
|
||||||
|
|
||||||
Tmux portable relies on repositories "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 at least that long to appear in this git repository.
|
|
||||||
(It might take longer, depending on the CVS mirror used to import the
|
|
||||||
OpenBSD code).
|
|
||||||
|
|
||||||
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 https://github.com/tmux/tmux.git
|
|
||||||
% git clone https://github.com/ThomasAdam/tmux-openbsd.git
|
|
||||||
|
|
||||||
Note that you do not need additional 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":
|
|
||||||
|
|
||||||
% 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
|
|
||||||
|
|
||||||
Keeping an eye on libutil in OpenBSD
|
|
||||||
====================================
|
|
||||||
|
|
||||||
A lot of the compat/ code in tmux comes from libutil, especially imsg.
|
|
||||||
Sometimes the API can change, etc., which might cause interesting problems
|
|
||||||
trying to run the portable version of tmux. It's worth checking
|
|
||||||
periodically for any changes to libutil in OpenBSD and syncing those files
|
|
||||||
to compat/ as and when appropriate.
|
|
||||||
|
|
||||||
Release tmux for next version
|
|
||||||
=============================
|
|
||||||
|
|
||||||
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 README 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 2.X
|
|
||||||
|
|
||||||
Where "2.X" is the next version.
|
|
||||||
|
|
||||||
Push the tag out with:
|
|
||||||
|
|
||||||
% git push 2.X
|
|
||||||
|
|
||||||
4. Build the tarball with 'make dist'.
|
|
||||||
|
|
||||||
5. Check the tarball. If it's good, go here to select the tag just pushed:
|
|
||||||
|
|
||||||
https://github.com/tmux/tmux/tags
|
|
||||||
|
|
||||||
Click the "Add release notes", upload the tarball and add a link in the
|
|
||||||
description field to the CHANGES file.
|
|
||||||
|
|
||||||
7. Clone the tmux.github.io repository, and change the RELEASE version in
|
|
||||||
the Makefile. Commit it, and run 'make' to replace %%VERSION%%. Push
|
|
||||||
the result out.
|
|
||||||
|
|
||||||
8. Bump version in tmu/tmux.git configure.ac and uncomment "found_debug=yes" to
|
|
||||||
create a debug build by default.
|
|
||||||
252
TODO
252
TODO
@@ -1,126 +1,130 @@
|
|||||||
- command bits and pieces:
|
- better errors when creating new windows/sessions (how?)
|
||||||
* allow multiple targets: fnmatch for -t/-c, for example detach all
|
- implicitly add exec to the commands for new windows (switch to disable it)?
|
||||||
clients with -t*
|
- it would be nice to have multichar commands eg C-b K K
|
||||||
* add -c for new-session like new-window
|
- commands:
|
||||||
* ' and " should be parsed the same (eg "\e" vs '\e') in config
|
extend list-clients to list clients attached to a session (-a for all?)
|
||||||
and command prompt
|
bring back detach-session to detach all clients on a session?
|
||||||
* last-pane across sessions
|
- 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
|
||||||
- make command sequences more usable
|
in $x time
|
||||||
* don't require space after ;
|
- lift SHRT_MAX limits for history?
|
||||||
* options for error handling: && and ||?
|
- flags to centre screen in window
|
||||||
|
- activity/bell should be per-window not per-link? what if it is cur win in
|
||||||
- options bits and pieces:
|
session not being watched?
|
||||||
* set-remain-on-exit is a complete hack
|
- next prev word etc in command prompt
|
||||||
* way to set socket path from config file
|
- 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
|
||||||
- format improvements:
|
number in status line/top-right would be cool for this
|
||||||
* option to quote format (#{session_name:quoted})
|
- support other mouse modes (highlight etc) and use it in copy mode
|
||||||
* formats need conditions for >0 (for #P)
|
- set-remain-on-exit is a bit of a hack, some way to do it generically?
|
||||||
* some way to pad # stuff with spaces
|
- clear window title on exit
|
||||||
* last window update time and format for it
|
- would be nice to be able to use "--" to mark start of command w/ neww etc
|
||||||
* formats to show if a window is linked into multiple sessions, into
|
to avoid quoting
|
||||||
multiple attached sessions, and is the active window in multiple
|
- make command sequences more usable: don't require space after ;, handle
|
||||||
attached sessions?
|
errors better
|
||||||
|
- attach should have a flag to create session if it doesn't exist
|
||||||
- choose mode improvements:
|
- choice and more mode would be better per client than per window?
|
||||||
* choose-pane command (augment choose-tree to do this?)
|
- hooks to which commands may be attached, for example: tmux add-hook
|
||||||
* choose-mode and copy-mode are very similar, make choose-mode a subset?
|
"new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file
|
||||||
* flag to choose-* for sort order
|
$HOME/.tmux-session.conf
|
||||||
* choose mode would be better per client than per window?
|
- get it passing all the vttest tests that don't require resizing the terminal
|
||||||
* two choices (first one then second, for swap-pane and join-pane)
|
- way to set socket path from config file
|
||||||
* choose modes should ditch the key bindings and just have fixed keys, and
|
- what about utmp etc? can tmux update it like screen? setgid?
|
||||||
be more customized to their purpose (d to delete a buffer for choose-buffer,
|
|
||||||
a preview of buffer contents, etc)
|
|
||||||
|
|
||||||
- improve monitor-*:
|
|
||||||
* straighten out rules for multiple clients
|
|
||||||
* think about what happens across sessions
|
|
||||||
* monitor changes within a region
|
|
||||||
* perhaps monitor /all/ panes in the window not just one
|
|
||||||
|
|
||||||
- improve mouse support:
|
|
||||||
* bind commands to mouse in different areas?
|
|
||||||
* commands executed when clicking on a pattern (URL)
|
|
||||||
|
|
||||||
- hooks!
|
|
||||||
|
|
||||||
- warts on current naming:
|
- warts on current naming:
|
||||||
* display-time but message-fg/bg/attr
|
- display-time but message-fg/bg/attr
|
||||||
* list-* vs show-*
|
- list-* vs show-*
|
||||||
* split-window -> split-pane?
|
- server-info
|
||||||
|
- up-pane/down-pane/swap-pane -U/swap-pane -D vs next-*/previous-*
|
||||||
|
- split-window -> split-pane??
|
||||||
|
- 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,
|
||||||
|
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
|
||||||
|
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
|
||||||
|
- handle resize better in copy mode
|
||||||
|
- way to copy stuff that is off screen due to resize
|
||||||
|
- commands should be able to succeed or fail and have || or && for command
|
||||||
|
lists
|
||||||
|
- some way to KEEP a command running continually and just use its LAST line of
|
||||||
|
output
|
||||||
|
- bind commands to mouse buttons
|
||||||
|
- UTF-8 to a non-UTF-8 terminal should not be able to balls up
|
||||||
|
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
|
||||||
|
- 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
|
||||||
|
- session history for client and last-session command
|
||||||
|
- option to change status line colour when current window is in a mode?
|
||||||
|
- option to move copy mode indicator into status line
|
||||||
|
- list-buffer/show-buffer should display UTF-8
|
||||||
|
- selection behaviour closer to vi in vi mode
|
||||||
|
- live update: server started with -U connects to server, requests sessions and
|
||||||
|
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:
|
||||||
|
should pick up default-path/termios/etc from client if possible,
|
||||||
|
else leave empty/default
|
||||||
|
- 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
|
||||||
|
- 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
|
||||||
|
- better session sharing: create-socket command to create socket somewhere (-r
|
||||||
|
flag for readonly)
|
||||||
|
- allow buffer to be specified when copying in copy mode
|
||||||
|
- multiline status line (no?)
|
||||||
|
- flag for absolute pane size to resize-pane
|
||||||
|
- sanity check input to socket
|
||||||
|
- select-buffer command
|
||||||
|
- support title stack, both internally and externally
|
||||||
|
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
|
||||||
|
- some way to pad # stuff with spaces, #!2T maybe
|
||||||
|
- FreeBSD console problems
|
||||||
|
- a binding to "scroll down and exit at bottom" copy mode
|
||||||
|
- some way to pass keystrokes in copy mode through to underlying window
|
||||||
|
- last window update time and # replacement for it for display-message
|
||||||
|
- find-window across sessions - other ways to make session handling easier?
|
||||||
|
- ' and " should be parsed the same (eg "\e" vs '\e') in config and command
|
||||||
|
prompt?
|
||||||
|
- command to toggle selection not to move it in copy-mode
|
||||||
|
- why are alerts per-winlink? try per window?
|
||||||
|
- audit of escape sequence support vs xterm
|
||||||
|
- support binding keys to mouse (mouse-select-pane -> mouse-keys or something,
|
||||||
|
mouse click == select-pane -t %%, mouse scroll up == copy-mode)
|
||||||
|
- something for -t "last window in session" so a session can be used as a stack
|
||||||
|
- synchronous commands - client sends cmd and blocks, neww/splitw saves client
|
||||||
|
ptr then when program inside died, sends MSG_SOMETHING with wait status to
|
||||||
|
client
|
||||||
|
- documentation improvements - rlpowell's tutorial - build instructions
|
||||||
|
- better configure? with-libevent
|
||||||
|
- bind commands to key sequences?
|
||||||
|
- monitor, bell etc should monitor /all/ panes in the window not just one
|
||||||
|
- a history of commands that can be reversed (reverse member of each command,
|
||||||
|
and a buffer) info() when changing to same window
|
||||||
|
- 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
|
||||||
|
- 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?
|
||||||
|
|
||||||
- better UTF-8 support:
|
|
||||||
* window names and titles
|
|
||||||
* message display
|
|
||||||
* prompt input
|
|
||||||
* multibyte key input
|
|
||||||
* searching in copy mode
|
|
||||||
|
|
||||||
- copy/paste improvements:
|
|
||||||
* incremental searching
|
|
||||||
* paste w/o trailing whitespace
|
|
||||||
* command to toggle selection not to move it in copy-mode
|
|
||||||
* regex searching
|
|
||||||
* copy-pipe should have -x as well
|
|
||||||
|
|
||||||
- layout stuff
|
|
||||||
* way to tag a layout as a number/name
|
|
||||||
* maybe keep last layout + size around and if size reverts just put it
|
|
||||||
back
|
|
||||||
* revamp layouts: they are too complicated, should be more closely
|
|
||||||
integrated, should support hints, layout sets should just be a
|
|
||||||
special case of custom layouts, and we should support panes that are
|
|
||||||
not attached to a cell at all. this could be the time to introduce
|
|
||||||
panelink to replace layout_cell
|
|
||||||
* way to set hints/limits about pane size for resizing
|
|
||||||
* panning over window (window larger than visible)
|
|
||||||
* a mode where one application can cross two panes (ie x|y, width =
|
|
||||||
COLUMNS/2 but height = ROWS * 2)
|
|
||||||
* general key to space cells out evenly (horiz or vert) within their
|
|
||||||
parent cell (could replace even-vert/even-horiz layouts)
|
|
||||||
* separate active panes for different clients
|
|
||||||
|
|
||||||
- terminfo bits
|
|
||||||
* use a better termcap internally instead of screen, perhaps xterm
|
|
||||||
* use screen-256color when started on 256 colour terminal?
|
|
||||||
|
|
||||||
- code cleanup
|
|
||||||
* instead of separate window and session options, just one master
|
|
||||||
options list with each option having a type (window or session), then
|
|
||||||
options on window, on session, and global. for window options we look
|
|
||||||
window->session->global, and for session we look session->global
|
|
||||||
* the way pane, window, session destroy is handled is too complicated
|
|
||||||
and the distinction between session.c, window.c and server-fn.c
|
|
||||||
functions is not clear. could we just have kill_pane(),
|
|
||||||
kill_window(), unlink_window(), kill_session() that fix up all data
|
|
||||||
structures (flagging sessions as dead) and return a value to say
|
|
||||||
whether clients need to be checked for dead sessions? sort of like
|
|
||||||
session_detach now but more so. or some other scheme to make it
|
|
||||||
simpler and clearer? also would be nice to remove/rename server-fn.c
|
|
||||||
* more readable way to work out the various things commands need to
|
|
||||||
know about the client, notably:
|
|
||||||
- is this the config file? (cmdq->c == NULL)
|
|
||||||
- is this a command client? (cmdq->c != NULL &&
|
|
||||||
cmdq->c->session == NULL)
|
|
||||||
- is this a control client?
|
|
||||||
- can i do stdin or stdout to this client?
|
|
||||||
or even guarantee that cmdq->c != NULL and provide a better way to
|
|
||||||
tell when in the config file - then we use cmdq->c if we need a
|
|
||||||
client w/o a session else cmd_current_client
|
|
||||||
* optimize pane redraws, 20120318184853.GK10965@yelena.nicm.ath.cx
|
|
||||||
|
|
||||||
- miscellaneous
|
|
||||||
* way to keep a job running just read its last line of output for #()
|
|
||||||
* link panes into multiple windows
|
|
||||||
* live update: server started with -U connects to server, requests
|
|
||||||
sessions and windows, receives file descriptors
|
|
||||||
* there are inconsistencies in what we get from old shell and what
|
|
||||||
comes from config for new sessions and windows. likewise, panes and
|
|
||||||
jobs and run-shell and lock command all start with slightly different
|
|
||||||
environments
|
|
||||||
* multiline status line?
|
|
||||||
* customizable command aliases
|
|
||||||
* automatic pane logging
|
|
||||||
* BCE? We are halfway there (output side is done for pane backgrounds),
|
|
||||||
just need to change how screen/grid handles erase
|
|
||||||
|
|||||||
263
alerts.c
263
alerts.c
@@ -1,263 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2015 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 <event.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
int alerts_fired;
|
|
||||||
|
|
||||||
void alerts_timer(int, short, void *);
|
|
||||||
int alerts_enabled(struct window *, int);
|
|
||||||
void alerts_callback(int, short, void *);
|
|
||||||
void alerts_reset(struct window *);
|
|
||||||
|
|
||||||
int alerts_check_bell(struct session *, struct winlink *);
|
|
||||||
int alerts_check_activity(struct session *, struct winlink *);
|
|
||||||
int alerts_check_silence(struct session *, struct winlink *);
|
|
||||||
void alerts_ring_bell(struct session *);
|
|
||||||
|
|
||||||
void
|
|
||||||
alerts_timer(unused int fd, unused short events, void *arg)
|
|
||||||
{
|
|
||||||
struct window *w = arg;
|
|
||||||
|
|
||||||
log_debug("@%u alerts timer expired", w->id);
|
|
||||||
alerts_reset(w);
|
|
||||||
alerts_queue(w, WINDOW_SILENCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
alerts_callback(unused int fd, unused short events, unused void *arg)
|
|
||||||
{
|
|
||||||
struct window *w;
|
|
||||||
struct session *s;
|
|
||||||
struct winlink *wl;
|
|
||||||
int flags, alerts;
|
|
||||||
|
|
||||||
RB_FOREACH(w, windows, &windows) {
|
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
|
||||||
if (wl->window != w)
|
|
||||||
continue;
|
|
||||||
flags = w->flags;
|
|
||||||
|
|
||||||
alerts = alerts_check_bell(s, wl);
|
|
||||||
alerts |= alerts_check_activity(s, wl);
|
|
||||||
alerts |= alerts_check_silence(s, wl);
|
|
||||||
if (alerts != 0)
|
|
||||||
server_status_session(s);
|
|
||||||
|
|
||||||
log_debug("%s:%d @%u alerts check, alerts %#x, "
|
|
||||||
"flags %#x", s->name, wl->idx, w->id,
|
|
||||||
alerts, flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
alerts_fired = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
alerts_enabled(struct window *w, int flags)
|
|
||||||
{
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
if (flags & WINDOW_ACTIVITY) {
|
|
||||||
if (options_get_number(&w->options, "monitor-activity"))
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
if (flags & WINDOW_SILENCE) {
|
|
||||||
if (options_get_number(&w->options, "monitor-silence") != 0)
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
if (~flags & WINDOW_BELL)
|
|
||||||
return (0);
|
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
|
||||||
if (!session_has(s, w))
|
|
||||||
continue;
|
|
||||||
if (options_get_number(&s->options, "bell-action") != BELL_NONE)
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
alerts_reset_all(void)
|
|
||||||
{
|
|
||||||
struct window *w;
|
|
||||||
|
|
||||||
RB_FOREACH(w, windows, &windows)
|
|
||||||
alerts_reset(w);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
alerts_reset(struct window *w)
|
|
||||||
{
|
|
||||||
struct timeval tv;
|
|
||||||
|
|
||||||
w->flags &= ~WINDOW_SILENCE;
|
|
||||||
event_del(&w->alerts_timer);
|
|
||||||
|
|
||||||
timerclear(&tv);
|
|
||||||
tv.tv_sec = options_get_number(&w->options, "monitor-silence");
|
|
||||||
|
|
||||||
log_debug("@%u alerts timer reset %u", w->id, (u_int)tv.tv_sec);
|
|
||||||
if (tv.tv_sec != 0)
|
|
||||||
event_add(&w->alerts_timer, &tv);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
alerts_queue(struct window *w, int flags)
|
|
||||||
{
|
|
||||||
if (w->flags & WINDOW_ACTIVITY)
|
|
||||||
alerts_reset(w);
|
|
||||||
|
|
||||||
if (!event_initialized(&w->alerts_timer))
|
|
||||||
evtimer_set(&w->alerts_timer, alerts_timer, w);
|
|
||||||
|
|
||||||
if (w->flags & flags)
|
|
||||||
return;
|
|
||||||
w->flags |= flags;
|
|
||||||
log_debug("@%u alerts flags added %#x", w->id, flags);
|
|
||||||
|
|
||||||
if (!alerts_fired && alerts_enabled(w, flags)) {
|
|
||||||
log_debug("alerts check queued (by @%u)", w->id);
|
|
||||||
event_once(-1, EV_TIMEOUT, alerts_callback, NULL, NULL);
|
|
||||||
alerts_fired = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
alerts_check_bell(struct session *s, struct winlink *wl)
|
|
||||||
{
|
|
||||||
struct client *c;
|
|
||||||
struct window *w = wl->window;
|
|
||||||
int action, visual;
|
|
||||||
|
|
||||||
if (!(w->flags & WINDOW_BELL) || wl->flags & WINLINK_BELL)
|
|
||||||
return (0);
|
|
||||||
if (s->curw != wl || s->flags & SESSION_UNATTACHED)
|
|
||||||
wl->flags |= WINLINK_BELL;
|
|
||||||
if (s->flags & SESSION_UNATTACHED)
|
|
||||||
return (0);
|
|
||||||
if (s->curw->window == w)
|
|
||||||
w->flags &= ~WINDOW_BELL;
|
|
||||||
|
|
||||||
action = options_get_number(&s->options, "bell-action");
|
|
||||||
if (action == BELL_NONE)
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
visual = options_get_number(&s->options, "visual-bell");
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
|
||||||
if (c->session != s || c->flags & CLIENT_CONTROL)
|
|
||||||
continue;
|
|
||||||
if (!visual) {
|
|
||||||
if ((action == BELL_CURRENT &&
|
|
||||||
c->session->curw->window == w) ||
|
|
||||||
(action == BELL_OTHER &&
|
|
||||||
c->session->curw->window != w) ||
|
|
||||||
action == BELL_ANY)
|
|
||||||
tty_putcode(&c->tty, TTYC_BEL);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (action == BELL_CURRENT && c->session->curw->window == w)
|
|
||||||
status_message_set(c, "Bell in current window");
|
|
||||||
else if (action == BELL_ANY || (action == BELL_OTHER &&
|
|
||||||
c->session->curw->window != w))
|
|
||||||
status_message_set(c, "Bell in window %d", wl->idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (WINDOW_BELL);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
alerts_check_activity(struct session *s, struct winlink *wl)
|
|
||||||
{
|
|
||||||
struct client *c;
|
|
||||||
struct window *w = wl->window;
|
|
||||||
|
|
||||||
if (s->curw->window == w)
|
|
||||||
w->flags &= ~WINDOW_ACTIVITY;
|
|
||||||
|
|
||||||
if (!(w->flags & WINDOW_ACTIVITY) || wl->flags & WINLINK_ACTIVITY)
|
|
||||||
return (0);
|
|
||||||
if (s->curw == wl && !(s->flags & SESSION_UNATTACHED))
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
if (!options_get_number(&w->options, "monitor-activity"))
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
if (options_get_number(&s->options, "bell-on-alert"))
|
|
||||||
alerts_ring_bell(s);
|
|
||||||
wl->flags |= WINLINK_ACTIVITY;
|
|
||||||
|
|
||||||
if (options_get_number(&s->options, "visual-activity")) {
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
|
||||||
if (c->session != s)
|
|
||||||
continue;
|
|
||||||
status_message_set(c, "Activity in window %d", wl->idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (WINDOW_ACTIVITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
alerts_check_silence(struct session *s, struct winlink *wl)
|
|
||||||
{
|
|
||||||
struct client *c;
|
|
||||||
struct window *w = wl->window;
|
|
||||||
|
|
||||||
if (s->curw->window == w)
|
|
||||||
w->flags &= ~WINDOW_SILENCE;
|
|
||||||
|
|
||||||
if (!(w->flags & WINDOW_SILENCE) || wl->flags & WINLINK_SILENCE)
|
|
||||||
return (0);
|
|
||||||
if (s->curw == wl && !(s->flags & SESSION_UNATTACHED))
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
if (options_get_number(&w->options, "monitor-silence") == 0)
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
if (options_get_number(&s->options, "bell-on-alert"))
|
|
||||||
alerts_ring_bell(s);
|
|
||||||
wl->flags |= WINLINK_SILENCE;
|
|
||||||
|
|
||||||
if (options_get_number(&s->options, "visual-silence")) {
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
|
||||||
if (c->session != s)
|
|
||||||
continue;
|
|
||||||
status_message_set(c, "Silence in window %d", wl->idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (WINDOW_SILENCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
alerts_ring_bell(struct session *s)
|
|
||||||
{
|
|
||||||
struct client *c;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
|
||||||
if (c->session == s && !(c->flags & CLIENT_CONTROL))
|
|
||||||
tty_putcode(&c->tty, TTYC_BEL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
263
arguments.c
263
arguments.c
@@ -1,263 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Manipulate command arguments.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct args_entry {
|
|
||||||
u_char flag;
|
|
||||||
char *value;
|
|
||||||
RB_ENTRY(args_entry) entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct args_entry *args_find(struct args *, u_char);
|
|
||||||
|
|
||||||
RB_GENERATE(args_tree, args_entry, entry, args_cmp);
|
|
||||||
|
|
||||||
/* Arguments tree comparison function. */
|
|
||||||
int
|
|
||||||
args_cmp(struct args_entry *a1, struct args_entry *a2)
|
|
||||||
{
|
|
||||||
return (a1->flag - a2->flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create an arguments set with no flags. */
|
|
||||||
struct args *
|
|
||||||
args_create(int argc, ...)
|
|
||||||
{
|
|
||||||
struct args *args;
|
|
||||||
va_list ap;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
args = xcalloc(1, sizeof *args);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find a flag in the arguments tree. */
|
|
||||||
struct args_entry *
|
|
||||||
args_find(struct args *args, u_char ch)
|
|
||||||
{
|
|
||||||
struct args_entry entry;
|
|
||||||
|
|
||||||
entry.flag = ch;
|
|
||||||
return (RB_FIND(args_tree, &args->tree, &entry));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse an argv and argc into a new argument set. */
|
|
||||||
struct args *
|
|
||||||
args_parse(const char *template, int argc, char **argv)
|
|
||||||
{
|
|
||||||
struct args *args;
|
|
||||||
int opt;
|
|
||||||
|
|
||||||
args = xcalloc(1, sizeof *args);
|
|
||||||
|
|
||||||
optreset = 1;
|
|
||||||
optind = 1;
|
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, template)) != -1) {
|
|
||||||
if (opt < 0)
|
|
||||||
continue;
|
|
||||||
if (opt == '?' || strchr(template, opt) == NULL) {
|
|
||||||
args_free(args);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
args_set(args, opt, 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)
|
|
||||||
{
|
|
||||||
struct args_entry *entry;
|
|
||||||
struct args_entry *entry1;
|
|
||||||
|
|
||||||
cmd_free_argv(args->argc, args->argv);
|
|
||||||
|
|
||||||
RB_FOREACH_SAFE(entry, args_tree, &args->tree, entry1) {
|
|
||||||
RB_REMOVE(args_tree, &args->tree, entry);
|
|
||||||
free(entry->value);
|
|
||||||
free(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print a set of arguments. */
|
|
||||||
size_t
|
|
||||||
args_print(struct args *args, char *buf, size_t len)
|
|
||||||
{
|
|
||||||
size_t off, used;
|
|
||||||
int i;
|
|
||||||
const char *quotes;
|
|
||||||
struct args_entry *entry;
|
|
||||||
|
|
||||||
/* There must be at least one byte at the start. */
|
|
||||||
if (len == 0)
|
|
||||||
return (0);
|
|
||||||
off = 0;
|
|
||||||
|
|
||||||
/* Process the flags first. */
|
|
||||||
buf[off++] = '-';
|
|
||||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
|
||||||
if (entry->value != NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (off == len - 1) {
|
|
||||||
buf[off] = '\0';
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
buf[off++] = entry->flag;
|
|
||||||
buf[off] = '\0';
|
|
||||||
}
|
|
||||||
if (off == 1)
|
|
||||||
buf[--off] = '\0';
|
|
||||||
|
|
||||||
/* Then the flags with arguments. */
|
|
||||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
|
||||||
if (entry->value == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (off >= len) {
|
|
||||||
/* snprintf will have zero terminated. */
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strchr(entry->value, ' ') != NULL)
|
|
||||||
quotes = "\"";
|
|
||||||
else
|
|
||||||
quotes = "";
|
|
||||||
used = xsnprintf(buf + off, len - off, "%s-%c %s%s%s",
|
|
||||||
off != 0 ? " " : "", entry->flag, quotes, entry->value,
|
|
||||||
quotes);
|
|
||||||
if (used > len - off)
|
|
||||||
used = len - off;
|
|
||||||
off += used;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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 = "";
|
|
||||||
used = xsnprintf(buf + off, len - off, "%s%s%s%s",
|
|
||||||
off != 0 ? " " : "", quotes, args->argv[i], quotes);
|
|
||||||
if (used > len - off)
|
|
||||||
used = len - off;
|
|
||||||
off += used;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (off);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return if an argument is present. */
|
|
||||||
int
|
|
||||||
args_has(struct args *args, u_char ch)
|
|
||||||
{
|
|
||||||
return (args_find(args, ch) == NULL ? 0 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set argument value in the arguments tree. */
|
|
||||||
void
|
|
||||||
args_set(struct args *args, u_char ch, const char *value)
|
|
||||||
{
|
|
||||||
struct args_entry *entry;
|
|
||||||
|
|
||||||
/* Replace existing argument. */
|
|
||||||
if ((entry = args_find(args, ch)) != NULL) {
|
|
||||||
free(entry->value);
|
|
||||||
entry->value = NULL;
|
|
||||||
} else {
|
|
||||||
entry = xcalloc(1, sizeof *entry);
|
|
||||||
entry->flag = ch;
|
|
||||||
RB_INSERT(args_tree, &args->tree, entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value != NULL)
|
|
||||||
entry->value = xstrdup(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get argument value. Will be NULL if it isn't present. */
|
|
||||||
const char *
|
|
||||||
args_get(struct args *args, u_char ch)
|
|
||||||
{
|
|
||||||
struct args_entry *entry;
|
|
||||||
|
|
||||||
if ((entry = args_find(args, ch)) == NULL)
|
|
||||||
return (NULL);
|
|
||||||
return (entry->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
struct args_entry *entry;
|
|
||||||
|
|
||||||
if ((entry = args_find(args, ch)) == NULL) {
|
|
||||||
*cause = xstrdup("missing");
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ll = strtonum(entry->value, minval, maxval, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
*cause = xstrdup(errstr);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
*cause = NULL;
|
|
||||||
return (ll);
|
|
||||||
}
|
|
||||||
11
array.h
11
array.h
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -39,10 +39,10 @@
|
|||||||
fatalx("size too big"); \
|
fatalx("size too big"); \
|
||||||
if ((a)->space == 0) { \
|
if ((a)->space == 0) { \
|
||||||
(a)->space = ARRAY_INITIALSPACE(a); \
|
(a)->space = ARRAY_INITIALSPACE(a); \
|
||||||
(a)->list = xrealloc((a)->list, (a)->space); \
|
(a)->list = xrealloc((a)->list, 1, (a)->space); \
|
||||||
} \
|
} \
|
||||||
while ((a)->space <= ((a)->num + (n)) * ARRAY_ITEMSIZE(a)) { \
|
while ((a)->space <= ((a)->num + (n)) * ARRAY_ITEMSIZE(a)) { \
|
||||||
(a)->list = xreallocarray((a)->list, 2, (a)->space); \
|
(a)->list = xrealloc((a)->list, 2, (a)->space); \
|
||||||
(a)->space *= 2; \
|
(a)->space *= 2; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
@@ -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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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);
|
||||||
}
|
}
|
||||||
|
|||||||
17
autogen.sh
17
autogen.sh
@@ -1,17 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ "x$(uname)" = "xOpenBSD" ]; then
|
|
||||||
[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.10
|
|
||||||
[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.65
|
|
||||||
fi
|
|
||||||
|
|
||||||
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"
|
|
||||||
261
cfg.c
261
cfg.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -17,196 +17,127 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
char *cfg_file;
|
/*
|
||||||
struct cmd_q *cfg_cmd_q;
|
* Config file parser. Pretty quick and simple, each line is parsed into a
|
||||||
int cfg_finished;
|
* argv array and executed as a command.
|
||||||
int cfg_references;
|
*/
|
||||||
char **cfg_causes;
|
|
||||||
u_int cfg_ncauses;
|
|
||||||
struct client *cfg_client;
|
|
||||||
|
|
||||||
void cfg_default_done(struct cmd_q *);
|
void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
|
||||||
|
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
|
||||||
|
|
||||||
void
|
char *cfg_cause;
|
||||||
set_cfg_file(const char *path)
|
int cfg_finished;
|
||||||
|
struct causelist cfg_causes = ARRAY_INITIALIZER;
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void printflike2
|
||||||
|
cfg_print(unused struct cmd_ctx *ctx, unused const char *fmt, ...)
|
||||||
{
|
{
|
||||||
free(cfg_file);
|
|
||||||
cfg_file = xstrdup(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/* ARGSUSED */
|
||||||
start_cfg(void)
|
void printflike2
|
||||||
|
cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char *cause = NULL;
|
va_list ap;
|
||||||
const char *home;
|
|
||||||
|
|
||||||
cfg_cmd_q = cmdq_new(NULL);
|
|
||||||
cfg_cmd_q->emptyfn = cfg_default_done;
|
|
||||||
|
|
||||||
cfg_finished = 0;
|
|
||||||
cfg_references = 1;
|
|
||||||
|
|
||||||
cfg_client = TAILQ_FIRST(&clients);
|
|
||||||
if (cfg_client != NULL)
|
|
||||||
cfg_client->references++;
|
|
||||||
|
|
||||||
if (access(TMUX_CONF, R_OK) == 0) {
|
|
||||||
if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1)
|
|
||||||
cfg_add_cause("%s: %s", TMUX_CONF, cause);
|
|
||||||
} else if (errno != ENOENT)
|
|
||||||
cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno));
|
|
||||||
|
|
||||||
if (cfg_file == NULL && (home = find_home()) != NULL) {
|
|
||||||
xasprintf(&cfg_file, "%s/.tmux.conf", home);
|
|
||||||
if (access(cfg_file, R_OK) != 0 && errno == ENOENT) {
|
|
||||||
free(cfg_file);
|
|
||||||
cfg_file = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cfg_file != NULL && load_cfg(cfg_file, cfg_cmd_q, &cause) == -1)
|
|
||||||
cfg_add_cause("%s: %s", cfg_file, cause);
|
|
||||||
free(cause);
|
|
||||||
|
|
||||||
cmdq_continue(cfg_cmd_q);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
char delim[3] = { '\\', '\\', '\0' };
|
|
||||||
u_int found;
|
|
||||||
size_t line = 0;
|
|
||||||
char *buf, *cause1, *p;
|
|
||||||
struct cmd_list *cmdlist;
|
|
||||||
|
|
||||||
log_debug("loading %s", path);
|
|
||||||
if ((f = fopen(path, "rb")) == NULL) {
|
|
||||||
xasprintf(cause, "%s: %s", path, strerror(errno));
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
found = 0;
|
|
||||||
while ((buf = fparseln(f, NULL, &line, delim, 0)) != NULL) {
|
|
||||||
log_debug("%s: %s", path, buf);
|
|
||||||
|
|
||||||
/* Skip empty lines. */
|
|
||||||
p = buf;
|
|
||||||
while (isspace((u_char) *p))
|
|
||||||
p++;
|
|
||||||
if (*p == '\0') {
|
|
||||||
free(buf);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse and run the command. */
|
|
||||||
if (cmd_string_parse(p, &cmdlist, path, line, &cause1) != 0) {
|
|
||||||
free(buf);
|
|
||||||
if (cause1 == NULL)
|
|
||||||
continue;
|
|
||||||
cfg_add_cause("%s:%zu: %s", path, line, cause1);
|
|
||||||
free(cause1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
if (cmdlist == NULL)
|
|
||||||
continue;
|
|
||||||
cmdq_append(cmdq, cmdlist, NULL);
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
found++;
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
return (found);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cfg_default_done(unused struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
if (--cfg_references != 0)
|
|
||||||
return;
|
|
||||||
cfg_finished = 1;
|
|
||||||
|
|
||||||
if (!RB_EMPTY(&sessions))
|
|
||||||
cfg_show_causes(RB_MIN(sessions, &sessions));
|
|
||||||
|
|
||||||
cmdq_free(cfg_cmd_q);
|
|
||||||
cfg_cmd_q = NULL;
|
|
||||||
|
|
||||||
if (cfg_client != NULL) {
|
|
||||||
/*
|
|
||||||
* The client command queue starts with client_exit set to 1 so
|
|
||||||
* only continue if not empty (that is, we have been delayed
|
|
||||||
* during configuration parsing for long enough that the
|
|
||||||
* MSG_COMMAND has arrived), else the client will exit before
|
|
||||||
* the MSG_COMMAND which might tell it not to.
|
|
||||||
*/
|
|
||||||
if (!TAILQ_EMPTY(&cfg_client->cmdq->queue))
|
|
||||||
cmdq_continue(cfg_client->cmdq);
|
|
||||||
server_client_unref(cfg_client);
|
|
||||||
cfg_client = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cfg_add_cause(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
char *msg;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
xvasprintf(&msg, fmt, ap);
|
xvasprintf(&cfg_cause, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printflike2
|
||||||
|
cfg_add_cause(struct causelist *causes, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char *cause;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
xvasprintf(&cause, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
cfg_ncauses++;
|
ARRAY_ADD(causes, cause);
|
||||||
cfg_causes = xreallocarray(cfg_causes, cfg_ncauses, sizeof *cfg_causes);
|
|
||||||
cfg_causes[cfg_ncauses - 1] = msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/*
|
||||||
cfg_print_causes(struct cmd_q *cmdq)
|
* Load configuration file. Returns -1 for an error with a list of messages in
|
||||||
|
* causes. Note that causes must be initialised by the caller!
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
||||||
{
|
{
|
||||||
u_int i;
|
FILE *f;
|
||||||
|
u_int n;
|
||||||
|
char *buf, *line, *cause;
|
||||||
|
size_t len;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
|
||||||
for (i = 0; i < cfg_ncauses; i++) {
|
if ((f = fopen(path, "rb")) == NULL) {
|
||||||
cmdq_print(cmdq, "%s", cfg_causes[i]);
|
cfg_add_cause(causes, "%s: %s", path, strerror(errno));
|
||||||
free(cfg_causes[i]);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
n = 0;
|
||||||
|
|
||||||
free(cfg_causes);
|
line = NULL;
|
||||||
cfg_causes = NULL;
|
while ((buf = fgetln(f, &len))) {
|
||||||
cfg_ncauses = 0;
|
if (buf[len - 1] == '\n')
|
||||||
}
|
buf[len - 1] = '\0';
|
||||||
|
else {
|
||||||
|
line = xrealloc(line, 1, len + 1);
|
||||||
|
memcpy(line, buf, len);
|
||||||
|
line[len] = '\0';
|
||||||
|
buf = line;
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
|
||||||
void
|
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
|
||||||
cfg_show_causes(struct session *s)
|
if (cause == NULL)
|
||||||
{
|
continue;
|
||||||
struct window_pane *wp;
|
cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
|
||||||
u_int i;
|
xfree(cause);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (cmdlist == NULL)
|
||||||
|
continue;
|
||||||
|
cfg_cause = NULL;
|
||||||
|
|
||||||
if (s == NULL || cfg_ncauses == 0)
|
if (ctxin == NULL) {
|
||||||
return;
|
ctx.msgdata = NULL;
|
||||||
wp = s->curw->window->active;
|
ctx.curclient = NULL;
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
} else {
|
||||||
|
ctx.msgdata = ctxin->msgdata;
|
||||||
|
ctx.curclient = ctxin->curclient;
|
||||||
|
ctx.cmdclient = ctxin->cmdclient;
|
||||||
|
}
|
||||||
|
|
||||||
window_pane_set_mode(wp, &window_copy_mode);
|
ctx.error = cfg_error;
|
||||||
window_copy_init_for_output(wp);
|
ctx.print = cfg_print;
|
||||||
for (i = 0; i < cfg_ncauses; i++) {
|
ctx.info = cfg_print;
|
||||||
window_copy_add(wp, "%s", cfg_causes[i]);
|
|
||||||
free(cfg_causes[i]);
|
cfg_cause = NULL;
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
if (cfg_cause != NULL) {
|
||||||
|
cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
|
||||||
|
xfree(cfg_cause);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (line != NULL)
|
||||||
|
xfree(line);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
free(cfg_causes);
|
if (ARRAY_LENGTH(causes) != 0)
|
||||||
cfg_causes = NULL;
|
return (-1);
|
||||||
cfg_ncauses = 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
617
client.c
617
client.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -26,84 +25,36 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <event.h>
|
#include <event.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
int client_flags;
|
|
||||||
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;
|
|
||||||
const char *client_exitsession;
|
|
||||||
int client_attached;
|
int client_attached;
|
||||||
|
|
||||||
__dead void client_exec(const char *);
|
int client_connect(char *, int);
|
||||||
int client_get_lock(char *);
|
void client_send_identify(int);
|
||||||
int client_connect(struct event_base *, char *, int);
|
void client_send_environ(void);
|
||||||
void client_send_identify(const char *, int);
|
void client_write_server(enum msgtype, void *, size_t);
|
||||||
int client_write_one(enum msgtype, int, const void *, size_t);
|
|
||||||
int client_write_server(enum msgtype, const 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");
|
|
||||||
log_debug("lock file is %s", lockfile);
|
|
||||||
|
|
||||||
if (flock(lockfd, LOCK_EX|LOCK_NB) == -1) {
|
|
||||||
log_debug("flock failed: %s", strerror(errno));
|
|
||||||
if (errno != EAGAIN)
|
|
||||||
return (lockfd);
|
|
||||||
while (flock(lockfd, LOCK_EX) == -1 && errno == EINTR)
|
|
||||||
/* nothing */;
|
|
||||||
close(lockfd);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
log_debug("flock succeeded");
|
|
||||||
|
|
||||||
return (lockfd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Connect client to server. */
|
/* Connect client to server. */
|
||||||
int
|
int
|
||||||
client_connect(struct event_base *base, char *path, int start_server)
|
client_connect(char *path, int start_server)
|
||||||
{
|
{
|
||||||
struct sockaddr_un sa;
|
struct sockaddr_un sa;
|
||||||
size_t size;
|
size_t size;
|
||||||
int fd, lockfd = -1, locked = 0;
|
int fd, mode;
|
||||||
char *lockfile = NULL;
|
|
||||||
|
|
||||||
memset(&sa, 0, sizeof sa);
|
memset(&sa, 0, sizeof sa);
|
||||||
sa.sun_family = AF_UNIX;
|
sa.sun_family = AF_UNIX;
|
||||||
@@ -112,118 +63,48 @@ client_connect(struct event_base *base, char *path, int start_server)
|
|||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
log_debug("socket is %s", path);
|
|
||||||
|
|
||||||
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");
|
||||||
|
|
||||||
log_debug("trying connect");
|
if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
|
||||||
if (connect(fd, (struct sockaddr *) &sa, sizeof(sa)) == -1) {
|
|
||||||
log_debug("connect failed: %s", strerror(errno));
|
|
||||||
if (errno != ECONNREFUSED && errno != ENOENT)
|
|
||||||
goto failed;
|
|
||||||
if (!start_server)
|
if (!start_server)
|
||||||
goto failed;
|
goto failed;
|
||||||
close(fd);
|
switch (errno) {
|
||||||
|
case ECONNREFUSED:
|
||||||
if (!locked) {
|
if (unlink(path) != 0)
|
||||||
xasprintf(&lockfile, "%s.lock", path);
|
goto failed;
|
||||||
if ((lockfd = client_get_lock(lockfile)) == -1) {
|
/* FALLTHROUGH */
|
||||||
log_debug("didn't get lock");
|
case ENOENT:
|
||||||
free(lockfile);
|
if ((fd = server_start()) == -1)
|
||||||
goto retry;
|
goto failed;
|
||||||
}
|
break;
|
||||||
log_debug("got lock");
|
default:
|
||||||
|
goto failed;
|
||||||
/*
|
|
||||||
* Always retry at least once, even if we got the lock,
|
|
||||||
* because another client could have taken the lock,
|
|
||||||
* started the server and released the lock between our
|
|
||||||
* connect() and flock().
|
|
||||||
*/
|
|
||||||
locked = 1;
|
|
||||||
goto retry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlink(path) != 0 && errno != ENOENT) {
|
|
||||||
free(lockfile);
|
|
||||||
close(lockfd);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
fd = server_start(base, lockfd, lockfile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locked) {
|
if ((mode = fcntl(fd, F_GETFL)) == -1)
|
||||||
free(lockfile);
|
fatal("fcntl failed");
|
||||||
close(lockfd);
|
if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||||
}
|
fatal("fcntl failed");
|
||||||
setblocking(fd, 0);
|
|
||||||
return (fd);
|
return (fd);
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
if (locked) {
|
|
||||||
free(lockfile);
|
|
||||||
close(lockfd);
|
|
||||||
}
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get exit string from reason number. */
|
|
||||||
const char *
|
|
||||||
client_exit_message(void)
|
|
||||||
{
|
|
||||||
static char msg[256];
|
|
||||||
|
|
||||||
switch (client_exitreason) {
|
|
||||||
case CLIENT_EXIT_NONE:
|
|
||||||
break;
|
|
||||||
case CLIENT_EXIT_DETACHED:
|
|
||||||
if (client_exitsession != NULL) {
|
|
||||||
xsnprintf(msg, sizeof msg, "detached "
|
|
||||||
"(from session %s)", client_exitsession);
|
|
||||||
return (msg);
|
|
||||||
}
|
|
||||||
return ("detached");
|
|
||||||
case CLIENT_EXIT_DETACHED_HUP:
|
|
||||||
if (client_exitsession != NULL) {
|
|
||||||
xsnprintf(msg, sizeof msg, "detached and SIGHUP "
|
|
||||||
"(from session %s)", client_exitsession);
|
|
||||||
return (msg);
|
|
||||||
}
|
|
||||||
return ("detached and SIGHUP");
|
|
||||||
case CLIENT_EXIT_LOST_TTY:
|
|
||||||
return ("lost tty");
|
|
||||||
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(struct event_base *base, int argc, char **argv, int flags)
|
client_main(int argc, char **argv, int flags)
|
||||||
{
|
{
|
||||||
struct cmd *cmd;
|
struct cmd *cmd;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
struct msg_command_data *data;
|
struct msg_command_data cmddata;
|
||||||
int cmdflags, fd, i, cwd;
|
int cmdflags, fd;
|
||||||
const char* ttynam;
|
|
||||||
pid_t ppid;
|
|
||||||
enum msgtype msg;
|
enum msgtype msg;
|
||||||
char *cause;
|
char *cause;
|
||||||
struct termios tio, saved_tio;
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
/* Save the flags. */
|
|
||||||
client_flags = flags;
|
|
||||||
|
|
||||||
/* Set up the initial command. */
|
/* Set up the initial command. */
|
||||||
cmdflags = 0;
|
cmdflags = 0;
|
||||||
@@ -232,7 +113,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
cmdflags = CMD_STARTSERVER;
|
cmdflags = CMD_STARTSERVER;
|
||||||
} else if (argc == 0) {
|
} else if (argc == 0) {
|
||||||
msg = MSG_COMMAND;
|
msg = MSG_COMMAND;
|
||||||
cmdflags = CMD_STARTSERVER;
|
cmdflags = CMD_STARTSERVER|CMD_SENDENVIRON|CMD_CANTNEST;
|
||||||
} else {
|
} else {
|
||||||
msg = MSG_COMMAND;
|
msg = MSG_COMMAND;
|
||||||
|
|
||||||
@@ -241,60 +122,39 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
* later in server) but it is necessary to get the start server
|
* later in server) but it is necessary to get the start server
|
||||||
* flag.
|
* flag.
|
||||||
*/
|
*/
|
||||||
cmdlist = cmd_list_parse(argc, argv, NULL, 0, &cause);
|
if ((cmdlist = cmd_list_parse(argc, argv, &cause)) == NULL) {
|
||||||
if (cmdlist == NULL) {
|
log_warnx("%s", cause);
|
||||||
fprintf(stderr, "%s\n", cause);
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
cmdflags &= ~CMD_STARTSERVER;
|
cmdflags &= ~CMD_STARTSERVER;
|
||||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
if (cmd->entry->flags & CMD_STARTSERVER)
|
if (cmd->entry->flags & CMD_STARTSERVER)
|
||||||
cmdflags |= CMD_STARTSERVER;
|
cmdflags |= CMD_STARTSERVER;
|
||||||
|
if (cmd->entry->flags & CMD_SENDENVIRON)
|
||||||
|
cmdflags |= CMD_SENDENVIRON;
|
||||||
|
if (cmd->entry->flags & CMD_CANTNEST)
|
||||||
|
cmdflags |= CMD_CANTNEST;
|
||||||
}
|
}
|
||||||
cmd_list_free(cmdlist);
|
cmd_list_free(cmdlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Establish signal handlers. */
|
/*
|
||||||
set_signals(client_signal);
|
* Check if this could be a nested session, if the command can't nest:
|
||||||
|
* if the socket path matches $TMUX, this is probably the same server.
|
||||||
/* Initialize the client socket and start the server. */
|
*/
|
||||||
fd = client_connect(base, socket_path, cmdflags & CMD_STARTSERVER);
|
if (shell_cmd == NULL && environ_path != NULL &&
|
||||||
if (fd == -1) {
|
cmdflags & CMD_CANTNEST && strcmp(socket_path, environ_path) == 0) {
|
||||||
if (errno == ECONNREFUSED) {
|
log_warnx("sessions should be nested with care. "
|
||||||
fprintf(stderr, "no server running on %s\n",
|
"unset $TMUX to force.");
|
||||||
socket_path);
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "error connecting to %s (%s)\n",
|
|
||||||
socket_path, strerror(errno));
|
|
||||||
}
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save these before pledge(). */
|
/* Initialise the client socket and start the server. */
|
||||||
if ((cwd = open(".", O_RDONLY)) == -1)
|
fd = client_connect(socket_path, cmdflags & CMD_STARTSERVER);
|
||||||
cwd = open("/", O_RDONLY);
|
if (fd == -1) {
|
||||||
if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
|
log_warn("failed to connect to server");
|
||||||
ttynam = "";
|
return (1);
|
||||||
|
}
|
||||||
#ifdef __OpenBSD__
|
|
||||||
/*
|
|
||||||
* Drop privileges for client. "proc exec" is needed for -c and for
|
|
||||||
* locking (which uses system(3)).
|
|
||||||
*
|
|
||||||
* "tty" is needed to restore termios(4) and also for some reason -CC
|
|
||||||
* does not work properly without it (input is not recognised).
|
|
||||||
*
|
|
||||||
* "sendfd" is dropped later in client_dispatch_wait().
|
|
||||||
*/
|
|
||||||
if (pledge("stdio unix sendfd proc exec tty", NULL) != 0)
|
|
||||||
fatal("pledge failed");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Free stuff that is not used in the client. */
|
|
||||||
options_free(&global_options);
|
|
||||||
options_free(&global_s_options);
|
|
||||||
options_free(&global_w_options);
|
|
||||||
environ_free(&global_environ);
|
|
||||||
|
|
||||||
/* Set process title, log and signals now this is the client. */
|
/* Set process title, log and signals now this is the client. */
|
||||||
#ifdef HAVE_SETPROCTITLE
|
#ifdef HAVE_SETPROCTITLE
|
||||||
@@ -304,59 +164,31 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
|
|
||||||
/* Create imsg. */
|
/* Create imsg. */
|
||||||
imsg_init(&client_ibuf, fd);
|
imsg_init(&client_ibuf, fd);
|
||||||
event_set(&client_event, fd, EV_READ, client_callback, NULL);
|
event_set(&client_event, fd, EV_READ, client_callback, shell_cmd);
|
||||||
|
|
||||||
/* Create stdin handler. */
|
/* Establish signal handlers. */
|
||||||
setblocking(STDIN_FILENO, 0);
|
set_signals(client_signal);
|
||||||
event_set(&client_stdin, STDIN_FILENO, EV_READ|EV_PERSIST,
|
|
||||||
client_stdin_callback, NULL);
|
|
||||||
if (client_flags & CLIENT_CONTROLCONTROL) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Send identify messages. */
|
/* Send initial environment. */
|
||||||
client_send_identify(ttynam, cwd); /* closes cwd */
|
if (cmdflags & CMD_SENDENVIRON)
|
||||||
|
client_send_environ();
|
||||||
|
client_send_identify(flags);
|
||||||
|
|
||||||
/* Send first command. */
|
/* Send first command. */
|
||||||
if (msg == MSG_COMMAND) {
|
if (msg == MSG_COMMAND) {
|
||||||
/* How big is the command? */
|
/* Fill in command line arguments. */
|
||||||
size = 0;
|
cmddata.pid = environ_pid;
|
||||||
for (i = 0; i < argc; i++)
|
cmddata.idx = environ_idx;
|
||||||
size += strlen(argv[i]) + 1;
|
|
||||||
data = xmalloc((sizeof *data) + size);
|
|
||||||
|
|
||||||
/* Prepare command for server. */
|
/* Prepare command for server. */
|
||||||
data->argc = argc;
|
cmddata.argc = argc;
|
||||||
if (cmd_pack_argv(argc, argv, (char *)(data + 1), size) != 0) {
|
if (cmd_pack_argv(
|
||||||
fprintf(stderr, "command too long\n");
|
argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
|
||||||
free(data);
|
log_warnx("command too long");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
size += sizeof *data;
|
|
||||||
|
|
||||||
/* Send the command. */
|
client_write_server(msg, &cmddata, sizeof cmddata);
|
||||||
if (client_write_server(msg, data, size) != 0) {
|
|
||||||
fprintf(stderr, "failed to send command\n");
|
|
||||||
free(data);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
free(data);
|
|
||||||
} else if (msg == MSG_SHELL)
|
} else if (msg == MSG_SHELL)
|
||||||
client_write_server(msg, NULL, 0);
|
client_write_server(msg, NULL, 0);
|
||||||
|
|
||||||
@@ -365,83 +197,64 @@ client_main(struct event_base *base, 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)
|
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 (client_flags & CLIENT_CONTROLCONTROL) {
|
|
||||||
if (client_exitreason != CLIENT_EXIT_NONE)
|
|
||||||
printf("%%exit %s\n", client_exit_message());
|
|
||||||
else
|
|
||||||
printf("%%exit\n");
|
|
||||||
printf("\033\\");
|
|
||||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
|
|
||||||
}
|
|
||||||
setblocking(STDIN_FILENO, 1);
|
|
||||||
return (client_exitval);
|
return (client_exitval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send identify messages to server. */
|
/* Send identify message to server with the file descriptors. */
|
||||||
void
|
void
|
||||||
client_send_identify(const char *ttynam, int cwd)
|
client_send_identify(int flags)
|
||||||
{
|
{
|
||||||
const char *s;
|
struct msg_identify_data data;
|
||||||
char **ss;
|
char *term;
|
||||||
size_t sslen;
|
int fd;
|
||||||
int fd, flags = client_flags;
|
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
client_write_one(MSG_IDENTIFY_FLAGS, -1, &flags, sizeof flags);
|
data.flags = flags;
|
||||||
|
|
||||||
if ((s = getenv("TERM")) == NULL)
|
if (getcwd(data.cwd, sizeof data.cwd) == NULL)
|
||||||
s = "";
|
*data.cwd = '\0';
|
||||||
client_write_one(MSG_IDENTIFY_TERM, -1, s, strlen(s) + 1);
|
|
||||||
|
|
||||||
client_write_one(MSG_IDENTIFY_TTYNAME, -1, ttynam, strlen(ttynam) + 1);
|
term = getenv("TERM");
|
||||||
client_write_one(MSG_IDENTIFY_CWD, cwd, NULL, 0);
|
if (term == NULL ||
|
||||||
|
strlcpy(data.term, term, sizeof data.term) >= sizeof data.term)
|
||||||
|
*data.term = '\0';
|
||||||
|
|
||||||
if ((fd = dup(STDIN_FILENO)) == -1)
|
if ((fd = dup(STDIN_FILENO)) == -1)
|
||||||
fatal("dup failed");
|
fatal("dup failed");
|
||||||
client_write_one(MSG_IDENTIFY_STDIN, fd, NULL, 0);
|
imsg_compose(&client_ibuf,
|
||||||
|
MSG_IDENTIFY, PROTOCOL_VERSION, -1, fd, &data, sizeof data);
|
||||||
|
|
||||||
pid = getpid();
|
if ((fd = dup(STDOUT_FILENO)) == -1)
|
||||||
client_write_one(MSG_IDENTIFY_CLIENTPID, -1, &pid, sizeof pid);
|
fatal("dup failed");
|
||||||
|
imsg_compose(&client_ibuf,
|
||||||
|
MSG_STDOUT, PROTOCOL_VERSION, -1, fd, NULL, 0);
|
||||||
|
|
||||||
for (ss = environ; *ss != NULL; ss++) {
|
if ((fd = dup(STDERR_FILENO)) == -1)
|
||||||
sslen = strlen(*ss) + 1;
|
fatal("dup failed");
|
||||||
if (sslen <= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
|
imsg_compose(&client_ibuf,
|
||||||
client_write_one(MSG_IDENTIFY_ENVIRON, -1, *ss, sslen);
|
MSG_STDERR, PROTOCOL_VERSION, -1, fd, NULL, 0);
|
||||||
}
|
|
||||||
|
|
||||||
client_write_one(MSG_IDENTIFY_DONE, -1, NULL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to send one message. */
|
/* Forward entire environment to server. */
|
||||||
int
|
void
|
||||||
client_write_one(enum msgtype type, int fd, const void *buf, size_t len)
|
client_send_environ(void)
|
||||||
{
|
{
|
||||||
int retval;
|
struct msg_environ_data data;
|
||||||
|
char **var;
|
||||||
|
|
||||||
retval = imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, fd,
|
for (var = environ; *var != NULL; var++) {
|
||||||
(void *)buf, len);
|
if (strlcpy(data.var, *var, sizeof data.var) >= sizeof data.var)
|
||||||
if (retval != 1)
|
continue;
|
||||||
return (-1);
|
client_write_server(MSG_ENVIRON, &data, sizeof data);
|
||||||
return (0);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a message to the server without a file descriptor. */
|
/* Write a message to the server without a file descriptor. */
|
||||||
int
|
void
|
||||||
client_write_server(enum msgtype type, const void *buf, size_t len)
|
client_write_server(enum msgtype type, void *buf, size_t len)
|
||||||
{
|
{
|
||||||
int retval;
|
imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
|
||||||
|
|
||||||
retval = client_write_one(type, -1, buf, len);
|
|
||||||
if (retval == 0)
|
|
||||||
client_update_event();
|
|
||||||
return (retval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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. */
|
||||||
@@ -454,31 +267,37 @@ client_update_event(void)
|
|||||||
events = EV_READ;
|
events = EV_READ;
|
||||||
if (client_ibuf.w.queued > 0)
|
if (client_ibuf.w.queued > 0)
|
||||||
events |= EV_WRITE;
|
events |= EV_WRITE;
|
||||||
event_set(&client_event, client_ibuf.fd, events, client_callback, NULL);
|
event_set(
|
||||||
|
&client_event, client_ibuf.fd, events, client_callback, shell_cmd);
|
||||||
event_add(&client_event, NULL);
|
event_add(&client_event, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback to handle signals in the client. */
|
/* Callback to handle signals in the client. */
|
||||||
|
/* ARGSUSED */
|
||||||
void
|
void
|
||||||
client_signal(int sig, unused short events, unused void *arg)
|
client_signal(int sig, unused short events, unused void *data)
|
||||||
{
|
{
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (sig == SIGCHLD)
|
if (!client_attached) {
|
||||||
waitpid(WAIT_ANY, &status, WNOHANG);
|
switch (sig) {
|
||||||
else if (!client_attached) {
|
case SIGCHLD:
|
||||||
if (sig == SIGTERM)
|
waitpid(WAIT_ANY, &status, WNOHANG);
|
||||||
|
break;
|
||||||
|
case SIGTERM:
|
||||||
event_loopexit(NULL);
|
event_loopexit(NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
} 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;
|
||||||
@@ -501,8 +320,9 @@ client_signal(int sig, unused short events, unused void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Callback for client imsg read events. */
|
/* Callback for client imsg read events. */
|
||||||
|
/* ARGSUSED */
|
||||||
void
|
void
|
||||||
client_callback(unused int fd, short events, unused void *arg)
|
client_callback(unused int fd, short events, void *data)
|
||||||
{
|
{
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
int retval;
|
int retval;
|
||||||
@@ -513,7 +333,7 @@ client_callback(unused int fd, short events, unused void *arg)
|
|||||||
if (client_attached)
|
if (client_attached)
|
||||||
retval = client_dispatch_attached();
|
retval = client_dispatch_attached();
|
||||||
else
|
else
|
||||||
retval = client_dispatch_wait();
|
retval = client_dispatch_wait(data);
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
event_loopexit(NULL);
|
event_loopexit(NULL);
|
||||||
return;
|
return;
|
||||||
@@ -521,7 +341,7 @@ client_callback(unused int fd, short events, unused void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (events & EV_WRITE) {
|
if (events & EV_WRITE) {
|
||||||
if (msgbuf_write(&client_ibuf.w) <= 0 && errno != EAGAIN)
|
if (msgbuf_write(&client_ibuf.w) < 0)
|
||||||
goto lost_server;
|
goto lost_server;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -529,118 +349,40 @@ client_callback(unused int fd, short events, unused void *arg)
|
|||||||
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. */
|
|
||||||
void
|
|
||||||
client_stdin_callback(unused int fd, unused short events, unused void *arg)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Run command in shell; used for -c. */
|
|
||||||
__dead void
|
|
||||||
client_exec(const char *shell)
|
|
||||||
{
|
|
||||||
const char *name, *ptr;
|
|
||||||
char *argv0;
|
|
||||||
|
|
||||||
log_debug("shell %s, command %s", shell, shell_cmd);
|
|
||||||
|
|
||||||
ptr = strrchr(shell, '/');
|
|
||||||
if (ptr != NULL && *(ptr + 1) != '\0')
|
|
||||||
name = ptr + 1;
|
|
||||||
else
|
|
||||||
name = shell;
|
|
||||||
if (client_flags & CLIENT_LOGIN)
|
|
||||||
xasprintf(&argv0, "-%s", name);
|
|
||||||
else
|
|
||||||
xasprintf(&argv0, "%s", name);
|
|
||||||
setenv("SHELL", shell, 1);
|
|
||||||
|
|
||||||
setblocking(STDIN_FILENO, 1);
|
|
||||||
setblocking(STDOUT_FILENO, 1);
|
|
||||||
setblocking(STDERR_FILENO, 1);
|
|
||||||
closefrom(STDERR_FILENO + 1);
|
|
||||||
|
|
||||||
execl(shell, argv0, "-c", shell_cmd, (char *) NULL);
|
|
||||||
fatal("execl failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
||||||
int
|
int
|
||||||
client_dispatch_wait(void)
|
client_dispatch_wait(void *data)
|
||||||
{
|
{
|
||||||
struct imsg imsg;
|
struct imsg imsg;
|
||||||
char *data;
|
ssize_t n, datalen;
|
||||||
ssize_t n, datalen;
|
struct msg_shell_data shelldata;
|
||||||
struct msg_stdout_data stdoutdata;
|
struct msg_exit_data exitdata;
|
||||||
struct msg_stderr_data stderrdata;
|
const char *shellcmd = data;
|
||||||
int retval;
|
|
||||||
#ifdef __OpenBSD__
|
|
||||||
static int pledge_applied;
|
|
||||||
|
|
||||||
/*
|
if ((n = imsg_read(&client_ibuf)) == -1 || n == 0)
|
||||||
* "sendfd" is no longer required once all of the identify messages
|
fatalx("imsg_read failed");
|
||||||
* have been sent. We know the server won't send us anything until that
|
|
||||||
* point (because we don't ask it to), so we can drop "sendfd" once we
|
|
||||||
* get the first message from the server.
|
|
||||||
*/
|
|
||||||
if (!pledge_applied) {
|
|
||||||
if (pledge("stdio unix proc exec tty", NULL) != 0)
|
|
||||||
fatal("pledge failed");
|
|
||||||
pledge_applied = 1;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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");
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
data = imsg.data;
|
|
||||||
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
|
||||||
log_debug("got %u 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:
|
||||||
if (datalen != sizeof retval && datalen != 0)
|
if (datalen != sizeof exitdata) {
|
||||||
fatalx("bad MSG_EXIT size");
|
if (datalen != 0)
|
||||||
if (datalen == sizeof retval) {
|
fatalx("bad MSG_EXIT size");
|
||||||
memcpy(&retval, data, sizeof retval);
|
} else {
|
||||||
client_exitval = retval;
|
memcpy(&exitdata, imsg.data, sizeof exitdata);
|
||||||
|
client_exitval = exitdata.retcode;
|
||||||
}
|
}
|
||||||
imsg_free(&imsg);
|
imsg_free(&imsg);
|
||||||
return (-1);
|
return (-1);
|
||||||
@@ -648,57 +390,30 @@ client_dispatch_wait(void)
|
|||||||
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;
|
||||||
client_write_server(MSG_RESIZE, NULL, 0);
|
|
||||||
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 size");
|
|
||||||
memcpy(&stdoutdata, data, sizeof stdoutdata);
|
|
||||||
|
|
||||||
client_write(STDOUT_FILENO, stdoutdata.data,
|
|
||||||
stdoutdata.size);
|
|
||||||
break;
|
|
||||||
case MSG_STDERR:
|
|
||||||
if (datalen != sizeof stderrdata)
|
|
||||||
fatalx("bad MSG_STDERR size");
|
|
||||||
memcpy(&stderrdata, data, sizeof stderrdata);
|
|
||||||
|
|
||||||
client_write(STDERR_FILENO, stderrdata.data,
|
|
||||||
stderrdata.size);
|
|
||||||
break;
|
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 %d, 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);
|
||||||
return (-1);
|
return (-1);
|
||||||
case MSG_SHELL:
|
case MSG_SHELL:
|
||||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
if (datalen != sizeof shelldata)
|
||||||
fatalx("bad MSG_SHELL string");
|
fatalx("bad MSG_SHELL size");
|
||||||
|
memcpy(&shelldata, imsg.data, sizeof shelldata);
|
||||||
|
shelldata.shell[(sizeof shelldata.shell) - 1] = '\0';
|
||||||
|
|
||||||
clear_signals(0);
|
clear_signals(0);
|
||||||
client_exec(data);
|
|
||||||
|
shell_exec(shelldata.shell, shellcmd);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
case MSG_DETACH:
|
default:
|
||||||
case MSG_DETACHKILL:
|
fatalx("unexpected message");
|
||||||
client_write_server(MSG_EXITING, NULL, 0);
|
|
||||||
break;
|
|
||||||
case MSG_EXITED:
|
|
||||||
imsg_free(&imsg);
|
|
||||||
return (-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imsg_free(&imsg);
|
imsg_free(&imsg);
|
||||||
@@ -706,44 +421,38 @@ client_dispatch_wait(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Dispatch imsgs in attached state (after MSG_READY). */
|
/* Dispatch imsgs in attached state (after MSG_READY). */
|
||||||
|
/* ARGSUSED */
|
||||||
int
|
int
|
||||||
client_dispatch_attached(void)
|
client_dispatch_attached(void)
|
||||||
{
|
{
|
||||||
struct imsg imsg;
|
struct imsg imsg;
|
||||||
struct sigaction sigact;
|
struct msg_lock_data lockdata;
|
||||||
char *data;
|
struct sigaction sigact;
|
||||||
ssize_t n, datalen;
|
ssize_t n, datalen;
|
||||||
|
|
||||||
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");
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
data = imsg.data;
|
|
||||||
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
|
||||||
log_debug("got %u from server", imsg.hdr.type);
|
log_debug("client got %d", imsg.hdr.type);
|
||||||
switch (imsg.hdr.type) {
|
switch (imsg.hdr.type) {
|
||||||
case MSG_DETACH:
|
case MSG_DETACH:
|
||||||
case MSG_DETACHKILL:
|
if (datalen != 0)
|
||||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
fatalx("bad MSG_DETACH size");
|
||||||
fatalx("bad MSG_DETACH string");
|
|
||||||
|
|
||||||
client_exitsession = xstrdup(data);
|
|
||||||
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 && datalen != sizeof (int))
|
if (datalen != 0 &&
|
||||||
|
datalen != sizeof (struct msg_exit_data))
|
||||||
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)
|
||||||
@@ -756,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:
|
||||||
@@ -772,12 +481,16 @@ client_dispatch_attached(void)
|
|||||||
kill(getpid(), SIGTSTP);
|
kill(getpid(), SIGTSTP);
|
||||||
break;
|
break;
|
||||||
case MSG_LOCK:
|
case MSG_LOCK:
|
||||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
if (datalen != sizeof lockdata)
|
||||||
fatalx("bad MSG_LOCK string");
|
fatalx("bad MSG_LOCK size");
|
||||||
|
memcpy(&lockdata, imsg.data, sizeof lockdata);
|
||||||
|
|
||||||
system(data);
|
lockdata.cmd[(sizeof lockdata.cmd) - 1] = '\0';
|
||||||
|
system(lockdata.cmd);
|
||||||
client_write_server(MSG_UNLOCK, NULL, 0);
|
client_write_server(MSG_UNLOCK, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
fatalx("unexpected message");
|
||||||
}
|
}
|
||||||
|
|
||||||
imsg_free(&imsg);
|
imsg_free(&imsg);
|
||||||
|
|||||||
159
clock.c
Normal file
159
clock.c
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
/* $Id: clock.c,v 1.9 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 <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
const char clock_table[14][5][5] = {
|
||||||
|
{ { 1,1,1,1,1 }, /* 0 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 0,0,0,0,1 }, /* 1 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 2 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 3 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,0,0,0,1 }, /* 4 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 5 */
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 6 */
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 7 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 8 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 9 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 0,0,0,0,0 }, /* : */
|
||||||
|
{ 0,0,1,0,0 },
|
||||||
|
{ 0,0,0,0,0 },
|
||||||
|
{ 0,0,1,0,0 },
|
||||||
|
{ 0,0,0,0,0 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* A */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* P */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,0,0,0,0 } },
|
||||||
|
{ { 1,0,0,0,1 }, /* M */
|
||||||
|
{ 1,1,0,1,1 },
|
||||||
|
{ 1,0,1,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 } },
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
clock_draw(struct screen_write_ctx *ctx, int colour, int style)
|
||||||
|
{
|
||||||
|
struct screen *s = ctx->s;
|
||||||
|
struct grid_cell gc;
|
||||||
|
char tim[64], *ptr;
|
||||||
|
time_t t;
|
||||||
|
u_int i, j, x, y, idx;
|
||||||
|
|
||||||
|
t = time(NULL);
|
||||||
|
if (style == 0)
|
||||||
|
strftime(tim, sizeof tim, "%l:%M %p", localtime(&t));
|
||||||
|
else
|
||||||
|
strftime(tim, sizeof tim, "%H:%M", localtime(&t));
|
||||||
|
|
||||||
|
screen_write_clearscreen(ctx);
|
||||||
|
|
||||||
|
if (screen_size_x(s) < 6 * strlen(tim) || screen_size_y(s) < 6) {
|
||||||
|
if (screen_size_x(s) >= strlen(tim) && screen_size_y(s) != 0) {
|
||||||
|
x = (screen_size_x(s) / 2) - (strlen(tim) / 2);
|
||||||
|
y = screen_size_y(s) / 2;
|
||||||
|
screen_write_cursormove(ctx, x, y);
|
||||||
|
|
||||||
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||||
|
colour_set_fg(&gc, colour);
|
||||||
|
screen_write_puts(ctx, &gc, "%s", tim);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = (screen_size_x(s) / 2) - 3 * strlen(tim);
|
||||||
|
y = (screen_size_y(s) / 2) - 3;
|
||||||
|
|
||||||
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||||
|
colour_set_bg(&gc, colour);
|
||||||
|
for (ptr = tim; *ptr != '\0'; ptr++) {
|
||||||
|
if (*ptr >= '0' && *ptr <= '9')
|
||||||
|
idx = *ptr - '0';
|
||||||
|
else if (*ptr == ':')
|
||||||
|
idx = 10;
|
||||||
|
else if (*ptr == 'A')
|
||||||
|
idx = 11;
|
||||||
|
else if (*ptr == 'P')
|
||||||
|
idx = 12;
|
||||||
|
else if (*ptr == 'M')
|
||||||
|
idx = 13;
|
||||||
|
else {
|
||||||
|
x += 6;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < 5; j++) {
|
||||||
|
for (i = 0; i < 5; i++) {
|
||||||
|
screen_write_cursormove(ctx, x + i, y + j);
|
||||||
|
if (clock_table[idx][j][i])
|
||||||
|
screen_write_putc(ctx, &gc, ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x += 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,171 +18,93 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.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_q *);
|
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",
|
||||||
"c:dErt:", 0, 0,
|
"[-dr] " CMD_TARGET_SESSION_USAGE,
|
||||||
"[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
|
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, "dr",
|
||||||
CMD_STARTSERVER,
|
cmd_target_init,
|
||||||
cmd_attach_session_exec
|
cmd_target_parse,
|
||||||
|
cmd_attach_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
const char *cflag, int Eflag)
|
|
||||||
{
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct client *c = cmdq->client, *c_loop;
|
struct client *c;
|
||||||
struct winlink *wl = NULL;
|
|
||||||
struct window *w = NULL;
|
|
||||||
struct window_pane *wp = NULL;
|
|
||||||
const char *update;
|
const char *update;
|
||||||
char *cause;
|
char *overrides, *cause;
|
||||||
int fd;
|
u_int i;
|
||||||
struct format_tree *ft;
|
|
||||||
char *cp;
|
|
||||||
|
|
||||||
if (RB_EMPTY(&sessions)) {
|
if (RB_EMPTY(&sessions)) {
|
||||||
cmdq_error(cmdq, "no sessions");
|
ctx->error(ctx, "no sessions");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
if (tflag == NULL) {
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||||
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
|
return (0);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
} else if (tflag[strcspn(tflag, ":.")] != '\0') {
|
|
||||||
if ((wl = cmd_find_pane(cmdq, tflag, &s, &wp)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
} else {
|
|
||||||
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
w = window_find_by_id_str(tflag);
|
|
||||||
if (w == NULL) {
|
|
||||||
wp = window_pane_find_by_id_str(tflag);
|
|
||||||
if (wp != NULL)
|
|
||||||
w = wp->window;
|
|
||||||
}
|
|
||||||
if (w != NULL)
|
|
||||||
wl = winlink_find_by_window(&s->windows, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == NULL)
|
if (ctx->cmdclient == NULL) {
|
||||||
return (CMD_RETURN_NORMAL);
|
if (cmd_check_flag(data->chflags, 'd')) {
|
||||||
if (server_client_check_nested(c)) {
|
|
||||||
cmdq_error(cmdq, "sessions should be nested with care, "
|
|
||||||
"unset $TMUX to force");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wl != NULL) {
|
|
||||||
if (wp != NULL)
|
|
||||||
window_set_active_pane(wp->window, wp);
|
|
||||||
session_set_current(s, wl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cflag != NULL) {
|
|
||||||
ft = format_create();
|
|
||||||
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
|
|
||||||
NULL, NULL);
|
|
||||||
cp = format_expand(ft, cflag);
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
fd = open(cp, O_RDONLY|O_DIRECTORY);
|
|
||||||
free(cp);
|
|
||||||
if (fd == -1) {
|
|
||||||
cmdq_error(cmdq, "bad working directory: %s",
|
|
||||||
strerror(errno));
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
close(s->cwd);
|
|
||||||
s->cwd = fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->session != NULL) {
|
|
||||||
if (dflag) {
|
|
||||||
/*
|
/*
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
if (c_loop->session != s || c == c_loop)
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session != s)
|
||||||
continue;
|
continue;
|
||||||
server_write_client(c, MSG_DETACH,
|
if (c == ctx->curclient)
|
||||||
c_loop->session->name,
|
continue;
|
||||||
strlen(c_loop->session->name) + 1);
|
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Eflag) {
|
ctx->curclient->session = s;
|
||||||
update = options_get_string(&s->options,
|
server_redraw_client(ctx->curclient);
|
||||||
"update-environment");
|
|
||||||
environ_update(update, &c->environ, &s->environ);
|
|
||||||
}
|
|
||||||
|
|
||||||
c->session = s;
|
|
||||||
status_timer_start(c);
|
|
||||||
notify_attached_session_changed(c);
|
|
||||||
session_update_activity(s, NULL);
|
|
||||||
gettimeofday(&s->last_attached_time, NULL);
|
|
||||||
server_redraw_client(c);
|
|
||||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
|
||||||
} else {
|
} else {
|
||||||
if (server_client_open(c, &cause) != 0) {
|
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||||
cmdq_error(cmdq, "open terminal failed: %s", cause);
|
ctx->error(ctx, "not a terminal");
|
||||||
free(cause);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rflag)
|
overrides =
|
||||||
c->flags |= CLIENT_READONLY;
|
options_get_string(&s->options, "terminal-overrides");
|
||||||
|
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||||
if (dflag) {
|
ctx->error(ctx, "terminal open failed: %s", cause);
|
||||||
server_write_session(s, MSG_DETACH, s->name,
|
xfree(cause);
|
||||||
strlen(s->name) + 1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Eflag) {
|
if (cmd_check_flag(data->chflags, 'r'))
|
||||||
update = options_get_string(&s->options,
|
ctx->cmdclient->flags |= CLIENT_READONLY;
|
||||||
"update-environment");
|
|
||||||
environ_update(update, &c->environ, &s->environ);
|
|
||||||
}
|
|
||||||
|
|
||||||
c->session = s;
|
if (cmd_check_flag(data->chflags, 'd'))
|
||||||
status_timer_start(c);
|
server_write_session(s, MSG_DETACH, NULL, 0);
|
||||||
notify_attached_session_changed(c);
|
|
||||||
session_update_activity(s, NULL);
|
|
||||||
gettimeofday(&s->last_attached_time, NULL);
|
|
||||||
server_redraw_client(c);
|
|
||||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
|
||||||
|
|
||||||
server_write_ready(c);
|
ctx->cmdclient->session = s;
|
||||||
cmdq->client_exit = 0;
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
|
|
||||||
|
update = options_get_string(&s->options, "update-environment");
|
||||||
|
environ_update(update, &ctx->cmdclient->environ, &s->environ);
|
||||||
|
|
||||||
|
server_redraw_client(ctx->cmdclient);
|
||||||
}
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
server_update_socket();
|
server_update_socket();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (1); /* 1 means don't tell command client to exit */
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
|
|
||||||
return (cmd_attach_session(cmdq, args_get(args, 't'),
|
|
||||||
args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'),
|
|
||||||
args_has(args, 'E')));
|
|
||||||
}
|
}
|
||||||
|
|||||||
253
cmd-bind-key.c
253
cmd-bind-key.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,128 +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_exec(struct cmd *, struct cmd_q *);
|
int cmd_bind_key_parse(struct cmd *, int, char **, char **);
|
||||||
|
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_mode_table(struct cmd *, struct cmd_q *, 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:T:", 1, -1,
|
"[-cnr] [-t key-table] key command [arguments]",
|
||||||
"[-cnr] [-t mode-table] [-T key-table] key command [arguments]",
|
0, "",
|
||||||
0,
|
NULL,
|
||||||
cmd_bind_key_exec
|
cmd_bind_key_parse,
|
||||||
|
cmd_bind_key_exec,
|
||||||
|
cmd_bind_key_free,
|
||||||
|
cmd_bind_key_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
cmd_bind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_bind_key_data *data;
|
||||||
char *cause;
|
int opt, no_prefix = 0;
|
||||||
struct cmd_list *cmdlist;
|
|
||||||
int key;
|
|
||||||
const char *tablename;
|
|
||||||
|
|
||||||
if (args_has(args, 't')) {
|
self->data = data = xmalloc(sizeof *data);
|
||||||
if (args->argc != 2 && args->argc != 3) {
|
data->can_repeat = 0;
|
||||||
cmdq_error(cmdq, "not enough arguments");
|
data->cmdlist = NULL;
|
||||||
return (CMD_RETURN_ERROR);
|
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)
|
||||||
cmdq_error(cmdq, "not enough arguments");
|
goto error;
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
key = key_string_lookup_string(args->argv[0]);
|
return (0);
|
||||||
if (key == KEYC_NONE) {
|
|
||||||
cmdq_error(cmdq, "unknown key: %s", args->argv[0]);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 't'))
|
usage:
|
||||||
return (cmd_bind_key_mode_table(self, cmdq, key));
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
if (args_has(args, 'T'))
|
error:
|
||||||
tablename = args_get(args, 'T');
|
self->entry->free(self);
|
||||||
else if (args_has(args, 'n'))
|
return (-1);
|
||||||
tablename = "root";
|
|
||||||
else
|
|
||||||
tablename = "prefix";
|
|
||||||
|
|
||||||
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0,
|
|
||||||
&cause);
|
|
||||||
if (cmdlist == NULL) {
|
|
||||||
cmdq_error(cmdq, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
key_bindings_add(tablename, key, args_has(args, 'r'), cmdlist);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, int key)
|
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;
|
||||||
const char *tablename;
|
|
||||||
|
if (data == NULL)
|
||||||
|
return (0);
|
||||||
|
if (data->tablename != NULL)
|
||||||
|
return (cmd_bind_key_table(self, ctx));
|
||||||
|
|
||||||
|
key_bindings_add(data->key, data->can_repeat, data->cmdlist);
|
||||||
|
data->cmdlist->references++;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_bind_key_data *data = self->data;
|
||||||
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;
|
||||||
const char *arg;
|
|
||||||
|
|
||||||
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);
|
||||||
cmdq_error(cmdq, "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) {
|
||||||
cmdq_error(cmdq, "unknown command: %s", args->argv[1]);
|
ctx->error(ctx, "unknown command: %s", data->modecmd);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cmd) {
|
mtmp.key = data->key & ~KEYC_PREFIX;
|
||||||
case MODEKEYCOPY_APPENDSELECTION:
|
mtmp.mode = data->command_key ? 1 : 0;
|
||||||
case MODEKEYCOPY_COPYSELECTION:
|
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||||
case MODEKEYCOPY_STARTNAMEDBUFFER:
|
mbind->cmd = cmd;
|
||||||
if (args->argc == 2)
|
return (0);
|
||||||
arg = NULL;
|
|
||||||
else {
|
|
||||||
arg = args->argv[2];
|
|
||||||
if (strcmp(arg, "-x") != 0) {
|
|
||||||
cmdq_error(cmdq, "unknown argument");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MODEKEYCOPY_COPYPIPE:
|
|
||||||
if (args->argc != 3) {
|
|
||||||
cmdq_error(cmdq, "no argument given");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
arg = args->argv[2];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (args->argc != 2) {
|
|
||||||
cmdq_error(cmdq, "no argument allowed");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
arg = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
mtmp.key = key;
|
|
||||||
mtmp.mode = !!args_has(args, 'c');
|
|
||||||
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) {
|
|
||||||
mbind = xmalloc(sizeof *mbind);
|
|
||||||
mbind->key = mtmp.key;
|
|
||||||
mbind->mode = mtmp.mode;
|
|
||||||
RB_INSERT(mode_key_tree, mtab->tree, mbind);
|
|
||||||
}
|
}
|
||||||
|
mbind = xmalloc(sizeof *mbind);
|
||||||
|
mbind->key = mtmp.key;
|
||||||
|
mbind->mode = mtmp.mode;
|
||||||
mbind->cmd = cmd;
|
mbind->cmd = cmd;
|
||||||
mbind->arg = arg != NULL ? xstrdup(arg) : NULL;
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
100
cmd-break-pane.c
100
cmd-break-pane.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_q *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_break_pane_entry = {
|
const struct cmd_entry cmd_break_pane_entry = {
|
||||||
"break-pane", "breakp",
|
"break-pane", "breakp",
|
||||||
"dPF:s:t:", 0, 0,
|
CMD_TARGET_PANE_USAGE " [-d]",
|
||||||
"[-dP] [-F format] " CMD_SRCDST_PANE_USAGE,
|
0, "d",
|
||||||
0,
|
cmd_target_init,
|
||||||
cmd_break_pane_exec
|
cmd_target_parse,
|
||||||
|
cmd_break_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
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 *src_s;
|
struct session *s;
|
||||||
struct session *dst_s;
|
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
char *name;
|
|
||||||
char *cause;
|
char *cause;
|
||||||
int idx;
|
int base_idx;
|
||||||
struct format_tree *ft;
|
|
||||||
const char *template;
|
|
||||||
char *cp;
|
|
||||||
|
|
||||||
wl = cmd_find_pane(cmdq, args_get(args, 's'), &src_s, &wp);
|
if ((wl = cmd_find_pane(ctx, data->target, &s, &wp)) == NULL)
|
||||||
if (wl == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst_s)) == -2)
|
if (window_count_panes(wl->window) == 1) {
|
||||||
return (CMD_RETURN_ERROR);
|
ctx->error(ctx, "can't break with only one pane");
|
||||||
if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) {
|
return (-1);
|
||||||
cmdq_error(cmdq, "index %d already in use", idx);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
w = wl->window;
|
|
||||||
|
|
||||||
if (window_count_panes(w) == 1) {
|
TAILQ_REMOVE(&wl->window->panes, wp, entry);
|
||||||
cmdq_error(cmdq, "can't break with only one pane");
|
if (wl->window->active == wp) {
|
||||||
return (CMD_RETURN_ERROR);
|
wl->window->active = TAILQ_PREV(wp, window_panes, entry);
|
||||||
|
if (wl->window->active == NULL)
|
||||||
|
wl->window->active = TAILQ_NEXT(wp, entry);
|
||||||
}
|
}
|
||||||
server_unzoom_window(w);
|
|
||||||
|
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
|
||||||
window_lost_pane(w, wp);
|
|
||||||
layout_close_pane(wp);
|
layout_close_pane(wp);
|
||||||
|
|
||||||
w = wp->window = window_create1(dst_s->sx, dst_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);
|
layout_init(w);
|
||||||
free(name);
|
|
||||||
layout_init(w, wp);
|
|
||||||
|
|
||||||
if (idx == -1)
|
base_idx = options_get_number(&s->options, "base-index");
|
||||||
idx = -1 - options_get_number(&dst_s->options, "base-index");
|
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
|
||||||
wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
|
if (!cmd_check_flag(data->chflags, 'd'))
|
||||||
if (!args_has(self->args, 'd'))
|
session_select(s, wl->idx);
|
||||||
session_select(dst_s, wl->idx);
|
|
||||||
|
|
||||||
server_redraw_session(src_s);
|
server_redraw_session(s);
|
||||||
if (src_s != dst_s)
|
server_status_session_group(s);
|
||||||
server_redraw_session(dst_s);
|
|
||||||
server_status_session_group(src_s);
|
|
||||||
if (src_s != dst_s)
|
|
||||||
server_status_session_group(dst_s);
|
|
||||||
|
|
||||||
if (args_has(args, 'P')) {
|
return (0);
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = BREAK_PANE_TEMPLATE;
|
|
||||||
|
|
||||||
ft = format_create();
|
|
||||||
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), dst_s, wl,
|
|
||||||
wp);
|
|
||||||
|
|
||||||
cp = format_expand(ft, template);
|
|
||||||
cmdq_print(cmdq, "%s", cp);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,204 +18,66 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write the entire contents of a pane to a buffer or stdout.
|
* Write the entire contents of a pane to a buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_q *);
|
int cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
|
|
||||||
char *cmd_capture_pane_pending(struct args *, struct window_pane *,
|
|
||||||
size_t *);
|
|
||||||
char *cmd_capture_pane_history(struct args *, struct cmd_q *,
|
|
||||||
struct window_pane *, size_t *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_capture_pane_entry = {
|
const struct cmd_entry cmd_capture_pane_entry = {
|
||||||
"capture-pane", "capturep",
|
"capture-pane", "capturep",
|
||||||
"ab:CeE:JpPqS:t:", 0, 0,
|
CMD_BUFFER_PANE_USAGE,
|
||||||
"[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] [-S start-line]"
|
0, "",
|
||||||
CMD_TARGET_PANE_USAGE,
|
cmd_buffer_init,
|
||||||
0,
|
cmd_buffer_parse,
|
||||||
cmd_capture_pane_exec
|
cmd_capture_pane_exec,
|
||||||
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
char *
|
int
|
||||||
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
|
cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
buf = xrealloc(buf, *len + linelen + 1);
|
struct cmd_buffer_data *data = self->data;
|
||||||
memcpy(buf + *len, line, linelen);
|
struct window_pane *wp;
|
||||||
*len += linelen;
|
char *buf, *line;
|
||||||
return (buf);
|
struct screen *s;
|
||||||
}
|
struct session *sess;
|
||||||
|
u_int i, limit;
|
||||||
|
size_t len, linelen;
|
||||||
|
|
||||||
char *
|
if (cmd_find_pane(ctx, data->target, &sess, &wp) == NULL)
|
||||||
cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
|
return (-1);
|
||||||
size_t *len)
|
s = &wp->base;
|
||||||
{
|
|
||||||
struct evbuffer *pending;
|
|
||||||
char *buf, *line, tmp[5];
|
|
||||||
size_t linelen;
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
pending = input_pending(wp);
|
|
||||||
if (pending == NULL)
|
|
||||||
return (xstrdup(""));
|
|
||||||
|
|
||||||
line = EVBUFFER_DATA(pending);
|
|
||||||
linelen = EVBUFFER_LENGTH(pending);
|
|
||||||
|
|
||||||
buf = xstrdup("");
|
|
||||||
if (args_has(args, 'C')) {
|
|
||||||
for (i = 0; i < linelen; i++) {
|
|
||||||
if (line[i] >= ' ') {
|
|
||||||
tmp[0] = line[i];
|
|
||||||
tmp[1] = '\0';
|
|
||||||
} else
|
|
||||||
xsnprintf(tmp, sizeof tmp, "\\%03hho", line[i]);
|
|
||||||
buf = cmd_capture_pane_append(buf, len, tmp,
|
|
||||||
strlen(tmp));
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
buf = cmd_capture_pane_append(buf, len, line, linelen);
|
|
||||||
return (buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq,
|
|
||||||
struct window_pane *wp, size_t *len)
|
|
||||||
{
|
|
||||||
struct grid *gd;
|
|
||||||
const struct grid_line *gl;
|
|
||||||
struct grid_cell *gc = NULL;
|
|
||||||
int n, with_codes, escape_c0, join_lines;
|
|
||||||
u_int i, sx, top, bottom, tmp;
|
|
||||||
char *cause, *buf, *line;
|
|
||||||
const char *Sflag, *Eflag;
|
|
||||||
size_t linelen;
|
|
||||||
|
|
||||||
sx = screen_size_x(&wp->base);
|
|
||||||
if (args_has(args, 'a')) {
|
|
||||||
gd = wp->saved_grid;
|
|
||||||
if (gd == NULL) {
|
|
||||||
if (!args_has(args, 'q')) {
|
|
||||||
cmdq_error(cmdq, "no alternate screen");
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
return (xstrdup(""));
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
gd = wp->base.grid;
|
|
||||||
|
|
||||||
Sflag = args_get(args, 'S');
|
|
||||||
if (Sflag != NULL && strcmp(Sflag, "-") == 0)
|
|
||||||
top = 0;
|
|
||||||
else {
|
|
||||||
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
top = gd->hsize;
|
|
||||||
free(cause);
|
|
||||||
} else if (n < 0 && (u_int) -n > gd->hsize)
|
|
||||||
top = 0;
|
|
||||||
else
|
|
||||||
top = gd->hsize + n;
|
|
||||||
if (top > gd->hsize + gd->sy - 1)
|
|
||||||
top = gd->hsize + gd->sy - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Eflag = args_get(args, 'E');
|
|
||||||
if (Eflag != NULL && strcmp(Eflag, "-") == 0)
|
|
||||||
bottom = gd->hsize + gd->sy - 1;
|
|
||||||
else {
|
|
||||||
n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
bottom = gd->hsize + gd->sy - 1;
|
|
||||||
free(cause);
|
|
||||||
} else if (n < 0 && (u_int) -n > gd->hsize)
|
|
||||||
bottom = 0;
|
|
||||||
else
|
|
||||||
bottom = gd->hsize + n;
|
|
||||||
if (bottom > gd->hsize + gd->sy - 1)
|
|
||||||
bottom = gd->hsize + gd->sy - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bottom < top) {
|
|
||||||
tmp = bottom;
|
|
||||||
bottom = top;
|
|
||||||
top = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
with_codes = args_has(args, 'e');
|
|
||||||
escape_c0 = args_has(args, 'C');
|
|
||||||
join_lines = args_has(args, 'J');
|
|
||||||
|
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
for (i = top; i <= bottom; i++) {
|
|
||||||
line = grid_string_cells(gd, 0, i, sx, &gc, with_codes,
|
|
||||||
escape_c0, !join_lines);
|
|
||||||
linelen = strlen(line);
|
|
||||||
|
|
||||||
buf = cmd_capture_pane_append(buf, len, line, linelen);
|
|
||||||
|
|
||||||
gl = grid_peek_line(gd, i);
|
|
||||||
if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED))
|
|
||||||
buf[(*len)++] = '\n';
|
|
||||||
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
return (buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c;
|
|
||||||
struct window_pane *wp;
|
|
||||||
char *buf, *cause;
|
|
||||||
const char *bufname;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
if (args_has(args, 'P'))
|
|
||||||
buf = cmd_capture_pane_pending(args, wp, &len);
|
|
||||||
else
|
|
||||||
buf = cmd_capture_pane_history(args, cmdq, wp, &len);
|
|
||||||
if (buf == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
if (args_has(args, 'p')) {
|
for (i = 0; i < screen_size_y(s); i++) {
|
||||||
c = cmdq->client;
|
line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
|
||||||
if (c == NULL ||
|
linelen = strlen(line);
|
||||||
(c->session != NULL && !(c->flags & CLIENT_CONTROL))) {
|
|
||||||
cmdq_error(cmdq, "can't write to stdout");
|
|
||||||
free(buf);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
evbuffer_add(c->stdout_data, buf, len);
|
|
||||||
free(buf);
|
|
||||||
if (args_has(args, 'P') && len > 0)
|
|
||||||
evbuffer_add(c->stdout_data, "\n", 1);
|
|
||||||
server_push_stdout(c);
|
|
||||||
} else {
|
|
||||||
bufname = NULL;
|
|
||||||
if (args_has(args, 'b'))
|
|
||||||
bufname = args_get(args, 'b');
|
|
||||||
|
|
||||||
if (paste_set(buf, len, bufname, &cause) != 0) {
|
buf = xrealloc(buf, 1, len + linelen + 1);
|
||||||
cmdq_error(cmdq, "%s", cause);
|
memcpy(buf + len, line, linelen);
|
||||||
free(cause);
|
len += linelen;
|
||||||
free(buf);
|
buf[len++] = '\n';
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
xfree(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
limit = options_get_number(&sess->options, "buffer-limit");
|
||||||
|
if (data->buffer == -1) {
|
||||||
|
paste_add(&sess->buffers, buf, len, limit);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (paste_replace(&sess->buffers, data->buffer, buf, len) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
|
xfree(buf);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,74 +26,121 @@
|
|||||||
* Enter choice mode to choose a buffer.
|
* Enter choice mode to choose a buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CHOOSE_BUFFER_TEMPLATE \
|
int cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}"
|
|
||||||
|
|
||||||
enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_q *);
|
void cmd_choose_buffer_callback(void *, int);
|
||||||
|
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,
|
||||||
cmd_choose_buffer_exec
|
cmd_target_parse,
|
||||||
|
cmd_choose_buffer_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
struct cmd_choose_buffer_data {
|
||||||
cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct client *c;
|
struct cmd_choose_buffer_data *cdata;
|
||||||
struct window_choose_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;
|
||||||
int utf8flag;
|
char *tmp;
|
||||||
|
|
||||||
if ((c = cmd_find_client(cmdq, NULL, 1)) == NULL) {
|
if (ctx->curclient == NULL) {
|
||||||
cmdq_error(cmdq, "no client available");
|
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(cmdq, args_get(args, 't'), NULL)) == NULL)
|
if (paste_get_top(&s->buffers) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (0);
|
||||||
utf8flag = options_get_number(&wl->window->options, "utf8");
|
|
||||||
|
|
||||||
if (paste_get_top(NULL) == 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;
|
||||||
pb = NULL;
|
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
||||||
while ((pb = paste_walk(pb)) != NULL) {
|
tmp = paste_print(pb, 50);
|
||||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
window_choose_add(wl->window->active, idx - 1,
|
||||||
cdata->idx = idx;
|
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||||
|
xfree(tmp);
|
||||||
cdata->ft_template = xstrdup(template);
|
|
||||||
format_defaults_paste_buffer(cdata->ft, pb, utf8flag);
|
|
||||||
|
|
||||||
xasprintf(&action_data, "%s", paste_buffer_name(pb));
|
|
||||||
cdata->command = cmd_template_replace(action, action_data, 1);
|
|
||||||
free(action_data);
|
|
||||||
|
|
||||||
window_choose_add(wl->window->active, cdata);
|
|
||||||
idx++;
|
|
||||||
}
|
}
|
||||||
free(action);
|
|
||||||
|
|
||||||
window_choose_ready(wl->window->active, 0, NULL);
|
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++;
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
window_choose_ready(wl->window->active,
|
||||||
|
0, cmd_choose_buffer_callback, cmd_choose_buffer_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_buffer_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_buffer_data *cdata = data;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause, tmp[16];
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
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
|
||||||
|
cmd_choose_buffer_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_buffer_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,106 +26,127 @@
|
|||||||
* Enter choice mode to choose a client.
|
* Enter choice mode to choose a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CHOOSE_CLIENT_TEMPLATE \
|
int cmd_choose_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{client_tty}: #{session_name} " \
|
|
||||||
"[#{client_width}x#{client_height} #{client_termname}]" \
|
|
||||||
"#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \
|
|
||||||
"(last used #{client_activity_string})"
|
|
||||||
|
|
||||||
enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_q *);
|
void cmd_choose_client_callback(void *, int);
|
||||||
|
void cmd_choose_client_free(void *);
|
||||||
void cmd_choose_client_callback(struct window_choose_data *);
|
|
||||||
|
|
||||||
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,
|
||||||
cmd_choose_client_exec
|
cmd_target_parse,
|
||||||
|
cmd_choose_client_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_choose_client_data {
|
struct cmd_choose_client_data {
|
||||||
struct client *client;
|
struct client *client;
|
||||||
|
char *template;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
cmd_choose_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 cmd_choose_client_data *cdata;
|
||||||
struct client *c1;
|
|
||||||
struct window_choose_data *cdata;
|
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
const char *template;
|
struct client *c;
|
||||||
char *action;
|
u_int i, idx, cur;
|
||||||
u_int idx, cur;
|
|
||||||
|
|
||||||
if ((c = cmd_find_client(cmdq, NULL, 1)) == NULL) {
|
if (ctx->curclient == NULL) {
|
||||||
cmdq_error(cmdq, "no client available");
|
ctx->error(ctx, "must be run interactively");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((wl = cmd_find_window(cmdq, 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;
|
||||||
TAILQ_FOREACH(c1, &clients, entry) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
if (c1->session == NULL || c1->tty.path == NULL)
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
continue;
|
continue;
|
||||||
if (c1 == cmdq->client)
|
if (c == ctx->curclient)
|
||||||
cur = idx;
|
cur = idx;
|
||||||
|
|
||||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
|
||||||
cdata->idx = idx;
|
|
||||||
|
|
||||||
cdata->ft_template = xstrdup(template);
|
|
||||||
format_add(cdata->ft, "line", "%u", idx);
|
|
||||||
format_defaults(cdata->ft, c1, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
cdata->command = cmd_template_replace(action, c1->tty.path, 1);
|
|
||||||
|
|
||||||
window_choose_add(wl->window->active, cdata);
|
|
||||||
|
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active, i,
|
||||||
|
"%s: %s [%ux%u %s]%s", c->tty.path,
|
||||||
|
c->session->name, c->tty.sx, c->tty.sy,
|
||||||
|
c->tty.termname, c->tty.flags & TTY_UTF8 ? " (utf8)" : "");
|
||||||
}
|
}
|
||||||
free(action);
|
|
||||||
|
|
||||||
window_choose_ready(wl->window->active, cur,
|
cdata = xmalloc(sizeof *cdata);
|
||||||
cmd_choose_client_callback);
|
if (data->arg != NULL)
|
||||||
|
cdata->template = xstrdup(data->arg);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("detach-client -t '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_client_callback, cmd_choose_client_free, cdata);
|
||||||
|
|
||||||
|
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;
|
||||||
u_int idx;
|
struct client *c;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause;
|
||||||
|
|
||||||
if (cdata == NULL)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
if (cdata->start_client->flags & CLIENT_DEAD)
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
idx = 0;
|
if ((u_int) idx > ARRAY_LENGTH(&clients) - 1)
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
return;
|
||||||
if (idx == cdata->idx)
|
c = ARRAY_ITEM(&clients, idx);
|
||||||
break;
|
|
||||||
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_data_run(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
|
||||||
|
cmd_choose_client_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_client_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(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,241 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define CHOOSE_TREE_SESSION_TEMPLATE \
|
|
||||||
"#{session_name}: #{session_windows} windows" \
|
|
||||||
"#{?session_grouped, (group ,}" \
|
|
||||||
"#{session_group}#{?session_grouped,),}" \
|
|
||||||
"#{?session_attached, (attached),}"
|
|
||||||
#define CHOOSE_TREE_WINDOW_TEMPLATE \
|
|
||||||
"#{window_index}: #{window_name}#{window_flags} " \
|
|
||||||
"\"#{pane_title}\""
|
|
||||||
|
|
||||||
enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_q *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_tree_entry = {
|
|
||||||
"choose-tree", NULL,
|
|
||||||
"S:W:swub:c:t:", 0, 1,
|
|
||||||
"[-suw] [-b session-template] [-c window template] [-S format] " \
|
|
||||||
"[-W format] " CMD_TARGET_WINDOW_USAGE,
|
|
||||||
0,
|
|
||||||
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,
|
|
||||||
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,
|
|
||||||
cmd_choose_tree_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_choose_tree_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct winlink *wl, *wm;
|
|
||||||
struct session *s, *s2;
|
|
||||||
struct client *c;
|
|
||||||
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 ((c = cmd_find_client(cmdq, NULL, 1)) == NULL) {
|
|
||||||
cmdq_error(cmdq, "no client available");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == 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,
|
|
||||||
c, s2, ses_template, 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 %s",
|
|
||||||
wcd != NULL ? wcd->command : "",
|
|
||||||
wcd != NULL ? ";" : "", win_action);
|
|
||||||
|
|
||||||
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,
|
|
||||||
c, 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, NULL);
|
|
||||||
|
|
||||||
if (args_has(args, 'u')) {
|
|
||||||
window_choose_expand_all(wl->window->active);
|
|
||||||
window_choose_set_current(wl->window->active, cur_win);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,30 +24,32 @@
|
|||||||
* Clear pane history.
|
* Clear pane history.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_q *);
|
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, "",
|
||||||
cmd_clear_history_exec
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_clear_history_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_clear_history_exec(struct cmd *self, struct cmd_q *cmdq)
|
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(cmdq, 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;
|
||||||
|
|
||||||
if (wp->mode == &window_copy_mode)
|
grid_move_lines(gd, 0, gd->hsize, gd->sy);
|
||||||
window_pane_reset_mode(wp);
|
gd->hsize = 0;
|
||||||
grid_clear_history(gd);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-clock-mode.c,v 1.7 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012 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,38 +18,35 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/* Get cell width. */
|
/*
|
||||||
u_int
|
* Enter clock mode.
|
||||||
grid_cell_width(const struct grid_cell *gc)
|
*/
|
||||||
{
|
|
||||||
return (gc->xstate >> 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get cell data. */
|
int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
void
|
|
||||||
grid_cell_get(const struct grid_cell *gc, struct utf8_data *ud)
|
|
||||||
{
|
|
||||||
ud->size = gc->xstate & 0xf;
|
|
||||||
ud->width = gc->xstate >> 4;
|
|
||||||
memcpy(ud->data, gc->xdata, ud->size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set cell data. */
|
const struct cmd_entry cmd_clock_mode_entry = {
|
||||||
void
|
"clock-mode", NULL,
|
||||||
grid_cell_set(struct grid_cell *gc, const struct utf8_data *ud)
|
CMD_TARGET_PANE_USAGE,
|
||||||
{
|
0, "",
|
||||||
memcpy(gc->xdata, ud->data, ud->size);
|
cmd_target_init,
|
||||||
gc->xstate = (ud->width << 4) | ud->size;
|
cmd_target_parse,
|
||||||
}
|
cmd_clock_mode_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
/* Set a single character as cell data. */
|
int
|
||||||
void
|
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
grid_cell_one(struct grid_cell *gc, u_char ch)
|
|
||||||
{
|
{
|
||||||
*gc->xdata = ch;
|
struct cmd_target_data *data = self->data;
|
||||||
gc->xstate = (1 << 4) | 1;
|
struct window_pane *wp;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
window_pane_set_mode(wp, &window_clock_mode);
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,87 +27,184 @@
|
|||||||
* Prompt for command in client.
|
* Prompt for command in client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *);
|
void cmd_command_prompt_init(struct cmd *, int);
|
||||||
|
int cmd_command_prompt_parse(struct cmd *, int, char **, char **);
|
||||||
|
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_exec
|
cmd_command_prompt_parse,
|
||||||
|
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;
|
||||||
int idx;
|
int idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
void
|
||||||
cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
|
cmd_command_prompt_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_command_prompt_data *data;
|
||||||
const char *inputs, *prompts;
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->prompts = NULL;
|
||||||
|
data->target = NULL;
|
||||||
|
data->template = NULL;
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case ',':
|
||||||
|
data->template = xstrdup("rename-window '%%'");
|
||||||
|
break;
|
||||||
|
case '.':
|
||||||
|
data->template = xstrdup("move-window -t '%%'");
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
data->template = xstrdup("find-window '%%'");
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
data->template = xstrdup("select-window -t ':%%'");
|
||||||
|
data->prompts = xstrdup("index");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
struct cmd_command_prompt_data *data = self->data;
|
||||||
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(cmdq, args_get(args, 't'), 0)) == 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
|
||||||
@@ -118,40 +213,43 @@ cmd_command_prompt_callback(void *data, const char *s)
|
|||||||
struct cmd_command_prompt_cdata *cdata = data;
|
struct cmd_command_prompt_cdata *cdata = data;
|
||||||
struct client *c = cdata->c;
|
struct client *c = cdata->c;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
char *cause, *new_template, *prompt, *ptr;
|
struct cmd_ctx ctx;
|
||||||
char *input = NULL;
|
char *cause, *newtempl, *prompt, *ptr;
|
||||||
|
|
||||||
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, NULL, 0, &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);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdq_run(c->cmdq, cmdlist, NULL);
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = c;
|
||||||
|
|
||||||
|
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);
|
cmd_list_free(cmdlist);
|
||||||
|
|
||||||
if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
|
if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
|
||||||
@@ -160,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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -16,10 +16,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -28,84 +25,112 @@
|
|||||||
* Asks for confirmation before executing a command.
|
* Asks for confirmation before executing a command.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *);
|
int 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_exec
|
cmd_target_parse,
|
||||||
|
cmd_confirm_before_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_confirm_before_data {
|
struct cmd_confirm_before_data {
|
||||||
|
struct client *c;
|
||||||
char *cmd;
|
char *cmd;
|
||||||
struct client *client;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
void
|
||||||
cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
|
cmd_confirm_before_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case '&':
|
||||||
|
data->arg = xstrdup("kill-window");
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
data->arg = xstrdup("kill-pane");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
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 ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
|
if (ctx->curclient == NULL) {
|
||||||
return (CMD_RETURN_ERROR);
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
if ((prompt = args_get(args, 'p')) != NULL)
|
|
||||||
xasprintf(&new_prompt, "%s ", prompt);
|
|
||||||
else {
|
|
||||||
ptr = copy = xstrdup(args->argv[0]);
|
|
||||||
cmd = strsep(&ptr, " \t");
|
|
||||||
xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
|
|
||||||
free(copy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
ptr = xstrdup(data->arg);
|
||||||
|
if ((cmd = strtok(ptr, " \t")) == NULL)
|
||||||
|
cmd = ptr;
|
||||||
|
xasprintf(&buf, "Confirm '%s'? (y/n) ", cmd);
|
||||||
|
xfree(ptr);
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
cdata->cmd = xstrdup(args->argv[0]);
|
cdata->cmd = xstrdup(data->arg);
|
||||||
|
cdata->c = c;
|
||||||
cdata->client = c;
|
status_prompt_set(cdata->c, buf,
|
||||||
cdata->client->references++;
|
|
||||||
|
|
||||||
status_prompt_set(c, new_prompt, NULL,
|
|
||||||
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_NORMAL);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cmd_confirm_before_callback(void *data, const char *s)
|
cmd_confirm_before_callback(void *data, const char *s)
|
||||||
{
|
{
|
||||||
struct cmd_confirm_before_data *cdata = data;
|
struct cmd_confirm_before_data *cdata = data;
|
||||||
struct client *c = cdata->client;
|
struct client *c = cdata->c;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
char *cause;
|
char *cause;
|
||||||
|
|
||||||
if (c->flags & CLIENT_DEAD)
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
if (s == NULL || *s == '\0')
|
if (s == NULL || *s == '\0')
|
||||||
return (0);
|
return (0);
|
||||||
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
if (cmd_string_parse(cdata->cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
cmdq_error(c->cmdq, "%s", cause);
|
*cause = toupper((u_char) *cause);
|
||||||
free(cause);
|
status_message_set(c, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdq_run(c->cmdq, cmdlist, NULL);
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = c;
|
||||||
|
|
||||||
|
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);
|
cmd_list_free(cmdlist);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@@ -115,10 +140,8 @@ void
|
|||||||
cmd_confirm_before_free(void *data)
|
cmd_confirm_before_free(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_confirm_before_data *cdata = data;
|
struct cmd_confirm_before_data *cdata = data;
|
||||||
struct client *c = cdata->client;
|
|
||||||
|
|
||||||
server_client_unref(c);
|
if (cdata->cmd != NULL)
|
||||||
|
xfree(cdata->cmd);
|
||||||
free(cdata->cmd);
|
xfree(cdata);
|
||||||
free(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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -21,60 +21,52 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enter copy or clock mode.
|
* Enter copy mode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_q *);
|
void cmd_copy_mode_init(struct cmd *, int);
|
||||||
|
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,
|
||||||
"Met:u", 0, 0,
|
"[-u] " CMD_TARGET_PANE_USAGE,
|
||||||
"[-Meu] " CMD_TARGET_PANE_USAGE,
|
0, "u",
|
||||||
0,
|
cmd_copy_mode_init,
|
||||||
cmd_copy_mode_exec
|
cmd_target_parse,
|
||||||
|
cmd_copy_mode_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_clock_mode_entry = {
|
void
|
||||||
"clock-mode", NULL,
|
cmd_copy_mode_init(struct cmd *self, int key)
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_PANE_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_copy_mode_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data;
|
||||||
struct client *c = cmdq->client;
|
|
||||||
struct session *s;
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case KEYC_PPAGE:
|
||||||
|
cmd_set_flag(&data->chflags, 'u');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
|
|
||||||
if (args_has(args, 'M')) {
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
if ((wp = cmd_mouse_pane(&cmdq->item->mouse, &s, NULL)) == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
if (c == NULL || c->session != s)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
} else if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
if (self->entry == &cmd_clock_mode_entry) {
|
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
|
||||||
window_pane_set_mode(wp, &window_clock_mode);
|
return (0);
|
||||||
return (CMD_RETURN_NORMAL);
|
window_copy_init_from_pane(wp);
|
||||||
}
|
if (wp->mode == &window_copy_mode && cmd_check_flag(data->chflags, 'u'))
|
||||||
|
|
||||||
if (wp->mode != &window_copy_mode) {
|
|
||||||
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
window_copy_init_from_pane(wp, args_has(self->args, 'e'));
|
|
||||||
}
|
|
||||||
if (args_has(args, 'M')) {
|
|
||||||
if (wp->mode != NULL && wp->mode != &window_copy_mode)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
window_copy_start_drag(c, &cmdq->item->mouse);
|
|
||||||
}
|
|
||||||
if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
|
|
||||||
window_copy_pageup(wp);
|
window_copy_pageup(wp);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
59
cmd-delete-buffer.c
Normal file
59
cmd-delete-buffer.c
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/* $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>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delete a paste buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_delete_buffer_entry = {
|
||||||
|
"delete-buffer", "deleteb",
|
||||||
|
CMD_BUFFER_SESSION_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_buffer_init,
|
||||||
|
cmd_buffer_parse,
|
||||||
|
cmd_delete_buffer_exec,
|
||||||
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -18,85 +18,35 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Detach a client.
|
* Detach a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_q *);
|
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,
|
|
||||||
"[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
|
||||||
CMD_READONLY,
|
|
||||||
cmd_detach_client_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_suspend_client_entry = {
|
|
||||||
"suspend-client", "suspendc",
|
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_CLIENT_USAGE,
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
0,
|
CMD_READONLY, "",
|
||||||
cmd_detach_client_exec
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_detach_client_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
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, *cloop;
|
struct client *c;
|
||||||
struct session *s;
|
|
||||||
enum msgtype msgtype;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_suspend_client_entry) {
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
tty_stop_tty(&c->tty);
|
|
||||||
c->flags |= CLIENT_SUSPENDED;
|
|
||||||
server_write_client(c, MSG_SUSPEND, NULL, 0);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'P'))
|
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||||
msgtype = MSG_DETACHKILL;
|
|
||||||
else
|
|
||||||
msgtype = MSG_DETACH;
|
|
||||||
|
|
||||||
if (args_has(args, 's')) {
|
return (0);
|
||||||
s = cmd_find_session(cmdq, args_get(args, 's'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
TAILQ_FOREACH(cloop, &clients, entry) {
|
|
||||||
if (cloop->session != s)
|
|
||||||
continue;
|
|
||||||
server_write_client(cloop, msgtype,
|
|
||||||
cloop->session->name,
|
|
||||||
strlen(cloop->session->name) + 1);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_STOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
c = cmd_find_client(cmdq, args_get(args, 't'), 0);
|
|
||||||
if (c == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
|
||||||
TAILQ_FOREACH(cloop, &clients, entry) {
|
|
||||||
if (cloop->session == NULL || cloop == c)
|
|
||||||
continue;
|
|
||||||
server_write_client(cloop, msgtype,
|
|
||||||
cloop->session->name,
|
|
||||||
strlen(cloop->session->name) + 1);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
server_write_client(c, msgtype, c->session->name,
|
|
||||||
strlen(c->session->name) + 1);
|
|
||||||
return (CMD_RETURN_STOP);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,84 +26,41 @@
|
|||||||
* Displays a message in the status line.
|
* Displays a message in the status line.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DISPLAY_MESSAGE_TEMPLATE \
|
int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"[#{session_name}] #{window_index}:" \
|
|
||||||
"#{window_name}, current pane #{pane_index} " \
|
|
||||||
"- (%H:%M %d-%b-%y)"
|
|
||||||
|
|
||||||
enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_q *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_display_message_entry = {
|
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] [-F format] " CMD_TARGET_PANE_USAGE
|
CMD_ARG01, "p",
|
||||||
" [message]",
|
cmd_target_init,
|
||||||
0,
|
cmd_target_parse,
|
||||||
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_q *cmdq)
|
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 (args_has(args, 't')) {
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
|
return (-1);
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
} else {
|
|
||||||
wl = cmd_find_pane(cmdq, NULL, &s, &wp);
|
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'F') && args->argc != 0) {
|
if (data->arg == NULL)
|
||||||
cmdq_error(cmdq, "only one of -F or argument must be given");
|
template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)";
|
||||||
return (CMD_RETURN_ERROR);
|
else
|
||||||
}
|
template = data->arg;
|
||||||
|
|
||||||
if (args_has(args, 'c')) {
|
msg = status_replace(c, NULL, template, time(NULL), 0);
|
||||||
c = cmd_find_client(cmdq, args_get(args, 'c'), 0);
|
if (cmd_check_flag(data->chflags, 'p'))
|
||||||
if (c == NULL)
|
ctx->print(ctx, "%s", msg);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
} else {
|
|
||||||
c = cmd_find_client(cmdq, NULL, 1);
|
|
||||||
if (c == NULL && !args_has(self->args, 'p')) {
|
|
||||||
cmdq_error(cmdq, "no client available");
|
|
||||||
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_defaults(ft, c, s, wl, 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'))
|
|
||||||
cmdq_print(cmdq, "%s", msg);
|
|
||||||
else
|
else
|
||||||
status_message_set(c, "%s", msg);
|
status_message_set(c, "%s", msg);
|
||||||
free(msg);
|
xfree(msg);
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,26 +24,29 @@
|
|||||||
* Display panes on a client.
|
* Display panes on a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_q *);
|
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, "",
|
||||||
cmd_display_panes_exec
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_display_panes_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
|
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(cmdq, args_get(args, 't'), 0)) == 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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,155 +27,93 @@
|
|||||||
* Find window containing text.
|
* Find window containing text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FIND_WINDOW_TEMPLATE \
|
int cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{window_index}: #{window_name} " \
|
|
||||||
"[#{window_width}x#{window_height}] " \
|
|
||||||
"(#{window_panes} panes) #{window_find_matches}"
|
|
||||||
|
|
||||||
enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_q *);
|
void cmd_find_window_callback(void *, int);
|
||||||
|
void cmd_find_window_free(void *);
|
||||||
void cmd_find_window_callback(struct window_choose_data *);
|
|
||||||
|
|
||||||
/* 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,
|
||||||
cmd_find_window_exec
|
cmd_target_parse,
|
||||||
|
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;
|
|
||||||
TAILQ_ENTRY(cmd_find_window_data) entry;
|
|
||||||
};
|
};
|
||||||
TAILQ_HEAD(cmd_find_window_list, cmd_find_window_data);
|
|
||||||
|
|
||||||
u_int cmd_find_window_match_flags(struct args *);
|
int
|
||||||
void cmd_find_window_match(struct cmd_find_window_list *, int,
|
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
struct winlink *, const char *, const char *);
|
|
||||||
|
|
||||||
u_int
|
|
||||||
cmd_find_window_match_flags(struct args *args)
|
|
||||||
{
|
{
|
||||||
u_int match_flags = 0;
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct cmd_find_window_data *cdata;
|
||||||
/* 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_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;
|
|
||||||
|
|
||||||
find_data = xcalloc(1, 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;
|
|
||||||
TAILQ_INSERT_TAIL(find_list, find_data, entry);
|
|
||||||
} else
|
|
||||||
free(find_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c;
|
|
||||||
struct window_choose_data *cdata;
|
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl, *wm;
|
struct winlink *wl, *wm;
|
||||||
struct cmd_find_window_list find_list;
|
struct window *w;
|
||||||
struct cmd_find_window_data *find_data;
|
struct window_pane *wp;
|
||||||
struct cmd_find_window_data *find_data1;
|
ARRAY_DECL(, u_int) list_idx;
|
||||||
char *str, *searchstr;
|
ARRAY_DECL(, char *) list_ctx;
|
||||||
const char *template;
|
char *sres, *sctx, *searchstr;
|
||||||
u_int i, match_flags;
|
u_int i, line;
|
||||||
|
|
||||||
if ((c = cmd_find_client(cmdq, NULL, 1)) == NULL) {
|
if (ctx->curclient == NULL) {
|
||||||
cmdq_error(cmdq, "no client available");
|
ctx->error(ctx, "must be run interactively");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
s = c->session;
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
if ((wl = cmd_find_window(cmdq, 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++;
|
||||||
|
|
||||||
TAILQ_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 (TAILQ_EMPTY(&find_list)) {
|
ARRAY_ADD(&list_idx, wm->idx);
|
||||||
cmdq_error(cmdq, "no windows matching: %s", str);
|
ARRAY_ADD(&list_ctx, sctx);
|
||||||
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 (TAILQ_NEXT(TAILQ_FIRST(&find_list), entry) == NULL) {
|
if (ARRAY_LENGTH(&list_idx) == 1) {
|
||||||
if (session_select(s, TAILQ_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;
|
||||||
@@ -185,55 +122,54 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
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;
|
||||||
|
|
||||||
i = 0;
|
for (i = 0; i < ARRAY_LENGTH(&list_idx); i++) {
|
||||||
TAILQ_FOREACH(find_data, &find_list, entry) {
|
wm = winlink_find_by_index(
|
||||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
&s->windows, ARRAY_ITEM(&list_idx, i));
|
||||||
cdata->idx = find_data->wl->idx;
|
w = wm->window;
|
||||||
cdata->wl = find_data->wl;
|
|
||||||
|
|
||||||
cdata->ft_template = xstrdup(template);
|
sctx = ARRAY_ITEM(&list_ctx, i);
|
||||||
cdata->pane_id = find_data->pane_id;
|
window_choose_add(wl->window->active,
|
||||||
|
wm->idx, "%3d: %s [%ux%u] (%u panes) %s", wm->idx, w->name,
|
||||||
format_add(cdata->ft, "line", "%u", i);
|
w->sx, w->sy, window_count_panes(w), sctx);
|
||||||
format_add(cdata->ft, "window_find_matches", "%s",
|
xfree(sctx);
|
||||||
find_data->list_ctx);
|
|
||||||
format_defaults(cdata->ft, NULL, s, find_data->wl, NULL);
|
|
||||||
|
|
||||||
window_choose_add(wl->window->active, cdata);
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window_choose_ready(wl->window->active, 0, cmd_find_window_callback);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
0, cmd_find_window_callback, cmd_find_window_free, cdata);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
TAILQ_FOREACH_SAFE(find_data, &find_list, entry, find_data1) {
|
ARRAY_FREE(&list_idx);
|
||||||
free(find_data->list_ctx);
|
ARRAY_FREE(&list_ctx);
|
||||||
TAILQ_REMOVE(&find_list, find_data, entry);
|
|
||||||
free(find_data);
|
return (0);
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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->start_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
|
||||||
|
cmd_find_window_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_find_window_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->session->references--;
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
|
|||||||
1228
cmd-find.c
1228
cmd-find.c
File diff suppressed because it is too large
Load Diff
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);
|
||||||
|
}
|
||||||
49
cmd-has-session.c
Normal file
49
cmd-has-session.c
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/* $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>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cause client to report an error and exit with 1 if session doesn't exist.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_has_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_has_session_entry = {
|
||||||
|
"has-session", "has",
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_has_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
|
||||||
|
if (cmd_find_session(ctx, data->target) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
182
cmd-if-shell.c
182
cmd-if-shell.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,190 +20,100 @@
|
|||||||
#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_q *);
|
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_done(struct cmd_q *);
|
|
||||||
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",
|
||||||
"bFt:", 2, 3,
|
"shell-command command",
|
||||||
"[-bF] " CMD_TARGET_PANE_USAGE " shell-command command [command]",
|
CMD_ARG2, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
cmd_if_shell_exec
|
cmd_target_parse,
|
||||||
|
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_q *cmdq;
|
|
||||||
struct mouse_event mouse;
|
|
||||||
|
|
||||||
int bflag;
|
|
||||||
int references;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
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;
|
||||||
char *shellcmd, *cmd, *cause;
|
struct job *job;
|
||||||
struct cmd_list *cmdlist;
|
|
||||||
struct client *c;
|
|
||||||
struct session *s = NULL;
|
|
||||||
struct winlink *wl = NULL;
|
|
||||||
struct window_pane *wp = NULL;
|
|
||||||
struct format_tree *ft;
|
|
||||||
int cwd;
|
|
||||||
|
|
||||||
if (args_has(args, 't')) {
|
|
||||||
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
|
|
||||||
cwd = wp->cwd;
|
|
||||||
} else {
|
|
||||||
c = cmd_find_client(cmdq, NULL, 1);
|
|
||||||
if (c != NULL && c->session != NULL) {
|
|
||||||
s = c->session;
|
|
||||||
wl = s->curw;
|
|
||||||
wp = wl->window->active;
|
|
||||||
}
|
|
||||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
|
||||||
cwd = cmdq->client->cwd;
|
|
||||||
else if (s != NULL)
|
|
||||||
cwd = s->cwd;
|
|
||||||
else
|
|
||||||
cwd = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ft = format_create();
|
|
||||||
format_defaults(ft, NULL, s, wl, wp);
|
|
||||||
shellcmd = format_expand(ft, args->argv[0]);
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
if (args_has(args, 'F')) {
|
|
||||||
cmd = NULL;
|
|
||||||
if (*shellcmd != '0' && *shellcmd != '\0')
|
|
||||||
cmd = args->argv[1];
|
|
||||||
else if (args->argc == 3)
|
|
||||||
cmd = args->argv[2];
|
|
||||||
if (cmd == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(cmdq, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
cmdq_run(cmdq, cmdlist, &cmdq->item->mouse);
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->cmd = xstrdup(data->arg2);
|
||||||
|
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||||
|
|
||||||
cdata->cmd_if = xstrdup(args->argv[1]);
|
if (ctx->cmdclient != NULL)
|
||||||
if (args->argc == 3)
|
ctx->cmdclient->references++;
|
||||||
cdata->cmd_else = xstrdup(args->argv[2]);
|
if (ctx->curclient != NULL)
|
||||||
else
|
ctx->curclient->references++;
|
||||||
cdata->cmd_else = NULL;
|
|
||||||
|
|
||||||
cdata->bflag = args_has(args, 'b');
|
job = job_add(NULL, 0, NULL,
|
||||||
|
data->arg, cmd_if_shell_callback, cmd_if_shell_free, cdata);
|
||||||
|
job_run(job);
|
||||||
|
|
||||||
cdata->cmdq = cmdq;
|
return (1); /* don't let client exit */
|
||||||
memcpy(&cdata->mouse, &cmdq->item->mouse, sizeof cdata->mouse);
|
|
||||||
cmdq->references++;
|
|
||||||
|
|
||||||
cdata->references = 1;
|
|
||||||
job_run(shellcmd, s, cwd, cmd_if_shell_callback, cmd_if_shell_free,
|
|
||||||
cdata);
|
|
||||||
free(shellcmd);
|
|
||||||
|
|
||||||
if (cdata->bflag)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_if_shell_callback(struct job *job)
|
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_q *cmdq = cdata->cmdq, *cmdq1;
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
char *cause, *cmd;
|
char *cause;
|
||||||
|
|
||||||
if (cmdq->flags & CMD_Q_DEAD)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
||||||
cmd = cdata->cmd_else;
|
|
||||||
else
|
|
||||||
cmd = cdata->cmd_if;
|
|
||||||
if (cmd == NULL)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
cmdq_error(cmdq, "%s", cause);
|
ctx->error(ctx, "%s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdq1 = cmdq_new(cmdq->client);
|
if (cmd_list_exec(cmdlist, ctx) < 0) {
|
||||||
cmdq1->emptyfn = cmd_if_shell_done;
|
cmd_list_free(cmdlist);
|
||||||
cmdq1->data = cdata;
|
|
||||||
|
|
||||||
cdata->references++;
|
|
||||||
cmdq_run(cmdq1, cmdlist, &cdata->mouse);
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_if_shell_done(struct cmd_q *cmdq1)
|
|
||||||
{
|
|
||||||
struct cmd_if_shell_data *cdata = cmdq1->data;
|
|
||||||
struct cmd_q *cmdq = cdata->cmdq;
|
|
||||||
|
|
||||||
if (cmdq1->client_exit >= 0)
|
|
||||||
cmdq->client_exit = cmdq1->client_exit;
|
|
||||||
cmdq_free(cmdq1);
|
|
||||||
|
|
||||||
if (--cdata->references != 0)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!cmdq_free(cmdq) && !cdata->bflag)
|
cmd_list_free(cmdlist);
|
||||||
cmdq_continue(cmdq);
|
|
||||||
|
|
||||||
free(cdata->cmd_else);
|
|
||||||
free(cdata->cmd_if);
|
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_if_shell_free(void *data)
|
cmd_if_shell_free(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_if_shell_data *cdata = data;
|
struct cmd_if_shell_data *cdata = data;
|
||||||
struct cmd_q *cmdq = cdata->cmdq;
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
struct msg_exit_data exitdata;
|
||||||
|
|
||||||
if (--cdata->references != 0)
|
if (ctx->cmdclient != NULL) {
|
||||||
return;
|
ctx->cmdclient->references--;
|
||||||
|
exitdata.retcode = ctx->cmdclient->retcode;
|
||||||
|
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||||
|
}
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references--;
|
||||||
|
|
||||||
if (!cmdq_free(cmdq) && !cdata->bflag)
|
xfree(cdata->cmd);
|
||||||
cmdq_continue(cmdq);
|
xfree(cdata);
|
||||||
|
|
||||||
free(cdata->cmd_else);
|
|
||||||
free(cdata->cmd_if);
|
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|||||||
253
cmd-join-pane.c
253
cmd-join-pane.c
@@ -1,7 +1,6 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,109 +24,180 @@
|
|||||||
#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).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *);
|
int cmd_join_pane_parse(struct cmd *, int, char **, char **);
|
||||||
|
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_q *, 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] " CMD_SRCDST_PANE_USAGE,
|
0, "",
|
||||||
0,
|
cmd_join_pane_init,
|
||||||
cmd_join_pane_exec
|
cmd_join_pane_parse,
|
||||||
|
cmd_join_pane_exec,
|
||||||
|
cmd_join_pane_free,
|
||||||
|
cmd_join_pane_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_move_pane_entry = {
|
void
|
||||||
"move-pane", "movep",
|
cmd_join_pane_init(struct cmd *self, int key)
|
||||||
"bdhvp:l:s:t:", 0, 0,
|
|
||||||
"[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_join_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
return (join_pane(self, cmdq, self->entry == &cmd_join_pane_entry));
|
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) {
|
||||||
|
case '%':
|
||||||
|
data->flag_horizontal = 1;
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
data->flag_horizontal = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
|
cmd_join_pane_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_join_pane_data *data;
|
||||||
struct session *dst_s;
|
int opt;
|
||||||
struct winlink *src_wl, *dst_wl;
|
const char *errstr;
|
||||||
struct window *src_w, *dst_w;
|
|
||||||
struct window_pane *src_wp, *dst_wp;
|
|
||||||
char *cause;
|
|
||||||
int size, percentage, dst_idx;
|
|
||||||
enum layout_type type;
|
|
||||||
struct layout_cell *lc;
|
|
||||||
|
|
||||||
dst_wl = cmd_find_pane(cmdq, args_get(args, 't'), &dst_s, &dst_wp);
|
self->entry->init(self, KEYC_NONE);
|
||||||
if (dst_wl == NULL)
|
data = self->data;
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_join_pane_data *data = self->data;
|
||||||
|
struct session *dst_s;
|
||||||
|
struct winlink *src_wl, *dst_wl;
|
||||||
|
struct window *src_w, *dst_w;
|
||||||
|
struct window_pane *src_wp, *dst_wp;
|
||||||
|
int size, dst_idx;
|
||||||
|
enum layout_type type;
|
||||||
|
struct layout_cell *lc;
|
||||||
|
|
||||||
|
if ((dst_wl = cmd_find_pane(ctx, data->dst, &dst_s, &dst_wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
dst_w = dst_wl->window;
|
dst_w = dst_wl->window;
|
||||||
dst_idx = dst_wl->idx;
|
dst_idx = dst_wl->idx;
|
||||||
server_unzoom_window(dst_w);
|
|
||||||
|
|
||||||
src_wl = cmd_find_pane_marked(cmdq, 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;
|
||||||
server_unzoom_window(src_w);
|
|
||||||
|
|
||||||
if (not_same_window && src_w == dst_w) {
|
if (src_w == dst_w) {
|
||||||
cmdq_error(cmdq, "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) {
|
|
||||||
cmdq_error(cmdq, "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) {
|
||||||
cmdq_error(cmdq, "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) {
|
|
||||||
cmdq_error(cmdq, "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) {
|
||||||
cmdq_error(cmdq, "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);
|
||||||
|
|
||||||
window_lost_pane(src_w, src_wp);
|
if (src_w->active == src_wp) {
|
||||||
|
src_w->active = TAILQ_PREV(src_wp, window_panes, entry);
|
||||||
|
if (src_w->active == NULL)
|
||||||
|
src_w->active = TAILQ_NEXT(src_wp, entry);
|
||||||
|
}
|
||||||
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
||||||
|
|
||||||
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);
|
||||||
@@ -138,13 +208,50 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, 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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,40 +26,45 @@
|
|||||||
* Kill pane.
|
* Kill pane.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_q *);
|
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",
|
||||||
cmd_kill_pane_exec
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_kill_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_kill_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
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(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
|
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
server_unzoom_window(wl->window);
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -67,5 +72,5 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
}
|
}
|
||||||
server_redraw_window(wl->window);
|
server_redraw_window(wl->window);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,29 +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_q *);
|
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, "",
|
||||||
cmd_kill_server_exec
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_kill_server_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_start_server_entry = {
|
/* ARGSUSED */
|
||||||
"start-server", "start",
|
int
|
||||||
"", 0, 0,
|
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
"",
|
|
||||||
CMD_STARTSERVER,
|
|
||||||
cmd_kill_server_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_kill_server_exec(struct cmd *self, unused struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
if (self->entry == &cmd_kill_server_entry)
|
kill(getpid(), SIGTERM);
|
||||||
kill(getpid(), SIGTERM);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,35 +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_q *);
|
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,
|
||||||
cmd_kill_session_exec
|
cmd_target_parse,
|
||||||
|
cmd_kill_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_kill_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
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, *sloop, *stmp;
|
struct session *s;
|
||||||
|
|
||||||
if ((s = cmd_find_session(cmdq, 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(sloop, sessions, &sessions, stmp) {
|
session_destroy(s);
|
||||||
if (sloop != s) {
|
|
||||||
server_destroy_session(sloop);
|
return (0);
|
||||||
session_destroy(sloop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
server_destroy_session(s);
|
|
||||||
session_destroy(s);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,52 +24,30 @@
|
|||||||
* Destroy window.
|
* Destroy window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_q *);
|
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,
|
||||||
cmd_kill_window_exec
|
cmd_target_parse,
|
||||||
|
cmd_kill_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_unlink_window_entry = {
|
int
|
||||||
"unlink-window", "unlinkw",
|
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
"kt:", 0, 0,
|
|
||||||
"[-k] " CMD_TARGET_WINDOW_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_kill_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl, *wl2, *wl3;
|
struct winlink *wl;
|
||||||
struct window *w;
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
w = wl->window;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_unlink_window_entry) {
|
|
||||||
if (!args_has(self->args, 'k') && !session_is_linked(s, w)) {
|
|
||||||
cmdq_error(cmdq, "window only linked to one session");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
server_unlink_window(s, wl);
|
|
||||||
} else {
|
|
||||||
if (args_has(args, 'a')) {
|
|
||||||
RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) {
|
|
||||||
if (wl != wl2)
|
|
||||||
server_kill_window(wl2->window);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
server_kill_window(wl->window);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
66
cmd-link-window.c
Normal file
66
cmd-link-window.c
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/* $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>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Link a window into another session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_link_window_entry = {
|
||||||
|
"link-window", "linkw",
|
||||||
|
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
|
0, "dk",
|
||||||
|
cmd_srcdst_init,
|
||||||
|
cmd_srcdst_parse,
|
||||||
|
cmd_link_window_exec,
|
||||||
|
cmd_srcdst_free,
|
||||||
|
cmd_srcdst_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_srcdst_data *data = self->data;
|
||||||
|
struct session *src, *dst;
|
||||||
|
struct winlink *wl;
|
||||||
|
char *cause;
|
||||||
|
int idx, kflag, dflag;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
kflag = cmd_check_flag(data->chflags, 'k');
|
||||||
|
dflag = cmd_check_flag(data->chflags, 'd');
|
||||||
|
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "can't link window: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,42 +26,38 @@
|
|||||||
* List paste buffers.
|
* List paste buffers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_BUFFERS_TEMPLATE \
|
int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\""
|
|
||||||
|
|
||||||
enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_q *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_buffers_entry = {
|
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,
|
||||||
cmd_list_buffers_exec
|
cmd_target_parse,
|
||||||
|
cmd_list_buffers_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_list_buffers_exec(unused struct cmd *self, struct cmd_q *cmdq)
|
cmd_list_buffers_exec(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;
|
||||||
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);
|
||||||
|
|
||||||
pb = NULL;
|
idx = 0;
|
||||||
while ((pb = paste_walk(pb)) != NULL) {
|
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
||||||
ft = format_create();
|
tmp = paste_print(pb, 50);
|
||||||
format_defaults_paste_buffer(ft, pb, 0);
|
ctx->print(ctx,
|
||||||
|
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||||
line = format_expand(ft, template);
|
xfree(tmp);
|
||||||
cmdq_print(cmdq, "%s", line);
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
|
|
||||||
@@ -28,59 +27,40 @@
|
|||||||
* List all clients.
|
* List all clients.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_CLIENTS_TEMPLATE \
|
int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{client_tty}: #{session_name} " \
|
|
||||||
"[#{client_width}x#{client_height} #{client_termname}]" \
|
|
||||||
"#{?client_utf8, (utf8),} #{?client_readonly, (ro),}"
|
|
||||||
|
|
||||||
enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmd_q *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_clients_entry = {
|
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,
|
||||||
cmd_list_clients_exec
|
NULL,
|
||||||
|
cmd_list_clients_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq)
|
int
|
||||||
|
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 idx;
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
if (args_has(args, 't')) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
c = ARRAY_ITEM(&clients, i);
|
||||||
if (s == NULL)
|
if (c == NULL || c->session == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
} else
|
|
||||||
s = NULL;
|
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = LIST_CLIENTS_TEMPLATE;
|
|
||||||
|
|
||||||
idx = 0;
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
|
||||||
if (c->session == NULL || (s != NULL && s != c->session))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ft = format_create();
|
if (c->tty.flags & TTY_UTF8)
|
||||||
format_add(ft, "line", "%u", idx);
|
s_utf8 = " (utf8)";
|
||||||
format_defaults(ft, c, NULL, NULL, NULL);
|
else
|
||||||
|
s_utf8 = "";
|
||||||
line = format_expand(ft, template);
|
ctx->print(ctx, "%s: %s [%ux%u %s]%s", c->tty.path,
|
||||||
cmdq_print(cmdq, "%s", line);
|
c->session->name, c->tty.sx, c->tty.sy,
|
||||||
free(line);
|
c->tty.termname, s_utf8);
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
idx++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
/* $Id: cmd-list-commands.c,v 1.7 2009-11-28 14:50:36 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 Dagobert Michelsen
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
* Copyright (c) 2013 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
|
||||||
@@ -15,16 +16,35 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
void
|
/*
|
||||||
cfmakeraw(struct termios *tio)
|
* List all commands with usages.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_list_commands_entry = {
|
||||||
|
"list-commands", "lscm",
|
||||||
|
"",
|
||||||
|
0, "",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_commands_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
tio->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
|
const struct cmd_entry **entryp;
|
||||||
tio->c_oflag &= ~OPOST;
|
|
||||||
tio->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
|
for (entryp = cmd_table; *entryp != NULL; entryp++)
|
||||||
tio->c_cflag &= ~(CSIZE|PARENB);
|
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
|
||||||
tio->c_cflag |= CS8;
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
213
cmd-list-keys.c
213
cmd-list-keys.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,168 +26,109 @@
|
|||||||
* List key bindings.
|
* List key bindings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *);
|
int cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *);
|
int cmd_list_keys_table(struct cmd *, struct cmd_ctx *);
|
||||||
enum cmd_retval cmd_list_keys_commands(struct cmd *, struct cmd_q *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_keys_entry = {
|
const struct cmd_entry cmd_list_keys_entry = {
|
||||||
"list-keys", "lsk",
|
"list-keys", "lsk",
|
||||||
"t:T:", 0, 0,
|
"[-t key-table]",
|
||||||
"[-t mode-table] [-T key-table]",
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
cmd_list_keys_exec
|
cmd_target_parse,
|
||||||
|
cmd_list_keys_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_commands_entry = {
|
int
|
||||||
"list-commands", "lscm",
|
cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
"", 0, 0,
|
|
||||||
"",
|
|
||||||
0,
|
|
||||||
cmd_list_keys_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct key_table *table;
|
|
||||||
struct key_binding *bd;
|
struct key_binding *bd;
|
||||||
const char *key, *tablename, *r;
|
const char *key;
|
||||||
char tmp[BUFSIZ];
|
char tmp[BUFSIZ];
|
||||||
size_t used;
|
size_t used;
|
||||||
int repeat, width, tablewidth, keywidth;
|
int width, keywidth;
|
||||||
|
|
||||||
if (self->entry == &cmd_list_commands_entry)
|
if (data->target != NULL)
|
||||||
return (cmd_list_keys_commands(self, cmdq));
|
return (cmd_list_keys_table(self, ctx));
|
||||||
|
|
||||||
if (args_has(args, 't'))
|
|
||||||
return (cmd_list_keys_table(self, cmdq));
|
|
||||||
|
|
||||||
tablename = args_get(args, 'T');
|
|
||||||
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) {
|
|
||||||
cmdq_error(cmdq, "table %s doesn't exist", tablename);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
repeat = 0;
|
|
||||||
tablewidth = keywidth = 0;
|
|
||||||
RB_FOREACH(table, key_tables, &key_tables) {
|
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0)
|
|
||||||
continue;
|
|
||||||
RB_FOREACH(bd, key_bindings, &table->key_bindings) {
|
|
||||||
key = key_string_lookup_key(bd->key);
|
|
||||||
if (key == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (bd->can_repeat)
|
|
||||||
repeat = 1;
|
|
||||||
|
|
||||||
width = strlen(table->name);
|
|
||||||
if (width > tablewidth)
|
|
||||||
tablewidth =width;
|
|
||||||
width = strlen(key);
|
|
||||||
if (width > keywidth)
|
|
||||||
keywidth = width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RB_FOREACH(table, key_tables, &key_tables) {
|
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0)
|
|
||||||
continue;
|
|
||||||
RB_FOREACH(bd, key_bindings, &table->key_bindings) {
|
|
||||||
key = key_string_lookup_key(bd->key);
|
|
||||||
if (key == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!repeat)
|
|
||||||
r = "";
|
|
||||||
else if (bd->can_repeat)
|
|
||||||
r = "-r ";
|
|
||||||
else
|
|
||||||
r = " ";
|
|
||||||
used = xsnprintf(tmp, sizeof tmp, "%s-T %-*s %-*s ", r,
|
|
||||||
(int)tablewidth, table->name, (int)keywidth, key);
|
|
||||||
if (used < sizeof tmp) {
|
|
||||||
cmd_list_print(bd->cmdlist, tmp + used,
|
|
||||||
(sizeof tmp) - used);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdq_print(cmdq, "bind-key %s", tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
const char *tablename;
|
|
||||||
const struct mode_key_table *mtab;
|
|
||||||
struct mode_key_binding *mbind;
|
|
||||||
const char *key, *cmdstr, *mode;
|
|
||||||
int width, keywidth, any_mode;
|
|
||||||
|
|
||||||
tablename = args_get(args, 't');
|
|
||||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
|
||||||
cmdq_error(cmdq, "unknown key table: %s", tablename);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
width = 0;
|
width = 0;
|
||||||
any_mode = 0;
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
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;
|
if (!(bd->key & KEYC_PREFIX))
|
||||||
|
keywidth += 2;
|
||||||
keywidth = strlen(key);
|
|
||||||
if (keywidth > width)
|
if (keywidth > width)
|
||||||
width = keywidth;
|
width = keywidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
|
if (key == NULL)
|
||||||
|
continue;
|
||||||
|
used = xsnprintf(tmp, sizeof tmp, "%*s: ", width, key);
|
||||||
|
if (used >= sizeof tmp)
|
||||||
|
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);
|
||||||
|
ctx->print(ctx, "%s", tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
const struct mode_key_table *mtab;
|
||||||
|
struct mode_key_binding *mbind;
|
||||||
|
const char *key, *cmdstr, *mode;
|
||||||
|
int width, keywidth;
|
||||||
|
|
||||||
|
if ((mtab = mode_key_findtable(data->target)) == NULL) {
|
||||||
|
ctx->error(ctx, "unknown key table: %s", data->target);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
width = 0;
|
||||||
|
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
|
key = key_string_lookup_key(mbind->key);
|
||||||
|
if (key == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
keywidth = strlen(key) + 1;
|
||||||
|
if (keywidth > width)
|
||||||
|
width = keywidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
cmdq_print(cmdq, "bind-key -%st %s%s %*s %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,
|
|
||||||
mbind->arg != NULL ? " \"" : "",
|
|
||||||
mbind->arg != NULL ? mbind->arg : "",
|
|
||||||
mbind->arg != NULL ? "\"": "");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_list_keys_commands(unused struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
const struct cmd_entry **entryp;
|
|
||||||
const struct cmd_entry *entry;
|
|
||||||
|
|
||||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
|
||||||
entry = *entryp;
|
|
||||||
if (entry->alias == NULL) {
|
|
||||||
cmdq_print(cmdq, "%s %s", entry->name, entry->usage);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cmdq_print(cmdq, "%s (%s) %s", entry->name, entry->alias,
|
|
||||||
entry->usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
131
cmd-list-panes.c
131
cmd-list-panes.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -26,114 +26,51 @@
|
|||||||
* List panes on given window.
|
* List panes on given window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_q *);
|
int cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
void cmd_list_panes_server(struct cmd *, struct cmd_q *);
|
|
||||||
void cmd_list_panes_session(struct cmd *, struct session *, struct cmd_q *,
|
|
||||||
int);
|
|
||||||
void cmd_list_panes_window(struct cmd *, struct session *, struct winlink *,
|
|
||||||
struct cmd_q *, 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] " CMD_TARGET_WINDOW_USAGE,
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
cmd_list_panes_exec
|
cmd_target_parse,
|
||||||
|
cmd_list_panes_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_list_panes_exec(struct cmd *self, struct cmd_q *cmdq)
|
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, cmdq);
|
|
||||||
else if (args_has(args, 's')) {
|
|
||||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
cmd_list_panes_session(self, s, cmdq, 1);
|
|
||||||
} else {
|
|
||||||
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
|
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
cmd_list_panes_window(self, s, wl, cmdq, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_list_panes_server(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions)
|
|
||||||
cmd_list_panes_session(self, s, cmdq, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_list_panes_session(struct cmd *self, struct session *s, struct cmd_q *cmdq,
|
|
||||||
int type)
|
|
||||||
{
|
|
||||||
struct winlink *wl;
|
|
||||||
|
|
||||||
RB_FOREACH(wl, winlinks, &s->windows)
|
|
||||||
cmd_list_panes_window(self, s, wl, cmdq, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
|
||||||
struct cmd_q *cmdq, 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_defaults(ft, NULL, s, wl, wp);
|
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
size = 0;
|
||||||
cmdq_print(cmdq, "%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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,50 +27,45 @@
|
|||||||
* List all sessions.
|
* List all sessions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_SESSIONS_TEMPLATE \
|
int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{session_name}: #{session_windows} windows " \
|
|
||||||
"(created #{session_created_string}) " \
|
|
||||||
"[#{session_width}x#{session_height}]" \
|
|
||||||
"#{?session_grouped, (group ,}" \
|
|
||||||
"#{session_group}#{?session_grouped,),}" \
|
|
||||||
"#{?session_attached, (attached),}"
|
|
||||||
|
|
||||||
enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_q *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_sessions_entry = {
|
const struct cmd_entry cmd_list_sessions_entry = {
|
||||||
"list-sessions", "ls",
|
"list-sessions", "ls", "",
|
||||||
"F:", 0, 0,
|
0, "",
|
||||||
"[-F format]",
|
NULL,
|
||||||
0,
|
NULL,
|
||||||
cmd_list_sessions_exec
|
cmd_list_sessions_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq)
|
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_defaults(ft, NULL, s, NULL, NULL);
|
*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;
|
||||||
cmdq_print(cmdq, "%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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,93 +26,37 @@
|
|||||||
* List windows on given session.
|
* List windows on given session.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_WINDOWS_TEMPLATE \
|
int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{window_index}: #{window_name}#{window_flags} " \
|
|
||||||
"(#{window_panes} panes) " \
|
|
||||||
"[#{window_width}x#{window_height}] " \
|
|
||||||
"[layout #{window_layout}] #{window_id}" \
|
|
||||||
"#{?window_active, (active),}";
|
|
||||||
#define LIST_WINDOWS_WITH_SESSION_TEMPLATE \
|
|
||||||
"#{session_name}:" \
|
|
||||||
"#{window_index}: #{window_name}#{window_flags} " \
|
|
||||||
"(#{window_panes} panes) " \
|
|
||||||
"[#{window_width}x#{window_height}] "
|
|
||||||
|
|
||||||
enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_q *);
|
|
||||||
|
|
||||||
void cmd_list_windows_server(struct cmd *, struct cmd_q *);
|
|
||||||
void cmd_list_windows_session(struct cmd *, struct session *,
|
|
||||||
struct cmd_q *, int);
|
|
||||||
|
|
||||||
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,
|
||||||
cmd_list_windows_exec
|
cmd_target_parse,
|
||||||
|
cmd_list_windows_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_list_windows_exec(struct cmd *self, struct cmd_q *cmdq)
|
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, cmdq);
|
|
||||||
else {
|
|
||||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
cmd_list_windows_session(self, s, cmdq, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_list_windows_server(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions)
|
|
||||||
cmd_list_windows_session(self, s, cmdq, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_list_windows_session(
|
|
||||||
struct cmd *self, struct session *s, struct cmd_q *cmdq, 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_defaults(ft, NULL, s, wl, NULL);
|
wl->idx, wl->window->name, wl->window->sx, wl->window->sy,
|
||||||
|
layout, wl == s->curw ? " (active)" : "");
|
||||||
line = format_expand(ft, template);
|
xfree(layout);
|
||||||
cmdq_print(cmdq, "%s", line);
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
n++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
71
cmd-list.c
71
cmd-list.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,14 +18,12 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
struct cmd_list *
|
struct cmd_list *
|
||||||
cmd_list_parse(int argc, char **argv, const char *file, u_int line,
|
cmd_list_parse(int argc, char **argv, char **cause)
|
||||||
char **cause)
|
|
||||||
{
|
{
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
struct cmd *cmd;
|
struct cmd *cmd;
|
||||||
@@ -35,7 +33,7 @@ cmd_list_parse(int argc, char **argv, const char *file, u_int line,
|
|||||||
|
|
||||||
copy_argv = cmd_copy_argv(argc, argv);
|
copy_argv = cmd_copy_argv(argc, argv);
|
||||||
|
|
||||||
cmdlist = xcalloc(1, sizeof *cmdlist);
|
cmdlist = xmalloc(sizeof *cmdlist);
|
||||||
cmdlist->references = 1;
|
cmdlist->references = 1;
|
||||||
TAILQ_INIT(&cmdlist->list);
|
TAILQ_INIT(&cmdlist->list);
|
||||||
|
|
||||||
@@ -56,7 +54,7 @@ cmd_list_parse(int argc, char **argv, const char *file, u_int line,
|
|||||||
if (arglen != 1)
|
if (arglen != 1)
|
||||||
new_argc++;
|
new_argc++;
|
||||||
|
|
||||||
cmd = cmd_parse(new_argc, new_argv, file, line, cause);
|
cmd = cmd_parse(new_argc, new_argv, cause);
|
||||||
if (cmd == NULL)
|
if (cmd == NULL)
|
||||||
goto bad;
|
goto bad;
|
||||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||||
@@ -65,8 +63,7 @@ cmd_list_parse(int argc, char **argv, const char *file, u_int line,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lastsplit != argc) {
|
if (lastsplit != argc) {
|
||||||
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit,
|
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit, cause);
|
||||||
file, line, cause);
|
|
||||||
if (cmd == NULL)
|
if (cmd == NULL)
|
||||||
goto bad;
|
goto bad;
|
||||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||||
@@ -81,29 +78,63 @@ bad:
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
int n, retval;
|
||||||
|
|
||||||
|
retval = 0;
|
||||||
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
|
if ((n = cmd_exec(cmd, ctx)) == -1)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A 1 return value means the command client is being attached
|
||||||
|
* (sent MSG_READY).
|
||||||
|
*/
|
||||||
|
if (n == 1) {
|
||||||
|
retval = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The command client has been attached, so mangle the
|
||||||
|
* context to treat any following commands as if they
|
||||||
|
* were called from inside.
|
||||||
|
*/
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->curclient = ctx->cmdclient;
|
||||||
|
ctx->cmdclient = NULL;
|
||||||
|
|
||||||
|
ctx->error = key_bindings_error;
|
||||||
|
ctx->print = key_bindings_print;
|
||||||
|
ctx->info = key_bindings_info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (retval);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_list_free(struct cmd_list *cmdlist)
|
cmd_list_free(struct cmd_list *cmdlist)
|
||||||
{
|
{
|
||||||
struct cmd *cmd, *cmd1;
|
struct cmd *cmd;
|
||||||
|
|
||||||
if (--cmdlist->references != 0)
|
if (--cmdlist->references != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TAILQ_FOREACH_SAFE(cmd, &cmdlist->list, qentry, cmd1) {
|
while (!TAILQ_EMPTY(&cmdlist->list)) {
|
||||||
|
cmd = TAILQ_FIRST(&cmdlist->list);
|
||||||
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
||||||
args_free(cmd->args);
|
cmd_free(cmd);
|
||||||
free(cmd->file);
|
|
||||||
free(cmd);
|
|
||||||
}
|
}
|
||||||
|
xfree(cmdlist);
|
||||||
free(cmdlist);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
|
cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
struct cmd *cmd;
|
struct cmd *cmd;
|
||||||
size_t off, used;
|
size_t off;
|
||||||
|
|
||||||
off = 0;
|
off = 0;
|
||||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
@@ -112,12 +143,8 @@ cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
|
|||||||
off += cmd_print(cmd, buf + off, len - off);
|
off += cmd_print(cmd, buf + off, len - off);
|
||||||
if (off >= len)
|
if (off >= len)
|
||||||
break;
|
break;
|
||||||
if (TAILQ_NEXT(cmd, qentry) != NULL) {
|
if (TAILQ_NEXT(cmd, qentry) != NULL)
|
||||||
used = xsnprintf(buf + off, len - off, " ; ");
|
off += xsnprintf(buf + off, len - off, " ; ");
|
||||||
if (used > len - off)
|
|
||||||
used = len - off;
|
|
||||||
off += used;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (off);
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -28,61 +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_q *);
|
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,
|
||||||
cmd_load_buffer_exec
|
cmd_buffer_parse,
|
||||||
|
cmd_load_buffer_exec,
|
||||||
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
struct cmd_load_buffer_cdata {
|
||||||
cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
struct session *session;
|
||||||
|
int buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
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 = cmdq->client;
|
struct cmd_load_buffer_cdata *cdata;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
FILE *f;
|
struct client *c = ctx->cmdclient;
|
||||||
const char *path, *bufname;
|
FILE *f;
|
||||||
char *pdata, *new_pdata, *cause;
|
char *pdata, *new_pdata;
|
||||||
size_t psize;
|
size_t psize;
|
||||||
int ch, error, cwd, fd;
|
u_int limit;
|
||||||
|
int ch;
|
||||||
|
|
||||||
bufname = NULL;
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
if (args_has(args, 'b'))
|
return (-1);
|
||||||
bufname = args_get(args, 'b');
|
|
||||||
|
|
||||||
path = args->argv[0];
|
if (strcmp(data->arg, "-") == 0) {
|
||||||
if (strcmp(path, "-") == 0) {
|
if (c == NULL) {
|
||||||
error = server_set_stdin_callback(c, cmd_load_buffer_callback,
|
ctx->error(ctx, "%s: can't read from stdin", data->arg);
|
||||||
(void *)bufname, &cause);
|
return (-1);
|
||||||
if (error != 0) {
|
|
||||||
cmdq_error(cmdq, "%s: %s", path, cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
return (CMD_RETURN_WAIT);
|
if (c->flags & CLIENT_TERMINAL) {
|
||||||
|
ctx->error(ctx, "%s: stdin is a tty", data->arg);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
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 && c->session == NULL)
|
if ((f = fopen(data->arg, "rb")) == NULL) {
|
||||||
cwd = c->cwd;
|
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||||
else if ((s = cmd_find_current(cmdq)) != NULL)
|
return (-1);
|
||||||
cwd = s->cwd;
|
|
||||||
else
|
|
||||||
cwd = AT_FDCWD;
|
|
||||||
|
|
||||||
if ((fd = openat(cwd, path, O_RDONLY)) == -1 ||
|
|
||||||
(f = fdopen(fd, "rb")) == NULL) {
|
|
||||||
if (fd != -1)
|
|
||||||
close(fd);
|
|
||||||
cmdq_error(cmdq, "%s: %s", path, strerror(errno));
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pdata = NULL;
|
pdata = NULL;
|
||||||
@@ -90,68 +101,85 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
while ((ch = getc(f)) != EOF) {
|
while ((ch = getc(f)) != EOF) {
|
||||||
/* Do not let the server die due to memory exhaustion. */
|
/* Do not let the server die due to memory exhaustion. */
|
||||||
if ((new_pdata = realloc(pdata, psize + 2)) == NULL) {
|
if ((new_pdata = realloc(pdata, psize + 2)) == NULL) {
|
||||||
cmdq_error(cmdq, "realloc error: %s", strerror(errno));
|
ctx->error(ctx, "realloc error: %s", strerror(errno));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
pdata = new_pdata;
|
pdata = new_pdata;
|
||||||
pdata[psize++] = ch;
|
pdata[psize++] = ch;
|
||||||
}
|
}
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
cmdq_error(cmdq, "%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;
|
||||||
|
|
||||||
if (paste_set(pdata, psize, bufname, &cause) != 0) {
|
limit = options_get_number(&s->options, "buffer-limit");
|
||||||
cmdq_error(cmdq, "%s", cause);
|
if (data->buffer == -1) {
|
||||||
free(pdata);
|
paste_add(&s->buffers, pdata, psize, limit);
|
||||||
free(cause);
|
return (0);
|
||||||
return (CMD_RETURN_ERROR);
|
}
|
||||||
|
if (paste_replace(&s->buffers, data->buffer, pdata, psize) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
const char *bufname = data;
|
struct cmd_load_buffer_cdata *cdata = data;
|
||||||
char *pdata, *cause;
|
struct session *s = cdata->session;
|
||||||
size_t psize;
|
char *pdata;
|
||||||
|
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->flags |= CLIENT_EXIT;
|
||||||
|
|
||||||
server_client_unref(c);
|
/* Does the target session still exist? */
|
||||||
if (c->flags & CLIENT_DEAD)
|
if (!session_alive(s))
|
||||||
return;
|
|
||||||
|
|
||||||
psize = EVBUFFER_LENGTH(c->stdin_data);
|
|
||||||
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL)
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
memcpy(pdata, EVBUFFER_DATA(c->stdin_data), psize);
|
psize = EVBUFFER_LENGTH(c->stdin_event->input);
|
||||||
pdata[psize] = '\0';
|
if (psize == 0)
|
||||||
evbuffer_drain(c->stdin_data, psize);
|
goto out;
|
||||||
|
|
||||||
if (paste_set(pdata, psize, bufname, &cause) != 0) {
|
pdata = malloc(psize + 1);
|
||||||
|
if (pdata == NULL)
|
||||||
|
goto out;
|
||||||
|
bufferevent_read(c->stdin_event, pdata, psize);
|
||||||
|
pdata[psize] = '\0';
|
||||||
|
|
||||||
|
limit = options_get_number(&s->options, "buffer-limit");
|
||||||
|
if (cdata->buffer == -1) {
|
||||||
|
paste_add(&s->buffers, pdata, psize, limit);
|
||||||
|
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, "%s", cause);
|
evbuffer_add_printf(
|
||||||
server_push_stderr(c);
|
c->stderr_event->output, "no buffer %d\n", cdata->buffer);
|
||||||
free(pdata);
|
bufferevent_enable(c->stderr_event, EV_WRITE);
|
||||||
free(cause);
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
cmdq_continue(c->cmdq);
|
cdata->session->references--;
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
53
cmd-lock-client.c
Normal file
53
cmd-lock-client.c
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* $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>
|
||||||
|
*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lock a single client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_lock_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_lock_client_entry = {
|
||||||
|
"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)
|
||||||
|
{
|
||||||
|
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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -18,59 +18,35 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lock commands.
|
* Lock server.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_q *);
|
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, "",
|
||||||
cmd_lock_server_exec
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_lock_server_exec,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_lock_session_entry = {
|
/* ARGSUSED */
|
||||||
"lock-session", "locks",
|
int
|
||||||
"t:", 0, 0,
|
cmd_lock_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
CMD_TARGET_SESSION_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_lock_server_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_lock_client_entry = {
|
|
||||||
"lock-client", "lockc",
|
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_CLIENT_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_lock_server_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_lock_server_exec(struct cmd *self, unused struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
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) {
|
|
||||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
server_lock_session(s);
|
|
||||||
} else {
|
|
||||||
c = cmd_find_client(cmdq, args_get(args, 't'), 0);
|
|
||||||
if (c == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
server_lock_client(c);
|
|
||||||
}
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
53
cmd-lock-session.c
Normal file
53
cmd-lock-session.c
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* $Id: cmd-lock-session.c,v 1.2 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lock all clients attached to a session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_lock_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_lock_session_entry = {
|
||||||
|
"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)
|
||||||
|
{
|
||||||
|
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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,79 +26,42 @@
|
|||||||
* Move a window.
|
* Move a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_q *);
|
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",
|
||||||
"adkrs:t:", 0, 0,
|
|
||||||
"[-dkr] " CMD_SRCDST_WINDOW_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_move_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_link_window_entry = {
|
|
||||||
"link-window", "linkw",
|
|
||||||
"adks:t:", 0, 0,
|
|
||||||
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
0,
|
0, "dk",
|
||||||
cmd_move_window_exec
|
cmd_srcdst_init,
|
||||||
|
cmd_srcdst_parse,
|
||||||
|
cmd_move_window_exec,
|
||||||
|
cmd_srcdst_free,
|
||||||
|
cmd_srcdst_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
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, sflag;
|
int idx, kflag, dflag;
|
||||||
|
|
||||||
if (args_has(args, 'r')) {
|
if ((wl = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
return (-1);
|
||||||
if (s == NULL)
|
if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
session_renumber_windows(s);
|
kflag = cmd_check_flag(data->chflags, 'k');
|
||||||
recalculate_sizes();
|
dflag = cmd_check_flag(data->chflags, 'd');
|
||||||
|
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||||
return (CMD_RETURN_NORMAL);
|
ctx->error(ctx, "can't move window: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
server_unlink_window(src, wl);
|
||||||
if ((wl = cmd_find_window(cmdq, args_get(args, 's'), &src)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst)) == -2)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
kflag = args_has(self->args, 'k');
|
|
||||||
dflag = args_has(self->args, 'd');
|
|
||||||
sflag = args_has(self->args, 's');
|
|
||||||
|
|
||||||
if (args_has(self->args, 'a')) {
|
|
||||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
if ((idx = winlink_shuffle_up(s, s->curw)) == -1)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (server_link_window(src, wl, dst, idx, kflag, !dflag,
|
|
||||||
&cause) != 0) {
|
|
||||||
cmdq_error(cmdq, "can't link window: %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (self->entry == &cmd_move_window_entry)
|
|
||||||
server_unlink_window(src, wl);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Renumber the winlinks in the src session only, the destination
|
|
||||||
* session already has the correct winlink id to us, either
|
|
||||||
* automatically or specified by -s.
|
|
||||||
*/
|
|
||||||
if (!sflag && options_get_number(&src->options, "renumber-windows"))
|
|
||||||
session_renumber_windows(src);
|
|
||||||
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -18,9 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <pwd.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -31,171 +29,196 @@
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define NEW_SESSION_TEMPLATE "#{session_name}:"
|
int cmd_new_session_parse(struct cmd *, int, char **, char **);
|
||||||
|
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);
|
||||||
|
|
||||||
enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
|
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",
|
||||||
"Ac:dDEF:n:Ps:t:x:y:", 0, -1,
|
"[-d] [-n window-name] [-s session-name] [-t target-session] [command]",
|
||||||
"[-AdDEP] [-c start-directory] [-F format] [-n window-name] "
|
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON, "",
|
||||||
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
|
cmd_new_session_init,
|
||||||
"[-y height] [command]",
|
cmd_new_session_parse,
|
||||||
CMD_STARTSERVER,
|
cmd_new_session_exec,
|
||||||
cmd_new_session_exec
|
cmd_new_session_free,
|
||||||
|
cmd_new_session_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_has_session_entry = {
|
/* ARGSUSED */
|
||||||
"has-session", "has",
|
void
|
||||||
"t:", 0, 0,
|
cmd_new_session_init(struct cmd *self, unused int arg)
|
||||||
CMD_TARGET_SESSION_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_new_session_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_new_session_data *data;
|
||||||
struct client *c = cmdq->client, *c0;
|
|
||||||
struct session *s, *groupwith;
|
|
||||||
struct window *w;
|
|
||||||
struct environ env;
|
|
||||||
struct termios tio, *tiop;
|
|
||||||
const char *newname, *target, *update, *errstr, *template;
|
|
||||||
const char *path;
|
|
||||||
char **argv, *cmd, *cause, *cp;
|
|
||||||
int detached, already_attached, idx, cwd, fd = -1;
|
|
||||||
int argc;
|
|
||||||
u_int sx, sy;
|
|
||||||
struct format_tree *ft;
|
|
||||||
struct environ_entry *envent;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_has_session_entry) {
|
self->data = data = xmalloc(sizeof *data);
|
||||||
if (cmd_find_session(cmdq, args_get(args, 't'), 0) == NULL)
|
data->flag_detached = 0;
|
||||||
return (CMD_RETURN_ERROR);
|
data->target = NULL;
|
||||||
return (CMD_RETURN_NORMAL);
|
data->newname = NULL;
|
||||||
}
|
data->winname = NULL;
|
||||||
|
data->cmd = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) {
|
int
|
||||||
cmdq_error(cmdq, "command or window name given with target");
|
cmd_new_session_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
return (CMD_RETURN_ERROR);
|
{
|
||||||
}
|
struct cmd_new_session_data *data;
|
||||||
|
int opt;
|
||||||
|
|
||||||
newname = args_get(args, 's');
|
self->entry->init(self, KEYC_NONE);
|
||||||
if (newname != NULL) {
|
data = self->data;
|
||||||
if (!session_check_name(newname)) {
|
|
||||||
cmdq_error(cmdq, "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;
|
||||||
if (args_has(args, 'A')) {
|
break;
|
||||||
return (cmd_attach_session(cmdq, newname,
|
case 's':
|
||||||
args_has(args, 'D'), 0, NULL,
|
if (data->newname == NULL)
|
||||||
args_has(args, 'E')));
|
data->newname = xstrdup(optarg);
|
||||||
}
|
break;
|
||||||
cmdq_error(cmdq, "duplicate session: %s", newname);
|
case 't':
|
||||||
return (CMD_RETURN_ERROR);
|
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(cmdq, target, 0);
|
|
||||||
if (groupwith == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
} else
|
|
||||||
groupwith = NULL;
|
|
||||||
|
|
||||||
/* Set -d if no client. */
|
if (argc == 1)
|
||||||
detached = args_has(args, 'd');
|
data->cmd = xstrdup(argv[0]);
|
||||||
if (c == NULL)
|
|
||||||
detached = 1;
|
|
||||||
|
|
||||||
/* Is this client already attached? */
|
return (0);
|
||||||
already_attached = 0;
|
|
||||||
if (c != NULL && c->session != NULL)
|
|
||||||
already_attached = 1;
|
|
||||||
|
|
||||||
/* Get the new session working directory. */
|
usage:
|
||||||
if (args_has(args, 'c')) {
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
ft = format_create();
|
|
||||||
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), NULL, NULL,
|
|
||||||
NULL);
|
|
||||||
cp = format_expand(ft, args_get(args, 'c'));
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
if (cp != NULL && *cp != '\0') {
|
self->entry->free(self);
|
||||||
fd = open(cp, O_RDONLY|O_DIRECTORY);
|
return (-1);
|
||||||
free(cp);
|
}
|
||||||
if (fd == -1) {
|
|
||||||
cmdq_error(cmdq, "bad working directory: %s",
|
int
|
||||||
strerror(errno));
|
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
return (CMD_RETURN_ERROR);
|
{
|
||||||
}
|
struct cmd_new_session_data *data = self->data;
|
||||||
} else if (cp != NULL)
|
struct session *s, *old_s, *groupwith;
|
||||||
free(cp);
|
struct window *w;
|
||||||
cwd = fd;
|
struct window_pane *wp;
|
||||||
} else if (c != NULL && c->session == NULL)
|
struct environ env;
|
||||||
cwd = c->cwd;
|
struct termios tio, *tiop;
|
||||||
else if ((c0 = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
struct passwd *pw;
|
||||||
cwd = c0->session->cwd;
|
const char *update, *cwd;
|
||||||
else {
|
char *overrides, *cmd, *cause;
|
||||||
fd = open(".", O_RDONLY);
|
int detached, idx;
|
||||||
cwd = fd;
|
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);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this is a new client, check for nesting and save the termios
|
* There are three cases:
|
||||||
* settings (part of which is used for new windows in this session).
|
|
||||||
*
|
*
|
||||||
* tcgetattr() is used rather than using tty.tio since if the client is
|
* 1. If cmdclient is non-NULL, new-session has been called from the
|
||||||
* detached, tty_open won't be called. It must be done before opening
|
* command-line - cmdclient is to become a new attached, interactive
|
||||||
* the terminal as that calls tcsetattr() to prepare for tmux taking
|
* client. Unless -d is given, the terminal must be opened and then
|
||||||
* over.
|
* the client sent MSG_READY.
|
||||||
|
*
|
||||||
|
* 2. If cmdclient is NULL, new-session has been called from an
|
||||||
|
* existing client (such as a key binding).
|
||||||
|
*
|
||||||
|
* 3. Both are NULL, the command was in the configuration file. Treat
|
||||||
|
* this as if -d was given even if it was not.
|
||||||
|
*
|
||||||
|
* In all cases, a new additional session needs to be created and
|
||||||
|
* (unless -d) set as the current session for the client.
|
||||||
*/
|
*/
|
||||||
if (!detached && !already_attached && c->tty.fd != -1) {
|
|
||||||
if (server_client_check_nested(cmdq->client)) {
|
/* Set -d if no client. */
|
||||||
cmdq_error(cmdq, "sessions should be nested with care, "
|
detached = data->flag_detached;
|
||||||
"unset $TMUX to force");
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
detached = 1;
|
||||||
}
|
|
||||||
if (tcgetattr(c->tty.fd, &tio) != 0)
|
/*
|
||||||
|
* Save the termios settings, part of which is used for new windows in
|
||||||
|
* this session.
|
||||||
|
*
|
||||||
|
* This is read again with tcgetattr() rather than using tty.tio as if
|
||||||
|
* detached, tty_open won't be called. Because of this, it must be done
|
||||||
|
* before opening the terminal as that calls tcsetattr() to prepare for
|
||||||
|
* tmux taking over.
|
||||||
|
*/
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->tty.fd != -1) {
|
||||||
|
if (tcgetattr(ctx->cmdclient->tty.fd, &tio) != 0)
|
||||||
fatal("tcgetattr failed");
|
fatal("tcgetattr failed");
|
||||||
tiop = &tio;
|
tiop = &tio;
|
||||||
} else
|
} else
|
||||||
tiop = NULL;
|
tiop = NULL;
|
||||||
|
|
||||||
/* Open the terminal if necessary. */
|
/* Open the terminal if necessary. */
|
||||||
if (!detached && !already_attached) {
|
if (!detached && ctx->cmdclient != NULL) {
|
||||||
if (server_client_open(c, &cause) != 0) {
|
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||||
cmdq_error(cmdq, "open terminal failed: %s", cause);
|
ctx->error(ctx, "not a terminal");
|
||||||
free(cause);
|
return (-1);
|
||||||
goto error;
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the new session working directory. */
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
|
cwd = ctx->cmdclient->cwd;
|
||||||
|
else {
|
||||||
|
pw = getpwuid(getuid());
|
||||||
|
if (pw->pw_dir != NULL && *pw->pw_dir != '\0')
|
||||||
|
cwd = pw->pw_dir;
|
||||||
|
else
|
||||||
|
cwd = "/";
|
||||||
|
}
|
||||||
|
|
||||||
/* Find new session size. */
|
/* Find new session size. */
|
||||||
if (c != NULL) {
|
if (detached) {
|
||||||
sx = c->tty.sx;
|
|
||||||
sy = c->tty.sy;
|
|
||||||
} else {
|
|
||||||
sx = 80;
|
sx = 80;
|
||||||
sy = 24;
|
sy = 24;
|
||||||
}
|
} else if (ctx->cmdclient != NULL) {
|
||||||
if (detached && args_has(args, 'x')) {
|
sx = ctx->cmdclient->tty.sx;
|
||||||
sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr);
|
sy = ctx->cmdclient->tty.sy;
|
||||||
if (errstr != NULL) {
|
} else {
|
||||||
cmdq_error(cmdq, "width %s", errstr);
|
sx = ctx->curclient->tty.sx;
|
||||||
goto error;
|
sy = ctx->curclient->tty.sy;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (detached && args_has(args, 'y')) {
|
|
||||||
sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(cmdq, "height %s", errstr);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (sy > 0 && options_get_number(&global_s_options, "status"))
|
if (sy > 0 && options_get_number(&global_s_options, "status"))
|
||||||
sy--;
|
sy--;
|
||||||
@@ -205,53 +228,37 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
sy = 1;
|
sy = 1;
|
||||||
|
|
||||||
/* Figure out the command for the new window. */
|
/* Figure out the command for the new window. */
|
||||||
argc = -1;
|
if (data->target != NULL)
|
||||||
argv = NULL;
|
cmd = NULL;
|
||||||
if (target == NULL && args->argc != 0) {
|
else if (data->cmd != NULL)
|
||||||
argc = args->argc;
|
cmd = data->cmd;
|
||||||
argv = args->argv;
|
|
||||||
} else if (target == NULL) {
|
|
||||||
cmd = options_get_string(&global_s_options, "default-command");
|
|
||||||
if (cmd != NULL && *cmd != '\0') {
|
|
||||||
argc = 1;
|
|
||||||
argv = &cmd;
|
|
||||||
} else {
|
|
||||||
argc = 0;
|
|
||||||
argv = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
path = NULL;
|
|
||||||
if (c != NULL && c->session == NULL)
|
|
||||||
envent = environ_find(&c->environ, "PATH");
|
|
||||||
else
|
else
|
||||||
envent = environ_find(&global_environ, "PATH");
|
cmd = options_get_string(&global_s_options, "default-command");
|
||||||
if (envent != NULL)
|
|
||||||
path = envent->value;
|
|
||||||
|
|
||||||
/* Construct the environment. */
|
/* Construct the environment. */
|
||||||
environ_init(&env);
|
environ_init(&env);
|
||||||
if (c != NULL && !args_has(args, 'E')) {
|
update = options_get_string(&global_s_options, "update-environment");
|
||||||
update = options_get_string(&global_s_options,
|
if (ctx->cmdclient != NULL)
|
||||||
"update-environment");
|
environ_update(update, &ctx->cmdclient->environ, &env);
|
||||||
environ_update(update, &c->environ, &env);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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, argc, argv, path, cwd, &env, tiop, idx, sx,
|
s = session_create(
|
||||||
sy, &cause);
|
data->newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
cmdq_error(cmdq, "create session failed: %s", cause);
|
ctx->error(ctx, "create session failed: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
goto 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 (argc >= 0 && 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +269,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
if (groupwith != NULL) {
|
if (groupwith != NULL) {
|
||||||
session_group_add(groupwith, s);
|
session_group_add(groupwith, s);
|
||||||
session_group_synchronize_to(s);
|
session_group_synchronize_to(s);
|
||||||
session_select(s, RB_MIN(winlinks, &s->windows)->idx);
|
session_select(s, RB_ROOT(&s->windows)->idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -270,16 +277,21 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
* taking this session and needs to get MSG_READY and stay around.
|
* taking this session and needs to get MSG_READY and stay around.
|
||||||
*/
|
*/
|
||||||
if (!detached) {
|
if (!detached) {
|
||||||
if (!already_attached)
|
if (ctx->cmdclient != NULL) {
|
||||||
server_write_ready(c);
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
else if (c->session != NULL)
|
|
||||||
c->last_session = c->session;
|
old_s = ctx->cmdclient->session;
|
||||||
c->session = s;
|
if (old_s != NULL)
|
||||||
status_timer_start(c);
|
ctx->cmdclient->last_session = old_s;
|
||||||
notify_attached_session_changed(c);
|
ctx->cmdclient->session = s;
|
||||||
session_update_activity(s, NULL);
|
server_redraw_client(ctx->cmdclient);
|
||||||
gettimeofday(&s->last_attached_time, NULL);
|
} else {
|
||||||
server_redraw_client(c);
|
old_s = ctx->curclient->session;
|
||||||
|
if (old_s != NULL)
|
||||||
|
ctx->curclient->last_session = old_s;
|
||||||
|
ctx->curclient->session = s;
|
||||||
|
server_redraw_client(ctx->curclient);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
server_update_socket();
|
server_update_socket();
|
||||||
@@ -288,34 +300,53 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
* If there are still configuration file errors to display, put the new
|
* If there are still configuration file errors to display, put the new
|
||||||
* session's current window into more mode and display them now.
|
* session's current window into more mode and display them now.
|
||||||
*/
|
*/
|
||||||
if (cfg_finished)
|
if (cfg_finished && !ARRAY_EMPTY(&cfg_causes)) {
|
||||||
cfg_show_causes(s);
|
wp = s->curw->window->active;
|
||||||
|
window_pane_set_mode(wp, &window_copy_mode);
|
||||||
/* Print if requested. */
|
window_copy_init_for_output(wp);
|
||||||
if (args_has(args, 'P')) {
|
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
cause = ARRAY_ITEM(&cfg_causes, i);
|
||||||
template = NEW_SESSION_TEMPLATE;
|
window_copy_add(wp, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
ft = format_create();
|
}
|
||||||
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL,
|
ARRAY_FREE(&cfg_causes);
|
||||||
NULL);
|
|
||||||
|
|
||||||
cp = format_expand(ft, template);
|
|
||||||
cmdq_print(cmdq, "%s", cp);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!detached)
|
return (!detached); /* 1 means don't tell command client to exit */
|
||||||
cmdq->client_exit = 0;
|
}
|
||||||
|
|
||||||
if (fd != -1)
|
void
|
||||||
close(fd);
|
cmd_new_session_free(struct cmd *self)
|
||||||
return (CMD_RETURN_NORMAL);
|
{
|
||||||
|
struct cmd_new_session_data *data = self->data;
|
||||||
error:
|
|
||||||
if (fd != -1)
|
if (data->newname != NULL)
|
||||||
close(fd);
|
xfree(data->newname);
|
||||||
return (CMD_RETURN_ERROR);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
280
cmd-new-window.c
280
cmd-new-window.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -18,11 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -30,147 +26,211 @@
|
|||||||
* Create a new window.
|
* Create a new window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define NEW_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
int cmd_new_window_parse(struct cmd *, int, char **, char **);
|
||||||
|
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);
|
||||||
|
|
||||||
enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_q *);
|
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, "",
|
||||||
CMD_TARGET_WINDOW_USAGE " [command]",
|
cmd_new_window_init,
|
||||||
0,
|
cmd_new_window_parse,
|
||||||
cmd_new_window_exec
|
cmd_new_window_exec,
|
||||||
|
cmd_new_window_free,
|
||||||
|
cmd_new_window_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
void
|
||||||
|
cmd_new_window_init(struct cmd *self, unused int arg)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_new_window_data *data;
|
||||||
struct session *s;
|
|
||||||
struct winlink *wl;
|
|
||||||
const char *cmd, *path, *template;
|
|
||||||
char **argv, *cause, *cp;
|
|
||||||
int argc, idx, detached, cwd, fd = -1;
|
|
||||||
struct format_tree *ft;
|
|
||||||
struct environ_entry *envent;
|
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
self->data = data = xmalloc(sizeof *data);
|
||||||
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
|
data->target = NULL;
|
||||||
if (wl == NULL)
|
data->name = NULL;
|
||||||
return (CMD_RETURN_ERROR);
|
data->cmd = NULL;
|
||||||
if ((idx = winlink_shuffle_up(s, wl)) == -1) {
|
data->flag_insert_after = 0;
|
||||||
cmdq_error(cmdq, "no free window indexes");
|
data->flag_detached = 0;
|
||||||
return (CMD_RETURN_ERROR);
|
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)
|
||||||
|
{
|
||||||
|
struct cmd_new_window_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
char *cmd, *cwd, *cause;
|
||||||
|
int idx, last;
|
||||||
|
|
||||||
|
if (data == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (data->flag_insert_after) {
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
idx = wl->idx + 1;
|
||||||
|
|
||||||
|
/* Find the next free index. */
|
||||||
|
for (last = idx; last < INT_MAX; last++) {
|
||||||
|
if (winlink_find_by_index(&s->windows, last) == NULL)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (last == INT_MAX) {
|
||||||
|
ctx->error(ctx, "no free window indexes");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move everything from last - 1 to idx up a bit. */
|
||||||
|
for (; last > idx; last--) {
|
||||||
|
wl = winlink_find_by_index(&s->windows, last - 1);
|
||||||
|
server_link_window(s, wl, s, last, 0, 0, NULL);
|
||||||
|
server_unlink_window(s, wl);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
idx = cmd_find_index(cmdq, args_get(args, 't'), &s);
|
if ((idx = cmd_find_index(ctx, data->target, &s)) == -2)
|
||||||
if (idx == -2)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
detached = args_has(args, 'd');
|
|
||||||
|
|
||||||
if (args->argc == 0) {
|
|
||||||
cmd = options_get_string(&s->options, "default-command");
|
|
||||||
if (cmd != NULL && *cmd != '\0') {
|
|
||||||
argc = 1;
|
|
||||||
argv = (char **)&cmd;
|
|
||||||
} else {
|
|
||||||
argc = 0;
|
|
||||||
argv = NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
argc = args->argc;
|
|
||||||
argv = args->argv;
|
|
||||||
}
|
|
||||||
|
|
||||||
path = NULL;
|
|
||||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
|
||||||
envent = environ_find(&cmdq->client->environ, "PATH");
|
|
||||||
else
|
|
||||||
envent = environ_find(&s->environ, "PATH");
|
|
||||||
if (envent != NULL)
|
|
||||||
path = envent->value;
|
|
||||||
|
|
||||||
if (args_has(args, 'c')) {
|
|
||||||
ft = format_create();
|
|
||||||
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL,
|
|
||||||
NULL);
|
|
||||||
cp = format_expand(ft, args_get(args, 'c'));
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
if (cp != NULL && *cp != '\0') {
|
|
||||||
fd = open(cp, O_RDONLY|O_DIRECTORY);
|
|
||||||
free(cp);
|
|
||||||
if (fd == -1) {
|
|
||||||
cmdq_error(cmdq, "bad working directory: %s",
|
|
||||||
strerror(errno));
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
} else if (cp != NULL)
|
|
||||||
free(cp);
|
|
||||||
cwd = fd;
|
|
||||||
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
|
|
||||||
cwd = cmdq->client->cwd;
|
|
||||||
else
|
|
||||||
cwd = s->cwd;
|
|
||||||
|
|
||||||
wl = NULL;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd = data->cmd;
|
||||||
|
if (cmd == NULL)
|
||||||
|
cmd = options_get_string(&s->options, "default-command");
|
||||||
|
cwd = options_get_string(&s->options, "default-path");
|
||||||
|
if (*cwd == '\0') {
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
|
cwd = ctx->cmdclient->cwd;
|
||||||
|
else
|
||||||
|
cwd = s->cwd;
|
||||||
|
}
|
||||||
|
|
||||||
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'), argc, argv, path, cwd, idx,
|
wl = session_new(s, data->name, cmd, cwd, idx, &cause);
|
||||||
&cause);
|
|
||||||
if (wl == NULL) {
|
if (wl == NULL) {
|
||||||
cmdq_error(cmdq, "create window failed: %s", cause);
|
ctx->error(ctx, "create window failed: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
goto 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)
|
||||||
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, wl,
|
{
|
||||||
NULL);
|
struct cmd_new_window_data *data = self->data;
|
||||||
|
|
||||||
cp = format_expand(ft, template);
|
if (data->target != NULL)
|
||||||
cmdq_print(cmdq, "%s", cp);
|
xfree(data->target);
|
||||||
free(cp);
|
if (data->name != NULL)
|
||||||
|
xfree(data->name);
|
||||||
format_free(ft);
|
if (data->cmd != NULL)
|
||||||
}
|
xfree(data->cmd);
|
||||||
|
xfree(data);
|
||||||
if (fd != -1)
|
}
|
||||||
close(fd);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
size_t
|
||||||
|
cmd_new_window_print(struct cmd *self, char *buf, size_t len)
|
||||||
error:
|
{
|
||||||
if (fd != -1)
|
struct cmd_new_window_data *data = self->data;
|
||||||
close(fd);
|
size_t off = 0;
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,82 +27,196 @@
|
|||||||
* Paste paste buffer if present.
|
* Paste paste buffer if present.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_q *);
|
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);
|
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] " CMD_BUFFER_USAGE " " CMD_TARGET_PANE_USAGE,
|
0, "",
|
||||||
0,
|
cmd_paste_buffer_init,
|
||||||
cmd_paste_buffer_exec
|
cmd_paste_buffer_parse,
|
||||||
|
cmd_paste_buffer_exec,
|
||||||
|
cmd_paste_buffer_free,
|
||||||
|
cmd_paste_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
void
|
||||||
|
cmd_paste_buffer_init(struct cmd *self, unused int arg)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_paste_buffer_data *data;
|
||||||
struct window_pane *wp;
|
|
||||||
struct session *s;
|
|
||||||
struct paste_buffer *pb;
|
|
||||||
const char *sepstr, *bufname, *bufdata, *bufend, *line;
|
|
||||||
size_t seplen, bufsize;
|
|
||||||
int bracket = args_has(args, 'p');
|
|
||||||
|
|
||||||
if (cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp) == NULL)
|
self->data = data = xmalloc(sizeof *data);
|
||||||
return (CMD_RETURN_ERROR);
|
data->target = NULL;
|
||||||
|
data->buffer = -1;
|
||||||
bufname = NULL;
|
data->flag_delete = 0;
|
||||||
if (args_has(args, 'b'))
|
data->sepstr = xstrdup("\r");
|
||||||
bufname = args_get(args, 'b');
|
}
|
||||||
|
|
||||||
if (bufname == NULL)
|
int
|
||||||
pb = paste_get_top(NULL);
|
cmd_paste_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
else {
|
{
|
||||||
pb = paste_get_name(bufname);
|
struct cmd_paste_buffer_data *data;
|
||||||
if (pb == NULL) {
|
int opt, n;
|
||||||
cmdq_error(cmdq, "no buffer %s", bufname);
|
const char *errstr;
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
cmd_paste_buffer_init(self, 0);
|
||||||
}
|
data = self->data;
|
||||||
|
|
||||||
if (pb != NULL && ~wp->flags & PANE_INPUTOFF) {
|
while ((opt = getopt(argc, argv, "b:ds:t:r")) != -1) {
|
||||||
sepstr = args_get(args, 's');
|
switch (opt) {
|
||||||
if (sepstr == NULL) {
|
case 'b':
|
||||||
if (args_has(args, 'r'))
|
if (data->buffer == -1) {
|
||||||
sepstr = "\n";
|
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
else
|
if (errstr != NULL) {
|
||||||
sepstr = "\r";
|
xasprintf(cause, "buffer %s", errstr);
|
||||||
}
|
goto error;
|
||||||
seplen = strlen(sepstr);
|
}
|
||||||
|
data->buffer = n;
|
||||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
}
|
||||||
bufferevent_write(wp->event, "\033[200~", 6);
|
break;
|
||||||
|
case 'd':
|
||||||
bufdata = paste_buffer_data(pb, &bufsize);
|
data->flag_delete = 1;
|
||||||
bufend = bufdata + bufsize;
|
break;
|
||||||
|
case 's':
|
||||||
for (;;) {
|
if (data->sepstr != NULL)
|
||||||
line = memchr(bufdata, '\n', bufend - bufdata);
|
xfree(data->sepstr);
|
||||||
if (line == NULL)
|
data->sepstr = xstrdup(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
bufferevent_write(wp->event, bufdata, line - bufdata);
|
if (data->target == NULL)
|
||||||
bufferevent_write(wp->event, sepstr, seplen);
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
bufdata = line + 1;
|
case 'r':
|
||||||
}
|
if (data->sepstr != NULL)
|
||||||
if (bufdata != bufend)
|
xfree(data->sepstr);
|
||||||
bufferevent_write(wp->event, bufdata, bufend - bufdata);
|
data->sepstr = xstrdup("\n");
|
||||||
|
break;
|
||||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
default:
|
||||||
bufferevent_write(wp->event, "\033[201~", 6);
|
goto usage;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (pb != NULL && args_has(args, 'd'))
|
argc -= optind;
|
||||||
paste_free(pb);
|
argv += optind;
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_paste_buffer_data *data = self->data;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct session *s;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, &s, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (data->buffer == -1)
|
||||||
|
pb = paste_get_top(&s->buffers);
|
||||||
|
else {
|
||||||
|
if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pb != NULL)
|
||||||
|
cmd_paste_buffer_filter(wp, pb->data, pb->size, data->sepstr);
|
||||||
|
|
||||||
|
/* Delete the buffer if -d. */
|
||||||
|
if (data->flag_delete) {
|
||||||
|
if (data->buffer == -1)
|
||||||
|
paste_free_top(&s->buffers);
|
||||||
|
else
|
||||||
|
paste_free_index(&s->buffers, data->buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add bytes to a buffer and filter '\n' according to separator. */
|
||||||
|
void
|
||||||
|
cmd_paste_buffer_filter(
|
||||||
|
struct window_pane *wp, const char *data, size_t size, char *sep)
|
||||||
|
{
|
||||||
|
const char *end = data + size;
|
||||||
|
const char *lf;
|
||||||
|
size_t seplen;
|
||||||
|
|
||||||
|
seplen = strlen(sep);
|
||||||
|
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
||||||
|
if (lf != data)
|
||||||
|
bufferevent_write(wp->event, data, lf - data);
|
||||||
|
bufferevent_write(wp->event, sep, seplen);
|
||||||
|
data = lf + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end != data)
|
||||||
|
bufferevent_write(wp->event, data, end - data);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -32,33 +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_q *);
|
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,
|
||||||
cmd_pipe_pane_exec
|
cmd_target_parse,
|
||||||
|
cmd_pipe_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
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 session *s;
|
|
||||||
struct winlink *wl;
|
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
char *cmd;
|
char *command;
|
||||||
int old_fd, pipe_fd[2], null_fd;
|
int old_fd, pipe_fd[2], null_fd, mode;
|
||||||
struct format_tree *ft;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
|
if ((c = cmd_find_client(ctx, NULL)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
c = cmd_find_client(cmdq, NULL, 1);
|
|
||||||
|
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;
|
||||||
@@ -69,8 +70,8 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 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
|
||||||
@@ -78,28 +79,20 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
*
|
*
|
||||||
* 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) {
|
||||||
cmdq_error(cmdq, "socketpair error: %s", strerror(errno));
|
ctx->error(ctx, "socketpair error: %s", strerror(errno));
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Expand the command. */
|
|
||||||
ft = format_create();
|
|
||||||
format_defaults(ft, c, s, wl, wp);
|
|
||||||
cmd = format_expand_time(ft, args->argv[0], time(NULL));
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
/* Fork the child. */
|
/* Fork the child. */
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
cmdq_error(cmdq, "fork error: %s", strerror(errno));
|
ctx->error(ctx, "fork error: %s", strerror(errno));
|
||||||
|
return (-1);
|
||||||
free(cmd);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
case 0:
|
case 0:
|
||||||
/* Child process. */
|
/* Child process. */
|
||||||
close(pipe_fd[0]);
|
close(pipe_fd[0]);
|
||||||
@@ -120,7 +113,8 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
|
|
||||||
closefrom(STDERR_FILENO + 1);
|
closefrom(STDERR_FILENO + 1);
|
||||||
|
|
||||||
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
|
command = status_replace(c, NULL, data->arg, time(NULL), 0);
|
||||||
|
execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
default:
|
default:
|
||||||
/* Parent process. */
|
/* Parent process. */
|
||||||
@@ -133,13 +127,15 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
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)
|
||||||
|
fatal("fcntl failed");
|
||||||
free(cmd);
|
if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||||
return (CMD_RETURN_NORMAL);
|
fatal("fcntl failed");
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
void
|
void
|
||||||
cmd_pipe_pane_error_callback(
|
cmd_pipe_pane_error_callback(
|
||||||
unused struct bufferevent *bufev, unused short what, void *data)
|
unused struct bufferevent *bufev, unused short what, void *data)
|
||||||
|
|||||||
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);
|
||||||
|
}
|
||||||
269
cmd-queue.c
269
cmd-queue.c
@@ -1,269 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 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 <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
enum cmd_retval cmdq_continue_one(struct cmd_q *);
|
|
||||||
|
|
||||||
/* Create new command queue. */
|
|
||||||
struct cmd_q *
|
|
||||||
cmdq_new(struct client *c)
|
|
||||||
{
|
|
||||||
struct cmd_q *cmdq;
|
|
||||||
|
|
||||||
cmdq = xcalloc(1, sizeof *cmdq);
|
|
||||||
cmdq->references = 1;
|
|
||||||
cmdq->flags = 0;
|
|
||||||
|
|
||||||
cmdq->client = c;
|
|
||||||
cmdq->client_exit = -1;
|
|
||||||
|
|
||||||
TAILQ_INIT(&cmdq->queue);
|
|
||||||
cmdq->item = NULL;
|
|
||||||
cmdq->cmd = NULL;
|
|
||||||
|
|
||||||
return (cmdq);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Free command queue */
|
|
||||||
int
|
|
||||||
cmdq_free(struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
if (--cmdq->references != 0) {
|
|
||||||
if (cmdq->flags & CMD_Q_DEAD)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdq_flush(cmdq);
|
|
||||||
free(cmdq);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Show message from command. */
|
|
||||||
void
|
|
||||||
cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
struct client *c = cmdq->client;
|
|
||||||
struct window *w;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
|
|
||||||
if (c == NULL)
|
|
||||||
/* nothing */;
|
|
||||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
|
||||||
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
|
|
||||||
|
|
||||||
evbuffer_add(c->stdout_data, "\n", 1);
|
|
||||||
server_push_stdout(c);
|
|
||||||
} else {
|
|
||||||
w = c->session->curw->window;
|
|
||||||
if (w->active->mode != &window_copy_mode) {
|
|
||||||
window_pane_reset_mode(w->active);
|
|
||||||
window_pane_set_mode(w->active, &window_copy_mode);
|
|
||||||
window_copy_init_for_output(w->active);
|
|
||||||
}
|
|
||||||
window_copy_vadd(w->active, fmt, ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Show error from command. */
|
|
||||||
void
|
|
||||||
cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
struct client *c = cmdq->client;
|
|
||||||
struct cmd *cmd = cmdq->cmd;
|
|
||||||
va_list ap;
|
|
||||||
char *msg;
|
|
||||||
size_t msglen;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
msglen = xvasprintf(&msg, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (c == NULL)
|
|
||||||
cfg_add_cause("%s:%u: %s", cmd->file, cmd->line, msg);
|
|
||||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
|
||||||
evbuffer_add(c->stderr_data, msg, msglen);
|
|
||||||
evbuffer_add(c->stderr_data, "\n", 1);
|
|
||||||
|
|
||||||
server_push_stderr(c);
|
|
||||||
c->retval = 1;
|
|
||||||
} else {
|
|
||||||
*msg = toupper((u_char) *msg);
|
|
||||||
status_message_set(c, "%s", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print a guard line. */
|
|
||||||
void
|
|
||||||
cmdq_guard(struct cmd_q *cmdq, const char *guard, int flags)
|
|
||||||
{
|
|
||||||
struct client *c = cmdq->client;
|
|
||||||
|
|
||||||
if (c == NULL || !(c->flags & CLIENT_CONTROL))
|
|
||||||
return;
|
|
||||||
|
|
||||||
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard,
|
|
||||||
(long) cmdq->time, cmdq->number, flags);
|
|
||||||
server_push_stdout(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add command list to queue and begin processing if needed. */
|
|
||||||
void
|
|
||||||
cmdq_run(struct cmd_q *cmdq, struct cmd_list *cmdlist, struct mouse_event *m)
|
|
||||||
{
|
|
||||||
cmdq_append(cmdq, cmdlist, m);
|
|
||||||
|
|
||||||
if (cmdq->item == NULL) {
|
|
||||||
cmdq->cmd = NULL;
|
|
||||||
cmdq_continue(cmdq);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add command list to queue. */
|
|
||||||
void
|
|
||||||
cmdq_append(struct cmd_q *cmdq, struct cmd_list *cmdlist, struct mouse_event *m)
|
|
||||||
{
|
|
||||||
struct cmd_q_item *item;
|
|
||||||
|
|
||||||
item = xcalloc(1, sizeof *item);
|
|
||||||
item->cmdlist = cmdlist;
|
|
||||||
TAILQ_INSERT_TAIL(&cmdq->queue, item, qentry);
|
|
||||||
cmdlist->references++;
|
|
||||||
|
|
||||||
if (m != NULL)
|
|
||||||
memcpy(&item->mouse, m, sizeof item->mouse);
|
|
||||||
else
|
|
||||||
item->mouse.valid = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Process one command. */
|
|
||||||
enum cmd_retval
|
|
||||||
cmdq_continue_one(struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct cmd *cmd = cmdq->cmd;
|
|
||||||
enum cmd_retval retval;
|
|
||||||
char tmp[1024];
|
|
||||||
int flags = !!(cmd->flags & CMD_CONTROL);
|
|
||||||
|
|
||||||
cmd_print(cmd, tmp, sizeof tmp);
|
|
||||||
log_debug("cmdq %p: %s", cmdq, tmp);
|
|
||||||
|
|
||||||
cmdq->time = time(NULL);
|
|
||||||
cmdq->number++;
|
|
||||||
|
|
||||||
cmdq_guard(cmdq, "begin", flags);
|
|
||||||
|
|
||||||
retval = cmd->entry->exec(cmd, cmdq);
|
|
||||||
|
|
||||||
if (retval == CMD_RETURN_ERROR)
|
|
||||||
cmdq_guard(cmdq, "error", flags);
|
|
||||||
else
|
|
||||||
cmdq_guard(cmdq, "end", flags);
|
|
||||||
return (retval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Continue processing command queue. Returns 1 if finishes empty. */
|
|
||||||
int
|
|
||||||
cmdq_continue(struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct client *c = cmdq->client;
|
|
||||||
struct cmd_q_item *next;
|
|
||||||
enum cmd_retval retval;
|
|
||||||
int empty;
|
|
||||||
|
|
||||||
cmdq->references++;
|
|
||||||
notify_disable();
|
|
||||||
|
|
||||||
log_debug("continuing cmdq %p: flags=%#x, client=%d", cmdq, cmdq->flags,
|
|
||||||
c != NULL ? c->ibuf.fd : -1);
|
|
||||||
|
|
||||||
empty = TAILQ_EMPTY(&cmdq->queue);
|
|
||||||
if (empty)
|
|
||||||
goto empty;
|
|
||||||
|
|
||||||
if (cmdq->item == NULL) {
|
|
||||||
cmdq->item = TAILQ_FIRST(&cmdq->queue);
|
|
||||||
cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list);
|
|
||||||
} else
|
|
||||||
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
|
|
||||||
|
|
||||||
do {
|
|
||||||
while (cmdq->cmd != NULL) {
|
|
||||||
retval = cmdq_continue_one(cmdq);
|
|
||||||
if (retval == CMD_RETURN_ERROR)
|
|
||||||
break;
|
|
||||||
if (retval == CMD_RETURN_WAIT)
|
|
||||||
goto out;
|
|
||||||
if (retval == CMD_RETURN_STOP) {
|
|
||||||
cmdq_flush(cmdq);
|
|
||||||
goto empty;
|
|
||||||
}
|
|
||||||
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
|
|
||||||
}
|
|
||||||
next = TAILQ_NEXT(cmdq->item, qentry);
|
|
||||||
|
|
||||||
TAILQ_REMOVE(&cmdq->queue, cmdq->item, qentry);
|
|
||||||
cmd_list_free(cmdq->item->cmdlist);
|
|
||||||
free(cmdq->item);
|
|
||||||
|
|
||||||
cmdq->item = next;
|
|
||||||
if (cmdq->item != NULL)
|
|
||||||
cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list);
|
|
||||||
} while (cmdq->item != NULL);
|
|
||||||
|
|
||||||
empty:
|
|
||||||
if (cmdq->client_exit > 0)
|
|
||||||
cmdq->client->flags |= CLIENT_EXIT;
|
|
||||||
if (cmdq->emptyfn != NULL)
|
|
||||||
cmdq->emptyfn(cmdq);
|
|
||||||
empty = 1;
|
|
||||||
|
|
||||||
out:
|
|
||||||
notify_enable();
|
|
||||||
cmdq_free(cmdq);
|
|
||||||
|
|
||||||
return (empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Flush command queue. */
|
|
||||||
void
|
|
||||||
cmdq_flush(struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct cmd_q_item *item, *item1;
|
|
||||||
|
|
||||||
TAILQ_FOREACH_SAFE(item, &cmdq->queue, qentry, item1) {
|
|
||||||
TAILQ_REMOVE(&cmdq->queue, item, qentry);
|
|
||||||
cmd_list_free(item->cmdlist);
|
|
||||||
free(item);
|
|
||||||
}
|
|
||||||
cmdq->item = NULL;
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,54 +24,29 @@
|
|||||||
* Refresh client.
|
* Refresh client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_q *);
|
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",
|
||||||
"C:St:", 0, 0,
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
"[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
cmd_refresh_client_exec
|
cmd_target_parse,
|
||||||
|
cmd_refresh_client_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_refresh_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
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;
|
||||||
const char *size;
|
|
||||||
u_int w, h;
|
|
||||||
|
|
||||||
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (args_has(args, 'C')) {
|
server_redraw_client(c);
|
||||||
if ((size = args_get(args, 'C')) == NULL) {
|
|
||||||
cmdq_error(cmdq, "missing size");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (sscanf(size, "%u,%u", &w, &h) != 2) {
|
|
||||||
cmdq_error(cmdq, "bad size argument");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (w < PANE_MINIMUM || w > 5000 ||
|
|
||||||
h < PANE_MINIMUM || h > 5000) {
|
|
||||||
cmdq_error(cmdq, "size too small or too big");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (!(c->flags & CLIENT_CONTROL)) {
|
|
||||||
cmdq_error(cmdq, "not a control client");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (tty_set_size(&c->tty, w, h))
|
|
||||||
recalculate_sizes();
|
|
||||||
} else if (args_has(args, 'S')) {
|
|
||||||
c->flags |= CLIENT_STATUSFORCE;
|
|
||||||
server_status_client(c);
|
|
||||||
} else {
|
|
||||||
c->flags |= CLIENT_STATUSFORCE;
|
|
||||||
server_redraw_client(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,43 +26,39 @@
|
|||||||
* Change session name.
|
* Change session name.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_q *);
|
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, "",
|
||||||
cmd_rename_session_exec
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_rename_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_rename_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
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);
|
||||||
cmdq_error(cmdq, "bad session name: %s", newname);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (session_find(newname) != NULL) {
|
|
||||||
cmdq_error(cmdq, "duplicate session: %s", newname);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((s = cmd_find_session(cmdq, 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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,30 +26,34 @@
|
|||||||
* Rename a window.
|
* Rename a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_q *);
|
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, "",
|
||||||
cmd_rename_window_exec
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_rename_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_rename_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
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(cmdq, 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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,145 +26,86 @@
|
|||||||
* Increase or decrease pane size.
|
* Increase or decrease pane size.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *);
|
void cmd_resize_pane_init(struct cmd *, int);
|
||||||
|
int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
void cmd_resize_pane_mouse_update(struct client *, struct mouse_event *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_resize_pane_entry = {
|
const struct cmd_entry cmd_resize_pane_entry = {
|
||||||
"resize-pane", "resizep",
|
"resize-pane", "resizep",
|
||||||
"DLMRt:Ux:y:Z", 0, 1,
|
"[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||||
"[-DLMRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE
|
CMD_ARG01, "DLRU",
|
||||||
" [adjustment]",
|
cmd_resize_pane_init,
|
||||||
0,
|
cmd_target_parse,
|
||||||
cmd_resize_pane_exec
|
cmd_resize_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
void
|
||||||
cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
cmd_resize_pane_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data;
|
||||||
struct client *c = cmdq->client;
|
|
||||||
struct session *s;
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
if (key == (KEYC_UP | KEYC_CTRL))
|
||||||
|
cmd_set_flag(&data->chflags, 'U');
|
||||||
|
if (key == (KEYC_DOWN | KEYC_CTRL))
|
||||||
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
|
if (key == (KEYC_LEFT | KEYC_CTRL))
|
||||||
|
cmd_set_flag(&data->chflags, 'L');
|
||||||
|
if (key == (KEYC_RIGHT | KEYC_CTRL))
|
||||||
|
cmd_set_flag(&data->chflags, 'R');
|
||||||
|
|
||||||
|
if (key == (KEYC_UP | KEYC_ESCAPE)) {
|
||||||
|
cmd_set_flag(&data->chflags, 'U');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
if (key == (KEYC_DOWN | KEYC_ESCAPE)) {
|
||||||
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
if (key == (KEYC_LEFT | KEYC_ESCAPE)) {
|
||||||
|
cmd_set_flag(&data->chflags, 'L');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
if (key == (KEYC_RIGHT | KEYC_ESCAPE)) {
|
||||||
|
cmd_set_flag(&data->chflags, 'R');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct window *w;
|
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
char *cause;
|
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int adjust;
|
u_int adjust;
|
||||||
int x, y;
|
|
||||||
|
|
||||||
if (args_has(args, 'M')) {
|
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||||
if (cmd_mouse_window(&cmdq->item->mouse, &s) == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
if (c == NULL || c->session != s)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
c->tty.mouse_drag_update = cmd_resize_pane_mouse_update;
|
|
||||||
cmd_resize_pane_mouse_update(c, &cmdq->item->mouse);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
|
if (data->arg == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
w = wl->window;
|
|
||||||
|
|
||||||
if (args_has(args, 'Z')) {
|
|
||||||
if (w->flags & WINDOW_ZOOMED)
|
|
||||||
window_unzoom(w);
|
|
||||||
else
|
|
||||||
window_zoom(wp);
|
|
||||||
server_redraw_window(w);
|
|
||||||
server_status_window(w);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
server_unzoom_window(w);
|
|
||||||
|
|
||||||
if (args->argc == 0)
|
|
||||||
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) {
|
||||||
cmdq_error(cmdq, "adjustment %s", errstr);
|
ctx->error(ctx, "adjustment %s: %s", errstr, data->arg);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(self->args, 'x')) {
|
if (cmd_check_flag(data->chflags, 'L'))
|
||||||
x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX,
|
|
||||||
&cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(cmdq, "width %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
|
|
||||||
}
|
|
||||||
if (args_has(self->args, 'y')) {
|
|
||||||
y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX,
|
|
||||||
&cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(cmdq, "height %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
|
|
||||||
{
|
|
||||||
struct winlink *wl;
|
|
||||||
struct window_pane *wp;
|
|
||||||
int found;
|
|
||||||
u_int y, ly;
|
|
||||||
|
|
||||||
wl = cmd_mouse_window(m, NULL);
|
|
||||||
if (wl == NULL) {
|
|
||||||
c->tty.mouse_drag_update = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
y = m->y;
|
|
||||||
if (m->statusat == 0 && y > 0)
|
|
||||||
y--;
|
|
||||||
else if (m->statusat > 0 && y >= (u_int)m->statusat)
|
|
||||||
y = m->statusat - 1;
|
|
||||||
ly = m->ly;
|
|
||||||
if (m->statusat == 0 && ly > 0)
|
|
||||||
ly--;
|
|
||||||
else if (m->statusat > 0 && ly >= (u_int)m->statusat)
|
|
||||||
ly = m->statusat - 1;
|
|
||||||
|
|
||||||
found = 0;
|
|
||||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
|
||||||
if (!window_pane_visible(wp))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (wp->xoff + wp->sx == m->lx &&
|
|
||||||
wp->yoff <= 1 + ly && wp->yoff + wp->sy >= ly) {
|
|
||||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, m->x - m->lx);
|
|
||||||
found = 1;
|
|
||||||
}
|
|
||||||
if (wp->yoff + wp->sy == ly &&
|
|
||||||
wp->xoff <= 1 + m->lx && wp->xoff + wp->sx >= m->lx) {
|
|
||||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, y - ly);
|
|
||||||
found = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found)
|
|
||||||
server_redraw_window(wl->window);
|
|
||||||
else
|
|
||||||
c->tty.mouse_drag_update = NULL;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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_q *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_respawn_pane_entry = {
|
|
||||||
"respawn-pane", "respawnp",
|
|
||||||
"kt:", 0, -1,
|
|
||||||
"[-k] " CMD_TARGET_PANE_USAGE " [command]",
|
|
||||||
0,
|
|
||||||
cmd_respawn_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct winlink *wl;
|
|
||||||
struct window *w;
|
|
||||||
struct window_pane *wp;
|
|
||||||
struct session *s;
|
|
||||||
struct environ env;
|
|
||||||
const char *path;
|
|
||||||
char *cause;
|
|
||||||
u_int idx;
|
|
||||||
struct environ_entry *envent;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
w = wl->window;
|
|
||||||
|
|
||||||
if (!args_has(self->args, 'k') && wp->fd != -1) {
|
|
||||||
if (window_pane_index(wp, &idx) != 0)
|
|
||||||
fatalx("index not found");
|
|
||||||
cmdq_error(cmdq, "pane still active: %s:%d.%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);
|
|
||||||
|
|
||||||
path = NULL;
|
|
||||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
|
||||||
envent = environ_find(&cmdq->client->environ, "PATH");
|
|
||||||
else
|
|
||||||
envent = environ_find(&s->environ, "PATH");
|
|
||||||
if (envent != NULL)
|
|
||||||
path = envent->value;
|
|
||||||
|
|
||||||
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, -1, &env,
|
|
||||||
s->tio, &cause) != 0) {
|
|
||||||
cmdq_error(cmdq, "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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,40 +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_q *);
|
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",
|
||||||
cmd_respawn_window_exec
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_respawn_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
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 *path;
|
|
||||||
char *cause;
|
char *cause;
|
||||||
struct environ_entry *envent;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_window(cmdq, 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;
|
||||||
cmdq_error(cmdq,
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,32 +75,21 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
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 (window_pane_spawn(
|
||||||
path = NULL;
|
wp, data->arg, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||||
envent = environ_find(&cmdq->client->environ, "PATH");
|
xfree(cause);
|
||||||
else
|
|
||||||
envent = environ_find(&s->environ, "PATH");
|
|
||||||
if (envent != NULL)
|
|
||||||
path = envent->value;
|
|
||||||
|
|
||||||
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, -1, &env,
|
|
||||||
s->tio, &cause) != 0) {
|
|
||||||
cmdq_error(cmdq, "respawn window failed: %s", cause);
|
|
||||||
free(cause);
|
|
||||||
environ_free(&env);
|
environ_free(&env);
|
||||||
server_destroy_pane(wp);
|
server_destroy_pane(wp);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
layout_init(w, wp);
|
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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,31 +24,47 @@
|
|||||||
* Rotate the panes in a window.
|
* Rotate the panes in a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *);
|
void cmd_rotate_window_init(struct cmd *, int);
|
||||||
|
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_exec
|
cmd_rotate_window_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_rotate_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
void
|
||||||
cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
cmd_rotate_window_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
if (key == ('o' | KEYC_ESCAPE))
|
||||||
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
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(cmdq, 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);
|
||||||
@@ -104,5 +120,5 @@ cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
server_redraw_window(w);
|
server_redraw_window(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
137
cmd-run-shell.c
137
cmd-run-shell.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,117 +28,69 @@
|
|||||||
* Runs a command without a window.
|
* Runs a command without a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_q *);
|
int cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
void cmd_run_shell_callback(struct job *);
|
void cmd_run_shell_callback(struct job *);
|
||||||
void cmd_run_shell_free(void *);
|
void cmd_run_shell_free(void *);
|
||||||
void cmd_run_shell_print(struct job *, const char *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_run_shell_entry = {
|
const struct cmd_entry cmd_run_shell_entry = {
|
||||||
"run-shell", "run",
|
"run-shell", "run",
|
||||||
"bt:", 1, 1,
|
"command",
|
||||||
"[-b] " CMD_TARGET_PANE_USAGE " shell-command",
|
CMD_ARG1, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
cmd_run_shell_exec
|
cmd_target_parse,
|
||||||
|
cmd_run_shell_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_run_shell_data {
|
struct cmd_run_shell_data {
|
||||||
char *cmd;
|
char *cmd;
|
||||||
struct cmd_q *cmdq;
|
struct cmd_ctx ctx;
|
||||||
int bflag;
|
|
||||||
int wp_id;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
int
|
||||||
cmd_run_shell_print(struct job *job, const char *msg)
|
cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct cmd_run_shell_data *cdata = job->data;
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_pane *wp = NULL;
|
|
||||||
|
|
||||||
if (cdata->wp_id != -1)
|
|
||||||
wp = window_pane_find_by_id(cdata->wp_id);
|
|
||||||
if (wp == NULL) {
|
|
||||||
cmdq_print(cdata->cmdq, "%s", msg);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window_pane_set_mode(wp, &window_copy_mode) == 0)
|
|
||||||
window_copy_init_for_output(wp);
|
|
||||||
if (wp->mode == &window_copy_mode)
|
|
||||||
window_copy_add(wp, "%s", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct cmd_run_shell_data *cdata;
|
struct cmd_run_shell_data *cdata;
|
||||||
char *shellcmd;
|
struct job *job;
|
||||||
struct client *c;
|
|
||||||
struct session *s = NULL;
|
|
||||||
struct winlink *wl = NULL;
|
|
||||||
struct window_pane *wp = NULL;
|
|
||||||
struct format_tree *ft;
|
|
||||||
int cwd;
|
|
||||||
|
|
||||||
if (args_has(args, 't')) {
|
|
||||||
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
|
|
||||||
cwd = wp->cwd;
|
|
||||||
} else {
|
|
||||||
c = cmd_find_client(cmdq, NULL, 1);
|
|
||||||
if (c != NULL && c->session != NULL) {
|
|
||||||
s = c->session;
|
|
||||||
wl = s->curw;
|
|
||||||
wp = wl->window->active;
|
|
||||||
}
|
|
||||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
|
||||||
cwd = cmdq->client->cwd;
|
|
||||||
else if (s != NULL)
|
|
||||||
cwd = s->cwd;
|
|
||||||
else
|
|
||||||
cwd = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ft = format_create();
|
|
||||||
format_defaults(ft, NULL, s, wl, wp);
|
|
||||||
shellcmd = format_expand(ft, args->argv[0]);
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
cdata->cmd = shellcmd;
|
cdata->cmd = xstrdup(data->arg);
|
||||||
cdata->bflag = args_has(args, 'b');
|
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||||
cdata->wp_id = wp != NULL ? (int) wp->id : -1;
|
|
||||||
|
|
||||||
cdata->cmdq = cmdq;
|
if (ctx->cmdclient != NULL)
|
||||||
cmdq->references++;
|
ctx->cmdclient->references++;
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references++;
|
||||||
|
|
||||||
job_run(shellcmd, s, cwd, cmd_run_shell_callback, cmd_run_shell_free,
|
job = job_add(NULL, 0, NULL,
|
||||||
cdata);
|
data->arg, cmd_run_shell_callback, cmd_run_shell_free, cdata);
|
||||||
|
job_run(job);
|
||||||
|
|
||||||
if (cdata->bflag)
|
return (1); /* don't let client exit */
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_run_shell_callback(struct job *job)
|
cmd_run_shell_callback(struct job *job)
|
||||||
{
|
{
|
||||||
struct cmd_run_shell_data *cdata = job->data;
|
struct cmd_run_shell_data *cdata = job->data;
|
||||||
struct cmd_q *cmdq = cdata->cmdq;
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
char *cmd, *msg, *line;
|
char *cmd, *msg, *line;
|
||||||
size_t size;
|
size_t size;
|
||||||
int retcode;
|
int retcode;
|
||||||
u_int lines;
|
u_int lines;
|
||||||
|
|
||||||
if (cmdq->flags & CMD_Q_DEAD)
|
if (ctx->cmdclient != NULL && ctx->cmdclient->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
if (ctx->curclient != NULL && ctx->curclient->flags & CLIENT_DEAD)
|
||||||
return;
|
return;
|
||||||
cmd = cdata->cmd;
|
|
||||||
|
|
||||||
lines = 0;
|
lines = 0;
|
||||||
do {
|
do {
|
||||||
if ((line = evbuffer_readline(job->event->input)) != NULL) {
|
if ((line = evbuffer_readline(job->event->input)) != NULL) {
|
||||||
cmd_run_shell_print(job, line);
|
ctx->print(ctx, "%s", line);
|
||||||
free(line);
|
|
||||||
lines++;
|
lines++;
|
||||||
}
|
}
|
||||||
} while (line != NULL);
|
} while (line != NULL);
|
||||||
@@ -150,12 +101,14 @@ cmd_run_shell_callback(struct job *job)
|
|||||||
memcpy(line, EVBUFFER_DATA(job->event->input), size);
|
memcpy(line, EVBUFFER_DATA(job->event->input), size);
|
||||||
line[size] = '\0';
|
line[size] = '\0';
|
||||||
|
|
||||||
cmd_run_shell_print(job, line);
|
ctx->print(ctx, "%s", line);
|
||||||
lines++;
|
lines++;
|
||||||
|
|
||||||
free(line);
|
xfree(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd = cdata->cmd;
|
||||||
|
|
||||||
msg = NULL;
|
msg = NULL;
|
||||||
if (WIFEXITED(job->status)) {
|
if (WIFEXITED(job->status)) {
|
||||||
if ((retcode = WEXITSTATUS(job->status)) != 0)
|
if ((retcode = WEXITSTATUS(job->status)) != 0)
|
||||||
@@ -164,20 +117,28 @@ cmd_run_shell_callback(struct job *job)
|
|||||||
retcode = WTERMSIG(job->status);
|
retcode = WTERMSIG(job->status);
|
||||||
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
||||||
}
|
}
|
||||||
if (msg != NULL)
|
if (msg != NULL) {
|
||||||
cmd_run_shell_print(job, msg);
|
if (lines != 0)
|
||||||
free(msg);
|
ctx->print(ctx, "%s", msg);
|
||||||
|
else
|
||||||
|
ctx->info(ctx, "%s", msg);
|
||||||
|
xfree(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_run_shell_free(void *data)
|
cmd_run_shell_free(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_run_shell_data *cdata = data;
|
struct cmd_run_shell_data *cdata = data;
|
||||||
struct cmd_q *cmdq = cdata->cmdq;
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
|
||||||
if (!cmdq_free(cmdq) && !cdata->bflag)
|
if (ctx->cmdclient != NULL) {
|
||||||
cmdq_continue(cmdq);
|
ctx->cmdclient->references--;
|
||||||
|
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||||
|
}
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references--;
|
||||||
|
|
||||||
free(cdata->cmd);
|
xfree(cdata->cmd);
|
||||||
free(cdata);
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,139 +20,76 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.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_q *);
|
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,
|
||||||
cmd_save_buffer_exec
|
cmd_buffer_parse,
|
||||||
|
cmd_save_buffer_exec,
|
||||||
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_buffer_entry = {
|
int
|
||||||
"show-buffer", "showb",
|
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
"b:", 0, 0,
|
|
||||||
CMD_BUFFER_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_save_buffer_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct client *c = cmdq->client;
|
struct session *s;
|
||||||
struct session *s;
|
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
const char *path, *bufname, *bufdata, *start, *end;
|
mode_t mask;
|
||||||
char *msg;
|
|
||||||
size_t size, used, msglen, bufsize;
|
|
||||||
int cwd, fd;
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if (!args_has(args, 'b')) {
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
if ((pb = paste_get_top(NULL)) == NULL) {
|
return (-1);
|
||||||
cmdq_error(cmdq, "no buffers");
|
|
||||||
return (CMD_RETURN_ERROR);
|
if (data->buffer == -1) {
|
||||||
|
if ((pb = paste_get_top(&s->buffers)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffers");
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bufname = args_get(args, 'b');
|
if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
|
||||||
pb = paste_get_name(bufname);
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
if (pb == NULL) {
|
return (-1);
|
||||||
cmdq_error(cmdq, "no buffer %s", bufname);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bufdata = paste_buffer_data(pb, &bufsize);
|
|
||||||
|
|
||||||
if (self->entry == &cmd_show_buffer_entry)
|
if (strcmp(data->arg, "-") == 0) {
|
||||||
path = "-";
|
if (ctx->cmdclient == NULL) {
|
||||||
else
|
ctx->error(ctx, "%s: can't write to stdout", data->arg);
|
||||||
path = args->argv[0];
|
return (-1);
|
||||||
if (strcmp(path, "-") == 0) {
|
|
||||||
if (c == NULL) {
|
|
||||||
cmdq_error(cmdq, "can't write to stdout");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
if (c->session == NULL || (c->flags & CLIENT_CONTROL))
|
bufferevent_write(
|
||||||
goto do_stdout;
|
ctx->cmdclient->stdout_event, pb->data, pb->size);
|
||||||
goto do_print;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c != NULL && c->session == NULL)
|
|
||||||
cwd = c->cwd;
|
|
||||||
else if ((s = cmd_find_current(cmdq)) != NULL)
|
|
||||||
cwd = s->cwd;
|
|
||||||
else
|
|
||||||
cwd = AT_FDCWD;
|
|
||||||
|
|
||||||
f = NULL;
|
|
||||||
if (args_has(self->args, 'a')) {
|
|
||||||
fd = openat(cwd, path, O_CREAT|O_RDWR|O_APPEND, 0600);
|
|
||||||
if (fd != -1)
|
|
||||||
f = fdopen(fd, "ab");
|
|
||||||
} else {
|
} else {
|
||||||
fd = openat(cwd, path, O_CREAT|O_RDWR|O_TRUNC, 0600);
|
mask = umask(S_IRWXG | S_IRWXO);
|
||||||
if (fd != -1)
|
if (cmd_check_flag(data->chflags, 'a'))
|
||||||
f = fdopen(fd, "wb");
|
f = fopen(data->arg, "ab");
|
||||||
}
|
|
||||||
if (f == NULL) {
|
|
||||||
if (fd != -1)
|
|
||||||
close(fd);
|
|
||||||
cmdq_error(cmdq, "%s: %s", path, strerror(errno));
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (fwrite(bufdata, 1, bufsize, f) != bufsize) {
|
|
||||||
cmdq_error(cmdq, "%s: fwrite error", path);
|
|
||||||
fclose(f);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
do_stdout:
|
|
||||||
evbuffer_add(c->stdout_data, bufdata, bufsize);
|
|
||||||
server_push_stdout(c);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
do_print:
|
|
||||||
if (bufsize > (INT_MAX / 4) - 1) {
|
|
||||||
cmdq_error(cmdq, "buffer too big");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
msg = NULL;
|
|
||||||
|
|
||||||
used = 0;
|
|
||||||
while (used != bufsize) {
|
|
||||||
start = bufdata + used;
|
|
||||||
end = memchr(start, '\n', bufsize - used);
|
|
||||||
if (end != NULL)
|
|
||||||
size = end - start;
|
|
||||||
else
|
else
|
||||||
size = bufsize - used;
|
f = fopen(data->arg, "wb");
|
||||||
|
umask(mask);
|
||||||
msglen = size * 4 + 1;
|
if (f == NULL) {
|
||||||
msg = xrealloc(msg, msglen);
|
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||||
|
return (-1);
|
||||||
strvisx(msg, start, size, VIS_OCTAL|VIS_TAB);
|
}
|
||||||
cmdq_print(cmdq, "%s", msg);
|
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
|
||||||
|
ctx->error(ctx, "%s: fwrite error", data->arg);
|
||||||
used += size + (end != NULL);
|
fclose(f);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(msg);
|
return (0);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -18,110 +18,77 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Switch window to selected layout.
|
* Switch window to selected layout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *);
|
void cmd_select_layout_init(struct cmd *, int);
|
||||||
|
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",
|
||||||
"nopt:", 0, 1,
|
CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
||||||
"[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
CMD_ARG01, "",
|
||||||
0,
|
cmd_select_layout_init,
|
||||||
cmd_select_layout_exec
|
cmd_target_parse,
|
||||||
|
cmd_select_layout_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_next_layout_entry = {
|
void
|
||||||
"next-layout", "nextl",
|
cmd_select_layout_init(struct cmd *self, int key)
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_WINDOW_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_select_layout_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_previous_layout_entry = {
|
|
||||||
"previous-layout", "prevl",
|
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_WINDOW_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_select_layout_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data;
|
||||||
struct winlink *wl;
|
|
||||||
struct window *w;
|
|
||||||
const char *layoutname;
|
|
||||||
char *oldlayout;
|
|
||||||
int next, previous, layout;
|
|
||||||
|
|
||||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
|
cmd_target_init(self, key);
|
||||||
return (CMD_RETURN_ERROR);
|
data = self->data;
|
||||||
w = wl->window;
|
|
||||||
|
|
||||||
server_unzoom_window(w);
|
switch (key) {
|
||||||
|
case ('1' | KEYC_ESCAPE):
|
||||||
next = self->entry == &cmd_next_layout_entry;
|
data->arg = xstrdup("even-horizontal");
|
||||||
if (args_has(args, 'n'))
|
break;
|
||||||
next = 1;
|
case ('2' | KEYC_ESCAPE):
|
||||||
previous = self->entry == &cmd_previous_layout_entry;
|
data->arg = xstrdup("even-vertical");
|
||||||
if (args_has(args, 'p'))
|
break;
|
||||||
previous = 1;
|
case ('3' | KEYC_ESCAPE):
|
||||||
|
data->arg = xstrdup("main-horizontal");
|
||||||
oldlayout = w->old_layout;
|
break;
|
||||||
w->old_layout = layout_dump(w->layout_root);
|
case ('4' | KEYC_ESCAPE):
|
||||||
|
data->arg = xstrdup("main-vertical");
|
||||||
if (next || previous) {
|
break;
|
||||||
if (next)
|
case ('5' | KEYC_ESCAPE):
|
||||||
layout_set_next(w);
|
data->arg = xstrdup("tiled");
|
||||||
else
|
break;
|
||||||
layout_set_previous(w);
|
|
||||||
goto changed;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!args_has(args, 'o')) {
|
|
||||||
if (args->argc == 0)
|
int
|
||||||
layout = w->lastlayout;
|
cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
else
|
{
|
||||||
layout = layout_set_lookup(args->argv[0]);
|
struct cmd_target_data *data = self->data;
|
||||||
if (layout != -1) {
|
struct winlink *wl;
|
||||||
layout_set_select(w, layout);
|
int layout;
|
||||||
goto changed;
|
|
||||||
}
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
}
|
return (-1);
|
||||||
|
|
||||||
if (args->argc != 0)
|
if (data->arg == NULL) {
|
||||||
layoutname = args->argv[0];
|
layout = wl->window->lastlayout;
|
||||||
else if (args_has(args, 'o'))
|
if (layout == -1)
|
||||||
layoutname = oldlayout;
|
return (0);
|
||||||
else
|
} else if ((layout = layout_set_lookup(data->arg)) != -1) {
|
||||||
layoutname = NULL;
|
layout = layout_set_select(wl->window, layout);
|
||||||
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
if (layoutname != NULL) {
|
} else {
|
||||||
if (layout_parse(w, layoutname) == -1) {
|
if (layout_parse(wl->window, data->arg) == -1) {
|
||||||
cmdq_error(cmdq, "can't set layout: %s", layoutname);
|
ctx->error(ctx, "can't set layout: %s", data->arg);
|
||||||
goto error;
|
return (-1);
|
||||||
}
|
}
|
||||||
goto changed;
|
ctx->info(ctx, "arranging in: %s", data->arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(oldlayout);
|
return (0);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
changed:
|
|
||||||
free(oldlayout);
|
|
||||||
server_redraw_window(w);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
error:
|
|
||||||
free(w->old_layout);
|
|
||||||
w->old_layout = oldlayout;
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,134 +24,71 @@
|
|||||||
* Select pane.
|
* Select pane.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *);
|
void cmd_select_pane_init(struct cmd *, int);
|
||||||
|
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",
|
||||||
"DdegLlMmP:Rt:U", 0, 0,
|
"[-DLRU] " CMD_TARGET_PANE_USAGE,
|
||||||
"[-DdegLlMmRU] [-P style] " CMD_TARGET_PANE_USAGE,
|
0, "DLRU",
|
||||||
0,
|
cmd_select_pane_init,
|
||||||
cmd_select_pane_exec
|
cmd_target_parse,
|
||||||
|
cmd_select_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_last_pane_entry = {
|
void
|
||||||
"last-pane", "lastp",
|
cmd_select_pane_init(struct cmd *self, int key)
|
||||||
"det:", 0, 0,
|
|
||||||
"[-de] " CMD_TARGET_WINDOW_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_select_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data;
|
||||||
struct winlink *wl;
|
|
||||||
struct window *w;
|
|
||||||
struct session *s;
|
|
||||||
struct window_pane *wp, *lastwp, *markedwp;
|
|
||||||
const char *style;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
cmd_target_init(self, key);
|
||||||
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
|
data = self->data;
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
w = wl->window;
|
|
||||||
|
|
||||||
if (w->last == NULL) {
|
if (key == KEYC_UP)
|
||||||
cmdq_error(cmdq, "no last pane");
|
cmd_set_flag(&data->chflags, 'U');
|
||||||
return (CMD_RETURN_ERROR);
|
if (key == KEYC_DOWN)
|
||||||
}
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
|
if (key == KEYC_LEFT)
|
||||||
if (args_has(self->args, 'e'))
|
cmd_set_flag(&data->chflags, 'L');
|
||||||
w->last->flags &= ~PANE_INPUTOFF;
|
if (key == KEYC_RIGHT)
|
||||||
else if (args_has(self->args, 'd'))
|
cmd_set_flag(&data->chflags, 'R');
|
||||||
w->last->flags |= PANE_INPUTOFF;
|
if (key == 'o')
|
||||||
else {
|
data->target = xstrdup(":.+");
|
||||||
server_unzoom_window(w);
|
}
|
||||||
window_redraw_active_switch(w, w->last);
|
|
||||||
if (window_set_active_pane(w, w->last)) {
|
int
|
||||||
server_status_window(w);
|
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
server_redraw_window_borders(w);
|
{
|
||||||
}
|
struct cmd_target_data *data = self->data;
|
||||||
}
|
struct winlink *wl;
|
||||||
|
struct window_pane *wp;
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
if (!window_pane_visible(wp)) {
|
||||||
w = wl->window;
|
ctx->error(ctx, "pane not visible: %s", data->target);
|
||||||
|
return (-1);
|
||||||
if (args_has(args, 'm') || args_has(args, 'M')) {
|
}
|
||||||
if (args_has(args, 'm') && !window_pane_visible(wp))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
if (cmd_check_flag(data->chflags, 'L'))
|
||||||
lastwp = marked_window_pane;
|
wp = window_pane_find_left(wp);
|
||||||
|
else if (cmd_check_flag(data->chflags, 'R'))
|
||||||
if (args_has(args, 'M') || server_is_marked(s, wl, wp))
|
wp = window_pane_find_right(wp);
|
||||||
server_clear_marked();
|
else if (cmd_check_flag(data->chflags, 'U'))
|
||||||
else
|
wp = window_pane_find_up(wp);
|
||||||
server_set_marked(s, wl, wp);
|
else if (cmd_check_flag(data->chflags, 'D'))
|
||||||
markedwp = marked_window_pane;
|
wp = window_pane_find_down(wp);
|
||||||
|
if (wp == NULL) {
|
||||||
if (lastwp != NULL) {
|
ctx->error(ctx, "pane not found");
|
||||||
server_redraw_window_borders(lastwp->window);
|
return (-1);
|
||||||
server_status_window(lastwp->window);
|
}
|
||||||
}
|
|
||||||
if (markedwp != NULL) {
|
window_set_active_pane(wl->window, wp);
|
||||||
server_redraw_window_borders(markedwp->window);
|
server_status_window(wl->window);
|
||||||
server_status_window(markedwp->window);
|
server_redraw_window_borders(wl->window);
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
|
|
||||||
if (args_has(args, 'P')) {
|
|
||||||
style = args_get(args, 'P');
|
|
||||||
if (style_parse(&grid_default_cell, &wp->colgc,
|
|
||||||
style) == -1) {
|
|
||||||
cmdq_error(cmdq, "bad style: %s", style);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
wp->flags |= PANE_REDRAW;
|
|
||||||
}
|
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
cmdq_print(cmdq, "%s", style_tostring(&wp->colgc));
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(self->args, 'L'))
|
|
||||||
wp = window_pane_find_left(wp);
|
|
||||||
else if (args_has(self->args, 'R'))
|
|
||||||
wp = window_pane_find_right(wp);
|
|
||||||
else if (args_has(self->args, 'U'))
|
|
||||||
wp = window_pane_find_up(wp);
|
|
||||||
else if (args_has(self->args, 'D'))
|
|
||||||
wp = window_pane_find_down(wp);
|
|
||||||
if (wp == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
if (args_has(self->args, 'e')) {
|
|
||||||
wp->flags &= ~PANE_INPUTOFF;
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
if (args_has(self->args, 'd')) {
|
|
||||||
wp->flags |= PANE_INPUTOFF;
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wp == w->active)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
server_unzoom_window(wp->window);
|
|
||||||
if (!window_pane_visible(wp)) {
|
|
||||||
cmdq_error(cmdq, "pane not visible");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
window_redraw_active_switch(w, wp);
|
|
||||||
if (window_set_active_pane(w, wp)) {
|
|
||||||
server_status_window(w);
|
|
||||||
server_redraw_window_borders(w);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,101 +26,44 @@
|
|||||||
* Select window by index.
|
* Select window by index.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_q *);
|
void cmd_select_window_init(struct cmd *, int);
|
||||||
|
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",
|
||||||
"lnpTt:", 0, 0,
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
"[-lnpT] " CMD_TARGET_WINDOW_USAGE,
|
0, "",
|
||||||
0,
|
cmd_select_window_init,
|
||||||
cmd_select_window_exec
|
cmd_target_parse,
|
||||||
|
cmd_select_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_next_window_entry = {
|
void
|
||||||
"next-window", "next",
|
cmd_select_window_init(struct cmd *self, int key)
|
||||||
"at:", 0, 0,
|
|
||||||
"[-a] " CMD_TARGET_SESSION_USAGE,
|
|
||||||
0,
|
|
||||||
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_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_last_window_entry = {
|
|
||||||
"last-window", "last",
|
|
||||||
"t:", 0, 0,
|
|
||||||
CMD_TARGET_SESSION_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_select_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data;
|
||||||
struct winlink *wl;
|
|
||||||
struct session *s;
|
|
||||||
int next, previous, last, activity;
|
|
||||||
|
|
||||||
next = self->entry == &cmd_next_window_entry;
|
cmd_target_init(self, key);
|
||||||
if (args_has(self->args, 'n'))
|
data = self->data;
|
||||||
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) {
|
xasprintf(&data->target, ":%d", key - '0');
|
||||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
}
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
activity = args_has(self->args, 'a');
|
int
|
||||||
if (next) {
|
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
if (session_next(s, activity) != 0) {
|
{
|
||||||
cmdq_error(cmdq, "no next window");
|
struct cmd_target_data *data = self->data;
|
||||||
return (CMD_RETURN_ERROR);
|
struct winlink *wl;
|
||||||
}
|
struct session *s;
|
||||||
} else if (previous) {
|
|
||||||
if (session_previous(s, activity) != 0) {
|
|
||||||
cmdq_error(cmdq, "no previous window");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (session_last(s) != 0) {
|
|
||||||
cmdq_error(cmdq, "no last window");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (session_select(s, wl->idx) == 0)
|
||||||
server_redraw_session(s);
|
server_redraw_session(s);
|
||||||
} else {
|
|
||||||
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
|
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If -T and select-window is invoked on same window as
|
|
||||||
* current, switch to previous window.
|
|
||||||
*/
|
|
||||||
if (args_has(self->args, 'T') && wl == s->curw) {
|
|
||||||
if (session_last(s) != 0) {
|
|
||||||
cmdq_error(cmdq, "no last window");
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
server_redraw_session(s);
|
|
||||||
} else if (session_select(s, wl->idx) == 0)
|
|
||||||
server_redraw_session(s);
|
|
||||||
}
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
165
cmd-send-keys.c
165
cmd-send-keys.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,70 +26,128 @@
|
|||||||
* Send keys to client.
|
* Send keys to client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_q *);
|
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",
|
||||||
"lRMt:", 0, -1,
|
"[-t target-pane] key ...",
|
||||||
"[-lRM] " CMD_TARGET_PANE_USAGE " key ...",
|
0, "",
|
||||||
0,
|
NULL,
|
||||||
cmd_send_keys_exec
|
cmd_send_keys_parse,
|
||||||
|
cmd_send_keys_exec,
|
||||||
|
cmd_send_keys_free,
|
||||||
|
cmd_send_keys_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_send_prefix_entry = {
|
int
|
||||||
"send-prefix", NULL,
|
cmd_send_keys_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
"2t:", 0, 0,
|
|
||||||
"[-2] " CMD_TARGET_PANE_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_send_keys_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_send_keys_data *data;
|
||||||
struct mouse_event *m = &cmdq->item->mouse;
|
int opt, key;
|
||||||
struct window_pane *wp;
|
char *s;
|
||||||
struct session *s;
|
|
||||||
const u_char *str;
|
|
||||||
int i, key;
|
|
||||||
|
|
||||||
if (args_has(args, 'M')) {
|
self->data = data = xmalloc(sizeof *data);
|
||||||
wp = cmd_mouse_pane(m, &s, NULL);
|
data->target = NULL;
|
||||||
if (wp == NULL) {
|
data->nkeys = 0;
|
||||||
cmdq_error(cmdq, "no mouse target");
|
data->keys = NULL;
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
while ((opt = getopt(argc, argv, "t:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
}
|
}
|
||||||
window_pane_key(wp, NULL, s, m->key, m);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc == 0)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
if (cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp) == NULL)
|
while (argc-- != 0) {
|
||||||
return (CMD_RETURN_ERROR);
|
if ((key = key_string_lookup_string(*argv)) != KEYC_NONE) {
|
||||||
|
data->keys = xrealloc(
|
||||||
if (self->entry == &cmd_send_prefix_entry) {
|
data->keys, data->nkeys + 1, sizeof *data->keys);
|
||||||
if (args_has(args, '2'))
|
data->keys[data->nkeys++] = key;
|
||||||
key = options_get_number(&s->options, "prefix2");
|
|
||||||
else
|
|
||||||
key = options_get_number(&s->options, "prefix");
|
|
||||||
window_pane_key(wp, NULL, s, key, NULL);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'R'))
|
|
||||||
input_reset(wp);
|
|
||||||
|
|
||||||
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, NULL, s, key, NULL);
|
|
||||||
} else {
|
} else {
|
||||||
for (; *str != '\0'; str++)
|
for (s = *argv; *s != '\0'; s++) {
|
||||||
window_pane_key(wp, NULL, s, *str, NULL);
|
data->keys = xrealloc(data->keys,
|
||||||
|
data->nkeys + 1, sizeof *data->keys);
|
||||||
|
data->keys[data->nkeys++] = *s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
55
cmd-send-prefix.c
Normal file
55
cmd-send-prefix.c
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/* $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>
|
||||||
|
*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send prefix key as a key.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_send_prefix_entry = {
|
||||||
|
"send-prefix", NULL,
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_send_prefix_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct keylist *keylist;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, &s, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
keylist = options_get_data(&s->options, "prefix");
|
||||||
|
window_pane_key(wp, s, ARRAY_FIRST(keylist));
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
183
cmd-server-info.c
Normal file
183
cmd-server-info.c
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
/* $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>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show various information about server.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_server_info_entry = {
|
||||||
|
"server-info", "info",
|
||||||
|
"",
|
||||||
|
0, "",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_server_info_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct tty_term *term;
|
||||||
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct tty_code *code;
|
||||||
|
struct tty_term_code_entry *ent;
|
||||||
|
struct utsname un;
|
||||||
|
struct job *job;
|
||||||
|
struct grid *gd;
|
||||||
|
struct grid_line *gl;
|
||||||
|
u_int i, j, k;
|
||||||
|
char out[80];
|
||||||
|
char *tim;
|
||||||
|
time_t t;
|
||||||
|
u_int lines, ulines;
|
||||||
|
size_t size, usize;
|
||||||
|
|
||||||
|
tim = ctime(&start_time);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
ctx->print(ctx,
|
||||||
|
"tmux " BUILD ", pid %ld, started %s", (long) getpid(), tim);
|
||||||
|
ctx->print(
|
||||||
|
ctx, "socket path %s, debug level %d", socket_path, debug_level);
|
||||||
|
if (uname(&un) == 0) {
|
||||||
|
ctx->print(ctx, "system is %s %s %s %s",
|
||||||
|
un.sysname, un.release, un.version, un.machine);
|
||||||
|
}
|
||||||
|
if (cfg_file != NULL)
|
||||||
|
ctx->print(ctx, "configuration file is %s", cfg_file);
|
||||||
|
else
|
||||||
|
ctx->print(ctx, "configuration file not specified");
|
||||||
|
ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Clients:");
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ctx->print(ctx, "%2d: %s (%d, %d): %s [%ux%u %s] "
|
||||||
|
"[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
|
||||||
|
c->ibuf.fd, c->tty.fd, c->session->name,
|
||||||
|
c->tty.sx, c->tty.sy, c->tty.termname, c->flags,
|
||||||
|
c->tty.flags, c->references);
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Sessions: [%zu/%zu]",
|
||||||
|
sizeof (struct grid_cell), sizeof (struct grid_utf8));
|
||||||
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
|
t = s->creation_time.tv_sec;
|
||||||
|
tim = ctime(&t);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
|
||||||
|
"[flags=0x%x]", s->idx, s->name,
|
||||||
|
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
|
||||||
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
|
w = wl->window;
|
||||||
|
ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
|
||||||
|
"references=%u, last layout=%d]", wl->idx, w->name,
|
||||||
|
w->sx, w->sy, w->flags, w->references,
|
||||||
|
w->lastlayout);
|
||||||
|
j = 0;
|
||||||
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
|
lines = ulines = size = usize = 0;
|
||||||
|
gd = wp->base.grid;
|
||||||
|
for (k = 0; k < gd->hsize + gd->sy; k++) {
|
||||||
|
gl = &gd->linedata[k];
|
||||||
|
if (gl->celldata != NULL) {
|
||||||
|
lines++;
|
||||||
|
size += gl->cellsize *
|
||||||
|
sizeof *gl->celldata;
|
||||||
|
}
|
||||||
|
if (gl->utf8data != NULL) {
|
||||||
|
ulines++;
|
||||||
|
usize += gl->utf8size *
|
||||||
|
sizeof *gl->utf8data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
|
||||||
|
"bytes; UTF-8 %u/%u, %zu bytes", j,
|
||||||
|
wp->tty, (u_long) wp->pid, wp->fd, lines,
|
||||||
|
gd->hsize + gd->sy, size, ulines,
|
||||||
|
gd->hsize + gd->sy, usize);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Terminals:");
|
||||||
|
SLIST_FOREACH(term, &tty_terms, entry) {
|
||||||
|
ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
|
||||||
|
term->name, term->references, term->flags);
|
||||||
|
for (i = 0; i < NTTYCODE; i++) {
|
||||||
|
ent = &tty_term_codes[i];
|
||||||
|
code = &term->codes[ent->code];
|
||||||
|
switch (code->type) {
|
||||||
|
case TTYCODE_NONE:
|
||||||
|
ctx->print(ctx, "%2u: %s: [missing]",
|
||||||
|
ent->code, ent->name);
|
||||||
|
break;
|
||||||
|
case TTYCODE_STRING:
|
||||||
|
strnvis(out, code->value.string, sizeof out,
|
||||||
|
VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||||
|
ctx->print(ctx, "%2u: %s: (string) %s",
|
||||||
|
ent->code, ent->name, out);
|
||||||
|
break;
|
||||||
|
case TTYCODE_NUMBER:
|
||||||
|
ctx->print(ctx, "%2u: %s: (number) %d",
|
||||||
|
ent->code, ent->name, code->value.number);
|
||||||
|
break;
|
||||||
|
case TTYCODE_FLAG:
|
||||||
|
ctx->print(ctx, "%2u: %s: (flag) %s",
|
||||||
|
ent->code, ent->name,
|
||||||
|
code->value.flag ? "true" : "false");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Jobs:");
|
||||||
|
SLIST_FOREACH(job, &all_jobs, lentry) {
|
||||||
|
ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d, flags=0x%x]",
|
||||||
|
job->cmd, job->fd, job->pid, job->status, job->flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
111
cmd-set-buffer.c
111
cmd-set-buffer.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,100 +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, set, append to or delete a paste buffer.
|
* Add or set a session paste buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_q *);
|
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",
|
||||||
"ab:n:", 0, 1,
|
CMD_BUFFER_SESSION_USAGE " data",
|
||||||
"[-a] " CMD_BUFFER_USAGE " [-n new-buffer-name] data",
|
CMD_ARG1, "",
|
||||||
0,
|
cmd_buffer_init,
|
||||||
cmd_set_buffer_exec
|
cmd_buffer_parse,
|
||||||
|
cmd_set_buffer_exec,
|
||||||
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_delete_buffer_entry = {
|
int
|
||||||
"delete-buffer", "deleteb",
|
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
"b:", 0, 0,
|
|
||||||
CMD_BUFFER_USAGE,
|
|
||||||
0,
|
|
||||||
cmd_set_buffer_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct paste_buffer *pb;
|
struct session *s;
|
||||||
char *bufdata, *cause;
|
u_int limit;
|
||||||
const char *bufname, *olddata;
|
char *pdata;
|
||||||
size_t bufsize, newsize;
|
size_t psize;
|
||||||
|
|
||||||
bufname = args_get(args, 'b');
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
if (bufname == NULL)
|
return (-1);
|
||||||
pb = NULL;
|
limit = options_get_number(&s->options, "buffer-limit");
|
||||||
else
|
|
||||||
pb = paste_get_name(bufname);
|
|
||||||
|
|
||||||
if (self->entry == &cmd_delete_buffer_entry) {
|
pdata = xstrdup(data->arg);
|
||||||
if (pb == NULL)
|
psize = strlen(pdata);
|
||||||
pb = paste_get_top(&bufname);
|
|
||||||
if (pb == NULL) {
|
if (data->buffer == -1) {
|
||||||
cmdq_error(cmdq, "no buffer");
|
paste_add(&s->buffers, pdata, psize, limit);
|
||||||
return (CMD_RETURN_ERROR);
|
return (0);
|
||||||
}
|
|
||||||
paste_free(pb);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
if (paste_replace(&s->buffers, data->buffer, pdata, psize) != 0) {
|
||||||
if (args_has(args, 'n')) {
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
if (pb == NULL)
|
xfree(pdata);
|
||||||
pb = paste_get_top(&bufname);
|
return (-1);
|
||||||
if (pb == NULL) {
|
|
||||||
cmdq_error(cmdq, "no buffer");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) {
|
|
||||||
cmdq_error(cmdq, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
if (args->argc != 1) {
|
|
||||||
cmdq_error(cmdq, "no data specified");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if ((newsize = strlen(args->argv[0])) == 0)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
bufsize = 0;
|
|
||||||
bufdata = NULL;
|
|
||||||
|
|
||||||
if (args_has(args, 'a') && pb != NULL) {
|
|
||||||
olddata = paste_buffer_data(pb, &bufsize);
|
|
||||||
bufdata = xmalloc(bufsize);
|
|
||||||
memcpy(bufdata, olddata, bufsize);
|
|
||||||
}
|
|
||||||
|
|
||||||
bufdata = xrealloc(bufdata, bufsize + newsize);
|
|
||||||
memcpy(bufdata + bufsize, args->argv[0], newsize);
|
|
||||||
bufsize += newsize;
|
|
||||||
|
|
||||||
if (paste_set(bufdata, bufsize, bufname, &cause) != 0) {
|
|
||||||
cmdq_error(cmdq, "%s", cause);
|
|
||||||
free(bufdata);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,66 +27,62 @@
|
|||||||
* Set an environment variable.
|
* Set an environment variable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_q *);
|
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",
|
||||||
cmd_set_environment_exec
|
NULL,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_set_environment_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
|
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");
|
||||||
cmdq_error(cmdq, "empty variable name");
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
if (strchr(name, '=') != NULL) {
|
if (strchr(data->arg, '=') != NULL) {
|
||||||
cmdq_error(cmdq, "variable name contains =");
|
ctx->error(ctx, "variable name contains =");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc < 2)
|
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(cmdq, 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) {
|
||||||
cmdq_error(cmdq, "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) {
|
||||||
cmdq_error(cmdq, "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) {
|
||||||
cmdq_error(cmdq, "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);
|
||||||
}
|
}
|
||||||
|
|||||||
823
cmd-set-option.c
823
cmd-set-option.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,425 +27,492 @@
|
|||||||
* Set an option.
|
* Set an option.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_q *);
|
int cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_q *,
|
const char *cmd_set_option_print(
|
||||||
const char *, const char *);
|
const struct set_option_entry *, struct options_entry *);
|
||||||
|
void cmd_set_option_string(struct cmd_ctx *,
|
||||||
int cmd_set_option_unset(struct cmd *, struct cmd_q *,
|
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 *);
|
||||||
int cmd_set_option_set(struct cmd *, struct cmd_q *,
|
void cmd_set_option_keys(struct cmd_ctx *,
|
||||||
const struct options_table_entry *, struct options *,
|
struct options *, const struct set_option_entry *, char *);
|
||||||
const char *);
|
void cmd_set_option_colour(struct cmd_ctx *,
|
||||||
|
struct options *, const struct set_option_entry *, char *);
|
||||||
struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_q *,
|
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_number(struct cmd *, struct cmd_q *,
|
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_key(struct cmd *, struct cmd_q *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_q *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_q *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_q *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
struct options_entry *cmd_set_option_style(struct cmd *, struct cmd_q *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_option_entry = {
|
const struct cmd_entry cmd_set_option_entry = {
|
||||||
"set-option", "set",
|
"set-option", "set",
|
||||||
"agoqst:uw", 1, 2,
|
"[-agsuw] [-t target-session|target-window] option [value]",
|
||||||
"[-agosquw] [-t target-session|target-window] option [value]",
|
CMD_ARG12, "agsuw",
|
||||||
0,
|
NULL,
|
||||||
cmd_set_option_exec
|
cmd_target_parse,
|
||||||
|
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
|
||||||
"agoqt:u", 1, 2,
|
};
|
||||||
"[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
const char *set_option_clock_mode_style_list[] = {
|
||||||
0,
|
"12", "24", NULL
|
||||||
cmd_set_option_exec
|
};
|
||||||
|
const char *set_option_status_keys_list[] = {
|
||||||
|
"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[] = {
|
||||||
cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
|
{ "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)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
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') {
|
|
||||||
cmdq_error(cmdq, "invalid option");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (args->argc < 2)
|
|
||||||
valstr = NULL;
|
|
||||||
else
|
|
||||||
valstr = args->argv[1];
|
|
||||||
|
|
||||||
/* Is this a user option? */
|
|
||||||
if (*optstr == '@')
|
|
||||||
return (cmd_set_option_user(self, cmdq, optstr, valstr));
|
|
||||||
|
|
||||||
/* Find the option entry, try each table. */
|
|
||||||
table = oe = NULL;
|
|
||||||
if (options_table_find(optstr, &table, &oe) != 0) {
|
|
||||||
if (!args_has(args, 'q')) {
|
|
||||||
cmdq_error(cmdq, "ambiguous option: %s", optstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
if (oe == NULL) {
|
|
||||||
if (!args_has(args, 'q')) {
|
|
||||||
cmdq_error(cmdq, "unknown option: %s", optstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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(cmdq, args_get(args, 't'), NULL);
|
wl = cmd_find_window(ctx, data->target, NULL);
|
||||||
if (wl == NULL) {
|
if (wl == NULL)
|
||||||
cmdq_error(cmdq,
|
return (-1);
|
||||||
"couldn't set '%s'%s", optstr,
|
|
||||||
(!args_has(args, 't') && !args_has(args,
|
|
||||||
'g')) ? " need target window or -g" : "");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
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(cmdq, args_get(args, 't'), 0);
|
s = cmd_find_session(ctx, data->target);
|
||||||
if (s == NULL) {
|
if (s == NULL)
|
||||||
cmdq_error(cmdq,
|
return (-1);
|
||||||
"couldn't set '%s'%s", optstr,
|
|
||||||
(!args_has(args, 't') && !args_has(args,
|
|
||||||
'g')) ? " need target session or -g" : "");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
oo = &s->options;
|
oo = &s->options;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cmdq_error(cmdq, "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, cmdq, oe, oo, valstr) != 0)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
}
|
||||||
} else {
|
|
||||||
if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
|
entry = NULL;
|
||||||
if (!args_has(args, 'q')) {
|
for (opt = table; opt->name != NULL; opt++) {
|
||||||
cmdq_error(cmdq, "already set: %s", optstr);
|
if (strncmp(opt->name, data->arg, strlen(data->arg)) != 0)
|
||||||
return (CMD_RETURN_ERROR);
|
continue;
|
||||||
}
|
if (entry != NULL) {
|
||||||
return (CMD_RETURN_NORMAL);
|
ctx->error(ctx, "ambiguous option: %s", data->arg);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0)
|
entry = opt;
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
/* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start or stop timers if necessary. */
|
if (cmd_check_flag(data->chflags, 'u')) {
|
||||||
if (strcmp(oe->name, "automatic-rename") == 0) {
|
if (cmd_check_flag(data->chflags, 'g')) {
|
||||||
RB_FOREACH(w, windows, &windows) {
|
ctx->error(ctx,
|
||||||
if (options_get_number(&w->options, "automatic-rename"))
|
"can't unset global option: %s", entry->name);
|
||||||
w->active->flags |= PANE_CHANGED;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strcmp(oe->name, "status") == 0 ||
|
|
||||||
strcmp(oe->name, "status-interval") == 0)
|
|
||||||
status_timer_start_all();
|
|
||||||
if (strcmp(oe->name, "monitor-silence") == 0)
|
|
||||||
alerts_reset_all();
|
|
||||||
|
|
||||||
/* Update sizes and redraw. May not need it but meh. */
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
if (c->session != NULL)
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c != NULL && c->session != NULL)
|
||||||
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;
|
||||||
|
|
||||||
/* Set user option. */
|
jobs = &c->status_jobs;
|
||||||
enum cmd_retval
|
do {
|
||||||
cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,
|
try_again = 0;
|
||||||
const char *valstr)
|
job = RB_ROOT(jobs);
|
||||||
{
|
while (job != NULL) {
|
||||||
struct args *args = self->args;
|
nextjob = RB_NEXT(jobs, jobs, job);
|
||||||
struct session *s;
|
if (job->flags & JOB_PERSIST) {
|
||||||
struct winlink *wl;
|
job_remove(jobs, job);
|
||||||
struct options *oo;
|
try_again = 1;
|
||||||
|
break;
|
||||||
if (args_has(args, 's'))
|
}
|
||||||
oo = &global_options;
|
job = nextjob;
|
||||||
else if (args_has(self->args, 'w') ||
|
}
|
||||||
self->entry == &cmd_set_window_option_entry) {
|
} while (try_again);
|
||||||
if (args_has(self->args, 'g'))
|
server_redraw_client(c);
|
||||||
oo = &global_w_options;
|
|
||||||
else {
|
|
||||||
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
|
|
||||||
if (wl == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
oo = &wl->window->options;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
oo = &global_s_options;
|
|
||||||
else {
|
|
||||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
oo = &s->options;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'u')) {
|
|
||||||
if (options_find1(oo, optstr) == NULL) {
|
|
||||||
if (!args_has(args, 'q')) {
|
|
||||||
cmdq_error(cmdq, "unknown option: %s", optstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
if (valstr != NULL) {
|
|
||||||
cmdq_error(cmdq, "value passed to unset option: %s",
|
|
||||||
optstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
options_remove(oo, optstr);
|
|
||||||
} else {
|
|
||||||
if (valstr == NULL) {
|
|
||||||
cmdq_error(cmdq, "empty value");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
|
|
||||||
if (!args_has(args, 'q')) {
|
|
||||||
cmdq_error(cmdq, "already set: %s", optstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
options_set_string(oo, optstr, "%s", valstr);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Unset an option. */
|
|
||||||
int
|
|
||||||
cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq,
|
|
||||||
const struct options_table_entry *oe, struct options *oo,
|
|
||||||
const char *value)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
|
|
||||||
if (value != NULL) {
|
|
||||||
cmdq_error(cmdq, "value passed to unset option: %s", oe->name);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'g') || oo == &global_options) {
|
|
||||||
switch (oe->type) {
|
|
||||||
case OPTIONS_TABLE_STRING:
|
|
||||||
options_set_string(oo, oe->name, "%s", oe->default_str);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_STYLE:
|
|
||||||
options_set_style(oo, oe->name, oe->default_str, 0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
options_set_number(oo, oe->name, oe->default_num);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
options_remove(oo, 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_q *cmdq,
|
const struct set_option_entry *entry, struct options_entry *o)
|
||||||
const struct options_table_entry *oe, struct options *oo,
|
|
||||||
const char *value)
|
|
||||||
{
|
{
|
||||||
struct options_entry *o;
|
static char out[BUFSIZ];
|
||||||
|
const char *s;
|
||||||
|
struct keylist *keylist;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
switch (oe->type) {
|
*out = '\0';
|
||||||
case OPTIONS_TABLE_FLAG:
|
switch (entry->type) {
|
||||||
case OPTIONS_TABLE_CHOICE:
|
case SET_OPTION_STRING:
|
||||||
break;
|
xsnprintf(out, sizeof out, "\"%s\"", o->str);
|
||||||
default:
|
break;
|
||||||
if (value == NULL) {
|
case SET_OPTION_NUMBER:
|
||||||
cmdq_error(cmdq, "empty value");
|
xsnprintf(out, sizeof out, "%lld", o->num);
|
||||||
return (-1);
|
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);
|
||||||
o = NULL;
|
|
||||||
switch (oe->type) {
|
|
||||||
case OPTIONS_TABLE_STRING:
|
|
||||||
o = cmd_set_option_string(self, cmdq, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_NUMBER:
|
|
||||||
o = cmd_set_option_number(self, cmdq, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_KEY:
|
|
||||||
o = cmd_set_option_key(self, cmdq, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_COLOUR:
|
|
||||||
o = cmd_set_option_colour(self, cmdq, oe, oo, value);
|
|
||||||
if (o != NULL)
|
|
||||||
style_update_new(oo, o->name, oe->style);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_ATTRIBUTES:
|
|
||||||
o = cmd_set_option_attributes(self, cmdq, oe, oo, value);
|
|
||||||
if (o != NULL)
|
|
||||||
style_update_new(oo, o->name, oe->style);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_FLAG:
|
|
||||||
o = cmd_set_option_flag(self, cmdq, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_CHOICE:
|
|
||||||
o = cmd_set_option_choice(self, cmdq, oe, oo, value);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_STYLE:
|
|
||||||
o = cmd_set_option_style(self, cmdq, oe, oo, value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (o == NULL)
|
|
||||||
return (-1);
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set a string option. */
|
void
|
||||||
struct options_entry *
|
cmd_set_option_string(struct cmd_ctx *ctx, struct options *oo,
|
||||||
cmd_set_option_string(struct cmd *self, unused struct cmd_q *cmdq,
|
const struct set_option_entry *entry, char *value, int append)
|
||||||
const struct options_table_entry *oe, struct options *oo,
|
|
||||||
const char *value)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
char *oldval, *newval;
|
char *oldvalue, *newvalue;
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
if (value == NULL) {
|
||||||
oldval = options_get_string(oo, oe->name);
|
ctx->error(ctx, "empty value");
|
||||||
xasprintf(&newval, "%s%s", oldval, value);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (append) {
|
||||||
|
oldvalue = options_get_string(oo, entry->name);
|
||||||
|
xasprintf(&newvalue, "%s%s", oldvalue, 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_q *cmdq,
|
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) {
|
||||||
cmdq_error(cmdq, "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_q *cmdq,
|
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) {
|
||||||
cmdq_error(cmdq, "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_q *cmdq,
|
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) {
|
||||||
cmdq_error(cmdq, "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_q *cmdq,
|
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) {
|
||||||
cmdq_error(cmdq, "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_q *cmdq,
|
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 ||
|
||||||
@@ -456,65 +523,47 @@ cmd_set_option_flag(unused struct cmd *self, struct cmd_q *cmdq,
|
|||||||
strcasecmp(value, "no") == 0)
|
strcasecmp(value, "no") == 0)
|
||||||
flag = 0;
|
flag = 0;
|
||||||
else {
|
else {
|
||||||
cmdq_error(cmdq, "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_q *cmdq,
|
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) {
|
if (value == NULL) {
|
||||||
choice = options_get_number(oo, oe->name);
|
ctx->error(ctx, "empty value");
|
||||||
if (choice < 2)
|
return;
|
||||||
choice = !choice;
|
|
||||||
} else {
|
|
||||||
n = 0;
|
|
||||||
for (choicep = oe->choices; *choicep != NULL; choicep++) {
|
|
||||||
n++;
|
|
||||||
if (strncmp(*choicep, value, strlen(value)) != 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (choice != -1) {
|
|
||||||
cmdq_error(cmdq, "ambiguous value: %s", value);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
choice = n - 1;
|
|
||||||
}
|
|
||||||
if (choice == -1) {
|
|
||||||
cmdq_error(cmdq, "unknown value: %s", value);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (options_set_number(oo, oe->name, choice));
|
n = 0;
|
||||||
}
|
for (choicep = entry->choices; *choicep != NULL; choicep++) {
|
||||||
|
n++;
|
||||||
|
if (strncmp(*choicep, value, strlen(value)) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
/* Set a style option. */
|
if (choice != -1) {
|
||||||
struct options_entry *
|
ctx->error(ctx, "ambiguous option value: %s", value);
|
||||||
cmd_set_option_style(struct cmd *self, struct cmd_q *cmdq,
|
return;
|
||||||
const struct options_table_entry *oe, struct options *oo,
|
}
|
||||||
const char *value)
|
choice = n - 1;
|
||||||
{
|
}
|
||||||
struct args *args = self->args;
|
if (choice == -1) {
|
||||||
struct options_entry *o;
|
ctx->error(ctx, "unknown option value: %s", value);
|
||||||
int append;
|
return;
|
||||||
|
|
||||||
append = args_has(args, 'a');
|
|
||||||
if ((o = options_set_style(oo, oe->name, value, append)) == NULL) {
|
|
||||||
cmdq_error(cmdq, "bad style: %s", value);
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
style_update_old(oo, oe->name, &o->style);
|
o = options_set_number(oo, entry->name, choice);
|
||||||
return (o);
|
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));
|
||||||
|
}
|
||||||
101
cmd-show-buffer.c
Normal file
101
cmd-show-buffer.c
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/* $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>
|
||||||
|
*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show a session paste buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_show_buffer_entry = {
|
||||||
|
"show-buffer", "showb",
|
||||||
|
CMD_BUFFER_SESSION_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_buffer_init,
|
||||||
|
cmd_buffer_parse,
|
||||||
|
cmd_show_buffer_exec,
|
||||||
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
char *in, *buf, *ptr;
|
||||||
|
size_t size, len;
|
||||||
|
u_int width;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (data->buffer == -1) {
|
||||||
|
if ((pb = paste_get_top(&s->buffers)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffers");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} 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;
|
||||||
|
if (size > SIZE_MAX / 4 - 1)
|
||||||
|
size = SIZE_MAX / 4 - 1;
|
||||||
|
in = xmalloc(size * 4 + 1);
|
||||||
|
strvisx(in, pb->data, size, VIS_OCTAL|VIS_TAB);
|
||||||
|
|
||||||
|
width = s->sx;
|
||||||
|
if (ctx->cmdclient != NULL)
|
||||||
|
width = ctx->cmdclient->tty.sx;
|
||||||
|
|
||||||
|
buf = xmalloc(width + 1);
|
||||||
|
len = 0;
|
||||||
|
|
||||||
|
ptr = in;
|
||||||
|
do {
|
||||||
|
buf[len++] = *ptr++;
|
||||||
|
|
||||||
|
if (len == width || buf[len - 1] == '\n') {
|
||||||
|
if (buf[len - 1] == '\n')
|
||||||
|
len--;
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%s", buf);
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
} while (*ptr != '\0');
|
||||||
|
|
||||||
|
if (len != 0) {
|
||||||
|
buf[len] = '\0';
|
||||||
|
ctx->print(ctx, "%s", buf);
|
||||||
|
}
|
||||||
|
xfree(buf);
|
||||||
|
|
||||||
|
xfree(in);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,89 +27,41 @@
|
|||||||
* Show environment.
|
* Show environment.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_q *);
|
int cmd_show_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
char *cmd_show_environment_escape(struct environ_entry *);
|
|
||||||
void cmd_show_environment_print(struct cmd *, struct cmd_q *,
|
|
||||||
struct environ_entry *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_environment_entry = {
|
const struct cmd_entry cmd_show_environment_entry = {
|
||||||
"show-environment", "showenv",
|
"show-environment", "showenv",
|
||||||
"gst:", 0, 1,
|
"[-g] " CMD_TARGET_SESSION_USAGE,
|
||||||
"[-gs] " CMD_TARGET_SESSION_USAGE " [name]",
|
0, "g",
|
||||||
0,
|
cmd_target_init,
|
||||||
cmd_show_environment_exec
|
cmd_target_parse,
|
||||||
|
cmd_show_environment_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
char *
|
int
|
||||||
cmd_show_environment_escape(struct environ_entry *envent)
|
cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
const char *value = envent->value;
|
struct cmd_target_data *data = self->data;
|
||||||
char c, *out, *ret;
|
struct session *s;
|
||||||
|
struct environ *env;
|
||||||
|
struct environ_entry *envent;
|
||||||
|
|
||||||
out = ret = xmalloc(strlen(value) * 2 + 1); /* at most twice the size */
|
if (cmd_check_flag(data->chflags, 'g'))
|
||||||
while ((c = *value++) != '\0') {
|
|
||||||
/* POSIX interprets $ ` " and \ in double quotes. */
|
|
||||||
if (c == '$' || c == '`' || c == '"' || c == '\\')
|
|
||||||
*out++ = '\\';
|
|
||||||
*out++ = c;
|
|
||||||
}
|
|
||||||
*out = '\0';
|
|
||||||
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cmd_show_environment_print(struct cmd *self, struct cmd_q *cmdq,
|
|
||||||
struct environ_entry *envent)
|
|
||||||
{
|
|
||||||
char *escaped;
|
|
||||||
|
|
||||||
if (!args_has(self->args, 's')) {
|
|
||||||
if (envent->value != NULL)
|
|
||||||
cmdq_print(cmdq, "%s=%s", envent->name, envent->value);
|
|
||||||
else
|
|
||||||
cmdq_print(cmdq, "-%s", envent->name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (envent->value != NULL) {
|
|
||||||
escaped = cmd_show_environment_escape(envent);
|
|
||||||
cmdq_print(cmdq, "%s=\"%s\"; export %s;", envent->name, escaped,
|
|
||||||
envent->name);
|
|
||||||
free(escaped);
|
|
||||||
} else
|
|
||||||
cmdq_print(cmdq, "unset %s;", envent->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct session *s;
|
|
||||||
struct environ *env;
|
|
||||||
struct environ_entry *envent;
|
|
||||||
|
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
env = &global_environ;
|
env = &global_environ;
|
||||||
else {
|
else {
|
||||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
if (s == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
env = &s->environ;
|
env = &s->environ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc != 0) {
|
RB_FOREACH(envent, environ, env) {
|
||||||
envent = environ_find(env, args->argv[0]);
|
if (envent->value != NULL)
|
||||||
if (envent == NULL) {
|
ctx->print(ctx, "%s=%s", envent->name, envent->value);
|
||||||
cmdq_error(cmdq, "unknown variable: %s", args->argv[0]);
|
else
|
||||||
return (CMD_RETURN_ERROR);
|
ctx->print(ctx, "-%s", envent->name);
|
||||||
}
|
|
||||||
cmd_show_environment_print(self, cmdq, envent);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_FOREACH(envent, environ, env)
|
return (0);
|
||||||
cmd_show_environment_print(self, cmdq, envent);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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>
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -28,118 +27,39 @@
|
|||||||
* Show client message log.
|
* Show client message log.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *);
|
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",
|
||||||
"IJTt:", 0, 0,
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
"[-IJT] " CMD_TARGET_CLIENT_USAGE,
|
0, "",
|
||||||
0,
|
cmd_target_init,
|
||||||
cmd_show_messages_exec
|
cmd_target_parse,
|
||||||
|
cmd_show_messages_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_server_info_entry = {
|
|
||||||
"server-info", "info",
|
|
||||||
"", 0, 0,
|
|
||||||
"",
|
|
||||||
0,
|
|
||||||
cmd_show_messages_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
int cmd_show_messages_server(struct cmd_q *);
|
|
||||||
int cmd_show_messages_terminals(struct cmd_q *, int);
|
|
||||||
int cmd_show_messages_jobs(struct cmd_q *, int);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
cmd_show_messages_server(struct cmd_q *cmdq)
|
cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
char *tim;
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct client *c;
|
||||||
|
struct message_entry *msg;
|
||||||
|
char *tim;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
tim = ctime(&start_time);
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
*strchr(tim, '\n') = '\0';
|
return (-1);
|
||||||
|
|
||||||
cmdq_print(cmdq, "started %s", tim);
|
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
|
||||||
cmdq_print(cmdq, "socket path %s", socket_path);
|
msg = &ARRAY_ITEM(&c->message_log, i);
|
||||||
cmdq_print(cmdq, "debug level %d", debug_level);
|
|
||||||
cmdq_print(cmdq, "protocol version %d", PROTOCOL_VERSION);
|
|
||||||
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
cmd_show_messages_terminals(struct cmd_q *cmdq, int blank)
|
|
||||||
{
|
|
||||||
struct tty_term *term;
|
|
||||||
u_int i, n;
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
LIST_FOREACH(term, &tty_terms, entry) {
|
|
||||||
if (blank) {
|
|
||||||
cmdq_print(cmdq, "%s", "");
|
|
||||||
blank = 0;
|
|
||||||
}
|
|
||||||
cmdq_print(cmdq, "Terminal %u: %s [references=%u, flags=0x%x]:",
|
|
||||||
n, term->name, term->references, term->flags);
|
|
||||||
n++;
|
|
||||||
for (i = 0; i < tty_term_ncodes(); i++)
|
|
||||||
cmdq_print(cmdq, "%s", tty_term_describe(term, i));
|
|
||||||
}
|
|
||||||
return (n != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
cmd_show_messages_jobs(struct cmd_q *cmdq, int blank)
|
|
||||||
{
|
|
||||||
struct job *job;
|
|
||||||
u_int n;
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
LIST_FOREACH(job, &all_jobs, lentry) {
|
|
||||||
if (blank) {
|
|
||||||
cmdq_print(cmdq, "%s", "");
|
|
||||||
blank = 0;
|
|
||||||
}
|
|
||||||
cmdq_print(cmdq, "Job %u: %s [fd=%d, pid=%d, status=%d]",
|
|
||||||
n, job->cmd, job->fd, job->pid, job->status);
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
return (n != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c;
|
|
||||||
struct message_entry *msg;
|
|
||||||
char *tim;
|
|
||||||
int done, blank;
|
|
||||||
|
|
||||||
done = blank = 0;
|
|
||||||
if (args_has(args, 'I') || self->entry == &cmd_server_info_entry) {
|
|
||||||
blank = cmd_show_messages_server(cmdq);
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) {
|
|
||||||
blank = cmd_show_messages_terminals(cmdq, blank);
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) {
|
|
||||||
cmd_show_messages_jobs(cmdq, blank);
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
if (done)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
TAILQ_FOREACH(msg, &c->message_log, entry) {
|
|
||||||
tim = ctime(&msg->msg_time);
|
tim = ctime(&msg->msg_time);
|
||||||
*strchr(tim, '\n') = '\0';
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
cmdq_print(cmdq, "%s %s", tim, msg->msg);
|
ctx->print(ctx, "%s %s", tim, msg->msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,151 +27,62 @@
|
|||||||
* Show options.
|
* Show options.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *);
|
int cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *,
|
|
||||||
struct options *, int);
|
|
||||||
enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *,
|
|
||||||
const struct options_table_entry *, struct options *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_options_entry = {
|
const struct cmd_entry cmd_show_options_entry = {
|
||||||
"show-options", "show",
|
"show-options", "show",
|
||||||
"gqst:vw", 0, 1,
|
"[-gsw] [-t target-session|target-window]",
|
||||||
"[-gqsvw] [-t target-session|target-window] [option]",
|
0, "gsw",
|
||||||
0,
|
cmd_target_init,
|
||||||
cmd_show_options_exec
|
cmd_target_parse,
|
||||||
|
cmd_show_options_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_window_options_entry = {
|
int
|
||||||
"show-window-options", "showw",
|
cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
"gvt:", 0, 1,
|
|
||||||
"[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
|
||||||
0,
|
|
||||||
cmd_show_options_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
const struct set_option_entry *table;
|
||||||
struct winlink *wl;
|
struct session *s;
|
||||||
const struct options_table_entry *table;
|
struct winlink *wl;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
int quiet;
|
struct options_entry *o;
|
||||||
|
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(cmdq, 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(cmdq, 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
quiet = args_has(self->args, 'q');
|
for (entry = table; entry->name != NULL; entry++) {
|
||||||
if (args->argc == 0)
|
if ((o = options_find1(oo, entry->name)) == NULL)
|
||||||
return (cmd_show_options_all(self, cmdq, table, oo));
|
|
||||||
else
|
|
||||||
return (cmd_show_options_one(self, cmdq, oo, quiet));
|
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq,
|
|
||||||
struct options *oo, int quiet)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
const char *name = args->argv[0];
|
|
||||||
const struct options_table_entry *table, *oe;
|
|
||||||
struct options_entry *o;
|
|
||||||
const char *optval;
|
|
||||||
|
|
||||||
retry:
|
|
||||||
if (*name == '@') {
|
|
||||||
if ((o = options_find1(oo, name)) == NULL) {
|
|
||||||
if (quiet)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
cmdq_error(cmdq, "unknown option: %s", name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (args_has(self->args, 'v'))
|
|
||||||
cmdq_print(cmdq, "%s", o->str);
|
|
||||||
else
|
|
||||||
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
table = oe = NULL;
|
|
||||||
if (options_table_find(name, &table, &oe) != 0) {
|
|
||||||
cmdq_error(cmdq, "ambiguous option: %s", name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (oe == NULL) {
|
|
||||||
if (quiet)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
cmdq_error(cmdq, "unknown option: %s", name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (oe->style != NULL) {
|
|
||||||
name = oe->style;
|
|
||||||
goto retry;
|
|
||||||
}
|
|
||||||
if ((o = options_find1(oo, oe->name)) == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
optval = options_table_print_entry(oe, o, args_has(self->args, 'v'));
|
|
||||||
if (args_has(self->args, 'v'))
|
|
||||||
cmdq_print(cmdq, "%s", optval);
|
|
||||||
else
|
|
||||||
cmdq_print(cmdq, "%s %s", oe->name, optval);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum cmd_retval
|
|
||||||
cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq,
|
|
||||||
const struct options_table_entry *table, struct options *oo)
|
|
||||||
{
|
|
||||||
const struct options_table_entry *oe;
|
|
||||||
struct options_entry *o;
|
|
||||||
const char *optval;
|
|
||||||
|
|
||||||
RB_FOREACH(o, options_tree, &oo->tree) {
|
|
||||||
if (*o->name == '@') {
|
|
||||||
if (args_has(self->args, 'v'))
|
|
||||||
cmdq_print(cmdq, "%s", o->str);
|
|
||||||
else
|
|
||||||
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (oe = table; oe->name != NULL; oe++) {
|
|
||||||
if (oe->style != NULL)
|
|
||||||
continue;
|
continue;
|
||||||
if ((o = options_find1(oo, oe->name)) == NULL)
|
optval = cmd_set_option_print(entry, o);
|
||||||
continue;
|
ctx->print(ctx, "%s %s", entry->name, optval);
|
||||||
optval = options_table_print_entry(oe, o,
|
|
||||||
args_has(self->args, 'v'));
|
|
||||||
if (args_has(self->args, 'v'))
|
|
||||||
cmdq_print(cmdq, "%s", optval);
|
|
||||||
else
|
|
||||||
cmdq_print(cmdq, "%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 @@
|
|||||||
/* $OpenBSD$ */
|
/* $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,79 +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_q *);
|
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);
|
||||||
|
|
||||||
void cmd_source_file_done(struct cmd_q *);
|
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, "",
|
||||||
cmd_source_file_exec
|
cmd_source_file_init,
|
||||||
|
cmd_source_file_parse,
|
||||||
|
cmd_source_file_exec,
|
||||||
|
cmd_source_file_free,
|
||||||
|
cmd_source_file_print
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
|
void
|
||||||
|
cmd_source_file_init(struct cmd *self, unused int arg)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_source_file_data *data;
|
||||||
struct cmd_q *cmdq1;
|
|
||||||
char *cause;
|
|
||||||
|
|
||||||
cmdq1 = cmdq_new(NULL);
|
self->data = data = xmalloc(sizeof *data);
|
||||||
cmdq1->client = cmdq->client;
|
data->path = NULL;
|
||||||
cmdq1->emptyfn = cmd_source_file_done;
|
}
|
||||||
cmdq1->data = cmdq;
|
|
||||||
|
|
||||||
switch (load_cfg(args->argv[0], cmdq1, &cause)) {
|
int
|
||||||
case -1:
|
cmd_source_file_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
if (cfg_references == 0) {
|
{
|
||||||
cmdq_free(cmdq1);
|
struct cmd_source_file_data *data;
|
||||||
cmdq_error(cmdq, "%s", cause);
|
int opt;
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
}
|
}
|
||||||
cfg_add_cause("%s", cause);
|
}
|
||||||
free(cause);
|
argc -= optind;
|
||||||
/* FALLTHROUGH */
|
argv += optind;
|
||||||
case 0:
|
if (argc != 1)
|
||||||
if (cfg_references == 0)
|
goto usage;
|
||||||
cfg_print_causes(cmdq);
|
|
||||||
cmdq_free(cmdq1);
|
data->path = xstrdup(argv[0]);
|
||||||
return (CMD_RETURN_NORMAL);
|
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)
|
||||||
|
{
|
||||||
|
struct cmd_source_file_data *data = self->data;
|
||||||
|
struct causelist causes;
|
||||||
|
char *cause;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
ARRAY_INIT(&causes);
|
||||||
|
if (load_cfg(data->path, ctx, &causes) != 0) {
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
|
||||||
|
cause = ARRAY_ITEM(&causes, i);
|
||||||
|
ctx->print(ctx, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
ARRAY_FREE(&causes);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdq->references++;
|
return (0);
|
||||||
cfg_references++;
|
|
||||||
|
|
||||||
cmdq_continue(cmdq1);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_source_file_done(struct cmd_q *cmdq1)
|
cmd_source_file_free(struct cmd *self)
|
||||||
{
|
{
|
||||||
struct cmd_q *cmdq = cmdq1->data;
|
struct cmd_source_file_data *data = self->data;
|
||||||
|
|
||||||
if (cmdq1->client_exit >= 0)
|
if (data->path != NULL)
|
||||||
cmdq->client_exit = cmdq1->client_exit;
|
xfree(data->path);
|
||||||
|
xfree(data);
|
||||||
cmdq_free(cmdq1);
|
}
|
||||||
|
|
||||||
cfg_references--;
|
size_t
|
||||||
|
cmd_source_file_print(struct cmd *self, char *buf, size_t len)
|
||||||
if (cmdq_free(cmdq))
|
{
|
||||||
return;
|
struct cmd_source_file_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
if (cfg_references == 0)
|
|
||||||
cfg_print_causes(cmdq);
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
cmdq_continue(cmdq);
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->path != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->path);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user