mirror of
https://github.com/tmux/tmux.git
synced 2026-03-12 03:25:45 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be20fc8699 |
20
.gitignore
vendored
20
.gitignore
vendored
@@ -1,20 +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.*
|
|
||||||
*.dSYM
|
|
||||||
37
.mailmap
37
.mailmap
@@ -1,37 +0,0 @@
|
|||||||
Bob Beck <beck@openbsd.org> beck <beck>
|
|
||||||
Claudio Jeker <claudio@openbsd.org> claudio <claudio>
|
|
||||||
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>
|
|
||||||
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>
|
|
||||||
Michael McConville <mmcc@openbsd.org> mmcc <mmcc>
|
|
||||||
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>
|
|
||||||
Sebastien Marie <semarie@openbsd.org> semarie <semarie>
|
|
||||||
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> Theo Deraadt <deraadt@openbsd.org>
|
|
||||||
Theo de Raadt <deraadt@openbsd.org> deraadt <deraadt>
|
|
||||||
Thomas Adam <thomas@xteddy.org> Thomas <thomas@xteddy.org>
|
|
||||||
Thomas Adam <thomas@xteddy.org> Thomas Adam <thomas.adam@smoothwall.net>
|
|
||||||
Thomas Adam <thomas@xteddy.org> n6tadam <n6tadam@xteddy.org>
|
|
||||||
Tim van der Molen <tim@openbsd.org> tim <tim>
|
|
||||||
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
|
|
||||||
879
CHANGES
879
CHANGES
@@ -1,873 +1,3 @@
|
|||||||
CHANGES FROM 2.4 to 2.5 09 May 2017
|
|
||||||
|
|
||||||
* Reset updated flag when restarting #() command so that new output is properly
|
|
||||||
recognised. GitHub issue 922.
|
|
||||||
|
|
||||||
* Fix ECH with a background colour.
|
|
||||||
|
|
||||||
* Do not rely on the terminal not moving the cursor after DL or EL.
|
|
||||||
|
|
||||||
* Fix send-keys and send-prefix in copy-mode (so C-b C-b works). GitHub issue
|
|
||||||
905.
|
|
||||||
|
|
||||||
* Set the current pane for rotate-window so it works in command sequences.
|
|
||||||
|
|
||||||
* Add pane_mode format.
|
|
||||||
|
|
||||||
* Differentiate M-Up from Escape+Up when possible (that is, in terminals with
|
|
||||||
xterm(1) style function keys). GitHub issue 907.
|
|
||||||
|
|
||||||
* Add session_stack and window_stack_index formats.
|
|
||||||
|
|
||||||
* Some new control mode notifications and corresponding hooks:
|
|
||||||
pane-mode-changed, window-pane-changed, client-session-changed,
|
|
||||||
session-window-changed.
|
|
||||||
|
|
||||||
* Format pane_search_string for last search term while in copy mode (useful
|
|
||||||
with command-prompt -I).
|
|
||||||
|
|
||||||
* Fix a problem with high CPU usage and multiple clients with #(). GitHub issue
|
|
||||||
889.
|
|
||||||
|
|
||||||
* Fix UTF-8 combining characters in column 0.
|
|
||||||
|
|
||||||
* Fix reference counting so that panes are properly destroyed and their
|
|
||||||
processes killed.
|
|
||||||
|
|
||||||
* Clamp SU (CSI S) parameter to work around a bug in Konsole.
|
|
||||||
|
|
||||||
* Tweak line wrapping in full width panes to play more nicely with terminal
|
|
||||||
copy and paste.
|
|
||||||
|
|
||||||
* Fix when we emit SGR 0 in capture-pane -e.
|
|
||||||
|
|
||||||
* Do not change TERM until after config file parsing has finished, so that
|
|
||||||
commands run inside the config file can use it to make decisions (typically
|
|
||||||
about default-terminal).
|
|
||||||
|
|
||||||
* Make the initial client wait until config file parsing has finished to avoid
|
|
||||||
racing with commands.
|
|
||||||
|
|
||||||
* Fix core when if-shell fails.
|
|
||||||
|
|
||||||
* Only use ED to clear screen if the pane is at the bottom.
|
|
||||||
|
|
||||||
* Fix multibyte UTF-8 output.
|
|
||||||
|
|
||||||
* Code improvements around target (-t) resolution.
|
|
||||||
|
|
||||||
* Change how the default target (for commands without -t) is managed across
|
|
||||||
command sequences: now it is set up at the start and commands are required
|
|
||||||
to update it if needed. Fixes binding command sequences to mouse keys.
|
|
||||||
|
|
||||||
* Make if-shell from the config file work correctly.
|
|
||||||
|
|
||||||
* Change to always check the root key table if no binding is found in the
|
|
||||||
current table (prefix table or copy-mode table or whatever). This means that
|
|
||||||
root key bindings will take effect even in copy mode, if not overridden by a
|
|
||||||
copy mode key binding.
|
|
||||||
|
|
||||||
* Fix so that the history file works again.
|
|
||||||
|
|
||||||
* Run config file without a client rather than using the first client, restores
|
|
||||||
previous behaviour.
|
|
||||||
|
|
||||||
* If a #() command doesn't exit, continue to read from it and use its last full
|
|
||||||
line of output.
|
|
||||||
|
|
||||||
* Handle slow terminals and fast output better: when the amount of data
|
|
||||||
outstanding gets too large, discard output until it is drained and we are
|
|
||||||
able to do a full redraw. Prevents tmux sitting on a huge buffer that the
|
|
||||||
terminal will take forever to consume.
|
|
||||||
|
|
||||||
* Do not redraw a client unless we realistically think it can accept the data -
|
|
||||||
defer redraws until the client has nothing else waiting to write.
|
|
||||||
|
|
||||||
CHANGES FROM 2.3 to 2.4 20 April 2017
|
|
||||||
|
|
||||||
Incompatible Changes
|
|
||||||
====================
|
|
||||||
|
|
||||||
* Key tables have undergone major changes. Mode key tables are no longer
|
|
||||||
separate from the main key tables. All mode key tables have been removed,
|
|
||||||
together with the -t flag to bind-key and unbind-key.
|
|
||||||
|
|
||||||
The emacs-edit, vi-edit, emacs-choose and vi-choose tables have been replaced
|
|
||||||
by fixed key bindings in the command prompt and choose modes. The mode-keys
|
|
||||||
and status-keys options remain.
|
|
||||||
|
|
||||||
The emacs-copy and vi-copy tables have been replaced by the copy-mode and
|
|
||||||
copy-mode-vi tables. Commands are sent using the -X and -N flags to
|
|
||||||
send-keys. So the following:
|
|
||||||
|
|
||||||
bind -temacs-copy C-Up scroll-up
|
|
||||||
bind -temacs-copy -R5 WheelUpPane scroll-up
|
|
||||||
|
|
||||||
Becomes:
|
|
||||||
|
|
||||||
bind -Tcopy-mode C-Up send -X scroll-up
|
|
||||||
bind -Tcopy-mode WheelUpPane send -N5 -X scroll-up
|
|
||||||
|
|
||||||
These changes allows the full command parser (including command sequences) and
|
|
||||||
command set to be used - for example, the normal command prompt with editing
|
|
||||||
and history is now used for searching, jumping, and so on instead of a custom
|
|
||||||
one. The default C-r binding is now:
|
|
||||||
|
|
||||||
bind -Tcopy-mode C-r command-prompt -p'search up' "send -X search-backward-incremental '%%'"
|
|
||||||
|
|
||||||
There are also some new commmands available with send -X, such as
|
|
||||||
copy-pipe-and-cancel.
|
|
||||||
* set-remain-on-exit has gone -- can be achieved with hooks instead.
|
|
||||||
* Hooks: before hooks have been removed and only a selection of commands now
|
|
||||||
have after hooks (they are no longer automatic). Additional hooks have been
|
|
||||||
added.
|
|
||||||
* The xterm-keys option now defaults to on.
|
|
||||||
|
|
||||||
Normal Changes
|
|
||||||
==============
|
|
||||||
|
|
||||||
* Support for mouse double and triple clicks.
|
|
||||||
* BCE (Background Colour Erase) is now supported.
|
|
||||||
* All occurrences of a search string in copy mode are now highlighted;
|
|
||||||
additionally, the number of search results is displayed. The highlighting
|
|
||||||
updates interactively with the default emacs key bindings (incremental
|
|
||||||
search).
|
|
||||||
* source-file now understands glob patterns.
|
|
||||||
* Formats now have simple comparisons:
|
|
||||||
|
|
||||||
#{==:a,b}
|
|
||||||
#{!=:a,b}
|
|
||||||
|
|
||||||
* There are the following new formats:
|
|
||||||
|
|
||||||
- #{version} -- the tmux server version;
|
|
||||||
- #{client_termtype} -- the terminal type of the client;
|
|
||||||
- #{client_name} -- the name of a client;
|
|
||||||
- #{client_written} -- the number of bytes written to the client.
|
|
||||||
|
|
||||||
* The configuration file now accepts %if/%endif conditional blocks which are
|
|
||||||
processed when it is parsed; the argument is a format string (useful with the
|
|
||||||
new format comparison options).
|
|
||||||
* detach-client now has -E to execute a command replacing the client instead of
|
|
||||||
exiting.
|
|
||||||
* Add support for custom command aliases, this is an array option which
|
|
||||||
contains items of the form "alias=command". This is consulted when an
|
|
||||||
unknown command is parsed.
|
|
||||||
* break-pane now has -n to specify the new window name.
|
|
||||||
* OSC 52 support has been added for programs inside tmux to set a tmux buffer.
|
|
||||||
* The mouse "all event" mode (1003) is now supported.
|
|
||||||
* Palette setting is now possible (OSC 4 and 104).
|
|
||||||
* Strikethrough support (a recent terminfo is required).
|
|
||||||
* Grouped sessions can now be named (new -t).
|
|
||||||
* terminal-overrides and update-environment are now array options (the previous
|
|
||||||
set -ag syntax should work without change).
|
|
||||||
* There have been substantial performance improvements.
|
|
||||||
|
|
||||||
CHANGES FROM 2.2 to 2.3 29 September 2016
|
|
||||||
|
|
||||||
Incompatible Changes
|
|
||||||
====================
|
|
||||||
|
|
||||||
None.
|
|
||||||
|
|
||||||
Normal Changes
|
|
||||||
==============
|
|
||||||
|
|
||||||
* New option 'pane-border-status' to add text in the pane borders.
|
|
||||||
* Support for hooks on commands: 'after' and 'before' hooks.
|
|
||||||
* 'source-file' understands '-q' to suppress errors for nonexistent files.
|
|
||||||
* Lots of UTF8 improvements, especially on MacOS.
|
|
||||||
* 'window-status-separator' understands #[] expansions.
|
|
||||||
* 'split-window' understands '-f' for performing a full-width split.
|
|
||||||
* Allow report count to be specified when using 'bind-key -R'.
|
|
||||||
* 'set -a' for appending to user options (@foo) is now supported.
|
|
||||||
* 'display-panes' can now accept a command to run, rather than always
|
|
||||||
selecting the pane.
|
|
||||||
|
|
||||||
CHANGES FROM 2.1 to 2.2 10 April 2016
|
|
||||||
|
|
||||||
Incompatible Changes
|
|
||||||
====================
|
|
||||||
|
|
||||||
* The format strings which referenced time have been removed. Instead:
|
|
||||||
|
|
||||||
#{t:window_activity}
|
|
||||||
|
|
||||||
can be used.
|
|
||||||
|
|
||||||
* Support for TMPDIR has been removed. Use TMUX_TMPDIR instead.
|
|
||||||
* UTF8 detection now happens automatically if the client supports it, hence
|
|
||||||
the:
|
|
||||||
|
|
||||||
mouse-utf8
|
|
||||||
utf8
|
|
||||||
|
|
||||||
options has been removed.
|
|
||||||
* The:
|
|
||||||
|
|
||||||
mouse_utf8_flag
|
|
||||||
|
|
||||||
format string has been removed.
|
|
||||||
* The -I option to show-messages has been removed. See:
|
|
||||||
|
|
||||||
#{t:start_time}
|
|
||||||
|
|
||||||
format option instead.
|
|
||||||
|
|
||||||
Normal Changes
|
|
||||||
==============
|
|
||||||
|
|
||||||
* Panes are unzoomed with selectp -LRUD
|
|
||||||
* New formats added:
|
|
||||||
|
|
||||||
#{scroll_position}
|
|
||||||
#{socket_path}
|
|
||||||
#{=10:...} -- limit to N characters (from the start)
|
|
||||||
#{=-10:...} -- limit to N characters (from the end)
|
|
||||||
#{t:...} -- used to format time-based formats
|
|
||||||
#{b:...} -- used to ascertain basename from string
|
|
||||||
#{d:...} -- used to ascertain dirname from string
|
|
||||||
#{s:...} -- used to perform substitutions on a string
|
|
||||||
|
|
||||||
* Job output is run via the format system, so formats work again
|
|
||||||
* If display-time is set to 0, then the indicators wait for a key to be
|
|
||||||
pressed.
|
|
||||||
* list-keys and list-commands can be run without starting the tmux server.
|
|
||||||
* kill-session learns -C to clear all alerts in all windows of the session.
|
|
||||||
* Support for hooks (internal for now), but hooks for the following have been
|
|
||||||
implemented:
|
|
||||||
|
|
||||||
alert-bell
|
|
||||||
alert-silence
|
|
||||||
alert-activity
|
|
||||||
client-attached
|
|
||||||
client-detached
|
|
||||||
client-resized
|
|
||||||
pane-died
|
|
||||||
pane-exited
|
|
||||||
|
|
||||||
* RGB (24bit) colour support. The 'Tc' flag must be set in the external TERM
|
|
||||||
entry (using terminal-overrides or a custom terminfo entry).
|
|
||||||
|
|
||||||
|
|
||||||
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_synchronized} format specifier has been added to be a conditional
|
|
||||||
format if a pane is in a synchronised mode (c.f. synchronize-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
|
|
||||||
|
|
||||||
* Window bell reporting fixed.
|
|
||||||
* Show which pane is active in the list-panes output.
|
|
||||||
* Backoff reworked.
|
|
||||||
* Prevent the server from dying when switching into copy mode when already
|
|
||||||
in a different mode.
|
|
||||||
* Reset running jobs when the status line is enabled or disabled.
|
|
||||||
* Simplify xterm modifier detection.
|
|
||||||
* Avoid crashing in copy mode if the screen size is too small for the
|
|
||||||
indicator.
|
|
||||||
* Flags -n and -p added to switch-client.
|
|
||||||
* Use UTF-8 line drawing characters on UTF-8 terminals, thus fixing some
|
|
||||||
terminals (eg putty) which disable the vt100 ACS mode switching sequences
|
|
||||||
in UTF-8 mode. On terminals without ACS, use ASCII equivalents.
|
|
||||||
* New server option exit-unattached added.
|
|
||||||
* New session option destroy-unattached added.
|
|
||||||
* Fall back on normal session choice method if $TMUX exists but is invalid
|
|
||||||
rather than rejecting.
|
|
||||||
* Mark repeating keys with "(repeat)" in the key list.
|
|
||||||
* When removing a pane, don't change the active pane unless the active pane
|
|
||||||
is actually the one being removed.
|
|
||||||
* New command last-pane added.
|
|
||||||
* AIX fixes.
|
|
||||||
* Flag -a added to unbind-key.
|
|
||||||
* Add XAUTHORITY to update-environment.
|
|
||||||
* More info regarding window and pane flags is now shown in list-*.
|
|
||||||
* If VISUAL or EDITOR contains "vi" configure mode-keys and status-key to vi.
|
|
||||||
* New window option monitor-silence and session option visual-silence added.
|
|
||||||
* In the built-in layouts distribute the panes more evenly.
|
|
||||||
* Set the default value of main-pane-width to 80 instead of 81.
|
|
||||||
* Command-line flag -V added.
|
|
||||||
* Instead of keeping a per-client prompt history make it global.
|
|
||||||
* Fix rectangle copy to behave like emacs (the cursor is not part of the
|
|
||||||
selection on the right edge but on the left it is).
|
|
||||||
* Flag -l added to switch-client.
|
|
||||||
* Retrieve environment variables from the global environment rather than
|
|
||||||
getenv(3), thus allowing them to be updated during the configuration file.
|
|
||||||
* New window options other-pane-{height,width} added.
|
|
||||||
* More minor bugs fixed and manpage improvements.
|
|
||||||
|
|
||||||
CHANGES FROM 1.2 TO 1.3, 18 July 2010
|
|
||||||
|
|
||||||
* New input parser.
|
|
||||||
* Flags to move through panes -UDLR added to select-pane.
|
|
||||||
* Commands up-pane, and down-pane removed, since equivalent behaviour is now
|
|
||||||
available through the target flag (-t:+ and -t:-).
|
|
||||||
* Jump-forward/backward in copy move (based on vi's F, and f commands).
|
|
||||||
* Make paste-buffer accept a pane as a target.
|
|
||||||
* Flag -a added to new-window to insert a window after an existing one, moving
|
|
||||||
windows up if necessary.
|
|
||||||
* Merge more mode into copy mode.
|
|
||||||
* Run job commands explicitly in the global environment (which can be modified
|
|
||||||
with setenv -g), rather than with the environment tmux started with.
|
|
||||||
* Use the machine's hostname as the default title, instead of an empty string.
|
|
||||||
* Prevent double free if the window option remain-on-exit is set.
|
|
||||||
* Key string conversions rewritten.
|
|
||||||
* Mark zombie windows as dead in the choose-window list.
|
|
||||||
* Tiled layout added.
|
|
||||||
* Signal handling reworked.
|
|
||||||
* Reset SIGCHLD after fork to fix problems with some shells.
|
|
||||||
* Select-prompt command removed. Therefore, bound ' to command-prompt -p index
|
|
||||||
"select-window -t:%%" by default.
|
|
||||||
* Catch SIGHUP and terminate if running as a client, thus avoiding clients from
|
|
||||||
being left hanging around when, for instance, a SSH session is disconnected.
|
|
||||||
* Solaris 9 fixes (such as adding compat {get,set}env(3) code).
|
|
||||||
* Accept none instead of default for attributes.
|
|
||||||
* Window options window-status-alert-{alert,bg,fg} added.
|
|
||||||
* Flag -s added to the paste-buffer command to specify a custom separator.
|
|
||||||
* Allow dragging to make a selection in copy mode if the mode-mouse option is
|
|
||||||
set.
|
|
||||||
* Support the mouse scroll wheel.
|
|
||||||
* Make pipe-pane accept special character sequences (eg #I).
|
|
||||||
* Fix problems with window sizing when starting tmux from .xinitrc.
|
|
||||||
* Give tmux sockets (but not the containing folder) group permissions.
|
|
||||||
* Extend the target flags (ie -t) to accept an offset (for example -t:+2), and
|
|
||||||
make it wrap windows, and panes.
|
|
||||||
* New command choose-buffer added.
|
|
||||||
* New server option detach-on-destroy to set what happens to a client when the
|
|
||||||
session it is attached to is destroyed. If on (default), the client is
|
|
||||||
detached. Otherwise, the client is switched to the most recently active of
|
|
||||||
the remaining sessions.
|
|
||||||
* The commands load-buffer, and save-buffer now accept a dash (-) as the file
|
|
||||||
to read from stdin, or write to stdout.
|
|
||||||
* Custom layouts added.
|
|
||||||
* Additional code reduction, bug fixes, and manpage enhancements.
|
|
||||||
|
|
||||||
CHANGES FROM 1.1 TO 1.2, 10 March 2010
|
|
||||||
|
|
||||||
* Switch to libevent.
|
|
||||||
* Emulate the ri (reverse index) capability, ergo allowing tmux to at least
|
|
||||||
start on Sun consoles (TERM=sun, or sun-color).
|
|
||||||
* Assign each entry a number, or lowercase letter in choose mode, and accept
|
|
||||||
that as a shortcut key.
|
|
||||||
* Permit top-bit-set characters to be entered in the status line.
|
|
||||||
* Mark no-prefix keys with (no prefix), rather than [] in list-keys.
|
|
||||||
* New command show-messages (alias showmsgs), and new session option
|
|
||||||
message-limit, to show a per-client log of status lines messages up to the
|
|
||||||
number defined by message-limit.
|
|
||||||
* Do not interpret #() for display-message to avoid leaking commands.
|
|
||||||
* New window options window-status-format, and window-status-current-format to
|
|
||||||
control the format of each window in the status line.
|
|
||||||
* Add a -p flag to display-message to print the output, instead of displaying
|
|
||||||
it in the status line.
|
|
||||||
* Emulate il1, dl1, ich1 to run with vt100 feature set.
|
|
||||||
* New command capture-pane (alias capturep) to copy the entire pane contents
|
|
||||||
to a paste buffer.
|
|
||||||
* Avoid duplicating code by adding a -w flag to set-option, and show-options to
|
|
||||||
set, and show window options. The commands set-window-option, and
|
|
||||||
show-window-options are now aliases.
|
|
||||||
* Panes can now be referred to as top, bottom, top-left, etc.
|
|
||||||
* Add server-wide options, which can be set with set-option -s, and shown with
|
|
||||||
show-options -s.
|
|
||||||
* New server option quiet (like -q from the command line).
|
|
||||||
* New server option escape-time to set the timeout used to detect if escapes
|
|
||||||
are alone, part of a function key, or meta sequence.
|
|
||||||
* New session options pane-active-border-bg, pane-active-border-fg,
|
|
||||||
pane-border-bg, and pane-border-fg to set pane colours.
|
|
||||||
* Make split-window accept a pane target, instead of a window.
|
|
||||||
* New command join-pane (alias joinp) to split, and move an existing pane into
|
|
||||||
the space (the opposite of break-pane), thus simplifying calls to
|
|
||||||
split-window, followed by move-window.
|
|
||||||
* Permit S- prefix on keys for shift when the terminal/terminfo supports them.
|
|
||||||
* Window targets (-t flag) can now refer to the last window (!), next (+), and
|
|
||||||
previous (-) window by number.
|
|
||||||
* Mode keys to jump to the bottom/top of history, end of the next word, scroll
|
|
||||||
up/down, and reverse search in copy mode.
|
|
||||||
* New session option display-panes-active-colour to display the active pane in
|
|
||||||
a different colour with the display-panes command.
|
|
||||||
* Read the socket path from $TMUX if it's present, and -L, and -S are not
|
|
||||||
given.
|
|
||||||
* Vi-style mode keys B, W, and E to navigate between words in copy mode.
|
|
||||||
* Start in more mode when configuration file errors are detected.
|
|
||||||
* Rectangle copy support added.
|
|
||||||
* If attach-session was specified with the -r flag, make the client read-only.
|
|
||||||
* Per-window alternate-screen option.
|
|
||||||
* Make load-buffer work with FIFOs.
|
|
||||||
* New window option word-separators to set the characters considered as word
|
|
||||||
separators in copy mode.
|
|
||||||
* Permit keys in copy mode to be prefixed by a repeat count, entered with [1-9]
|
|
||||||
in vi mode, or M-[1-9] in emacs mode.
|
|
||||||
* utf8 improvements.
|
|
||||||
* As usual, additional code reduction, bug fixes, and manpage enhancements.
|
|
||||||
|
|
||||||
CHANGES FROM 1.0 TO 1.1, 05 November 2009
|
|
||||||
|
|
||||||
* New run-shell (alias run) command to run an external command without a
|
|
||||||
window, capture it's stdout, and send it to output mode.
|
|
||||||
* Ability to define multiple prefix keys.
|
|
||||||
* Internal locking mechanism removed. Instead, detach each client and run the
|
|
||||||
external command specified in the new session option lock-command (by default
|
|
||||||
lock -np), thus allowing the system password to be used.
|
|
||||||
* set-password command, and -U command line flag removed per the above change.
|
|
||||||
* Add support for -c command line flag to execute a shell command.
|
|
||||||
* New lock-client (alias lockc), and lock-session (alias locks) commands to
|
|
||||||
lock a particular client, or all clients attached to a session.
|
|
||||||
* Support C-n/C-p/C-v/M-v with emacs keys in choice mode.
|
|
||||||
* Use : for goto line rather than g in vi mode.
|
|
||||||
* Try to guess which client to use when no target client was specified. Finds
|
|
||||||
the current session, and if only one client is present, use it. Otherwise,
|
|
||||||
return the most recently used client.
|
|
||||||
* Make C-Down/C-Up in copy mode scroll the screen down/up one line without
|
|
||||||
moving the cursor.
|
|
||||||
* Scroll mode superseded by copy mode.
|
|
||||||
* New synchronize-panes window option to send all input to all other panes in
|
|
||||||
the same window.
|
|
||||||
* New lock-server session option to lock, when off (on by default), each
|
|
||||||
session when it has been idle for the lock-after-time setting. When on, the
|
|
||||||
entire server locks when all sessions have been idle for their individual
|
|
||||||
lock-after-time setting.
|
|
||||||
* Add support for grouped sessions which have independent name, options,
|
|
||||||
current window, but where the linked windows are synchronized (ie creating,
|
|
||||||
killing windows are mirrored between the sessions). A grouped session may be
|
|
||||||
created by passing -t to new-session.
|
|
||||||
* New mouse-select-pane session option to select the current pane with the
|
|
||||||
mouse.
|
|
||||||
* Queue, and run commands in the background for if-shell, status-left,
|
|
||||||
status-right, and #() by starting each once every status-interval. Adds the
|
|
||||||
capability to call some programs which would previously cause the server to
|
|
||||||
hang (eg sleep/tmux). It also avoids running commands excessively (ie if used
|
|
||||||
multiple times, it will be run only once).
|
|
||||||
* When a window is zombified and automatic-rename is on, append [dead] to the
|
|
||||||
name.
|
|
||||||
* Split list-panes (alias lsp) off from list-windows.
|
|
||||||
* New pipe-pane (alias pipep) to redirect a pane output to an external command.
|
|
||||||
* Support for automatic-renames for Solaris.
|
|
||||||
* Permit attributes to be turned off in #[] by prefixing with no (eg nobright).
|
|
||||||
* Add H/M/L in vi mode, and M-R/M-r in emacs to move the cursor to the top,
|
|
||||||
middle, and bottom of the screen.
|
|
||||||
* -a option added to kill-pane to kill all except current pane.
|
|
||||||
* The -d command line flag is now gone (can be replaced by terminal-overrides).
|
|
||||||
Just use op/AX to detect default colours.
|
|
||||||
* input/tty/utf8 improvements.
|
|
||||||
* xterm-keys rewrite.
|
|
||||||
* Additional code reduction, and bug fixes.
|
|
||||||
|
|
||||||
CHANGES FROM 0.9 TO 1.0, 20 Sept 2009
|
CHANGES FROM 0.9 TO 1.0, 20 Sept 2009
|
||||||
|
|
||||||
* Option to alter the format of the window title set by tmux.
|
* Option to alter the format of the window title set by tmux.
|
||||||
@@ -1204,7 +334,7 @@ The list of older changes is below.
|
|||||||
* -u flag to scroll-mode and copy-mode to start scrolled one page
|
* -u flag to scroll-mode and copy-mode to start scrolled one page
|
||||||
up. scroll-mode -u is bound to prefix,page-up (ppage) by default.
|
up. scroll-mode -u is bound to prefix,page-up (ppage) by default.
|
||||||
* Allow status, mode and message attributes to be changed by three new options:
|
* Allow status, mode and message attributes to be changed by three new options:
|
||||||
status-attr, mode-attr, message-attr. A comma-separated list is accepted
|
status-attr, mode-attr, message-attr. A comma-separataed list is accepted
|
||||||
containing: bright, dim, underscore, blink, reverse, hidden, italics, for
|
containing: bright, dim, underscore, blink, reverse, hidden, italics, for
|
||||||
example:
|
example:
|
||||||
|
|
||||||
@@ -2227,3 +1357,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.300 2009-09-20 18:54:21 nicm Exp $
|
||||||
|
|
||||||
|
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
|
||||||
|
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
|
||||||
|
LocalWords: dstidx srcname srcidx winlink lsw nabc sabc Exp Tiago Cunha dch
|
||||||
|
LocalWords: setw Chisnall renamew merdely eg Maier newname selectw neww Gass
|
||||||
|
|||||||
33
CONTRIBUTING
33
CONTRIBUTING
@@ -1,33 +0,0 @@
|
|||||||
When reporting issues:
|
|
||||||
|
|
||||||
YOU MUST INCLUDE THE TMUX VERSION
|
|
||||||
|
|
||||||
DO NOT OPEN AN ISSUE THAT DOES NOT MENTION THE TMUX VERSION
|
|
||||||
|
|
||||||
Please also include:
|
|
||||||
|
|
||||||
- your platform (Linux, OS X, or whatever);
|
|
||||||
- a brief description of the problem with steps to reproduce;
|
|
||||||
- a minimal tmux config, if you can't reproduce without a config;
|
|
||||||
- your terminal, and $TERM inside and outside of tmux;
|
|
||||||
- logs from tmux (see below);
|
|
||||||
- at most one or two screenshots, if helpful.
|
|
||||||
|
|
||||||
This should include at least the output of:
|
|
||||||
|
|
||||||
$ uname -sp && tmux -V && echo $TERM
|
|
||||||
|
|
||||||
Please do not report bugs (crashes, incorrect behaviour) without reproducing on
|
|
||||||
a tmux built from Git master.
|
|
||||||
|
|
||||||
Note that TERM inside tmux must be a variant of screen or tmux (for example:
|
|
||||||
screen or screen-256color, tmux or tmux-256color). Please ensure this is the
|
|
||||||
case before opening an issue.
|
|
||||||
|
|
||||||
To run tmux without a config and get logs, run:
|
|
||||||
|
|
||||||
tmux -Ltest kill-server
|
|
||||||
tmux -vvvv -Ltest -f/dev/null new
|
|
||||||
|
|
||||||
Then reproduce the problem, exit tmux, and attach the tmux-server-*.log file
|
|
||||||
from the current directory to the issue.
|
|
||||||
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.
|
|
||||||
318
FAQ
318
FAQ
@@ -1,116 +1,33 @@
|
|||||||
tmux frequently asked questions
|
tmux frequently asked questions
|
||||||
|
|
||||||
******************************************************************************
|
* How is tmux different from GNU screen? What else does it offer?
|
||||||
* PLEASE NOTE: most display problems are due to incorrect TERM! Before *
|
|
||||||
* reporting problems make SURE that TERM settings are correct inside and *
|
|
||||||
* outside tmux. *
|
|
||||||
* *
|
|
||||||
* Inside tmux TERM must be "screen" or similar (such as "screen-256color"). *
|
|
||||||
* Don't bother reporting problems where it isn't! *
|
|
||||||
* *
|
|
||||||
* Outside, it must match your terminal: particularly, use "rxvt" for rxvt *
|
|
||||||
* and derivatives. *
|
|
||||||
******************************************************************************
|
|
||||||
|
|
||||||
* How is tmux different from GNU screen?
|
tmux offers several advantages over screen:
|
||||||
|
|
||||||
tmux and GNU screen have many similarities. Some of the main differences I am
|
- a clearly-defined client-server model: windows are independent entities which
|
||||||
aware of are (bearing in mind I haven't used screen for a few years now):
|
may be attached simultaneously to multiple sessions and viewed from multiple
|
||||||
|
clients (terminals), as well as moved freely between sessions within the same
|
||||||
|
tmux server;
|
||||||
|
- a consistent, well-documented command interface, with the same syntax
|
||||||
|
whether used interactively, as a key binding, or from the shell;
|
||||||
|
- easily scriptable from the shell;
|
||||||
|
- multiple paste buffers;
|
||||||
|
- choice of vi or emacs key layouts;
|
||||||
|
- an option to limit the window size;
|
||||||
|
- a more usable status line syntax, with the ability to display the first line
|
||||||
|
of output of a specific command;
|
||||||
|
- a cleaner, modern, easily extended, BSD-licensed codebase.
|
||||||
|
|
||||||
- tmux uses a client-server model. Each server has single Unix domain socket in
|
There are still a few features screen includes that tmux omits:
|
||||||
/tmp and within one server there are multiple sessions which may be attached
|
|
||||||
to multiple clients (terminals).
|
|
||||||
|
|
||||||
This has advantages, notably: windows may be linked simultaneously to
|
- builtin serial and telnet support; this is bloat and is unlikely to be added
|
||||||
multiple sessions; windows may be moved freely between sessions; and a client
|
to tmux;
|
||||||
may be switched between sessions easily (C-b D). There is one major
|
- wider platform support, for example IRIX and HP-UX, and for odd terminals.
|
||||||
disadvantage: if the server crashes, game over, all sessions die. In
|
|
||||||
practice, however, tmux is quite stable and gets more so as people report any
|
|
||||||
bugs they hit :-).
|
|
||||||
|
|
||||||
This model is different from screen, where typically each new screen instance
|
|
||||||
is independent. tmux supports the same behaviour by using multiple servers
|
|
||||||
with the -L option but it is not typically recommended.
|
|
||||||
|
|
||||||
- Different command interfaces. One of the goals of tmux is that the shell
|
|
||||||
should be easily usable as a scripting language - almost all tmux commands
|
|
||||||
can be used from the shell and behave identically whether used from the
|
|
||||||
shell, from a key binding or from the command prompt. Personally I also find
|
|
||||||
tmux's command interface much more consistent and clearer, but this is
|
|
||||||
subjective.
|
|
||||||
|
|
||||||
- tmux calls window names (what you see in the status line) "names", screen
|
|
||||||
calls them "titles".
|
|
||||||
|
|
||||||
- tmux has a multiple paste buffers. Not a major one but comes in handy quite a
|
|
||||||
lot.
|
|
||||||
|
|
||||||
- tmux supports automatically renaming windows to the running application
|
|
||||||
without gross hacks using escape sequences. Its even on by default.
|
|
||||||
|
|
||||||
- tmux has a choice of vi or emacs key layouts. Again, not major, but I use
|
|
||||||
emacs so if tmux did support only one key set it would be emacs and then all
|
|
||||||
the vi users would get humpy. Key bindings may be completely reconfigured in
|
|
||||||
any case.
|
|
||||||
|
|
||||||
- tmux has an option to limit the window size.
|
|
||||||
|
|
||||||
- tmux has search in windows (C-b f).
|
|
||||||
|
|
||||||
- The window split (pane) model is different. tmux has two objects, windows and
|
|
||||||
panes; screen has just windows. This difference has several implications:
|
|
||||||
|
|
||||||
* In screen you can have a window appear in several layouts, in tmux a pane
|
|
||||||
can only be in one window (fixing this is a big todo item but quite
|
|
||||||
invasive).
|
|
||||||
|
|
||||||
* tmux layouts are immutable and do not get changed unless you modify them.
|
|
||||||
|
|
||||||
* In tmux, all panes are closed when you kill a window.
|
|
||||||
|
|
||||||
* tmux panes do not have individual names, titles and so on.
|
|
||||||
|
|
||||||
I think tmux's model is much easier to manage and navigate within a window,
|
|
||||||
but breaking panes off from and joining them to windows is more clumsy.
|
|
||||||
|
|
||||||
tmux also has support for preset pane layouts.
|
|
||||||
|
|
||||||
- tmux's status line syntax is more readable and easier to use. I think it'd be
|
|
||||||
hard for anyone to argue with this. tmux doesn't support running a command
|
|
||||||
constantly and always using the last line of its output, commands must be run
|
|
||||||
again each time.
|
|
||||||
|
|
||||||
- tmux has modern, easily extended code. Again hard to argue screen is better
|
|
||||||
if you have looked at the code.
|
|
||||||
|
|
||||||
- tmux depends on libevent. I don't see this as a disadvantage: libevent is
|
|
||||||
small and portable, and on modern systems with current package management
|
|
||||||
systems dependencies are not an issue. libevent brings advantages in code
|
|
||||||
simplicity and performance.
|
|
||||||
|
|
||||||
- screen allows the window to be bigger than the terminal and can pan around
|
|
||||||
it. tmux limits the size to the largest attached client. This is a big todo
|
|
||||||
item for tmux but it is not trivial.
|
|
||||||
|
|
||||||
- screen has builtin serial and telnet support; this is bloat and is unlikely
|
|
||||||
to be added to tmux.
|
|
||||||
|
|
||||||
- Environment handling is different.
|
|
||||||
|
|
||||||
- tmux tends to be more demanding on the terminal so tends to show up terminal
|
|
||||||
and application bugs which screen does not.
|
|
||||||
|
|
||||||
- screen has wider platform support, for example IRIX, 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. Please
|
||||||
reproducible. Sometimes the length of time between releases means a lot of
|
include as much of the following information as possible:
|
||||||
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:
|
|
||||||
|
|
||||||
- the version of tmux you are running;
|
- the version of tmux you are running;
|
||||||
- the operating system you are using and its version;
|
- the operating system you are using and its version;
|
||||||
@@ -123,7 +40,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.
|
||||||
|
|
||||||
@@ -165,17 +82,19 @@ default) to the new key. For example:
|
|||||||
|
|
||||||
* How do I use UTF-8?
|
* How do I use UTF-8?
|
||||||
|
|
||||||
When running tmux in a UTF-8 capable terminal, UTF-8 must be turned on in tmux;
|
When running tmux in a UTF-8 capable terminal, two things must be done to
|
||||||
as of release 0.9, tmux attempts to autodetect a UTF-8-capable terminal by
|
enable support. UTF-8 must be turned on in tmux; this may be done separately
|
||||||
|
for each tmux window or globally by setting the "utf8" flag:
|
||||||
|
|
||||||
|
setw -g utf8 on
|
||||||
|
|
||||||
|
As of release 0.9, tmux attempts to autodetect a UTF-8-capable terminal by
|
||||||
checking the LC_ALL, LC_CTYPE and LANG environment variables. list-clients may
|
checking the LC_ALL, LC_CTYPE and LANG environment variables. list-clients may
|
||||||
be used to check if this is detected correctly; if not, the -u command-line
|
be used to check if this is detected correctly; if not, the -u command-line
|
||||||
flag may be specified when creating or attaching a client to a tmux session:
|
flag may be specified when creating or attaching a client to a tmux session:
|
||||||
|
|
||||||
$ tmux -u new
|
$ tmux -u new
|
||||||
|
|
||||||
Since the 1.0 release, tmux will turn on UTF-8 related options automatically
|
|
||||||
(ie status-utf8, and utf8) if the above conditions are met.
|
|
||||||
|
|
||||||
* How do I use a 256 colour terminal?
|
* How do I use a 256 colour terminal?
|
||||||
|
|
||||||
Provided the underlying terminal supports 256 colours, it is usually sufficient
|
Provided the underlying terminal supports 256 colours, it is usually sufficient
|
||||||
@@ -237,33 +156,6 @@ the ctrl (bit 5 set, for example ^[[5~ to ^[[5^) modifier in non-xterm(1) mode;
|
|||||||
it may be possible to configure vim to accept these, an example of how to do so
|
it may be possible to configure vim to accept these, an example of how to do so
|
||||||
would be welcome.
|
would be welcome.
|
||||||
|
|
||||||
vim users may also want to set the "ttyfast" option inside tmux.
|
|
||||||
|
|
||||||
* How do I make ctrl and shift arrow keys work in emacs?
|
|
||||||
|
|
||||||
The terminal-init-screen function in term/screen.el is called for new frames,
|
|
||||||
but it doesn't configure any function keys.
|
|
||||||
|
|
||||||
If the tmux xterm-keys option is on, it is enough to define the same keys as
|
|
||||||
xterm. Add the following to init.el or .emacs to do this:
|
|
||||||
|
|
||||||
(defadvice terminal-init-screen
|
|
||||||
;; The advice is named `tmux', and is run before `terminal-init-screen' runs.
|
|
||||||
(before tmux activate)
|
|
||||||
;; Docstring. This describes the advice and is made available inside emacs;
|
|
||||||
;; for example when doing C-h f terminal-init-screen RET
|
|
||||||
"Apply xterm keymap, allowing use of keys passed through tmux."
|
|
||||||
;; This is the elisp code that is run before `terminal-init-screen'.
|
|
||||||
(if (getenv "TMUX")
|
|
||||||
(let ((map (copy-keymap xterm-function-map)))
|
|
||||||
(set-keymap-parent map (keymap-parent input-decode-map))
|
|
||||||
(set-keymap-parent input-decode-map map))))
|
|
||||||
|
|
||||||
And ensure .tmux.conf contains "set -g xterm-keys on".
|
|
||||||
|
|
||||||
Alternatively, the screen.el file can be copied to the load path and
|
|
||||||
customized.
|
|
||||||
|
|
||||||
* Why doesn't elinks set the window title inside tmux?
|
* 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
|
||||||
@@ -309,154 +201,4 @@ on the Window -> Translation configuration page. For example, change UTF-8 to
|
|||||||
ISO-8859-1 or CP437. It may also be necessary to adjust the way PuTTY treats
|
ISO-8859-1 or CP437. It may also be necessary to adjust the way PuTTY treats
|
||||||
line drawing characters in the lower part of the same configuration page.
|
line drawing characters in the lower part of the same configuration page.
|
||||||
|
|
||||||
* What is the best way to display the load average? Why no #L?
|
$Id: FAQ,v 1.29 2009-08-08 20:46:26 nicm Exp $
|
||||||
|
|
||||||
It isn't possible to get the load average portably in code and it is preferable
|
|
||||||
not to add portability goop. The following works on at least Linux, *BSD and OS
|
|
||||||
X:
|
|
||||||
|
|
||||||
uptime|awk '{split(substr($0, index($0, "load")), a, ":"); print a[2]}'
|
|
||||||
|
|
||||||
* How do I attach the same session to multiple clients but with a different
|
|
||||||
current window, like screen -x?
|
|
||||||
|
|
||||||
One or more of the windows can be linked into multiple sessions manually with
|
|
||||||
link-window, or a grouped session with all the windows can be created with
|
|
||||||
new-session -t.
|
|
||||||
|
|
||||||
* Ctrl and arrow keys doesn't work in putty! What do I do?
|
|
||||||
|
|
||||||
putty inverts the sense of the cursor key mode on ctrl, which is a bit hard for
|
|
||||||
tmux to detect properly. To get ctrl keys right, change the terminfo settings
|
|
||||||
so kUP5 (Ctrl-Up etc) are the adjusted versions, and disable smkx/rmkx so tmux
|
|
||||||
doesn't change the mode. For example with this line in .tmux.conf (assuming you
|
|
||||||
have TERM set to xterm):
|
|
||||||
|
|
||||||
set -g terminal-overrides "xterm*:kLFT5=\eOD:kRIT5=\eOC:kUP5=\eOA:kDN5=\eOB:smkx@:rmkx@"
|
|
||||||
|
|
||||||
Note that this will only work in tmux 1.2 and above.
|
|
||||||
|
|
||||||
* How can I blank the tmux window?
|
|
||||||
|
|
||||||
GNU screen has a feature whereby it will blank the screen after a period of
|
|
||||||
inactivity. To do the same thing in tmux, use the lock-command setting, for
|
|
||||||
example (with GNU bash):
|
|
||||||
|
|
||||||
set -g lock-command 'tput civis && read -s -n1'
|
|
||||||
|
|
||||||
This will remove the cursor and tell the shell to quit once a key has been
|
|
||||||
pressed. For zsh, use "read -s -k1".
|
|
||||||
|
|
||||||
In addition, it's possible to have both blanking and locking (for instance via
|
|
||||||
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'
|
|
||||||
|
|
||||||
* I don't see italics! Or less and vim show italics and reverse the wrong way round!
|
|
||||||
|
|
||||||
GNU screen does not support italics and the "screen" terminfo description uses
|
|
||||||
the italics escape sequence incorrectly.
|
|
||||||
|
|
||||||
As of tmux 2.1, if default-terminal is set to "screen" or matches "screen-*",
|
|
||||||
tmux will behave like screen and italics will be disabled.
|
|
||||||
|
|
||||||
To enable italics, create a new terminfo entry called "tmux" (some platforms
|
|
||||||
may already have this, you can check with "infocmp tmux"):
|
|
||||||
|
|
||||||
$ cat <<EOF|tic -x -
|
|
||||||
tmux|tmux terminal multiplexer,
|
|
||||||
ritm=\E[23m, rmso=\E[27m, sitm=\E[3m, smso=\E[7m, Ms@,
|
|
||||||
use=xterm+tmux, use=screen,
|
|
||||||
|
|
||||||
tmux-256color|tmux with 256 colors,
|
|
||||||
use=xterm+256setaf, use=tmux,
|
|
||||||
EOF
|
|
||||||
$
|
|
||||||
|
|
||||||
And tell tmux to use it in ~/.tmux.conf:
|
|
||||||
|
|
||||||
set -g default-terminal "tmux"
|
|
||||||
|
|
||||||
If using urxvt, make sure you have an italics capable font enabled. for
|
|
||||||
example, add to ~/.Xdefaults:
|
|
||||||
|
|
||||||
urxvt.italicFont: xft:Bitstream Vera Sans Mono:italic:autohint=true
|
|
||||||
|
|
||||||
* How can I make tmux use my terminal's scrollback buffer?
|
|
||||||
|
|
||||||
Normally, tmux enables the terminal's "alternate screen". Most terminals (such
|
|
||||||
as xterm) do not save scrollback for the alternate screen. You might prefer
|
|
||||||
tmux to use the normal screen, so it uses your terminal's scrollback
|
|
||||||
buffer. This way, you can access the scrollback buffer as usual, for example
|
|
||||||
using the mouse wheel - although there is no guarantee output inside tmux will
|
|
||||||
always (or ever) be added to the scrollback.
|
|
||||||
|
|
||||||
You can make tmux use the normal screen by telling it that your terminal does
|
|
||||||
not have an alternate screen. Put the following in ~/.tmux.conf:
|
|
||||||
|
|
||||||
set -ga terminal-overrides ',xterm*:smcup@:rmcup@'
|
|
||||||
|
|
||||||
Adjust if your $TERM does not start with xterm.
|
|
||||||
|
|
||||||
tmux will still emulate the alternate screen for applications run under tmux,
|
|
||||||
so you don't really lose anything with this setting. The only disadvantage is
|
|
||||||
that when you exit tmux, it will not restore whatever was there before you
|
|
||||||
started.
|
|
||||||
|
|
||||||
* How do I see the default configuration?
|
|
||||||
|
|
||||||
Show the default session options by starting a new tmux server with no
|
|
||||||
configuration file:
|
|
||||||
|
|
||||||
$ tmux -Lfoo -f/dev/null start\; show -g
|
|
||||||
|
|
||||||
Or the default window options:
|
|
||||||
|
|
||||||
$ tmux -Lfoo -f/dev/null start\; show -gw
|
|
||||||
|
|
||||||
* 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, look at the pbcopy(1) and pbpaste(1) commands.
|
|
||||||
|
|
||||||
* Why don't some commands work inside tmux on OS X?
|
|
||||||
|
|
||||||
Apple requires some undocumented, unsupported fiddling to allow commands that
|
|
||||||
interact with the GUI to work. Neither tmux itself nor most shells do this, so
|
|
||||||
an external program is required. This can be found here:
|
|
||||||
|
|
||||||
https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
|
|
||||||
|
|
||||||
Affected commands may include say(1), pbcopy(1), pbpaste(1) and ssh(1).
|
|
||||||
|
|
||||||
* Why do I see dots around a session when I attach to it?
|
|
||||||
|
|
||||||
tmux limits the size of the window to the smallest attached session. If
|
|
||||||
it didn't do this then it would be impossible to see the entire window.
|
|
||||||
The dots mark the size of the window tmux can display.
|
|
||||||
|
|
||||||
To avoid this, detach all other clients when attaching:
|
|
||||||
|
|
||||||
$ tmux attach -d
|
|
||||||
|
|
||||||
Or from inside tmux by detaching individual clients with C-b D or all
|
|
||||||
using:
|
|
||||||
|
|
||||||
C-b : attach -d
|
|
||||||
|
|||||||
65
GNUmakefile
Normal file
65
GNUmakefile
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
# $Id: GNUmakefile,v 1.114 2009-09-20 18:54:21 nicm Exp $
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
VERSION= 1.0
|
||||||
|
|
||||||
|
#FDEBUG= 1
|
||||||
|
|
||||||
|
CC?= gcc
|
||||||
|
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...
|
||||||
|
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
|
||||||
|
INSTALLDIR= install -d
|
||||||
|
INSTALLBIN= install -g bin -o root -m 555
|
||||||
|
INSTALLMAN= install -g bin -o root -m 444
|
||||||
|
|
||||||
|
SRCS= $(shell echo *.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
|
||||||
|
|
||||||
|
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
|
||||||
@@ -1 +0,0 @@
|
|||||||
Please read https://raw.githubusercontent.com/tmux/tmux/master/CONTRIBUTING
|
|
||||||
68
Makefile
Normal file
68
Makefile
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# $Id: Makefile,v 1.149 2009-09-20 18:54:21 nicm Exp $
|
||||||
|
|
||||||
|
.SUFFIXES: .c .o
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
VERSION= 1.0
|
||||||
|
|
||||||
|
#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
|
||||||
|
INSTALLDIR= install -d
|
||||||
|
INSTALLBIN= install -g bin -o root -m 555
|
||||||
|
INSTALLMAN= install -g bin -o root -m 444
|
||||||
|
|
||||||
|
SRCS!= echo *.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
|
||||||
|
|
||||||
|
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/
|
||||||
202
Makefile.am
202
Makefile.am
@@ -1,202 +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 example_tmux.conf compat/*.[ch] \
|
|
||||||
osdep-*.c mdoc2man.awk tmux.1
|
|
||||||
|
|
||||||
# Preprocessor flags.
|
|
||||||
AM_CPPFLAGS += @XOPEN_DEFINES@ -DTMUX_CONF="\"$(sysconfdir)/tmux.conf\""
|
|
||||||
|
|
||||||
# Additional object files.
|
|
||||||
LDADD = $(LIBOBJS)
|
|
||||||
|
|
||||||
# Set flags for gcc.
|
|
||||||
if IS_GCC
|
|
||||||
AM_CFLAGS += -std=gnu99 -O2
|
|
||||||
if IS_DEBUG
|
|
||||||
AM_CFLAGS += -g
|
|
||||||
AM_CFLAGS += -Wno-long-long -Wall -W -Wformat=2
|
|
||||||
AM_CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
|
|
||||||
AM_CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
|
||||||
AM_CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
|
|
||||||
AM_CFLAGS += -Wdeclaration-after-statement -Wno-pointer-sign -Wno-attributes
|
|
||||||
AM_CFLAGS += -Wno-unused-result
|
|
||||||
AM_CPPFLAGS += -DDEBUG
|
|
||||||
endif
|
|
||||||
AM_CPPFLAGS += -iquote.
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Set flags for Solaris.
|
|
||||||
if IS_SUNOS
|
|
||||||
if IS_GCC
|
|
||||||
AM_CPPFLAGS += -D_XPG6
|
|
||||||
else
|
|
||||||
AM_CPPFLAGS += -D_XPG4_2
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Set flags for Sun CC.
|
|
||||||
if IS_SUNCC
|
|
||||||
AM_CFLAGS += -erroff=E_EMPTY_DECLARATION
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Set _LINUX_SOURCE_COMPAT for AIX for malloc(0).
|
|
||||||
if IS_AIX
|
|
||||||
AM_CPPFLAGS += -D_LINUX_SOURCE_COMPAT=1
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Set flags for NetBSD.
|
|
||||||
if IS_NETBSD
|
|
||||||
AM_CPPFLAGS += -D_OPENBSD_SOURCE
|
|
||||||
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-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-window.c \
|
|
||||||
cmd-find.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-hook.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 \
|
|
||||||
compat.h \
|
|
||||||
control-notify.c \
|
|
||||||
control.c \
|
|
||||||
environ.c \
|
|
||||||
format.c \
|
|
||||||
grid-view.c \
|
|
||||||
grid.c \
|
|
||||||
hooks.c \
|
|
||||||
input-keys.c \
|
|
||||||
input.c \
|
|
||||||
job.c \
|
|
||||||
key-bindings.c \
|
|
||||||
key-string.c \
|
|
||||||
layout-custom.c \
|
|
||||||
layout-set.c \
|
|
||||||
layout.c \
|
|
||||||
log.c \
|
|
||||||
names.c \
|
|
||||||
notify.c \
|
|
||||||
options-table.c \
|
|
||||||
options.c \
|
|
||||||
paste.c \
|
|
||||||
proc.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 \
|
|
||||||
tmux.h \
|
|
||||||
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 \
|
|
||||||
xmalloc.h \
|
|
||||||
xterm-keys.c
|
|
||||||
nodist_tmux_SOURCES = osdep-@PLATFORM@.c
|
|
||||||
|
|
||||||
# Add compat file for forkpty.
|
|
||||||
if NEED_FORKPTY
|
|
||||||
nodist_tmux_SOURCES += compat/forkpty-@PLATFORM@.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Add compat file for utf8proc.
|
|
||||||
if HAVE_UTF8PROC
|
|
||||||
nodist_tmux_SOURCES += compat/utf8proc.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
|
|
||||||
86
NOTES
Normal file
86
NOTES
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
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 0.9 release runs on OpenBSD, FreeBSD, NetBSD, Linux and OS X and may still
|
||||||
|
run on Solaris and AIX (although they hasn't been tested in a while). It is
|
||||||
|
usable, although there remain a number of missing features and some remaining
|
||||||
|
bugs are expected.
|
||||||
|
|
||||||
|
If upgrading from 0.5, PLEASE NOTE the following configuration file changes: it
|
||||||
|
is now required to pass the -g flag to set-option or set-window-option to set
|
||||||
|
global options; remain-by-default and utf8-default are now gone, use global
|
||||||
|
window options (set-window-option -g) instead.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
The following is a summary of major features implemented in this version:
|
||||||
|
|
||||||
|
- Basic multiplexing, window switching, attaching and detaching.
|
||||||
|
- Window listing and renaming.
|
||||||
|
- Key binding.
|
||||||
|
- Handling of client terminal resize.
|
||||||
|
- Terminal emulation sufficient to handle most curses applications.
|
||||||
|
- A optional status line (enabled by default).
|
||||||
|
- Window history and copy and paste.
|
||||||
|
- Support for VT100 line drawing characters.
|
||||||
|
- A large command set.
|
||||||
|
- Vertical window splitting and layout.
|
||||||
|
- Automatic server locking on inactivity.
|
||||||
|
- A configuration file.
|
||||||
|
- UTF-8 support.
|
||||||
|
|
||||||
|
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. Known working are
|
||||||
|
TERM=screen (tmux in screen), xterm, xterm-color and rxvt. Note that TERM=xterm
|
||||||
|
does not support colour on OpenBSD. screen ignores this, tmux does not: use
|
||||||
|
xterm-color or rxvt for colour.
|
||||||
|
|
||||||
|
tmux supports UTF-8. To use it, the utf8 option must be set on each window;
|
||||||
|
this may be turned on for all windows by setting it as a global option, see
|
||||||
|
tmux(1) and the FAQ file. As of 0.9, tmux attempts to autodetect a
|
||||||
|
UTF-8-capable terminal by checking the LC_ALL, LC_CTYPE and LANG environment
|
||||||
|
variables. list-clients may be used to check if this is detected correctly; if
|
||||||
|
not, the -u command-line flag may be specified.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
-- Nicholas Marriott <nicm@users.sf.net>
|
||||||
|
|
||||||
|
$Id: NOTES,v 1.49 2009-07-06 18:53:24 nicm Exp $
|
||||||
73
README
73
README
@@ -1,73 +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://libevent.org
|
|
||||||
|
|
||||||
It also depends on ncurses, available from:
|
|
||||||
|
|
||||||
http://invisible-island.net/ncurses/
|
|
||||||
|
|
||||||
To build and install tmux from a release tarball, use:
|
|
||||||
|
|
||||||
$ ./configure && make
|
|
||||||
$ sudo make install
|
|
||||||
|
|
||||||
tmux can use the utempter library to update utmp(5), if it is installed - run
|
|
||||||
configure with --enable-utempter to enable this.
|
|
||||||
|
|
||||||
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, a rough todo list is in the
|
|
||||||
TODO file and an example configuration in example_tmux.conf.
|
|
||||||
|
|
||||||
A vim(1) syntax file is available at:
|
|
||||||
|
|
||||||
https://github.com/ericpruitt/tmux.vim
|
|
||||||
https://raw.githubusercontent.com/ericpruitt/tmux.vim/master/vim/syntax/tmux.vim
|
|
||||||
|
|
||||||
And a bash(1) completion file at:
|
|
||||||
|
|
||||||
https://github.com/imomaliev/tmux-bash-completion
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
Subscribe by sending an email to <tmux-users+subscribe@googlegroups.com>.
|
|
||||||
|
|
||||||
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. All other files have a license and copyright notice at their start.
|
|
||||||
|
|
||||||
-- Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
172
SYNCING
172
SYNCING
@@ -1,172 +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 BUILDING 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. 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.
|
|
||||||
|
|
||||||
2. Tag with:
|
|
||||||
|
|
||||||
% git tag -a 2.X
|
|
||||||
|
|
||||||
Where "2.X" is the next version.
|
|
||||||
|
|
||||||
Push the tag out with:
|
|
||||||
|
|
||||||
% git push --tags
|
|
||||||
|
|
||||||
3. Build the tarball with 'make dist'.
|
|
||||||
|
|
||||||
4. 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.
|
|
||||||
|
|
||||||
5. 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.
|
|
||||||
|
|
||||||
6. Bump version in tmux/tmux.git configure.ac and uncomment "enable_debug=yes"
|
|
||||||
to create a debug build by default.
|
|
||||||
231
TODO
231
TODO
@@ -1,127 +1,106 @@
|
|||||||
- command bits and pieces:
|
- window creation/idle time
|
||||||
* allow multiple targets: fnmatch for -t/-c, for example detach all
|
- better errors when creating new windows/sessions (how?)
|
||||||
clients with -t*
|
- implicitly add exec to the commands for new windows (switch to disable it)?
|
||||||
* add -c for new-session like new-window
|
- it would be nice to have multichar commands eg C-b K K
|
||||||
* ' and " should be parsed the same (eg "\e" vs '\e') in config
|
- commands:
|
||||||
and command prompt
|
extend list-clients to list clients attached to a session (-a for all?)
|
||||||
* last-pane across sessions
|
bring back detach-session to detach all clients on a session?
|
||||||
* resize-pane -p to match split-window -p
|
- allow fnmatch for -c, so that you can, eg, detach all clients
|
||||||
* flag to wait-for to have a timeout and/or to stop waiting when the
|
- garbage collect window history (100 lines at a time?) if it hasn't been used
|
||||||
client gets a signal
|
in $x time (need window creation/use times)
|
||||||
|
- lift SHRT_MAX limits for history?
|
||||||
- make command sequences more usable
|
- better mode features: search
|
||||||
* don't require space after ;
|
- flags to centre screen in window
|
||||||
* options for error handling: && and ||?
|
- better terminal emulation
|
||||||
|
- activity/bell should be per-window not per-link? what if it is cur win in
|
||||||
- options bits and pieces:
|
session not being watched?
|
||||||
* way to set socket path from config file
|
- next prev word etc in command prompt; also ^K
|
||||||
|
- many more info() displays for various things
|
||||||
- format improvements:
|
- backspace should perhaps wrap backwards over newlines which were not moved
|
||||||
* option to quote format (#{q:session_name})
|
down by a newline: screen and the OS X terminal does this but xterm and most
|
||||||
* some way to pad # stuff with spaces
|
others do not. this might be hard: a flag for each grid line (top bit of size
|
||||||
* formats to show if a window is linked into multiple sessions, into
|
maybe)? a single flag is insufficient as can't then tell when to /stop/
|
||||||
multiple attached sessions, and is the active window in multiple
|
unwrapping
|
||||||
attached sessions?
|
- input.c is too complicated. simplify?
|
||||||
* comparison operators like < and > (for #{version}?)
|
- use a better termcap internally instead of screen, perhaps xterm
|
||||||
* %else statement in config file
|
- kill all but current pane
|
||||||
|
- fix rxvt cursor fg issue (text under cursor can have non-white fg)
|
||||||
- choose mode improvements:
|
- client sx/sy should be in tty, then can let the terminal wrap at edge
|
||||||
* choose-pane command (augment choose-tree to do this?)
|
to allow xterm to pick up it should be one line for its c/p
|
||||||
* flag to choose-* for sort order
|
- should be able to move to a hidden pane and it would be moved into view. pane
|
||||||
* two choices (first one then second, for swap-pane and join-pane)
|
number in status line/top-right would be cool for this
|
||||||
* choose modes should ditch the key bindings and just have fixed keys, and
|
- support other mouse modes (highlight etc) and use it in copy mode
|
||||||
be more customized to their purpose (d to delete a buffer for choose-buffer,
|
- set-remain-on-exit is a bit of a hack, some way to do it generically?
|
||||||
a preview of buffer contents, etc)
|
- set-option should be set-session-option and should be overall global options
|
||||||
|
for stuff like mode keys?
|
||||||
- improve monitor-*:
|
also quiet, utf8 and maybe other flags?
|
||||||
* straighten out rules for multiple clients
|
-g is a bit unexpected in conf file
|
||||||
* think about what happens across sessions
|
- clear window title on exit
|
||||||
* monitor changes within a region
|
- the output code (tty.c) could do with optimisation depending on term
|
||||||
* perhaps monitor /all/ panes in the window not just one
|
capibilities
|
||||||
|
- would be nice to be able to use "--" to mark start of command w/ neww etc
|
||||||
- improve mouse support:
|
to avoid quoting
|
||||||
* bind commands to mouse in different areas?
|
- goto line and search history in copy/scroll modes
|
||||||
* commands executed when clicking on a pattern (URL)
|
- clone session command
|
||||||
|
- make command sequences more usable: don't require space after ;, handle
|
||||||
|
errors better
|
||||||
|
- key to switch to copy mode from scroll mode
|
||||||
|
- attach should have a flag to create session if it doesn't exist
|
||||||
|
- rename split-window -> split-pane??
|
||||||
|
- fix UTF-8 guesswork on sparc64, improve tty checks
|
||||||
|
- choice and more mode would be better per client than per window?
|
||||||
|
- hooks to which commands may be attached, for example: tmux add-hook
|
||||||
|
"new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file
|
||||||
|
$HOME/.tmux-session.conf
|
||||||
|
- get it passing all the vttest tests that don't require resizing the terminal
|
||||||
|
- esc seq to set window title should be documented and should set
|
||||||
|
automatic-rename
|
||||||
|
- way to set socket path from config file
|
||||||
|
- XXX once env stuff is in, default-path and VISUAL/EDITOR should be picked up
|
||||||
|
when session is started
|
||||||
|
- what about utmp etc? can tmux update it like screen? setgid?
|
||||||
|
- H/M/L commands in copy mode with vi-keys, for jumping to the top/middle/last
|
||||||
|
line on the screen
|
||||||
|
- split list-windows into separate list-windows and list-panes
|
||||||
- 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-*
|
||||||
|
- server-info
|
||||||
- copy/paste improvements:
|
- up-pane/down-pane/swap-pane -U/swap-pane -D vs next-*/previous-*
|
||||||
* paste w/o trailing whitespace
|
- pcvt25 doesn't work properly, why? (bce?)
|
||||||
* command to toggle selection not to move it in copy-mode
|
- tidy up and prioritise todo list ;-)
|
||||||
* regex searching
|
- it is only possible to specify 8 colours to fg/bg options; should be able to
|
||||||
* searching in copy mode should unwrap lines, so if you search for "foobar"
|
set 256 as well
|
||||||
then it should be found even if it is now "foo\nbar" (if the WRAP flag
|
- neww and attach can create a session if none exists?
|
||||||
is set on the line)
|
would work fine with config file since
|
||||||
* capture-pane option to preserve spaces but not join lines
|
- a way for force-width/height to apply to only one pane (how?)
|
||||||
* improve word and line selection in copy mode (for example when
|
- **** a command to run something without a window and send any output to the
|
||||||
dragging it should select by word. compare how xterm works. GitHub
|
window-more. if no output, info() a line saying "'%s' returned %d". so i can
|
||||||
issue 682)
|
bind mpc control commands to function keys ;-)
|
||||||
|
- command to list what is actually running in each window with command line,
|
||||||
- layout stuff
|
pid (need some adaption of the osdep code)
|
||||||
* way to tag a layout as a number/name
|
- string option to change/remove the symbols (*-+ etc) in status line
|
||||||
* maybe keep last layout + size around and if size reverts just put it
|
- support for bce
|
||||||
back
|
- it would be nice if the start/end line keys in copy mode were aware of
|
||||||
* revamp layouts: they are too complicated, should be more closely
|
wrapped lines
|
||||||
integrated, should support hints, layout sets should just be a
|
- per session locking
|
||||||
special case of custom layouts, and we should support panes that are
|
- some way to force a screen to use the entire terminal even if it is forced
|
||||||
not attached to a cell at all. this could be the time to introduce
|
to be smaller by other clients. pan smaller terminal? (like screen F)
|
||||||
panelink to replace layout_cell
|
-- idea of a "view" onto a window, need base x/y offsets
|
||||||
* way to set hints/limits about pane size for resizing
|
for redraw
|
||||||
* panning over window (window larger than visible)
|
- a window option which means data is echoed to all panes in a window
|
||||||
* a mode where one application can cross two panes (ie x|y, width =
|
- support running tmux from inside tmux [#(), if-shell] --
|
||||||
COLUMNS/2 but height = ROWS * 2)
|
generic system-like function which may take a callback
|
||||||
* separate active panes for different clients
|
also sets up environment (TMUX) and has a timeout
|
||||||
* way to choose where the freed space goes when a pane is killed:
|
for #(): command schedular, status line queues it with a time, run in
|
||||||
option to kill-pane? GitHub issue 918
|
main loop, and uses most recent result -- can also be used for persistent
|
||||||
|
commands which never exit just continually output
|
||||||
- code cleanup
|
for if-shell, callback??
|
||||||
* instead of separate window and session options, just one master
|
- handle resize better in copy mode
|
||||||
options list with each option having a type (window or session), then
|
- way to copy stuff that is off screen due to resize
|
||||||
options on window, on session, and global. for window options we look
|
- fix line wrapping c&p problems in xterm etc
|
||||||
window->session->global, and for session we look session->global.
|
- a way to address panes by name ("top-left") and position ("0,0")
|
||||||
problem: what about windows in multiple sessions? there are contexts
|
- ability to specify multiple prefix keys
|
||||||
where we do not know which session, or where multiple choices makes
|
- commands should be able to succeed or fail and have || or && for command
|
||||||
no sense... could at least have one global list for all types of
|
lists
|
||||||
global options and keep separate window,session lists
|
- support the mouse wheel to scroll through history
|
||||||
* 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
|
|
||||||
|
|
||||||
- miscellaneous
|
|
||||||
* 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? separate command prompt and status line?
|
|
||||||
* automatic pane logging
|
|
||||||
* marks in history, automatically add (move?) one when pane is changed
|
|
||||||
* this doesn't work, need pane reference count probably:
|
|
||||||
bind -n DoubleClick3Status confirm-before -p "kill-window #I? (y/n)" kill-window
|
|
||||||
* respawn -c flag same as neww etc
|
|
||||||
|
|
||||||
- hooks
|
|
||||||
* more hooks for various things
|
|
||||||
* finish after hooks for special commands
|
|
||||||
* multiple hooks with the same name?
|
|
||||||
* finish hooks for notifys
|
|
||||||
* for session_closed, if no sessions at all, perhaps fake up a temporary one
|
|
||||||
|
|||||||
324
alerts.c
324
alerts.c
@@ -1,324 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
*
|
|
||||||
* 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 <stdlib.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
static int alerts_fired;
|
|
||||||
|
|
||||||
static void alerts_timer(int, short, void *);
|
|
||||||
static int alerts_enabled(struct window *, int);
|
|
||||||
static void alerts_callback(int, short, void *);
|
|
||||||
static void alerts_reset(struct window *);
|
|
||||||
|
|
||||||
static int alerts_check_all(struct window *);
|
|
||||||
static int alerts_check_bell(struct window *);
|
|
||||||
static int alerts_check_activity(struct window *);
|
|
||||||
static int alerts_check_silence(struct window *);
|
|
||||||
static void printflike(2, 3) alerts_set_message(struct session *, const char *,
|
|
||||||
...);
|
|
||||||
static void alerts_ring_bell(struct session *);
|
|
||||||
|
|
||||||
static TAILQ_HEAD(, window) alerts_list = TAILQ_HEAD_INITIALIZER(alerts_list);
|
|
||||||
|
|
||||||
static 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
alerts_callback(__unused int fd, __unused short events, __unused void *arg)
|
|
||||||
{
|
|
||||||
struct window *w, *w1;
|
|
||||||
int alerts;
|
|
||||||
|
|
||||||
TAILQ_FOREACH_SAFE(w, &alerts_list, alerts_entry, w1) {
|
|
||||||
alerts = alerts_check_all(w);
|
|
||||||
log_debug("@%u alerts check, alerts %#x", w->id, alerts);
|
|
||||||
|
|
||||||
w->alerts_queued = 0;
|
|
||||||
TAILQ_REMOVE(&alerts_list, w, alerts_entry);
|
|
||||||
|
|
||||||
w->flags &= ~WINDOW_ALERTFLAGS;
|
|
||||||
window_remove_ref(w, __func__);
|
|
||||||
}
|
|
||||||
alerts_fired = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
alerts_check_all(struct window *w)
|
|
||||||
{
|
|
||||||
int alerts;
|
|
||||||
|
|
||||||
alerts = alerts_check_bell(w);
|
|
||||||
alerts |= alerts_check_activity(w);
|
|
||||||
alerts |= alerts_check_silence(w);
|
|
||||||
return (alerts);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
alerts_check_session(struct session *s)
|
|
||||||
{
|
|
||||||
struct winlink *wl;
|
|
||||||
|
|
||||||
RB_FOREACH(wl, winlinks, &s->windows)
|
|
||||||
alerts_check_all(wl->window);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
alerts_enabled(struct window *w, int flags)
|
|
||||||
{
|
|
||||||
if (flags & WINDOW_BELL)
|
|
||||||
return (1);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
alerts_reset_all(void)
|
|
||||||
{
|
|
||||||
struct window *w;
|
|
||||||
|
|
||||||
RB_FOREACH(w, windows, &windows)
|
|
||||||
alerts_reset(w);
|
|
||||||
}
|
|
||||||
|
|
||||||
static 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) != flags) {
|
|
||||||
w->flags |= flags;
|
|
||||||
log_debug("@%u alerts flags added %#x", w->id, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alerts_enabled(w, flags)) {
|
|
||||||
if (!w->alerts_queued) {
|
|
||||||
w->alerts_queued = 1;
|
|
||||||
TAILQ_INSERT_TAIL(&alerts_list, w, alerts_entry);
|
|
||||||
window_add_ref(w, __func__);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!alerts_fired) {
|
|
||||||
log_debug("alerts check queued (by @%u)", w->id);
|
|
||||||
event_once(-1, EV_TIMEOUT, alerts_callback, NULL, NULL);
|
|
||||||
alerts_fired = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
alerts_check_bell(struct window *w)
|
|
||||||
{
|
|
||||||
struct window *ws;
|
|
||||||
struct winlink *wl;
|
|
||||||
struct session *s;
|
|
||||||
struct client *c;
|
|
||||||
int action, visual;
|
|
||||||
|
|
||||||
if (~w->flags & WINDOW_BELL)
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
TAILQ_FOREACH(wl, &w->winlinks, wentry)
|
|
||||||
wl->session->flags &= ~SESSION_ALERTED;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(wl, &w->winlinks, wentry) {
|
|
||||||
if (wl->flags & WINLINK_BELL)
|
|
||||||
continue;
|
|
||||||
s = wl->session;
|
|
||||||
if (s->curw != wl) {
|
|
||||||
wl->flags |= WINLINK_BELL;
|
|
||||||
notify_winlink("alert-bell", wl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->flags & SESSION_ALERTED)
|
|
||||||
continue;
|
|
||||||
s->flags |= SESSION_ALERTED;
|
|
||||||
|
|
||||||
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;
|
|
||||||
ws = c->session->curw->window;
|
|
||||||
|
|
||||||
if (action == BELL_CURRENT && ws != w)
|
|
||||||
action = BELL_NONE;
|
|
||||||
if (action == BELL_OTHER && ws != w)
|
|
||||||
action = BELL_NONE;
|
|
||||||
|
|
||||||
if (!visual) {
|
|
||||||
if (action != BELL_NONE)
|
|
||||||
tty_putcode(&c->tty, TTYC_BEL);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (action == BELL_CURRENT)
|
|
||||||
status_message_set(c, "Bell in current window");
|
|
||||||
else if (action != BELL_NONE) {
|
|
||||||
status_message_set(c, "Bell in window %d",
|
|
||||||
wl->idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (WINDOW_BELL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
alerts_check_activity(struct window *w)
|
|
||||||
{
|
|
||||||
struct winlink *wl;
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
if (~w->flags & WINDOW_ACTIVITY)
|
|
||||||
return (0);
|
|
||||||
if (!options_get_number(w->options, "monitor-activity"))
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
TAILQ_FOREACH(wl, &w->winlinks, wentry)
|
|
||||||
wl->session->flags &= ~SESSION_ALERTED;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(wl, &w->winlinks, wentry) {
|
|
||||||
if (wl->flags & WINLINK_ACTIVITY)
|
|
||||||
continue;
|
|
||||||
s = wl->session;
|
|
||||||
if (s->curw == wl)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
wl->flags |= WINLINK_ACTIVITY;
|
|
||||||
notify_winlink("alert-activity", wl);
|
|
||||||
|
|
||||||
if (s->flags & SESSION_ALERTED)
|
|
||||||
continue;
|
|
||||||
s->flags |= SESSION_ALERTED;
|
|
||||||
|
|
||||||
if (options_get_number(s->options, "bell-on-alert"))
|
|
||||||
alerts_ring_bell(s);
|
|
||||||
if (options_get_number(s->options, "visual-activity"))
|
|
||||||
alerts_set_message(s, "Activity in window %d", wl->idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (WINDOW_ACTIVITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
alerts_check_silence(struct window *w)
|
|
||||||
{
|
|
||||||
struct winlink *wl;
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
if (~w->flags & WINDOW_SILENCE)
|
|
||||||
return (0);
|
|
||||||
if (!options_get_number(w->options, "monitor-silence"))
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
TAILQ_FOREACH(wl, &w->winlinks, wentry)
|
|
||||||
wl->session->flags &= ~SESSION_ALERTED;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(wl, &w->winlinks, wentry) {
|
|
||||||
if (wl->flags & WINLINK_SILENCE)
|
|
||||||
continue;
|
|
||||||
s = wl->session;
|
|
||||||
if (s->curw == wl)
|
|
||||||
continue;
|
|
||||||
wl->flags |= WINLINK_SILENCE;
|
|
||||||
notify_winlink("alert-silence", wl);
|
|
||||||
|
|
||||||
if (s->flags & SESSION_ALERTED)
|
|
||||||
continue;
|
|
||||||
s->flags |= SESSION_ALERTED;
|
|
||||||
|
|
||||||
if (options_get_number(s->options, "bell-on-alert"))
|
|
||||||
alerts_ring_bell(s);
|
|
||||||
|
|
||||||
if (!options_get_number(s->options, "visual-silence"))
|
|
||||||
alerts_set_message(s, "Silence in window %d", wl->idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (WINDOW_SILENCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
alerts_set_message(struct session *s, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
struct client *c;
|
|
||||||
va_list ap;
|
|
||||||
char *message;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
xvasprintf(&message, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
|
||||||
if (c->session == s)
|
|
||||||
status_message_set(c, "%s", message);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
static 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
250
arguments.c
250
arguments.c
@@ -1,250 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
*
|
|
||||||
* 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void args_set(struct args *, u_char, const char *);
|
|
||||||
static struct args_entry *args_find(struct args *, u_char);
|
|
||||||
|
|
||||||
static int args_cmp(struct args_entry *, struct args_entry *);
|
|
||||||
RB_GENERATE_STATIC(args_tree, args_entry, entry, args_cmp);
|
|
||||||
|
|
||||||
/* Arguments tree comparison function. */
|
|
||||||
static int
|
|
||||||
args_cmp(struct args_entry *a1, struct args_entry *a2)
|
|
||||||
{
|
|
||||||
return (a1->flag - a2->flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find a flag in the arguments tree. */
|
|
||||||
static 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add to string. */
|
|
||||||
static void printflike(3, 4)
|
|
||||||
args_print_add(char **buf, size_t *len, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
char *s;
|
|
||||||
size_t slen;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
slen = xvasprintf(&s, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
*len += slen;
|
|
||||||
*buf = xrealloc(*buf, *len);
|
|
||||||
|
|
||||||
strlcat(*buf, s, *len);
|
|
||||||
free(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print a set of arguments. */
|
|
||||||
char *
|
|
||||||
args_print(struct args *args)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
char *buf, *escaped;
|
|
||||||
int i, flags;
|
|
||||||
struct args_entry *entry;
|
|
||||||
static const char quoted[] = " #\"';$";
|
|
||||||
|
|
||||||
len = 1;
|
|
||||||
buf = xcalloc(1, len);
|
|
||||||
|
|
||||||
/* Process the flags first. */
|
|
||||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
|
||||||
if (entry->value != NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (*buf == '\0')
|
|
||||||
args_print_add(&buf, &len, "-");
|
|
||||||
args_print_add(&buf, &len, "%c", entry->flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then the flags with arguments. */
|
|
||||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
|
||||||
if (entry->value == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (*buf != '\0')
|
|
||||||
args_print_add(&buf, &len, " -%c ", entry->flag);
|
|
||||||
else
|
|
||||||
args_print_add(&buf, &len, "-%c ", entry->flag);
|
|
||||||
|
|
||||||
flags = VIS_OCTAL|VIS_TAB|VIS_NL;
|
|
||||||
if (entry->value[strcspn(entry->value, quoted)] != '\0')
|
|
||||||
flags |= VIS_DQ;
|
|
||||||
utf8_stravis(&escaped, entry->value, flags);
|
|
||||||
if (flags & VIS_DQ)
|
|
||||||
args_print_add(&buf, &len, "\"%s\"", escaped);
|
|
||||||
else
|
|
||||||
args_print_add(&buf, &len, "%s", escaped);
|
|
||||||
free(escaped);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* And finally the argument vector. */
|
|
||||||
for (i = 0; i < args->argc; i++) {
|
|
||||||
if (*buf != '\0')
|
|
||||||
args_print_add(&buf, &len, " ");
|
|
||||||
|
|
||||||
flags = VIS_OCTAL|VIS_TAB|VIS_NL;
|
|
||||||
if (args->argv[i][strcspn(args->argv[i], quoted)] != '\0')
|
|
||||||
flags |= VIS_DQ;
|
|
||||||
utf8_stravis(&escaped, args->argv[i], flags);
|
|
||||||
if (flags & VIS_DQ)
|
|
||||||
args_print_add(&buf, &len, "\"%s\"", escaped);
|
|
||||||
else
|
|
||||||
args_print_add(&buf, &len, "%s", escaped);
|
|
||||||
free(escaped);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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. */
|
|
||||||
static 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);
|
|
||||||
}
|
|
||||||
119
array.h
Normal file
119
array.h
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
/* $Id: array.h,v 1.7 2008-09-29 16:58:02 nicm Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ARRAY_H
|
||||||
|
#define ARRAY_H
|
||||||
|
|
||||||
|
#define ARRAY_DECL(n, c) \
|
||||||
|
struct n { \
|
||||||
|
c *list; \
|
||||||
|
u_int num; \
|
||||||
|
size_t space; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ARRAY_ITEM(a, i) ((a)->list[i])
|
||||||
|
#define ARRAY_ITEMSIZE(a) (sizeof *(a)->list)
|
||||||
|
#define ARRAY_INITIALSPACE(a) (10 * ARRAY_ITEMSIZE(a))
|
||||||
|
|
||||||
|
#define ARRAY_ENSURE(a, n) do { \
|
||||||
|
if (UINT_MAX - (n) < (a)->num) \
|
||||||
|
fatalx("number too big"); \
|
||||||
|
if (SIZE_MAX / ((a)->num + (n)) < ARRAY_ITEMSIZE(a)) \
|
||||||
|
fatalx("size too big"); \
|
||||||
|
if ((a)->space == 0) { \
|
||||||
|
(a)->space = ARRAY_INITIALSPACE(a); \
|
||||||
|
(a)->list = xrealloc((a)->list, 1, (a)->space); \
|
||||||
|
} \
|
||||||
|
while ((a)->space <= ((a)->num + (n)) * ARRAY_ITEMSIZE(a)) { \
|
||||||
|
(a)->list = xrealloc((a)->list, 2, (a)->space); \
|
||||||
|
(a)->space *= 2; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_EMPTY(a) ((a) == NULL || (a)->num == 0)
|
||||||
|
#define ARRAY_LENGTH(a) ((a)->num)
|
||||||
|
#define ARRAY_DATA(a) ((a)->list)
|
||||||
|
|
||||||
|
#define ARRAY_FIRST(a) ARRAY_ITEM(a, 0)
|
||||||
|
#define ARRAY_LAST(a) ARRAY_ITEM(a, (a)->num - 1)
|
||||||
|
|
||||||
|
#define ARRAY_INIT(a) do { \
|
||||||
|
(a)->num = 0; \
|
||||||
|
(a)->list = NULL; \
|
||||||
|
(a)->space = 0; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_CLEAR(a) do { \
|
||||||
|
(a)->num = 0; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_SET(a, i, s) do { \
|
||||||
|
(a)->list[i] = s; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_ADD(a, s) do { \
|
||||||
|
ARRAY_ENSURE(a, 1); \
|
||||||
|
(a)->list[(a)->num] = s; \
|
||||||
|
(a)->num++; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_INSERT(a, i, s) do { \
|
||||||
|
ARRAY_ENSURE(a, 1); \
|
||||||
|
if ((i) < (a)->num) { \
|
||||||
|
memmove((a)->list + (i) + 1, (a)->list + (i), \
|
||||||
|
ARRAY_ITEMSIZE(a) * ((a)->num - (i))); \
|
||||||
|
} \
|
||||||
|
(a)->list[i] = s; \
|
||||||
|
(a)->num++; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_REMOVE(a, i) do { \
|
||||||
|
if ((i) < (a)->num - 1) { \
|
||||||
|
memmove((a)->list + (i), (a)->list + (i) + 1, \
|
||||||
|
ARRAY_ITEMSIZE(a) * ((a)->num - (i) - 1)); \
|
||||||
|
} \
|
||||||
|
(a)->num--; \
|
||||||
|
if ((a)->num == 0) \
|
||||||
|
ARRAY_FREE(a); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_EXPAND(a, n) do { \
|
||||||
|
ARRAY_ENSURE(a, n); \
|
||||||
|
(a)->num += n; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_TRUNC(a, n) do { \
|
||||||
|
if ((a)->num > n) \
|
||||||
|
(a)->num -= n; \
|
||||||
|
else \
|
||||||
|
ARRAY_FREE(a); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_CONCAT(a, b) do { \
|
||||||
|
ARRAY_ENSURE(a, (b)->num); \
|
||||||
|
memcpy((a)->list + (a)->num, (b)->list, (b)->num * ARRAY_ITEMSIZE(a)) \
|
||||||
|
(a)->num += (b)->num; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_FREE(a) do { \
|
||||||
|
if ((a)->list != NULL) \
|
||||||
|
xfree((a)->list); \
|
||||||
|
ARRAY_INIT(a); \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_FREEALL(a) do { \
|
||||||
|
ARRAY_FREE(a); \
|
||||||
|
xfree(a); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif
|
||||||
61
attributes.c
61
attributes.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: attributes.c,v 1.2 2009-06-25 15:25:45 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
||||||
@@ -23,25 +23,30 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
attributes_tostring(int attr)
|
attributes_tostring(u_char ch)
|
||||||
{
|
{
|
||||||
static char buf[128];
|
static char buf[128];
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (attr == 0)
|
if (ch == 0)
|
||||||
return ("none");
|
return ("default");
|
||||||
|
|
||||||
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s",
|
buf[0] = '\0';
|
||||||
(attr & GRID_ATTR_BRIGHT) ? "bright," : "",
|
if (ch & GRID_ATTR_BRIGHT)
|
||||||
(attr & GRID_ATTR_DIM) ? "dim," : "",
|
strlcat(buf, "bright,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_UNDERSCORE) ? "underscore," : "",
|
if (ch & GRID_ATTR_DIM)
|
||||||
(attr & GRID_ATTR_BLINK)? "blink," : "",
|
strlcat(buf, "dim,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_REVERSE) ? "reverse," : "",
|
if (ch & GRID_ATTR_UNDERSCORE)
|
||||||
(attr & GRID_ATTR_HIDDEN) ? "hidden," : "",
|
strlcat(buf, "underscore,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_ITALICS) ? "italics," : "",
|
if (ch & GRID_ATTR_BLINK)
|
||||||
(attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : "");
|
strlcat(buf, "blink,", sizeof (buf));
|
||||||
if (len > 0)
|
if (ch & GRID_ATTR_REVERSE)
|
||||||
buf[len - 1] = '\0';
|
strlcat(buf, "reverse,", sizeof (buf));
|
||||||
|
if (ch & GRID_ATTR_HIDDEN)
|
||||||
|
strlcat(buf, "hidden,", sizeof (buf));
|
||||||
|
if (ch & GRID_ATTR_ITALICS)
|
||||||
|
strlcat(buf, "italics,", sizeof (buf));
|
||||||
|
if (*buf)
|
||||||
|
*(strrchr(buf, ',')) = '\0';
|
||||||
|
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
@@ -50,7 +55,7 @@ int
|
|||||||
attributes_fromstring(const char *str)
|
attributes_fromstring(const char *str)
|
||||||
{
|
{
|
||||||
const char delimiters[] = " ,|";
|
const char delimiters[] = " ,|";
|
||||||
int attr;
|
u_char ch;
|
||||||
size_t end;
|
size_t end;
|
||||||
|
|
||||||
if (*str == '\0' || strcspn(str, delimiters) == 0)
|
if (*str == '\0' || strcspn(str, delimiters) == 0)
|
||||||
@@ -58,33 +63,31 @@ attributes_fromstring(const char *str)
|
|||||||
if (strchr(delimiters, str[strlen(str) - 1]) != NULL)
|
if (strchr(delimiters, str[strlen(str) - 1]) != NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (strcasecmp(str, "default") == 0 || strcasecmp(str, "none") == 0)
|
if (strcasecmp(str, "default") == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
attr = 0;
|
ch = 0;
|
||||||
do {
|
do {
|
||||||
end = strcspn(str, delimiters);
|
end = strcspn(str, delimiters);
|
||||||
if ((end == 6 && strncasecmp(str, "bright", end) == 0) ||
|
if ((end == 6 && strncasecmp(str, "bright", end) == 0) ||
|
||||||
(end == 4 && strncasecmp(str, "bold", end) == 0))
|
(end == 4 && strncasecmp(str, "bold", end) == 0))
|
||||||
attr |= GRID_ATTR_BRIGHT;
|
ch |= GRID_ATTR_BRIGHT;
|
||||||
else if (end == 3 && strncasecmp(str, "dim", end) == 0)
|
else if (end == 3 && strncasecmp(str, "dim", end) == 0)
|
||||||
attr |= GRID_ATTR_DIM;
|
ch |= GRID_ATTR_DIM;
|
||||||
else if (end == 10 && strncasecmp(str, "underscore", end) == 0)
|
else if (end == 10 && strncasecmp(str, "underscore", end) == 0)
|
||||||
attr |= GRID_ATTR_UNDERSCORE;
|
ch |= GRID_ATTR_UNDERSCORE;
|
||||||
else if (end == 5 && strncasecmp(str, "blink", end) == 0)
|
else if (end == 5 && strncasecmp(str, "blink", end) == 0)
|
||||||
attr |= GRID_ATTR_BLINK;
|
ch |= GRID_ATTR_BLINK;
|
||||||
else if (end == 7 && strncasecmp(str, "reverse", end) == 0)
|
else if (end == 7 && strncasecmp(str, "reverse", end) == 0)
|
||||||
attr |= GRID_ATTR_REVERSE;
|
ch |= GRID_ATTR_REVERSE;
|
||||||
else if (end == 6 && strncasecmp(str, "hidden", end) == 0)
|
else if (end == 6 && strncasecmp(str, "hidden", end) == 0)
|
||||||
attr |= GRID_ATTR_HIDDEN;
|
ch |= GRID_ATTR_HIDDEN;
|
||||||
else if (end == 7 && strncasecmp(str, "italics", end) == 0)
|
else if (end == 7 && strncasecmp(str, "italics", end) == 0)
|
||||||
attr |= GRID_ATTR_ITALICS;
|
ch |= GRID_ATTR_ITALICS;
|
||||||
else if (end == 13 && strncasecmp(str, "strikethrough", end) == 0)
|
|
||||||
attr |= GRID_ATTR_STRIKETHROUGH;
|
|
||||||
else
|
else
|
||||||
return (-1);
|
return (-1);
|
||||||
str += end + strspn(str + end, delimiters);
|
str += end + strspn(str + end, delimiters);
|
||||||
} while (*str != '\0');
|
} while (*str != '\0');
|
||||||
|
|
||||||
return (attr);
|
return (ch);
|
||||||
}
|
}
|
||||||
|
|||||||
17
autogen.sh
17
autogen.sh
@@ -1,17 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ "x$(uname)" = "xOpenBSD" ]; then
|
|
||||||
[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.15
|
|
||||||
[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.69
|
|
||||||
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"
|
|
||||||
54
buffer-poll.c
Normal file
54
buffer-poll.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* $Id: buffer-poll.c,v 1.16 2009-08-19 09:28:10 nicm 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 <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/* Fill buffers from socket based on poll results. */
|
||||||
|
int
|
||||||
|
buffer_poll(struct pollfd *pfd, struct buffer *in, struct buffer *out)
|
||||||
|
{
|
||||||
|
ssize_t n;
|
||||||
|
|
||||||
|
if (pfd->revents & (POLLERR|POLLNVAL|POLLHUP))
|
||||||
|
return (-1);
|
||||||
|
if (pfd->revents & POLLIN) {
|
||||||
|
buffer_ensure(in, BUFSIZ);
|
||||||
|
n = read(pfd->fd, BUFFER_IN(in), BUFFER_FREE(in));
|
||||||
|
if (n == 0)
|
||||||
|
return (-1);
|
||||||
|
if (n == -1) {
|
||||||
|
if (errno != EINTR && errno != EAGAIN)
|
||||||
|
return (-1);
|
||||||
|
} else
|
||||||
|
buffer_add(in, n);
|
||||||
|
}
|
||||||
|
if (BUFFER_USED(out) > 0 && pfd->revents & POLLOUT) {
|
||||||
|
n = write(pfd->fd, BUFFER_OUT(out), BUFFER_USED(out));
|
||||||
|
if (n == -1) {
|
||||||
|
if (errno != EINTR && errno != EAGAIN)
|
||||||
|
return (-1);
|
||||||
|
} else
|
||||||
|
buffer_remove(out, n);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
139
buffer.c
Normal file
139
buffer.c
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
/* $Id: buffer.c,v 1.8 2009-08-21 21:09:13 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 <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/* Create a buffer. */
|
||||||
|
struct buffer *
|
||||||
|
buffer_create(size_t size)
|
||||||
|
{
|
||||||
|
struct buffer *b;
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
|
fatalx("zero size");
|
||||||
|
|
||||||
|
b = xcalloc(1, sizeof *b);
|
||||||
|
|
||||||
|
b->base = xmalloc(size);
|
||||||
|
b->space = size;
|
||||||
|
|
||||||
|
return (b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Destroy a buffer. */
|
||||||
|
void
|
||||||
|
buffer_destroy(struct buffer *b)
|
||||||
|
{
|
||||||
|
xfree(b->base);
|
||||||
|
xfree(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure free space for size in buffer. */
|
||||||
|
void
|
||||||
|
buffer_ensure(struct buffer *b, size_t size)
|
||||||
|
{
|
||||||
|
if (size == 0)
|
||||||
|
fatalx("zero size");
|
||||||
|
|
||||||
|
if (BUFFER_FREE(b) >= size)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (b->off > 0) {
|
||||||
|
if (b->size > 0)
|
||||||
|
memmove(b->base, b->base + b->off, b->size);
|
||||||
|
b->off = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SIZE_MAX - b->size < size)
|
||||||
|
fatalx("size too big");
|
||||||
|
while (b->space < b->size + size) {
|
||||||
|
b->base = xrealloc(b->base, 2, b->space);
|
||||||
|
b->space *= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adjust buffer after data appended. */
|
||||||
|
void
|
||||||
|
buffer_add(struct buffer *b, size_t size)
|
||||||
|
{
|
||||||
|
if (size == 0)
|
||||||
|
fatalx("zero size");
|
||||||
|
if (size > b->space - b->size)
|
||||||
|
fatalx("overflow");
|
||||||
|
|
||||||
|
b->size += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adjust buffer after data removed. */
|
||||||
|
void
|
||||||
|
buffer_remove(struct buffer *b, size_t size)
|
||||||
|
{
|
||||||
|
if (size == 0)
|
||||||
|
fatalx("zero size");
|
||||||
|
if (size > b->size)
|
||||||
|
fatalx("underflow");
|
||||||
|
|
||||||
|
b->size -= size;
|
||||||
|
b->off += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy data into a buffer. */
|
||||||
|
void
|
||||||
|
buffer_write(struct buffer *b, const void *data, size_t size)
|
||||||
|
{
|
||||||
|
buffer_ensure(b, size);
|
||||||
|
memcpy(BUFFER_IN(b), data, size);
|
||||||
|
buffer_add(b, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy data out of a buffer. */
|
||||||
|
void
|
||||||
|
buffer_read(struct buffer *b, void *data, size_t size)
|
||||||
|
{
|
||||||
|
if (size == 0)
|
||||||
|
fatalx("zero size");
|
||||||
|
if (size > b->size)
|
||||||
|
fatalx("underflow");
|
||||||
|
|
||||||
|
memcpy(data, BUFFER_OUT(b), size);
|
||||||
|
buffer_remove(b, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Store an 8-bit value. */
|
||||||
|
void
|
||||||
|
buffer_write8(struct buffer *b, uint8_t n)
|
||||||
|
{
|
||||||
|
buffer_ensure(b, 1);
|
||||||
|
BUFFER_IN(b)[0] = n;
|
||||||
|
b->size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Extract an 8-bit value. */
|
||||||
|
uint8_t
|
||||||
|
buffer_read8(struct buffer *b)
|
||||||
|
{
|
||||||
|
uint8_t n;
|
||||||
|
|
||||||
|
n = BUFFER_OUT(b)[0];
|
||||||
|
buffer_remove(b, 1);
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
275
cfg.c
275
cfg.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cfg.c,v 1.22 2009-08-24 16:27:03 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 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
|
||||||
@@ -17,230 +17,111 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#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"
|
||||||
|
|
||||||
static char *cfg_file;
|
/*
|
||||||
int cfg_finished;
|
* Config file parser. Pretty quick and simple, each line is parsed into a
|
||||||
static char **cfg_causes;
|
* argv array and executed as a command.
|
||||||
static u_int cfg_ncauses;
|
*/
|
||||||
static struct cmdq_item *cfg_item;
|
|
||||||
|
|
||||||
static enum cmd_retval
|
void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
|
||||||
cfg_client_done(__unused struct cmdq_item *item, __unused void *data)
|
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
|
||||||
|
|
||||||
|
char *cfg_cause;
|
||||||
|
|
||||||
|
void printflike2
|
||||||
|
cfg_print(unused struct cmd_ctx *ctx, unused const char *fmt, ...)
|
||||||
{
|
{
|
||||||
if (!cfg_finished)
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
void printflike2
|
||||||
cfg_done(__unused struct cmdq_item *item, __unused void *data)
|
cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
if (cfg_finished)
|
va_list ap;
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
cfg_finished = 1;
|
|
||||||
|
|
||||||
if (!RB_EMPTY(&sessions))
|
va_start(ap, fmt);
|
||||||
cfg_show_causes(RB_MIN(sessions, &sessions));
|
xvasprintf(&cfg_cause, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
if (cfg_item != NULL)
|
|
||||||
cfg_item->flags &= ~CMDQ_WAITING;
|
|
||||||
|
|
||||||
status_prompt_load_history();
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
set_cfg_file(const char *path)
|
|
||||||
{
|
|
||||||
free(cfg_file);
|
|
||||||
cfg_file = xstrdup(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
start_cfg(void)
|
|
||||||
{
|
|
||||||
const char *home;
|
|
||||||
int quiet = 0;
|
|
||||||
struct client *c;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Configuration files are loaded without a client, so NULL is passed
|
|
||||||
* into load_cfg() and commands run in the global queue with
|
|
||||||
* item->client NULL.
|
|
||||||
*
|
|
||||||
* However, we must block the initial client (but just the initial
|
|
||||||
* client) so that its command runs after the configuration is loaded.
|
|
||||||
* Because start_cfg() is called so early, we can be sure the client's
|
|
||||||
* command queue is currently empty and our callback will be at the
|
|
||||||
* front - we need to get in before MSG_COMMAND.
|
|
||||||
*/
|
|
||||||
c = TAILQ_FIRST(&clients);
|
|
||||||
if (c != NULL) {
|
|
||||||
cfg_item = cmdq_get_callback(cfg_client_done, NULL);
|
|
||||||
cmdq_append(c, cfg_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
load_cfg(TMUX_CONF, NULL, NULL, 1);
|
|
||||||
|
|
||||||
if (cfg_file == NULL && (home = find_home()) != NULL) {
|
|
||||||
xasprintf(&cfg_file, "%s/.tmux.conf", home);
|
|
||||||
quiet = 1;
|
|
||||||
}
|
|
||||||
if (cfg_file != NULL)
|
|
||||||
load_cfg(cfg_file, NULL, NULL, quiet);
|
|
||||||
|
|
||||||
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
load_cfg(const char *path, struct cmd_ctx *ctxin, char **cause)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
const char delim[3] = { '\\', '\\', '\0' };
|
u_int n;
|
||||||
u_int found = 0;
|
char *buf, *line, *ptr;
|
||||||
size_t line = 0;
|
size_t len;
|
||||||
char *buf, *cause1, *p, *q, *s;
|
struct cmd_list *cmdlist;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_ctx ctx;
|
||||||
struct cmdq_item *new_item;
|
|
||||||
int condition = 0;
|
|
||||||
struct format_tree *ft;
|
|
||||||
|
|
||||||
log_debug("loading %s", path);
|
|
||||||
if ((f = fopen(path, "rb")) == NULL) {
|
if ((f = fopen(path, "rb")) == NULL) {
|
||||||
if (errno == ENOENT && quiet)
|
xasprintf(cause, "%s: %s", path, strerror(errno));
|
||||||
return (0);
|
return (1);
|
||||||
cfg_add_cause("%s: %s", path, strerror(errno));
|
|
||||||
return (-1);
|
|
||||||
}
|
}
|
||||||
|
n = 0;
|
||||||
|
|
||||||
while ((buf = fparseln(f, NULL, &line, delim, 0)) != NULL) {
|
line = NULL;
|
||||||
log_debug("%s: %s", path, buf);
|
while ((buf = fgetln(f, &len))) {
|
||||||
|
if (buf[len - 1] == '\n')
|
||||||
p = buf;
|
buf[len - 1] = '\0';
|
||||||
while (isspace((u_char)*p))
|
else {
|
||||||
p++;
|
line = xrealloc(line, 1, len + 1);
|
||||||
if (*p == '\0') {
|
memcpy(line, buf, len);
|
||||||
free(buf);
|
line[len] = '\0';
|
||||||
continue;
|
buf = line;
|
||||||
}
|
}
|
||||||
q = p + strlen(p) - 1;
|
n++;
|
||||||
while (q != p && isspace((u_char)*q))
|
|
||||||
*q-- = '\0';
|
|
||||||
|
|
||||||
if (condition != 0 && strcmp(p, "%endif") == 0) {
|
if (cmd_string_parse(buf, &cmdlist, cause) != 0) {
|
||||||
condition = 0;
|
if (*cause == NULL)
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (strncmp(p, "%if ", 4) == 0) {
|
|
||||||
if (condition != 0) {
|
|
||||||
cfg_add_cause("%s:%zu: nested %%if", path,
|
|
||||||
line);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
goto error;
|
||||||
ft = format_create(NULL, NULL, FORMAT_NONE,
|
|
||||||
FORMAT_NOJOBS);
|
|
||||||
|
|
||||||
s = p + 3;
|
|
||||||
while (isspace((u_char)*s))
|
|
||||||
s++;
|
|
||||||
s = format_expand(ft, s);
|
|
||||||
if (*s != '\0' && (s[0] != '0' || s[1] != '\0'))
|
|
||||||
condition = 1;
|
|
||||||
else
|
|
||||||
condition = -1;
|
|
||||||
free(s);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (condition == -1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
cmdlist = cmd_string_parse(p, path, line, &cause1);
|
|
||||||
if (cmdlist == NULL) {
|
|
||||||
free(buf);
|
|
||||||
if (cause1 == NULL)
|
|
||||||
continue;
|
|
||||||
cfg_add_cause("%s:%zu: %s", path, line, cause1);
|
|
||||||
free(cause1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
if (cmdlist == NULL)
|
if (cmdlist == NULL)
|
||||||
continue;
|
continue;
|
||||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
cfg_cause = NULL;
|
||||||
if (item != NULL)
|
|
||||||
cmdq_insert_after(item, new_item);
|
|
||||||
else
|
|
||||||
cmdq_append(c, new_item);
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
|
|
||||||
found++;
|
if (ctxin == NULL) {
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = NULL;
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
} else {
|
||||||
|
ctx.msgdata = ctxin->msgdata;
|
||||||
|
ctx.curclient = ctxin->curclient;
|
||||||
|
ctx.cmdclient = ctxin->cmdclient;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.error = cfg_error;
|
||||||
|
ctx.print = cfg_print;
|
||||||
|
ctx.info = cfg_print;
|
||||||
|
|
||||||
|
cfg_cause = NULL;
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
if (cfg_cause != NULL) {
|
||||||
|
*cause = cfg_cause;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (line != NULL)
|
||||||
|
xfree(line);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
return (found);
|
return (0);
|
||||||
}
|
|
||||||
|
error:
|
||||||
void
|
if (line != NULL)
|
||||||
cfg_add_cause(const char *fmt, ...)
|
xfree(line);
|
||||||
{
|
fclose(f);
|
||||||
va_list ap;
|
|
||||||
char *msg;
|
xasprintf(&ptr, "%s: %s at line %u", path, *cause, n);
|
||||||
|
xfree(*cause);
|
||||||
va_start(ap, fmt);
|
*cause = ptr;
|
||||||
xvasprintf(&msg, fmt, ap);
|
return (1);
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
cfg_ncauses++;
|
|
||||||
cfg_causes = xreallocarray(cfg_causes, cfg_ncauses, sizeof *cfg_causes);
|
|
||||||
cfg_causes[cfg_ncauses - 1] = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cfg_print_causes(struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
for (i = 0; i < cfg_ncauses; i++) {
|
|
||||||
cmdq_print(item, "%s", cfg_causes[i]);
|
|
||||||
free(cfg_causes[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(cfg_causes);
|
|
||||||
cfg_causes = NULL;
|
|
||||||
cfg_ncauses = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cfg_show_causes(struct session *s)
|
|
||||||
{
|
|
||||||
struct window_pane *wp;
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
if (s == NULL || cfg_ncauses == 0)
|
|
||||||
return;
|
|
||||||
wp = s->curw->window->active;
|
|
||||||
|
|
||||||
window_pane_set_mode(wp, &window_copy_mode);
|
|
||||||
window_copy_init_for_output(wp);
|
|
||||||
for (i = 0; i < cfg_ncauses; i++) {
|
|
||||||
window_copy_add(wp, "%s", cfg_causes[i]);
|
|
||||||
free(cfg_causes[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(cfg_causes);
|
|
||||||
cfg_causes = NULL;
|
|
||||||
cfg_ncauses = 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
90
client-fn.c
Normal file
90
client-fn.c
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
/* $Id: client-fn.c,v 1.10 2009-08-14 21:04:04 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 <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
client_fill_session(struct msg_command_data *data)
|
||||||
|
{
|
||||||
|
char *env, *ptr1, *ptr2, buf[256];
|
||||||
|
size_t len;
|
||||||
|
const char *errstr;
|
||||||
|
long long ll;
|
||||||
|
|
||||||
|
data->pid = -1;
|
||||||
|
if ((env = getenv("TMUX")) == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ((ptr2 = strrchr(env, ',')) == NULL || ptr2 == env)
|
||||||
|
return;
|
||||||
|
for (ptr1 = ptr2 - 1; ptr1 > env && *ptr1 != ','; ptr1--)
|
||||||
|
;
|
||||||
|
if (*ptr1 != ',')
|
||||||
|
return;
|
||||||
|
ptr1++;
|
||||||
|
ptr2++;
|
||||||
|
|
||||||
|
len = ptr2 - ptr1 - 1;
|
||||||
|
if (len > (sizeof buf) - 1)
|
||||||
|
return;
|
||||||
|
memcpy(buf, ptr1, len);
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
ll = strtonum(buf, 0, LONG_MAX, &errstr);
|
||||||
|
if (errstr != NULL)
|
||||||
|
return;
|
||||||
|
data->pid = ll;
|
||||||
|
|
||||||
|
ll = strtonum(ptr2, 0, UINT_MAX, &errstr);
|
||||||
|
if (errstr != NULL)
|
||||||
|
return;
|
||||||
|
data->idx = ll;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
client_write_server(
|
||||||
|
struct client_ctx *cctx, enum msgtype type, void *buf, size_t len)
|
||||||
|
{
|
||||||
|
imsg_compose(&cctx->ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
client_suspend(void)
|
||||||
|
{
|
||||||
|
struct sigaction act;
|
||||||
|
|
||||||
|
memset(&act, 0, sizeof act);
|
||||||
|
sigemptyset(&act.sa_mask);
|
||||||
|
act.sa_flags = SA_RESTART;
|
||||||
|
|
||||||
|
act.sa_handler = SIG_DFL;
|
||||||
|
if (sigaction(SIGTSTP, &act, NULL) != 0)
|
||||||
|
fatal("sigaction failed");
|
||||||
|
|
||||||
|
act.sa_handler = sighandler;
|
||||||
|
if (sigaction(SIGCONT, &act, NULL) != 0)
|
||||||
|
fatal("sigaction failed");
|
||||||
|
|
||||||
|
kill(getpid(), SIGTSTP);
|
||||||
|
}
|
||||||
920
client.c
920
client.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: client.c,v 1.70 2009-09-03 21:06:30 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -17,706 +17,314 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/file.h>
|
#include <sys/ioctl.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>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.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 <syslog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
static struct tmuxproc *client_proc;
|
void client_send_environ(struct client_ctx *);
|
||||||
static struct tmuxpeer *client_peer;
|
void client_handle_winch(struct client_ctx *);
|
||||||
static int client_flags;
|
|
||||||
static struct event client_stdin;
|
|
||||||
static 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;
|
|
||||||
static int client_exitval;
|
|
||||||
static enum msgtype client_exittype;
|
|
||||||
static const char *client_exitsession;
|
|
||||||
static const char *client_execshell;
|
|
||||||
static const char *client_execcmd;
|
|
||||||
static int client_attached;
|
|
||||||
|
|
||||||
static __dead void client_exec(const char *,const char *);
|
int
|
||||||
static int client_get_lock(char *);
|
client_init(char *path, struct client_ctx *cctx, int cmdflags, int flags)
|
||||||
static int client_connect(struct event_base *, const char *, int);
|
|
||||||
static void client_send_identify(const char *, const char *);
|
|
||||||
static void client_stdin_callback(int, short, void *);
|
|
||||||
static void client_write(int, const char *, size_t);
|
|
||||||
static void client_signal(int);
|
|
||||||
static void client_dispatch(struct imsg *, void *);
|
|
||||||
static void client_dispatch_attached(struct imsg *);
|
|
||||||
static void client_dispatch_wait(struct imsg *, const char *);
|
|
||||||
static 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 -2 to
|
|
||||||
* retry. Return -1 on failure to continue and start the server anyway.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
client_get_lock(char *lockfile)
|
|
||||||
{
|
{
|
||||||
int lockfd;
|
struct sockaddr_un sa;
|
||||||
|
struct stat sb;
|
||||||
|
struct msg_identify_data data;
|
||||||
|
struct winsize ws;
|
||||||
|
size_t size;
|
||||||
|
int fd, fd2, mode;
|
||||||
|
char *name, *term;
|
||||||
|
#ifdef HAVE_SETPROCTITLE
|
||||||
|
char rpathbuf[MAXPATHLEN];
|
||||||
|
#endif
|
||||||
|
|
||||||
log_debug("lock file is %s", lockfile);
|
#ifdef HAVE_SETPROCTITLE
|
||||||
|
if (realpath(path, rpathbuf) == NULL)
|
||||||
|
strlcpy(rpathbuf, path, sizeof rpathbuf);
|
||||||
|
setproctitle("client (%s)", rpathbuf);
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((lockfd = open(lockfile, O_WRONLY|O_CREAT, 0600)) == -1) {
|
if (lstat(path, &sb) != 0) {
|
||||||
log_debug("open failed: %s", strerror(errno));
|
if (cmdflags & CMD_STARTSERVER && errno == ENOENT) {
|
||||||
return (-1);
|
if ((fd = server_start(path)) == -1)
|
||||||
|
goto start_failed;
|
||||||
|
goto server_started;
|
||||||
|
}
|
||||||
|
goto not_found;
|
||||||
}
|
}
|
||||||
|
if (!S_ISSOCK(sb.st_mode)) {
|
||||||
if (flock(lockfd, LOCK_EX|LOCK_NB) == -1) {
|
errno = ENOTSOCK;
|
||||||
log_debug("flock failed: %s", strerror(errno));
|
goto not_found;
|
||||||
if (errno != EAGAIN)
|
|
||||||
return (lockfd);
|
|
||||||
while (flock(lockfd, LOCK_EX) == -1 && errno == EINTR)
|
|
||||||
/* nothing */;
|
|
||||||
close(lockfd);
|
|
||||||
return (-2);
|
|
||||||
}
|
}
|
||||||
log_debug("flock succeeded");
|
|
||||||
|
|
||||||
return (lockfd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Connect client to server. */
|
|
||||||
static int
|
|
||||||
client_connect(struct event_base *base, const char *path, int start_server)
|
|
||||||
{
|
|
||||||
struct sockaddr_un sa;
|
|
||||||
size_t size;
|
|
||||||
int fd, lockfd = -1, locked = 0;
|
|
||||||
char *lockfile = NULL;
|
|
||||||
|
|
||||||
memset(&sa, 0, sizeof sa);
|
memset(&sa, 0, sizeof sa);
|
||||||
sa.sun_family = AF_UNIX;
|
sa.sun_family = AF_UNIX;
|
||||||
size = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
|
size = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
|
||||||
if (size >= sizeof sa.sun_path) {
|
if (size >= sizeof sa.sun_path) {
|
||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
return (-1);
|
goto not_found;
|
||||||
}
|
}
|
||||||
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)
|
||||||
return (-1);
|
fatal("socket");
|
||||||
|
|
||||||
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)
|
|
||||||
goto failed;
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (!locked) {
|
|
||||||
xasprintf(&lockfile, "%s.lock", path);
|
|
||||||
if ((lockfd = client_get_lock(lockfile)) < 0) {
|
|
||||||
log_debug("didn't get lock (%d)", lockfd);
|
|
||||||
|
|
||||||
free(lockfile);
|
|
||||||
lockfile = NULL;
|
|
||||||
|
|
||||||
if (lockfd == -2)
|
|
||||||
goto retry;
|
|
||||||
}
|
|
||||||
log_debug("got lock (%d)", lockfd);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 (lockfd >= 0 && unlink(path) != 0 && errno != ENOENT) {
|
|
||||||
free(lockfile);
|
|
||||||
close(lockfd);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
fd = server_start(base, lockfd, lockfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (locked && lockfd >= 0) {
|
|
||||||
free(lockfile);
|
|
||||||
close(lockfd);
|
|
||||||
}
|
|
||||||
setblocking(fd, 0);
|
|
||||||
return (fd);
|
|
||||||
|
|
||||||
failed:
|
|
||||||
if (locked) {
|
|
||||||
free(lockfile);
|
|
||||||
close(lockfd);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
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. */
|
|
||||||
int
|
|
||||||
client_main(struct event_base *base, int argc, char **argv, int flags,
|
|
||||||
const char *shellcmd)
|
|
||||||
{
|
|
||||||
struct cmd *cmd;
|
|
||||||
struct cmd_list *cmdlist;
|
|
||||||
struct msg_command_data *data;
|
|
||||||
int cmdflags, fd, i;
|
|
||||||
const char *ttynam, *cwd;
|
|
||||||
pid_t ppid;
|
|
||||||
enum msgtype msg;
|
|
||||||
char *cause, path[PATH_MAX];
|
|
||||||
struct termios tio, saved_tio;
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
/* Ignore SIGCHLD now or daemon() in the server will leave a zombie. */
|
|
||||||
signal(SIGCHLD, SIG_IGN);
|
|
||||||
|
|
||||||
/* Save the flags. */
|
|
||||||
client_flags = flags;
|
|
||||||
|
|
||||||
/* Set up the initial command. */
|
|
||||||
cmdflags = 0;
|
|
||||||
if (shellcmd != NULL) {
|
|
||||||
msg = MSG_SHELL;
|
|
||||||
cmdflags = CMD_STARTSERVER;
|
|
||||||
} else if (argc == 0) {
|
|
||||||
msg = MSG_COMMAND;
|
|
||||||
cmdflags = CMD_STARTSERVER;
|
|
||||||
} else {
|
|
||||||
msg = MSG_COMMAND;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* It sucks parsing the command string twice (in client and
|
|
||||||
* later in server) but it is necessary to get the start server
|
|
||||||
* flag.
|
|
||||||
*/
|
|
||||||
cmdlist = cmd_list_parse(argc, argv, NULL, 0, &cause);
|
|
||||||
if (cmdlist != NULL) {
|
|
||||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
|
||||||
if (cmd->entry->flags & CMD_STARTSERVER)
|
|
||||||
cmdflags |= CMD_STARTSERVER;
|
|
||||||
}
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create client process structure (starts logging). */
|
|
||||||
client_proc = proc_start("client", base, 0, client_signal);
|
|
||||||
|
|
||||||
/* Initialize the client socket and start the server. */
|
|
||||||
fd = client_connect(base, socket_path, cmdflags & CMD_STARTSERVER);
|
|
||||||
if (fd == -1) {
|
|
||||||
if (errno == ECONNREFUSED) {
|
if (errno == ECONNREFUSED) {
|
||||||
fprintf(stderr, "no server running on %s\n",
|
if (unlink(path) != 0 || !(cmdflags & CMD_STARTSERVER))
|
||||||
socket_path);
|
goto not_found;
|
||||||
} else {
|
if ((fd = server_start(path)) == -1)
|
||||||
fprintf(stderr, "error connecting to %s (%s)\n",
|
goto start_failed;
|
||||||
socket_path, strerror(errno));
|
goto server_started;
|
||||||
}
|
}
|
||||||
|
goto not_found;
|
||||||
|
}
|
||||||
|
|
||||||
|
server_started:
|
||||||
|
if ((mode = fcntl(fd, F_GETFL)) == -1)
|
||||||
|
fatal("fcntl failed");
|
||||||
|
if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||||
|
fatal("fcntl failed");
|
||||||
|
imsg_init(&cctx->ibuf, fd);
|
||||||
|
|
||||||
|
if (cmdflags & CMD_SENDENVIRON)
|
||||||
|
client_send_environ(cctx);
|
||||||
|
if (isatty(STDIN_FILENO)) {
|
||||||
|
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1)
|
||||||
|
fatal("ioctl(TIOCGWINSZ)");
|
||||||
|
data.flags = flags;
|
||||||
|
data.sx = ws.ws_col;
|
||||||
|
data.sy = ws.ws_row;
|
||||||
|
|
||||||
|
if (getcwd(data.cwd, sizeof data.cwd) == NULL)
|
||||||
|
*data.cwd = '\0';
|
||||||
|
|
||||||
|
*data.term = '\0';
|
||||||
|
if ((term = getenv("TERM")) != NULL) {
|
||||||
|
if (strlcpy(data.term,
|
||||||
|
term, sizeof data.term) >= sizeof data.term)
|
||||||
|
*data.term = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
*data.tty = '\0';
|
||||||
|
if ((name = ttyname(STDIN_FILENO)) == NULL)
|
||||||
|
fatal("ttyname failed");
|
||||||
|
if (strlcpy(data.tty, name, sizeof data.tty) >= sizeof data.tty)
|
||||||
|
fatalx("ttyname failed");
|
||||||
|
|
||||||
|
fd2 = dup(STDIN_FILENO);
|
||||||
|
imsg_compose(&cctx->ibuf, MSG_IDENTIFY,
|
||||||
|
PROTOCOL_VERSION, -1, fd2, &data, sizeof data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
start_failed:
|
||||||
|
log_warnx("server failed to start");
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
not_found:
|
||||||
|
log_warn("server not found");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
client_send_environ(struct client_ctx *cctx)
|
||||||
|
{
|
||||||
|
char **var;
|
||||||
|
struct msg_environ_data data;
|
||||||
|
|
||||||
|
for (var = environ; *var != NULL; var++) {
|
||||||
|
if (strlcpy(data.var, *var, sizeof data.var) >= sizeof data.var)
|
||||||
|
continue;
|
||||||
|
client_write_server(cctx, MSG_ENVIRON, &data, sizeof data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
client_main(struct client_ctx *cctx)
|
||||||
|
{
|
||||||
|
struct pollfd pfd;
|
||||||
|
int n, nfds;
|
||||||
|
|
||||||
|
siginit();
|
||||||
|
|
||||||
|
logfile("client");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* imsg_read in the first client poll loop (before the terminal has
|
||||||
|
* been initialiased) may have read messages into the buffer after the
|
||||||
|
* MSG_READY switched to here. Process anything outstanding now so poll
|
||||||
|
* doesn't hang waiting for messages that have already arrived.
|
||||||
|
*/
|
||||||
|
if (client_msg_dispatch(cctx) != 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if (sigterm)
|
||||||
|
client_write_server(cctx, MSG_EXITING, NULL, 0);
|
||||||
|
if (sigchld) {
|
||||||
|
waitpid(WAIT_ANY, NULL, WNOHANG);
|
||||||
|
sigchld = 0;
|
||||||
|
}
|
||||||
|
if (sigwinch)
|
||||||
|
client_handle_winch(cctx);
|
||||||
|
if (sigcont) {
|
||||||
|
siginit();
|
||||||
|
client_write_server(cctx, MSG_WAKEUP, NULL, 0);
|
||||||
|
sigcont = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pfd.fd = cctx->ibuf.fd;
|
||||||
|
pfd.events = POLLIN;
|
||||||
|
if (cctx->ibuf.w.queued > 0)
|
||||||
|
pfd.events |= POLLOUT;
|
||||||
|
|
||||||
|
if ((nfds = poll(&pfd, 1, INFTIM)) == -1) {
|
||||||
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
|
continue;
|
||||||
|
fatal("poll failed");
|
||||||
|
}
|
||||||
|
if (nfds == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (pfd.revents & (POLLERR|POLLHUP|POLLNVAL))
|
||||||
|
fatalx("socket error");
|
||||||
|
|
||||||
|
if (pfd.revents & POLLIN) {
|
||||||
|
if ((n = imsg_read(&cctx->ibuf)) == -1 || n == 0) {
|
||||||
|
cctx->exittype = CCTX_DIED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (client_msg_dispatch(cctx) != 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pfd.revents & POLLOUT) {
|
||||||
|
if (msgbuf_write(&cctx->ibuf.w) < 0) {
|
||||||
|
cctx->exittype = CCTX_DIED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (sigterm) {
|
||||||
|
printf("[terminated]\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
switch (cctx->exittype) {
|
||||||
|
case CCTX_DIED:
|
||||||
|
printf("[lost server]\n");
|
||||||
|
return (0);
|
||||||
|
case CCTX_SHUTDOWN:
|
||||||
|
printf("[server exited]\n");
|
||||||
|
return (0);
|
||||||
|
case CCTX_EXIT:
|
||||||
|
if (cctx->errstr != NULL) {
|
||||||
|
printf("[error: %s]\n", cctx->errstr);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
printf("[exited]\n");
|
||||||
|
return (0);
|
||||||
|
case CCTX_DETACH:
|
||||||
|
printf("[detached]\n");
|
||||||
|
return (0);
|
||||||
|
default:
|
||||||
|
printf("[unknown error]\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
client_peer = proc_add_peer(client_proc, fd, client_dispatch,
|
|
||||||
(void *)shellcmd);
|
|
||||||
|
|
||||||
/* Save these before pledge(). */
|
|
||||||
if ((cwd = getcwd(path, sizeof path)) == NULL) {
|
|
||||||
if ((cwd = find_home()) == NULL)
|
|
||||||
cwd = "/";
|
|
||||||
}
|
|
||||||
if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
|
|
||||||
ttynam = "";
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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");
|
|
||||||
|
|
||||||
/* Free stuff that is not used in the client. */
|
|
||||||
if (ptm_fd != -1)
|
|
||||||
close(ptm_fd);
|
|
||||||
options_free(global_options);
|
|
||||||
options_free(global_s_options);
|
|
||||||
options_free(global_w_options);
|
|
||||||
environ_free(global_environ);
|
|
||||||
|
|
||||||
/* Create stdin handler. */
|
|
||||||
setblocking(STDIN_FILENO, 0);
|
|
||||||
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. */
|
|
||||||
client_send_identify(ttynam, cwd);
|
|
||||||
|
|
||||||
/* Send first command. */
|
|
||||||
if (msg == MSG_COMMAND) {
|
|
||||||
/* How big is the command? */
|
|
||||||
size = 0;
|
|
||||||
for (i = 0; i < argc; i++)
|
|
||||||
size += strlen(argv[i]) + 1;
|
|
||||||
data = xmalloc((sizeof *data) + size);
|
|
||||||
|
|
||||||
/* Prepare command for server. */
|
|
||||||
data->argc = argc;
|
|
||||||
if (cmd_pack_argv(argc, argv, (char *)(data + 1), size) != 0) {
|
|
||||||
fprintf(stderr, "command too long\n");
|
|
||||||
free(data);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
size += sizeof *data;
|
|
||||||
|
|
||||||
/* Send the command. */
|
|
||||||
if (proc_send(client_peer, msg, -1, data, size) != 0) {
|
|
||||||
fprintf(stderr, "failed to send command\n");
|
|
||||||
free(data);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
free(data);
|
|
||||||
} else if (msg == MSG_SHELL)
|
|
||||||
proc_send(client_peer, msg, -1, NULL, 0);
|
|
||||||
|
|
||||||
/* Start main loop. */
|
|
||||||
proc_loop(client_proc, NULL);
|
|
||||||
|
|
||||||
/* Run command if user requested exec, instead of exiting. */
|
|
||||||
if (client_exittype == MSG_EXEC) {
|
|
||||||
if (client_flags & CLIENT_CONTROLCONTROL)
|
|
||||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
|
|
||||||
clear_signals(0);
|
|
||||||
client_exec(client_execshell, client_execcmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print the exit message, if any, and exit. */
|
|
||||||
if (client_attached) {
|
|
||||||
if (client_exitreason != CLIENT_EXIT_NONE)
|
|
||||||
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);
|
|
||||||
} else if (client_exitreason != CLIENT_EXIT_NONE)
|
|
||||||
fprintf(stderr, "%s\n", client_exit_message());
|
|
||||||
setblocking(STDIN_FILENO, 1);
|
|
||||||
return (client_exitval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send identify messages to server. */
|
void
|
||||||
static void
|
client_handle_winch(struct client_ctx *cctx)
|
||||||
client_send_identify(const char *ttynam, const char *cwd)
|
|
||||||
{
|
{
|
||||||
const char *s;
|
struct msg_resize_data data;
|
||||||
char **ss;
|
struct winsize ws;
|
||||||
size_t sslen;
|
|
||||||
int fd, flags = client_flags;
|
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
proc_send(client_peer, MSG_IDENTIFY_FLAGS, -1, &flags, sizeof flags);
|
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1)
|
||||||
|
fatal("ioctl failed");
|
||||||
|
|
||||||
if ((s = getenv("TERM")) == NULL)
|
data.sx = ws.ws_col;
|
||||||
s = "";
|
data.sy = ws.ws_row;
|
||||||
proc_send(client_peer, MSG_IDENTIFY_TERM, -1, s, strlen(s) + 1);
|
client_write_server(cctx, MSG_RESIZE, &data, sizeof data);
|
||||||
|
|
||||||
proc_send(client_peer, MSG_IDENTIFY_TTYNAME, -1, ttynam,
|
sigwinch = 0;
|
||||||
strlen(ttynam) + 1);
|
|
||||||
proc_send(client_peer, MSG_IDENTIFY_CWD, -1, cwd, strlen(cwd) + 1);
|
|
||||||
|
|
||||||
if ((fd = dup(STDIN_FILENO)) == -1)
|
|
||||||
fatal("dup failed");
|
|
||||||
proc_send(client_peer, MSG_IDENTIFY_STDIN, fd, NULL, 0);
|
|
||||||
|
|
||||||
pid = getpid();
|
|
||||||
proc_send(client_peer, MSG_IDENTIFY_CLIENTPID, -1, &pid, sizeof pid);
|
|
||||||
|
|
||||||
for (ss = environ; *ss != NULL; ss++) {
|
|
||||||
sslen = strlen(*ss) + 1;
|
|
||||||
if (sslen > MAX_IMSGSIZE - IMSG_HEADER_SIZE)
|
|
||||||
continue;
|
|
||||||
proc_send(client_peer, MSG_IDENTIFY_ENVIRON, -1, *ss, sslen);
|
|
||||||
}
|
|
||||||
|
|
||||||
proc_send(client_peer, MSG_IDENTIFY_DONE, -1, NULL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback for client stdin read events. */
|
int
|
||||||
static void
|
client_msg_dispatch(struct client_ctx *cctx)
|
||||||
client_stdin_callback(__unused int fd, __unused short events,
|
|
||||||
__unused void *arg)
|
|
||||||
{
|
{
|
||||||
struct msg_stdin_data data;
|
struct imsg imsg;
|
||||||
|
struct msg_print_data printdata;
|
||||||
|
ssize_t n, datalen;
|
||||||
|
|
||||||
data.size = read(STDIN_FILENO, data.data, sizeof data.data);
|
for (;;) {
|
||||||
if (data.size < 0 && (errno == EINTR || errno == EAGAIN))
|
if ((n = imsg_get(&cctx->ibuf, &imsg)) == -1)
|
||||||
return;
|
fatalx("imsg_get failed");
|
||||||
|
if (n == 0)
|
||||||
|
return (0);
|
||||||
|
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
|
||||||
proc_send(client_peer, MSG_STDIN, -1, &data, sizeof data);
|
switch (imsg.hdr.type) {
|
||||||
if (data.size <= 0)
|
case MSG_DETACH:
|
||||||
event_del(&client_stdin);
|
if (datalen != 0)
|
||||||
}
|
fatalx("bad MSG_DETACH size");
|
||||||
|
|
||||||
/* Force write to file descriptor. */
|
client_write_server(cctx, MSG_EXITING, NULL, 0);
|
||||||
static void
|
cctx->exittype = CCTX_DETACH;
|
||||||
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;
|
break;
|
||||||
|
case MSG_ERROR:
|
||||||
|
if (datalen != sizeof printdata)
|
||||||
|
fatalx("bad MSG_ERROR size");
|
||||||
|
memcpy(&printdata, imsg.data, sizeof printdata);
|
||||||
|
|
||||||
|
printdata.msg[(sizeof printdata.msg) - 1] = '\0';
|
||||||
|
/* Error string used after exit message from server. */
|
||||||
|
cctx->errstr = xstrdup(printdata.msg);
|
||||||
|
imsg_free(&imsg);
|
||||||
|
return (-1);
|
||||||
|
case MSG_EXIT:
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_EXIT size");
|
||||||
|
|
||||||
|
client_write_server(cctx, MSG_EXITING, NULL, 0);
|
||||||
|
cctx->exittype = CCTX_EXIT;
|
||||||
|
break;
|
||||||
|
case MSG_EXITED:
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_EXITED size");
|
||||||
|
|
||||||
|
imsg_free(&imsg);
|
||||||
|
return (-1);
|
||||||
|
case MSG_SHUTDOWN:
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_SHUTDOWN size");
|
||||||
|
|
||||||
|
client_write_server(cctx, MSG_EXITING, NULL, 0);
|
||||||
|
cctx->exittype = CCTX_SHUTDOWN;
|
||||||
|
break;
|
||||||
|
case MSG_SUSPEND:
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_SUSPEND size");
|
||||||
|
|
||||||
|
client_suspend();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fatalx("unexpected message");
|
||||||
}
|
}
|
||||||
data += used;
|
|
||||||
size -= used;
|
imsg_free(&imsg);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Run command in shell; used for -c. */
|
|
||||||
static __dead void
|
|
||||||
client_exec(const char *shell, const char *shellcmd)
|
|
||||||
{
|
|
||||||
const char *name, *ptr;
|
|
||||||
char *argv0;
|
|
||||||
|
|
||||||
log_debug("shell %s, command %s", shell, shellcmd);
|
|
||||||
|
|
||||||
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", shellcmd, (char *) NULL);
|
|
||||||
fatal("execl failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Callback to handle signals in the client. */
|
|
||||||
static void
|
|
||||||
client_signal(int sig)
|
|
||||||
{
|
|
||||||
struct sigaction sigact;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
if (sig == SIGCHLD)
|
|
||||||
waitpid(WAIT_ANY, &status, WNOHANG);
|
|
||||||
else if (!client_attached) {
|
|
||||||
if (sig == SIGTERM)
|
|
||||||
proc_exit(client_proc);
|
|
||||||
} else {
|
|
||||||
switch (sig) {
|
|
||||||
case SIGHUP:
|
|
||||||
client_exitreason = CLIENT_EXIT_LOST_TTY;
|
|
||||||
client_exitval = 1;
|
|
||||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
|
||||||
break;
|
|
||||||
case SIGTERM:
|
|
||||||
client_exitreason = CLIENT_EXIT_TERMINATED;
|
|
||||||
client_exitval = 1;
|
|
||||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
|
||||||
break;
|
|
||||||
case SIGWINCH:
|
|
||||||
proc_send(client_peer, MSG_RESIZE, -1, NULL, 0);
|
|
||||||
break;
|
|
||||||
case SIGCONT:
|
|
||||||
memset(&sigact, 0, sizeof sigact);
|
|
||||||
sigemptyset(&sigact.sa_mask);
|
|
||||||
sigact.sa_flags = SA_RESTART;
|
|
||||||
sigact.sa_handler = SIG_IGN;
|
|
||||||
if (sigaction(SIGTSTP, &sigact, NULL) != 0)
|
|
||||||
fatal("sigaction failed");
|
|
||||||
proc_send(client_peer, MSG_WAKEUP, -1, NULL, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Callback for client read events. */
|
|
||||||
static void
|
|
||||||
client_dispatch(struct imsg *imsg, void *arg)
|
|
||||||
{
|
|
||||||
if (imsg == NULL) {
|
|
||||||
client_exitreason = CLIENT_EXIT_LOST_SERVER;
|
|
||||||
client_exitval = 1;
|
|
||||||
proc_exit(client_proc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (client_attached)
|
|
||||||
client_dispatch_attached(imsg);
|
|
||||||
else
|
|
||||||
client_dispatch_wait(imsg, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
|
||||||
static void
|
|
||||||
client_dispatch_wait(struct imsg *imsg, const char *shellcmd)
|
|
||||||
{
|
|
||||||
char *data;
|
|
||||||
ssize_t datalen;
|
|
||||||
struct msg_stdout_data stdoutdata;
|
|
||||||
struct msg_stderr_data stderrdata;
|
|
||||||
int retval;
|
|
||||||
static int pledge_applied;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* "sendfd" is no longer required once all of the identify messages
|
|
||||||
* 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
data = imsg->data;
|
|
||||||
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
|
|
||||||
|
|
||||||
switch (imsg->hdr.type) {
|
|
||||||
case MSG_EXIT:
|
|
||||||
case MSG_SHUTDOWN:
|
|
||||||
if (datalen != sizeof retval && datalen != 0)
|
|
||||||
fatalx("bad MSG_EXIT size");
|
|
||||||
if (datalen == sizeof retval) {
|
|
||||||
memcpy(&retval, data, sizeof retval);
|
|
||||||
client_exitval = retval;
|
|
||||||
}
|
|
||||||
proc_exit(client_proc);
|
|
||||||
break;
|
|
||||||
case MSG_READY:
|
|
||||||
if (datalen != 0)
|
|
||||||
fatalx("bad MSG_READY size");
|
|
||||||
|
|
||||||
event_del(&client_stdin);
|
|
||||||
client_attached = 1;
|
|
||||||
proc_send(client_peer, MSG_RESIZE, -1, 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;
|
|
||||||
case MSG_VERSION:
|
|
||||||
if (datalen != 0)
|
|
||||||
fatalx("bad MSG_VERSION size");
|
|
||||||
|
|
||||||
fprintf(stderr, "protocol version mismatch "
|
|
||||||
"(client %d, server %u)\n", PROTOCOL_VERSION,
|
|
||||||
imsg->hdr.peerid & 0xff);
|
|
||||||
client_exitval = 1;
|
|
||||||
proc_exit(client_proc);
|
|
||||||
break;
|
|
||||||
case MSG_SHELL:
|
|
||||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
|
||||||
fatalx("bad MSG_SHELL string");
|
|
||||||
|
|
||||||
clear_signals(0);
|
|
||||||
client_exec(data, shellcmd);
|
|
||||||
/* NOTREACHED */
|
|
||||||
case MSG_DETACH:
|
|
||||||
case MSG_DETACHKILL:
|
|
||||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
|
||||||
break;
|
|
||||||
case MSG_EXITED:
|
|
||||||
proc_exit(client_proc);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dispatch imsgs in attached state (after MSG_READY). */
|
|
||||||
static void
|
|
||||||
client_dispatch_attached(struct imsg *imsg)
|
|
||||||
{
|
|
||||||
struct sigaction sigact;
|
|
||||||
char *data;
|
|
||||||
ssize_t datalen;
|
|
||||||
|
|
||||||
data = imsg->data;
|
|
||||||
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
|
|
||||||
|
|
||||||
switch (imsg->hdr.type) {
|
|
||||||
case MSG_DETACH:
|
|
||||||
case MSG_DETACHKILL:
|
|
||||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
|
||||||
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;
|
|
||||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
|
||||||
break;
|
|
||||||
case MSG_EXEC:
|
|
||||||
if (datalen == 0 || data[datalen - 1] != '\0' ||
|
|
||||||
strlen(data) + 1 == (size_t)datalen)
|
|
||||||
fatalx("bad MSG_EXEC string");
|
|
||||||
client_execcmd = xstrdup(data);
|
|
||||||
client_execshell = xstrdup(data + strlen(data) + 1);
|
|
||||||
|
|
||||||
client_exittype = imsg->hdr.type;
|
|
||||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
|
||||||
break;
|
|
||||||
case MSG_EXIT:
|
|
||||||
if (datalen != 0 && datalen != sizeof (int))
|
|
||||||
fatalx("bad MSG_EXIT size");
|
|
||||||
|
|
||||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
|
||||||
client_exitreason = CLIENT_EXIT_EXITED;
|
|
||||||
break;
|
|
||||||
case MSG_EXITED:
|
|
||||||
if (datalen != 0)
|
|
||||||
fatalx("bad MSG_EXITED size");
|
|
||||||
|
|
||||||
proc_exit(client_proc);
|
|
||||||
break;
|
|
||||||
case MSG_SHUTDOWN:
|
|
||||||
if (datalen != 0)
|
|
||||||
fatalx("bad MSG_SHUTDOWN size");
|
|
||||||
|
|
||||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
|
||||||
client_exitreason = CLIENT_EXIT_SERVER_EXITED;
|
|
||||||
client_exitval = 1;
|
|
||||||
break;
|
|
||||||
case MSG_SUSPEND:
|
|
||||||
if (datalen != 0)
|
|
||||||
fatalx("bad MSG_SUSPEND size");
|
|
||||||
|
|
||||||
memset(&sigact, 0, sizeof sigact);
|
|
||||||
sigemptyset(&sigact.sa_mask);
|
|
||||||
sigact.sa_flags = SA_RESTART;
|
|
||||||
sigact.sa_handler = SIG_DFL;
|
|
||||||
if (sigaction(SIGTSTP, &sigact, NULL) != 0)
|
|
||||||
fatal("sigaction failed");
|
|
||||||
kill(getpid(), SIGTSTP);
|
|
||||||
break;
|
|
||||||
case MSG_LOCK:
|
|
||||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
|
||||||
fatalx("bad MSG_LOCK string");
|
|
||||||
|
|
||||||
system(data);
|
|
||||||
proc_send(client_peer, MSG_UNLOCK, -1, NULL, 0);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
159
clock.c
Normal file
159
clock.c
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
/* $Id: clock.c,v 1.7 2009-09-11 14:13:52 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, u_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,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-attach-session.c,v 1.32 2009-08-09 17:48:55 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,154 +18,89 @@
|
|||||||
|
|
||||||
#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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_attach_session_exec(struct cmd *,
|
int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_attach_session_entry = {
|
const struct cmd_entry cmd_attach_session_entry = {
|
||||||
.name = "attach-session",
|
"attach-session", "attach",
|
||||||
.alias = "attach",
|
"[-d] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, CMD_CHFLAG('d'),
|
||||||
.args = { "c:dErt:", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_attach_session_exec,
|
||||||
/* -t is special */
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_STARTSERVER,
|
|
||||||
.exec = cmd_attach_session_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
int rflag, const char *cflag, int Eflag)
|
|
||||||
{
|
{
|
||||||
struct cmd_find_state *current = &item->shared->current;
|
struct cmd_target_data *data = self->data;
|
||||||
enum cmd_find_type type;
|
|
||||||
int flags;
|
|
||||||
struct client *c = item->client, *c_loop;
|
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct client *c;
|
||||||
struct window_pane *wp;
|
const char *update;
|
||||||
char *cause;
|
char *overrides, *cause;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
if (RB_EMPTY(&sessions)) {
|
if (ARRAY_LENGTH(&sessions) == 0) {
|
||||||
cmdq_error(item, "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 (c == NULL)
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
if (server_client_check_nested(c)) {
|
|
||||||
cmdq_error(item, "sessions should be nested with care, "
|
|
||||||
"unset $TMUX to force");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') {
|
if (ctx->cmdclient == NULL) {
|
||||||
type = CMD_FIND_PANE;
|
if (data->chflags & CMD_CHFLAG('d')) {
|
||||||
flags = 0;
|
/*
|
||||||
} else {
|
* Can't use server_write_session in case attaching to
|
||||||
type = CMD_FIND_SESSION;
|
* the same session as currently attached to.
|
||||||
flags = CMD_FIND_PREFER_UNATTACHED;
|
*/
|
||||||
}
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
if (cmd_find_target(&item->target, item, tflag, type, flags) != 0)
|
c = ARRAY_ITEM(&clients, i);
|
||||||
return (CMD_RETURN_ERROR);
|
if (c == NULL || c->session != s)
|
||||||
s = item->target.s;
|
|
||||||
wl = item->target.wl;
|
|
||||||
wp = item->target.wp;
|
|
||||||
|
|
||||||
if (wl != NULL) {
|
|
||||||
if (wp != NULL)
|
|
||||||
window_set_active_pane(wp->window, wp);
|
|
||||||
session_set_current(s, wl);
|
|
||||||
if (wp != NULL)
|
|
||||||
cmd_find_from_winlink_pane(current, wl, wp);
|
|
||||||
else
|
|
||||||
cmd_find_from_winlink(current, wl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cflag != NULL) {
|
|
||||||
free((void *)s->cwd);
|
|
||||||
s->cwd = format_single(item, cflag, c, s, wl, wp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->session != NULL) {
|
|
||||||
if (dflag) {
|
|
||||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
|
||||||
if (c_loop->session != s || c == c_loop)
|
|
||||||
continue;
|
continue;
|
||||||
server_client_detach(c_loop, MSG_DETACH);
|
if (c == ctx->curclient)
|
||||||
|
continue;
|
||||||
|
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Eflag)
|
|
||||||
environ_update(s->options, c->environ, s->environ);
|
ctx->curclient->session = s;
|
||||||
|
server_redraw_client(ctx->curclient);
|
||||||
c->session = s;
|
|
||||||
if (~item->shared->flags & CMDQ_SHARED_REPEAT)
|
|
||||||
server_client_set_key_table(c, NULL);
|
|
||||||
status_timer_start(c);
|
|
||||||
notify_client("client-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(item, "open terminal failed: %s", cause);
|
ctx->error(ctx, "not a terminal");
|
||||||
free(cause);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
if (rflag)
|
|
||||||
c->flags |= CLIENT_READONLY;
|
|
||||||
|
|
||||||
if (dflag) {
|
overrides =
|
||||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
options_get_string(&s->options, "terminal-overrides");
|
||||||
if (c_loop->session != s || c == c_loop)
|
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||||
continue;
|
ctx->error(ctx, "terminal open failed: %s", cause);
|
||||||
server_client_detach(c_loop, MSG_DETACH);
|
xfree(cause);
|
||||||
}
|
return (-1);
|
||||||
}
|
}
|
||||||
if (!Eflag)
|
|
||||||
environ_update(s->options, c->environ, s->environ);
|
|
||||||
|
|
||||||
c->session = s;
|
if (data->chflags & CMD_CHFLAG('d'))
|
||||||
server_client_set_key_table(c, NULL);
|
server_write_session(s, MSG_DETACH, NULL, 0);
|
||||||
status_timer_start(c);
|
|
||||||
notify_client("client-session-changed", c);
|
|
||||||
session_update_activity(s, NULL);
|
|
||||||
gettimeofday(&s->last_attached_time, NULL);
|
|
||||||
server_redraw_client(c);
|
|
||||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
|
||||||
|
|
||||||
if (~c->flags & CLIENT_CONTROL)
|
ctx->cmdclient->session = s;
|
||||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
notify_client("client-attached", c);
|
|
||||||
c->flags |= CLIENT_ATTACHED;
|
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();
|
||||||
alerts_check_session(s);
|
|
||||||
server_update_socket();
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (1); /* 1 means don't tell command client to exit */
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
|
|
||||||
return (cmd_attach_session(item, args_get(args, 't'),
|
|
||||||
args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'),
|
|
||||||
args_has(args, 'E')));
|
|
||||||
}
|
}
|
||||||
|
|||||||
203
cmd-bind-key.c
203
cmd-bind-key.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-bind-key.c,v 1.25 2009-07-28 23:19:06 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,59 +18,184 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bind a key to a command.
|
* Bind a key to a command, this recurses through cmd_*.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmdq_item *);
|
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);
|
||||||
|
|
||||||
const struct cmd_entry cmd_bind_key_entry = {
|
int cmd_bind_key_table(struct cmd *, struct cmd_ctx *);
|
||||||
.name = "bind-key",
|
|
||||||
.alias = "bind",
|
|
||||||
|
|
||||||
.args = { "cnrT:", 2, -1 },
|
struct cmd_bind_key_data {
|
||||||
.usage = "[-cnr] [-T key-table] key "
|
int key;
|
||||||
"command [arguments]",
|
int can_repeat;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
int command_key;
|
||||||
.exec = cmd_bind_key_exec
|
char *tablename;
|
||||||
|
char *modecmd;
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
const struct cmd_entry cmd_bind_key_entry = {
|
||||||
cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
"bind-key", "bind",
|
||||||
|
"[-cnr] [-t key-table] key command [arguments]",
|
||||||
|
0, 0,
|
||||||
|
NULL,
|
||||||
|
cmd_bind_key_parse,
|
||||||
|
cmd_bind_key_exec,
|
||||||
|
cmd_bind_key_free,
|
||||||
|
cmd_bind_key_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
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;
|
|
||||||
key_code key;
|
|
||||||
const char *tablename;
|
|
||||||
|
|
||||||
key = key_string_lookup_string(args->argv[0]);
|
self->data = data = xmalloc(sizeof *data);
|
||||||
if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
|
data->can_repeat = 0;
|
||||||
cmdq_error(item, "unknown key: %s", args->argv[0]);
|
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':
|
||||||
|
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 {
|
||||||
|
if ((data->cmdlist = cmd_list_parse(argc, argv, cause)) == NULL)
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'T'))
|
return (0);
|
||||||
tablename = args_get(args, 'T');
|
|
||||||
else if (args_has(args, 'n'))
|
|
||||||
tablename = "root";
|
|
||||||
else
|
|
||||||
tablename = "prefix";
|
|
||||||
|
|
||||||
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0,
|
usage:
|
||||||
&cause);
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
if (cmdlist == NULL) {
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
key_bindings_add(tablename, key, args_has(args, 'r'), cmdlist);
|
error:
|
||||||
return (CMD_RETURN_NORMAL);
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_bind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_bind_key_data *data = self->data;
|
||||||
|
|
||||||
|
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 = NULL; /* avoid free */
|
||||||
|
|
||||||
|
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;
|
||||||
|
struct mode_key_binding *mbind, mtmp;
|
||||||
|
enum mode_key_cmd cmd;
|
||||||
|
|
||||||
|
if ((mtab = mode_key_findtable(data->tablename)) == NULL) {
|
||||||
|
ctx->error(ctx, "unknown key table: %s", data->tablename);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = mode_key_fromstring(mtab->cmdstr, data->modecmd);
|
||||||
|
if (cmd == MODEKEY_NONE) {
|
||||||
|
ctx->error(ctx, "unknown command: %s", data->modecmd);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mtmp.key = data->key & ~KEYC_PREFIX;
|
||||||
|
mtmp.mode = data->command_key ? 1 : 0;
|
||||||
|
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||||
|
mbind->cmd = cmd;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
mbind = xmalloc(sizeof *mbind);
|
||||||
|
mbind->key = mtmp.key;
|
||||||
|
mbind->mode = mtmp.mode;
|
||||||
|
mbind->cmd = cmd;
|
||||||
|
SPLAY_INSERT(mode_key_tree, mtab->tree, mbind);
|
||||||
|
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) {
|
||||||
|
skey = key_string_lookup_key(data->key);
|
||||||
|
off += xsnprintf(buf + off, len - off, " %s ", skey);
|
||||||
|
}
|
||||||
|
if (off < len)
|
||||||
|
off += cmd_list_print(data->cmdlist, buf + off, len - off);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
121
cmd-break-pane.c
121
cmd-break-pane.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-break-pane.c,v 1.8 2009-08-16 19:16:27 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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
|
||||||
@@ -26,93 +26,58 @@
|
|||||||
* 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 *);
|
||||||
|
|
||||||
static enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_break_pane_entry = {
|
const struct cmd_entry cmd_break_pane_entry = {
|
||||||
.name = "break-pane",
|
"break-pane", "breakp",
|
||||||
.alias = "breakp",
|
CMD_TARGET_PANE_USAGE " [-d]",
|
||||||
|
0, CMD_CHFLAG('d'),
|
||||||
.args = { "dPF:n:s:t:", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-dP] [-F format] [-n window-name] [-s src-pane] "
|
cmd_target_parse,
|
||||||
"[-t dst-window]",
|
cmd_break_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
.source = { 's', CMD_FIND_PANE, 0 },
|
cmd_target_print
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_break_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct cmd_find_state *current = &item->shared->current;
|
struct winlink *wl;
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
struct session *s;
|
||||||
struct winlink *wl = item->source.wl;
|
struct window_pane *wp;
|
||||||
struct session *src_s = item->source.s;
|
struct window *w;
|
||||||
struct session *dst_s = item->target.s;
|
char *cause;
|
||||||
struct window_pane *wp = item->source.wp;
|
int base_idx;
|
||||||
struct window *w = wl->window;
|
|
||||||
char *name, *cause;
|
|
||||||
int idx = item->target.idx;
|
|
||||||
const char *template;
|
|
||||||
char *cp;
|
|
||||||
|
|
||||||
if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) {
|
if ((wl = cmd_find_pane(ctx, data->target, &s, &wp)) == NULL)
|
||||||
cmdq_error(item, "index %d already in use", idx);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
if (window_count_panes(wl->window) == 1) {
|
||||||
|
ctx->error(ctx, "can't break with only one pane");
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window_count_panes(w) == 1) {
|
TAILQ_REMOVE(&wl->window->panes, wp, entry);
|
||||||
cmdq_error(item, "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);
|
layout_close_pane(wp);
|
||||||
|
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
w = wp->window = window_create1(s->sx, s->sy);
|
||||||
window_lost_pane(w, wp);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
layout_close_pane(wp);
|
w->active = wp;
|
||||||
|
w->name = default_window_name(w);
|
||||||
|
layout_init(w);
|
||||||
|
|
||||||
w = wp->window = window_create(dst_s->sx, dst_s->sy);
|
base_idx = options_get_number(&s->options, "base-index");
|
||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
|
||||||
w->active = wp;
|
if (!(data->chflags & CMD_CHFLAG('d')))
|
||||||
|
session_select(s, wl->idx);
|
||||||
|
|
||||||
if (!args_has(args, 'n')) {
|
server_redraw_session(s);
|
||||||
name = default_window_name(w);
|
|
||||||
window_set_name(w, name);
|
|
||||||
free(name);
|
|
||||||
} else {
|
|
||||||
window_set_name(w, args_get(args, 'n'));
|
|
||||||
options_set_number(w->options, "automatic-rename", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
layout_init(w, wp);
|
return (0);
|
||||||
wp->flags |= PANE_CHANGED;
|
|
||||||
|
|
||||||
if (idx == -1)
|
|
||||||
idx = -1 - options_get_number(dst_s->options, "base-index");
|
|
||||||
wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
|
|
||||||
if (!args_has(self->args, 'd')) {
|
|
||||||
session_select(dst_s, wl->idx);
|
|
||||||
cmd_find_from_session(current, dst_s);
|
|
||||||
}
|
|
||||||
|
|
||||||
server_redraw_session(src_s);
|
|
||||||
if (src_s != dst_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')) {
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = BREAK_PANE_TEMPLATE;
|
|
||||||
cp = format_single(item, template, c, dst_s, wl, wp);
|
|
||||||
cmdq_print(item, "%s", cp);
|
|
||||||
free(cp);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,243 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2009 Jonathan Alvarado <radobobo@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"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the entire contents of a pane to a buffer or stdout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
static char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
|
|
||||||
static char *cmd_capture_pane_pending(struct args *, struct window_pane *,
|
|
||||||
size_t *);
|
|
||||||
static char *cmd_capture_pane_history(struct args *, struct cmdq_item *,
|
|
||||||
struct window_pane *, size_t *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_capture_pane_entry = {
|
|
||||||
.name = "capture-pane",
|
|
||||||
.alias = "capturep",
|
|
||||||
|
|
||||||
.args = { "ab:CeE:JpPqS:t:", 0, 0 },
|
|
||||||
.usage = "[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] "
|
|
||||||
"[-S start-line]" CMD_TARGET_PANE_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_capture_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_clear_history_entry = {
|
|
||||||
.name = "clear-history",
|
|
||||||
.alias = "clearhist",
|
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
|
||||||
.usage = CMD_TARGET_PANE_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_capture_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static char *
|
|
||||||
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
|
|
||||||
{
|
|
||||||
buf = xrealloc(buf, *len + linelen + 1);
|
|
||||||
memcpy(buf + *len, line, linelen);
|
|
||||||
*len += linelen;
|
|
||||||
return (buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
|
|
||||||
size_t *len)
|
|
||||||
{
|
|
||||||
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] >= ' ' && 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
|
||||||
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(item, "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;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
char *buf, *cause;
|
|
||||||
const char *bufname;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_clear_history_entry) {
|
|
||||||
if (wp->mode == &window_copy_mode)
|
|
||||||
window_pane_reset_mode(wp);
|
|
||||||
grid_clear_history(wp->base.grid);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
len = 0;
|
|
||||||
if (args_has(args, 'P'))
|
|
||||||
buf = cmd_capture_pane_pending(args, wp, &len);
|
|
||||||
else
|
|
||||||
buf = cmd_capture_pane_history(args, item, wp, &len);
|
|
||||||
if (buf == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
if (args_has(args, 'p')) {
|
|
||||||
c = item->client;
|
|
||||||
if (c == NULL ||
|
|
||||||
(c->session != NULL && !(c->flags & CLIENT_CONTROL))) {
|
|
||||||
cmdq_error(item, "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_client_push_stdout(c);
|
|
||||||
} else {
|
|
||||||
bufname = NULL;
|
|
||||||
if (args_has(args, 'b'))
|
|
||||||
bufname = args_get(args, 'b');
|
|
||||||
|
|
||||||
if (paste_set(buf, len, bufname, &cause) != 0) {
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
free(buf);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
*
|
|
||||||
* 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 "tmux.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Enter choice mode to choose a buffer.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define CHOOSE_BUFFER_TEMPLATE \
|
|
||||||
"#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}"
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_choose_buffer_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_buffer_entry = {
|
|
||||||
.name = "choose-buffer",
|
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "F:t:", 0, 1 },
|
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_choose_buffer_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_choose_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window_choose_data *cdata;
|
|
||||||
struct paste_buffer *pb;
|
|
||||||
char *action, *action_data;
|
|
||||||
const char *template;
|
|
||||||
u_int idx;
|
|
||||||
|
|
||||||
if (c == NULL) {
|
|
||||||
cmdq_error(item, "no client available");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = CHOOSE_BUFFER_TEMPLATE;
|
|
||||||
|
|
||||||
if (paste_get_top(NULL) == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
if (args->argc != 0)
|
|
||||||
action = xstrdup(args->argv[0]);
|
|
||||||
else
|
|
||||||
action = xstrdup("paste-buffer -b '%%'");
|
|
||||||
|
|
||||||
idx = 0;
|
|
||||||
pb = NULL;
|
|
||||||
while ((pb = paste_walk(pb)) != NULL) {
|
|
||||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
|
||||||
cdata->idx = idx;
|
|
||||||
|
|
||||||
cdata->ft_template = xstrdup(template);
|
|
||||||
format_defaults_paste_buffer(cdata->ft, pb);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-choose-client.c,v 1.3 2009-09-07 23:59:19 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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
|
||||||
@@ -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,109 +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_name}: #{session_name} " \
|
|
||||||
"[#{client_width}x#{client_height} #{client_termname}]" \
|
|
||||||
"#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \
|
|
||||||
"(last used #{t:client_activity})"
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_choose_client_exec(struct cmd *,
|
void cmd_choose_client_callback(void *, int);
|
||||||
struct cmdq_item *);
|
void cmd_choose_client_free(void *);
|
||||||
|
|
||||||
static 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 = {
|
||||||
.name = "choose-client",
|
"choose-client", NULL,
|
||||||
.alias = NULL,
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
CMD_ARG01, 0,
|
||||||
.args = { "F:t:", 0, 1 },
|
cmd_target_init,
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
cmd_target_parse,
|
||||||
|
cmd_choose_client_exec,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_choose_client_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_choose_client_data {
|
struct cmd_choose_client_data {
|
||||||
struct client *client;
|
struct client *client;
|
||||||
|
char *template;
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_choose_client_exec(struct cmd *self, struct cmdq_item *item)
|
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 = cmd_find_client(item, NULL, 1);
|
struct cmd_choose_client_data *cdata;
|
||||||
struct client *c1;
|
struct winlink *wl;
|
||||||
struct window_choose_data *cdata;
|
struct client *c;
|
||||||
struct winlink *wl = item->target.wl;
|
u_int i, idx, cur;
|
||||||
const char *template;
|
|
||||||
char *action;
|
|
||||||
u_int idx, cur;
|
|
||||||
|
|
||||||
if (c == NULL) {
|
if (ctx->curclient == NULL) {
|
||||||
cmdq_error(item, "no client available");
|
ctx->error(ctx, "must be run interactively");
|
||||||
return (CMD_RETURN_ERROR);
|
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)
|
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)
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
continue;
|
continue;
|
||||||
if (c1 == item->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->name, 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
static 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);
|
||||||
}
|
}
|
||||||
|
|||||||
152
cmd-choose-session.c
Normal file
152
cmd-choose-session.c
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
/* $Id: cmd-choose-session.c,v 1.13 2009-09-07 23:59:19 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, 0,
|
||||||
|
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;
|
||||||
|
u_int i, idx, cur;
|
||||||
|
|
||||||
|
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;
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||||
|
s = ARRAY_ITEM(&sessions, i);
|
||||||
|
if (s == NULL)
|
||||||
|
continue;
|
||||||
|
if (s == ctx->curclient->session)
|
||||||
|
cur = idx;
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active, i,
|
||||||
|
"%s: %u windows [%ux%u]%s", s->name,
|
||||||
|
winlink_count(&s->windows), s->sx, s->sy,
|
||||||
|
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;
|
||||||
|
|
||||||
|
if ((u_int) idx > ARRAY_LENGTH(&sessions) - 1)
|
||||||
|
return;
|
||||||
|
s = ARRAY_ITEM(&sessions, 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,253 +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}\""
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_tree_entry = {
|
|
||||||
.name = "choose-tree",
|
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "S:W:swub:c:t:", 0, 1 },
|
|
||||||
.usage = "[-suw] [-b session-template] [-c window template] "
|
|
||||||
"[-S format] [-W format] " CMD_TARGET_WINDOW_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_choose_tree_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_session_entry = {
|
|
||||||
.name = "choose-session",
|
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "F:t:", 0, 1 },
|
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_choose_tree_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_window_entry = {
|
|
||||||
.name = "choose-window",
|
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "F:t:", 0, 1 },
|
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE "[-F format] [template]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_choose_tree_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
struct winlink *wl = item->target.wl, *wm;
|
|
||||||
struct session *s = item->target.s, *s2;
|
|
||||||
struct window_choose_data *wcd = NULL;
|
|
||||||
const char *ses_template, *win_template;
|
|
||||||
char *final_win_action, *cur_win_template;
|
|
||||||
char *final_win_template_middle;
|
|
||||||
char *final_win_template_last;
|
|
||||||
const char *ses_action, *win_action;
|
|
||||||
u_int cur_win, idx_ses, win_ses, win_max;
|
|
||||||
u_int wflag, sflag;
|
|
||||||
|
|
||||||
ses_template = win_template = NULL;
|
|
||||||
ses_action = win_action = NULL;
|
|
||||||
|
|
||||||
if (c == NULL) {
|
|
||||||
cmdq_error(item, "no client available");
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
179
cmd-choose-window.c
Normal file
179
cmd-choose-window.c
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
/* $Id: cmd-choose-window.c,v 1.17 2009-09-07 23:59:19 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, 0,
|
||||||
|
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 (session_alert_has(s, wm, WINDOW_ACTIVITY))
|
||||||
|
flag = '#';
|
||||||
|
else if (session_alert_has(s, wm, WINDOW_BELL))
|
||||||
|
flag = '!';
|
||||||
|
else if (session_alert_has(s, wm, WINDOW_CONTENT))
|
||||||
|
flag = '+';
|
||||||
|
else if (wm == s->curw)
|
||||||
|
flag = '*';
|
||||||
|
else if (wm == SLIST_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",
|
||||||
|
wm->idx, w->name, flag, w->sx, w->sy, window_count_panes(w),
|
||||||
|
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 cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *target, *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
if (cdata->session->flags & SESSION_DEAD)
|
||||||
|
return;
|
||||||
|
if (cdata->client->session != cdata->session)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xasprintf(&target, "%s:%d", cdata->session->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);
|
||||||
|
}
|
||||||
55
cmd-clear-history.c
Normal file
55
cmd-clear-history.c
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/* $Id: cmd-clear-history.c,v 1.7 2009-07-30 21:04:40 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Clear pane history.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_clear_history_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_clear_history_entry = {
|
||||||
|
"clear-history", "clearhist",
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0, 0,
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_clear_history_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct grid *gd;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
gd = wp->base.grid;
|
||||||
|
|
||||||
|
grid_move_lines(gd, 0, gd->hsize, gd->sy);
|
||||||
|
gd->hsize = 0;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
/* $Id: cmd-clock-mode.c,v 1.6 2009-08-20 11:37:46 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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
|
||||||
@@ -16,19 +18,35 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <limits.h>
|
#include "tmux.h"
|
||||||
|
|
||||||
#include "compat.h"
|
/*
|
||||||
|
* Enter clock mode.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_clock_mode_entry = {
|
||||||
|
"clock-mode", NULL,
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0, 0,
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_clock_mode_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
getptmfd(void)
|
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
return (INT_MAX);
|
struct cmd_target_data *data = self->data;
|
||||||
}
|
struct window_pane *wp;
|
||||||
|
|
||||||
pid_t
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
fdforkpty(__unused int ptmfd, int *master, char *name, struct termios *tio,
|
return (-1);
|
||||||
struct winsize *ws)
|
|
||||||
{
|
window_pane_set_mode(wp, &window_clock_mode);
|
||||||
return (forkpty(master, name, tio, ws));
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-command-prompt.c,v 1.25 2009-08-25 13:53:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 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
|
||||||
@@ -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,182 +27,240 @@
|
|||||||
* Prompt for command in client.
|
* Prompt for command in client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_command_prompt_exec(struct cmd *,
|
void cmd_command_prompt_init(struct cmd *, int);
|
||||||
struct cmdq_item *);
|
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);
|
||||||
|
|
||||||
static int cmd_command_prompt_callback(void *, const char *, int);
|
int cmd_command_prompt_callback(void *, const char *);
|
||||||
static 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 = {
|
||||||
.name = "command-prompt",
|
"command-prompt", NULL,
|
||||||
.alias = NULL,
|
CMD_TARGET_CLIENT_USAGE " [-p prompts] [template]",
|
||||||
|
0, 0,
|
||||||
|
cmd_command_prompt_init,
|
||||||
|
cmd_command_prompt_parse,
|
||||||
|
cmd_command_prompt_exec,
|
||||||
|
cmd_command_prompt_free,
|
||||||
|
cmd_command_prompt_print
|
||||||
|
};
|
||||||
|
|
||||||
.args = { "1iI:Np:t:", 0, 1 },
|
struct cmd_command_prompt_data {
|
||||||
.usage = "[-1Ni] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
|
char *prompts;
|
||||||
"[template]",
|
char *target;
|
||||||
|
char *template;
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_command_prompt_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_command_prompt_cdata {
|
struct cmd_command_prompt_cdata {
|
||||||
struct client *c;
|
struct client *c;
|
||||||
int flags;
|
|
||||||
|
|
||||||
char *inputs;
|
|
||||||
char *next_input;
|
|
||||||
|
|
||||||
char *prompts;
|
|
||||||
char *next_prompt;
|
char *next_prompt;
|
||||||
|
char *prompts;
|
||||||
char *template;
|
char *template;
|
||||||
int idx;
|
int idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
void
|
||||||
cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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, 0);
|
||||||
|
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(item, 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 = xcalloc(1, sizeof *cdata);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
cdata->c = c;
|
cdata->c = c;
|
||||||
|
|
||||||
cdata->inputs = NULL;
|
|
||||||
cdata->next_input = NULL;
|
|
||||||
|
|
||||||
cdata->prompts = NULL;
|
|
||||||
cdata->next_prompt = NULL;
|
|
||||||
|
|
||||||
cdata->template = NULL;
|
|
||||||
cdata->idx = 1;
|
cdata->idx = 1;
|
||||||
|
cdata->next_prompt = NULL;
|
||||||
|
cdata->prompts = 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, ",");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, '1'))
|
|
||||||
cdata->flags |= PROMPT_SINGLE;
|
|
||||||
else if (args_has(args, 'N'))
|
|
||||||
cdata->flags |= PROMPT_NUMERIC;
|
|
||||||
else if (args_has(args, 'i'))
|
|
||||||
cdata->flags |= PROMPT_INCREMENTAL;
|
|
||||||
status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
|
|
||||||
cmd_command_prompt_free, cdata, cdata->flags);
|
|
||||||
free(prompt);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
void
|
||||||
cmd_command_prompt_error(struct cmdq_item *item, void *data)
|
cmd_command_prompt_free(struct cmd *self)
|
||||||
{
|
{
|
||||||
char *error = data;
|
struct cmd_command_prompt_data *data = self->data;
|
||||||
|
|
||||||
cmdq_error(item, "%s", error);
|
if (data->prompts != NULL)
|
||||||
free(error);
|
xfree(data->prompts);
|
||||||
|
if (data->target != NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
xfree(data->target);
|
||||||
|
if (data->template != NULL)
|
||||||
|
xfree(data->template);
|
||||||
|
xfree(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
size_t
|
||||||
cmd_command_prompt_callback(void *data, const char *s, int done)
|
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
|
||||||
|
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;
|
||||||
struct cmdq_item *new_item;
|
struct cmd_ctx ctx;
|
||||||
char *cause, *new_template, *prompt, *ptr;
|
char *cause, *newtempl, *prompt, *ptr;
|
||||||
char *input = NULL;
|
|
||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
if (done && (cdata->flags & PROMPT_INCREMENTAL))
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
new_template = cmd_template_replace(cdata->template, s, cdata->idx);
|
newtempl = cmd_template_replace(cdata->template, s, cdata->idx);
|
||||||
if (done) {
|
xfree(cdata->template);
|
||||||
free(cdata->template);
|
cdata->template = newtempl;
|
||||||
cdata->template = new_template;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
|
||||||
* Check if there are more prompts; if so, get its respective input
|
|
||||||
* and update the prompt data.
|
|
||||||
*/
|
|
||||||
if (done && (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);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdlist = cmd_string_parse(new_template, NULL, 0, &cause);
|
if (cmd_string_parse(newtempl, &cmdlist, &cause) != 0) {
|
||||||
if (cmdlist == NULL) {
|
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
new_item = cmdq_get_callback(cmd_command_prompt_error,
|
*cause = toupper((u_char) *cause);
|
||||||
cause);
|
status_message_set(c, "%s", cause);
|
||||||
} else
|
xfree(cause);
|
||||||
new_item = NULL;
|
}
|
||||||
} else {
|
return (0);
|
||||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_item != NULL)
|
ctx.msgdata = NULL;
|
||||||
cmdq_append(c, new_item);
|
ctx.curclient = c;
|
||||||
|
|
||||||
if (!done)
|
ctx.error = key_bindings_error;
|
||||||
free(new_template);
|
ctx.print = key_bindings_print;
|
||||||
if (c->prompt_callbackfn != cmd_command_prompt_callback)
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
|
||||||
|
if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static 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.11 2009-08-24 16:24:18 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,117 +25,123 @@
|
|||||||
* Asks for confirmation before executing a command.
|
* Asks for confirmation before executing a command.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_confirm_before_exec(struct cmd *,
|
int cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
void cmd_confirm_before_init(struct cmd *, int);
|
||||||
|
|
||||||
static int cmd_confirm_before_callback(void *, const char *, int);
|
int cmd_confirm_before_callback(void *, const char *);
|
||||||
static 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 = {
|
||||||
.name = "confirm-before",
|
"confirm-before", "confirm",
|
||||||
.alias = "confirm",
|
CMD_TARGET_CLIENT_USAGE " command",
|
||||||
|
CMD_ARG1, 0,
|
||||||
.args = { "p:t:", 1, 1 },
|
cmd_confirm_before_init,
|
||||||
.usage = "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
|
cmd_target_parse,
|
||||||
|
cmd_confirm_before_exec,
|
||||||
.flags = 0,
|
cmd_target_free,
|
||||||
.exec = cmd_confirm_before_exec
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_confirm_before_data {
|
struct cmd_confirm_before_data {
|
||||||
|
struct client *c;
|
||||||
char *cmd;
|
char *cmd;
|
||||||
struct client *client;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
void
|
||||||
cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
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(item, 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_confirm_before_error(struct cmdq_item *item, void *data)
|
cmd_confirm_before_callback(void *data, const char *s)
|
||||||
{
|
|
||||||
char *error = data;
|
|
||||||
|
|
||||||
cmdq_error(item, "%s", error);
|
|
||||||
free(error);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
cmd_confirm_before_callback(void *data, const char *s, __unused int done)
|
|
||||||
{
|
{
|
||||||
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 cmdq_item *new_item;
|
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);
|
||||||
|
|
||||||
cmdlist = cmd_string_parse(cdata->cmd, NULL, 0, &cause);
|
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||||
if (cmdlist == NULL) {
|
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
new_item = cmdq_get_callback(cmd_confirm_before_error,
|
*cause = toupper((u_char) *cause);
|
||||||
cause);
|
status_message_set(c, "%s", cause);
|
||||||
} else
|
xfree(cause);
|
||||||
new_item = NULL;
|
}
|
||||||
} else {
|
return (0);
|
||||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_item != NULL)
|
ctx.msgdata = NULL;
|
||||||
cmdq_append(c, new_item);
|
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);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
204
cmd-copy-buffer.c
Normal file
204
cmd-copy-buffer.c
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
/* $Id: cmd-copy-buffer.c,v 1.4 2009-09-07 23:48:54 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, 0,
|
||||||
|
cmd_copy_buffer_init,
|
||||||
|
cmd_copy_buffer_parse,
|
||||||
|
cmd_copy_buffer_exec,
|
||||||
|
cmd_copy_buffer_free,
|
||||||
|
cmd_copy_buffer_print
|
||||||
|
};
|
||||||
|
|
||||||
|
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, 0);
|
||||||
|
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,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-copy-mode.c,v 1.23 2009-08-20 11:37:46 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -21,70 +21,34 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enter copy or clock mode.
|
* Enter copy mode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmdq_item *);
|
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 = {
|
||||||
.name = "copy-mode",
|
"copy-mode", NULL,
|
||||||
.alias = NULL,
|
"[-u] " CMD_TARGET_PANE_USAGE,
|
||||||
|
0, CMD_CHFLAG('u'),
|
||||||
.args = { "Met:u", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-Mu] " CMD_TARGET_PANE_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_copy_mode_exec,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_target_free,
|
||||||
|
NULL
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_copy_mode_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_clock_mode_entry = {
|
int
|
||||||
.name = "clock-mode",
|
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
|
||||||
.usage = CMD_TARGET_PANE_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_copy_mode_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct cmdq_shared *shared = item->shared;
|
struct window_pane *wp;
|
||||||
struct client *c = item->client;
|
|
||||||
struct session *s;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
|
|
||||||
if (args_has(args, 'M')) {
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
if ((wp = cmd_mouse_pane(&shared->mouse, &s, NULL)) == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
if (c == NULL || c->session != s)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self->entry == &cmd_clock_mode_entry) {
|
window_pane_set_mode(wp, &window_copy_mode);
|
||||||
window_pane_set_mode(wp, &window_clock_mode);
|
if (wp->mode == &window_copy_mode && data->chflags & CMD_CHFLAG('u'))
|
||||||
return (CMD_RETURN_NORMAL);
|
window_copy_pageup(wp);
|
||||||
}
|
|
||||||
|
|
||||||
if (wp->mode != &window_copy_mode) {
|
return (0);
|
||||||
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, &shared->mouse);
|
|
||||||
}
|
|
||||||
if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
|
|
||||||
window_copy_pageup(wp, 0);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
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.7 2009-07-28 22:12:16 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, 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,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-detach-client.c,v 1.9 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,94 +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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_detach_client_exec(struct cmd *,
|
int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_detach_client_entry = {
|
const struct cmd_entry cmd_detach_client_entry = {
|
||||||
.name = "detach-client",
|
"detach-client", "detach",
|
||||||
.alias = "detach",
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0, 0,
|
||||||
.args = { "aE:s:t:P", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-aP] [-E shell-command] "
|
cmd_target_parse,
|
||||||
"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
cmd_detach_client_exec,
|
||||||
|
cmd_target_free,
|
||||||
.source = { 's', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
cmd_target_print
|
||||||
|
|
||||||
.flags = CMD_READONLY,
|
|
||||||
.exec = cmd_detach_client_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_suspend_client_entry = {
|
int
|
||||||
.name = "suspend-client",
|
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "suspendc",
|
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
|
||||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_detach_client_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
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;
|
|
||||||
const char *cmd = args_get(args, 'E');
|
|
||||||
|
|
||||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (self->entry == &cmd_suspend_client_entry) {
|
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||||
server_client_suspend(c);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'P'))
|
return (0);
|
||||||
msgtype = MSG_DETACHKILL;
|
|
||||||
else
|
|
||||||
msgtype = MSG_DETACH;
|
|
||||||
|
|
||||||
if (args_has(args, 's')) {
|
|
||||||
s = item->source.s;
|
|
||||||
if (s == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
TAILQ_FOREACH(cloop, &clients, entry) {
|
|
||||||
if (cloop->session == s) {
|
|
||||||
if (cmd != NULL)
|
|
||||||
server_client_exec(cloop, cmd);
|
|
||||||
else
|
|
||||||
server_client_detach(cloop, msgtype);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_STOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
|
||||||
TAILQ_FOREACH(cloop, &clients, entry) {
|
|
||||||
if (cloop->session != NULL && cloop != c) {
|
|
||||||
if (cmd != NULL)
|
|
||||||
server_client_exec(cloop, cmd);
|
|
||||||
else
|
|
||||||
server_client_detach(cloop, msgtype);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd != NULL)
|
|
||||||
server_client_exec(c, cmd);
|
|
||||||
else
|
|
||||||
server_client_detach(c, msgtype);
|
|
||||||
return (CMD_RETURN_STOP);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-display-message.c,v 1.2 2009-07-28 22:12:16 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,63 +26,38 @@
|
|||||||
* 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)"
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_display_message_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_display_message_entry = {
|
const struct cmd_entry cmd_display_message_entry = {
|
||||||
.name = "display-message",
|
"display-message", "display",
|
||||||
.alias = "display",
|
CMD_TARGET_CLIENT_USAGE " [message]",
|
||||||
|
CMD_ARG01, 0,
|
||||||
.args = { "c:pt:F:", 0, 1 },
|
cmd_target_init,
|
||||||
.usage = "[-p] [-c target-client] [-F format] "
|
cmd_target_parse,
|
||||||
CMD_TARGET_PANE_USAGE " [message]",
|
cmd_display_message_exec,
|
||||||
|
cmd_target_free,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_target_print
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_display_message_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
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 = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
const char *template;
|
const char *template;
|
||||||
char *msg;
|
char *msg;
|
||||||
struct format_tree *ft;
|
|
||||||
|
|
||||||
if (args_has(args, 'F') && args->argc != 0) {
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
cmdq_error(item, "only one of -F or argument must be given");
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
c = cmd_find_client(item, args_get(args, 'c'), 1);
|
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
if (data->arg == NULL)
|
||||||
if (args->argc != 0)
|
template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)";
|
||||||
template = args->argv[0];
|
else
|
||||||
if (template == NULL)
|
template = data->arg;
|
||||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
|
||||||
|
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
msg = status_replace(c->session, template, time(NULL));
|
||||||
format_defaults(ft, c, s, wl, wp);
|
status_message_set(c, "%s", msg);
|
||||||
|
xfree(msg);
|
||||||
|
|
||||||
msg = format_expand_time(ft, template, time(NULL));
|
return (0);
|
||||||
if (args_has(self->args, 'p'))
|
|
||||||
cmdq_print(item, "%s", msg);
|
|
||||||
else if (c != NULL)
|
|
||||||
status_message_set(c, "%s", msg);
|
|
||||||
free(msg);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-display-panes.c,v 1.1 2009-08-31 22:30:15 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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,99 +18,35 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display panes on a client.
|
* Display panes on a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_display_panes_exec(struct cmd *,
|
int cmd_display_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
static void cmd_display_panes_callback(struct client *,
|
|
||||||
struct window_pane *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_display_panes_entry = {
|
const struct cmd_entry cmd_display_panes_entry = {
|
||||||
.name = "display-panes",
|
"display-panes", "displayp",
|
||||||
.alias = "displayp",
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0, 0,
|
||||||
.args = { "t:", 0, 1 },
|
cmd_target_init,
|
||||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_display_panes_exec,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_target_free,
|
||||||
.exec = cmd_display_panes_exec
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
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(item, args_get(args, 't'), 0)) == NULL)
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
if (c->identify_callback != NULL)
|
server_set_identify(c);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
c->identify_callback = cmd_display_panes_callback;
|
return (0);
|
||||||
if (args->argc != 0)
|
|
||||||
c->identify_callback_data = xstrdup(args->argv[0]);
|
|
||||||
else
|
|
||||||
c->identify_callback_data = xstrdup("select-pane -t '%%'");
|
|
||||||
|
|
||||||
server_client_set_identify(c);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_display_panes_error(struct cmdq_item *item, void *data)
|
|
||||||
{
|
|
||||||
char *error = data;
|
|
||||||
|
|
||||||
cmdq_error(item, "%s", error);
|
|
||||||
free(error);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_display_panes_callback(struct client *c, struct window_pane *wp)
|
|
||||||
{
|
|
||||||
struct cmd_list *cmdlist;
|
|
||||||
struct cmdq_item *new_item;
|
|
||||||
char *template, *cmd, *expanded, *cause;
|
|
||||||
|
|
||||||
template = c->identify_callback_data;
|
|
||||||
if (wp == NULL)
|
|
||||||
goto out;
|
|
||||||
xasprintf(&expanded, "%%%u", wp->id);
|
|
||||||
cmd = cmd_template_replace(template, expanded, 1);
|
|
||||||
|
|
||||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
|
||||||
if (cmdlist == NULL) {
|
|
||||||
if (cause != NULL) {
|
|
||||||
new_item = cmdq_get_callback(cmd_display_panes_error,
|
|
||||||
cause);
|
|
||||||
} else
|
|
||||||
new_item = NULL;
|
|
||||||
} else {
|
|
||||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_item != NULL)
|
|
||||||
cmdq_append(c, new_item);
|
|
||||||
|
|
||||||
free(cmd);
|
|
||||||
free(expanded);
|
|
||||||
|
|
||||||
out:
|
|
||||||
free(c->identify_callback_data);
|
|
||||||
c->identify_callback_data = NULL;
|
|
||||||
c->identify_callback = NULL;
|
|
||||||
}
|
}
|
||||||
|
|||||||
59
cmd-down-pane.c
Normal file
59
cmd-down-pane.c
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/* $Id: cmd-down-pane.c,v 1.12 2009-07-28 22:12: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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move down a pane.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_down_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_down_pane_entry = {
|
||||||
|
"down-pane", "downp",
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, 0,
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_down_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_down_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;
|
||||||
|
|
||||||
|
do {
|
||||||
|
w->active = TAILQ_NEXT(w->active, entry);
|
||||||
|
if (w->active == NULL)
|
||||||
|
w->active = TAILQ_FIRST(&w->panes);
|
||||||
|
} while (!window_pane_visible(w->active));
|
||||||
|
server_status_window(wl->window);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-find-window.c,v 1.13 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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
|
||||||
@@ -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,160 +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}"
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmdq_item *);
|
void cmd_find_window_callback(void *, int);
|
||||||
|
|
||||||
static 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 = {
|
||||||
.name = "find-window",
|
"find-window", "findw",
|
||||||
.alias = "findw",
|
CMD_TARGET_WINDOW_USAGE " match-string",
|
||||||
|
CMD_ARG1, 0,
|
||||||
.args = { "F:CNt:T", 1, 4 },
|
cmd_target_init,
|
||||||
.usage = "[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string",
|
cmd_target_parse,
|
||||||
|
cmd_find_window_exec,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_find_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_find_window_data {
|
struct cmd_find_window_data {
|
||||||
struct winlink *wl;
|
u_int 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);
|
|
||||||
|
|
||||||
static u_int cmd_find_window_match_flags(struct args *);
|
int
|
||||||
static 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 *);
|
|
||||||
|
|
||||||
static 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. */
|
struct session *s;
|
||||||
if (args_has(args, 'T'))
|
struct winlink *wl, *wm;
|
||||||
match_flags |= CMD_FIND_WINDOW_BY_TITLE;
|
struct window *w;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static 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;
|
struct window_pane *wp;
|
||||||
|
ARRAY_DECL(, u_int) list_idx;
|
||||||
|
ARRAY_DECL(, char *) list_ctx;
|
||||||
|
char *sres, *sctx, *searchstr;
|
||||||
u_int i, line;
|
u_int i, line;
|
||||||
char *sres;
|
|
||||||
|
|
||||||
find_data = xcalloc(1, sizeof *find_data);
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
i = 0;
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
return (-1);
|
||||||
i++;
|
|
||||||
|
|
||||||
if ((match_flags & CMD_FIND_WINDOW_BY_NAME) &&
|
ARRAY_INIT(&list_idx);
|
||||||
fnmatch(searchstr, wl->window->name, 0) == 0) {
|
ARRAY_INIT(&list_ctx);
|
||||||
find_data->list_ctx = xstrdup("");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((match_flags & CMD_FIND_WINDOW_BY_TITLE) &&
|
xasprintf(&searchstr, "*%s*", data->arg);
|
||||||
fnmatch(searchstr, wp->base.title, 0) == 0) {
|
RB_FOREACH(wm, winlinks, &s->windows) {
|
||||||
xasprintf(&find_data->list_ctx,
|
i = 0;
|
||||||
"pane %u title: \"%s\"", i - 1, wp->base.title);
|
TAILQ_FOREACH(wp, &wm->window->panes, entry) {
|
||||||
break;
|
i++;
|
||||||
}
|
|
||||||
|
|
||||||
if (match_flags & CMD_FIND_WINDOW_BY_CONTENT &&
|
if (fnmatch(searchstr, wm->window->name, 0) == 0)
|
||||||
(sres = window_pane_search(wp, str, &line)) != NULL) {
|
sctx = xstrdup("");
|
||||||
xasprintf(&find_data->list_ctx,
|
else {
|
||||||
"pane %u line %u: \"%s\"", i - 1, line + 1, sres);
|
sres = window_pane_search(wp, data->arg, &line);
|
||||||
free(sres);
|
if (sres == NULL &&
|
||||||
break;
|
fnmatch(searchstr, wp->base.title, 0) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (sres == NULL) {
|
||||||
|
xasprintf(&sctx,
|
||||||
|
"pane %u title: \"%s\"", i - 1,
|
||||||
|
wp->base.title);
|
||||||
|
} else {
|
||||||
|
xasprintf(&sctx,
|
||||||
|
"pane %u line %u: \"%s\"", i - 1,
|
||||||
|
line + 1, sres);
|
||||||
|
xfree(sres);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ARRAY_ADD(&list_idx, wm->idx);
|
||||||
|
ARRAY_ADD(&list_ctx, sctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
xfree(searchstr);
|
||||||
|
|
||||||
if (find_data->list_ctx != NULL) {
|
if (ARRAY_LENGTH(&list_idx) == 0) {
|
||||||
find_data->wl = wl;
|
ctx->error(ctx, "no windows matching: %s", data->arg);
|
||||||
find_data->pane_id = i - 1;
|
ARRAY_FREE(&list_idx);
|
||||||
TAILQ_INSERT_TAIL(find_list, find_data, entry);
|
ARRAY_FREE(&list_ctx);
|
||||||
} else
|
return (-1);
|
||||||
free(find_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct cmd_find_state *current = &item->shared->current;
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
struct window_choose_data *cdata;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl, *wm;
|
|
||||||
struct cmd_find_window_list find_list;
|
|
||||||
struct cmd_find_window_data *find_data;
|
|
||||||
struct cmd_find_window_data *find_data1;
|
|
||||||
char *str, *searchstr;
|
|
||||||
const char *template;
|
|
||||||
u_int i, match_flags;
|
|
||||||
|
|
||||||
if (c == NULL) {
|
|
||||||
cmdq_error(item, "no client available");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
if (ARRAY_LENGTH(&list_idx) == 1) {
|
||||||
template = FIND_WINDOW_TEMPLATE;
|
if (session_select(s, ARRAY_FIRST(&list_idx)) == 0)
|
||||||
|
|
||||||
match_flags = cmd_find_window_match_flags(args);
|
|
||||||
str = args->argv[0];
|
|
||||||
|
|
||||||
TAILQ_INIT(&find_list);
|
|
||||||
|
|
||||||
xasprintf(&searchstr, "*%s*", str);
|
|
||||||
RB_FOREACH(wm, winlinks, &s->windows)
|
|
||||||
cmd_find_window_match(&find_list, match_flags, wm, str, searchstr);
|
|
||||||
free(searchstr);
|
|
||||||
|
|
||||||
if (TAILQ_EMPTY(&find_list)) {
|
|
||||||
cmdq_error(item, "no windows matching: %s", str);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TAILQ_NEXT(TAILQ_FIRST(&find_list), entry) == NULL) {
|
|
||||||
if (session_select(s, TAILQ_FIRST(&find_list)->wl->idx) == 0) {
|
|
||||||
cmd_find_from_session(current, s);
|
|
||||||
server_redraw_session(s);
|
server_redraw_session(s);
|
||||||
}
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -189,55 +121,42 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
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);
|
||||||
|
if (session_index(s, &cdata->session) != 0)
|
||||||
|
fatalx("session not found");
|
||||||
|
|
||||||
|
window_choose_ready(
|
||||||
|
wl->window->active, 0, cmd_find_window_callback, xfree, 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static 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;
|
||||||
|
|
||||||
if (cdata == NULL)
|
if (idx != -1 && cdata->session <= ARRAY_LENGTH(&sessions) - 1) {
|
||||||
return;
|
s = ARRAY_ITEM(&sessions, cdata->session);
|
||||||
|
if (s != NULL && session_select(s, idx) == 0)
|
||||||
s = cdata->start_session;
|
server_redraw_session(s);
|
||||||
if (!session_alive(s))
|
|
||||||
return;
|
|
||||||
|
|
||||||
wp = window_pane_at_index(cdata->wl->window, cdata->pane_id);
|
|
||||||
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);
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1278
cmd-find.c
1278
cmd-find.c
File diff suppressed because it is too large
Load Diff
418
cmd-generic.c
Normal file
418
cmd-generic.c
Normal file
@@ -0,0 +1,418 @@
|
|||||||
|
/* $Id: cmd-generic.c,v 1.34 2009-08-26 22:13:52 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 *, uint64_t);
|
||||||
|
int cmd_flags(int, uint64_t, 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prepend flags from chflags onto flagstr and call getopt. */
|
||||||
|
int
|
||||||
|
cmd_getopt(int argc, char **argv, const char *flagstr, uint64_t chflags)
|
||||||
|
{
|
||||||
|
u_char ch;
|
||||||
|
char buf[128];
|
||||||
|
size_t len, off;
|
||||||
|
|
||||||
|
*buf = '\0';
|
||||||
|
|
||||||
|
len = sizeof buf;
|
||||||
|
off = 0;
|
||||||
|
|
||||||
|
for (ch = 0; ch < 26; ch++) {
|
||||||
|
if (chflags & CMD_CHFLAG('a' + ch))
|
||||||
|
off += xsnprintf(buf + off, len - off, "%c", 'a' + ch);
|
||||||
|
if (chflags & CMD_CHFLAG('A' + ch))
|
||||||
|
off += xsnprintf(buf + off, len - off, "%c", 'A' + ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
strlcat(buf, flagstr, sizeof buf);
|
||||||
|
|
||||||
|
return (getopt(argc, argv, buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If this option is expected (in ichflags), set it in ochflags, otherwise
|
||||||
|
* return -1.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
cmd_flags(int opt, uint64_t ichflags, uint64_t *ochflags)
|
||||||
|
{
|
||||||
|
u_char ch;
|
||||||
|
|
||||||
|
for (ch = 0; ch < 26; ch++) {
|
||||||
|
if (opt == 'a' + ch && ichflags & CMD_CHFLAG(opt)) {
|
||||||
|
(*ochflags) |= CMD_CHFLAG(opt);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (opt == 'A' + ch && ichflags & CMD_CHFLAG(opt)) {
|
||||||
|
(*ochflags) |= CMD_CHFLAG(opt);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the flags supported 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 (chflags & CMD_CHFLAG('a' + ch))
|
||||||
|
off += xsnprintf(buf + off, len - off, "%c", 'a' + ch);
|
||||||
|
if (chflags & CMD_CHFLAG('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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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_flags(opt, entry->chflags, &data->chflags) == 0)
|
||||||
|
continue;
|
||||||
|
switch (opt) {
|
||||||
|
case 'b':
|
||||||
|
if (data->buffer == -1) {
|
||||||
|
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "buffer %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
data->buffer = n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (cmd_fill_argument(
|
||||||
|
self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
|
||||||
|
goto usage;
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_buffer_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
xfree(data->arg);
|
||||||
|
if (data->arg2 != NULL)
|
||||||
|
xfree(data->arg2);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_buffer_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
off += cmd_print_flags(buf, len, off, data->chflags);
|
||||||
|
if (off < len && data->buffer != -1)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -b %d", data->buffer);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->arg != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||||
|
if (off < len && data->arg2 != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
|
/* $Id: cmd-has-session.c,v 1.14 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010 Dagobert Michelsen
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
* Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -17,33 +18,32 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include "tmux.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "compat.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, 0,
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_has_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
setenv(const char *name, const char *value, __unused int overwrite)
|
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
char *newval;
|
struct cmd_target_data *data = self->data;
|
||||||
|
|
||||||
xasprintf(&newval, "%s=%s", name, value);
|
if (cmd_find_session(ctx, data->target) == NULL)
|
||||||
return (putenv(newval));
|
return (-1);
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
unsetenv(const char *name)
|
|
||||||
{
|
|
||||||
char **envptr;
|
|
||||||
int namelen;
|
|
||||||
|
|
||||||
namelen = strlen(name);
|
|
||||||
for (envptr = environ; *envptr != NULL; envptr++) {
|
|
||||||
if (strncmp(name, *envptr, namelen) == 0 &&
|
|
||||||
((*envptr)[namelen] == '=' || (*envptr)[namelen] == '\0'))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (; *envptr != NULL; envptr++)
|
|
||||||
*envptr = *(envptr + 1);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
238
cmd-if-shell.c
238
cmd-if-shell.c
@@ -1,8 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-if-shell.c,v 1.4 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@openbsd.org>
|
|
||||||
*
|
*
|
||||||
* 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,176 +17,135 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdlib.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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmdq_item *);
|
int cmd_if_shell_parse(struct cmd *, int, char **, char **);
|
||||||
|
int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||||
static void cmd_if_shell_callback(struct job *);
|
void cmd_if_shell_free(struct cmd *);
|
||||||
static void cmd_if_shell_free(void *);
|
void cmd_if_shell_init(struct cmd *, int);
|
||||||
|
size_t cmd_if_shell_print(struct cmd *, char *, size_t);
|
||||||
const struct cmd_entry cmd_if_shell_entry = {
|
|
||||||
.name = "if-shell",
|
|
||||||
.alias = "if",
|
|
||||||
|
|
||||||
.args = { "bFt:", 2, 3 },
|
|
||||||
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
|
|
||||||
"[command]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_if_shell_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cmd_if_shell_data {
|
struct cmd_if_shell_data {
|
||||||
char *file;
|
char *cmd;
|
||||||
u_int line;
|
char *sh_cmd;
|
||||||
|
|
||||||
char *cmd_if;
|
|
||||||
char *cmd_else;
|
|
||||||
|
|
||||||
struct client *client;
|
|
||||||
struct cmdq_item *item;
|
|
||||||
struct mouse_event mouse;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
const struct cmd_entry cmd_if_shell_entry = {
|
||||||
cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
"if-shell", "if",
|
||||||
|
"shell-command command",
|
||||||
|
0, 0,
|
||||||
|
cmd_if_shell_init,
|
||||||
|
cmd_if_shell_parse,
|
||||||
|
cmd_if_shell_exec,
|
||||||
|
cmd_if_shell_free,
|
||||||
|
cmd_if_shell_print
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_if_shell_init(struct cmd *self, unused int arg)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_if_shell_data *data;
|
||||||
struct cmdq_shared *shared = item->shared;
|
|
||||||
struct cmd_if_shell_data *cdata;
|
|
||||||
char *shellcmd, *cmd, *cause;
|
|
||||||
struct cmd_list *cmdlist;
|
|
||||||
struct cmdq_item *new_item;
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
const char *cwd;
|
|
||||||
|
|
||||||
if (item->client != NULL && item->client->session == NULL)
|
self->data = data = xmalloc(sizeof *data);
|
||||||
cwd = item->client->cwd;
|
data->cmd = NULL;
|
||||||
else if (s != NULL)
|
data->sh_cmd = NULL;
|
||||||
cwd = s->cwd;
|
}
|
||||||
else
|
|
||||||
cwd = NULL;
|
|
||||||
|
|
||||||
shellcmd = format_single(item, args->argv[0], c, s, wl, wp);
|
int
|
||||||
if (args_has(args, 'F')) {
|
cmd_if_shell_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
cmd = NULL;
|
{
|
||||||
if (*shellcmd != '0' && *shellcmd != '\0')
|
struct cmd_if_shell_data *data;
|
||||||
cmd = args->argv[1];
|
int opt;
|
||||||
else if (args->argc == 3)
|
|
||||||
cmd = args->argv[2];
|
self->entry->init(self, 0);
|
||||||
free(shellcmd);
|
data = self->data;
|
||||||
if (cmd == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
while ((opt = getopt(argc, argv, "")) != -1) {
|
||||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
switch (opt) {
|
||||||
if (cmdlist == NULL) {
|
default:
|
||||||
if (cause != NULL) {
|
goto usage;
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
new_item = cmdq_get_command(cmdlist, NULL, &shared->mouse, 0);
|
|
||||||
cmdq_insert_after(item, new_item);
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 2)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
data->sh_cmd = xstrdup(argv[0]);
|
||||||
if (self->file != NULL) {
|
data->cmd = xstrdup(argv[1]);
|
||||||
cdata->file = xstrdup(self->file);
|
return (0);
|
||||||
cdata->line = self->line;
|
|
||||||
}
|
|
||||||
|
|
||||||
cdata->cmd_if = xstrdup(args->argv[1]);
|
usage:
|
||||||
if (args->argc == 3)
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
cdata->cmd_else = xstrdup(args->argv[2]);
|
|
||||||
else
|
|
||||||
cdata->cmd_else = NULL;
|
|
||||||
|
|
||||||
cdata->client = item->client;
|
self->entry->free(self);
|
||||||
if (cdata->client != NULL)
|
return (-1);
|
||||||
cdata->client->references++;
|
|
||||||
|
|
||||||
if (!args_has(args, 'b'))
|
|
||||||
cdata->item = item;
|
|
||||||
else
|
|
||||||
cdata->item = NULL;
|
|
||||||
memcpy(&cdata->mouse, &shared->mouse, sizeof cdata->mouse);
|
|
||||||
|
|
||||||
job_run(shellcmd, s, cwd, NULL, cmd_if_shell_callback,
|
|
||||||
cmd_if_shell_free, cdata);
|
|
||||||
free(shellcmd);
|
|
||||||
|
|
||||||
if (args_has(args, 'b'))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
int
|
||||||
cmd_if_shell_callback(struct job *job)
|
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct cmd_if_shell_data *cdata = job->data;
|
struct cmd_if_shell_data *data = self->data;
|
||||||
struct client *c = cdata->client;
|
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
struct cmdq_item *new_item;
|
char *cause;
|
||||||
char *cause, *cmd, *file = cdata->file;
|
int ret;
|
||||||
u_int line = cdata->line;
|
|
||||||
|
|
||||||
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
if ((ret = system(data->sh_cmd)) < 0) {
|
||||||
cmd = cdata->cmd_else;
|
ctx->error(ctx, "system error: %s", strerror(errno));
|
||||||
else
|
return (-1);
|
||||||
cmd = cdata->cmd_if;
|
} else if (ret != 0)
|
||||||
if (cmd == NULL)
|
return (0);
|
||||||
goto out;
|
|
||||||
|
|
||||||
cmdlist = cmd_string_parse(cmd, file, line, &cause);
|
if (cmd_string_parse(data->cmd, &cmdlist, &cause) != 0) {
|
||||||
if (cmdlist == NULL) {
|
if (cause != NULL) {
|
||||||
if (cause != NULL && cdata->item != NULL)
|
ctx->error(ctx, "%s", cause);
|
||||||
cmdq_error(cdata->item, "%s", cause);
|
xfree(cause);
|
||||||
free(cause);
|
}
|
||||||
new_item = NULL;
|
return (-1);
|
||||||
} else {
|
}
|
||||||
new_item = cmdq_get_command(cmdlist, NULL, &cdata->mouse, 0);
|
|
||||||
|
if (cmd_list_exec(cmdlist, ctx) < 0) {
|
||||||
cmd_list_free(cmdlist);
|
cmd_list_free(cmdlist);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_item != NULL) {
|
cmd_list_free(cmdlist);
|
||||||
if (cdata->item == NULL)
|
return (0);
|
||||||
cmdq_append(c, new_item);
|
|
||||||
else
|
|
||||||
cmdq_insert_after(cdata->item, new_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
if (cdata->item != NULL)
|
|
||||||
cdata->item->flags &= ~CMDQ_WAITING;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_if_shell_free(void *data)
|
cmd_if_shell_free(struct cmd *self)
|
||||||
{
|
{
|
||||||
struct cmd_if_shell_data *cdata = data;
|
struct cmd_if_shell_data *data = self->data;
|
||||||
|
|
||||||
if (cdata->client != NULL)
|
if (data->cmd != NULL)
|
||||||
server_client_unref(cdata->client);
|
xfree(data->cmd);
|
||||||
|
if (data->sh_cmd != NULL)
|
||||||
free(cdata->cmd_else);
|
xfree(data->sh_cmd);
|
||||||
free(cdata->cmd_if);
|
xfree(data);
|
||||||
|
}
|
||||||
free(cdata->file);
|
|
||||||
free(cdata);
|
size_t
|
||||||
|
cmd_if_shell_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_if_shell_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->sh_cmd != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->sh_cmd);
|
||||||
|
if (off < len && data->cmd != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
161
cmd-join-pane.c
161
cmd-join-pane.c
@@ -1,161 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
|
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
*
|
|
||||||
* 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"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Join or move a pane into another (like split/swap/kill).
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_join_pane_entry = {
|
|
||||||
.name = "join-pane",
|
|
||||||
.alias = "joinp",
|
|
||||||
|
|
||||||
.args = { "bdhvp:l:s:t:", 0, 0 },
|
|
||||||
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
|
|
||||||
|
|
||||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_join_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_move_pane_entry = {
|
|
||||||
.name = "move-pane",
|
|
||||||
.alias = "movep",
|
|
||||||
|
|
||||||
.args = { "bdhvp:l:s:t:", 0, 0 },
|
|
||||||
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
|
|
||||||
|
|
||||||
.source = { 's', CMD_FIND_PANE, 0 },
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_join_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct cmd_find_state *current = &item->shared->current;
|
|
||||||
struct session *dst_s;
|
|
||||||
struct winlink *src_wl, *dst_wl;
|
|
||||||
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;
|
|
||||||
int not_same_window;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_join_pane_entry)
|
|
||||||
not_same_window = 1;
|
|
||||||
else
|
|
||||||
not_same_window = 0;
|
|
||||||
|
|
||||||
dst_s = item->target.s;
|
|
||||||
dst_wl = item->target.wl;
|
|
||||||
dst_wp = item->target.wp;
|
|
||||||
dst_w = dst_wl->window;
|
|
||||||
dst_idx = dst_wl->idx;
|
|
||||||
server_unzoom_window(dst_w);
|
|
||||||
|
|
||||||
src_wl = item->source.wl;
|
|
||||||
src_wp = item->source.wp;
|
|
||||||
src_w = src_wl->window;
|
|
||||||
server_unzoom_window(src_w);
|
|
||||||
|
|
||||||
if (not_same_window && src_w == dst_w) {
|
|
||||||
cmdq_error(item, "can't join a pane to its own window");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (!not_same_window && src_wp == dst_wp) {
|
|
||||||
cmdq_error(item, "source and target panes must be different");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
type = LAYOUT_TOPBOTTOM;
|
|
||||||
if (args_has(args, 'h'))
|
|
||||||
type = LAYOUT_LEFTRIGHT;
|
|
||||||
|
|
||||||
size = -1;
|
|
||||||
if (args_has(args, 'l')) {
|
|
||||||
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(item, "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(item, "percentage %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (type == LAYOUT_TOPBOTTOM)
|
|
||||||
size = (dst_wp->sy * percentage) / 100;
|
|
||||||
else
|
|
||||||
size = (dst_wp->sx * percentage) / 100;
|
|
||||||
}
|
|
||||||
lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'), 0);
|
|
||||||
if (lc == NULL) {
|
|
||||||
cmdq_error(item, "create pane failed: pane too small");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
layout_close_pane(src_wp);
|
|
||||||
|
|
||||||
window_lost_pane(src_w, src_wp);
|
|
||||||
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
|
||||||
|
|
||||||
src_wp->window = dst_w;
|
|
||||||
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
|
||||||
layout_assign_pane(lc, src_wp);
|
|
||||||
|
|
||||||
recalculate_sizes();
|
|
||||||
|
|
||||||
server_redraw_window(src_w);
|
|
||||||
server_redraw_window(dst_w);
|
|
||||||
|
|
||||||
if (!args_has(args, 'd')) {
|
|
||||||
window_set_active_pane(dst_w, src_wp);
|
|
||||||
session_select(dst_s, dst_idx);
|
|
||||||
cmd_find_from_session(current, dst_s);
|
|
||||||
server_redraw_session(dst_s);
|
|
||||||
} else
|
|
||||||
server_status_session(dst_s);
|
|
||||||
|
|
||||||
if (window_count_panes(src_w) == 0)
|
|
||||||
server_kill_window(src_w);
|
|
||||||
else
|
|
||||||
notify_window("window-layout-changed", src_w);
|
|
||||||
notify_window("window-layout-changed", dst_w);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-kill-pane.c,v 1.12 2009-07-30 20:45:20 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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
|
||||||
@@ -26,47 +26,37 @@
|
|||||||
* Kill pane.
|
* Kill pane.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmdq_item *);
|
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 = {
|
||||||
.name = "kill-pane",
|
"kill-pane", "killp",
|
||||||
.alias = "killp",
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0, 0,
|
||||||
.args = { "at:", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-a] " CMD_TARGET_PANE_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_kill_pane_exec,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_kill_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct winlink *wl = item->target.wl;
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_pane *loopwp, *tmpwp, *wp = item->target.wp;
|
struct winlink *wl;
|
||||||
|
struct window_pane *wp;
|
||||||
|
|
||||||
server_unzoom_window(wl->window);
|
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
if (args_has(self->args, 'a')) {
|
|
||||||
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
|
|
||||||
if (loopwp == wp)
|
|
||||||
continue;
|
|
||||||
layout_close_pane(loopwp);
|
|
||||||
window_remove_pane(wl->window, loopwp);
|
|
||||||
}
|
|
||||||
server_redraw_window(wl->window);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window_count_panes(wl->window) == 1) {
|
if (window_count_panes(wl->window) == 1) {
|
||||||
|
/* Only one pane, kill the window. */
|
||||||
server_kill_window(wl->window);
|
server_kill_window(wl->window);
|
||||||
recalculate_sizes();
|
return (0);
|
||||||
} else {
|
|
||||||
layout_close_pane(wp);
|
|
||||||
window_remove_pane(wl->window, wp);
|
|
||||||
server_redraw_window(wl->window);
|
|
||||||
}
|
}
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
layout_close_pane(wp);
|
||||||
|
window_remove_pane(wl->window, wp);
|
||||||
|
server_redraw_window(wl->window);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-kill-server.c,v 1.8 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -27,35 +27,23 @@
|
|||||||
* Kill the server and do nothing else.
|
* Kill the server and do nothing else.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmdq_item *);
|
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 = {
|
||||||
.name = "kill-server",
|
"kill-server", NULL,
|
||||||
.alias = NULL,
|
"",
|
||||||
|
0, 0,
|
||||||
.args = { "", 0, 0 },
|
NULL,
|
||||||
.usage = "",
|
NULL,
|
||||||
|
cmd_kill_server_exec,
|
||||||
.flags = 0,
|
NULL,
|
||||||
.exec = cmd_kill_server_exec
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_start_server_entry = {
|
int
|
||||||
.name = "start-server",
|
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
.alias = "start",
|
|
||||||
|
|
||||||
.args = { "", 0, 0 },
|
|
||||||
.usage = "",
|
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER,
|
|
||||||
.exec = cmd_kill_server_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_kill_server_exec(struct cmd *self, __unused struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
if (self->entry == &cmd_kill_server_entry)
|
sigterm = 1;
|
||||||
kill(getpid(), SIGTERM);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-kill-session.c,v 1.14 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -27,46 +27,40 @@
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmdq_item *);
|
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 = {
|
||||||
.name = "kill-session",
|
"kill-session", NULL,
|
||||||
.alias = NULL,
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, 0,
|
||||||
.args = { "aCt:", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_kill_session_exec,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_kill_session_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
|
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;
|
||||||
struct winlink *wl;
|
struct client *c;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
s = item->target.s;
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
if (args_has(args, 'C')) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
c = ARRAY_ITEM(&clients, i);
|
||||||
wl->window->flags &= ~WINDOW_ALERTFLAGS;
|
if (c->session == s) {
|
||||||
wl->flags &= ~WINLINK_ALERTFLAGS;
|
c->session = NULL;
|
||||||
|
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||||
}
|
}
|
||||||
server_redraw_session(s);
|
|
||||||
} else if (args_has(args, 'a')) {
|
|
||||||
RB_FOREACH_SAFE(sloop, sessions, &sessions, stmp) {
|
|
||||||
if (sloop != s) {
|
|
||||||
server_destroy_session(sloop);
|
|
||||||
session_destroy(sloop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
server_destroy_session(s);
|
|
||||||
session_destroy(s);
|
|
||||||
}
|
}
|
||||||
return (CMD_RETURN_NORMAL);
|
recalculate_sizes();
|
||||||
|
|
||||||
|
session_destroy(s);
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-kill-window.c,v 1.19 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -24,58 +24,29 @@
|
|||||||
* Destroy window.
|
* Destroy window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmdq_item *);
|
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 = {
|
||||||
.name = "kill-window",
|
"kill-window", "killw",
|
||||||
.alias = "killw",
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, 0,
|
||||||
.args = { "at:", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-a] " CMD_TARGET_WINDOW_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_kill_window_exec,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_kill_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_unlink_window_entry = {
|
int
|
||||||
.name = "unlink-window",
|
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "unlinkw",
|
|
||||||
|
|
||||||
.args = { "kt:", 0, 0 },
|
|
||||||
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_kill_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_kill_window_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl = item->target.wl, *wl2, *wl3;
|
struct winlink *wl;
|
||||||
struct window *w = wl->window;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_unlink_window_entry) {
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
if (!args_has(self->args, 'k') && !session_is_linked(s, w)) {
|
return (-1);
|
||||||
cmdq_error(item, "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);
|
|
||||||
}
|
|
||||||
|
|
||||||
recalculate_sizes();
|
server_kill_window(wl->window);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
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.18 2009-07-28 22:12:16 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, 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);
|
||||||
|
}
|
||||||
98
cmd-link-window.c
Normal file
98
cmd-link-window.c
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/* $Id: cmd-link-window.c,v 1.32 2009-08-16 19:16:27 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, CMD_CHFLAG('d')|CMD_CHFLAG('k'),
|
||||||
|
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 *dst;
|
||||||
|
struct winlink *wl_src, *wl_dst;
|
||||||
|
char *cause;
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
wl_dst = NULL;
|
||||||
|
if (idx != -1)
|
||||||
|
wl_dst = winlink_find_by_index(&dst->windows, idx);
|
||||||
|
if (wl_dst != NULL) {
|
||||||
|
if (wl_dst->window == wl_src->window)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (data->chflags & CMD_CHFLAG('k')) {
|
||||||
|
/*
|
||||||
|
* Can't use session_detach as it will destroy session
|
||||||
|
* if this makes it empty.
|
||||||
|
*/
|
||||||
|
session_alert_cancel(dst, wl_dst);
|
||||||
|
winlink_stack_remove(&dst->lastw, wl_dst);
|
||||||
|
winlink_remove(&dst->windows, wl_dst);
|
||||||
|
|
||||||
|
/* Force select/redraw if current. */
|
||||||
|
if (wl_dst == dst->curw) {
|
||||||
|
data->chflags &= ~CMD_CHFLAG('d');
|
||||||
|
dst->curw = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
idx = -1 - options_get_number(&dst->options, "base-index");
|
||||||
|
wl_dst = session_attach(dst, wl_src->window, idx, &cause);
|
||||||
|
if (wl_dst == NULL) {
|
||||||
|
ctx->error(ctx, "create session failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data->chflags & CMD_CHFLAG('d'))
|
||||||
|
server_status_session(dst);
|
||||||
|
else {
|
||||||
|
session_select(dst, wl_dst->idx);
|
||||||
|
server_redraw_session(dst);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-buffers.c,v 1.12 2009-09-07 23:48:54 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,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,45 +26,53 @@
|
|||||||
* 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}\""
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_buffers_entry = {
|
const struct cmd_entry cmd_list_buffers_entry = {
|
||||||
.name = "list-buffers",
|
"list-buffers", "lsb",
|
||||||
.alias = "lsb",
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, 0,
|
||||||
.args = { "F:", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-F format]",
|
cmd_target_parse,
|
||||||
|
cmd_list_buffers_exec,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_target_free,
|
||||||
.exec = cmd_list_buffers_exec
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item)
|
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[51 * 4 + 1];
|
||||||
const char *template;
|
size_t size, len;
|
||||||
|
|
||||||
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(item->client, item, FORMAT_NONE, 0);
|
size = pb->size;
|
||||||
format_defaults_paste_buffer(ft, pb);
|
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
/* Translate the first 50 characters. */
|
||||||
cmdq_print(item, "%s", line);
|
len = size;
|
||||||
free(line);
|
if (len > 50)
|
||||||
|
len = 50;
|
||||||
|
strvisx(tmp, pb->data, len, VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||||
|
|
||||||
format_free(ft);
|
/*
|
||||||
|
* If the first 50 characterswere encoded as a longer string,
|
||||||
|
* or there is definitely more data, add "...".
|
||||||
|
*/
|
||||||
|
if (size > 50 || strlen(tmp) > 50) {
|
||||||
|
tmp[50 - 3] = '\0';
|
||||||
|
strlcat(tmp, "...", sizeof tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->print(ctx, "%u: %zu bytes: \"%s\"", idx - 1, size, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-clients.c,v 1.18 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,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,62 +27,39 @@
|
|||||||
* List all clients.
|
* List all clients.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_CLIENTS_TEMPLATE \
|
int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{client_name}: #{session_name} " \
|
|
||||||
"[#{client_width}x#{client_height} #{client_termname}]" \
|
|
||||||
"#{?client_utf8, (utf8),} #{?client_readonly, (ro),}"
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_clients_entry = {
|
const struct cmd_entry cmd_list_clients_entry = {
|
||||||
.name = "list-clients",
|
"list-clients", "lsc",
|
||||||
.alias = "lsc",
|
"",
|
||||||
|
0, 0,
|
||||||
.args = { "F:t:", 0, 0 },
|
NULL,
|
||||||
.usage = "[-F format] " CMD_TARGET_SESSION_USAGE,
|
NULL,
|
||||||
|
cmd_list_clients_exec,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
NULL,
|
||||||
|
NULL
|
||||||
.flags = CMD_READONLY|CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_list_clients_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
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 = item->target.s;
|
c = ARRAY_ITEM(&clients, i);
|
||||||
else
|
if (c == NULL || c->session == NULL)
|
||||||
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(item->client, item, FORMAT_NONE, 0);
|
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(item, "%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,5 +1,7 @@
|
|||||||
|
/* $Id: cmd-list-commands.c,v 1.5 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -16,40 +18,32 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <glob.h>
|
#include "tmux.h"
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "compat.h"
|
/*
|
||||||
|
* List all commands with usages.
|
||||||
|
*/
|
||||||
|
|
||||||
void fatal(const char *, ...);
|
int cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
|
||||||
void fatalx(const char *, ...);
|
|
||||||
|
const struct cmd_entry cmd_list_commands_entry = {
|
||||||
|
"list-commands", "lscm",
|
||||||
|
"",
|
||||||
|
0, 0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_commands_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef HAVE_PROC_PID
|
|
||||||
int
|
int
|
||||||
getdtablecount(void)
|
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
const struct cmd_entry **entryp;
|
||||||
glob_t g;
|
|
||||||
int n;
|
for (entryp = cmd_table; *entryp != NULL; entryp++)
|
||||||
|
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
|
||||||
|
|
||||||
if (snprintf(path, sizeof path, "/proc/%ld/fd/*", (long)getpid()) < 0)
|
|
||||||
fatal("snprintf overflow");
|
|
||||||
switch (glob(path, 0, NULL, &g)) {
|
|
||||||
case GLOB_NOMATCH:
|
|
||||||
return (0);
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fatal("glob(\"%s\") failed", path);
|
|
||||||
}
|
|
||||||
n = g.gl_pathc;
|
|
||||||
globfree(&g);
|
|
||||||
return (n);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
int
|
|
||||||
getdtablecount(void)
|
|
||||||
{
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
190
cmd-list-keys.c
190
cmd-list-keys.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-keys.c,v 1.20 2009-07-28 23:19:06 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,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,147 +26,100 @@
|
|||||||
* List key bindings.
|
* List key bindings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *);
|
int cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_keys_commands(struct cmd *,
|
int cmd_list_keys_table(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_keys_entry = {
|
const struct cmd_entry cmd_list_keys_entry = {
|
||||||
.name = "list-keys",
|
"list-keys", "lsk",
|
||||||
.alias = "lsk",
|
"[-t key-table]",
|
||||||
|
0, 0,
|
||||||
.args = { "T:", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-T key-table]",
|
cmd_target_parse,
|
||||||
|
cmd_list_keys_exec,
|
||||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
cmd_target_free,
|
||||||
.exec = cmd_list_keys_exec
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_commands_entry = {
|
int
|
||||||
.name = "list-commands",
|
cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "lscm",
|
|
||||||
|
|
||||||
.args = { "F:", 0, 0 },
|
|
||||||
.usage = "[-F format]",
|
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_list_keys_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
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 *cp, tmp[BUFSIZ];
|
char tmp[BUFSIZ], keytmp[64];
|
||||||
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, item));
|
return (cmd_list_keys_table(self, ctx));
|
||||||
|
|
||||||
tablename = args_get(args, 'T');
|
width = 0;
|
||||||
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) {
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
return (CMD_RETURN_ERROR);
|
if (key == NULL)
|
||||||
}
|
|
||||||
|
|
||||||
repeat = 0;
|
|
||||||
tablewidth = keywidth = 0;
|
|
||||||
RB_FOREACH(table, key_tables, &key_tables) {
|
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0)
|
|
||||||
continue;
|
continue;
|
||||||
RB_FOREACH(bd, key_bindings, &table->key_bindings) {
|
|
||||||
key = key_string_lookup_key(bd->key);
|
|
||||||
|
|
||||||
if (bd->flags & KEY_BINDING_REPEAT)
|
keywidth = strlen(key) + 1;
|
||||||
repeat = 1;
|
if (!(bd->key & KEYC_PREFIX))
|
||||||
|
keywidth += 2;
|
||||||
width = utf8_cstrwidth(table->name);
|
if (keywidth > width)
|
||||||
if (width > tablewidth)
|
width = keywidth;
|
||||||
tablewidth = width;
|
|
||||||
width = utf8_cstrwidth(key);
|
|
||||||
if (width > keywidth)
|
|
||||||
keywidth = width;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_FOREACH(table, key_tables, &key_tables) {
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0)
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
|
if (key == NULL)
|
||||||
continue;
|
continue;
|
||||||
RB_FOREACH(bd, key_bindings, &table->key_bindings) {
|
|
||||||
key = key_string_lookup_key(bd->key);
|
|
||||||
|
|
||||||
if (!repeat)
|
*tmp = '\0';
|
||||||
r = "";
|
cmd_list_print(bd->cmdlist, tmp, sizeof tmp);
|
||||||
else if (bd->flags & KEY_BINDING_REPEAT)
|
if (!(bd->key & KEYC_PREFIX)) {
|
||||||
r = "-r ";
|
xsnprintf(keytmp, sizeof keytmp, "[%s]", key);
|
||||||
else
|
key = keytmp;
|
||||||
r = " ";
|
|
||||||
xsnprintf(tmp, sizeof tmp, "%s-T ", r);
|
|
||||||
|
|
||||||
cp = utf8_padcstr(table->name, tablewidth);
|
|
||||||
strlcat(tmp, cp, sizeof tmp);
|
|
||||||
strlcat(tmp, " ", sizeof tmp);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
cp = utf8_padcstr(key, keywidth);
|
|
||||||
strlcat(tmp, cp, sizeof tmp);
|
|
||||||
strlcat(tmp, " ", sizeof tmp);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
cp = cmd_list_print(bd->cmdlist);
|
|
||||||
strlcat(tmp, cp, sizeof tmp);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
cmdq_print(item, "bind-key %s", tmp);
|
|
||||||
}
|
}
|
||||||
|
ctx->print(ctx, "%*s: %s", width, key, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
const struct cmd_entry **entryp;
|
const struct mode_key_table *mtab;
|
||||||
const struct cmd_entry *entry;
|
struct mode_key_binding *mbind;
|
||||||
struct format_tree *ft;
|
const char *key, *cmdstr, *mode;
|
||||||
const char *template, *s;
|
int width, keywidth;
|
||||||
char *line;
|
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL) {
|
if ((mtab = mode_key_findtable(data->target)) == NULL) {
|
||||||
template = "#{command_list_name}"
|
ctx->error(ctx, "unknown key table: %s", data->target);
|
||||||
"#{?command_list_alias, (#{command_list_alias}),} "
|
return (-1);
|
||||||
"#{command_list_usage}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
width = 0;
|
||||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
|
key = key_string_lookup_key(mbind->key);
|
||||||
|
if (key == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
keywidth = strlen(key) + 1;
|
||||||
entry = *entryp;
|
if (keywidth > width)
|
||||||
|
width = keywidth;
|
||||||
format_add(ft, "command_list_name", "%s", entry->name);
|
|
||||||
if (entry->alias != NULL)
|
|
||||||
s = entry->alias;
|
|
||||||
else
|
|
||||||
s = "";
|
|
||||||
format_add(ft, "command_list_alias", "%s", s);
|
|
||||||
if (entry->usage != NULL)
|
|
||||||
s = entry->usage;
|
|
||||||
else
|
|
||||||
s = "";
|
|
||||||
format_add(ft, "command_list_usage", "%s", s);
|
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
|
||||||
if (*line != '\0')
|
|
||||||
cmdq_print(item, "%s", line);
|
|
||||||
free(line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
format_free(ft);
|
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
return (CMD_RETURN_NORMAL);
|
key = key_string_lookup_key(mbind->key);
|
||||||
|
if (key == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
mode = "";
|
||||||
|
if (mbind->mode != 0)
|
||||||
|
mode = "(command mode) ";
|
||||||
|
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
|
||||||
|
if (cmdstr != NULL)
|
||||||
|
ctx->print(ctx, "%*s: %s%s", width, key, mode, cmdstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
137
cmd-list-panes.c
137
cmd-list-panes.c
@@ -1,137 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
*
|
|
||||||
* 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"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* List panes on given window.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
static void cmd_list_panes_server(struct cmd *, struct cmdq_item *);
|
|
||||||
static void cmd_list_panes_session(struct cmd *, struct session *,
|
|
||||||
struct cmdq_item *, int);
|
|
||||||
static void cmd_list_panes_window(struct cmd *, struct session *,
|
|
||||||
struct winlink *, struct cmdq_item *, int);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_panes_entry = {
|
|
||||||
.name = "list-panes",
|
|
||||||
.alias = "lsp",
|
|
||||||
|
|
||||||
.args = { "asF:t:", 0, 0 },
|
|
||||||
.usage = "[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_list_panes_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
|
|
||||||
if (args_has(args, 'a'))
|
|
||||||
cmd_list_panes_server(self, item);
|
|
||||||
else if (args_has(args, 's'))
|
|
||||||
cmd_list_panes_session(self, s, item, 1);
|
|
||||||
else
|
|
||||||
cmd_list_panes_window(self, s, wl, item, 0);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_list_panes_server(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions)
|
|
||||||
cmd_list_panes_session(self, s, item, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_list_panes_session(struct cmd *self, struct session *s,
|
|
||||||
struct cmdq_item *item, int type)
|
|
||||||
{
|
|
||||||
struct winlink *wl;
|
|
||||||
|
|
||||||
RB_FOREACH(wl, winlinks, &s->windows)
|
|
||||||
cmd_list_panes_window(self, s, wl, item, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
|
||||||
struct cmdq_item *item, int type)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct window_pane *wp;
|
|
||||||
u_int n;
|
|
||||||
struct format_tree *ft;
|
|
||||||
const char *template;
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
|
||||||
if (template == NULL) {
|
|
||||||
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;
|
|
||||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
|
||||||
format_add(ft, "line", "%u", n);
|
|
||||||
format_defaults(ft, NULL, s, wl, wp);
|
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
|
||||||
cmdq_print(item, "%s", line);
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-sessions.c,v 1.21 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,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,54 +27,39 @@
|
|||||||
* 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 #{t:session_created}) " \
|
|
||||||
"[#{session_width}x#{session_height}]" \
|
|
||||||
"#{?session_grouped, (group ,}" \
|
|
||||||
"#{session_group}#{?session_grouped,),}" \
|
|
||||||
"#{?session_attached, (attached),}"
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_sessions_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_sessions_entry = {
|
const struct cmd_entry cmd_list_sessions_entry = {
|
||||||
.name = "list-sessions",
|
"list-sessions", "ls", "",
|
||||||
.alias = "ls",
|
0, 0,
|
||||||
|
NULL,
|
||||||
.args = { "F:", 0, 0 },
|
NULL,
|
||||||
.usage = "[-F format]",
|
cmd_list_sessions_exec,
|
||||||
|
NULL,
|
||||||
.flags = CMD_AFTERHOOK,
|
NULL
|
||||||
.exec = cmd_list_sessions_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct session *s;
|
||||||
struct session *s;
|
char *tim;
|
||||||
u_int n;
|
u_int i;
|
||||||
struct format_tree *ft;
|
time_t t;
|
||||||
const char *template;
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||||
template = LIST_SESSIONS_TEMPLATE;
|
s = ARRAY_ITEM(&sessions, i);
|
||||||
|
if (s == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
n = 0;
|
t = s->tv.tv_sec;
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
tim = ctime(&t);
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
*strchr(tim, '\n') = '\0';
|
||||||
format_add(ft, "line", "%u", n);
|
|
||||||
format_defaults(ft, NULL, s, NULL, NULL);
|
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s",
|
||||||
cmdq_print(item, "%s", line);
|
s->name, winlink_count(&s->windows), tim, s->sx, s->sy,
|
||||||
free(line);
|
s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
n++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-windows.c,v 1.40 2009-08-09 17:28:23 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,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,62 @@
|
|||||||
* 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}] "
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
static void cmd_list_windows_server(struct cmd *, struct cmdq_item *);
|
|
||||||
static void cmd_list_windows_session(struct cmd *, struct session *,
|
|
||||||
struct cmdq_item *, int);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_windows_entry = {
|
const struct cmd_entry cmd_list_windows_entry = {
|
||||||
.name = "list-windows",
|
"list-windows", "lsw",
|
||||||
.alias = "lsw",
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, 0,
|
||||||
.args = { "F:at:", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_list_windows_exec,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_list_windows_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item)
|
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;
|
||||||
if (args_has(args, 'a'))
|
|
||||||
cmd_list_windows_server(self, item);
|
|
||||||
else
|
|
||||||
cmd_list_windows_session(self, item->target.s, item, 0);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_list_windows_server(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions)
|
|
||||||
cmd_list_windows_session(self, s, item, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_list_windows_session(struct cmd *self, struct session *s,
|
|
||||||
struct cmdq_item *item, int type)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
u_int n;
|
struct window *w;
|
||||||
struct format_tree *ft;
|
struct window_pane *wp;
|
||||||
const char *template;
|
struct grid *gd;
|
||||||
char *line;
|
struct grid_line *gl;
|
||||||
|
u_int i;
|
||||||
|
unsigned long long size;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
if (template == NULL) {
|
return (-1);
|
||||||
switch (type) {
|
|
||||||
case 0:
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
template = LIST_WINDOWS_TEMPLATE;
|
w = wl->window;
|
||||||
break;
|
ctx->print(ctx,
|
||||||
case 1:
|
"%3d: %s [%ux%u]", wl->idx, w->name, w->sx, w->sy);
|
||||||
template = LIST_WINDOWS_WITH_SESSION_TEMPLATE;
|
|
||||||
break;
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
|
gd = wp->base.grid;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
for (i = 0; i < gd->hsize; i++) {
|
||||||
|
gl = &gd->linedata[i];
|
||||||
|
size += gl->cellsize * sizeof *gl->celldata;
|
||||||
|
size += gl->utf8size * sizeof *gl->utf8data;
|
||||||
|
}
|
||||||
|
size += gd->hsize * sizeof *gd->linedata;
|
||||||
|
|
||||||
|
name = NULL;
|
||||||
|
if (wp->fd != -1)
|
||||||
|
name = ttyname(wp->fd);
|
||||||
|
if (name == NULL)
|
||||||
|
name = "unknown";
|
||||||
|
ctx->print(ctx,
|
||||||
|
" %s [%ux%u] [history %u/%u, %llu bytes]",
|
||||||
|
name, wp->sx, wp->sy, gd->hsize, gd->hlimit, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
n = 0;
|
return (0);
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
|
||||||
format_add(ft, "line", "%u", n);
|
|
||||||
format_defaults(ft, NULL, s, wl, NULL);
|
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
|
||||||
cmdq_print(item, "%s", line);
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
101
cmd-list.c
101
cmd-list.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list.c,v 1.6 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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,109 +18,102 @@
|
|||||||
|
|
||||||
#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;
|
||||||
int i, lastsplit;
|
int i, lastsplit;
|
||||||
size_t arglen, new_argc;
|
size_t arglen, new_argc;
|
||||||
char **copy_argv, **new_argv;
|
char **new_argv;
|
||||||
|
|
||||||
copy_argv = cmd_copy_argv(argc, argv);
|
cmdlist = xmalloc(sizeof *cmdlist);
|
||||||
|
TAILQ_INIT(cmdlist);
|
||||||
cmdlist = xcalloc(1, sizeof *cmdlist);
|
|
||||||
cmdlist->references = 1;
|
|
||||||
TAILQ_INIT(&cmdlist->list);
|
|
||||||
|
|
||||||
lastsplit = 0;
|
lastsplit = 0;
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
arglen = strlen(copy_argv[i]);
|
arglen = strlen(argv[i]);
|
||||||
if (arglen == 0 || copy_argv[i][arglen - 1] != ';')
|
if (arglen == 0 || argv[i][arglen - 1] != ';')
|
||||||
continue;
|
continue;
|
||||||
copy_argv[i][arglen - 1] = '\0';
|
argv[i][arglen - 1] = '\0';
|
||||||
|
|
||||||
if (arglen > 1 && copy_argv[i][arglen - 2] == '\\') {
|
if (arglen > 1 && argv[i][arglen - 2] == '\\') {
|
||||||
copy_argv[i][arglen - 2] = ';';
|
argv[i][arglen - 2] = ';';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_argc = i - lastsplit;
|
new_argc = i - lastsplit;
|
||||||
new_argv = copy_argv + lastsplit;
|
new_argv = argv + lastsplit;
|
||||||
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, cmd, qentry);
|
||||||
|
|
||||||
lastsplit = i + 1;
|
lastsplit = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastsplit != argc) {
|
if (lastsplit != argc) {
|
||||||
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit,
|
cmd = cmd_parse(argc - lastsplit, 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, cmd, qentry);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_free_argv(argc, copy_argv);
|
|
||||||
return (cmdlist);
|
return (cmdlist);
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
cmd_list_free(cmdlist);
|
cmd_list_free(cmdlist);
|
||||||
cmd_free_argv(argc, copy_argv);
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
TAILQ_FOREACH(cmd, cmdlist, qentry) {
|
||||||
|
if ((n = cmd_exec(cmd, ctx)) != 0)
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
while (!TAILQ_EMPTY(cmdlist)) {
|
||||||
return;
|
cmd = TAILQ_FIRST(cmdlist);
|
||||||
|
TAILQ_REMOVE(cmdlist, cmd, qentry);
|
||||||
TAILQ_FOREACH_SAFE(cmd, &cmdlist->list, qentry, cmd1) {
|
cmd_free(cmd);
|
||||||
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
|
||||||
args_free(cmd->args);
|
|
||||||
free(cmd->file);
|
|
||||||
free(cmd);
|
|
||||||
}
|
}
|
||||||
|
xfree(cmdlist);
|
||||||
free(cmdlist);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
size_t
|
||||||
cmd_list_print(struct cmd_list *cmdlist)
|
cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
struct cmd *cmd;
|
struct cmd *cmd;
|
||||||
char *buf, *this;
|
size_t off;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
len = 1;
|
off = 0;
|
||||||
buf = xcalloc(1, len);
|
TAILQ_FOREACH(cmd, cmdlist, qentry) {
|
||||||
|
if (off >= len)
|
||||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
break;
|
||||||
this = cmd_print(cmd);
|
off += cmd_print(cmd, buf + off, len - off);
|
||||||
|
if (off >= len)
|
||||||
len += strlen(this) + 3;
|
break;
|
||||||
buf = xrealloc(buf, len);
|
|
||||||
|
|
||||||
strlcat(buf, this, len);
|
|
||||||
if (TAILQ_NEXT(cmd, qentry) != NULL)
|
if (TAILQ_NEXT(cmd, qentry) != NULL)
|
||||||
strlcat(buf, " ; ", len);
|
off += xsnprintf(buf + off, len - off, " ; ");
|
||||||
|
|
||||||
free(this);
|
|
||||||
}
|
}
|
||||||
|
return (off);
|
||||||
return (buf);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-load-buffer.c,v 1.10 2009-09-07 23:48:54 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -17,10 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -28,147 +27,74 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Loads a paste buffer from a file.
|
* Loads a session paste buffer from a file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmdq_item *);
|
int cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static void cmd_load_buffer_callback(struct client *, int, void *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_load_buffer_entry = {
|
const struct cmd_entry cmd_load_buffer_entry = {
|
||||||
.name = "load-buffer",
|
"load-buffer", "loadb",
|
||||||
.alias = "loadb",
|
CMD_BUFFER_SESSION_USAGE " path",
|
||||||
|
CMD_ARG1, 0,
|
||||||
.args = { "b:", 1, 1 },
|
cmd_buffer_init,
|
||||||
.usage = CMD_BUFFER_USAGE " path",
|
cmd_buffer_parse,
|
||||||
|
cmd_load_buffer_exec,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_buffer_free,
|
||||||
.exec = cmd_load_buffer_exec
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_load_buffer_data {
|
int
|
||||||
struct cmdq_item *item;
|
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
char *bufname;
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct cmd_load_buffer_data *cdata;
|
struct session *s;
|
||||||
struct client *c = item->client;
|
struct stat sb;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
const char *path, *bufname;
|
u_char *buf;
|
||||||
char *pdata, *new_pdata, *cause, *file;
|
u_int limit;
|
||||||
size_t psize;
|
|
||||||
int ch, error;
|
|
||||||
|
|
||||||
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 (stat(data->arg, &sb) < 0) {
|
||||||
if (strcmp(path, "-") == 0) {
|
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
return (-1);
|
||||||
cdata->item = item;
|
|
||||||
|
|
||||||
if (bufname != NULL)
|
|
||||||
cdata->bufname = xstrdup(bufname);
|
|
||||||
|
|
||||||
error = server_set_stdin_callback(c, cmd_load_buffer_callback,
|
|
||||||
cdata, &cause);
|
|
||||||
if (error != 0) {
|
|
||||||
cmdq_error(item, "%s: %s", path, cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file = server_client_get_path(c, path);
|
if ((f = fopen(data->arg, "rb")) == NULL) {
|
||||||
f = fopen(file, "rb");
|
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||||
if (f == NULL) {
|
return (-1);
|
||||||
cmdq_error(item, "%s: %s", file, strerror(errno));
|
|
||||||
free(file);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pdata = NULL;
|
/*
|
||||||
psize = 0;
|
* We don't want to die due to memory exhaustion, hence xmalloc can't
|
||||||
while ((ch = getc(f)) != EOF) {
|
* be used here.
|
||||||
/* Do not let the server die due to memory exhaustion. */
|
*/
|
||||||
if ((new_pdata = realloc(pdata, psize + 2)) == NULL) {
|
if ((buf = malloc(sb.st_size + 1)) == NULL) {
|
||||||
cmdq_error(item, "realloc error: %s", strerror(errno));
|
ctx->error(ctx, "malloc error: %s", strerror(errno));
|
||||||
goto error;
|
fclose(f);
|
||||||
}
|
return (-1);
|
||||||
pdata = new_pdata;
|
|
||||||
pdata[psize++] = ch;
|
|
||||||
}
|
}
|
||||||
if (ferror(f)) {
|
|
||||||
cmdq_error(item, "%s: read error", file);
|
if (fread(buf, 1, sb.st_size, f) != (size_t) sb.st_size) {
|
||||||
goto error;
|
ctx->error(ctx, "%s: fread error", data->arg);
|
||||||
|
xfree(buf);
|
||||||
|
fclose(f);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
if (pdata != NULL)
|
|
||||||
pdata[psize] = '\0';
|
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(file);
|
|
||||||
|
|
||||||
if (paste_set(pdata, psize, bufname, &cause) != 0) {
|
limit = options_get_number(&s->options, "buffer-limit");
|
||||||
cmdq_error(item, "%s", cause);
|
if (data->buffer == -1) {
|
||||||
free(pdata);
|
paste_add(&s->buffers, buf, sb.st_size, limit);
|
||||||
free(cause);
|
return (0);
|
||||||
return (CMD_RETURN_ERROR);
|
}
|
||||||
|
if (paste_replace(&s->buffers, data->buffer, buf, sb.st_size) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
|
xfree(buf);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
error:
|
|
||||||
free(pdata);
|
|
||||||
if (f != NULL)
|
|
||||||
fclose(f);
|
|
||||||
free(file);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_load_buffer_callback(struct client *c, int closed, void *data)
|
|
||||||
{
|
|
||||||
struct cmd_load_buffer_data *cdata = data;
|
|
||||||
char *pdata, *cause, *saved;
|
|
||||||
size_t psize;
|
|
||||||
|
|
||||||
if (!closed)
|
|
||||||
return;
|
|
||||||
c->stdin_callback = NULL;
|
|
||||||
|
|
||||||
server_client_unref(c);
|
|
||||||
if (c->flags & CLIENT_DEAD)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
psize = EVBUFFER_LENGTH(c->stdin_data);
|
|
||||||
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
memcpy(pdata, EVBUFFER_DATA(c->stdin_data), psize);
|
|
||||||
pdata[psize] = '\0';
|
|
||||||
evbuffer_drain(c->stdin_data, psize);
|
|
||||||
|
|
||||||
if (paste_set(pdata, psize, cdata->bufname, &cause) != 0) {
|
|
||||||
/* No context so can't use server_client_msg_error. */
|
|
||||||
if (~c->flags & CLIENT_UTF8) {
|
|
||||||
saved = cause;
|
|
||||||
cause = utf8_sanitize(saved);
|
|
||||||
free(saved);
|
|
||||||
}
|
|
||||||
evbuffer_add_printf(c->stderr_data, "%s", cause);
|
|
||||||
server_client_push_stderr(c);
|
|
||||||
free(pdata);
|
|
||||||
free(cause);
|
|
||||||
}
|
|
||||||
out:
|
|
||||||
cdata->item->flags &= ~CMDQ_WAITING;
|
|
||||||
|
|
||||||
free(cdata->bufname);
|
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-lock-server.c,v 1.6 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 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,65 +18,33 @@
|
|||||||
|
|
||||||
#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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmdq_item *);
|
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 = {
|
||||||
.name = "lock-server",
|
"lock-server", "lock",
|
||||||
.alias = "lock",
|
"",
|
||||||
|
0, 0,
|
||||||
.args = { "", 0, 0 },
|
NULL,
|
||||||
.usage = "",
|
NULL,
|
||||||
|
cmd_lock_server_exec,
|
||||||
.flags = CMD_AFTERHOOK,
|
NULL,
|
||||||
.exec = cmd_lock_server_exec
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_lock_session_entry = {
|
int
|
||||||
.name = "lock-session",
|
cmd_lock_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
.alias = "locks",
|
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
|
||||||
.usage = CMD_TARGET_SESSION_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_lock_server_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_lock_client_entry = {
|
|
||||||
.name = "lock-client",
|
|
||||||
.alias = "lockc",
|
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
|
||||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_lock_server_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_lock_server_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
server_lock();
|
||||||
struct client *c;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_lock_server_entry)
|
return (0);
|
||||||
server_lock();
|
|
||||||
else if (self->entry == &cmd_lock_session_entry)
|
|
||||||
server_lock_session(item->target.s);
|
|
||||||
else {
|
|
||||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
server_lock_client(c);
|
|
||||||
}
|
|
||||||
recalculate_sizes();
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-move-window.c,v 1.9 2009-08-16 19:16:27 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 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
|
||||||
@@ -26,93 +26,87 @@
|
|||||||
* Move a window.
|
* Move a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmdq_item *);
|
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 = {
|
||||||
.name = "move-window",
|
"move-window", "movew",
|
||||||
.alias = "movew",
|
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
|
0, CMD_CHFLAG('d')|CMD_CHFLAG('k'),
|
||||||
.args = { "adkrs:t:", 0, 0 },
|
cmd_srcdst_init,
|
||||||
.usage = "[-dkr] " CMD_SRCDST_WINDOW_USAGE,
|
cmd_srcdst_parse,
|
||||||
|
cmd_move_window_exec,
|
||||||
.source = { 's', CMD_FIND_WINDOW, 0 },
|
cmd_srcdst_free,
|
||||||
/* -t is special */
|
cmd_srcdst_print
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_move_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_link_window_entry = {
|
int
|
||||||
.name = "link-window",
|
cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "linkw",
|
|
||||||
|
|
||||||
.args = { "adks:t:", 0, 0 },
|
|
||||||
.usage = "[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
|
||||||
|
|
||||||
.source = { 's', CMD_FIND_WINDOW, 0 },
|
|
||||||
/* -t is special */
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_move_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_srcdst_data *data = self->data;
|
||||||
const char *tflag = args_get(args, 't');
|
struct session *src, *dst;
|
||||||
struct session *src;
|
struct winlink *wl_src, *wl_dst;
|
||||||
struct session *dst;
|
struct client *c;
|
||||||
struct winlink *wl;
|
u_int i;
|
||||||
char *cause;
|
int destroyed, idx;
|
||||||
int idx, kflag, dflag, sflag;
|
char *cause;
|
||||||
|
|
||||||
if (args_has(args, 'r')) {
|
if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||||
if (cmd_find_target(&item->target, item, tflag,
|
return (-1);
|
||||||
CMD_FIND_SESSION, CMD_FIND_QUIET) != 0)
|
if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
session_renumber_windows(item->target.s);
|
wl_dst = NULL;
|
||||||
recalculate_sizes();
|
if (idx != -1)
|
||||||
server_status_session(item->target.s);
|
wl_dst = winlink_find_by_index(&dst->windows, idx);
|
||||||
|
if (wl_dst != NULL) {
|
||||||
|
if (wl_dst->window == wl_src->window)
|
||||||
|
return (0);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
if (data->chflags & CMD_CHFLAG('k')) {
|
||||||
}
|
/*
|
||||||
if (cmd_find_target(&item->target, item, tflag, CMD_FIND_WINDOW,
|
* Can't use session_detach as it will destroy session
|
||||||
CMD_FIND_WINDOW_INDEX) != 0)
|
* if this makes it empty.
|
||||||
return (CMD_RETURN_ERROR);
|
*/
|
||||||
src = item->source.s;
|
session_alert_cancel(dst, wl_dst);
|
||||||
dst = item->target.s;
|
winlink_stack_remove(&dst->lastw, wl_dst);
|
||||||
wl = item->source.wl;
|
winlink_remove(&dst->windows, wl_dst);
|
||||||
idx = item->target.idx;
|
|
||||||
|
|
||||||
kflag = args_has(self->args, 'k');
|
/* Force select/redraw if current. */
|
||||||
dflag = args_has(self->args, 'd');
|
if (wl_dst == dst->curw) {
|
||||||
sflag = args_has(self->args, 's');
|
data->chflags &= ~CMD_CHFLAG('d');
|
||||||
|
dst->curw = NULL;
|
||||||
if (args_has(self->args, 'a')) {
|
}
|
||||||
if ((idx = winlink_shuffle_up(dst, dst->curw)) == -1)
|
}
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server_link_window(src, wl, dst, idx, kflag, !dflag,
|
if (idx == -1)
|
||||||
&cause) != 0) {
|
idx = -1 - options_get_number(&dst->options, "base-index");
|
||||||
cmdq_error(item, "can't link window: %s", cause);
|
wl_dst = session_attach(dst, wl_src->window, idx, &cause);
|
||||||
free(cause);
|
if (wl_dst == NULL) {
|
||||||
return (CMD_RETURN_ERROR);
|
ctx->error(ctx, "attach window failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
if (self->entry == &cmd_move_window_entry)
|
|
||||||
server_unlink_window(src, wl);
|
|
||||||
|
|
||||||
/*
|
destroyed = session_detach(src, wl_src);
|
||||||
* Renumber the winlinks in the src session only, the destination
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
* session already has the correct winlink id to us, either
|
c = ARRAY_ITEM(&clients, i);
|
||||||
* automatically or specified by -s.
|
if (c == NULL || c->session != src)
|
||||||
*/
|
continue;
|
||||||
if (!sflag && options_get_number(src->options, "renumber-windows"))
|
if (destroyed) {
|
||||||
session_renumber_windows(src);
|
c->session = NULL;
|
||||||
|
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||||
|
} else
|
||||||
|
server_redraw_client(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data->chflags & CMD_CHFLAG('d'))
|
||||||
|
server_status_session(dst);
|
||||||
|
else {
|
||||||
|
session_select(dst, wl_dst->idx);
|
||||||
|
server_redraw_session(dst);
|
||||||
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-new-session.c,v 1.66 2009-09-16 12:36:27 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,9 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.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,182 +28,176 @@
|
|||||||
* 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);
|
||||||
|
|
||||||
static enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmdq_item *);
|
struct cmd_new_session_data {
|
||||||
|
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 = {
|
||||||
.name = "new-session",
|
"new-session", "new",
|
||||||
.alias = "new",
|
"[-d] [-n window-name] [-s session-name] [command]",
|
||||||
|
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON, 0,
|
||||||
.args = { "Ac:dDEF:n:Ps:t:x:y:", 0, -1 },
|
cmd_new_session_init,
|
||||||
.usage = "[-AdDEP] [-c start-directory] [-F format] [-n window-name] "
|
cmd_new_session_parse,
|
||||||
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
|
cmd_new_session_exec,
|
||||||
"[-y height] [command]",
|
cmd_new_session_free,
|
||||||
|
cmd_new_session_print
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER,
|
|
||||||
.exec = cmd_new_session_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_has_session_entry = {
|
void
|
||||||
.name = "has-session",
|
cmd_new_session_init(struct cmd *self, unused int arg)
|
||||||
.alias = "has",
|
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
|
||||||
.usage = CMD_TARGET_SESSION_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_new_session_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_new_session_data *data;
|
||||||
struct client *c = item->client;
|
|
||||||
struct session *s, *as, *groupwith;
|
|
||||||
struct window *w;
|
|
||||||
struct environ *env;
|
|
||||||
struct termios tio, *tiop;
|
|
||||||
struct session_group *sg;
|
|
||||||
const char *newname, *errstr, *template, *group, *prefix;
|
|
||||||
const char *path, *cmd, *cwd, *to_free = NULL;
|
|
||||||
char **argv, *cause, *cp;
|
|
||||||
int detached, already_attached, idx, argc;
|
|
||||||
u_int sx, sy;
|
|
||||||
struct environ_entry *envent;
|
|
||||||
struct cmd_find_state fs;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_has_session_entry) {
|
self->data = data = xmalloc(sizeof *data);
|
||||||
/*
|
data->flag_detached = 0;
|
||||||
* cmd_find_target() will fail if the session cannot be found,
|
data->newname = NULL;
|
||||||
* so always return success here.
|
data->winname = NULL;
|
||||||
*/
|
data->cmd = NULL;
|
||||||
return (CMD_RETURN_NORMAL);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) {
|
int
|
||||||
cmdq_error(item, "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, 0);
|
||||||
if (newname != NULL) {
|
data = self->data;
|
||||||
if (!session_check_name(newname)) {
|
|
||||||
cmdq_error(item, "bad session name: %s", newname);
|
while ((opt = getopt(argc, argv, "ds:n:")) != -1) {
|
||||||
return (CMD_RETURN_ERROR);
|
switch (opt) {
|
||||||
}
|
case 'd':
|
||||||
if ((as = session_find(newname)) != NULL) {
|
data->flag_detached = 1;
|
||||||
if (args_has(args, 'A')) {
|
break;
|
||||||
return (cmd_attach_session(item,
|
case 's':
|
||||||
newname, args_has(args, 'D'),
|
if (data->newname == NULL)
|
||||||
0, NULL, args_has(args, 'E')));
|
data->newname = xstrdup(optarg);
|
||||||
}
|
break;
|
||||||
cmdq_error(item, "duplicate session: %s", newname);
|
case 'n':
|
||||||
return (CMD_RETURN_ERROR);
|
if (data->winname == NULL)
|
||||||
|
data->winname = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 0 && argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
/* Is this going to be part of a session group? */
|
if (argc == 1)
|
||||||
group = args_get(args, 't');
|
data->cmd = xstrdup(argv[0]);
|
||||||
if (group != NULL) {
|
|
||||||
groupwith = item->target.s;
|
return (0);
|
||||||
if (groupwith == NULL) {
|
|
||||||
if (!session_check_name(group)) {
|
usage:
|
||||||
cmdq_error(item, "bad group name: %s", group);
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
goto error;
|
|
||||||
}
|
self->entry->free(self);
|
||||||
sg = session_group_find(group);
|
return (-1);
|
||||||
} else
|
}
|
||||||
sg = session_group_contains(groupwith);
|
|
||||||
if (sg != NULL)
|
int
|
||||||
prefix = sg->name;
|
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
else if (groupwith != NULL)
|
{
|
||||||
prefix = groupwith->name;
|
struct cmd_new_session_data *data = self->data;
|
||||||
else
|
struct session *s;
|
||||||
prefix = group;
|
struct window *w;
|
||||||
} else {
|
struct environ env;
|
||||||
groupwith = NULL;
|
struct termios tio, *tiop;
|
||||||
sg = NULL;
|
const char *update;
|
||||||
prefix = NULL;
|
char *overrides, *cmd, *cwd, *cause;
|
||||||
|
int detached, idx;
|
||||||
|
u_int sx, sy;
|
||||||
|
|
||||||
|
if (data->newname != NULL && session_find(data->newname) != NULL) {
|
||||||
|
ctx->error(ctx, "duplicate session: %s", data->newname);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set -d if no client. */
|
|
||||||
detached = args_has(args, 'd');
|
|
||||||
if (c == NULL)
|
|
||||||
detached = 1;
|
|
||||||
|
|
||||||
/* Is this client already attached? */
|
|
||||||
already_attached = 0;
|
|
||||||
if (c != NULL && c->session != NULL)
|
|
||||||
already_attached = 1;
|
|
||||||
|
|
||||||
/* Get the new session working directory. */
|
|
||||||
if (args_has(args, 'c')) {
|
|
||||||
cwd = args_get(args, 'c');
|
|
||||||
to_free = cwd = format_single(item, cwd, c, NULL, NULL, NULL);
|
|
||||||
} else if (c != NULL && c->session == NULL && c->cwd != NULL)
|
|
||||||
cwd = c->cwd;
|
|
||||||
else
|
|
||||||
cwd = ".";
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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(item->client)) {
|
/* Set -d if no client. */
|
||||||
cmdq_error(item, "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(item, "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
|
||||||
|
cwd = options_get_string(&global_s_options, "default-path");
|
||||||
|
|
||||||
/* 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) {
|
||||||
|
sx = ctx->cmdclient->tty.sx;
|
||||||
|
sy = ctx->cmdclient->tty.sy;
|
||||||
|
} else {
|
||||||
|
sx = ctx->curclient->tty.sx;
|
||||||
|
sy = ctx->curclient->tty.sy;
|
||||||
}
|
}
|
||||||
if (detached && args_has(args, 'x')) {
|
if (sy > 0 && options_get_number(&global_s_options, "status"))
|
||||||
sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "width %s", errstr);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (detached && args_has(args, 'y')) {
|
|
||||||
sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "height %s", errstr);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sy > 0 && options_get_number(global_s_options, "status"))
|
|
||||||
sy--;
|
sy--;
|
||||||
if (sx == 0)
|
if (sx == 0)
|
||||||
sx = 1;
|
sx = 1;
|
||||||
@@ -214,124 +205,87 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
sy = 1;
|
sy = 1;
|
||||||
|
|
||||||
/* Figure out the command for the new window. */
|
/* Figure out the command for the new window. */
|
||||||
argc = -1;
|
if (data->cmd != NULL)
|
||||||
argv = NULL;
|
cmd = data->cmd;
|
||||||
if (!args_has(args, 't') && args->argc != 0) {
|
|
||||||
argc = args->argc;
|
|
||||||
argv = args->argv;
|
|
||||||
} else if (sg == NULL && groupwith == NULL) {
|
|
||||||
cmd = options_get_string(global_s_options, "default-command");
|
|
||||||
if (cmd != NULL && *cmd != '\0') {
|
|
||||||
argc = 1;
|
|
||||||
argv = (char **)&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. */
|
||||||
env = environ_create();
|
environ_init(&env);
|
||||||
if (c != NULL && !args_has(args, 'E'))
|
update = options_get_string(&global_s_options, "update-environment");
|
||||||
environ_update(global_s_options, c->environ, env);
|
if (ctx->cmdclient != NULL)
|
||||||
|
environ_update(update, &ctx->cmdclient->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(prefix, newname, argc, argv, path, cwd, env, tiop,
|
s = session_create(
|
||||||
idx, sx, sy, &cause);
|
data->newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
||||||
environ_free(env);
|
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
cmdq_error(item, "create session failed: %s", cause);
|
ctx->error(ctx, "create session failed: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
goto error;
|
return (-1);
|
||||||
}
|
}
|
||||||
|
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 (data->winname != NULL) {
|
||||||
w = s->curw->window;
|
w = s->curw->window;
|
||||||
window_set_name(w, args_get(args, 'n'));
|
|
||||||
options_set_number(w->options, "automatic-rename", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
xfree(w->name);
|
||||||
* If a target session is given, this is to be part of a session group,
|
w->name = xstrdup(data->winname);
|
||||||
* so add it to the group and synchronize.
|
|
||||||
*/
|
options_set_number(&w->options, "automatic-rename", 0);
|
||||||
if (group != NULL) {
|
|
||||||
if (sg == NULL) {
|
|
||||||
if (groupwith != NULL) {
|
|
||||||
sg = session_group_new(groupwith->name);
|
|
||||||
session_group_add(sg, groupwith);
|
|
||||||
} else
|
|
||||||
sg = session_group_new(group);
|
|
||||||
}
|
|
||||||
session_group_add(sg, s);
|
|
||||||
session_group_synchronize_to(s);
|
|
||||||
session_select(s, RB_MIN(winlinks, &s->windows)->idx);
|
|
||||||
}
|
}
|
||||||
notify_session("session-created", s);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the client to the new session. If a command client exists, it is
|
* Set the client to the new session. If a command client exists, it is
|
||||||
* 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) {
|
||||||
if (~c->flags & CLIENT_CONTROL)
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
ctx->cmdclient->session = s;
|
||||||
} else if (c->session != NULL)
|
server_redraw_client(ctx->cmdclient);
|
||||||
c->last_session = c->session;
|
} else {
|
||||||
c->session = s;
|
ctx->curclient->session = s;
|
||||||
if (~item->shared->flags & CMDQ_SHARED_REPEAT)
|
server_redraw_client(ctx->curclient);
|
||||||
server_client_set_key_table(c, NULL);
|
}
|
||||||
status_timer_start(c);
|
|
||||||
notify_client("client-session-changed", c);
|
|
||||||
session_update_activity(s, NULL);
|
|
||||||
gettimeofday(&s->last_attached_time, NULL);
|
|
||||||
server_redraw_client(c);
|
|
||||||
}
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
server_update_socket();
|
|
||||||
|
|
||||||
/*
|
return (!detached); /* 1 means don't tell command client to exit */
|
||||||
* If there are still configuration file errors to display, put the new
|
}
|
||||||
* session's current window into more mode and display them now.
|
|
||||||
*/
|
void
|
||||||
if (cfg_finished)
|
cmd_new_session_free(struct cmd *self)
|
||||||
cfg_show_causes(s);
|
{
|
||||||
|
struct cmd_new_session_data *data = self->data;
|
||||||
/* Print if requested. */
|
|
||||||
if (args_has(args, 'P')) {
|
if (data->newname != NULL)
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
xfree(data->newname);
|
||||||
template = NEW_SESSION_TEMPLATE;
|
if (data->winname != NULL)
|
||||||
cp = format_single(item, template, c, s, NULL, NULL);
|
xfree(data->winname);
|
||||||
cmdq_print(item, "%s", cp);
|
if (data->cmd != NULL)
|
||||||
free(cp);
|
xfree(data->cmd);
|
||||||
}
|
xfree(data);
|
||||||
|
}
|
||||||
if (!detached) {
|
|
||||||
c->flags |= CLIENT_ATTACHED;
|
size_t
|
||||||
cmd_find_from_session(&item->shared->current, s);
|
cmd_new_session_print(struct cmd *self, char *buf, size_t len)
|
||||||
}
|
{
|
||||||
|
struct cmd_new_session_data *data = self->data;
|
||||||
if (to_free != NULL)
|
size_t off = 0;
|
||||||
free((void *)to_free);
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
cmd_find_from_session(&fs, s);
|
if (data == NULL)
|
||||||
hooks_insert(s->hooks, item, &fs, "after-new-session");
|
return (off);
|
||||||
|
if (off < len && data->flag_detached)
|
||||||
return (CMD_RETURN_NORMAL);
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && data->newname != NULL)
|
||||||
error:
|
off += cmd_prarg(buf + off, len - off, " -s ", data->newname);
|
||||||
if (to_free != NULL)
|
if (off < len && data->winname != NULL)
|
||||||
free((void *)to_free);
|
off += cmd_prarg(buf + off, len - off, " -n ", data->winname);
|
||||||
return (CMD_RETURN_ERROR);
|
if (off < len && data->cmd != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
265
cmd-new-window.c
265
cmd-new-window.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-new-window.c,v 1.37 2009-08-16 19:16:27 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,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,132 +26,181 @@
|
|||||||
* 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);
|
||||||
|
|
||||||
static enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmdq_item *);
|
struct cmd_new_window_data {
|
||||||
|
char *target;
|
||||||
const struct cmd_entry cmd_new_window_entry = {
|
char *name;
|
||||||
.name = "new-window",
|
char *cmd;
|
||||||
.alias = "neww",
|
int flag_detached;
|
||||||
|
int flag_kill;
|
||||||
.args = { "ac:dF:kn:Pt:", 0, -1 },
|
|
||||||
.usage = "[-adkP] [-c start-directory] [-F format] [-n window-name] "
|
|
||||||
CMD_TARGET_WINDOW_USAGE " [command]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_new_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
const struct cmd_entry cmd_new_window_entry = {
|
||||||
cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
"new-window", "neww",
|
||||||
|
"[-dk] [-n window-name] [-t target-window] [command]",
|
||||||
|
0, 0,
|
||||||
|
cmd_new_window_init,
|
||||||
|
cmd_new_window_parse,
|
||||||
|
cmd_new_window_exec,
|
||||||
|
cmd_new_window_free,
|
||||||
|
cmd_new_window_print
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_new_window_init(struct cmd *self, unused int arg)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_new_window_data *data;
|
||||||
struct cmd_find_state *current = &item->shared->current;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
int idx = item->target.idx;
|
|
||||||
const char *cmd, *path, *template, *cwd, *to_free;
|
|
||||||
char **argv, *cause, *cp;
|
|
||||||
int argc, detached;
|
|
||||||
struct environ_entry *envent;
|
|
||||||
struct cmd_find_state fs;
|
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
self->data = data = xmalloc(sizeof *data);
|
||||||
if ((idx = winlink_shuffle_up(s, wl)) == -1) {
|
data->target = NULL;
|
||||||
cmdq_error(item, "no free window indexes");
|
data->name = NULL;
|
||||||
return (CMD_RETURN_ERROR);
|
data->cmd = NULL;
|
||||||
|
data->flag_detached = 0;
|
||||||
|
data->flag_kill = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_new_window_data *data;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
self->entry->init(self, 0);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "dkt:n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
detached = args_has(args, 'd');
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 0 && argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
if (args->argc == 0) {
|
if (argc == 1)
|
||||||
cmd = options_get_string(s->options, "default-command");
|
data->cmd = xstrdup(argv[0]);
|
||||||
if (cmd != NULL && *cmd != '\0') {
|
|
||||||
argc = 1;
|
|
||||||
argv = (char **)&cmd;
|
|
||||||
} else {
|
|
||||||
argc = 0;
|
|
||||||
argv = NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
argc = args->argc;
|
|
||||||
argv = args->argv;
|
|
||||||
}
|
|
||||||
|
|
||||||
path = NULL;
|
return (0);
|
||||||
if (item->client != NULL && item->client->session == NULL)
|
|
||||||
envent = environ_find(item->client->environ, "PATH");
|
|
||||||
else
|
|
||||||
envent = environ_find(s->environ, "PATH");
|
|
||||||
if (envent != NULL)
|
|
||||||
path = envent->value;
|
|
||||||
|
|
||||||
to_free = NULL;
|
usage:
|
||||||
if (args_has(args, 'c')) {
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
cwd = args_get(args, 'c');
|
|
||||||
to_free = cwd = format_single(item, cwd, c, s, NULL, NULL);
|
self->entry->free(self);
|
||||||
} else if (item->client != NULL && item->client->session == NULL)
|
return (-1);
|
||||||
cwd = item->client->cwd;
|
}
|
||||||
else
|
|
||||||
cwd = s->cwd;
|
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;
|
||||||
|
|
||||||
|
if (data == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if ((idx = cmd_find_index(ctx, data->target, &s)) == -2)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
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) {
|
||||||
/*
|
if (data->flag_kill) {
|
||||||
* Can't use session_detach as it will destroy session if this
|
/*
|
||||||
* makes it empty.
|
* Can't use session_detach as it will destroy session
|
||||||
*/
|
* if this makes it empty.
|
||||||
notify_session_window("window-unlinked", s, wl->window);
|
*/
|
||||||
wl->flags &= ~WINLINK_ALERTFLAGS;
|
session_alert_cancel(s, wl);
|
||||||
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");
|
||||||
|
if (ctx->cmdclient == NULL || ctx->cmdclient->cwd == NULL)
|
||||||
|
cwd = options_get_string(&s->options, "default-path");
|
||||||
|
else
|
||||||
|
cwd = ctx->cmdclient->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(item, "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);
|
||||||
cmd_find_from_winlink(current, wl);
|
server_redraw_session(s);
|
||||||
server_redraw_session_group(s);
|
|
||||||
} else
|
} else
|
||||||
server_status_session_group(s);
|
server_status_session(s);
|
||||||
|
|
||||||
if (args_has(args, 'P')) {
|
return (0);
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
}
|
||||||
template = NEW_WINDOW_TEMPLATE;
|
|
||||||
cp = format_single(item, template, c, s, wl, NULL);
|
void
|
||||||
cmdq_print(item, "%s", cp);
|
cmd_new_window_free(struct cmd *self)
|
||||||
free(cp);
|
{
|
||||||
}
|
struct cmd_new_window_data *data = self->data;
|
||||||
|
|
||||||
if (to_free != NULL)
|
if (data->target != NULL)
|
||||||
free((void *)to_free);
|
xfree(data->target);
|
||||||
|
if (data->name != NULL)
|
||||||
cmd_find_from_winlink(&fs, wl);
|
xfree(data->name);
|
||||||
hooks_insert(s->hooks, item, &fs, "after-new-window");
|
if (data->cmd != NULL)
|
||||||
|
xfree(data->cmd);
|
||||||
return (CMD_RETURN_NORMAL);
|
xfree(data);
|
||||||
|
}
|
||||||
error:
|
|
||||||
if (to_free != NULL)
|
size_t
|
||||||
free((void *)to_free);
|
cmd_new_window_print(struct cmd *self, char *buf, size_t len)
|
||||||
return (CMD_RETURN_ERROR);
|
{
|
||||||
|
struct cmd_new_window_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->flag_detached)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->name != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -n ", data->name);
|
||||||
|
if (off < len && data->cmd != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
54
cmd-next-layout.c
Normal file
54
cmd-next-layout.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* $Id: cmd-next-layout.c,v 1.5 2009-07-28 22:12: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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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, 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.20 2009-07-28 22:12:16 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, CMD_CHFLAG('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))
|
||||||
|
data->chflags |= CMD_CHFLAG('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 (data->chflags & CMD_CHFLAG('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,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-paste-buffer.c,v 1.20 2009-09-07 23:48:54 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,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,81 +26,75 @@
|
|||||||
* Paste paste buffer if present.
|
* Paste paste buffer if present.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmdq_item *);
|
int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_paste_buffer_lf2cr(struct buffer *, const char *, size_t);
|
||||||
|
|
||||||
const struct cmd_entry cmd_paste_buffer_entry = {
|
const struct cmd_entry cmd_paste_buffer_entry = {
|
||||||
.name = "paste-buffer",
|
"paste-buffer", "pasteb",
|
||||||
.alias = "pasteb",
|
"[-dr] " CMD_BUFFER_WINDOW_USAGE,
|
||||||
|
0, CMD_CHFLAG('d')|CMD_CHFLAG('r'),
|
||||||
.args = { "db:prs:t:", 0, 0 },
|
cmd_buffer_init,
|
||||||
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
|
cmd_buffer_parse,
|
||||||
CMD_TARGET_PANE_USAGE,
|
cmd_paste_buffer_exec,
|
||||||
|
cmd_buffer_free,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_buffer_print
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_paste_buffer_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct window_pane *wp = item->target.wp;
|
struct winlink *wl;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct session *s;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
const char *sepstr, *bufname, *bufdata, *bufend, *line;
|
|
||||||
size_t seplen, bufsize;
|
|
||||||
int bracket = args_has(args, 'p');
|
|
||||||
|
|
||||||
bufname = NULL;
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
if (args_has(args, 'b'))
|
return (-1);
|
||||||
bufname = args_get(args, 'b');
|
wp = wl->window->active;
|
||||||
|
|
||||||
if (bufname == NULL)
|
if (data->buffer == -1)
|
||||||
pb = paste_get_top(NULL);
|
pb = paste_get_top(&s->buffers);
|
||||||
else {
|
else {
|
||||||
pb = paste_get_name(bufname);
|
if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
|
||||||
if (pb == NULL) {
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
cmdq_error(item, "no buffer %s", bufname);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pb != NULL && ~wp->flags & PANE_INPUTOFF) {
|
if (pb != NULL && *pb->data != '\0') {
|
||||||
sepstr = args_get(args, 's');
|
/* -r means raw data without LF->CR conversion. */
|
||||||
if (sepstr == NULL) {
|
if (data->chflags & CMD_CHFLAG('r'))
|
||||||
if (args_has(args, 'r'))
|
buffer_write(wp->out, pb->data, pb->size);
|
||||||
sepstr = "\n";
|
else
|
||||||
else
|
cmd_paste_buffer_lf2cr(wp->out, pb->data, pb->size);
|
||||||
sepstr = "\r";
|
|
||||||
}
|
|
||||||
seplen = strlen(sepstr);
|
|
||||||
|
|
||||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
|
||||||
bufferevent_write(wp->event, "\033[200~", 6);
|
|
||||||
|
|
||||||
bufdata = paste_buffer_data(pb, &bufsize);
|
|
||||||
bufend = bufdata + bufsize;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
line = memchr(bufdata, '\n', bufend - bufdata);
|
|
||||||
if (line == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
bufferevent_write(wp->event, bufdata, line - bufdata);
|
|
||||||
bufferevent_write(wp->event, sepstr, seplen);
|
|
||||||
|
|
||||||
bufdata = line + 1;
|
|
||||||
}
|
|
||||||
if (bufdata != bufend)
|
|
||||||
bufferevent_write(wp->event, bufdata, bufend - bufdata);
|
|
||||||
|
|
||||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
|
||||||
bufferevent_write(wp->event, "\033[201~", 6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pb != NULL && args_has(args, 'd'))
|
/* Delete the buffer if -d. */
|
||||||
paste_free(pb);
|
if (data->chflags & CMD_CHFLAG('d')) {
|
||||||
|
if (data->buffer == -1)
|
||||||
|
paste_free_top(&s->buffers);
|
||||||
|
else
|
||||||
|
paste_free_index(&s->buffers, data->buffer);
|
||||||
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add bytes to a buffer but change every '\n' to '\r'. */
|
||||||
|
void
|
||||||
|
cmd_paste_buffer_lf2cr(struct buffer *b, const char *data, size_t size)
|
||||||
|
{
|
||||||
|
const char *end = data + size;
|
||||||
|
const char *lf;
|
||||||
|
|
||||||
|
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
||||||
|
if (lf != data)
|
||||||
|
buffer_write(b, data, lf - data);
|
||||||
|
buffer_write8(b, '\r');
|
||||||
|
data = lf + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end != data)
|
||||||
|
buffer_write(b, data, end - data);
|
||||||
}
|
}
|
||||||
|
|||||||
153
cmd-pipe-pane.c
153
cmd-pipe-pane.c
@@ -1,153 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
*
|
|
||||||
* 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/socket.h>
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Open pipe to redirect pane output. If already open, close first.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
static void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_pipe_pane_entry = {
|
|
||||||
.name = "pipe-pane",
|
|
||||||
.alias = "pipep",
|
|
||||||
|
|
||||||
.args = { "ot:", 0, 1 },
|
|
||||||
.usage = "[-o] " CMD_TARGET_PANE_USAGE " [command]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_pipe_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
char *cmd;
|
|
||||||
int old_fd, pipe_fd[2], null_fd;
|
|
||||||
struct format_tree *ft;
|
|
||||||
|
|
||||||
/* Destroy the old pipe. */
|
|
||||||
old_fd = wp->pipe_fd;
|
|
||||||
if (wp->pipe_fd != -1) {
|
|
||||||
bufferevent_free(wp->pipe_event);
|
|
||||||
close(wp->pipe_fd);
|
|
||||||
wp->pipe_fd = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If no pipe command, that is enough. */
|
|
||||||
if (args->argc == 0 || *args->argv[0] == '\0')
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* With -o, only open the new pipe if there was no previous one. This
|
|
||||||
* allows a pipe to be toggled with a single key, for example:
|
|
||||||
*
|
|
||||||
* bind ^p pipep -o 'cat >>~/output'
|
|
||||||
*/
|
|
||||||
if (args_has(self->args, 'o') && old_fd != -1)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
/* Open the new pipe. */
|
|
||||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
|
||||||
cmdq_error(item, "socketpair error: %s", strerror(errno));
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Expand the command. */
|
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
|
||||||
format_defaults(ft, c, s, wl, wp);
|
|
||||||
cmd = format_expand_time(ft, args->argv[0], time(NULL));
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
/* Fork the child. */
|
|
||||||
switch (fork()) {
|
|
||||||
case -1:
|
|
||||||
cmdq_error(item, "fork error: %s", strerror(errno));
|
|
||||||
|
|
||||||
free(cmd);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
case 0:
|
|
||||||
/* Child process. */
|
|
||||||
close(pipe_fd[0]);
|
|
||||||
clear_signals(1);
|
|
||||||
|
|
||||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
|
||||||
_exit(1);
|
|
||||||
if (pipe_fd[1] != STDIN_FILENO)
|
|
||||||
close(pipe_fd[1]);
|
|
||||||
|
|
||||||
null_fd = open(_PATH_DEVNULL, O_WRONLY, 0);
|
|
||||||
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
|
||||||
_exit(1);
|
|
||||||
if (dup2(null_fd, STDERR_FILENO) == -1)
|
|
||||||
_exit(1);
|
|
||||||
if (null_fd != STDOUT_FILENO && null_fd != STDERR_FILENO)
|
|
||||||
close(null_fd);
|
|
||||||
|
|
||||||
closefrom(STDERR_FILENO + 1);
|
|
||||||
|
|
||||||
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
|
|
||||||
_exit(1);
|
|
||||||
default:
|
|
||||||
/* Parent process. */
|
|
||||||
close(pipe_fd[1]);
|
|
||||||
|
|
||||||
wp->pipe_fd = pipe_fd[0];
|
|
||||||
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
|
|
||||||
|
|
||||||
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
|
||||||
NULL, NULL, cmd_pipe_pane_error_callback, wp);
|
|
||||||
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
|
||||||
|
|
||||||
setblocking(wp->pipe_fd, 0);
|
|
||||||
|
|
||||||
free(cmd);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_pipe_pane_error_callback(__unused struct bufferevent *bufev,
|
|
||||||
__unused short what, void *data)
|
|
||||||
{
|
|
||||||
struct window_pane *wp = data;
|
|
||||||
|
|
||||||
bufferevent_free(wp->pipe_event);
|
|
||||||
close(wp->pipe_fd);
|
|
||||||
wp->pipe_fd = -1;
|
|
||||||
}
|
|
||||||
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.4 2009-07-28 22:12: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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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, 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.20 2009-07-28 22:12:16 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, CMD_CHFLAG('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))
|
||||||
|
data->chflags |= CMD_CHFLAG('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 (data->chflags & CMD_CHFLAG('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);
|
||||||
|
}
|
||||||
474
cmd-queue.c
474
cmd-queue.c
@@ -1,474 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
*
|
|
||||||
* 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"
|
|
||||||
|
|
||||||
/* Global command queue. */
|
|
||||||
static struct cmdq_list global_queue = TAILQ_HEAD_INITIALIZER(global_queue);
|
|
||||||
|
|
||||||
/* Get command queue name. */
|
|
||||||
static const char *
|
|
||||||
cmdq_name(struct client *c)
|
|
||||||
{
|
|
||||||
static char s[32];
|
|
||||||
|
|
||||||
if (c == NULL)
|
|
||||||
return ("<global>");
|
|
||||||
xsnprintf(s, sizeof s, "<%p>", c);
|
|
||||||
return (s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get command queue from client. */
|
|
||||||
static struct cmdq_list *
|
|
||||||
cmdq_get(struct client *c)
|
|
||||||
{
|
|
||||||
if (c == NULL)
|
|
||||||
return (&global_queue);
|
|
||||||
return (&c->queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Append an item. */
|
|
||||||
void
|
|
||||||
cmdq_append(struct client *c, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct cmdq_list *queue = cmdq_get(c);
|
|
||||||
struct cmdq_item *next;
|
|
||||||
|
|
||||||
do {
|
|
||||||
next = item->next;
|
|
||||||
item->next = NULL;
|
|
||||||
|
|
||||||
if (c != NULL)
|
|
||||||
c->references++;
|
|
||||||
item->client = c;
|
|
||||||
|
|
||||||
item->queue = queue;
|
|
||||||
TAILQ_INSERT_TAIL(queue, item, entry);
|
|
||||||
|
|
||||||
item = next;
|
|
||||||
} while (item != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Insert an item. */
|
|
||||||
void
|
|
||||||
cmdq_insert_after(struct cmdq_item *after, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct client *c = after->client;
|
|
||||||
struct cmdq_list *queue = after->queue;
|
|
||||||
struct cmdq_item *next;
|
|
||||||
|
|
||||||
do {
|
|
||||||
next = item->next;
|
|
||||||
item->next = NULL;
|
|
||||||
|
|
||||||
if (c != NULL)
|
|
||||||
c->references++;
|
|
||||||
item->client = c;
|
|
||||||
|
|
||||||
item->queue = queue;
|
|
||||||
if (after->next != NULL)
|
|
||||||
TAILQ_INSERT_AFTER(queue, after->next, item, entry);
|
|
||||||
else
|
|
||||||
TAILQ_INSERT_AFTER(queue, after, item, entry);
|
|
||||||
after->next = item;
|
|
||||||
|
|
||||||
item = next;
|
|
||||||
} while (item != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove an item. */
|
|
||||||
static void
|
|
||||||
cmdq_remove(struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
if (item->shared != NULL && --item->shared->references == 0) {
|
|
||||||
if (item->shared->formats != NULL)
|
|
||||||
format_free(item->shared->formats);
|
|
||||||
free(item->shared);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item->client != NULL)
|
|
||||||
server_client_unref(item->client);
|
|
||||||
|
|
||||||
if (item->type == CMDQ_COMMAND)
|
|
||||||
cmd_list_free(item->cmdlist);
|
|
||||||
|
|
||||||
TAILQ_REMOVE(item->queue, item, entry);
|
|
||||||
|
|
||||||
free((void *)item->name);
|
|
||||||
free(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set command group. */
|
|
||||||
static u_int
|
|
||||||
cmdq_next_group(void)
|
|
||||||
{
|
|
||||||
static u_int group;
|
|
||||||
|
|
||||||
return (++group);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove all subsequent items that match this item's group. */
|
|
||||||
static void
|
|
||||||
cmdq_remove_group(struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct cmdq_item *this, *next;
|
|
||||||
|
|
||||||
this = TAILQ_NEXT(item, entry);
|
|
||||||
while (this != NULL) {
|
|
||||||
next = TAILQ_NEXT(this, entry);
|
|
||||||
if (this->group == item->group)
|
|
||||||
cmdq_remove(this);
|
|
||||||
this = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get a command for the command queue. */
|
|
||||||
struct cmdq_item *
|
|
||||||
cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
|
|
||||||
struct mouse_event *m, int flags)
|
|
||||||
{
|
|
||||||
struct cmdq_item *item, *first = NULL, *last = NULL;
|
|
||||||
struct cmd *cmd;
|
|
||||||
u_int group = cmdq_next_group();
|
|
||||||
char *tmp;
|
|
||||||
struct cmdq_shared *shared;
|
|
||||||
|
|
||||||
shared = xcalloc(1, sizeof *shared);
|
|
||||||
if (current != NULL)
|
|
||||||
cmd_find_copy_state(&shared->current, current);
|
|
||||||
else
|
|
||||||
cmd_find_clear_state(&shared->current, 0);
|
|
||||||
if (m != NULL)
|
|
||||||
memcpy(&shared->mouse, m, sizeof shared->mouse);
|
|
||||||
|
|
||||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
|
||||||
xasprintf(&tmp, "command[%s]", cmd->entry->name);
|
|
||||||
|
|
||||||
item = xcalloc(1, sizeof *item);
|
|
||||||
item->name = tmp;
|
|
||||||
item->type = CMDQ_COMMAND;
|
|
||||||
|
|
||||||
item->group = group;
|
|
||||||
item->flags = flags;
|
|
||||||
|
|
||||||
item->shared = shared;
|
|
||||||
item->cmdlist = cmdlist;
|
|
||||||
item->cmd = cmd;
|
|
||||||
|
|
||||||
shared->references++;
|
|
||||||
cmdlist->references++;
|
|
||||||
|
|
||||||
if (first == NULL)
|
|
||||||
first = item;
|
|
||||||
if (last != NULL)
|
|
||||||
last->next = item;
|
|
||||||
last = item;
|
|
||||||
}
|
|
||||||
return (first);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fill in flag for a command. */
|
|
||||||
static enum cmd_retval
|
|
||||||
cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs,
|
|
||||||
const struct cmd_entry_flag *flag)
|
|
||||||
{
|
|
||||||
const char *value;
|
|
||||||
|
|
||||||
if (flag->flag == 0) {
|
|
||||||
cmd_find_clear_state(fs, 0);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
value = args_get(item->cmd->args, flag->flag);
|
|
||||||
if (cmd_find_target(fs, item, value, flag->type, flag->flags) != 0) {
|
|
||||||
cmd_find_clear_state(fs, 0);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fire command on command queue. */
|
|
||||||
static enum cmd_retval
|
|
||||||
cmdq_fire_command(struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct client *c = item->client;
|
|
||||||
struct cmd *cmd = item->cmd;
|
|
||||||
const struct cmd_entry *entry = cmd->entry;
|
|
||||||
enum cmd_retval retval;
|
|
||||||
struct cmd_find_state *fsp, fs;
|
|
||||||
int flags;
|
|
||||||
|
|
||||||
flags = !!(cmd->flags & CMD_CONTROL);
|
|
||||||
cmdq_guard(item, "begin", flags);
|
|
||||||
|
|
||||||
if (item->client == NULL)
|
|
||||||
item->client = cmd_find_client(item, NULL, 1);
|
|
||||||
retval = cmdq_find_flag(item, &item->source, &entry->source);
|
|
||||||
if (retval == CMD_RETURN_ERROR)
|
|
||||||
goto out;
|
|
||||||
retval = cmdq_find_flag(item, &item->target, &entry->target);
|
|
||||||
if (retval == CMD_RETURN_ERROR)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
retval = entry->exec(cmd, item);
|
|
||||||
if (retval == CMD_RETURN_ERROR)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (entry->flags & CMD_AFTERHOOK) {
|
|
||||||
if (cmd_find_valid_state(&item->target))
|
|
||||||
fsp = &item->target;
|
|
||||||
else if (cmd_find_valid_state(&item->shared->current))
|
|
||||||
fsp = &item->shared->current;
|
|
||||||
else if (cmd_find_from_client(&fs, item->client) == 0)
|
|
||||||
fsp = &fs;
|
|
||||||
else
|
|
||||||
goto out;
|
|
||||||
hooks_insert(fsp->s->hooks, item, fsp, "after-%s", entry->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
item->client = c;
|
|
||||||
if (retval == CMD_RETURN_ERROR)
|
|
||||||
cmdq_guard(item, "error", flags);
|
|
||||||
else
|
|
||||||
cmdq_guard(item, "end", flags);
|
|
||||||
return (retval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get a callback for the command queue. */
|
|
||||||
struct cmdq_item *
|
|
||||||
cmdq_get_callback1(const char *name, cmdq_cb cb, void *data)
|
|
||||||
{
|
|
||||||
struct cmdq_item *item;
|
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
xasprintf(&tmp, "callback[%s]", name);
|
|
||||||
|
|
||||||
item = xcalloc(1, sizeof *item);
|
|
||||||
item->name = tmp;
|
|
||||||
item->type = CMDQ_CALLBACK;
|
|
||||||
|
|
||||||
item->group = 0;
|
|
||||||
item->flags = 0;
|
|
||||||
|
|
||||||
item->cb = cb;
|
|
||||||
item->data = data;
|
|
||||||
|
|
||||||
return (item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fire callback on callback queue. */
|
|
||||||
static enum cmd_retval
|
|
||||||
cmdq_fire_callback(struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
return (item->cb(item, item->data));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add a format to command queue. */
|
|
||||||
void
|
|
||||||
cmdq_format(struct cmdq_item *item, const char *key, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
struct cmdq_shared *shared = item->shared;
|
|
||||||
va_list ap;
|
|
||||||
char *value;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
xvasprintf(&value, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (shared->formats == NULL)
|
|
||||||
shared->formats = format_create(NULL, NULL, FORMAT_NONE, 0);
|
|
||||||
format_add(shared->formats, key, "%s", value);
|
|
||||||
|
|
||||||
free(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Process next item on command queue. */
|
|
||||||
u_int
|
|
||||||
cmdq_next(struct client *c)
|
|
||||||
{
|
|
||||||
struct cmdq_list *queue = cmdq_get(c);
|
|
||||||
const char *name = cmdq_name(c);
|
|
||||||
struct cmdq_item *item;
|
|
||||||
enum cmd_retval retval;
|
|
||||||
u_int items = 0;
|
|
||||||
static u_int number;
|
|
||||||
|
|
||||||
if (TAILQ_EMPTY(queue)) {
|
|
||||||
log_debug("%s %s: empty", __func__, name);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
if (TAILQ_FIRST(queue)->flags & CMDQ_WAITING) {
|
|
||||||
log_debug("%s %s: waiting", __func__, name);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_debug("%s %s: enter", __func__, name);
|
|
||||||
for (;;) {
|
|
||||||
item = TAILQ_FIRST(queue);
|
|
||||||
if (item == NULL)
|
|
||||||
break;
|
|
||||||
log_debug("%s %s: %s (%d), flags %x", __func__, name,
|
|
||||||
item->name, item->type, item->flags);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Any item with the waiting flag set waits until an external
|
|
||||||
* event clears the flag (for example, a job - look at
|
|
||||||
* run-shell).
|
|
||||||
*/
|
|
||||||
if (item->flags & CMDQ_WAITING)
|
|
||||||
goto waiting;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Items are only fired once, once the fired flag is set, a
|
|
||||||
* waiting flag can only be cleared by an external event.
|
|
||||||
*/
|
|
||||||
if (~item->flags & CMDQ_FIRED) {
|
|
||||||
item->time = time(NULL);
|
|
||||||
item->number = ++number;
|
|
||||||
|
|
||||||
switch (item->type) {
|
|
||||||
case CMDQ_COMMAND:
|
|
||||||
retval = cmdq_fire_command(item);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If a command returns an error, remove any
|
|
||||||
* subsequent commands in the same group.
|
|
||||||
*/
|
|
||||||
if (retval == CMD_RETURN_ERROR)
|
|
||||||
cmdq_remove_group(item);
|
|
||||||
break;
|
|
||||||
case CMDQ_CALLBACK:
|
|
||||||
retval = cmdq_fire_callback(item);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
retval = CMD_RETURN_ERROR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
item->flags |= CMDQ_FIRED;
|
|
||||||
|
|
||||||
if (retval == CMD_RETURN_WAIT) {
|
|
||||||
item->flags |= CMDQ_WAITING;
|
|
||||||
goto waiting;
|
|
||||||
}
|
|
||||||
items++;
|
|
||||||
}
|
|
||||||
cmdq_remove(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_debug("%s %s: exit (empty)", __func__, name);
|
|
||||||
return (items);
|
|
||||||
|
|
||||||
waiting:
|
|
||||||
log_debug("%s %s: exit (wait)", __func__, name);
|
|
||||||
return (items);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print a guard line. */
|
|
||||||
void
|
|
||||||
cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
|
|
||||||
{
|
|
||||||
struct client *c = item->client;
|
|
||||||
|
|
||||||
if (c == NULL || !(c->flags & CLIENT_CONTROL))
|
|
||||||
return;
|
|
||||||
|
|
||||||
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard,
|
|
||||||
(long)item->time, item->number, flags);
|
|
||||||
server_client_push_stdout(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Show message from command. */
|
|
||||||
void
|
|
||||||
cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
struct client *c = item->client;
|
|
||||||
struct window *w;
|
|
||||||
va_list ap;
|
|
||||||
char *tmp, *msg;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
|
|
||||||
if (c == NULL)
|
|
||||||
/* nothing */;
|
|
||||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
|
||||||
if (~c->flags & CLIENT_UTF8) {
|
|
||||||
xvasprintf(&tmp, fmt, ap);
|
|
||||||
msg = utf8_sanitize(tmp);
|
|
||||||
free(tmp);
|
|
||||||
evbuffer_add(c->stdout_data, msg, strlen(msg));
|
|
||||||
free(msg);
|
|
||||||
} else
|
|
||||||
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
|
|
||||||
evbuffer_add(c->stdout_data, "\n", 1);
|
|
||||||
server_client_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 cmdq_item *item, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
struct client *c = item->client;
|
|
||||||
struct cmd *cmd = item->cmd;
|
|
||||||
va_list ap;
|
|
||||||
char *msg;
|
|
||||||
size_t msglen;
|
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
msglen = xvasprintf(&msg, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (c == NULL)
|
|
||||||
cfg_add_cause("%s:%u: %s", cmd->file, cmd->line, msg);
|
|
||||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
|
||||||
if (~c->flags & CLIENT_UTF8) {
|
|
||||||
tmp = msg;
|
|
||||||
msg = utf8_sanitize(tmp);
|
|
||||||
free(tmp);
|
|
||||||
msglen = strlen(msg);
|
|
||||||
}
|
|
||||||
evbuffer_add(c->stderr_data, msg, msglen);
|
|
||||||
evbuffer_add(c->stderr_data, "\n", 1);
|
|
||||||
server_client_push_stderr(c);
|
|
||||||
c->retval = 1;
|
|
||||||
} else {
|
|
||||||
*msg = toupper((u_char) *msg);
|
|
||||||
status_message_set(c, "%s", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(msg);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-refresh-client.c,v 1.10 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -24,58 +24,29 @@
|
|||||||
* Refresh client.
|
* Refresh client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_refresh_client_exec(struct cmd *,
|
int cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_refresh_client_entry = {
|
const struct cmd_entry cmd_refresh_client_entry = {
|
||||||
.name = "refresh-client",
|
"refresh-client", "refresh",
|
||||||
.alias = "refresh",
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0, 0,
|
||||||
.args = { "C:St:", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_refresh_client_exec,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_target_free,
|
||||||
.exec = cmd_refresh_client_exec
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
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(item, 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(item, "missing size");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (sscanf(size, "%u,%u", &w, &h) != 2) {
|
|
||||||
cmdq_error(item, "bad size argument");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (w < PANE_MINIMUM || w > 5000 ||
|
|
||||||
h < PANE_MINIMUM || h > 5000) {
|
|
||||||
cmdq_error(item, "size too small or too big");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (!(c->flags & CLIENT_CONTROL)) {
|
|
||||||
cmdq_error(item, "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,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-rename-session.c,v 1.18 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -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,49 +26,32 @@
|
|||||||
* Change session name.
|
* Change session name.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_rename_session_exec(struct cmd *,
|
int cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_rename_session_entry = {
|
const struct cmd_entry cmd_rename_session_entry = {
|
||||||
.name = "rename-session",
|
"rename-session", "rename",
|
||||||
.alias = "rename",
|
CMD_TARGET_SESSION_USAGE " new-name",
|
||||||
|
CMD_ARG1, 0,
|
||||||
.args = { "t:", 1, 1 },
|
cmd_target_init,
|
||||||
.usage = CMD_TARGET_SESSION_USAGE " new-name",
|
cmd_target_parse,
|
||||||
|
cmd_rename_session_exec,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_rename_session_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
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 = item->target.s;
|
struct session *s;
|
||||||
const char *newname;
|
|
||||||
|
|
||||||
newname = args->argv[0];
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
if (strcmp(newname, s->name) == 0)
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
if (!session_check_name(newname)) {
|
xfree(s->name);
|
||||||
cmdq_error(item, "bad session name: %s", newname);
|
s->name = xstrdup(data->arg);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (session_find(newname) != NULL) {
|
|
||||||
cmdq_error(item, "duplicate session: %s", newname);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
RB_REMOVE(sessions, &sessions, s);
|
|
||||||
free(s->name);
|
|
||||||
s->name = xstrdup(newname);
|
|
||||||
RB_INSERT(sessions, &sessions, s);
|
|
||||||
|
|
||||||
server_status_session(s);
|
server_status_session(s);
|
||||||
notify_session("session-renamed", s);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-rename-window.c,v 1.29 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -26,32 +26,34 @@
|
|||||||
* Rename a window.
|
* Rename a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_rename_window_exec(struct cmd *,
|
int cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_rename_window_entry = {
|
const struct cmd_entry cmd_rename_window_entry = {
|
||||||
.name = "rename-window",
|
"rename-window", "renamew",
|
||||||
.alias = "renamew",
|
CMD_TARGET_WINDOW_USAGE " new-name",
|
||||||
|
CMD_ARG1, 0,
|
||||||
.args = { "t:", 1, 1 },
|
cmd_target_init,
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE " new-name",
|
cmd_target_parse,
|
||||||
|
cmd_rename_window_exec,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_rename_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl = item->target.wl;
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
|
||||||
window_set_name(wl->window, args->argv[0]);
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
options_set_number(wl->window->options, "automatic-rename", 0);
|
return (-1);
|
||||||
|
|
||||||
server_status_window(wl->window);
|
xfree(wl->window->name);
|
||||||
|
wl->window->name = xstrdup(data->arg);
|
||||||
|
options_set_number(&wl->window->options, "automatic-rename", 0);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
server_status_session(s);
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-resize-pane.c,v 1.12 2009-07-30 20:45:20 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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
|
||||||
@@ -26,150 +26,88 @@
|
|||||||
* Increase or decrease pane size.
|
* Increase or decrease pane size.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmdq_item *);
|
void cmd_resize_pane_init(struct cmd *, int);
|
||||||
|
int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
static 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 = {
|
||||||
.name = "resize-pane",
|
"resize-pane", "resizep",
|
||||||
.alias = "resizep",
|
"[-DU] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||||
|
CMD_ARG01,
|
||||||
.args = { "DLMRt:Ux:y:Z", 0, 1 },
|
CMD_CHFLAG('D')|CMD_CHFLAG('L')|CMD_CHFLAG('R')|CMD_CHFLAG('U'),
|
||||||
.usage = "[-DLMRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
|
cmd_resize_pane_init,
|
||||||
"[adjustment]",
|
cmd_target_parse,
|
||||||
|
cmd_resize_pane_exec,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_resize_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
void
|
||||||
cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_resize_pane_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data;
|
||||||
struct cmdq_shared *shared = item->shared;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
cmd_target_init(self, key);
|
||||||
struct winlink *wl = item->target.wl;
|
data = self->data;
|
||||||
struct window *w = wl->window;
|
|
||||||
struct client *c = item->client;
|
if (key == (KEYC_UP | KEYC_CTRL))
|
||||||
struct session *s = item->target.s;
|
data->chflags |= CMD_CHFLAG('U');
|
||||||
|
if (key == (KEYC_DOWN | KEYC_CTRL))
|
||||||
|
data->chflags |= CMD_CHFLAG('D');
|
||||||
|
if (key == (KEYC_LEFT | KEYC_CTRL))
|
||||||
|
data->chflags |= CMD_CHFLAG('L');
|
||||||
|
if (key == (KEYC_RIGHT | KEYC_CTRL))
|
||||||
|
data->chflags |= CMD_CHFLAG('R');
|
||||||
|
|
||||||
|
if (key == (KEYC_UP | KEYC_ESCAPE)) {
|
||||||
|
data->chflags |= CMD_CHFLAG('U');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
if (key == (KEYC_DOWN | KEYC_ESCAPE)) {
|
||||||
|
data->chflags |= CMD_CHFLAG('D');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
if (key == (KEYC_LEFT | KEYC_ESCAPE)) {
|
||||||
|
data->chflags |= CMD_CHFLAG('L');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
if (key == (KEYC_RIGHT | KEYC_ESCAPE)) {
|
||||||
|
data->chflags |= CMD_CHFLAG('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;
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
char *cause;
|
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(&shared->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, &shared->mouse);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'Z')) {
|
if (data->arg == NULL)
|
||||||
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(item, "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 (data->chflags & (CMD_CHFLAG('L')|CMD_CHFLAG('R'))) {
|
||||||
x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX,
|
if (data->chflags & CMD_CHFLAG('L'))
|
||||||
&cause);
|
adjust = -adjust;
|
||||||
if (cause != NULL) {
|
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
|
||||||
cmdq_error(item, "width %s", cause);
|
} else {
|
||||||
free(cause);
|
if (data->chflags & CMD_CHFLAG('U'))
|
||||||
return (CMD_RETURN_ERROR);
|
adjust = -adjust;
|
||||||
}
|
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
|
||||||
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(item, "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, 1);
|
|
||||||
else if (args_has(self->args, 'R'))
|
|
||||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust, 1);
|
|
||||||
else if (args_has(self->args, 'U'))
|
|
||||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust, 1);
|
|
||||||
else if (args_has(self->args, 'D'))
|
|
||||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust, 1);
|
|
||||||
server_redraw_window(wl->window);
|
server_redraw_window(wl->window);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
|
||||||
|
|
||||||
static 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, 0);
|
|
||||||
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, 0);
|
|
||||||
found = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found)
|
|
||||||
server_redraw_window(wl->window);
|
|
||||||
else
|
|
||||||
c->tty.mouse_drag_update = NULL;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_respawn_pane_entry = {
|
|
||||||
.name = "respawn-pane",
|
|
||||||
.alias = "respawnp",
|
|
||||||
|
|
||||||
.args = { "kt:", 0, -1 },
|
|
||||||
.usage = "[-k] " CMD_TARGET_PANE_USAGE " [command]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_respawn_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window *w = wl->window;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct environ *env;
|
|
||||||
const char *path;
|
|
||||||
char *cause;
|
|
||||||
u_int idx;
|
|
||||||
struct environ_entry *envent;
|
|
||||||
|
|
||||||
if (!args_has(self->args, 'k') && wp->fd != -1) {
|
|
||||||
if (window_pane_index(wp, &idx) != 0)
|
|
||||||
fatalx("index not found");
|
|
||||||
cmdq_error(item, "pane still active: %s:%d.%u",
|
|
||||||
s->name, wl->idx, idx);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
window_pane_reset_mode(wp);
|
|
||||||
screen_reinit(&wp->base);
|
|
||||||
input_init(wp);
|
|
||||||
|
|
||||||
path = NULL;
|
|
||||||
if (item->client != NULL && item->client->session == NULL)
|
|
||||||
envent = environ_find(item->client->environ, "PATH");
|
|
||||||
else
|
|
||||||
envent = environ_find(s->environ, "PATH");
|
|
||||||
if (envent != NULL)
|
|
||||||
path = envent->value;
|
|
||||||
|
|
||||||
env = environ_for_session(s, 0);
|
|
||||||
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env,
|
|
||||||
s->tio, &cause) != 0) {
|
|
||||||
cmdq_error(item, "respawn pane failed: %s", cause);
|
|
||||||
free(cause);
|
|
||||||
environ_free(env);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
environ_free(env);
|
|
||||||
|
|
||||||
wp->flags |= PANE_REDRAW;
|
|
||||||
server_status_window(w);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-respawn-window.c,v 1.22 2009-09-16 12:36:27 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 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,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,78 +26,69 @@
|
|||||||
* Respawn a window (restart the command). Kill existing if -k given.
|
* Respawn a window (restart the command). Kill existing if -k given.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_respawn_window_exec(struct cmd *,
|
int cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_respawn_window_entry = {
|
const struct cmd_entry cmd_respawn_window_entry = {
|
||||||
.name = "respawn-window",
|
"respawn-window", "respawnw",
|
||||||
.alias = "respawnw",
|
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
|
||||||
|
CMD_ARG01, CMD_CHFLAG('k'),
|
||||||
.args = { "kt:", 0, -1 },
|
cmd_target_init,
|
||||||
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
|
cmd_target_parse,
|
||||||
|
cmd_respawn_window_exec,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_respawn_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s = item->target.s;
|
struct winlink *wl;
|
||||||
struct winlink *wl = item->target.wl;
|
struct window *w;
|
||||||
struct window *w = wl->window;
|
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct environ *env;
|
struct session *s;
|
||||||
const char *path;
|
struct environ env;
|
||||||
char *cause;
|
char *cause;
|
||||||
struct environ_entry *envent;
|
|
||||||
|
|
||||||
if (!args_has(self->args, 'k')) {
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
|
if (!(data->chflags & CMD_CHFLAG('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(item, "window still active: %s:%d", s->name,
|
ctx->error(ctx,
|
||||||
wl->idx);
|
"window still active: %s:%d", s->name, wl->idx);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
environ_init(&env);
|
||||||
|
environ_copy(&global_environ, &env);
|
||||||
|
environ_copy(&s->environ, &env);
|
||||||
|
server_fill_environ(s, &env);
|
||||||
|
|
||||||
wp = TAILQ_FIRST(&w->panes);
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
layout_free(w);
|
layout_free(w);
|
||||||
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 (item->client != NULL && item->client->session == NULL)
|
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||||
envent = environ_find(item->client->environ, "PATH");
|
xfree(cause);
|
||||||
else
|
environ_free(&env);
|
||||||
envent = environ_find(s->environ, "PATH");
|
return (-1);
|
||||||
if (envent != NULL)
|
|
||||||
path = envent->value;
|
|
||||||
|
|
||||||
env = environ_for_session(s, 0);
|
|
||||||
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env,
|
|
||||||
s->tio, &cause) != 0) {
|
|
||||||
cmdq_error(item, "respawn window failed: %s", cause);
|
|
||||||
free(cause);
|
|
||||||
environ_free(env);
|
|
||||||
server_destroy_pane(wp, 0);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
environ_free(env);
|
layout_init(w);
|
||||||
layout_init(w, wp);
|
|
||||||
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);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
environ_free(&env);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-rotate-window.c,v 1.9 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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
|
||||||
@@ -24,35 +24,47 @@
|
|||||||
* Rotate the panes in a window.
|
* Rotate the panes in a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_rotate_window_exec(struct cmd *,
|
void cmd_rotate_window_init(struct cmd *, int);
|
||||||
struct cmdq_item *);
|
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 = {
|
||||||
.name = "rotate-window",
|
"rotate-window", "rotatew",
|
||||||
.alias = "rotatew",
|
"[-DU] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, CMD_CHFLAG('D')|CMD_CHFLAG('U'),
|
||||||
.args = { "Dt:U", 0, 0 },
|
cmd_rotate_window_init,
|
||||||
.usage = "[-DU] " CMD_TARGET_WINDOW_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_rotate_window_exec,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_rotate_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
void
|
||||||
cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_rotate_window_init(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct cmd_find_state *current = &item->shared->current;
|
struct cmd_target_data *data;
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window *w = wl->window;
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
if (key == ('o' | KEYC_ESCAPE))
|
||||||
|
data->chflags |= CMD_CHFLAG('D');
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct winlink *wl;
|
||||||
|
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;
|
||||||
|
|
||||||
server_unzoom_window(w);
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
if (args_has(self->args, 'D')) {
|
if (data->chflags & CMD_CHFLAG('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);
|
||||||
@@ -78,7 +90,6 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
|
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
|
||||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||||
window_set_active_pane(w, wp);
|
window_set_active_pane(w, wp);
|
||||||
cmd_find_from_winlink_pane(current, wl, wp);
|
|
||||||
server_redraw_window(w);
|
server_redraw_window(w);
|
||||||
} else {
|
} else {
|
||||||
wp = TAILQ_FIRST(&w->panes);
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
@@ -106,9 +117,8 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
|
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
|
||||||
wp = TAILQ_FIRST(&w->panes);
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
window_set_active_pane(w, wp);
|
window_set_active_pane(w, wp);
|
||||||
cmd_find_from_winlink_pane(current, wl, wp);
|
|
||||||
server_redraw_window(w);
|
server_redraw_window(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
170
cmd-run-shell.c
170
cmd-run-shell.c
@@ -1,170 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@openbsd.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 <sys/wait.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Runs a command without a window.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
static void cmd_run_shell_callback(struct job *);
|
|
||||||
static void cmd_run_shell_free(void *);
|
|
||||||
static void cmd_run_shell_print(struct job *, const char *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_run_shell_entry = {
|
|
||||||
.name = "run-shell",
|
|
||||||
.alias = "run",
|
|
||||||
|
|
||||||
.args = { "bt:", 1, 1 },
|
|
||||||
.usage = "[-b] " CMD_TARGET_PANE_USAGE " shell-command",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_run_shell_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cmd_run_shell_data {
|
|
||||||
char *cmd;
|
|
||||||
struct cmdq_item *item;
|
|
||||||
int wp_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_run_shell_print(struct job *job, const char *msg)
|
|
||||||
{
|
|
||||||
struct cmd_run_shell_data *cdata = job->data;
|
|
||||||
struct window_pane *wp = NULL;
|
|
||||||
struct cmd_find_state fs;
|
|
||||||
|
|
||||||
if (cdata->wp_id != -1)
|
|
||||||
wp = window_pane_find_by_id(cdata->wp_id);
|
|
||||||
if (wp == NULL) {
|
|
||||||
if (cdata->item != NULL) {
|
|
||||||
cmdq_print(cdata->item, "%s", msg);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (cmd_find_from_nothing(&fs) != 0)
|
|
||||||
return;
|
|
||||||
wp = fs.wp;
|
|
||||||
if (wp == NULL)
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct cmd_run_shell_data *cdata;
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
const char *cwd;
|
|
||||||
|
|
||||||
if (item->client != NULL && item->client->session == NULL)
|
|
||||||
cwd = item->client->cwd;
|
|
||||||
else if (s != NULL)
|
|
||||||
cwd = s->cwd;
|
|
||||||
else
|
|
||||||
cwd = NULL;
|
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
|
||||||
cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp);
|
|
||||||
|
|
||||||
if (args_has(args, 't') && wp != NULL)
|
|
||||||
cdata->wp_id = wp->id;
|
|
||||||
else
|
|
||||||
cdata->wp_id = -1;
|
|
||||||
|
|
||||||
if (!args_has(args, 'b'))
|
|
||||||
cdata->item = item;
|
|
||||||
|
|
||||||
job_run(cdata->cmd, s, cwd, NULL, cmd_run_shell_callback,
|
|
||||||
cmd_run_shell_free, cdata);
|
|
||||||
|
|
||||||
if (args_has(args, 'b'))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_run_shell_callback(struct job *job)
|
|
||||||
{
|
|
||||||
struct cmd_run_shell_data *cdata = job->data;
|
|
||||||
char *cmd = cdata->cmd, *msg, *line;
|
|
||||||
size_t size;
|
|
||||||
int retcode;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if ((line = evbuffer_readline(job->event->input)) != NULL) {
|
|
||||||
cmd_run_shell_print(job, line);
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
} while (line != NULL);
|
|
||||||
|
|
||||||
size = EVBUFFER_LENGTH(job->event->input);
|
|
||||||
if (size != 0) {
|
|
||||||
line = xmalloc(size + 1);
|
|
||||||
memcpy(line, EVBUFFER_DATA(job->event->input), size);
|
|
||||||
line[size] = '\0';
|
|
||||||
|
|
||||||
cmd_run_shell_print(job, line);
|
|
||||||
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = NULL;
|
|
||||||
if (WIFEXITED(job->status)) {
|
|
||||||
if ((retcode = WEXITSTATUS(job->status)) != 0)
|
|
||||||
xasprintf(&msg, "'%s' returned %d", cmd, retcode);
|
|
||||||
} else if (WIFSIGNALED(job->status)) {
|
|
||||||
retcode = WTERMSIG(job->status);
|
|
||||||
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
|
||||||
}
|
|
||||||
if (msg != NULL)
|
|
||||||
cmd_run_shell_print(job, msg);
|
|
||||||
free(msg);
|
|
||||||
|
|
||||||
if (cdata->item != NULL)
|
|
||||||
cdata->item->flags &= ~CMDQ_WAITING;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_run_shell_free(void *data)
|
|
||||||
{
|
|
||||||
struct cmd_run_shell_data *cdata = data;
|
|
||||||
|
|
||||||
free(cdata->cmd);
|
|
||||||
free(cdata);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-save-buffer.c,v 1.8 2009-09-07 23:48:54 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -20,136 +20,69 @@
|
|||||||
#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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmdq_item *);
|
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 = {
|
||||||
.name = "save-buffer",
|
"save-buffer", "saveb",
|
||||||
.alias = "saveb",
|
"[-a] " CMD_BUFFER_SESSION_USAGE " path",
|
||||||
|
CMD_ARG1, CMD_CHFLAG('a'),
|
||||||
.args = { "ab:", 1, 1 },
|
cmd_buffer_init,
|
||||||
.usage = "[-a] " CMD_BUFFER_USAGE " path",
|
cmd_buffer_parse,
|
||||||
|
cmd_save_buffer_exec,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_buffer_free,
|
||||||
.exec = cmd_save_buffer_exec
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_buffer_entry = {
|
int
|
||||||
.name = "show-buffer",
|
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "showb",
|
|
||||||
|
|
||||||
.args = { "b:", 0, 0 },
|
|
||||||
.usage = CMD_BUFFER_USAGE,
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_save_buffer_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct client *c = item->client;
|
struct session *s;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
const char *path, *bufname, *bufdata, *start, *end;
|
mode_t mask;
|
||||||
const char *flags;
|
|
||||||
char *msg, *file;
|
|
||||||
size_t size, used, msglen, bufsize;
|
|
||||||
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(item, "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(item, "no buffer %s", bufname);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bufdata = paste_buffer_data(pb, &bufsize);
|
|
||||||
|
|
||||||
if (self->entry == &cmd_show_buffer_entry)
|
mask = umask(S_IRWXG | S_IRWXO);
|
||||||
path = "-";
|
if (data->chflags & CMD_CHFLAG('a'))
|
||||||
|
f = fopen(data->arg, "ab");
|
||||||
else
|
else
|
||||||
path = args->argv[0];
|
f = fopen(data->arg, "wb");
|
||||||
if (strcmp(path, "-") == 0) {
|
|
||||||
if (c == NULL) {
|
|
||||||
cmdq_error(item, "can't write to stdout");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (c->session == NULL || (c->flags & CLIENT_CONTROL))
|
|
||||||
goto do_stdout;
|
|
||||||
goto do_print;
|
|
||||||
}
|
|
||||||
|
|
||||||
flags = "wb";
|
|
||||||
if (args_has(self->args, 'a'))
|
|
||||||
flags = "ab";
|
|
||||||
|
|
||||||
file = server_client_get_path(c, path);
|
|
||||||
f = fopen(file, flags);
|
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
cmdq_error(item, "%s: %s", file, strerror(errno));
|
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||||
free(file);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fwrite(bufdata, 1, bufsize, f) != bufsize) {
|
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
|
||||||
cmdq_error(item, "%s: write error", file);
|
ctx->error(ctx, "%s: fwrite error", data->arg);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(file);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(file);
|
umask(mask);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
do_stdout:
|
|
||||||
evbuffer_add(c->stdout_data, bufdata, bufsize);
|
|
||||||
server_client_push_stdout(c);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
do_print:
|
|
||||||
if (bufsize > (INT_MAX / 4) - 1) {
|
|
||||||
cmdq_error(item, "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
|
|
||||||
size = bufsize - used;
|
|
||||||
|
|
||||||
msglen = size * 4 + 1;
|
|
||||||
msg = xrealloc(msg, msglen);
|
|
||||||
|
|
||||||
strvisx(msg, start, size, VIS_OCTAL|VIS_TAB);
|
|
||||||
cmdq_print(item, "%s", msg);
|
|
||||||
|
|
||||||
used += size + (end != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(msg);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
70
cmd-scroll-mode.c
Normal file
70
cmd-scroll-mode.c
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/* $Id: cmd-scroll-mode.c,v 1.23 2009-08-20 11:37:46 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter scroll mode.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_scroll_mode_init(struct cmd *, int);
|
||||||
|
int cmd_scroll_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_scroll_mode_entry = {
|
||||||
|
"scroll-mode", NULL,
|
||||||
|
"[-u] " CMD_TARGET_PANE_USAGE,
|
||||||
|
0, CMD_CHFLAG('u'),
|
||||||
|
cmd_scroll_mode_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_scroll_mode_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_scroll_mode_init(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case KEYC_PPAGE:
|
||||||
|
data->chflags |= CMD_CHFLAG('u');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_scroll_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct window_pane *wp;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
window_pane_set_mode(wp, &window_scroll_mode);
|
||||||
|
if (wp->mode == &window_scroll_mode && data->chflags & CMD_CHFLAG('u'))
|
||||||
|
window_scroll_pageup(wp);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-select-layout.c,v 1.8 2009-07-28 23:04:29 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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,123 +18,71 @@
|
|||||||
|
|
||||||
#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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_select_layout_exec(struct cmd *,
|
void cmd_select_layout_init(struct cmd *, int);
|
||||||
struct cmdq_item *);
|
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 = {
|
||||||
.name = "select-layout",
|
"select-layout", "selectl",
|
||||||
.alias = "selectl",
|
CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
||||||
|
CMD_ARG01, 0,
|
||||||
.args = { "nopt:", 0, 1 },
|
cmd_select_layout_init,
|
||||||
.usage = "[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
cmd_target_parse,
|
||||||
|
cmd_select_layout_exec,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_select_layout_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_next_layout_entry = {
|
void
|
||||||
.name = "next-layout",
|
cmd_select_layout_init(struct cmd *self, int key)
|
||||||
.alias = "nextl",
|
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_select_layout_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_previous_layout_entry = {
|
|
||||||
.name = "previous-layout",
|
|
||||||
.alias = "prevl",
|
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_select_layout_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data;
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window *w;
|
|
||||||
const char *layoutname;
|
|
||||||
char *oldlayout;
|
|
||||||
int next, previous, layout;
|
|
||||||
|
|
||||||
w = wl->window;
|
cmd_target_init(self, key);
|
||||||
server_unzoom_window(w);
|
data = self->data;
|
||||||
|
|
||||||
next = self->entry == &cmd_next_layout_entry;
|
switch (key) {
|
||||||
if (args_has(args, 'n'))
|
case ('1' | KEYC_ESCAPE):
|
||||||
next = 1;
|
data->arg = xstrdup("even-horizontal");
|
||||||
previous = self->entry == &cmd_previous_layout_entry;
|
break;
|
||||||
if (args_has(args, 'p'))
|
case ('2' | KEYC_ESCAPE):
|
||||||
previous = 1;
|
data->arg = xstrdup("even-vertical");
|
||||||
|
break;
|
||||||
oldlayout = w->old_layout;
|
case ('3' | KEYC_ESCAPE):
|
||||||
w->old_layout = layout_dump(w->layout_root);
|
data->arg = xstrdup("main-horizontal");
|
||||||
|
break;
|
||||||
if (next || previous) {
|
case ('4' | KEYC_ESCAPE):
|
||||||
if (next)
|
data->arg = xstrdup("main-vertical");
|
||||||
layout_set_next(w);
|
break;
|
||||||
else
|
|
||||||
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;
|
ctx->error(ctx, "unknown layout or ambiguous: %s", data->arg);
|
||||||
|
return (-1);
|
||||||
if (layoutname != NULL) {
|
}
|
||||||
if (layout_parse(w, layoutname) == -1) {
|
|
||||||
cmdq_error(item, "can't set layout: %s", layoutname);
|
layout = layout_set_select(wl->window, layout);
|
||||||
goto error;
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
}
|
|
||||||
goto changed;
|
return (0);
|
||||||
}
|
|
||||||
|
|
||||||
free(oldlayout);
|
|
||||||
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,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-select-pane.c,v 1.10 2009-07-30 20:45:20 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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
|
||||||
@@ -24,142 +24,35 @@
|
|||||||
* Select pane.
|
* Select pane.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmdq_item *);
|
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 = {
|
||||||
.name = "select-pane",
|
"select-pane", "selectp",
|
||||||
.alias = "selectp",
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0, 0,
|
||||||
.args = { "DdegLlMmP:Rt:U", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-DdegLlMmRU] [-P style] " CMD_TARGET_PANE_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_select_pane_exec,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_last_pane_entry = {
|
int
|
||||||
.name = "last-pane",
|
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "lastp",
|
|
||||||
|
|
||||||
.args = { "det:", 0, 0 },
|
|
||||||
.usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct cmd_find_state *current = &item->shared->current;
|
struct winlink *wl;
|
||||||
struct winlink *wl = item->target.wl;
|
struct window_pane *wp;
|
||||||
struct window *w = wl->window;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
|
|
||||||
const char *style;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||||
lastwp = w->last;
|
return (-1);
|
||||||
if (lastwp == NULL) {
|
|
||||||
cmdq_error(item, "no last pane");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (args_has(self->args, 'e'))
|
|
||||||
lastwp->flags &= ~PANE_INPUTOFF;
|
|
||||||
else if (args_has(self->args, 'd'))
|
|
||||||
lastwp->flags |= PANE_INPUTOFF;
|
|
||||||
else {
|
|
||||||
server_unzoom_window(w);
|
|
||||||
window_redraw_active_switch(w, lastwp);
|
|
||||||
if (window_set_active_pane(w, lastwp)) {
|
|
||||||
cmd_find_from_winlink(current, wl);
|
|
||||||
server_status_window(w);
|
|
||||||
server_redraw_window_borders(w);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'm') || args_has(args, 'M')) {
|
|
||||||
if (args_has(args, 'm') && !window_pane_visible(wp))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
lastwp = marked_pane.wp;
|
|
||||||
|
|
||||||
if (args_has(args, 'M') || server_is_marked(s, wl, wp))
|
|
||||||
server_clear_marked();
|
|
||||||
else
|
|
||||||
server_set_marked(s, wl, wp);
|
|
||||||
markedwp = marked_pane.wp;
|
|
||||||
|
|
||||||
if (lastwp != NULL) {
|
|
||||||
server_redraw_window_borders(lastwp->window);
|
|
||||||
server_status_window(lastwp->window);
|
|
||||||
}
|
|
||||||
if (markedwp != NULL) {
|
|
||||||
server_redraw_window_borders(markedwp->window);
|
|
||||||
server_status_window(markedwp->window);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
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(item, "bad style: %s", style);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
wp->flags |= PANE_REDRAW;
|
|
||||||
}
|
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
cmdq_print(item, "%s", style_tostring(&wp->colgc));
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(self->args, 'L')) {
|
|
||||||
server_unzoom_window(wp->window);
|
|
||||||
wp = window_pane_find_left(wp);
|
|
||||||
} else if (args_has(self->args, 'R')) {
|
|
||||||
server_unzoom_window(wp->window);
|
|
||||||
wp = window_pane_find_right(wp);
|
|
||||||
} else if (args_has(self->args, 'U')) {
|
|
||||||
server_unzoom_window(wp->window);
|
|
||||||
wp = window_pane_find_up(wp);
|
|
||||||
} else if (args_has(self->args, 'D')) {
|
|
||||||
server_unzoom_window(wp->window);
|
|
||||||
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)) {
|
if (!window_pane_visible(wp)) {
|
||||||
cmdq_error(item, "pane not visible");
|
ctx->error(ctx, "pane not visible: %s", data->target);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
|
||||||
window_redraw_active_switch(w, wp);
|
|
||||||
if (window_set_active_pane(w, wp)) {
|
|
||||||
cmd_find_from_winlink(current, wl);
|
|
||||||
server_status_window(w);
|
|
||||||
server_redraw_window_borders(w);
|
|
||||||
}
|
}
|
||||||
|
window_set_active_pane(wl->window, wp);
|
||||||
|
server_status_window(wl->window);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
91
cmd-select-prompt.c
Normal file
91
cmd-select-prompt.c
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/* $Id: cmd-select-prompt.c,v 1.12 2009-08-16 19:29:24 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prompt for window index and select it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_select_prompt_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
int cmd_select_prompt_callback(void *, const char *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_select_prompt_entry = {
|
||||||
|
"select-prompt", NULL,
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0, 0,
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_select_prompt_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_select_prompt_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);
|
||||||
|
|
||||||
|
if (c->prompt_string != NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
status_prompt_set(c, "index ", cmd_select_prompt_callback, NULL, c, 0);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_select_prompt_callback(void *data, const char *s)
|
||||||
|
{
|
||||||
|
struct client *c = data;
|
||||||
|
const char *errstr;
|
||||||
|
char msg[128];
|
||||||
|
u_int idx;
|
||||||
|
|
||||||
|
if (s == NULL || *s == '\0')
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
idx = strtonum(s, 0, UINT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xsnprintf(msg, sizeof msg, "Index %s: %s", errstr, s);
|
||||||
|
status_message_set(c, "%s", msg);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (winlink_find_by_index(&c->session->windows, idx) == NULL) {
|
||||||
|
xsnprintf(msg, sizeof msg,
|
||||||
|
"Window not found: %s:%d", c->session->name, idx);
|
||||||
|
status_message_set(c, "%s", msg);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session_select(c->session, idx) == 0)
|
||||||
|
server_redraw_session(c->session);
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-select-window.c,v 1.23 2009-07-28 22:12:16 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -26,118 +26,44 @@
|
|||||||
* Select window by index.
|
* Select window by index.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_select_window_exec(struct cmd *,
|
void cmd_select_window_init(struct cmd *, int);
|
||||||
struct cmdq_item *);
|
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 = {
|
||||||
.name = "select-window",
|
"select-window", "selectw",
|
||||||
.alias = "selectw",
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, 0,
|
||||||
.args = { "lnpTt:", 0, 0 },
|
cmd_select_window_init,
|
||||||
.usage = "[-lnpT] " CMD_TARGET_WINDOW_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_select_window_exec,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_next_window_entry = {
|
void
|
||||||
.name = "next-window",
|
cmd_select_window_init(struct cmd *self, int key)
|
||||||
.alias = "next",
|
|
||||||
|
|
||||||
.args = { "at:", 0, 0 },
|
|
||||||
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_previous_window_entry = {
|
|
||||||
.name = "previous-window",
|
|
||||||
.alias = "prev",
|
|
||||||
|
|
||||||
.args = { "at:", 0, 0 },
|
|
||||||
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_last_window_entry = {
|
|
||||||
.name = "last-window",
|
|
||||||
.alias = "last",
|
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
|
||||||
.usage = CMD_TARGET_SESSION_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct cmd_find_state *current = &item->shared->current;
|
struct cmd_target_data *data;
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct session *s = item->target.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');
|
||||||
activity = args_has(self->args, 'a');
|
}
|
||||||
if (next) {
|
|
||||||
if (session_next(s, activity) != 0) {
|
int
|
||||||
cmdq_error(item, "no next window");
|
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
return (CMD_RETURN_ERROR);
|
{
|
||||||
}
|
struct cmd_target_data *data = self->data;
|
||||||
} else if (previous) {
|
struct winlink *wl;
|
||||||
if (session_previous(s, activity) != 0) {
|
struct session *s;
|
||||||
cmdq_error(item, "no previous window");
|
|
||||||
return (CMD_RETURN_ERROR);
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
}
|
return (-1);
|
||||||
} else {
|
|
||||||
if (session_last(s) != 0) {
|
if (session_select(s, wl->idx) == 0)
|
||||||
cmdq_error(item, "no last window");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cmd_find_from_session(&item->shared->current, s);
|
|
||||||
server_redraw_session(s);
|
server_redraw_session(s);
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* 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(item, "no last window");
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
if (current->s == s)
|
|
||||||
cmd_find_from_session(current, s);
|
|
||||||
server_redraw_session(s);
|
|
||||||
} else if (session_select(s, wl->idx) == 0) {
|
|
||||||
cmd_find_from_session(current, s);
|
|
||||||
server_redraw_session(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
239
cmd-send-keys.c
239
cmd-send-keys.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-send-keys.c,v 1.21 2009-08-20 11:37:46 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 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
|
||||||
@@ -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,141 +26,131 @@
|
|||||||
* Send keys to client.
|
* Send keys to client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmdq_item *);
|
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;
|
||||||
|
int idx;
|
||||||
|
u_int nkeys;
|
||||||
|
int *keys;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_send_keys_entry = {
|
const struct cmd_entry cmd_send_keys_entry = {
|
||||||
.name = "send-keys",
|
"send-keys", "send",
|
||||||
.alias = "send",
|
"[-t target-pane] key ...",
|
||||||
|
0, 0,
|
||||||
.args = { "lXRMN:t:", 0, -1 },
|
NULL,
|
||||||
.usage = "[-lXRM] [-N repeat-count] " CMD_TARGET_PANE_USAGE " key ...",
|
cmd_send_keys_parse,
|
||||||
|
cmd_send_keys_exec,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_send_keys_free,
|
||||||
|
cmd_send_keys_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_send_keys_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_send_prefix_entry = {
|
int
|
||||||
.name = "send-prefix",
|
cmd_send_keys_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "2t:", 0, 0 },
|
|
||||||
.usage = "[-2] " CMD_TARGET_PANE_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_send_keys_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key)
|
|
||||||
{
|
{
|
||||||
struct window_pane *wp = item->target.wp;
|
struct cmd_send_keys_data *data;
|
||||||
struct session *s = item->target.s;
|
int opt, key;
|
||||||
struct key_table *table;
|
char *s;
|
||||||
struct key_binding *bd, bd_find;
|
|
||||||
|
|
||||||
if (wp->mode == NULL || wp->mode->key_table == NULL) {
|
self->data = data = xmalloc(sizeof *data);
|
||||||
window_pane_key(wp, NULL, s, key, NULL);
|
data->target = NULL;
|
||||||
return;
|
data->idx = -1;
|
||||||
}
|
data->nkeys = 0;
|
||||||
table = key_bindings_get_table(wp->mode->key_table(wp), 1);
|
data->keys = NULL;
|
||||||
|
|
||||||
bd_find.key = (key & ~KEYC_XTERM);
|
while ((opt = getopt(argc, argv, "t:")) != -1) {
|
||||||
bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find);
|
switch (opt) {
|
||||||
if (bd != NULL) {
|
case 't':
|
||||||
table->references++;
|
if (data->target == NULL)
|
||||||
key_bindings_dispatch(bd, c, NULL, &item->target);
|
data->target = xstrdup(optarg);
|
||||||
key_bindings_unref_table(table);
|
break;
|
||||||
}
|
default:
|
||||||
}
|
goto usage;
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct mouse_event *m = &item->shared->mouse;
|
|
||||||
struct utf8_data *ud, *uc;
|
|
||||||
wchar_t wc;
|
|
||||||
int i, literal;
|
|
||||||
key_code key;
|
|
||||||
u_int np = 1;
|
|
||||||
char *cause = NULL;
|
|
||||||
|
|
||||||
if (args_has(args, 'N')) {
|
|
||||||
np = args_strtonum(args, 'N', 1, UINT_MAX, &cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(item, "repeat count %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
if (args_has(args, 'X') || args->argc == 0)
|
|
||||||
wp->modeprefix = np;
|
|
||||||
}
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc == 0)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
if (args_has(args, 'X')) {
|
while (argc-- != 0) {
|
||||||
if (wp->mode == NULL || wp->mode->command == NULL) {
|
if ((key = key_string_lookup_string(*argv)) != KEYC_NONE) {
|
||||||
cmdq_error(item, "not in a mode");
|
data->keys = xrealloc(
|
||||||
return (CMD_RETURN_ERROR);
|
data->keys, data->nkeys + 1, sizeof *data->keys);
|
||||||
}
|
data->keys[data->nkeys++] = key;
|
||||||
if (!m->valid)
|
} else {
|
||||||
wp->mode->command(wp, c, s, args, NULL);
|
for (s = *argv; *s != '\0'; s++) {
|
||||||
else
|
data->keys = xrealloc(data->keys,
|
||||||
wp->mode->command(wp, c, s, args, m);
|
data->nkeys + 1, sizeof *data->keys);
|
||||||
return (CMD_RETURN_NORMAL);
|
data->keys[data->nkeys++] = *s;
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'M')) {
|
|
||||||
wp = cmd_mouse_pane(m, &s, NULL);
|
|
||||||
if (wp == NULL) {
|
|
||||||
cmdq_error(item, "no mouse target");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
window_pane_key(wp, NULL, s, m->key, m);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self->entry == &cmd_send_prefix_entry) {
|
|
||||||
if (args_has(args, '2'))
|
|
||||||
key = options_get_number(s->options, "prefix2");
|
|
||||||
else
|
|
||||||
key = options_get_number(s->options, "prefix");
|
|
||||||
cmd_send_keys_inject(c, item, key);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'R')) {
|
|
||||||
window_pane_reset_palette(wp);
|
|
||||||
input_reset(wp, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; np != 0; np--) {
|
|
||||||
for (i = 0; i < args->argc; i++) {
|
|
||||||
literal = args_has(args, 'l');
|
|
||||||
if (!literal) {
|
|
||||||
key = key_string_lookup_string(args->argv[i]);
|
|
||||||
if (key != KEYC_NONE && key != KEYC_UNKNOWN)
|
|
||||||
cmd_send_keys_inject(c, item, key);
|
|
||||||
else
|
|
||||||
literal = 1;
|
|
||||||
}
|
|
||||||
if (literal) {
|
|
||||||
ud = utf8_fromcstr(args->argv[i]);
|
|
||||||
for (uc = ud; uc->size != 0; uc++) {
|
|
||||||
if (utf8_combine(uc, &wc) != UTF8_DONE)
|
|
||||||
continue;
|
|
||||||
cmd_send_keys_inject(c, item, wc);
|
|
||||||
}
|
|
||||||
free(ud);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
if (data == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
for (i = 0; i < data->nkeys; i++)
|
||||||
|
window_pane_key(wp, ctx->curclient, 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);
|
||||||
|
if (off < len && data->idx != -1)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -i %d", data->idx);
|
||||||
|
|
||||||
|
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.26 2009-08-20 11:37:46 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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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, 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;
|
||||||
|
int key;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, &s, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
key = options_get_number(&s->options, "prefix");
|
||||||
|
window_pane_key(wp, ctx->curclient, key);
|
||||||
|
|
||||||
|
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.28 2009-09-07 23:59:19 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, 0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_server_info_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
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 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%s%s",
|
||||||
|
socket_path, debug_level, be_quiet ? ", quiet" : "",
|
||||||
|
login_shell ? ", login shell" : "");
|
||||||
|
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, "%u clients, %u sessions",
|
||||||
|
ARRAY_LENGTH(&clients), ARRAY_LENGTH(&sessions));
|
||||||
|
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));
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||||
|
s = ARRAY_ITEM(&sessions, i);
|
||||||
|
if (s == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
t = s->tv.tv_sec;
|
||||||
|
tim = ctime(&t);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
|
||||||
|
"[flags=0x%x, references=%u]", i, s->name,
|
||||||
|
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags,
|
||||||
|
s->references);
|
||||||
|
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", "");
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
121
cmd-set-buffer.c
121
cmd-set-buffer.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-set-buffer.c,v 1.10 2009-09-07 23:48:54 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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,106 +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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmdq_item *);
|
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 = {
|
||||||
.name = "set-buffer",
|
"set-buffer", "setb",
|
||||||
.alias = "setb",
|
CMD_BUFFER_SESSION_USAGE " data",
|
||||||
|
CMD_ARG1, 0,
|
||||||
.args = { "ab:n:", 0, 1 },
|
cmd_buffer_init,
|
||||||
.usage = "[-a] " CMD_BUFFER_USAGE " [-n new-buffer-name] data",
|
cmd_buffer_parse,
|
||||||
|
cmd_set_buffer_exec,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_buffer_free,
|
||||||
.exec = cmd_set_buffer_exec
|
cmd_buffer_print
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_delete_buffer_entry = {
|
int
|
||||||
.name = "delete-buffer",
|
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "deleteb",
|
|
||||||
|
|
||||||
.args = { "b:", 0, 0 },
|
|
||||||
.usage = CMD_BUFFER_USAGE,
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_set_buffer_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
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;
|
u_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(item, "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(item, "no buffer");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) {
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
if (args->argc != 1) {
|
|
||||||
cmdq_error(item, "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(item, "%s", cause);
|
|
||||||
free(bufdata);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-set-environment.c,v 1.2 2009-08-11 14:42:59 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* 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
|
||||||
@@ -27,77 +27,62 @@
|
|||||||
* Set an environment variable.
|
* Set an environment variable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_set_environment_exec(struct cmd *,
|
int cmd_set_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_environment_entry = {
|
const struct cmd_entry cmd_set_environment_entry = {
|
||||||
.name = "set-environment",
|
"set-environment", "setenv",
|
||||||
.alias = "setenv",
|
"[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
||||||
|
CMD_ARG12, CMD_CHFLAG('g')|CMD_CHFLAG('r')|CMD_CHFLAG('u'),
|
||||||
.args = { "grt:u", 1, 2 },
|
NULL,
|
||||||
.usage = "[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
cmd_target_parse,
|
||||||
|
cmd_set_environment_exec,
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_set_environment_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct environ *env;
|
struct session *s;
|
||||||
const char *name, *value, *target;
|
struct environ *env;
|
||||||
|
|
||||||
name = args->argv[0];
|
if (*data->arg == '\0') {
|
||||||
if (*name == '\0') {
|
ctx->error(ctx, "empty variable name");
|
||||||
cmdq_error(item, "empty variable name");
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
if (strchr(name, '=') != NULL) {
|
if (strchr(data->arg, '=') != NULL) {
|
||||||
cmdq_error(item, "variable name contains =");
|
ctx->error(ctx, "variable name contains =");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc < 2)
|
if (data->chflags & CMD_CHFLAG('g'))
|
||||||
value = NULL;
|
env = &global_environ;
|
||||||
else
|
|
||||||
value = args->argv[1];
|
|
||||||
|
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
env = global_environ;
|
|
||||||
else {
|
else {
|
||||||
if (item->target.s == NULL) {
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
target = args_get(args, 't');
|
return (-1);
|
||||||
if (target != NULL)
|
env = &s->environ;
|
||||||
cmdq_error(item, "no such session: %s", target);
|
|
||||||
else
|
|
||||||
cmdq_error(item, "no current session");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
env = item->target.s->environ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(self->args, 'u')) {
|
if (data->chflags & CMD_CHFLAG('u')) {
|
||||||
if (value != NULL) {
|
if (data->arg2 != NULL) {
|
||||||
cmdq_error(item, "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 (data->chflags & CMD_CHFLAG('r')) {
|
||||||
if (value != NULL) {
|
if (data->arg2 != NULL) {
|
||||||
cmdq_error(item, "can't specify a value with -r");
|
ctx->error(ctx, "can't specify a value with -r");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
environ_clear(env, name);
|
environ_set(env, data->arg, NULL);
|
||||||
} else {
|
} else {
|
||||||
if (value == NULL) {
|
if (data->arg2 == NULL) {
|
||||||
cmdq_error(item, "no value specified");
|
ctx->error(ctx, "no value specified");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
environ_set(env, name, "%s", value);
|
environ_set(env, data->arg, data->arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
130
cmd-set-hook.c
130
cmd-set-hook.c
@@ -1,130 +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 <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set or show global or session hooks.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_set_hook_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_hook_entry = {
|
|
||||||
.name = "set-hook",
|
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "gt:u", 1, 2 },
|
|
||||||
.usage = "[-gu] " CMD_TARGET_SESSION_USAGE " hook-name [command]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_set_hook_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_hooks_entry = {
|
|
||||||
.name = "show-hooks",
|
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "gt:", 0, 1 },
|
|
||||||
.usage = "[-g] " CMD_TARGET_SESSION_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_set_hook_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct cmd_list *cmdlist;
|
|
||||||
struct hooks *hooks;
|
|
||||||
struct hook *hook;
|
|
||||||
char *cause, *tmp;
|
|
||||||
const char *name, *cmd, *target;
|
|
||||||
|
|
||||||
if (args_has(args, 'g'))
|
|
||||||
hooks = global_hooks;
|
|
||||||
else {
|
|
||||||
if (item->target.s == NULL) {
|
|
||||||
target = args_get(args, 't');
|
|
||||||
if (target != NULL)
|
|
||||||
cmdq_error(item, "no such session: %s", target);
|
|
||||||
else
|
|
||||||
cmdq_error(item, "no current session");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
hooks = item->target.s->hooks;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self->entry == &cmd_show_hooks_entry) {
|
|
||||||
hook = hooks_first(hooks);
|
|
||||||
while (hook != NULL) {
|
|
||||||
tmp = cmd_list_print(hook->cmdlist);
|
|
||||||
cmdq_print(item, "%s -> %s", hook->name, tmp);
|
|
||||||
free(tmp);
|
|
||||||
|
|
||||||
hook = hooks_next(hook);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
name = args->argv[0];
|
|
||||||
if (*name == '\0') {
|
|
||||||
cmdq_error(item, "invalid hook name");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (args->argc < 2)
|
|
||||||
cmd = NULL;
|
|
||||||
else
|
|
||||||
cmd = args->argv[1];
|
|
||||||
|
|
||||||
if (args_has(args, 'u')) {
|
|
||||||
if (cmd != NULL) {
|
|
||||||
cmdq_error(item, "command passed to unset hook: %s",
|
|
||||||
name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
hooks_remove(hooks, name);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd == NULL) {
|
|
||||||
cmdq_error(item, "no command to set hook: %s", name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
|
||||||
if (cmdlist == NULL) {
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
hooks_add(hooks, name, cmdlist);
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
491
cmd-set-option.c
491
cmd-set-option.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-set-option.c,v 1.79 2009-09-19 18:53:01 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 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
|
||||||
@@ -27,372 +27,165 @@
|
|||||||
* Set an option.
|
* Set an option.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmdq_item *);
|
int cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static int cmd_set_option_set(struct cmd *, struct cmdq_item *,
|
|
||||||
struct options *, struct options_entry *, const char *);
|
|
||||||
static int cmd_set_option_flag(struct cmdq_item *,
|
|
||||||
const struct options_table_entry *, struct options *,
|
|
||||||
const char *);
|
|
||||||
static int cmd_set_option_choice(struct cmdq_item *,
|
|
||||||
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 = {
|
||||||
.name = "set-option",
|
"set-option", "set",
|
||||||
.alias = "set",
|
"[-agu] " CMD_TARGET_SESSION_USAGE " option [value]",
|
||||||
|
CMD_ARG12, CMD_CHFLAG('a')|CMD_CHFLAG('g')|CMD_CHFLAG('u'),
|
||||||
.args = { "agoqst:uw", 1, 2 },
|
NULL,
|
||||||
.usage = "[-agosquw] [-t target-window] option [value]",
|
cmd_target_parse,
|
||||||
|
cmd_set_option_exec,
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_set_option_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_window_option_entry = {
|
const char *set_option_status_keys_list[] = {
|
||||||
.name = "set-window-option",
|
"emacs", "vi", NULL
|
||||||
.alias = "setw",
|
};
|
||||||
|
const char *set_option_status_justify_list[] = {
|
||||||
.args = { "agoqt:u", 1, 2 },
|
"left", "centre", "right", NULL
|
||||||
.usage = "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
};
|
||||||
|
const char *set_option_bell_action_list[] = {
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
"none", "any", "current", NULL
|
||||||
|
};
|
||||||
.flags = CMD_AFTERHOOK,
|
const struct set_option_entry set_option_table[] = {
|
||||||
.exec = cmd_set_option_exec
|
{ "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 },
|
||||||
|
{ "display-panes-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 },
|
||||||
|
{ "message-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||||
|
{ "message-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "message-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
|
{ "prefix", SET_OPTION_KEY, 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 },
|
||||||
|
{ NULL, 0, 0, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
int append = args_has(args, 'a');
|
struct session *s;
|
||||||
struct cmd_find_state *fs = &item->target;
|
|
||||||
struct session *s = fs->s;
|
|
||||||
struct winlink *wl = fs->wl;
|
|
||||||
struct window *w;
|
|
||||||
struct client *c;
|
struct client *c;
|
||||||
enum options_table_scope scope;
|
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
struct options_entry *parent, *o;
|
const struct set_option_entry *entry, *opt;
|
||||||
char *name;
|
u_int i;
|
||||||
const char *value, *target;
|
|
||||||
int window, idx, already, error, ambiguous;
|
|
||||||
char *cause;
|
|
||||||
|
|
||||||
/* Parse option name and index. */
|
if (data->chflags & CMD_CHFLAG('g'))
|
||||||
name = options_match(args->argv[0], &idx, &ambiguous);
|
oo = &global_s_options;
|
||||||
if (name == NULL) {
|
else {
|
||||||
if (args_has(args, 'q'))
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (-1);
|
||||||
if (ambiguous)
|
oo = &s->options;
|
||||||
cmdq_error(item, "ambiguous option: %s", args->argv[0]);
|
|
||||||
else
|
|
||||||
cmdq_error(item, "invalid option: %s", args->argv[0]);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
if (args->argc < 2)
|
|
||||||
value = NULL;
|
|
||||||
else
|
|
||||||
value = args->argv[1];
|
|
||||||
|
|
||||||
/*
|
if (*data->arg == '\0') {
|
||||||
* Figure out the scope: for user options it comes from the arguments,
|
ctx->error(ctx, "invalid option");
|
||||||
* otherwise from the option name.
|
return (-1);
|
||||||
*/
|
}
|
||||||
if (*name == '@') {
|
|
||||||
window = (self->entry == &cmd_set_window_option_entry);
|
entry = NULL;
|
||||||
scope = options_scope_from_flags(args, window, fs, &oo, &cause);
|
for (opt = set_option_table; opt->name != NULL; opt++) {
|
||||||
|
if (strncmp(opt->name, data->arg, strlen(data->arg)) != 0)
|
||||||
|
continue;
|
||||||
|
if (entry != NULL) {
|
||||||
|
ctx->error(ctx, "ambiguous option: %s", data->arg);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
entry = opt;
|
||||||
|
|
||||||
|
/* Bail now if an exact match. */
|
||||||
|
if (strcmp(entry->name, data->arg) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (entry == NULL) {
|
||||||
|
ctx->error(ctx, "unknown option: %s", data->arg);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data->chflags & CMD_CHFLAG('u')) {
|
||||||
|
if (data->chflags & CMD_CHFLAG('g')) {
|
||||||
|
ctx->error(ctx,
|
||||||
|
"can't unset global option: %s", entry->name);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (data->arg2 != NULL) {
|
||||||
|
ctx->error(ctx,
|
||||||
|
"value passed to unset option: %s", entry->name);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
options_remove(oo, entry->name);
|
||||||
|
ctx->info(ctx, "unset option: %s", entry->name);
|
||||||
} else {
|
} else {
|
||||||
if (options_get_only(global_options, name) != NULL)
|
switch (entry->type) {
|
||||||
scope = OPTIONS_TABLE_SERVER;
|
case SET_OPTION_STRING:
|
||||||
else if (options_get_only(global_s_options, name) != NULL)
|
set_option_string(ctx, oo, entry,
|
||||||
scope = OPTIONS_TABLE_SESSION;
|
data->arg2, data->chflags & CMD_CHFLAG('a'));
|
||||||
else if (options_get_only(global_w_options, name) != NULL)
|
break;
|
||||||
scope = OPTIONS_TABLE_WINDOW;
|
case SET_OPTION_NUMBER:
|
||||||
else {
|
set_option_number(ctx, oo, entry, data->arg2);
|
||||||
scope = OPTIONS_TABLE_NONE;
|
break;
|
||||||
xasprintf(&cause, "unknown option: %s", args->argv[0]);
|
case SET_OPTION_KEY:
|
||||||
}
|
set_option_key(ctx, oo, entry, data->arg2);
|
||||||
}
|
break;
|
||||||
if (scope == OPTIONS_TABLE_NONE) {
|
case SET_OPTION_COLOUR:
|
||||||
if (args_has(args, 'q'))
|
set_option_colour(ctx, oo, entry, data->arg2);
|
||||||
return (CMD_RETURN_NORMAL);
|
break;
|
||||||
cmdq_error(item, "%s", cause);
|
case SET_OPTION_ATTRIBUTES:
|
||||||
free(cause);
|
set_option_attributes(ctx, oo, entry, data->arg2);
|
||||||
goto fail;
|
break;
|
||||||
}
|
case SET_OPTION_FLAG:
|
||||||
|
set_option_flag(ctx, oo, entry, data->arg2);
|
||||||
/* Which table should this option go into? */
|
break;
|
||||||
if (scope == OPTIONS_TABLE_SERVER)
|
case SET_OPTION_CHOICE:
|
||||||
oo = global_options;
|
set_option_choice(ctx, oo, entry, data->arg2);
|
||||||
else if (scope == OPTIONS_TABLE_SESSION) {
|
break;
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
oo = global_s_options;
|
|
||||||
else if (s == NULL) {
|
|
||||||
target = args_get(args, 't');
|
|
||||||
if (target != NULL)
|
|
||||||
cmdq_error(item, "no such session: %s", target);
|
|
||||||
else
|
|
||||||
cmdq_error(item, "no current session");
|
|
||||||
goto fail;
|
|
||||||
} else
|
|
||||||
oo = s->options;
|
|
||||||
} else if (scope == OPTIONS_TABLE_WINDOW) {
|
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
oo = global_w_options;
|
|
||||||
else if (wl == NULL) {
|
|
||||||
target = args_get(args, 't');
|
|
||||||
if (target != NULL)
|
|
||||||
cmdq_error(item, "no such window: %s", target);
|
|
||||||
else
|
|
||||||
cmdq_error(item, "no current window");
|
|
||||||
goto fail;
|
|
||||||
} else
|
|
||||||
oo = wl->window->options;
|
|
||||||
}
|
|
||||||
o = options_get_only(oo, name);
|
|
||||||
parent = options_get(oo, name);
|
|
||||||
|
|
||||||
/* Check that array options and indexes match up. */
|
|
||||||
if (idx != -1) {
|
|
||||||
if (*name == '@' || options_array_size(parent, NULL) == -1) {
|
|
||||||
cmdq_error(item, "not an array: %s", args->argv[0]);
|
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* With -o, check this option is not already set. */
|
|
||||||
if (!args_has(args, 'u') && args_has(args, 'o')) {
|
|
||||||
if (idx == -1)
|
|
||||||
already = (o != NULL);
|
|
||||||
else {
|
|
||||||
if (o == NULL)
|
|
||||||
already = 0;
|
|
||||||
else
|
|
||||||
already = (options_array_get(o, idx) != NULL);
|
|
||||||
}
|
|
||||||
if (already) {
|
|
||||||
if (args_has(args, 'q'))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
cmdq_error(item, "already set: %s", args->argv[0]);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Change the option. */
|
|
||||||
if (args_has(args, 'u')) {
|
|
||||||
if (o == NULL)
|
|
||||||
goto fail;
|
|
||||||
if (idx == -1) {
|
|
||||||
if (oo == global_options ||
|
|
||||||
oo == global_s_options ||
|
|
||||||
oo == global_w_options)
|
|
||||||
options_default(oo, options_table_entry(o));
|
|
||||||
else
|
|
||||||
options_remove(o);
|
|
||||||
} else
|
|
||||||
options_array_set(o, idx, NULL, 0);
|
|
||||||
} else if (*name == '@') {
|
|
||||||
if (value == NULL) {
|
|
||||||
cmdq_error(item, "empty value");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
options_set_string(oo, name, append, "%s", value);
|
|
||||||
} else if (idx == -1 && options_array_size(parent, NULL) == -1) {
|
|
||||||
error = cmd_set_option_set(self, item, oo, parent, value);
|
|
||||||
if (error != 0)
|
|
||||||
goto fail;
|
|
||||||
} else {
|
|
||||||
if (value == NULL) {
|
|
||||||
cmdq_error(item, "empty value");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
if (o == NULL)
|
|
||||||
o = options_empty(oo, options_table_entry(parent));
|
|
||||||
if (idx == -1) {
|
|
||||||
if (!append)
|
|
||||||
options_array_clear(o);
|
|
||||||
options_array_assign(o, value);
|
|
||||||
} else if (options_array_set(o, idx, value, append) != 0) {
|
|
||||||
cmdq_error(item, "invalid index: %s", args->argv[0]);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update timers and so on for various options. */
|
|
||||||
if (strcmp(name, "automatic-rename") == 0) {
|
|
||||||
RB_FOREACH(w, windows, &windows) {
|
|
||||||
if (w->active == NULL)
|
|
||||||
continue;
|
|
||||||
if (options_get_number(w->options, "automatic-rename"))
|
|
||||||
w->active->flags |= PANE_CHANGED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (strcmp(name, "key-table") == 0) {
|
|
||||||
TAILQ_FOREACH(c, &clients, entry)
|
|
||||||
server_client_set_key_table(c, NULL);
|
|
||||||
}
|
|
||||||
if (strcmp(name, "status") == 0 ||
|
|
||||||
strcmp(name, "status-interval") == 0)
|
|
||||||
status_timer_start_all();
|
|
||||||
if (strcmp(name, "monitor-silence") == 0)
|
|
||||||
alerts_reset_all();
|
|
||||||
if (strcmp(name, "window-style") == 0 ||
|
|
||||||
strcmp(name, "window-active-style") == 0) {
|
|
||||||
RB_FOREACH(w, windows, &windows)
|
|
||||||
w->flags |= WINDOW_STYLECHANGED;
|
|
||||||
}
|
|
||||||
if (strcmp(name, "pane-border-status") == 0) {
|
|
||||||
RB_FOREACH(w, windows, &windows)
|
|
||||||
layout_fix_panes(w, w->sx, w->sy);
|
|
||||||
}
|
|
||||||
RB_FOREACH (s, sessions, &sessions)
|
|
||||||
status_update_saved(s);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Update sizes and redraw. May not always be necessary but do it
|
|
||||||
* anyway.
|
|
||||||
*/
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(name);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
fail:
|
|
||||||
free(name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
|
|
||||||
struct options_entry *parent, const char *value)
|
|
||||||
{
|
|
||||||
const struct options_table_entry *oe;
|
|
||||||
struct args *args = self->args;
|
|
||||||
int append = args_has(args, 'a');
|
|
||||||
struct options_entry *o;
|
|
||||||
long long number;
|
|
||||||
const char *errstr;
|
|
||||||
key_code key;
|
|
||||||
|
|
||||||
oe = options_table_entry(parent);
|
|
||||||
if (value == NULL &&
|
|
||||||
oe->type != OPTIONS_TABLE_FLAG &&
|
|
||||||
oe->type != OPTIONS_TABLE_CHOICE) {
|
|
||||||
cmdq_error(item, "empty value");
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (oe->type) {
|
|
||||||
case OPTIONS_TABLE_STRING:
|
|
||||||
options_set_string(oo, oe->name, append, "%s", value);
|
|
||||||
return (0);
|
|
||||||
case OPTIONS_TABLE_NUMBER:
|
|
||||||
number = strtonum(value, oe->minimum, oe->maximum, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "value is %s: %s", errstr, value);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
options_set_number(oo, oe->name, number);
|
|
||||||
return (0);
|
|
||||||
case OPTIONS_TABLE_KEY:
|
|
||||||
key = key_string_lookup_string(value);
|
|
||||||
if (key == KEYC_UNKNOWN) {
|
|
||||||
cmdq_error(item, "bad key: %s", value);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
options_set_number(oo, oe->name, key);
|
|
||||||
return (0);
|
|
||||||
case OPTIONS_TABLE_COLOUR:
|
|
||||||
if ((number = colour_fromstring(value)) == -1) {
|
|
||||||
cmdq_error(item, "bad colour: %s", value);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
o = options_set_number(oo, oe->name, number);
|
|
||||||
options_style_update_new(oo, o);
|
|
||||||
return (0);
|
|
||||||
case OPTIONS_TABLE_ATTRIBUTES:
|
|
||||||
if ((number = attributes_fromstring(value)) == -1) {
|
|
||||||
cmdq_error(item, "bad attributes: %s", value);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
o = options_set_number(oo, oe->name, number);
|
|
||||||
options_style_update_new(oo, o);
|
|
||||||
return (0);
|
|
||||||
case OPTIONS_TABLE_FLAG:
|
|
||||||
return (cmd_set_option_flag(item, oe, oo, value));
|
|
||||||
case OPTIONS_TABLE_CHOICE:
|
|
||||||
return (cmd_set_option_choice(item, oe, oo, value));
|
|
||||||
case OPTIONS_TABLE_STYLE:
|
|
||||||
o = options_set_style(oo, oe->name, append, value);
|
|
||||||
if (o == NULL) {
|
|
||||||
cmdq_error(item, "bad style: %s", value);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
options_style_update_old(oo, o);
|
|
||||||
return (0);
|
|
||||||
case OPTIONS_TABLE_ARRAY:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
cmd_set_option_flag(struct cmdq_item *item,
|
|
||||||
const struct options_table_entry *oe, struct options *oo,
|
|
||||||
const char *value)
|
|
||||||
{
|
|
||||||
int flag;
|
|
||||||
|
|
||||||
if (value == NULL || *value == '\0')
|
|
||||||
flag = !options_get_number(oo, oe->name);
|
|
||||||
else if (strcmp(value, "1") == 0 ||
|
|
||||||
strcasecmp(value, "on") == 0 ||
|
|
||||||
strcasecmp(value, "yes") == 0)
|
|
||||||
flag = 1;
|
|
||||||
else if (strcmp(value, "0") == 0 ||
|
|
||||||
strcasecmp(value, "off") == 0 ||
|
|
||||||
strcasecmp(value, "no") == 0)
|
|
||||||
flag = 0;
|
|
||||||
else {
|
|
||||||
cmdq_error(item, "bad value: %s", value);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
options_set_number(oo, oe->name, flag);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
cmd_set_option_choice(struct cmdq_item *item,
|
|
||||||
const struct options_table_entry *oe, struct options *oo,
|
|
||||||
const char *value)
|
|
||||||
{
|
|
||||||
const char **cp;
|
|
||||||
int n, choice = -1;
|
|
||||||
|
|
||||||
if (value == NULL) {
|
|
||||||
choice = options_get_number(oo, oe->name);
|
|
||||||
if (choice < 2)
|
|
||||||
choice = !choice;
|
|
||||||
} else {
|
|
||||||
n = 0;
|
|
||||||
for (cp = oe->choices; *cp != NULL; cp++) {
|
|
||||||
if (strcmp(*cp, value) == 0)
|
|
||||||
choice = n;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
if (choice == -1) {
|
|
||||||
cmdq_error(item, "unknown value: %s", value);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
options_set_number(oo, oe->name, choice);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
145
cmd-set-password.c
Normal file
145
cmd-set-password.c
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
/* $Id: cmd-set-password.c,v 1.8 2009-07-28 22:12: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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set server password.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_set_password_parse(struct cmd *, int, char **, char **);
|
||||||
|
int cmd_set_password_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_set_password_free(struct cmd *);
|
||||||
|
void cmd_set_password_init(struct cmd *, int);
|
||||||
|
size_t cmd_set_password_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
|
struct cmd_set_password_data {
|
||||||
|
char *password;
|
||||||
|
int flag_encrypted;
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_set_password_entry = {
|
||||||
|
"set-password", "pass",
|
||||||
|
"[-c] password",
|
||||||
|
0, 0,
|
||||||
|
cmd_set_password_init,
|
||||||
|
cmd_set_password_parse,
|
||||||
|
cmd_set_password_exec,
|
||||||
|
cmd_set_password_free,
|
||||||
|
cmd_set_password_print
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_set_password_init(struct cmd *self, unused int arg)
|
||||||
|
{
|
||||||
|
struct cmd_set_password_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->password = NULL;
|
||||||
|
data->flag_encrypted = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_set_password_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_set_password_data *data;
|
||||||
|
int opt;
|
||||||
|
char *out;
|
||||||
|
|
||||||
|
self->entry->init(self, 0);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "c")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'c':
|
||||||
|
data->flag_encrypted = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
if (!data->flag_encrypted) {
|
||||||
|
if ((out = crypt(argv[0], "$1")) != NULL)
|
||||||
|
data->password = xstrdup(out);
|
||||||
|
} else
|
||||||
|
data->password = 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_set_password_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_set_password_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->password == NULL) {
|
||||||
|
ctx->error(ctx, "failed to encrypt password");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server_password != NULL)
|
||||||
|
xfree(server_password);
|
||||||
|
if (*data->password == '\0')
|
||||||
|
server_password = NULL;
|
||||||
|
else
|
||||||
|
server_password = xstrdup(data->password);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_set_password_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_set_password_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->password != NULL)
|
||||||
|
xfree(data->password);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_set_password_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_set_password_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_encrypted)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -c");
|
||||||
|
if (off < len && data->password != NULL)
|
||||||
|
off += xsnprintf(buf + off, len - off, " password");
|
||||||
|
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