mirror of
https://github.com/tmux/tmux.git
synced 2026-03-12 11:35:46 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2365b09d6a |
78
.github/CONTRIBUTING.md
vendored
78
.github/CONTRIBUTING.md
vendored
@@ -1,78 +0,0 @@
|
|||||||
## What should I do before opening an issue?
|
|
||||||
|
|
||||||
Before opening an issue, please ensure that:
|
|
||||||
|
|
||||||
- Your problem is a specific problem or question or suggestion, not a general
|
|
||||||
complaint.
|
|
||||||
|
|
||||||
- `$TERM` inside tmux is screen, screen-256color, tmux or tmux-256color. Check
|
|
||||||
by running `echo $TERM` inside tmux.
|
|
||||||
|
|
||||||
- You can reproduce the problem with the latest tmux release, or a build from
|
|
||||||
Git master.
|
|
||||||
|
|
||||||
- Your question or issue is not covered [in the
|
|
||||||
manual](https://man.openbsd.org/tmux.1) (run `man tmux`).
|
|
||||||
|
|
||||||
- Your problem is not mentioned in [the CHANGES
|
|
||||||
file](https://raw.githubusercontent.com/tmux/tmux/master/CHANGES).
|
|
||||||
|
|
||||||
- Nobody else has opened the same issue recently.
|
|
||||||
|
|
||||||
## What should I include in an issue?
|
|
||||||
|
|
||||||
Please include the output of:
|
|
||||||
|
|
||||||
~~~bash
|
|
||||||
uname -sp && tmux -V && echo $TERM
|
|
||||||
~~~
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
## How do I test without a .tmux.conf?
|
|
||||||
|
|
||||||
Run a separate tmux server with `-f/dev/null` to skip loading `.tmux.conf`:
|
|
||||||
|
|
||||||
~~~bash
|
|
||||||
tmux -Ltest kill-server
|
|
||||||
tmux -Ltest -f/dev/null new
|
|
||||||
~~~
|
|
||||||
|
|
||||||
## How do I get logs from tmux?
|
|
||||||
|
|
||||||
Add `-vv` to tmux to create three log files in the current directory. If you can
|
|
||||||
reproduce without a configuration file:
|
|
||||||
|
|
||||||
~~~bash
|
|
||||||
tmux -Ltest kill-server
|
|
||||||
tmux -vv -Ltest -f/dev/null new
|
|
||||||
~~~
|
|
||||||
|
|
||||||
Or if you need your configuration:
|
|
||||||
|
|
||||||
~~~base
|
|
||||||
tmux kill-server
|
|
||||||
tmux -vv new
|
|
||||||
~~~
|
|
||||||
|
|
||||||
The log files are:
|
|
||||||
|
|
||||||
- `tmux-server*.log`: server log file.
|
|
||||||
|
|
||||||
- `tmux-client*.log`: client log file.
|
|
||||||
|
|
||||||
- `tmux-out*.log`: output log file.
|
|
||||||
|
|
||||||
Please attach the log files to your issue.
|
|
||||||
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,2 +0,0 @@
|
|||||||
github: nicm
|
|
||||||
liberapay: tmux
|
|
||||||
22
.github/ISSUE_TEMPLATE.md
vendored
22
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,22 +0,0 @@
|
|||||||
### Issue description
|
|
||||||
|
|
||||||
Please read https://github.com/tmux/tmux/blob/master/.github/CONTRIBUTING.md
|
|
||||||
before opening an issue.
|
|
||||||
|
|
||||||
If you have upgraded, make sure your issue is not covered in the CHANGES file
|
|
||||||
for your version: https://raw.githubusercontent.com/tmux/tmux/master/CHANGES
|
|
||||||
|
|
||||||
Describe the problem and the steps to reproduce. Add a minimal tmux config if
|
|
||||||
necessary. Screenshots can be helpful, but no more than one or two.
|
|
||||||
|
|
||||||
Do not report bugs (crashes, incorrect behaviour) without reproducing on a tmux
|
|
||||||
built from the latest code in Git.
|
|
||||||
|
|
||||||
### Required information
|
|
||||||
|
|
||||||
Please provide the following information:
|
|
||||||
|
|
||||||
* tmux version (`tmux -V`).
|
|
||||||
* Platform (`uname -sp`).
|
|
||||||
* $TERM inside and outside of tmux (`echo $TERM`).
|
|
||||||
* Logs from tmux (`tmux kill-server; tmux -vv new`).
|
|
||||||
83
.github/README.md
vendored
83
.github/README.md
vendored
@@ -1,83 +0,0 @@
|
|||||||
# Welcome to tmux!
|
|
||||||
|
|
||||||
tmux is a terminal multiplexer: it enables a number of terminals to be created,
|
|
||||||
accessed, and controlled from a single screen. tmux may be detached from a
|
|
||||||
screen and continue running in the background, then later reattached.
|
|
||||||
|
|
||||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, OS X and Solaris.
|
|
||||||
|
|
||||||
## Dependencies
|
|
||||||
|
|
||||||
tmux depends on [libevent](https://libevent.org) 2.x, available from [this
|
|
||||||
page](https://github.com/libevent/libevent/releases/latest).
|
|
||||||
|
|
||||||
It also depends on [ncurses](https://www.gnu.org/software/ncurses/), available
|
|
||||||
from [this page](https://invisible-mirror.net/archives/ncurses/).
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
### From release tarball
|
|
||||||
|
|
||||||
To build and install tmux from a release tarball, use:
|
|
||||||
|
|
||||||
~~~bash
|
|
||||||
./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.
|
|
||||||
|
|
||||||
### From version control
|
|
||||||
|
|
||||||
To get and build the latest from version control - note that this requires
|
|
||||||
`autoconf`, `automake` and `pkg-config`:
|
|
||||||
|
|
||||||
~~~bash
|
|
||||||
git clone https://github.com/tmux/tmux.git
|
|
||||||
cd tmux
|
|
||||||
sh autogen.sh
|
|
||||||
./configure && make
|
|
||||||
~~~
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
Bug reports, feature suggestions and especially code contributions are most
|
|
||||||
welcome. Please send by email to:
|
|
||||||
|
|
||||||
tmux-users@googlegroups.com
|
|
||||||
|
|
||||||
Or open a GitHub issue or pull request. **Please read [this
|
|
||||||
document](CONTRIBUTING.md) before opening an issue.**
|
|
||||||
|
|
||||||
There is [a list of suggestions for contributions](https://github.com/tmux/tmux/wiki/Contributing).
|
|
||||||
Please feel free to ask on the mailing list if you're thinking of working on something or need
|
|
||||||
further information.
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
For documentation on using tmux, see the tmux.1 manpage. View it from the
|
|
||||||
source tree with:
|
|
||||||
|
|
||||||
~~~bash
|
|
||||||
nroff -mdoc tmux.1|less
|
|
||||||
~~~
|
|
||||||
|
|
||||||
A small example configuration is in `example_tmux.conf`.
|
|
||||||
|
|
||||||
And a bash(1) completion file at:
|
|
||||||
|
|
||||||
https://github.com/imomaliev/tmux-bash-completion
|
|
||||||
|
|
||||||
For debugging, run tmux with `-v` or `-vv` to generate server and client log
|
|
||||||
files in the current directory.
|
|
||||||
|
|
||||||
## Support
|
|
||||||
|
|
||||||
The tmux mailing list for general discussion and bug reports is:
|
|
||||||
|
|
||||||
https://groups.google.com/forum/#!forum/tmux-users
|
|
||||||
|
|
||||||
Subscribe by sending an email to:
|
|
||||||
|
|
||||||
tmux-users+subscribe@googlegroups.com
|
|
||||||
10
.github/lock.yml
vendored
10
.github/lock.yml
vendored
@@ -1,10 +0,0 @@
|
|||||||
daysUntilLock: 180
|
|
||||||
skipCreatedBefore: false
|
|
||||||
exemptLabels: []
|
|
||||||
lockLabel: false
|
|
||||||
lockComment: >
|
|
||||||
This thread has been automatically locked since there has not been
|
|
||||||
any recent activity after it was closed. Please open a new issue for
|
|
||||||
related bugs.
|
|
||||||
setLockReason: false
|
|
||||||
#only: issues
|
|
||||||
21
.gitignore
vendored
21
.gitignore
vendored
@@ -1,21 +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
|
|
||||||
cmd-parse.c
|
|
||||||
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>
|
|
||||||
16
.travis.yml
16
.travis.yml
@@ -1,16 +0,0 @@
|
|||||||
language: c
|
|
||||||
|
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
- osx
|
|
||||||
|
|
||||||
compiler:
|
|
||||||
- gcc
|
|
||||||
- clang
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; fi
|
|
||||||
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -y install bison autotools-dev libncurses5-dev libevent-dev pkg-config libutempter-dev build-essential; fi
|
|
||||||
|
|
||||||
script:
|
|
||||||
- ./autogen.sh && ./configure && make
|
|
||||||
18
COPYING
18
COPYING
@@ -1,18 +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. 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.
|
|
||||||
375
FAQ
Normal file
375
FAQ
Normal file
@@ -0,0 +1,375 @@
|
|||||||
|
tmux frequently asked questions
|
||||||
|
|
||||||
|
******************************************************************************
|
||||||
|
* 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 and GNU screen have many similarities. Some of the main differences I am
|
||||||
|
aware of are (bearing in mind I haven't used screen for a few years now):
|
||||||
|
|
||||||
|
- tmux uses a client-server model. Each server has single Unix domain socket in
|
||||||
|
/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
|
||||||
|
multiple sessions; windows may be moved freely between sessions; and a client
|
||||||
|
may be switched between sessions easily (C-b D). There is one major
|
||||||
|
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.
|
||||||
|
|
||||||
|
- screen has support for updating utmp. Nobody has really come up with a clean,
|
||||||
|
portable way to do this without making tmux setuid or setgid yet.
|
||||||
|
|
||||||
|
- Environment handling is different.
|
||||||
|
|
||||||
|
- tmux tends to be more demanding on the terminal so tends to show up terminal
|
||||||
|
and application bugs which screen does not.
|
||||||
|
|
||||||
|
- screen has wider platform support, for example IRIX and HP-UX, and for odd
|
||||||
|
terminals.
|
||||||
|
|
||||||
|
* I found a bug! What do I do?
|
||||||
|
|
||||||
|
Please send bug reports by email to nicm@users.sourceforge.net or
|
||||||
|
tmux-users@lists.sourceforge.net. Please include as much of the following
|
||||||
|
information as possible:
|
||||||
|
|
||||||
|
- the version of tmux you are running;
|
||||||
|
- the operating system you are using and its version;
|
||||||
|
- the terminal emulator you are using and the TERM setting when tmux was
|
||||||
|
started;
|
||||||
|
- a description of the problem;
|
||||||
|
- if the problem is repeatable, the steps to repeat the problem;
|
||||||
|
- for screen corruption issues, a screenshot and the output of "infocmp $TERM"
|
||||||
|
from outside tmux are often very useful.
|
||||||
|
|
||||||
|
* Why doesn't tmux do $x?
|
||||||
|
|
||||||
|
Please send feature requests by email to nicm@users.sourceforge.net.
|
||||||
|
|
||||||
|
* Why do you use the screen terminal description inside tmux? It sucks.
|
||||||
|
|
||||||
|
It is already widely available. It is planned to change to something else such
|
||||||
|
as xterm-xfree86 at some point, if possible.
|
||||||
|
|
||||||
|
* I don't see any colour in my terminal! Help!
|
||||||
|
|
||||||
|
On some platforms, common terminal descriptions such as xterm do not include
|
||||||
|
colour. screen ignores this, tmux does not. If the terminal emulator in use
|
||||||
|
supports colour, use a value for TERM which correctly lists this, such as
|
||||||
|
xterm-color.
|
||||||
|
|
||||||
|
* tmux freezes my terminal when I attach to a session. I even have to kill -9
|
||||||
|
the shell it was started from to recover!
|
||||||
|
|
||||||
|
Some consoles really really don't like attempts to set the window title. Tell
|
||||||
|
tmux not to do this by turning off the "set-titles" option (you can do this
|
||||||
|
in .tmux.conf):
|
||||||
|
|
||||||
|
set -g set-titles off
|
||||||
|
|
||||||
|
If this doesn't fix it, send a bug report.
|
||||||
|
|
||||||
|
* Why is C-b the prefix key? How do I change it?
|
||||||
|
|
||||||
|
The default key is C-b because the prototype of tmux was originally developed
|
||||||
|
inside screen and C-b was chosen not to clash with the screen meta key. It
|
||||||
|
also has the advantage of not interfering with the use of C-a for start-of-line
|
||||||
|
in emacs and the shell (although it does interfere with previous-character).
|
||||||
|
|
||||||
|
Changing is simple: change the "prefix-key" option, and - if required - move
|
||||||
|
the binding of the "send-prefix" command from C-b (C-b C-b sends C-b by
|
||||||
|
default) to the new key. For example:
|
||||||
|
|
||||||
|
set -g prefix C-a
|
||||||
|
unbind C-b
|
||||||
|
bind C-a send-prefix
|
||||||
|
|
||||||
|
* How do I use UTF-8?
|
||||||
|
|
||||||
|
When running tmux in a UTF-8 capable terminal, UTF-8 must be turned on in tmux;
|
||||||
|
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
|
||||||
|
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:
|
||||||
|
|
||||||
|
$ 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?
|
||||||
|
|
||||||
|
Provided the underlying terminal supports 256 colours, it is usually sufficient
|
||||||
|
to add the following to ~/.tmux.conf:
|
||||||
|
|
||||||
|
set -g default-terminal "screen-256color"
|
||||||
|
|
||||||
|
Note that some platforms do not support "screen-256color" ("infocmp
|
||||||
|
screen-256color" will return an error) - in this case see the next entry in
|
||||||
|
this FAQ.
|
||||||
|
|
||||||
|
tmux attempts to detect a 256 colour terminal both by looking at the colors
|
||||||
|
terminfo entry and by looking for the string "256col" in the TERM environment
|
||||||
|
variable.
|
||||||
|
|
||||||
|
If both these methods fail, the -2 flag may be passed to tmux when attaching
|
||||||
|
to a session to indicate the terminal supports 256 colours.
|
||||||
|
|
||||||
|
* vim or $otherprogram doesn't display 256 colours. What's up?
|
||||||
|
|
||||||
|
Some programs attempt to detect the number of colours a terminal is capable of
|
||||||
|
by checking the colors terminfo or Co termcap entry. However, this is not
|
||||||
|
reliable, and in any case is missing from the "screen" terminal description
|
||||||
|
used inside tmux.
|
||||||
|
|
||||||
|
There are two options (aside from using "screen-256color") to allow programs to
|
||||||
|
recognise they are running on a 256-colour terminal inside tmux:
|
||||||
|
|
||||||
|
- Manually force the application to use 256 colours always or if TERM is set to
|
||||||
|
screen. For vim, you can do this by overriding the t_Co option, see
|
||||||
|
http://vim.wikia.com/wiki/256_colors_in_vim.
|
||||||
|
- Creating a custom terminfo file that includes colors#256 in ~/.terminfo and
|
||||||
|
using it instead. These may be compiled with tic(1).
|
||||||
|
|
||||||
|
* How do I make Ctrl-PgUp and Ctrl-PgDn work in vim?
|
||||||
|
|
||||||
|
tmux supports passing through ctrl (and where supported by the client terminal,
|
||||||
|
alt and shift) modifiers to function keys using xterm(1)-style key sequences.
|
||||||
|
This may be enabled per window, or globally with the tmux command:
|
||||||
|
|
||||||
|
setw -g xterm-keys on
|
||||||
|
|
||||||
|
Because the TERM variable inside tmux must be set to "screen", vim will not
|
||||||
|
automatically detect these keys are available; however, the appropriate key
|
||||||
|
sequences can be overridden in .vimrc using the following:
|
||||||
|
|
||||||
|
if &term == "screen"
|
||||||
|
set t_kN=^[[6;*~
|
||||||
|
set t_kP=^[[5;*~
|
||||||
|
endif
|
||||||
|
|
||||||
|
And similarly for any other keys for which modifiers are desired.
|
||||||
|
|
||||||
|
Please note that the "xterm-keys" setting may affect other programs, in the
|
||||||
|
same way as running them in a standard xterm; for example most shells do not
|
||||||
|
expect to receive xterm(1)-style key sequences so this setting may prevent keys
|
||||||
|
such as ctrl-left and ctrl-right working correctly. tmux also passes through
|
||||||
|
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
|
||||||
|
would be welcome.
|
||||||
|
|
||||||
|
vim users may also want to set the "ttyfast" option 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
|
||||||
|
elinks attempts to guess by looking at the environment. Rather than looking for
|
||||||
|
TERM=screen, it uses the STY variable to detect if it is running in screen;
|
||||||
|
tmux does not use this so the check fails. A workaround is to set STY before
|
||||||
|
running elinks.
|
||||||
|
|
||||||
|
The following shell function does this, and also clears the window title on
|
||||||
|
exit (elinks, for some strange reason, sets it to the value of TERM):
|
||||||
|
|
||||||
|
elinks() {
|
||||||
|
STY= `which elinks` $*
|
||||||
|
echo -ne \\033]0\;\\007;
|
||||||
|
}
|
||||||
|
|
||||||
|
* What is the proper way to escape characters with #(command)?
|
||||||
|
|
||||||
|
When using the #(command) construction to include the output from a command in
|
||||||
|
the status line, the command will be parsed twice. First, when it's read by the
|
||||||
|
configuration file or the command-prompt parser, and second when the status
|
||||||
|
line is being drawn and the command is passed to the shell. For example, to
|
||||||
|
echo the string "(test)" to the status line, either single or double quotes
|
||||||
|
could be used:
|
||||||
|
|
||||||
|
set -g status-right "#(echo \\\\(test\\\\))"
|
||||||
|
set -g status-right '#(echo \\\(test\\\))'
|
||||||
|
|
||||||
|
In both cases, the status-right option will be set to the string "#(echo
|
||||||
|
\\(test\\))" and the command executed will be "echo \(test\)".
|
||||||
|
|
||||||
|
* tmux uses too much CPU. What do I do?
|
||||||
|
|
||||||
|
Automatic window renaming may use a lot of CPU, particularly on slow computers:
|
||||||
|
if this is a problem, turn it off with "setw -g automatic-rename off". If this
|
||||||
|
doesn't fix it, please report the problem.
|
||||||
|
|
||||||
|
* I use PuTTY and my tmux window pane separators are all qqqqqqqqq's!
|
||||||
|
|
||||||
|
PuTTY is using a character set translation that doesn't support ACS line
|
||||||
|
drawing. With a Unicode font, try setting PuTTY to use a different translation
|
||||||
|
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
|
||||||
|
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?
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
* How can I open a new window in the same directory as the current window?
|
||||||
|
|
||||||
|
One option is to just run "TMUX= tmux" in the window. However, this only works if no
|
||||||
|
command is running, so that you can input the command.
|
||||||
|
|
||||||
|
A workaround is to let tmux know about the current path through an environment
|
||||||
|
variable. To do so, use the following command:
|
||||||
|
|
||||||
|
[ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD
|
||||||
|
|
||||||
|
Which sets TMUXPWD_i (where i is the number of the current window) to the path
|
||||||
|
of the current directory. This command can be added to PS1, for example:
|
||||||
|
|
||||||
|
PS1='$([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD)\h$ '
|
||||||
|
|
||||||
|
When a new window is created, the shell should be asked to change
|
||||||
|
directory. You can define a new binding (for example, if using GNU bash):
|
||||||
|
|
||||||
|
bind-key C-c run-shell 'tmux neww "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'
|
||||||
|
|
||||||
|
This solution will work even if a command is currently running in the terminal,
|
||||||
|
but it will not work from a window that has just been swapped with another
|
||||||
|
because TMUXPWD_i will not be updated after a swap. However, once a new prompt
|
||||||
|
is displayed, TMUXPWD_i is updated properly.
|
||||||
|
|
||||||
|
* tmux doesn't start with "daemon failed"
|
||||||
|
|
||||||
|
tmux shows something similar to this when started:
|
||||||
|
|
||||||
|
fatal: server_start: daemon failed: No such file or directory
|
||||||
|
fatal: main_dispatch: imsg_read failed
|
||||||
|
|
||||||
|
A possible reason is that /dev/null is not a character device or is otherwise
|
||||||
|
inaccessible.
|
||||||
|
|
||||||
|
Check with:
|
||||||
|
|
||||||
|
file /dev/null
|
||||||
|
ls -l /dev/null
|
||||||
|
|
||||||
|
If it is not a character device or has incorrect permissions, it can typically
|
||||||
|
be recreated with:
|
||||||
|
|
||||||
|
cd /dev && rm null && ./MAKEDEV null
|
||||||
|
|
||||||
|
$Id: FAQ,v 1.41 2010-12-15 23:31:30 nicm Exp $
|
||||||
87
GNUmakefile
Normal file
87
GNUmakefile
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
# $Id: GNUmakefile,v 1.130 2010-12-27 21:32:16 tcunha Exp $
|
||||||
|
#
|
||||||
|
# Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
VERSION= 1.4
|
||||||
|
|
||||||
|
#FDEBUG= 1
|
||||||
|
|
||||||
|
CC?= cc
|
||||||
|
CFLAGS+= -DBUILD="\"$(VERSION)\""
|
||||||
|
LDFLAGS+= -L/usr/local/lib
|
||||||
|
LIBS+=
|
||||||
|
|
||||||
|
# Sun CC
|
||||||
|
ifneq ($(shell ($(CC) -V 2>&1|awk '/Sun C/' || true)), )
|
||||||
|
CFLAGS+= -erroff=E_EMPTY_DECLARATION
|
||||||
|
FDEBUG=
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef FDEBUG
|
||||||
|
CFLAGS+= -g -ggdb -DDEBUG
|
||||||
|
CFLAGS+= -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
|
||||||
|
CFLAGS+= -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
|
||||||
|
CFLAGS+= -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
||||||
|
CFLAGS+= -Wundef -Wbad-function-cast -Winline -Wcast-align
|
||||||
|
endif
|
||||||
|
|
||||||
|
# This sort of sucks but gets rid of the stupid warning and should work on
|
||||||
|
# most platforms...
|
||||||
|
ifeq ($(shell (LC_ALL=C $(CC) -v 2>&1|awk '/gcc version 4|clang/') || true), )
|
||||||
|
CPPFLAGS:= -I. -I- $(CPPFLAGS)
|
||||||
|
else
|
||||||
|
CPPFLAGS:= -iquote. $(CPPFLAGS)
|
||||||
|
ifdef FDEBUG
|
||||||
|
CFLAGS+= -Wno-pointer-sign
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
PREFIX?= /usr/local
|
||||||
|
INSTALL?= install
|
||||||
|
INSTALLDIR= $(INSTALL) -d
|
||||||
|
INSTALLBIN= $(INSTALL) -m 555
|
||||||
|
INSTALLMAN= $(INSTALL) -m 444
|
||||||
|
|
||||||
|
SRCS= $(shell echo *.c|LC_ALL=C sed 's|osdep-[a-z0-9]*.c||g')
|
||||||
|
include config.mk
|
||||||
|
OBJS= $(patsubst %.c,%.o,$(SRCS))
|
||||||
|
|
||||||
|
all: tmux
|
||||||
|
|
||||||
|
tmux: $(OBJS)
|
||||||
|
$(CC) $(LDFLAGS) -o tmux $+ $(LIBS)
|
||||||
|
|
||||||
|
depend: $(SRCS)
|
||||||
|
$(CC) $(CPPFLAGS) $(CFLAGS) -MM $(SRCS) > .depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f tmux *.o *~ *.core *.log compat/*.o compat/*~
|
||||||
|
|
||||||
|
clean-depend:
|
||||||
|
rm -f .depend
|
||||||
|
|
||||||
|
clean-all: clean clean-depend
|
||||||
|
rm -f config.h config.mk
|
||||||
|
|
||||||
|
install: all
|
||||||
|
$(INSTALLDIR) $(DESTDIR)$(PREFIX)/bin
|
||||||
|
$(INSTALLBIN) tmux $(DESTDIR)$(PREFIX)/bin/tmux
|
||||||
|
$(INSTALLDIR) $(DESTDIR)$(PREFIX)/man/man1
|
||||||
|
$(INSTALLMAN) tmux.1 $(DESTDIR)$(PREFIX)/man/man1/tmux.1
|
||||||
|
|
||||||
|
-include .depend
|
||||||
84
Makefile
Normal file
84
Makefile
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# $Id: Makefile,v 1.162 2010-12-27 21:32:16 tcunha Exp $
|
||||||
|
#
|
||||||
|
# Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
|
||||||
|
.SUFFIXES: .c .o
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
VERSION= 1.4
|
||||||
|
|
||||||
|
#FDEBUG= 1
|
||||||
|
|
||||||
|
CC?= cc
|
||||||
|
CFLAGS+= -DBUILD="\"$(VERSION)\""
|
||||||
|
LDFLAGS+= -L/usr/local/lib
|
||||||
|
LIBS+=
|
||||||
|
|
||||||
|
.ifdef FDEBUG
|
||||||
|
CFLAGS+= -g -ggdb -DDEBUG
|
||||||
|
CFLAGS+= -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
|
||||||
|
CFLAGS+= -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
|
||||||
|
CFLAGS+= -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
||||||
|
CFLAGS+= -Wundef -Wbad-function-cast -Winline -Wcast-align
|
||||||
|
.endif
|
||||||
|
|
||||||
|
# This sort of sucks but gets rid of the stupid warning and should work on
|
||||||
|
# most platforms...
|
||||||
|
CCV!= (LC_ALL=C ${CC} -v 2>&1|awk '/gcc version 4|clang/') || true
|
||||||
|
.if empty(CCV)
|
||||||
|
CPPFLAGS:= -I. -I- -I/usr/local/include ${CPPFLAGS}
|
||||||
|
.else
|
||||||
|
CPPFLAGS:= -iquote. -I/usr/local/include ${CPPFLAGS}
|
||||||
|
.ifdef FDEBUG
|
||||||
|
CFLAGS+= -Wno-pointer-sign
|
||||||
|
.endif
|
||||||
|
.endif
|
||||||
|
|
||||||
|
PREFIX?= /usr/local
|
||||||
|
INSTALL?= install
|
||||||
|
INSTALLDIR= ${INSTALL} -d
|
||||||
|
INSTALLBIN= ${INSTALL} -m 555
|
||||||
|
INSTALLMAN= ${INSTALL} -m 444
|
||||||
|
|
||||||
|
SRCS!= echo *.c|LC_ALL=C sed 's|osdep-[a-z0-9]*.c||g'
|
||||||
|
.include "config.mk"
|
||||||
|
OBJS= ${SRCS:S/.c/.o/}
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CPPFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
|
||||||
|
|
||||||
|
all: tmux
|
||||||
|
|
||||||
|
tmux: ${OBJS}
|
||||||
|
${CC} ${LDFLAGS} -o tmux ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
depend:
|
||||||
|
mkdep ${CPPFLAGS} ${CFLAGS} ${SRCS:M*.c}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f tmux *.o *~ *.core *.log compat/*.o compat/*~
|
||||||
|
|
||||||
|
clean-depend:
|
||||||
|
rm -f .depend
|
||||||
|
|
||||||
|
clean-all: clean clean-depend
|
||||||
|
rm -f config.h config.mk
|
||||||
|
|
||||||
|
install: all
|
||||||
|
${INSTALLDIR} ${DESTDIR}${PREFIX}/bin
|
||||||
|
${INSTALLBIN} tmux ${DESTDIR}${PREFIX}/bin/
|
||||||
|
${INSTALLDIR} ${DESTDIR}${PREFIX}/man/man1
|
||||||
|
${INSTALLMAN} tmux.1 ${DESTDIR}${PREFIX}/man/man1/
|
||||||
209
Makefile.am
209
Makefile.am
@@ -1,209 +0,0 @@
|
|||||||
# Makefile.am
|
|
||||||
|
|
||||||
# Obvious program stuff.
|
|
||||||
bin_PROGRAMS = tmux
|
|
||||||
CLEANFILES = tmux.1.mdoc tmux.1.man cmd-parse.c
|
|
||||||
|
|
||||||
# Distribution tarball options.
|
|
||||||
EXTRA_DIST = \
|
|
||||||
CHANGES README README.ja COPYING example_tmux.conf \
|
|
||||||
osdep-*.c mdoc2man.awk tmux.1
|
|
||||||
dist_EXTRA_tmux_SOURCES = compat/*.[ch]
|
|
||||||
|
|
||||||
# Preprocessor flags.
|
|
||||||
AM_CPPFLAGS += @XOPEN_DEFINES@ \
|
|
||||||
-DTMUX_VERSION="\"@VERSION@\"" \
|
|
||||||
-DTMUX_CONF="\"$(sysconfdir)/tmux.conf:~/.tmux.conf:~/.config/tmux/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-tree.c \
|
|
||||||
cmd-command-prompt.c \
|
|
||||||
cmd-confirm-before.c \
|
|
||||||
cmd-copy-mode.c \
|
|
||||||
cmd-detach-client.c \
|
|
||||||
cmd-display-menu.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-load-buffer.c \
|
|
||||||
cmd-lock-server.c \
|
|
||||||
cmd-move-window.c \
|
|
||||||
cmd-new-session.c \
|
|
||||||
cmd-new-window.c \
|
|
||||||
cmd-parse.y \
|
|
||||||
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-resize-window.c \
|
|
||||||
cmd-respawn-pane.c \
|
|
||||||
cmd-respawn-window.c \
|
|
||||||
cmd-rotate-window.c \
|
|
||||||
cmd-run-shell.c \
|
|
||||||
cmd-save-buffer.c \
|
|
||||||
cmd-select-layout.c \
|
|
||||||
cmd-select-pane.c \
|
|
||||||
cmd-select-window.c \
|
|
||||||
cmd-send-keys.c \
|
|
||||||
cmd-set-buffer.c \
|
|
||||||
cmd-set-environment.c \
|
|
||||||
cmd-set-option.c \
|
|
||||||
cmd-show-environment.c \
|
|
||||||
cmd-show-messages.c \
|
|
||||||
cmd-show-options.c \
|
|
||||||
cmd-source-file.c \
|
|
||||||
cmd-split-window.c \
|
|
||||||
cmd-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 \
|
|
||||||
file.c \
|
|
||||||
format.c \
|
|
||||||
format-draw.c \
|
|
||||||
grid-view.c \
|
|
||||||
grid.c \
|
|
||||||
input-keys.c \
|
|
||||||
input.c \
|
|
||||||
job.c \
|
|
||||||
key-bindings.c \
|
|
||||||
key-string.c \
|
|
||||||
layout-custom.c \
|
|
||||||
layout-set.c \
|
|
||||||
layout.c \
|
|
||||||
log.c \
|
|
||||||
menu.c \
|
|
||||||
mode-tree.c \
|
|
||||||
names.c \
|
|
||||||
notify.c \
|
|
||||||
options-table.c \
|
|
||||||
options.c \
|
|
||||||
paste.c \
|
|
||||||
proc.c \
|
|
||||||
regsub.c \
|
|
||||||
resize.c \
|
|
||||||
screen-redraw.c \
|
|
||||||
screen-write.c \
|
|
||||||
screen.c \
|
|
||||||
server-client.c \
|
|
||||||
server-fn.c \
|
|
||||||
server.c \
|
|
||||||
session.c \
|
|
||||||
spawn.c \
|
|
||||||
status.c \
|
|
||||||
style.c \
|
|
||||||
tmux.c \
|
|
||||||
tmux.h \
|
|
||||||
tty-acs.c \
|
|
||||||
tty-keys.c \
|
|
||||||
tty-term.c \
|
|
||||||
tty.c \
|
|
||||||
utf8.c \
|
|
||||||
window-buffer.c \
|
|
||||||
window-client.c \
|
|
||||||
window-clock.c \
|
|
||||||
window-copy.c \
|
|
||||||
window-tree.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
|
|
||||||
66
NOTES
Normal file
66
NOTES
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
Welcome to tmux!
|
||||||
|
|
||||||
|
tmux is a "terminal multiplexer", it enables a number of terminals (or windows)
|
||||||
|
to be accessed and controlled from a single terminal. tmux is intended to be a
|
||||||
|
simple, modern, BSD-licensed alternative to programs such as GNU screen.
|
||||||
|
|
||||||
|
This release runs on OpenBSD, FreeBSD, NetBSD, Linux and OS X and may still
|
||||||
|
run on Solaris and AIX (although they haven't been tested in a while). It is
|
||||||
|
usable, although there remain a number of missing features and some remaining
|
||||||
|
bugs are expected.
|
||||||
|
|
||||||
|
Since the 1.2 release that tmux depends on libevent. Download the stable
|
||||||
|
version from:
|
||||||
|
|
||||||
|
http://www.monkey.org/~provos/libevent/
|
||||||
|
|
||||||
|
tmux consists of a server part and multiple clients. The server is created when
|
||||||
|
required and runs continuously unless killed by the user. Clients access the
|
||||||
|
server through a socket in /tmp. Multiple sessions may be created on a single
|
||||||
|
server and attached to a number of clients. Each session may then have a number
|
||||||
|
of windows and windows may be linked to a number of sessions. Commands are
|
||||||
|
available to create, rename and destroy windows and sessions; to attach and
|
||||||
|
detach sessions from client terminals; to set configuration options; to split
|
||||||
|
windows into several simultaneously displayed panes; and to bind and unbind
|
||||||
|
command keys (invoked preceded by a prefix key, by default ctrl-b). Please see
|
||||||
|
the tmux(1) man page for further information.
|
||||||
|
|
||||||
|
A more extensive, but rough, todo list is included in the TODO file.
|
||||||
|
|
||||||
|
tmux also depends on several features of the client terminal (TERM), if these
|
||||||
|
are missing it may refuse to run, or not behave correctly.
|
||||||
|
|
||||||
|
A Vim syntax file is available in the examples directory. To install it:
|
||||||
|
|
||||||
|
- Drop the file in the syntax directory in your runtimepath (such as
|
||||||
|
~/.vim/syntax/tmux.vim).
|
||||||
|
- Make the filetype recognisable by adding the following to filetype.vim
|
||||||
|
in your runtimepath (~/.vim/filetype.vim):
|
||||||
|
|
||||||
|
augroup filetypedetect
|
||||||
|
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
- Switch on syntax highlighting by adding "syntax enable" to your vimrc file.
|
||||||
|
|
||||||
|
For debugging, running tmux with -v or -vv will generate server and client log
|
||||||
|
files in the current directory.
|
||||||
|
|
||||||
|
tmux mailing lists are available; visit:
|
||||||
|
|
||||||
|
https://sourceforge.net/mail/?group_id=200378
|
||||||
|
|
||||||
|
Bug reports, feature suggestions and especially code contributions are most
|
||||||
|
welcome. Please send by email to:
|
||||||
|
|
||||||
|
nicm@users.sf.net
|
||||||
|
|
||||||
|
This file and the CHANGES, FAQ and TODO files are licensed under the ISC
|
||||||
|
license. Files under examples/ remain copyright their authors unless otherwise
|
||||||
|
stated in the file but permission has been received to distribute them with
|
||||||
|
tmux. All other files have a license and copyright notice at their
|
||||||
|
start. Please contact me with any queries.
|
||||||
|
|
||||||
|
-- Nicholas Marriott <nicm@users.sf.net>
|
||||||
|
|
||||||
|
$Id: NOTES,v 1.54 2010-12-27 21:36:37 tcunha Exp $
|
||||||
75
README
75
README
@@ -1,75 +0,0 @@
|
|||||||
Welcome to tmux!
|
|
||||||
|
|
||||||
tmux is a terminal multiplexer: it enables a number of terminals to be created,
|
|
||||||
accessed, and controlled from a single screen. tmux may be detached from a
|
|
||||||
screen and continue running in the background, then later reattached.
|
|
||||||
|
|
||||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, OS X and Solaris.
|
|
||||||
|
|
||||||
* Dependencies
|
|
||||||
|
|
||||||
tmux depends on libevent 2.x, available from:
|
|
||||||
|
|
||||||
https://github.com/libevent/libevent/releases/latest
|
|
||||||
|
|
||||||
It also depends on ncurses, available from:
|
|
||||||
|
|
||||||
https://invisible-mirror.net/archives/ncurses/
|
|
||||||
|
|
||||||
* Installation
|
|
||||||
|
|
||||||
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 - note that this requires
|
|
||||||
autoconf, automake and pkg-config:
|
|
||||||
|
|
||||||
$ git clone https://github.com/tmux/tmux.git
|
|
||||||
$ cd tmux
|
|
||||||
$ sh autogen.sh
|
|
||||||
$ ./configure && make
|
|
||||||
|
|
||||||
* Contributing
|
|
||||||
|
|
||||||
Bug reports, feature suggestions and especially code contributions are most
|
|
||||||
welcome. Please send by email to:
|
|
||||||
|
|
||||||
tmux-users@googlegroups.com
|
|
||||||
|
|
||||||
Or open a GitHub issue or pull request.
|
|
||||||
|
|
||||||
* Documentation
|
|
||||||
|
|
||||||
For documentation on using tmux, see the tmux.1 manpage. View it from the
|
|
||||||
source tree with:
|
|
||||||
|
|
||||||
$ nroff -mdoc tmux.1|less
|
|
||||||
|
|
||||||
A small example configuration is in example_tmux.conf.
|
|
||||||
|
|
||||||
A bash(1) completion file is at:
|
|
||||||
|
|
||||||
https://github.com/imomaliev/tmux-bash-completion
|
|
||||||
|
|
||||||
For debugging, run tmux with -v and -vv to generate server and client log files
|
|
||||||
in the current directory.
|
|
||||||
|
|
||||||
* Support
|
|
||||||
|
|
||||||
The tmux mailing list for general discussion and bug reports is:
|
|
||||||
|
|
||||||
https://groups.google.com/forum/#!forum/tmux-users
|
|
||||||
|
|
||||||
Subscribe by sending an email to:
|
|
||||||
|
|
||||||
tmux-users+subscribe@googlegroups.com
|
|
||||||
|
|
||||||
* License
|
|
||||||
|
|
||||||
This file and the CHANGES files are licensed under the ISC license. All other
|
|
||||||
files have a license and copyright notice at their start.
|
|
||||||
62
README.ja
62
README.ja
@@ -1,62 +0,0 @@
|
|||||||
tmuxへようこそ!
|
|
||||||
|
|
||||||
tmuxはターミナルマルチプレクサーです。複数のターミナルを一つのスクリーン内に作成し、操作することができます。
|
|
||||||
バックグラウンドで処理を実行中に一度スクリーンから離れて後から復帰することも可能です。
|
|
||||||
|
|
||||||
OpenBSD、FreeBSD、NetBSD、Linux、OS X、Solarisで実行できます。
|
|
||||||
|
|
||||||
tmuxはlibevent 2.x.に依存します。 下記からダウンロードしてください。
|
|
||||||
|
|
||||||
http://libevent.org
|
|
||||||
|
|
||||||
また、ncursesも必要です。こちらからどうぞ。
|
|
||||||
|
|
||||||
http://invisible-island.net/ncurses/
|
|
||||||
|
|
||||||
tarballでのtmuxのビルドとインストール方法。
|
|
||||||
|
|
||||||
$ ./configure && make
|
|
||||||
$ sudo make install
|
|
||||||
|
|
||||||
tmuxはutmp(5)をアップデートするためにutempterを使うことができます。もしインストール済みであればオプション「--enable-utempter」をつけて実行してください。
|
|
||||||
|
|
||||||
リポジトリから最新バージョンを手に入れるためには下記を実行。
|
|
||||||
|
|
||||||
$ git clone https://github.com/tmux/tmux.git
|
|
||||||
$ cd tmux
|
|
||||||
$ sh autogen.sh
|
|
||||||
$ ./configure && make
|
|
||||||
|
|
||||||
(ビルドのためにはlibevent、ncurses libraries、headersに加えて、C compiler、make、autoconf、automake、pkg-configが必要です。)
|
|
||||||
|
|
||||||
詳しい情報はhttp://git-scm.comをご覧ください。修正はメール<tmux-users@googlegroups.com>宛、もしくはhttps://github.com/tmux/tmux/issuesにて受け付けています。
|
|
||||||
|
|
||||||
tmuxのドキュメントについてはtmux.1マニュアルをご覧ください。こちらのコマンドで参照可能です。
|
|
||||||
|
|
||||||
$ nroff -mdoc tmux.1|less
|
|
||||||
|
|
||||||
サンプル設定は本リポジトリのexample_tmux.confに
|
|
||||||
また、bash-completionファイルは下記にあります。
|
|
||||||
|
|
||||||
https://github.com/imomaliev/tmux-bash-completion
|
|
||||||
|
|
||||||
「-v」や「-vv」を指定することでデバッグモードでの起動が可能です。カレントディレクトリにサーバーやクライアントのログファイルが生成されます。
|
|
||||||
|
|
||||||
議論やバグレポート用のメーリングリストにはこちらから参加可能です。
|
|
||||||
|
|
||||||
https://groups.google.com/forum/#!forum/tmux-users
|
|
||||||
|
|
||||||
gitコミットについての連絡先
|
|
||||||
|
|
||||||
https://groups.google.com/forum/#!forum/tmux-git
|
|
||||||
|
|
||||||
購読は<tmux-users+subscribe@googlegroups.com>までメールをお願いします。
|
|
||||||
|
|
||||||
バグレポートや機能追加(特にコードへの貢献)は大歓迎です。こちらにご連絡ください。
|
|
||||||
|
|
||||||
tmux-users@googlegroups.com
|
|
||||||
|
|
||||||
本ファイル、CHANGES、 FAQ、SYNCINGそしてTODOはISC licenseで保護されています。
|
|
||||||
その他のファイルのライセンスや著作権については、ファイルの上部に明記されています。
|
|
||||||
|
|
||||||
-- Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
173
SYNCING
173
SYNCING
@@ -1,173 +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. Make sure configure.ac has the new version number.
|
|
||||||
|
|
||||||
3. Tag with:
|
|
||||||
|
|
||||||
% git tag -a 2.X
|
|
||||||
|
|
||||||
Where "2.X" is the next version.
|
|
||||||
|
|
||||||
Push the tag out with:
|
|
||||||
|
|
||||||
% git push --tags
|
|
||||||
|
|
||||||
4. Build the tarball with 'make dist'.
|
|
||||||
|
|
||||||
5. Check the tarball. If it's good, go here to select the tag just pushed:
|
|
||||||
|
|
||||||
https://github.com/tmux/tmux/tags
|
|
||||||
|
|
||||||
Click the "Add release notes", upload the tarball and add a link in the
|
|
||||||
description field to the CHANGES file.
|
|
||||||
|
|
||||||
6. Clone the tmux.github.io repository, and change the RELEASE version in the
|
|
||||||
Makefile. Commit it, and run 'make' to replace %%RELEASE%%. Push the
|
|
||||||
result out.
|
|
||||||
|
|
||||||
7. Change version back to master in configure.ac.
|
|
||||||
130
TODO
Normal file
130
TODO
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
- better errors when creating new windows/sessions (how?)
|
||||||
|
- implicitly add exec to the commands for new windows (switch to disable it)?
|
||||||
|
- it would be nice to have multichar commands eg C-b K K
|
||||||
|
- commands:
|
||||||
|
extend list-clients to list clients attached to a session (-a for all?)
|
||||||
|
bring back detach-session to detach all clients on a session?
|
||||||
|
- allow fnmatch for -c, so that you can, eg, detach all clients
|
||||||
|
- garbage collect window history (100 lines at a time?) if it hasn't been used
|
||||||
|
in $x time
|
||||||
|
- lift SHRT_MAX limits for history?
|
||||||
|
- flags to centre screen in window
|
||||||
|
- activity/bell should be per-window not per-link? what if it is cur win in
|
||||||
|
session not being watched?
|
||||||
|
- next prev word etc in command prompt
|
||||||
|
- use a better termcap internally instead of screen, perhaps xterm
|
||||||
|
- should be able to move to a hidden pane and it would be moved into view. pane
|
||||||
|
number in status line/top-right would be cool for this
|
||||||
|
- support other mouse modes (highlight etc) and use it in copy mode
|
||||||
|
- set-remain-on-exit is a bit of a hack, some way to do it generically?
|
||||||
|
- clear window title on exit
|
||||||
|
- would be nice to be able to use "--" to mark start of command w/ neww etc
|
||||||
|
to avoid quoting
|
||||||
|
- make command sequences more usable: don't require space after ;, handle
|
||||||
|
errors better
|
||||||
|
- attach should have a flag to create session if it doesn't exist
|
||||||
|
- 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
|
||||||
|
- way to set socket path from config file
|
||||||
|
- what about utmp etc? can tmux update it like screen? setgid?
|
||||||
|
- warts on current naming:
|
||||||
|
- display-time but message-fg/bg/attr
|
||||||
|
- list-* vs show-*
|
||||||
|
- server-info
|
||||||
|
- up-pane/down-pane/swap-pane -U/swap-pane -D vs next-*/previous-*
|
||||||
|
- split-window -> split-pane??
|
||||||
|
- a way for force-width/height to apply to only one pane (how?)
|
||||||
|
- command to list what is actually running in each window with command line,
|
||||||
|
pid (need some adaption of the osdep code)
|
||||||
|
- support for bce
|
||||||
|
- some way to force a screen to use the entire terminal even if it is forced
|
||||||
|
to be smaller by other clients. pan smaller terminal? (like screen F)
|
||||||
|
-- idea of a "view" onto a window, need base x/y offsets for redraw
|
||||||
|
- handle resize better in copy mode
|
||||||
|
- way to copy stuff that is off screen due to resize
|
||||||
|
- commands should be able to succeed or fail and have || or && for command
|
||||||
|
lists
|
||||||
|
- some way to KEEP a command running continually and just use its LAST line of
|
||||||
|
output
|
||||||
|
- bind commands to mouse buttons
|
||||||
|
- UTF-8 to a non-UTF-8 terminal should not be able to balls up
|
||||||
|
the terminal - www/ruby-addressable; make regress
|
||||||
|
- multiple keys could be done with tables, ie have prefixes go and instead
|
||||||
|
bind -n ^A prefix-table "default"
|
||||||
|
where prefix-table sets command lookup table and sets prefix flag, then next
|
||||||
|
key is looked up in that table
|
||||||
|
- support esc-esc to quit in modes
|
||||||
|
- fix ctrl+F1-F4 output. to what?
|
||||||
|
- look into xterm clearing its selection when scrolling etc
|
||||||
|
- better utf8 support: window names, prompt input, message display
|
||||||
|
- session history for client and last-session command
|
||||||
|
- option to change status line colour when current window is in a mode?
|
||||||
|
- option to move copy mode indicator into status line
|
||||||
|
- list-buffer/show-buffer should display UTF-8
|
||||||
|
- selection behaviour closer to vi in vi mode
|
||||||
|
- live update: server started with -U connects to server, requests sessions and
|
||||||
|
windows, receives fds
|
||||||
|
- command to show a tree of sessions-windows-panes (active marked with *)
|
||||||
|
- sort out inheriting config from shell on new sessions/windows:
|
||||||
|
should pick up default-path/termios/etc from client if possible,
|
||||||
|
else leave empty/default
|
||||||
|
- link panes into multiple windows
|
||||||
|
- -h option to capture-pane to capture the history as well
|
||||||
|
- bells should be passed between sessions with visual-bell etc
|
||||||
|
- use screen-256color when started on 256 colour terminal??
|
||||||
|
- if-shell/run-shell should block further command execution in the same command
|
||||||
|
sequence until its shell exits, to allow them to be used from the config file
|
||||||
|
- better session sharing: create-socket command to create socket somewhere (-r
|
||||||
|
flag for readonly)
|
||||||
|
- allow buffer to be specified when copying in copy mode
|
||||||
|
- multiline status line (no?)
|
||||||
|
- flag for absolute pane size to resize-pane
|
||||||
|
- sanity check input to socket
|
||||||
|
- select-buffer command
|
||||||
|
- support title stack, both internally and externally
|
||||||
|
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=1149299+0+archive/2010/freebsd-questions/20100207.freebsd-questions
|
||||||
|
- copy buffers should be global, limit can be server option, nuke copy-buffer
|
||||||
|
command
|
||||||
|
- command to show status line information briefly when it is off
|
||||||
|
- some way to pad # stuff with spaces, #!2T maybe
|
||||||
|
- FreeBSD console problems
|
||||||
|
- a binding to "scroll down and exit at bottom" copy mode
|
||||||
|
- some way to pass keystrokes in copy mode through to underlying window
|
||||||
|
- last window update time and # replacement for it for display-message
|
||||||
|
- find-window across sessions - other ways to make session handling easier?
|
||||||
|
- ' and " should be parsed the same (eg "\e" vs '\e') in config and command
|
||||||
|
prompt?
|
||||||
|
- command to toggle selection not to move it in copy-mode
|
||||||
|
- why are alerts per-winlink? try per window?
|
||||||
|
- audit of escape sequence support vs xterm
|
||||||
|
- support binding keys to mouse (mouse-select-pane -> mouse-keys or something,
|
||||||
|
mouse click == select-pane -t %%, mouse scroll up == copy-mode)
|
||||||
|
- something for -t "last window in session" so a session can be used as a stack
|
||||||
|
- synchronous commands - client sends cmd and blocks, neww/splitw saves client
|
||||||
|
ptr then when program inside died, sends MSG_SOMETHING with wait status to
|
||||||
|
client
|
||||||
|
- documentation improvements - rlpowell's tutorial - build instructions
|
||||||
|
- better configure? with-libevent
|
||||||
|
- bind commands to key sequences?
|
||||||
|
- monitor, bell etc should monitor /all/ panes in the window not just one
|
||||||
|
- a history of commands that can be reversed (reverse member of each command,
|
||||||
|
and a buffer) info() when changing to same window
|
||||||
|
- don't pass UTF-8 through vis for titles
|
||||||
|
- clearing screen should push lines into history
|
||||||
|
- add a unique ever-increasing pane id to each pane, export it in $TMUX_PANE
|
||||||
|
(as %1, %2 etc) and allow it to be used as a target
|
||||||
|
- way to add dest for break-pane; maybe some easier way to unbreak-pane
|
||||||
|
- case insensitive searching
|
||||||
|
- dynamically generated jobs (eg "date ...") do not work well because
|
||||||
|
their entries are never collected, should either store status jobs in
|
||||||
|
a different tree or flush all unused persist jobs every update rather
|
||||||
|
than just updating them
|
||||||
|
- pane-index option like base-index
|
||||||
|
- option to move status line to top
|
||||||
|
- support "xterm2" mouse mode
|
||||||
|
- respawn-pane command
|
||||||
|
- configurable borders and empty space filler for when panes < window?
|
||||||
|
|
||||||
323
alerts.c
323
alerts.c
@@ -1,323 +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_action_applies(struct winlink *, const char *);
|
|
||||||
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 alerts_set_message(struct winlink *, const char *,
|
|
||||||
const char *);
|
|
||||||
|
|
||||||
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_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_action_applies(struct winlink *wl, const char *name)
|
|
||||||
{
|
|
||||||
int action;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* {bell,activity,silence}-action determines when to alert: none means
|
|
||||||
* nothing happens, current means only do something for the current
|
|
||||||
* window and other means only for windows other than the current.
|
|
||||||
*/
|
|
||||||
|
|
||||||
action = options_get_number(wl->session->options, name);
|
|
||||||
if (action == ALERT_ANY)
|
|
||||||
return (1);
|
|
||||||
if (action == ALERT_CURRENT)
|
|
||||||
return (wl == wl->session->curw);
|
|
||||||
if (action == ALERT_OTHER)
|
|
||||||
return (wl != wl->session->curw);
|
|
||||||
return (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) {
|
|
||||||
if (options_get_number(w->options, "monitor-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;
|
|
||||||
|
|
||||||
if (!event_initialized(&w->alerts_timer))
|
|
||||||
evtimer_set(&w->alerts_timer, alerts_timer, w);
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
alerts_reset(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 winlink *wl;
|
|
||||||
struct session *s;
|
|
||||||
|
|
||||||
if (~w->flags & WINDOW_BELL)
|
|
||||||
return (0);
|
|
||||||
if (!options_get_number(w->options, "monitor-bell"))
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
TAILQ_FOREACH(wl, &w->winlinks, wentry)
|
|
||||||
wl->session->flags &= ~SESSION_ALERTED;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(wl, &w->winlinks, wentry) {
|
|
||||||
/*
|
|
||||||
* Bells are allowed even if there is an existing bell (so do
|
|
||||||
* not check WINLINK_BELL).
|
|
||||||
*/
|
|
||||||
s = wl->session;
|
|
||||||
if (s->curw != wl) {
|
|
||||||
wl->flags |= WINLINK_BELL;
|
|
||||||
server_status_session(s);
|
|
||||||
}
|
|
||||||
if (!alerts_action_applies(wl, "bell-action"))
|
|
||||||
continue;
|
|
||||||
notify_winlink("alert-bell", wl);
|
|
||||||
|
|
||||||
if (s->flags & SESSION_ALERTED)
|
|
||||||
continue;
|
|
||||||
s->flags |= SESSION_ALERTED;
|
|
||||||
|
|
||||||
alerts_set_message(wl, "Bell", "visual-bell");
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
wl->flags |= WINLINK_ACTIVITY;
|
|
||||||
server_status_session(s);
|
|
||||||
}
|
|
||||||
if (!alerts_action_applies(wl, "activity-action"))
|
|
||||||
continue;
|
|
||||||
notify_winlink("alert-activity", wl);
|
|
||||||
|
|
||||||
if (s->flags & SESSION_ALERTED)
|
|
||||||
continue;
|
|
||||||
s->flags |= SESSION_ALERTED;
|
|
||||||
|
|
||||||
alerts_set_message(wl, "Activity", "visual-activity");
|
|
||||||
}
|
|
||||||
|
|
||||||
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") == 0)
|
|
||||||
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) {
|
|
||||||
wl->flags |= WINLINK_SILENCE;
|
|
||||||
server_status_session(s);
|
|
||||||
}
|
|
||||||
if (!alerts_action_applies(wl, "silence-action"))
|
|
||||||
continue;
|
|
||||||
notify_winlink("alert-silence", wl);
|
|
||||||
|
|
||||||
if (s->flags & SESSION_ALERTED)
|
|
||||||
continue;
|
|
||||||
s->flags |= SESSION_ALERTED;
|
|
||||||
|
|
||||||
alerts_set_message(wl, "Silence", "visual-silence");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (WINDOW_SILENCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
alerts_set_message(struct winlink *wl, const char *type, const char *option)
|
|
||||||
{
|
|
||||||
struct client *c;
|
|
||||||
int visual;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We have found an alert (bell, activity or silence), so we need to
|
|
||||||
* pass it on to the user. For each client attached to this session,
|
|
||||||
* decide whether a bell, message or both is needed.
|
|
||||||
*
|
|
||||||
* If visual-{bell,activity,silence} is on, then a message is
|
|
||||||
* substituted for a bell; if it is off, a bell is sent as normal; both
|
|
||||||
* mean both a bell and message is sent.
|
|
||||||
*/
|
|
||||||
|
|
||||||
visual = options_get_number(wl->session->options, option);
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
|
||||||
if (c->session != wl->session || c->flags & CLIENT_CONTROL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (visual == VISUAL_OFF || visual == VISUAL_BOTH)
|
|
||||||
tty_putcode(&c->tty, TTYC_BEL);
|
|
||||||
if (visual == VISUAL_OFF)
|
|
||||||
continue;
|
|
||||||
if (c->session->curw == wl)
|
|
||||||
status_message_set(c, "%s in current window", type);
|
|
||||||
else
|
|
||||||
status_message_set(c, "%s in window %d", type, wl->idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
345
arguments.c
345
arguments.c
@@ -1,345 +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_value {
|
|
||||||
char *value;
|
|
||||||
TAILQ_ENTRY(args_value) entry;
|
|
||||||
};
|
|
||||||
TAILQ_HEAD(args_values, args_value);
|
|
||||||
|
|
||||||
struct args_entry {
|
|
||||||
u_char flag;
|
|
||||||
struct args_values values;
|
|
||||||
u_int count;
|
|
||||||
RB_ENTRY(args_entry) entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
|
||||||
optarg = NULL;
|
|
||||||
|
|
||||||
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);
|
|
||||||
optarg = NULL;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
struct args_value *value;
|
|
||||||
struct args_value *value1;
|
|
||||||
|
|
||||||
cmd_free_argv(args->argc, args->argv);
|
|
||||||
|
|
||||||
RB_FOREACH_SAFE(entry, args_tree, &args->tree, entry1) {
|
|
||||||
RB_REMOVE(args_tree, &args->tree, entry);
|
|
||||||
TAILQ_FOREACH_SAFE(value, &entry->values, entry, value1) {
|
|
||||||
TAILQ_REMOVE(&entry->values, value, entry);
|
|
||||||
free(value->value);
|
|
||||||
free(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add value to string. */
|
|
||||||
static void
|
|
||||||
args_print_add_value(char **buf, size_t *len, struct args_entry *entry,
|
|
||||||
struct args_value *value)
|
|
||||||
{
|
|
||||||
char *escaped;
|
|
||||||
|
|
||||||
if (**buf != '\0')
|
|
||||||
args_print_add(buf, len, " -%c ", entry->flag);
|
|
||||||
else
|
|
||||||
args_print_add(buf, len, "-%c ", entry->flag);
|
|
||||||
|
|
||||||
escaped = args_escape(value->value);
|
|
||||||
args_print_add(buf, len, "%s", escaped);
|
|
||||||
free(escaped);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add argument to string. */
|
|
||||||
static void
|
|
||||||
args_print_add_argument(char **buf, size_t *len, const char *argument)
|
|
||||||
{
|
|
||||||
char *escaped;
|
|
||||||
|
|
||||||
if (**buf != '\0')
|
|
||||||
args_print_add(buf, len, " ");
|
|
||||||
|
|
||||||
escaped = args_escape(argument);
|
|
||||||
args_print_add(buf, len, "%s", escaped);
|
|
||||||
free(escaped);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print a set of arguments. */
|
|
||||||
char *
|
|
||||||
args_print(struct args *args)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
char *buf;
|
|
||||||
int i;
|
|
||||||
u_int j;
|
|
||||||
struct args_entry *entry;
|
|
||||||
struct args_value *value;
|
|
||||||
|
|
||||||
len = 1;
|
|
||||||
buf = xcalloc(1, len);
|
|
||||||
|
|
||||||
/* Process the flags first. */
|
|
||||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
|
||||||
if (!TAILQ_EMPTY(&entry->values))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (*buf == '\0')
|
|
||||||
args_print_add(&buf, &len, "-");
|
|
||||||
for (j = 0; j < entry->count; j++)
|
|
||||||
args_print_add(&buf, &len, "%c", entry->flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then the flags with arguments. */
|
|
||||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
|
||||||
TAILQ_FOREACH(value, &entry->values, entry)
|
|
||||||
args_print_add_value(&buf, &len, entry, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* And finally the argument vector. */
|
|
||||||
for (i = 0; i < args->argc; i++)
|
|
||||||
args_print_add_argument(&buf, &len, args->argv[i]);
|
|
||||||
|
|
||||||
return (buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Escape an argument. */
|
|
||||||
char *
|
|
||||||
args_escape(const char *s)
|
|
||||||
{
|
|
||||||
static const char quoted[] = " #\"';${}";
|
|
||||||
char *escaped, *result;
|
|
||||||
int flags;
|
|
||||||
|
|
||||||
if (*s == '\0')
|
|
||||||
return (xstrdup(s));
|
|
||||||
if (s[0] != ' ' &&
|
|
||||||
(strchr(quoted, s[0]) != NULL || s[0] == '~') &&
|
|
||||||
s[1] == '\0') {
|
|
||||||
xasprintf(&escaped, "\\%c", s[0]);
|
|
||||||
return (escaped);
|
|
||||||
}
|
|
||||||
|
|
||||||
flags = VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL;
|
|
||||||
if (s[strcspn(s, quoted)] != '\0')
|
|
||||||
flags |= VIS_DQ;
|
|
||||||
utf8_stravis(&escaped, s, flags);
|
|
||||||
|
|
||||||
if (flags & VIS_DQ) {
|
|
||||||
if (*escaped == '~')
|
|
||||||
xasprintf(&result, "\"\\%s\"", escaped);
|
|
||||||
else
|
|
||||||
xasprintf(&result, "\"%s\"", escaped);
|
|
||||||
} else {
|
|
||||||
if (*escaped == '~')
|
|
||||||
xasprintf(&result, "\\%s", escaped);
|
|
||||||
else
|
|
||||||
result = xstrdup(escaped);
|
|
||||||
}
|
|
||||||
free(escaped);
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return if an argument is present. */
|
|
||||||
int
|
|
||||||
args_has(struct args *args, u_char ch)
|
|
||||||
{
|
|
||||||
struct args_entry *entry;
|
|
||||||
|
|
||||||
entry = args_find(args, ch);
|
|
||||||
if (entry == NULL)
|
|
||||||
return (0);
|
|
||||||
return (entry->count);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set argument value in the arguments tree. */
|
|
||||||
void
|
|
||||||
args_set(struct args *args, u_char ch, const char *s)
|
|
||||||
{
|
|
||||||
struct args_entry *entry;
|
|
||||||
struct args_value *value;
|
|
||||||
|
|
||||||
entry = args_find(args, ch);
|
|
||||||
if (entry == NULL) {
|
|
||||||
entry = xcalloc(1, sizeof *entry);
|
|
||||||
entry->flag = ch;
|
|
||||||
entry->count = 1;
|
|
||||||
TAILQ_INIT(&entry->values);
|
|
||||||
RB_INSERT(args_tree, &args->tree, entry);
|
|
||||||
} else
|
|
||||||
entry->count++;
|
|
||||||
|
|
||||||
if (s != NULL) {
|
|
||||||
value = xcalloc(1, sizeof *value);
|
|
||||||
value->value = xstrdup(s);
|
|
||||||
TAILQ_INSERT_TAIL(&entry->values, value, entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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 (TAILQ_LAST(&entry->values, args_values)->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get first value in argument. */
|
|
||||||
const char *
|
|
||||||
args_first_value(struct args *args, u_char ch, struct args_value **value)
|
|
||||||
{
|
|
||||||
struct args_entry *entry;
|
|
||||||
|
|
||||||
if ((entry = args_find(args, ch)) == NULL)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
*value = TAILQ_FIRST(&entry->values);
|
|
||||||
if (*value == NULL)
|
|
||||||
return (NULL);
|
|
||||||
return ((*value)->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get next value in argument. */
|
|
||||||
const char *
|
|
||||||
args_next_value(struct args_value **value)
|
|
||||||
{
|
|
||||||
if (*value == NULL)
|
|
||||||
return (NULL);
|
|
||||||
*value = TAILQ_NEXT(*value, entry);
|
|
||||||
if (*value == NULL)
|
|
||||||
return (NULL);
|
|
||||||
return ((*value)->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;
|
|
||||||
struct args_value *value;
|
|
||||||
|
|
||||||
if ((entry = args_find(args, ch)) == NULL) {
|
|
||||||
*cause = xstrdup("missing");
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
value = TAILQ_LAST(&entry->values, args_values);
|
|
||||||
|
|
||||||
ll = strtonum(value->value, minval, maxval, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
*cause = xstrdup(errstr);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
*cause = NULL;
|
|
||||||
return (ll);
|
|
||||||
}
|
|
||||||
121
array.h
Normal file
121
array.h
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/* $Id: array.h,v 1.11 2010-06-06 00:27:08 tcunha 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_INITIALIZER { NULL, 0, 0 }
|
||||||
|
|
||||||
|
#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) (((void *) (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
|
||||||
87
attributes.c
87
attributes.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: attributes.c,v 1.4 2010-06-05 23:54:51 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
||||||
@@ -23,30 +23,30 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
attributes_tostring(int attr)
|
attributes_tostring(u_char attr)
|
||||||
{
|
{
|
||||||
static char buf[512];
|
static char buf[128];
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (attr == 0)
|
if (attr == 0)
|
||||||
return ("none");
|
return ("none");
|
||||||
|
|
||||||
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s%s%s%s%s%s",
|
buf[0] = '\0';
|
||||||
(attr & GRID_ATTR_BRIGHT) ? "bright," : "",
|
if (attr & GRID_ATTR_BRIGHT)
|
||||||
(attr & GRID_ATTR_DIM) ? "dim," : "",
|
strlcat(buf, "bright,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_UNDERSCORE) ? "underscore," : "",
|
if (attr & GRID_ATTR_DIM)
|
||||||
(attr & GRID_ATTR_BLINK)? "blink," : "",
|
strlcat(buf, "dim,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_REVERSE) ? "reverse," : "",
|
if (attr & GRID_ATTR_UNDERSCORE)
|
||||||
(attr & GRID_ATTR_HIDDEN) ? "hidden," : "",
|
strlcat(buf, "underscore,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_ITALICS) ? "italics," : "",
|
if (attr & GRID_ATTR_BLINK)
|
||||||
(attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : "",
|
strlcat(buf, "blink,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_UNDERSCORE_2) ? "double-underscore," : "",
|
if (attr & GRID_ATTR_REVERSE)
|
||||||
(attr & GRID_ATTR_UNDERSCORE_3) ? "curly-underscore," : "",
|
strlcat(buf, "reverse,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_UNDERSCORE_4) ? "dotted-underscore," : "",
|
if (attr & GRID_ATTR_HIDDEN)
|
||||||
(attr & GRID_ATTR_UNDERSCORE_5) ? "dashed-underscore," : "",
|
strlcat(buf, "hidden,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_OVERLINE) ? "overline," : "");
|
if (attr & GRID_ATTR_ITALICS)
|
||||||
if (len > 0)
|
strlcat(buf, "italics,", sizeof (buf));
|
||||||
buf[len - 1] = '\0';
|
if (*buf != '\0')
|
||||||
|
*(strrchr(buf, ',')) = '\0';
|
||||||
|
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
@@ -55,28 +55,8 @@ int
|
|||||||
attributes_fromstring(const char *str)
|
attributes_fromstring(const char *str)
|
||||||
{
|
{
|
||||||
const char delimiters[] = " ,|";
|
const char delimiters[] = " ,|";
|
||||||
int attr;
|
u_char attr;
|
||||||
size_t end;
|
size_t end;
|
||||||
u_int i;
|
|
||||||
struct {
|
|
||||||
const char *name;
|
|
||||||
int attr;
|
|
||||||
} table[] = {
|
|
||||||
{ "bright", GRID_ATTR_BRIGHT },
|
|
||||||
{ "bold", GRID_ATTR_BRIGHT },
|
|
||||||
{ "dim", GRID_ATTR_DIM },
|
|
||||||
{ "underscore", GRID_ATTR_UNDERSCORE },
|
|
||||||
{ "blink", GRID_ATTR_BLINK },
|
|
||||||
{ "reverse", GRID_ATTR_REVERSE },
|
|
||||||
{ "hidden", GRID_ATTR_HIDDEN },
|
|
||||||
{ "italics", GRID_ATTR_ITALICS },
|
|
||||||
{ "strikethrough", GRID_ATTR_STRIKETHROUGH },
|
|
||||||
{ "double-underscore", GRID_ATTR_UNDERSCORE_2 },
|
|
||||||
{ "curly-underscore", GRID_ATTR_UNDERSCORE_3 },
|
|
||||||
{ "dotted-underscore", GRID_ATTR_UNDERSCORE_4 },
|
|
||||||
{ "dashed-underscore", GRID_ATTR_UNDERSCORE_5 },
|
|
||||||
{ "overline", GRID_ATTR_OVERLINE }
|
|
||||||
};
|
|
||||||
|
|
||||||
if (*str == '\0' || strcspn(str, delimiters) == 0)
|
if (*str == '\0' || strcspn(str, delimiters) == 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
@@ -89,15 +69,22 @@ attributes_fromstring(const char *str)
|
|||||||
attr = 0;
|
attr = 0;
|
||||||
do {
|
do {
|
||||||
end = strcspn(str, delimiters);
|
end = strcspn(str, delimiters);
|
||||||
for (i = 0; i < nitems(table); i++) {
|
if ((end == 6 && strncasecmp(str, "bright", end) == 0) ||
|
||||||
if (end != strlen(table[i].name))
|
(end == 4 && strncasecmp(str, "bold", end) == 0))
|
||||||
continue;
|
attr |= GRID_ATTR_BRIGHT;
|
||||||
if (strncasecmp(str, table[i].name, end) == 0) {
|
else if (end == 3 && strncasecmp(str, "dim", end) == 0)
|
||||||
attr |= table[i].attr;
|
attr |= GRID_ATTR_DIM;
|
||||||
break;
|
else if (end == 10 && strncasecmp(str, "underscore", end) == 0)
|
||||||
}
|
attr |= GRID_ATTR_UNDERSCORE;
|
||||||
}
|
else if (end == 5 && strncasecmp(str, "blink", end) == 0)
|
||||||
if (i == nitems(table))
|
attr |= GRID_ATTR_BLINK;
|
||||||
|
else if (end == 7 && strncasecmp(str, "reverse", end) == 0)
|
||||||
|
attr |= GRID_ATTR_REVERSE;
|
||||||
|
else if (end == 6 && strncasecmp(str, "hidden", end) == 0)
|
||||||
|
attr |= GRID_ATTR_HIDDEN;
|
||||||
|
else if (end == 7 && strncasecmp(str, "italics", end) == 0)
|
||||||
|
attr |= GRID_ATTR_ITALICS;
|
||||||
|
else
|
||||||
return (-1);
|
return (-1);
|
||||||
str += end + strspn(str + end, delimiters);
|
str += end + strspn(str + end, delimiters);
|
||||||
} while (*str != '\0');
|
} while (*str != '\0');
|
||||||
|
|||||||
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"
|
|
||||||
348
cfg.c
348
cfg.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cfg.c,v 1.27 2010-06-06 00:04:18 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,279 +17,127 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
struct client *cfg_client;
|
/*
|
||||||
static char *cfg_file;
|
* Config file parser. Pretty quick and simple, each line is parsed into a
|
||||||
int cfg_finished;
|
* argv array and executed as a command.
|
||||||
static char **cfg_causes;
|
*/
|
||||||
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;
|
||||||
|
int cfg_finished;
|
||||||
|
struct causelist cfg_causes = ARRAY_INITIALIZER;
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
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
|
/* ARGSUSED */
|
||||||
cfg_done(__unused struct cmdq_item *item, __unused void *data)
|
void printflike2
|
||||||
|
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))
|
|
||||||
cfg_show_causes(RB_MIN(sessions, &sessions));
|
|
||||||
|
|
||||||
if (cfg_item != NULL)
|
|
||||||
cmdq_continue(cfg_item);
|
|
||||||
|
|
||||||
status_prompt_load_history();
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
set_cfg_file(const char *path)
|
|
||||||
{
|
|
||||||
free(cfg_file);
|
|
||||||
cfg_file = xstrdup(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
expand_cfg_file(const char *path, const char *home)
|
|
||||||
{
|
|
||||||
char *expanded, *name;
|
|
||||||
const char *end;
|
|
||||||
struct environ_entry *value;
|
|
||||||
|
|
||||||
if (strncmp(path, "~/", 2) == 0) {
|
|
||||||
if (home == NULL)
|
|
||||||
return (NULL);
|
|
||||||
xasprintf(&expanded, "%s%s", home, path + 1);
|
|
||||||
return (expanded);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*path == '$') {
|
|
||||||
end = strchr(path, '/');
|
|
||||||
if (end == NULL)
|
|
||||||
name = xstrdup(path + 1);
|
|
||||||
else
|
|
||||||
name = xstrndup(path + 1, end - path - 1);
|
|
||||||
value = environ_find(global_environ, name);
|
|
||||||
free(name);
|
|
||||||
if (value == NULL)
|
|
||||||
return (NULL);
|
|
||||||
if (end == NULL)
|
|
||||||
end = "";
|
|
||||||
xasprintf(&expanded, "%s%s", value->value, end);
|
|
||||||
return (expanded);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (xstrdup(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
start_cfg(void)
|
|
||||||
{
|
|
||||||
const char *home = find_home();
|
|
||||||
struct client *c;
|
|
||||||
char *path, *copy, *next, *expanded;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Configuration files are loaded without a client, so commands are 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.
|
|
||||||
*/
|
|
||||||
cfg_client = c = TAILQ_FIRST(&clients);
|
|
||||||
if (c != NULL) {
|
|
||||||
cfg_item = cmdq_get_callback(cfg_client_done, NULL);
|
|
||||||
cmdq_append(c, cfg_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cfg_file == NULL) {
|
|
||||||
path = copy = xstrdup(TMUX_CONF);
|
|
||||||
while ((next = strsep(&path, ":")) != NULL) {
|
|
||||||
expanded = expand_cfg_file(next, home);
|
|
||||||
if (expanded == NULL) {
|
|
||||||
log_debug("couldn't expand %s", next);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
log_debug("expanded %s to %s", next, expanded);
|
|
||||||
load_cfg(expanded, c, NULL, CMD_PARSE_QUIET, NULL);
|
|
||||||
free(expanded);
|
|
||||||
}
|
|
||||||
free(copy);
|
|
||||||
} else
|
|
||||||
load_cfg(cfg_file, c, NULL, 0, NULL);
|
|
||||||
|
|
||||||
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
|
|
||||||
struct cmdq_item **new_item)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
struct cmd_parse_input pi;
|
|
||||||
struct cmd_parse_result *pr;
|
|
||||||
struct cmdq_item *new_item0;
|
|
||||||
|
|
||||||
if (new_item != NULL)
|
|
||||||
*new_item = NULL;
|
|
||||||
|
|
||||||
log_debug("loading %s", path);
|
|
||||||
if ((f = fopen(path, "rb")) == NULL) {
|
|
||||||
if (errno == ENOENT && (flags & CMD_PARSE_QUIET))
|
|
||||||
return (0);
|
|
||||||
cfg_add_cause("%s: %s", path, strerror(errno));
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&pi, 0, sizeof pi);
|
|
||||||
pi.flags = flags;
|
|
||||||
pi.file = path;
|
|
||||||
pi.line = 1;
|
|
||||||
pi.item = item;
|
|
||||||
pi.c = c;
|
|
||||||
|
|
||||||
pr = cmd_parse_from_file(f, &pi);
|
|
||||||
fclose(f);
|
|
||||||
if (pr->status == CMD_PARSE_EMPTY)
|
|
||||||
return (0);
|
|
||||||
if (pr->status == CMD_PARSE_ERROR) {
|
|
||||||
cfg_add_cause("%s", pr->error);
|
|
||||||
free(pr->error);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
if (flags & CMD_PARSE_PARSEONLY) {
|
|
||||||
cmd_list_free(pr->cmdlist);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
new_item0 = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
|
|
||||||
if (item != NULL)
|
|
||||||
new_item0 = cmdq_insert_after(item, new_item0);
|
|
||||||
else
|
|
||||||
new_item0 = cmdq_append(NULL, new_item0);
|
|
||||||
cmd_list_free(pr->cmdlist);
|
|
||||||
|
|
||||||
if (new_item != NULL)
|
|
||||||
*new_item = new_item0;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
load_cfg_from_buffer(const void *buf, size_t len, const char *path,
|
|
||||||
struct client *c, struct cmdq_item *item, int flags,
|
|
||||||
struct cmdq_item **new_item)
|
|
||||||
{
|
|
||||||
struct cmd_parse_input pi;
|
|
||||||
struct cmd_parse_result *pr;
|
|
||||||
struct cmdq_item *new_item0;
|
|
||||||
|
|
||||||
if (new_item != NULL)
|
|
||||||
*new_item = NULL;
|
|
||||||
|
|
||||||
log_debug("loading %s", path);
|
|
||||||
|
|
||||||
memset(&pi, 0, sizeof pi);
|
|
||||||
pi.flags = flags;
|
|
||||||
pi.file = path;
|
|
||||||
pi.line = 1;
|
|
||||||
pi.item = item;
|
|
||||||
pi.c = c;
|
|
||||||
|
|
||||||
pr = cmd_parse_from_buffer(buf, len, &pi);
|
|
||||||
if (pr->status == CMD_PARSE_EMPTY)
|
|
||||||
return (0);
|
|
||||||
if (pr->status == CMD_PARSE_ERROR) {
|
|
||||||
cfg_add_cause("%s", pr->error);
|
|
||||||
free(pr->error);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
if (flags & CMD_PARSE_PARSEONLY) {
|
|
||||||
cmd_list_free(pr->cmdlist);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
new_item0 = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
|
|
||||||
if (item != NULL)
|
|
||||||
new_item0 = cmdq_insert_after(item, new_item0);
|
|
||||||
else
|
|
||||||
new_item0 = cmdq_append(NULL, new_item0);
|
|
||||||
cmd_list_free(pr->cmdlist);
|
|
||||||
|
|
||||||
if (new_item != NULL)
|
|
||||||
*new_item = new_item0;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
cfg_add_cause(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
char *msg;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
xvasprintf(&msg, fmt, ap);
|
xvasprintf(&cfg_cause, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printflike2
|
||||||
|
cfg_add_cause(struct causelist *causes, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char *cause;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
xvasprintf(&cause, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
cfg_ncauses++;
|
ARRAY_ADD(causes, cause);
|
||||||
cfg_causes = xreallocarray(cfg_causes, cfg_ncauses, sizeof *cfg_causes);
|
|
||||||
cfg_causes[cfg_ncauses - 1] = msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/*
|
||||||
cfg_print_causes(struct cmdq_item *item)
|
* Load configuration file. Returns -1 for an error with a list of messages in
|
||||||
|
* causes. Note that causes must be initialised by the caller!
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
||||||
{
|
{
|
||||||
u_int i;
|
FILE *f;
|
||||||
|
u_int n;
|
||||||
|
char *buf, *line, *cause;
|
||||||
|
size_t len;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
|
||||||
for (i = 0; i < cfg_ncauses; i++) {
|
if ((f = fopen(path, "rb")) == NULL) {
|
||||||
cmdq_print(item, "%s", cfg_causes[i]);
|
cfg_add_cause(causes, "%s: %s", path, strerror(errno));
|
||||||
free(cfg_causes[i]);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
n = 0;
|
||||||
|
|
||||||
free(cfg_causes);
|
line = NULL;
|
||||||
cfg_causes = NULL;
|
while ((buf = fgetln(f, &len))) {
|
||||||
cfg_ncauses = 0;
|
if (buf[len - 1] == '\n')
|
||||||
}
|
buf[len - 1] = '\0';
|
||||||
|
else {
|
||||||
|
line = xrealloc(line, 1, len + 1);
|
||||||
|
memcpy(line, buf, len);
|
||||||
|
line[len] = '\0';
|
||||||
|
buf = line;
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
|
||||||
void
|
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
|
||||||
cfg_show_causes(struct session *s)
|
if (cause == NULL)
|
||||||
{
|
continue;
|
||||||
struct window_pane *wp;
|
cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
|
||||||
struct window_mode_entry *wme;
|
xfree(cause);
|
||||||
u_int i;
|
continue;
|
||||||
|
}
|
||||||
|
if (cmdlist == NULL)
|
||||||
|
continue;
|
||||||
|
cfg_cause = NULL;
|
||||||
|
|
||||||
if (s == NULL || cfg_ncauses == 0)
|
if (ctxin == NULL) {
|
||||||
return;
|
ctx.msgdata = NULL;
|
||||||
wp = s->curw->window->active;
|
ctx.curclient = NULL;
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
} else {
|
||||||
|
ctx.msgdata = ctxin->msgdata;
|
||||||
|
ctx.curclient = ctxin->curclient;
|
||||||
|
ctx.cmdclient = ctxin->cmdclient;
|
||||||
|
}
|
||||||
|
|
||||||
wme = TAILQ_FIRST(&wp->modes);
|
ctx.error = cfg_error;
|
||||||
if (wme == NULL || wme->mode != &window_view_mode)
|
ctx.print = cfg_print;
|
||||||
window_pane_set_mode(wp, &window_view_mode, NULL, NULL);
|
ctx.info = cfg_print;
|
||||||
for (i = 0; i < cfg_ncauses; i++) {
|
|
||||||
window_copy_add(wp, "%s", cfg_causes[i]);
|
cfg_cause = NULL;
|
||||||
free(cfg_causes[i]);
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
if (cfg_cause != NULL) {
|
||||||
|
cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
|
||||||
|
xfree(cfg_cause);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (line != NULL)
|
||||||
|
xfree(line);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
free(cfg_causes);
|
if (ARRAY_LENGTH(causes) != 0)
|
||||||
cfg_causes = NULL;
|
return (-1);
|
||||||
cfg_ncauses = 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
159
clock.c
Normal file
159
clock.c
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
/* $Id: clock.c,v 1.9 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
const char clock_table[14][5][5] = {
|
||||||
|
{ { 1,1,1,1,1 }, /* 0 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 0,0,0,0,1 }, /* 1 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 2 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 3 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,0,0,0,1 }, /* 4 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 5 */
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 6 */
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 7 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 8 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 9 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 0,0,0,0,0 }, /* : */
|
||||||
|
{ 0,0,1,0,0 },
|
||||||
|
{ 0,0,0,0,0 },
|
||||||
|
{ 0,0,1,0,0 },
|
||||||
|
{ 0,0,0,0,0 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* A */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* P */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,0,0,0,0 } },
|
||||||
|
{ { 1,0,0,0,1 }, /* M */
|
||||||
|
{ 1,1,0,1,1 },
|
||||||
|
{ 1,0,1,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 } },
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
clock_draw(struct screen_write_ctx *ctx, int colour, int style)
|
||||||
|
{
|
||||||
|
struct screen *s = ctx->s;
|
||||||
|
struct grid_cell gc;
|
||||||
|
char tim[64], *ptr;
|
||||||
|
time_t t;
|
||||||
|
u_int i, j, x, y, idx;
|
||||||
|
|
||||||
|
t = time(NULL);
|
||||||
|
if (style == 0)
|
||||||
|
strftime(tim, sizeof tim, "%l:%M %p", localtime(&t));
|
||||||
|
else
|
||||||
|
strftime(tim, sizeof tim, "%H:%M", localtime(&t));
|
||||||
|
|
||||||
|
screen_write_clearscreen(ctx);
|
||||||
|
|
||||||
|
if (screen_size_x(s) < 6 * strlen(tim) || screen_size_y(s) < 6) {
|
||||||
|
if (screen_size_x(s) >= strlen(tim) && screen_size_y(s) != 0) {
|
||||||
|
x = (screen_size_x(s) / 2) - (strlen(tim) / 2);
|
||||||
|
y = screen_size_y(s) / 2;
|
||||||
|
screen_write_cursormove(ctx, x, y);
|
||||||
|
|
||||||
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||||
|
colour_set_fg(&gc, colour);
|
||||||
|
screen_write_puts(ctx, &gc, "%s", tim);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = (screen_size_x(s) / 2) - 3 * strlen(tim);
|
||||||
|
y = (screen_size_y(s) / 2) - 3;
|
||||||
|
|
||||||
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||||
|
colour_set_bg(&gc, colour);
|
||||||
|
for (ptr = tim; *ptr != '\0'; ptr++) {
|
||||||
|
if (*ptr >= '0' && *ptr <= '9')
|
||||||
|
idx = *ptr - '0';
|
||||||
|
else if (*ptr == ':')
|
||||||
|
idx = 10;
|
||||||
|
else if (*ptr == 'A')
|
||||||
|
idx = 11;
|
||||||
|
else if (*ptr == 'P')
|
||||||
|
idx = 12;
|
||||||
|
else if (*ptr == 'M')
|
||||||
|
idx = 13;
|
||||||
|
else {
|
||||||
|
x += 6;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < 5; j++) {
|
||||||
|
for (i = 0; i < 5; i++) {
|
||||||
|
screen_write_cursormove(ctx, x + i, y + j);
|
||||||
|
if (clock_table[idx][j][i])
|
||||||
|
screen_write_putc(ctx, &gc, ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x += 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-attach-session.c,v 1.37 2010-12-22 15:36:44 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,168 +18,93 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attach existing session to the current terminal.
|
* Attach existing session to the current terminal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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",
|
"[-dr] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, "dr",
|
||||||
.args = { "c:dErt:x", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-dErx] [-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 xflag, 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;
|
||||||
enum msgtype msgtype;
|
u_int i;
|
||||||
|
|
||||||
if (RB_EMPTY(&sessions)) {
|
if (RB_EMPTY(&sessions)) {
|
||||||
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 (cmd_check_flag(data->chflags, '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, 1);
|
|
||||||
session_set_current(s, wl);
|
|
||||||
if (wp != NULL)
|
|
||||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
|
||||||
else
|
|
||||||
cmd_find_from_winlink(current, wl, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cflag != NULL) {
|
|
||||||
free((void *)s->cwd);
|
|
||||||
s->cwd = format_single(item, cflag, c, s, wl, wp);
|
|
||||||
}
|
|
||||||
|
|
||||||
c->last_session = c->session;
|
|
||||||
if (c->session != NULL) {
|
|
||||||
if (dflag || xflag) {
|
|
||||||
if (xflag)
|
|
||||||
msgtype = MSG_DETACHKILL;
|
|
||||||
else
|
|
||||||
msgtype = MSG_DETACH;
|
|
||||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
|
||||||
if (c_loop->session != s || c == c_loop)
|
|
||||||
continue;
|
continue;
|
||||||
server_client_detach(c_loop, msgtype);
|
if (c == ctx->curclient)
|
||||||
|
continue;
|
||||||
|
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Eflag)
|
|
||||||
environ_update(s->options, c->environ, s->environ);
|
|
||||||
|
|
||||||
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);
|
|
||||||
tty_update_client_offset(c);
|
|
||||||
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;
|
|
||||||
s->curw->window->latest = c;
|
|
||||||
} 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 || xflag) {
|
overrides =
|
||||||
if (xflag)
|
options_get_string(&s->options, "terminal-overrides");
|
||||||
msgtype = MSG_DETACHKILL;
|
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||||
else
|
ctx->error(ctx, "terminal open failed: %s", cause);
|
||||||
msgtype = MSG_DETACH;
|
xfree(cause);
|
||||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
return (-1);
|
||||||
if (c_loop->session != s || c == c_loop)
|
|
||||||
continue;
|
|
||||||
server_client_detach(c_loop, msgtype);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!Eflag)
|
|
||||||
environ_update(s->options, c->environ, s->environ);
|
|
||||||
|
|
||||||
c->session = s;
|
if (cmd_check_flag(data->chflags, 'r'))
|
||||||
server_client_set_key_table(c, NULL);
|
ctx->cmdclient->flags |= CLIENT_READONLY;
|
||||||
tty_update_client_offset(c);
|
|
||||||
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;
|
|
||||||
s->curw->window->latest = c;
|
|
||||||
|
|
||||||
if (~c->flags & CLIENT_CONTROL)
|
if (cmd_check_flag(data->chflags, 'd'))
|
||||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
server_write_session(s, MSG_DETACH, NULL, 0);
|
||||||
notify_client("client-attached", c);
|
|
||||||
c->flags |= CLIENT_ATTACHED;
|
ctx->cmdclient->session = s;
|
||||||
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
|
|
||||||
|
update = options_get_string(&s->options, "update-environment");
|
||||||
|
environ_update(update, &ctx->cmdclient->environ, &s->environ);
|
||||||
|
|
||||||
|
server_redraw_client(ctx->cmdclient);
|
||||||
}
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
alerts_check_session(s);
|
|
||||||
server_update_socket();
|
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, 'x'), args_has(args, 'r'),
|
|
||||||
args_get(args, 'c'), args_has(args, 'E')));
|
|
||||||
}
|
}
|
||||||
|
|||||||
225
cmd-bind-key.c
225
cmd-bind-key.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-bind-key.c,v 1.29 2010-07-02 02:43: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
|
||||||
@@ -18,69 +18,194 @@
|
|||||||
|
|
||||||
#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 = { "nrN:T:", 2, -1 },
|
struct cmd_bind_key_data {
|
||||||
.usage = "[-nr] [-T key-table] [-N note] 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, "",
|
||||||
|
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;
|
||||||
key_code key;
|
int opt, no_prefix = 0;
|
||||||
const char *tablename, *note;
|
|
||||||
struct cmd_parse_result *pr;
|
|
||||||
char **argv = args->argv;
|
|
||||||
int argc = args->argc, repeat;
|
|
||||||
|
|
||||||
key = key_string_lookup_string(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", 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':
|
||||||
|
if (data->tablename == NULL)
|
||||||
|
data->tablename = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc < 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
if ((data->key = key_string_lookup_string(argv[0])) == KEYC_NONE) {
|
||||||
|
xasprintf(cause, "unknown key: %s", argv[0]);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (!no_prefix)
|
||||||
|
data->key |= KEYC_PREFIX;
|
||||||
|
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
if (data->tablename != NULL) {
|
||||||
|
if (argc != 1)
|
||||||
|
goto usage;
|
||||||
|
data->modecmd = xstrdup(argv[0]);
|
||||||
|
} else {
|
||||||
|
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";
|
|
||||||
repeat = args_has(args, 'r');
|
|
||||||
|
|
||||||
if (argc == 2)
|
usage:
|
||||||
pr = cmd_parse_from_string(argv[1], NULL);
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
else
|
|
||||||
pr = cmd_parse_from_arguments(argc - 1, argv + 1, NULL);
|
error:
|
||||||
switch (pr->status) {
|
self->entry->free(self);
|
||||||
case CMD_PARSE_EMPTY:
|
return (-1);
|
||||||
cmdq_error(item, "empty command");
|
}
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
case CMD_PARSE_ERROR:
|
int
|
||||||
cmdq_error(item, "%s", pr->error);
|
cmd_bind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
free(pr->error);
|
{
|
||||||
return (CMD_RETURN_ERROR);
|
struct cmd_bind_key_data *data = self->data;
|
||||||
case CMD_PARSE_SUCCESS:
|
|
||||||
break;
|
if (data == NULL)
|
||||||
}
|
return (0);
|
||||||
note = args_get(args, 'N');
|
if (data->tablename != NULL)
|
||||||
key_bindings_add(tablename, key, note, repeat, pr->cmdlist);
|
return (cmd_bind_key_table(self, ctx));
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
key_bindings_add(data->key, data->can_repeat, data->cmdlist);
|
||||||
|
data->cmdlist->references++;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_bind_key_data *data = self->data;
|
||||||
|
const struct mode_key_table *mtab;
|
||||||
|
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 && data->command_key)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -c");
|
||||||
|
if (off < len && !(data->key & KEYC_PREFIX))
|
||||||
|
off += xsnprintf(buf + off, len - off, " -n");
|
||||||
|
if (off < len && data->can_repeat)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -r");
|
||||||
|
if (off < len && data->tablename != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->tablename);
|
||||||
|
if (off < len) {
|
||||||
|
skey = key_string_lookup_key(data->key & ~KEYC_PREFIX);
|
||||||
|
off += xsnprintf(buf + off, len - off, " %s ", skey);
|
||||||
|
}
|
||||||
|
if (off < len)
|
||||||
|
off += cmd_list_print(data->cmdlist, buf + off, len - off);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
119
cmd-break-pane.c
119
cmd-break-pane.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-break-pane.c,v 1.11 2009-12-04 22:14:47 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,96 +26,59 @@
|
|||||||
* Break pane off into a window.
|
* Break pane off into a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
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, "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);
|
|
||||||
|
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
|
||||||
window_lost_pane(w, wp);
|
|
||||||
layout_close_pane(wp);
|
layout_close_pane(wp);
|
||||||
|
|
||||||
w = wp->window = window_create(w->sx, w->sy, w->xpixel, w->ypixel);
|
w = wp->window = window_create1(s->sx, s->sy);
|
||||||
options_set_parent(wp->options, w->options);
|
|
||||||
wp->flags |= PANE_STYLECHANGED;
|
|
||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
w->active = wp;
|
w->active = wp;
|
||||||
w->latest = c;
|
w->name = default_window_name(w);
|
||||||
|
layout_init(w);
|
||||||
|
|
||||||
if (!args_has(args, 'n')) {
|
base_idx = options_get_number(&s->options, "base-index");
|
||||||
name = default_window_name(w);
|
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
|
||||||
window_set_name(w, name);
|
if (!cmd_check_flag(data->chflags, 'd'))
|
||||||
free(name);
|
session_select(s, wl->idx);
|
||||||
} else {
|
|
||||||
window_set_name(w, args_get(args, 'n'));
|
|
||||||
options_set_number(w->options, "automatic-rename", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
layout_init(w, wp);
|
server_redraw_session(s);
|
||||||
wp->flags |= PANE_CHANGED;
|
server_status_session_group(s);
|
||||||
|
|
||||||
if (idx == -1)
|
return (0);
|
||||||
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, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
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,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-capture-pane.c,v 1.3 2010-01-22 17:29:19 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
|
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
|
||||||
@@ -18,223 +18,66 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write the entire contents of a pane to a buffer or stdout.
|
* Write the entire contents of a pane to a buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmdq_item *);
|
int cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
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 = {
|
const struct cmd_entry cmd_capture_pane_entry = {
|
||||||
.name = "capture-pane",
|
"capture-pane", "capturep",
|
||||||
.alias = "capturep",
|
CMD_BUFFER_PANE_USAGE,
|
||||||
|
0, "",
|
||||||
.args = { "ab:CeE:JNpPqS:t:", 0, 0 },
|
cmd_buffer_init,
|
||||||
.usage = "[-aCeJNpPq] " CMD_BUFFER_USAGE " [-E end-line] "
|
cmd_buffer_parse,
|
||||||
"[-S start-line] " CMD_TARGET_PANE_USAGE,
|
cmd_capture_pane_exec,
|
||||||
|
cmd_buffer_free,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_buffer_print
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_capture_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_clear_history_entry = {
|
int
|
||||||
.name = "clear-history",
|
cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.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);
|
struct cmd_buffer_data *data = self->data;
|
||||||
memcpy(buf + *len, line, linelen);
|
struct window_pane *wp;
|
||||||
*len += linelen;
|
char *buf, *line;
|
||||||
return (buf);
|
struct screen *s;
|
||||||
}
|
struct session *sess;
|
||||||
|
u_int i, limit;
|
||||||
|
size_t len, linelen;
|
||||||
|
|
||||||
static char *
|
if (cmd_find_pane(ctx, data->target, &sess, &wp) == NULL)
|
||||||
cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
|
return (-1);
|
||||||
size_t *len)
|
s = &wp->base;
|
||||||
{
|
|
||||||
struct evbuffer *pending;
|
|
||||||
char *buf, *line, tmp[5];
|
|
||||||
size_t linelen;
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
pending = input_pending(wp);
|
|
||||||
if (pending == NULL)
|
|
||||||
return (xstrdup(""));
|
|
||||||
|
|
||||||
line = EVBUFFER_DATA(pending);
|
|
||||||
linelen = EVBUFFER_LENGTH(pending);
|
|
||||||
|
|
||||||
buf = xstrdup("");
|
|
||||||
if (args_has(args, 'C')) {
|
|
||||||
for (i = 0; i < linelen; i++) {
|
|
||||||
if (line[i] >= ' ' && 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, no_trim;
|
|
||||||
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');
|
|
||||||
no_trim = args_has(args, 'N');
|
|
||||||
|
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
for (i = top; i <= bottom; i++) {
|
|
||||||
line = grid_string_cells(gd, 0, i, sx, &gc, with_codes,
|
|
||||||
escape_c0, !join_lines && !no_trim);
|
|
||||||
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 = item->client;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
char *buf, *cause;
|
|
||||||
const char *bufname;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_clear_history_entry) {
|
|
||||||
window_pane_reset_mode_all(wp);
|
|
||||||
grid_clear_history(wp->base.grid);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
len = 0;
|
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')) {
|
for (i = 0; i < screen_size_y(s); i++) {
|
||||||
if (!file_can_print(c)) {
|
line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
|
||||||
cmdq_error(item, "can't write output to client");
|
linelen = strlen(line);
|
||||||
free(buf);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
file_print_buffer(c, buf, len);
|
|
||||||
if (args_has(args, 'P') && len > 0)
|
|
||||||
file_print(c, "\n");
|
|
||||||
free(buf);
|
|
||||||
} else {
|
|
||||||
bufname = NULL;
|
|
||||||
if (args_has(args, 'b'))
|
|
||||||
bufname = args_get(args, 'b');
|
|
||||||
|
|
||||||
if (paste_set(buf, len, bufname, &cause) != 0) {
|
buf = xrealloc(buf, 1, len + linelen + 1);
|
||||||
cmdq_error(item, "%s", cause);
|
memcpy(buf + len, line, linelen);
|
||||||
free(cause);
|
len += linelen;
|
||||||
free(buf);
|
buf[len++] = '\n';
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
xfree(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
limit = options_get_number(&sess->options, "buffer-limit");
|
||||||
|
if (data->buffer == -1) {
|
||||||
|
paste_add(&sess->buffers, buf, len, limit);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (paste_replace(&sess->buffers, data->buffer, buf, len) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
|
xfree(buf);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
146
cmd-choose-buffer.c
Normal file
146
cmd-choose-buffer.c
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
/* $Id: cmd-choose-buffer.c,v 1.1 2010-06-22 23:35:20 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* 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 buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_buffer_callback(void *, int);
|
||||||
|
void cmd_choose_buffer_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_buffer_entry = {
|
||||||
|
"choose-buffer", NULL,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
CMD_ARG01, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_choose_buffer_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_buffer_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct cmd_choose_buffer_data *cdata;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
u_int idx;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
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 (paste_get_top(&s->buffers) == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
idx = 0;
|
||||||
|
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
||||||
|
tmp = paste_print(pb, 50);
|
||||||
|
window_choose_add(wl->window->active, idx - 1,
|
||||||
|
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||||
|
xfree(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
cdata->template = xstrdup(data->arg);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("paste-buffer -b '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
0, cmd_choose_buffer_callback, cmd_choose_buffer_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_buffer_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_buffer_data *cdata = data;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause, tmp[16];
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xsnprintf(tmp, sizeof tmp, "%u", idx);
|
||||||
|
template = cmd_template_replace(cdata->template, tmp, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_buffer_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_buffer_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
152
cmd-choose-client.c
Normal file
152
cmd-choose-client.c
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
/* $Id: cmd-choose-client.c,v 1.4 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* 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 client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_client_callback(void *, int);
|
||||||
|
void cmd_choose_client_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_client_entry = {
|
||||||
|
"choose-client", NULL,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
CMD_ARG01, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_choose_client_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_client_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct cmd_choose_client_data *cdata;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct client *c;
|
||||||
|
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(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
continue;
|
||||||
|
if (c == ctx->curclient)
|
||||||
|
cur = 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)" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
cdata->template = xstrdup(data->arg);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("detach-client -t '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_client_callback, cmd_choose_client_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_client_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_client_data *cdata = data;
|
||||||
|
struct client *c;
|
||||||
|
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(&clients) - 1)
|
||||||
|
return;
|
||||||
|
c = ARRAY_ITEM(&clients, idx);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
return;
|
||||||
|
template = cmd_template_replace(cdata->template, c->tty.path, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(c, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_client_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_client_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
157
cmd-choose-session.c
Normal file
157
cmd-choose-session.c
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
/* $Id: cmd-choose-session.c,v 1.17 2010-12-22 15:36:44 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_session_callback(void *, int);
|
||||||
|
void cmd_choose_session_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_session_entry = {
|
||||||
|
"choose-session", NULL,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
CMD_ARG01, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_choose_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_session_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct cmd_choose_session_data *cdata;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct session *s;
|
||||||
|
struct session_group *sg;
|
||||||
|
u_int idx, sgidx, cur;
|
||||||
|
char tmp[64];
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
cur = idx = 0;
|
||||||
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
|
if (s == ctx->curclient->session)
|
||||||
|
cur = idx;
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
sg = session_group_find(s);
|
||||||
|
if (sg == NULL)
|
||||||
|
*tmp = '\0';
|
||||||
|
else {
|
||||||
|
sgidx = session_group_index(sg);
|
||||||
|
xsnprintf(tmp, sizeof tmp, " (group %u)", sgidx);
|
||||||
|
}
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active, s->idx,
|
||||||
|
"%s: %u windows [%ux%u]%s%s", s->name,
|
||||||
|
winlink_count(&s->windows), s->sx, s->sy,
|
||||||
|
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
cdata->template = xstrdup(data->arg);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("switch-client -t '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_session_callback, cmd_choose_session_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_session_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_session_data *cdata = data;
|
||||||
|
struct session *s;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
s = session_find_by_index(idx);
|
||||||
|
if (s == NULL)
|
||||||
|
return;
|
||||||
|
template = cmd_template_replace(cdata->template, s->name, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_session_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_session_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
@@ -1,91 +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 "tmux.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Enter a mode.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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 = { "F:Gf:NO:rst:wZ", 0, 1 },
|
|
||||||
.usage = "[-GNrswZ] [-F format] [-f filter] [-O sort-order] "
|
|
||||||
CMD_TARGET_PANE_USAGE " [template]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_choose_tree_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_client_entry = {
|
|
||||||
.name = "choose-client",
|
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "F:f:NO:rt:Z", 0, 1 },
|
|
||||||
.usage = "[-NrZ] [-F format] [-f filter] [-O sort-order] "
|
|
||||||
CMD_TARGET_PANE_USAGE " [template]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_choose_tree_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_choose_buffer_entry = {
|
|
||||||
.name = "choose-buffer",
|
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "F:f:NO:rt:Z", 0, 1 },
|
|
||||||
.usage = "[-NrZ] [-F format] [-f filter] [-O sort-order] "
|
|
||||||
CMD_TARGET_PANE_USAGE " [template]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 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 window_pane *wp = item->target.wp;
|
|
||||||
const struct window_mode *mode;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_choose_buffer_entry) {
|
|
||||||
if (paste_get_top(NULL) == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
mode = &window_buffer_mode;
|
|
||||||
} else if (self->entry == &cmd_choose_client_entry) {
|
|
||||||
if (server_client_how_many() == 0)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
mode = &window_client_mode;
|
|
||||||
} else
|
|
||||||
mode = &window_tree_mode;
|
|
||||||
|
|
||||||
window_pane_set_mode(wp, mode, &item->target, args);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
181
cmd-choose-window.c
Normal file
181
cmd-choose-window.c
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
/* $Id: cmd-choose-window.c,v 1.24 2010-12-22 15:28:50 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_window_callback(void *, int);
|
||||||
|
void cmd_choose_window_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_window_entry = {
|
||||||
|
"choose-window", NULL,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
CMD_ARG01, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_choose_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_window_data {
|
||||||
|
struct client *client;
|
||||||
|
struct session *session;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct cmd_choose_window_data *cdata;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl, *wm;
|
||||||
|
struct window *w;
|
||||||
|
u_int idx, cur;
|
||||||
|
char flag, *title;
|
||||||
|
const char *left, *right;
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
cur = idx = 0;
|
||||||
|
RB_FOREACH(wm, winlinks, &s->windows) {
|
||||||
|
w = wm->window;
|
||||||
|
|
||||||
|
if (wm == s->curw)
|
||||||
|
cur = idx;
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
flag = ' ';
|
||||||
|
if (wm->flags & WINLINK_ACTIVITY)
|
||||||
|
flag = '#';
|
||||||
|
else if (wm->flags & WINLINK_BELL)
|
||||||
|
flag = '!';
|
||||||
|
else if (wm->flags & WINLINK_CONTENT)
|
||||||
|
flag = '+';
|
||||||
|
else if (wm->flags & WINLINK_SILENCE)
|
||||||
|
flag = '~';
|
||||||
|
else if (wm == s->curw)
|
||||||
|
flag = '*';
|
||||||
|
else if (wm == TAILQ_FIRST(&s->lastw))
|
||||||
|
flag = '-';
|
||||||
|
|
||||||
|
title = w->active->screen->title;
|
||||||
|
if (wm == wl)
|
||||||
|
title = w->active->base.title;
|
||||||
|
left = " \"";
|
||||||
|
right = "\"";
|
||||||
|
if (*title == '\0')
|
||||||
|
left = right = "";
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active,
|
||||||
|
wm->idx, "%3d: %s%c [%ux%u] (%u panes%s)%s%s%s",
|
||||||
|
wm->idx, w->name, flag, w->sx, w->sy, window_count_panes(w),
|
||||||
|
w->active->fd == -1 ? ", dead" : "",
|
||||||
|
left, title, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
cdata->template = xstrdup(data->arg);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("select-window -t '%%'");
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_window_callback, cmd_choose_window_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_window_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_window_data *cdata = data;
|
||||||
|
struct session *s = cdata->session;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *target, *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (!session_alive(s))
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xasprintf(&target, "%s:%d", s->name, idx);
|
||||||
|
template = cmd_template_replace(cdata->template, target, 1);
|
||||||
|
xfree(target);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_window_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_window_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->session->references--;
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
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.8 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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, "",
|
||||||
|
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.7 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 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,37 +18,35 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include "tmux.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "compat.h"
|
/*
|
||||||
|
* Enter clock mode.
|
||||||
|
*/
|
||||||
|
|
||||||
#if defined(HAVE_PRCTL) && defined(HAVE_PR_SET_NAME)
|
int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
#include <sys/prctl.h>
|
const struct cmd_entry cmd_clock_mode_entry = {
|
||||||
|
"clock-mode", NULL,
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_clock_mode_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
void
|
int
|
||||||
setproctitle(const char *fmt, ...)
|
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
char title[16], name[16], *cp;
|
struct cmd_target_data *data = self->data;
|
||||||
va_list ap;
|
struct window_pane *wp;
|
||||||
int used;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
vsnprintf(title, sizeof title, fmt, ap);
|
return (-1);
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
used = snprintf(name, sizeof name, "%s: %s", getprogname(), title);
|
window_pane_set_mode(wp, &window_clock_mode);
|
||||||
if (used >= (int)sizeof name) {
|
|
||||||
cp = strrchr(name, ' ');
|
return (0);
|
||||||
if (cp != NULL)
|
|
||||||
*cp = '\0';
|
|
||||||
}
|
|
||||||
prctl(PR_SET_NAME, name);
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
void
|
|
||||||
setproctitle(__unused const char *fmt, ...)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-command-prompt.c,v 1.28 2010-05-14 14:33: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,174 +27,244 @@
|
|||||||
* 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(struct client *, void *,
|
int cmd_command_prompt_callback(void *, const char *);
|
||||||
const char *, int);
|
void cmd_command_prompt_cfree(void *);
|
||||||
static void cmd_command_prompt_free(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, "",
|
||||||
|
cmd_command_prompt_init,
|
||||||
|
cmd_command_prompt_parse,
|
||||||
|
cmd_command_prompt_exec,
|
||||||
|
cmd_command_prompt_free,
|
||||||
|
cmd_command_prompt_print
|
||||||
|
};
|
||||||
|
|
||||||
.args = { "1kiI:Np:t:", 0, 1 },
|
struct cmd_command_prompt_data {
|
||||||
.usage = "[-1kiN] [-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 {
|
||||||
int flags;
|
struct client *c;
|
||||||
|
char *next_prompt;
|
||||||
char *inputs;
|
char *prompts;
|
||||||
char *next_input;
|
char *template;
|
||||||
|
int idx;
|
||||||
char *prompts;
|
|
||||||
char *next_prompt;
|
|
||||||
|
|
||||||
char *template;
|
|
||||||
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;
|
||||||
|
case '\'':
|
||||||
|
data->template = xstrdup("select-window -t ':%%'");
|
||||||
|
data->prompts = xstrdup("index");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_command_prompt_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_command_prompt_data *data;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "p:t:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'p':
|
||||||
|
if (data->prompts == NULL)
|
||||||
|
data->prompts = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 0 && argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
data->template = xstrdup(argv[0]);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_command_prompt_data *data = self->data;
|
||||||
struct cmd_command_prompt_cdata *cdata;
|
struct cmd_command_prompt_cdata *cdata;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
char *prompt, *ptr, *input = NULL;
|
char *prompt, *ptr;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
if ((c = cmd_find_client(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->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;
|
|
||||||
else if (args_has(args, 'k'))
|
|
||||||
cdata->flags |= PROMPT_KEY;
|
|
||||||
status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
|
|
||||||
cmd_command_prompt_free, cdata, cdata->flags);
|
|
||||||
free(prompt);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
void
|
||||||
cmd_command_prompt_callback(struct client *c, void *data, const char *s,
|
cmd_command_prompt_free(struct cmd *self)
|
||||||
int done)
|
{
|
||||||
|
struct cmd_command_prompt_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->prompts != NULL)
|
||||||
|
xfree(data->prompts);
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
if (data->template != NULL)
|
||||||
|
xfree(data->template);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_command_prompt_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_command_prompt_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->prompts != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -p ", data->prompts);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->template != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->template);
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_command_prompt_callback(void *data, const char *s)
|
||||||
{
|
{
|
||||||
struct cmd_command_prompt_cdata *cdata = data;
|
struct cmd_command_prompt_cdata *cdata = data;
|
||||||
struct cmdq_item *new_item;
|
struct client *c = cdata->c;
|
||||||
char *new_template, *prompt, *ptr;
|
struct cmd_list *cmdlist;
|
||||||
char *input = NULL;
|
struct cmd_ctx ctx;
|
||||||
struct cmd_parse_result *pr;
|
char *cause, *newtempl, *prompt, *ptr;
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
pr = cmd_parse_from_string(new_template, NULL);
|
if (cmd_string_parse(newtempl, &cmdlist, &cause) != 0) {
|
||||||
switch (pr->status) {
|
if (cause != NULL) {
|
||||||
case CMD_PARSE_EMPTY:
|
*cause = toupper((u_char) *cause);
|
||||||
new_item = NULL;
|
status_message_set(c, "%s", cause);
|
||||||
break;
|
xfree(cause);
|
||||||
case CMD_PARSE_ERROR:
|
}
|
||||||
new_item = cmdq_get_error(pr->error);
|
return (0);
|
||||||
free(pr->error);
|
|
||||||
cmdq_append(c, new_item);
|
|
||||||
break;
|
|
||||||
case CMD_PARSE_SUCCESS:
|
|
||||||
new_item = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
|
|
||||||
cmd_list_free(pr->cmdlist);
|
|
||||||
cmdq_append(c, new_item);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!done)
|
ctx.msgdata = NULL;
|
||||||
free(new_template);
|
ctx.curclient = c;
|
||||||
if (c->prompt_inputcb != cmd_command_prompt_callback)
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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.12 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -16,10 +16,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -28,101 +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(struct client *, void *,
|
int cmd_confirm_before_callback(void *, const char *);
|
||||||
const char *, int);
|
void cmd_confirm_before_free(void *);
|
||||||
static 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, "",
|
||||||
.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 {
|
||||||
char *cmd;
|
struct client *c;
|
||||||
|
char *cmd;
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
cdata->cmd = xstrdup(args->argv[0]);
|
return (-1);
|
||||||
|
|
||||||
status_prompt_set(c, new_prompt, NULL,
|
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->cmd = xstrdup(data->arg);
|
||||||
|
cdata->c = c;
|
||||||
|
status_prompt_set(cdata->c, buf,
|
||||||
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
||||||
PROMPT_SINGLE);
|
PROMPT_SINGLE);
|
||||||
|
|
||||||
free(new_prompt);
|
xfree(buf);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
int
|
||||||
cmd_confirm_before_callback(struct client *c, void *data, const char *s,
|
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 cmdq_item *new_item;
|
struct client *c = cdata->c;
|
||||||
struct cmd_parse_result *pr;
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
if (c->flags & CLIENT_DEAD)
|
char *cause;
|
||||||
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);
|
||||||
|
|
||||||
pr = cmd_parse_from_string(cdata->cmd, NULL);
|
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||||
switch (pr->status) {
|
if (cause != NULL) {
|
||||||
case CMD_PARSE_EMPTY:
|
*cause = toupper((u_char) *cause);
|
||||||
new_item = NULL;
|
status_message_set(c, "%s", cause);
|
||||||
break;
|
xfree(cause);
|
||||||
case CMD_PARSE_ERROR:
|
}
|
||||||
new_item = cmdq_get_error(pr->error);
|
return (0);
|
||||||
free(pr->error);
|
|
||||||
cmdq_append(c, new_item);
|
|
||||||
break;
|
|
||||||
case CMD_PARSE_SUCCESS:
|
|
||||||
new_item = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
|
|
||||||
cmd_list_free(pr->cmdlist);
|
|
||||||
cmdq_append(c, new_item);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = c;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
free(cdata->cmd);
|
if (cdata->cmd != NULL)
|
||||||
free(cdata);
|
xfree(cdata->cmd);
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
205
cmd-copy-buffer.c
Normal file
205
cmd-copy-buffer.c
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
/* $Id: cmd-copy-buffer.c,v 1.7 2009-11-28 14:50:36 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copies a session paste buffer to another session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_copy_buffer_parse(struct cmd *, int, char **, char **);
|
||||||
|
int cmd_copy_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_copy_buffer_free(struct cmd *);
|
||||||
|
void cmd_copy_buffer_init(struct cmd *, int);
|
||||||
|
size_t cmd_copy_buffer_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
|
struct cmd_copy_buffer_data {
|
||||||
|
char *dst_session;
|
||||||
|
char *src_session;
|
||||||
|
int dst_idx;
|
||||||
|
int src_idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_copy_buffer_entry = {
|
||||||
|
"copy-buffer", "copyb",
|
||||||
|
"[-a src-index] [-b dst-index] [-s src-session] [-t dst-session]",
|
||||||
|
0, "",
|
||||||
|
cmd_copy_buffer_init,
|
||||||
|
cmd_copy_buffer_parse,
|
||||||
|
cmd_copy_buffer_exec,
|
||||||
|
cmd_copy_buffer_free,
|
||||||
|
cmd_copy_buffer_print
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_copy_buffer_init(struct cmd *self, unused int arg)
|
||||||
|
{
|
||||||
|
struct cmd_copy_buffer_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->dst_session = NULL;
|
||||||
|
data->src_session = NULL;
|
||||||
|
data->dst_idx = -1;
|
||||||
|
data->src_idx = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_copy_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_copy_buffer_data *data;
|
||||||
|
const char *errstr;
|
||||||
|
int n, opt;
|
||||||
|
|
||||||
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "a:b:s:t:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'a':
|
||||||
|
if (data->src_idx == -1) {
|
||||||
|
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "buffer %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
data->src_idx = n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
if (data->dst_idx == -1) {
|
||||||
|
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "buffer %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
data->dst_idx = n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
if (data->src_session == NULL)
|
||||||
|
data->src_session = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->dst_session == NULL)
|
||||||
|
data->dst_session = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_copy_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_copy_buffer_data *data = self->data;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
struct paste_stack *dst_ps, *src_ps;
|
||||||
|
u_char *pdata;
|
||||||
|
struct session *dst_session, *src_session;
|
||||||
|
u_int limit;
|
||||||
|
|
||||||
|
if ((dst_session = cmd_find_session(ctx, data->dst_session)) == NULL ||
|
||||||
|
(src_session = cmd_find_session(ctx, data->src_session)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
dst_ps = &dst_session->buffers;
|
||||||
|
src_ps = &src_session->buffers;
|
||||||
|
|
||||||
|
if (data->src_idx == -1) {
|
||||||
|
if ((pb = paste_get_top(src_ps)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffers");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((pb = paste_get_index(src_ps, data->src_idx)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->src_idx);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
limit = options_get_number(&dst_session->options, "buffer-limit");
|
||||||
|
|
||||||
|
pdata = xmalloc(pb->size);
|
||||||
|
memcpy(pdata, pb->data, pb->size);
|
||||||
|
|
||||||
|
if (data->dst_idx == -1)
|
||||||
|
paste_add(dst_ps, pdata, pb->size, limit);
|
||||||
|
else if (paste_replace(dst_ps, data->dst_idx, pdata, pb->size) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->dst_idx);
|
||||||
|
xfree(pdata);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_copy_buffer_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_copy_buffer_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->dst_session != NULL)
|
||||||
|
xfree(data->dst_session);
|
||||||
|
if (data->src_session != NULL)
|
||||||
|
xfree(data->src_session);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_copy_buffer_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_copy_buffer_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->src_idx != -1) {
|
||||||
|
off += xsnprintf(buf + off, len - off, " -a %d",
|
||||||
|
data->src_idx);
|
||||||
|
}
|
||||||
|
if (off < len && data->dst_idx != -1) {
|
||||||
|
off += xsnprintf(buf + off, len - off, " -b %d",
|
||||||
|
data->dst_idx);
|
||||||
|
}
|
||||||
|
if (off < len && data->src_session != NULL) {
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -s ",
|
||||||
|
data->src_session);
|
||||||
|
}
|
||||||
|
if (off < len && data->dst_session != NULL) {
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ",
|
||||||
|
data->dst_session);
|
||||||
|
}
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-copy-mode.c,v 1.28 2010-08-11 22:18:28 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,69 +21,52 @@
|
|||||||
#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 *);
|
void cmd_copy_mode_init(struct cmd *, int);
|
||||||
|
int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_copy_mode_entry = {
|
const struct cmd_entry cmd_copy_mode_entry = {
|
||||||
.name = "copy-mode",
|
"copy-mode", NULL,
|
||||||
.alias = NULL,
|
"[-u] " CMD_TARGET_PANE_USAGE,
|
||||||
|
0, "u",
|
||||||
.args = { "eHMt:uq", 0, 0 },
|
cmd_copy_mode_init,
|
||||||
.usage = "[-eHMuq] " CMD_TARGET_PANE_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_copy_mode_exec,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_copy_mode_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_clock_mode_entry = {
|
void
|
||||||
.name = "clock-mode",
|
cmd_copy_mode_init(struct cmd *self, int key)
|
||||||
.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;
|
||||||
struct cmdq_shared *shared = item->shared;
|
|
||||||
struct client *c = item->client;
|
|
||||||
struct session *s;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
|
|
||||||
if (args_has(args, 'q')) {
|
cmd_target_init(self, key);
|
||||||
window_pane_reset_mode_all(wp);
|
data = self->data;
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
switch (key) {
|
||||||
|
case KEYC_PPAGE:
|
||||||
|
cmd_set_flag(&data->chflags, 'u');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (args_has(args, 'M')) {
|
|
||||||
if ((wp = cmd_mouse_pane(&shared->mouse, &s, NULL)) == NULL)
|
int
|
||||||
return (CMD_RETURN_NORMAL);
|
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
if (c == NULL || c->session != s)
|
{
|
||||||
return (CMD_RETURN_NORMAL);
|
struct cmd_target_data *data = self->data;
|
||||||
}
|
struct window_pane *wp;
|
||||||
|
|
||||||
if (self->entry == &cmd_clock_mode_entry) {
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
window_pane_set_mode(wp, &window_clock_mode, NULL, NULL);
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
|
||||||
|
return (0);
|
||||||
if (!window_pane_set_mode(wp, &window_copy_mode, NULL, args)) {
|
window_copy_init_from_pane(wp);
|
||||||
if (args_has(args, 'M'))
|
if (wp->mode == &window_copy_mode && cmd_check_flag(data->chflags, 'u'))
|
||||||
window_copy_start_drag(c, &shared->mouse);
|
window_copy_pageup(wp);
|
||||||
}
|
|
||||||
if (args_has(self->args, 'u'))
|
return (0);
|
||||||
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.8 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delete a paste buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_delete_buffer_entry = {
|
||||||
|
"delete-buffer", "deleteb",
|
||||||
|
CMD_BUFFER_SESSION_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_buffer_init,
|
||||||
|
cmd_buffer_parse,
|
||||||
|
cmd_delete_buffer_exec,
|
||||||
|
cmd_buffer_free,
|
||||||
|
cmd_buffer_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (data->buffer == -1)
|
||||||
|
paste_free_top(&s->buffers);
|
||||||
|
else if (paste_free_index(&s->buffers, data->buffer) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-detach-client.c,v 1.11 2010-02-08 18:27:34 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,
|
||||||
|
CMD_READONLY, "",
|
||||||
.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,178 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 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 "tmux.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Display a menu on a client.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_display_menu_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_display_menu_entry = {
|
|
||||||
.name = "display-menu",
|
|
||||||
.alias = "menu",
|
|
||||||
|
|
||||||
.args = { "c:t:T:x:y:", 1, -1 },
|
|
||||||
.usage = "[-c target-client] " CMD_TARGET_PANE_USAGE " [-T title] "
|
|
||||||
"[-x position] [-y position] name key command ...",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_display_menu_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
struct cmd_find_state *fs = &item->target;
|
|
||||||
struct menu *menu = NULL;
|
|
||||||
struct style_range *sr;
|
|
||||||
struct menu_item menu_item;
|
|
||||||
const char *xp, *yp, *key;
|
|
||||||
char *title, *name;
|
|
||||||
int at, flags, i;
|
|
||||||
u_int px, py, ox, oy, sx, sy;
|
|
||||||
|
|
||||||
if ((c = cmd_find_client(item, args_get(args, 'c'), 0)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
if (c->overlay_draw != NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
at = status_at_line(c);
|
|
||||||
|
|
||||||
if (args_has(args, 'T'))
|
|
||||||
title = format_single(NULL, args_get(args, 'T'), c, s, wl, wp);
|
|
||||||
else
|
|
||||||
title = xstrdup("");
|
|
||||||
|
|
||||||
menu = menu_create(title);
|
|
||||||
|
|
||||||
for (i = 0; i != args->argc; /* nothing */) {
|
|
||||||
name = args->argv[i++];
|
|
||||||
if (*name == '\0') {
|
|
||||||
menu_add_item(menu, NULL, item, c, fs);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args->argc - i < 2) {
|
|
||||||
cmdq_error(item, "not enough arguments");
|
|
||||||
free(title);
|
|
||||||
menu_free(menu);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
key = args->argv[i++];
|
|
||||||
|
|
||||||
menu_item.name = name;
|
|
||||||
menu_item.key = key_string_lookup_string(key);
|
|
||||||
menu_item.command = args->argv[i++];
|
|
||||||
|
|
||||||
menu_add_item(menu, &menu_item, item, c, fs);
|
|
||||||
}
|
|
||||||
free(title);
|
|
||||||
if (menu == NULL) {
|
|
||||||
cmdq_error(item, "invalid menu arguments");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (menu->count == 0) {
|
|
||||||
menu_free(menu);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
xp = args_get(args, 'x');
|
|
||||||
if (xp == NULL)
|
|
||||||
px = 0;
|
|
||||||
else if (strcmp(xp, "R") == 0)
|
|
||||||
px = c->tty.sx - 1;
|
|
||||||
else if (strcmp(xp, "P") == 0) {
|
|
||||||
tty_window_offset(&c->tty, &ox, &oy, &sx, &sy);
|
|
||||||
if (wp->xoff >= ox)
|
|
||||||
px = wp->xoff - ox;
|
|
||||||
else
|
|
||||||
px = 0;
|
|
||||||
} else if (strcmp(xp, "M") == 0 && item->shared->mouse.valid) {
|
|
||||||
if (item->shared->mouse.x > (menu->width + 4) / 2)
|
|
||||||
px = item->shared->mouse.x - (menu->width + 4) / 2;
|
|
||||||
else
|
|
||||||
px = 0;
|
|
||||||
}
|
|
||||||
else if (strcmp(xp, "W") == 0) {
|
|
||||||
if (at == -1)
|
|
||||||
px = 0;
|
|
||||||
else {
|
|
||||||
TAILQ_FOREACH(sr, &c->status.entries[0].ranges, entry) {
|
|
||||||
if (sr->type != STYLE_RANGE_WINDOW)
|
|
||||||
continue;
|
|
||||||
if (sr->argument == (u_int)wl->idx)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (sr != NULL)
|
|
||||||
px = sr->start;
|
|
||||||
else
|
|
||||||
px = 0;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
px = strtoul(xp, NULL, 10);
|
|
||||||
if (px + menu->width + 4 >= c->tty.sx)
|
|
||||||
px = c->tty.sx - menu->width - 4;
|
|
||||||
|
|
||||||
yp = args_get(args, 'y');
|
|
||||||
if (yp == NULL)
|
|
||||||
py = 0;
|
|
||||||
else if (strcmp(yp, "P") == 0) {
|
|
||||||
tty_window_offset(&c->tty, &ox, &oy, &sx, &sy);
|
|
||||||
if (wp->yoff + wp->sy >= oy)
|
|
||||||
py = wp->yoff + wp->sy - oy;
|
|
||||||
else
|
|
||||||
py = 0;
|
|
||||||
} else if (strcmp(yp, "M") == 0 && item->shared->mouse.valid)
|
|
||||||
py = item->shared->mouse.y + menu->count + 2;
|
|
||||||
else if (strcmp(yp, "S") == 0) {
|
|
||||||
if (at == -1)
|
|
||||||
py = c->tty.sy;
|
|
||||||
else if (at == 0)
|
|
||||||
py = status_line_size(c) + menu->count + 2;
|
|
||||||
else
|
|
||||||
py = at;
|
|
||||||
} else
|
|
||||||
py = strtoul(yp, NULL, 10);
|
|
||||||
if (py < menu->count + 2)
|
|
||||||
py = 0;
|
|
||||||
else
|
|
||||||
py -= menu->count + 2;
|
|
||||||
if (py + menu->count + 2 >= c->tty.sy)
|
|
||||||
py = c->tty.sy - menu->count - 2;
|
|
||||||
|
|
||||||
flags = 0;
|
|
||||||
if (!item->shared->mouse.valid)
|
|
||||||
flags |= MENU_NOMOUSE;
|
|
||||||
if (menu_display(menu, flags, item, px, py, c, fs, NULL, NULL) != 0)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-display-message.c,v 1.7 2009-11-28 14:39:53 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,100 +26,41 @@
|
|||||||
* Displays a message in the status line.
|
* Displays a message in the status line.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DISPLAY_MESSAGE_TEMPLATE \
|
int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"[#{session_name}] #{window_index}:" \
|
|
||||||
"#{window_name}, current pane #{pane_index} " \
|
|
||||||
"- (%H:%M %d-%b-%y)"
|
|
||||||
|
|
||||||
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",
|
"[-p] " CMD_TARGET_CLIENT_USAGE " [message]",
|
||||||
|
CMD_ARG01, "p",
|
||||||
.args = { "ac:Ipt:F:v", 0, 1 },
|
cmd_target_init,
|
||||||
.usage = "[-aIpv] [-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 void
|
int
|
||||||
cmd_display_message_each(const char *key, const char *value, void *arg)
|
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct cmdq_item *item = arg;
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct client *c;
|
||||||
cmdq_print(item, "%s=%s", key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c, *target_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, *cause;
|
char *msg;
|
||||||
struct format_tree *ft;
|
|
||||||
int flags;
|
|
||||||
|
|
||||||
if (args_has(args, 'I')) {
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
if (window_pane_start_input(wp, item, &cause) != 0) {
|
return (-1);
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'F') && args->argc != 0) {
|
if (data->arg == NULL)
|
||||||
cmdq_error(item, "only one of -F or argument must be given");
|
template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)";
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
|
||||||
if (args->argc != 0)
|
|
||||||
template = args->argv[0];
|
|
||||||
if (template == NULL)
|
|
||||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* -c is intended to be the client where the message should be
|
|
||||||
* displayed if -p is not given. But it makes sense to use it for the
|
|
||||||
* formats too, assuming it matches the session. If it doesn't, use the
|
|
||||||
* best client for the session.
|
|
||||||
*/
|
|
||||||
c = cmd_find_client(item, args_get(args, 'c'), 1);
|
|
||||||
if (c != NULL && c->session == s)
|
|
||||||
target_c = c;
|
|
||||||
else
|
else
|
||||||
target_c = cmd_find_best_client(s);
|
template = data->arg;
|
||||||
if (args_has(self->args, 'v'))
|
|
||||||
flags = FORMAT_VERBOSE;
|
msg = status_replace(c, NULL, template, time(NULL), 0);
|
||||||
|
if (cmd_check_flag(data->chflags, 'p'))
|
||||||
|
ctx->print(ctx, "%s", msg);
|
||||||
else
|
else
|
||||||
flags = 0;
|
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, flags);
|
|
||||||
format_defaults(ft, target_c, s, wl, wp);
|
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
|
||||||
format_each(ft, cmd_display_message_each, item);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = format_expand_time(ft, template);
|
|
||||||
if (args_has(self->args, 'p'))
|
|
||||||
cmdq_print(item, "%s", msg);
|
|
||||||
else if (c != NULL)
|
|
||||||
status_message_set(c, "%s", msg);
|
status_message_set(c, "%s", msg);
|
||||||
free(msg);
|
xfree(msg);
|
||||||
|
|
||||||
format_free(ft);
|
return (0);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-display-panes.c,v 1.2 2009-11-14 17:56:39 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,265 +18,35 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.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 *);
|
|
||||||
|
|
||||||
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, "",
|
||||||
.args = { "bd:t:", 0, 1 },
|
cmd_target_init,
|
||||||
.usage = "[-b] [-d duration] " CMD_TARGET_CLIENT_USAGE " [template]",
|
cmd_target_parse,
|
||||||
|
cmd_display_panes_exec,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_target_free,
|
||||||
.exec = cmd_display_panes_exec
|
cmd_target_print
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_display_panes_data {
|
int
|
||||||
struct cmdq_item *item;
|
cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
char *command;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
|
||||||
struct window_pane *wp)
|
|
||||||
{
|
{
|
||||||
struct client *c = ctx->c;
|
struct cmd_target_data *data = self->data;
|
||||||
struct tty *tty = &c->tty;
|
struct client *c;
|
||||||
struct session *s = c->session;
|
|
||||||
struct options *oo = s->options;
|
|
||||||
struct window *w = wp->window;
|
|
||||||
struct grid_cell gc;
|
|
||||||
u_int idx, px, py, i, j, xoff, yoff, sx, sy;
|
|
||||||
int colour, active_colour;
|
|
||||||
char buf[16], *ptr;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (wp->xoff + wp->sx <= ctx->ox ||
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
wp->xoff >= ctx->ox + ctx->sx ||
|
|
||||||
wp->yoff + wp->sy <= ctx->oy ||
|
|
||||||
wp->yoff >= ctx->oy + ctx->sy)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (wp->xoff >= ctx->ox && wp->xoff + wp->sx <= ctx->ox + ctx->sx) {
|
|
||||||
/* All visible. */
|
|
||||||
xoff = wp->xoff - ctx->ox;
|
|
||||||
sx = wp->sx;
|
|
||||||
} else if (wp->xoff < ctx->ox &&
|
|
||||||
wp->xoff + wp->sx > ctx->ox + ctx->sx) {
|
|
||||||
/* Both left and right not visible. */
|
|
||||||
xoff = 0;
|
|
||||||
sx = ctx->sx;
|
|
||||||
} else if (wp->xoff < ctx->ox) {
|
|
||||||
/* Left not visible. */
|
|
||||||
xoff = 0;
|
|
||||||
sx = wp->sx - (ctx->ox - wp->xoff);
|
|
||||||
} else {
|
|
||||||
/* Right not visible. */
|
|
||||||
xoff = wp->xoff - ctx->ox;
|
|
||||||
sx = wp->sx - xoff;
|
|
||||||
}
|
|
||||||
if (wp->yoff >= ctx->oy && wp->yoff + wp->sy <= ctx->oy + ctx->sy) {
|
|
||||||
/* All visible. */
|
|
||||||
yoff = wp->yoff - ctx->oy;
|
|
||||||
sy = wp->sy;
|
|
||||||
} else if (wp->yoff < ctx->oy &&
|
|
||||||
wp->yoff + wp->sy > ctx->oy + ctx->sy) {
|
|
||||||
/* Both top and bottom not visible. */
|
|
||||||
yoff = 0;
|
|
||||||
sy = ctx->sy;
|
|
||||||
} else if (wp->yoff < ctx->oy) {
|
|
||||||
/* Top not visible. */
|
|
||||||
yoff = 0;
|
|
||||||
sy = wp->sy - (ctx->oy - wp->yoff);
|
|
||||||
} else {
|
|
||||||
/* Bottom not visible. */
|
|
||||||
yoff = wp->yoff - ctx->oy;
|
|
||||||
sy = wp->sy - yoff;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx->statustop)
|
|
||||||
yoff += ctx->statuslines;
|
|
||||||
px = sx / 2;
|
|
||||||
py = sy / 2;
|
|
||||||
|
|
||||||
if (window_pane_index(wp, &idx) != 0)
|
|
||||||
fatalx("index not found");
|
|
||||||
len = xsnprintf(buf, sizeof buf, "%u", idx);
|
|
||||||
|
|
||||||
if (sx < len)
|
|
||||||
return;
|
|
||||||
colour = options_get_number(oo, "display-panes-colour");
|
|
||||||
active_colour = options_get_number(oo, "display-panes-active-colour");
|
|
||||||
|
|
||||||
if (sx < len * 6 || sy < 5) {
|
|
||||||
tty_cursor(tty, xoff + px - len / 2, yoff + py);
|
|
||||||
goto draw_text;
|
|
||||||
}
|
|
||||||
|
|
||||||
px -= len * 3;
|
|
||||||
py -= 2;
|
|
||||||
|
|
||||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
||||||
if (w->active == wp)
|
|
||||||
gc.bg = active_colour;
|
|
||||||
else
|
|
||||||
gc.bg = colour;
|
|
||||||
gc.flags |= GRID_FLAG_NOPALETTE;
|
|
||||||
|
|
||||||
tty_attributes(tty, &gc, wp);
|
|
||||||
for (ptr = buf; *ptr != '\0'; ptr++) {
|
|
||||||
if (*ptr < '0' || *ptr > '9')
|
|
||||||
continue;
|
|
||||||
idx = *ptr - '0';
|
|
||||||
|
|
||||||
for (j = 0; j < 5; j++) {
|
|
||||||
for (i = px; i < px + 5; i++) {
|
|
||||||
tty_cursor(tty, xoff + i, yoff + py + j);
|
|
||||||
if (window_clock_table[idx][j][i - px])
|
|
||||||
tty_putc(tty, ' ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
px += 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = xsnprintf(buf, sizeof buf, "%ux%u", wp->sx, wp->sy);
|
|
||||||
if (sx < len || sy < 6)
|
|
||||||
return;
|
|
||||||
tty_cursor(tty, xoff + sx - len, yoff);
|
|
||||||
|
|
||||||
draw_text:
|
|
||||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
||||||
if (w->active == wp)
|
|
||||||
gc.fg = active_colour;
|
|
||||||
else
|
|
||||||
gc.fg = colour;
|
|
||||||
gc.flags |= GRID_FLAG_NOPALETTE;
|
|
||||||
|
|
||||||
tty_attributes(tty, &gc, wp);
|
|
||||||
tty_puts(tty, buf);
|
|
||||||
|
|
||||||
tty_cursor(tty, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_display_panes_draw(struct client *c, struct screen_redraw_ctx *ctx)
|
|
||||||
{
|
|
||||||
struct window *w = c->session->curw->window;
|
|
||||||
struct window_pane *wp;
|
|
||||||
|
|
||||||
log_debug("%s: %s @%u", __func__, c->name, w->id);
|
|
||||||
|
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
||||||
if (window_pane_visible(wp))
|
|
||||||
cmd_display_panes_draw_pane(ctx, wp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_display_panes_free(struct client *c)
|
|
||||||
{
|
|
||||||
struct cmd_display_panes_data *cdata = c->overlay_data;
|
|
||||||
|
|
||||||
if (cdata->item != NULL)
|
|
||||||
cmdq_continue(cdata->item);
|
|
||||||
free(cdata->command);
|
|
||||||
free(cdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
cmd_display_panes_key(struct client *c, struct key_event *event)
|
|
||||||
{
|
|
||||||
struct cmd_display_panes_data *cdata = c->overlay_data;
|
|
||||||
struct cmdq_item *new_item;
|
|
||||||
char *cmd, *expanded;
|
|
||||||
struct window *w = c->session->curw->window;
|
|
||||||
struct window_pane *wp;
|
|
||||||
struct cmd_parse_result *pr;
|
|
||||||
|
|
||||||
if (event->key < '0' || event->key > '9')
|
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
wp = window_pane_at_index(w, event->key - '0');
|
server_set_identify(c);
|
||||||
if (wp == NULL)
|
|
||||||
return (1);
|
|
||||||
window_unzoom(w);
|
|
||||||
|
|
||||||
xasprintf(&expanded, "%%%u", wp->id);
|
return (0);
|
||||||
cmd = cmd_template_replace(cdata->command, expanded, 1);
|
|
||||||
|
|
||||||
pr = cmd_parse_from_string(cmd, NULL);
|
|
||||||
switch (pr->status) {
|
|
||||||
case CMD_PARSE_EMPTY:
|
|
||||||
new_item = NULL;
|
|
||||||
break;
|
|
||||||
case CMD_PARSE_ERROR:
|
|
||||||
new_item = cmdq_get_error(pr->error);
|
|
||||||
free(pr->error);
|
|
||||||
cmdq_append(c, new_item);
|
|
||||||
break;
|
|
||||||
case CMD_PARSE_SUCCESS:
|
|
||||||
new_item = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
|
|
||||||
cmd_list_free(pr->cmdlist);
|
|
||||||
cmdq_append(c, new_item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(cmd);
|
|
||||||
free(expanded);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct client *c;
|
|
||||||
struct session *s;
|
|
||||||
u_int delay;
|
|
||||||
char *cause;
|
|
||||||
struct cmd_display_panes_data *cdata;
|
|
||||||
|
|
||||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
s = c->session;
|
|
||||||
|
|
||||||
if (c->overlay_draw != NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
if (args_has(args, 'd')) {
|
|
||||||
delay = args_strtonum(args, 'd', 0, UINT_MAX, &cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(item, "delay %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
delay = options_get_number(s->options, "display-panes-time");
|
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
|
||||||
if (args->argc != 0)
|
|
||||||
cdata->command = xstrdup(args->argv[0]);
|
|
||||||
else
|
|
||||||
cdata->command = xstrdup("select-pane -t '%%'");
|
|
||||||
if (args_has(args, 'b'))
|
|
||||||
cdata->item = NULL;
|
|
||||||
else
|
|
||||||
cdata->item = item;
|
|
||||||
|
|
||||||
server_client_set_overlay(c, delay, cmd_display_panes_draw,
|
|
||||||
cmd_display_panes_key, cmd_display_panes_free, cdata);
|
|
||||||
|
|
||||||
if (args_has(args, 'b'))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-find-window.c,v 1.15 2010-12-22 15:28:50 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,7 +18,8 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <fnmatch.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -26,100 +27,149 @@
|
|||||||
* Find window containing text.
|
* Find window containing text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmdq_item *);
|
int cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_find_window_callback(void *, int);
|
||||||
|
void cmd_find_window_free(void *);
|
||||||
|
|
||||||
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, "",
|
||||||
.args = { "CNrt:TZ", 1, 1 },
|
cmd_target_init,
|
||||||
.usage = "[-CNrTZ] " CMD_TARGET_PANE_USAGE " match-string",
|
cmd_target_parse,
|
||||||
|
cmd_find_window_exec,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_find_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
struct cmd_find_window_data {
|
||||||
cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
struct session *session;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args, *new_args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_pane *wp = item->target.wp;
|
struct cmd_find_window_data *cdata;
|
||||||
const char *s = args->argv[0];
|
struct session *s;
|
||||||
char *filter, *argv = { NULL };
|
struct winlink *wl, *wm;
|
||||||
int C, N, T;
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
ARRAY_DECL(, u_int) list_idx;
|
||||||
|
ARRAY_DECL(, char *) list_ctx;
|
||||||
|
char *sres, *sctx, *searchstr;
|
||||||
|
u_int i, line;
|
||||||
|
|
||||||
C = args_has(args, 'C');
|
if (ctx->curclient == NULL) {
|
||||||
N = args_has(args, 'N');
|
ctx->error(ctx, "must be run interactively");
|
||||||
T = args_has(args, 'T');
|
return (-1);
|
||||||
|
}
|
||||||
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
if (!C && !N && !T)
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
C = N = T = 1;
|
return (-1);
|
||||||
|
|
||||||
if (!args_has(args, 'r')) {
|
ARRAY_INIT(&list_idx);
|
||||||
if (C && N && T) {
|
ARRAY_INIT(&list_ctx);
|
||||||
xasprintf(&filter,
|
|
||||||
"#{||:"
|
xasprintf(&searchstr, "*%s*", data->arg);
|
||||||
"#{C:%s},#{||:#{m:*%s*,#{window_name}},"
|
RB_FOREACH(wm, winlinks, &s->windows) {
|
||||||
"#{m:*%s*,#{pane_title}}}}",
|
i = 0;
|
||||||
s, s, s);
|
TAILQ_FOREACH(wp, &wm->window->panes, entry) {
|
||||||
} else if (C && N) {
|
i++;
|
||||||
xasprintf(&filter,
|
|
||||||
"#{||:#{C:%s},#{m:*%s*,#{window_name}}}",
|
if (fnmatch(searchstr, wm->window->name, 0) == 0)
|
||||||
s, s);
|
sctx = xstrdup("");
|
||||||
} else if (C && T) {
|
else {
|
||||||
xasprintf(&filter,
|
sres = window_pane_search(wp, data->arg, &line);
|
||||||
"#{||:#{C:%s},#{m:*%s*,#{pane_title}}}",
|
if (sres == NULL &&
|
||||||
s, s);
|
fnmatch(searchstr, wp->base.title, 0) != 0)
|
||||||
} else if (N && T) {
|
continue;
|
||||||
xasprintf(&filter,
|
|
||||||
"#{||:#{m:*%s*,#{window_name}},"
|
if (sres == NULL) {
|
||||||
"#{m:*%s*,#{pane_title}}}",
|
xasprintf(&sctx,
|
||||||
s, s);
|
"pane %u title: \"%s\"", i - 1,
|
||||||
} else if (C)
|
wp->base.title);
|
||||||
xasprintf(&filter, "#{C:%s}", s);
|
} else {
|
||||||
else if (N)
|
xasprintf(&sctx,
|
||||||
xasprintf(&filter, "#{m:*%s*,#{window_name}}", s);
|
"pane %u line %u: \"%s\"", i - 1,
|
||||||
else
|
line + 1, sres);
|
||||||
xasprintf(&filter, "#{m:*%s*,#{pane_title}}", s);
|
xfree(sres);
|
||||||
} else {
|
}
|
||||||
if (C && N && T) {
|
}
|
||||||
xasprintf(&filter,
|
|
||||||
"#{||:"
|
ARRAY_ADD(&list_idx, wm->idx);
|
||||||
"#{C/r:%s},#{||:#{m/r:%s,#{window_name}},"
|
ARRAY_ADD(&list_ctx, sctx);
|
||||||
"#{m/r:%s,#{pane_title}}}}",
|
}
|
||||||
s, s, s);
|
}
|
||||||
} else if (C && N) {
|
xfree(searchstr);
|
||||||
xasprintf(&filter,
|
|
||||||
"#{||:#{C/r:%s},#{m/r:%s,#{window_name}}}",
|
if (ARRAY_LENGTH(&list_idx) == 0) {
|
||||||
s, s);
|
ctx->error(ctx, "no windows matching: %s", data->arg);
|
||||||
} else if (C && T) {
|
ARRAY_FREE(&list_idx);
|
||||||
xasprintf(&filter,
|
ARRAY_FREE(&list_ctx);
|
||||||
"#{||:#{C/r:%s},#{m/r:%s,#{pane_title}}}",
|
return (-1);
|
||||||
s, s);
|
|
||||||
} else if (N && T) {
|
|
||||||
xasprintf(&filter,
|
|
||||||
"#{||:#{m/r:%s,#{window_name}},"
|
|
||||||
"#{m/r:%s,#{pane_title}}}",
|
|
||||||
s, s);
|
|
||||||
} else if (C)
|
|
||||||
xasprintf(&filter, "#{C/r:%s}", s);
|
|
||||||
else if (N)
|
|
||||||
xasprintf(&filter, "#{m/r:%s,#{window_name}}", s);
|
|
||||||
else
|
|
||||||
xasprintf(&filter, "#{m/r:%s,#{pane_title}}", s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new_args = args_parse("", 1, &argv);
|
if (ARRAY_LENGTH(&list_idx) == 1) {
|
||||||
if (args_has(args, 'Z'))
|
if (session_select(s, ARRAY_FIRST(&list_idx)) == 0)
|
||||||
args_set(new_args, 'Z', NULL);
|
server_redraw_session(s);
|
||||||
args_set(new_args, 'f', filter);
|
recalculate_sizes();
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
window_pane_set_mode(wp, &window_tree_mode, &item->target, new_args);
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
args_free(new_args);
|
for (i = 0; i < ARRAY_LENGTH(&list_idx); i++) {
|
||||||
free(filter);
|
wm = winlink_find_by_index(
|
||||||
|
&s->windows, ARRAY_ITEM(&list_idx, i));
|
||||||
|
w = wm->window;
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
sctx = ARRAY_ITEM(&list_ctx, i);
|
||||||
|
window_choose_add(wl->window->active,
|
||||||
|
wm->idx, "%3d: %s [%ux%u] (%u panes) %s", wm->idx, w->name,
|
||||||
|
w->sx, w->sy, window_count_panes(w), sctx);
|
||||||
|
xfree(sctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
0, cmd_find_window_callback, cmd_find_window_free, cdata);
|
||||||
|
|
||||||
|
out:
|
||||||
|
ARRAY_FREE(&list_idx);
|
||||||
|
ARRAY_FREE(&list_ctx);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_find_window_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_find_window_data *cdata = data;
|
||||||
|
struct session *s = cdata->session;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (!session_alive(s))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (session_select(s, idx) == 0) {
|
||||||
|
server_redraw_session(s);
|
||||||
|
recalculate_sizes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_find_window_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_find_window_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->session->references--;
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
1300
cmd-find.c
1300
cmd-find.c
File diff suppressed because it is too large
Load Diff
423
cmd-generic.c
Normal file
423
cmd-generic.c
Normal file
@@ -0,0 +1,423 @@
|
|||||||
|
/* $Id: cmd-generic.c,v 1.38 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
int cmd_getopt(int, char **, const char *, const char *);
|
||||||
|
int cmd_parse_flags(int, const char *, uint64_t *);
|
||||||
|
size_t cmd_print_flags(char *, size_t, size_t, uint64_t);
|
||||||
|
int cmd_fill_argument(int, char **, char **, int, char **);
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_prarg(char *buf, size_t len, const char *prefix, char *arg)
|
||||||
|
{
|
||||||
|
if (strchr(arg, ' ') != NULL)
|
||||||
|
return (xsnprintf(buf, len, "%s\"%s\"", prefix, arg));
|
||||||
|
return (xsnprintf(buf, len, "%s%s", prefix, arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Append two flag strings together and call getopt. */
|
||||||
|
int
|
||||||
|
cmd_getopt(int argc, char **argv, const char *flagstr, const char *chflagstr)
|
||||||
|
{
|
||||||
|
char tmp[BUFSIZ];
|
||||||
|
|
||||||
|
if (strlcpy(tmp, flagstr, sizeof tmp) >= sizeof tmp)
|
||||||
|
fatalx("strlcpy overflow");
|
||||||
|
if (strlcat(tmp, chflagstr, sizeof tmp) >= sizeof tmp)
|
||||||
|
fatalx("strlcat overflow");
|
||||||
|
return (getopt(argc, argv, tmp));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return if flag character is set. */
|
||||||
|
int
|
||||||
|
cmd_check_flag(uint64_t chflags, int flag)
|
||||||
|
{
|
||||||
|
if (flag >= 'A' && flag <= 'Z')
|
||||||
|
flag = 26 + flag - 'A';
|
||||||
|
else if (flag >= 'a' && flag <= 'z')
|
||||||
|
flag = flag - 'a';
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
return ((chflags & (1ULL << flag)) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set flag character. */
|
||||||
|
void
|
||||||
|
cmd_set_flag(uint64_t *chflags, int flag)
|
||||||
|
{
|
||||||
|
if (flag >= 'A' && flag <= 'Z')
|
||||||
|
flag = 26 + flag - 'A';
|
||||||
|
else if (flag >= 'a' && flag <= 'z')
|
||||||
|
flag = flag - 'a';
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
(*chflags) |= (1ULL << flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If this option is expected, set it in chflags, otherwise return -1. */
|
||||||
|
int
|
||||||
|
cmd_parse_flags(int opt, const char *chflagstr, uint64_t *chflags)
|
||||||
|
{
|
||||||
|
if (strchr(chflagstr, opt) == NULL)
|
||||||
|
return (-1);
|
||||||
|
cmd_set_flag(chflags, opt);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the flags present in chflags. */
|
||||||
|
size_t
|
||||||
|
cmd_print_flags(char *buf, size_t len, size_t off, uint64_t chflags)
|
||||||
|
{
|
||||||
|
u_char ch;
|
||||||
|
size_t boff = off;
|
||||||
|
|
||||||
|
if (chflags == 0)
|
||||||
|
return (0);
|
||||||
|
off += xsnprintf(buf + off, len - off, " -");
|
||||||
|
|
||||||
|
for (ch = 0; ch < 26; ch++) {
|
||||||
|
if (cmd_check_flag(chflags, 'a' + ch))
|
||||||
|
off += xsnprintf(buf + off, len - off, "%c", 'a' + ch);
|
||||||
|
if (cmd_check_flag(chflags, 'A' + ch))
|
||||||
|
off += xsnprintf(buf + off, len - off, "%c", 'A' + ch);
|
||||||
|
}
|
||||||
|
return (off - boff);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_fill_argument(int flags, char **arg, char **arg2, int argc, char **argv)
|
||||||
|
{
|
||||||
|
*arg = NULL;
|
||||||
|
*arg2 = NULL;
|
||||||
|
|
||||||
|
if (flags & CMD_ARG1) {
|
||||||
|
if (argc != 1)
|
||||||
|
return (-1);
|
||||||
|
*arg = xstrdup(argv[0]);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & CMD_ARG01) {
|
||||||
|
if (argc != 0 && argc != 1)
|
||||||
|
return (-1);
|
||||||
|
if (argc == 1)
|
||||||
|
*arg = xstrdup(argv[0]);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & CMD_ARG2) {
|
||||||
|
if (argc != 2)
|
||||||
|
return (-1);
|
||||||
|
*arg = xstrdup(argv[0]);
|
||||||
|
*arg2 = xstrdup(argv[1]);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & CMD_ARG12) {
|
||||||
|
if (argc != 1 && argc != 2)
|
||||||
|
return (-1);
|
||||||
|
*arg = xstrdup(argv[0]);
|
||||||
|
if (argc == 2)
|
||||||
|
*arg2 = xstrdup(argv[1]);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc != 0)
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_target_init(struct cmd *self, unused int key)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->chflags = 0;
|
||||||
|
data->target = NULL;
|
||||||
|
data->arg = NULL;
|
||||||
|
data->arg2 = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
const struct cmd_entry *entry = self->entry;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
/* Don't use the entry version since it may be dependent on key. */
|
||||||
|
cmd_target_init(self, 0);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = cmd_getopt(argc, argv, "t:", entry->chflags)) != -1) {
|
||||||
|
if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
|
||||||
|
continue;
|
||||||
|
switch (opt) {
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (cmd_fill_argument(
|
||||||
|
self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
|
||||||
|
goto usage;
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_target_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
xfree(data->arg);
|
||||||
|
if (data->arg2 != NULL)
|
||||||
|
xfree(data->arg2);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_target_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
off += cmd_print_flags(buf, len, off, data->chflags);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->arg != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||||
|
if (off < len && data->arg2 != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_srcdst_init(struct cmd *self, unused int key)
|
||||||
|
{
|
||||||
|
struct cmd_srcdst_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->chflags = 0;
|
||||||
|
data->src = NULL;
|
||||||
|
data->dst = NULL;
|
||||||
|
data->arg = NULL;
|
||||||
|
data->arg2 = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_srcdst_data *data;
|
||||||
|
const struct cmd_entry *entry = self->entry;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
cmd_srcdst_init(self, 0);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = cmd_getopt(argc, argv, "s:t:", entry->chflags)) != -1) {
|
||||||
|
if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
|
||||||
|
continue;
|
||||||
|
switch (opt) {
|
||||||
|
case 's':
|
||||||
|
if (data->src == NULL)
|
||||||
|
data->src = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->dst == NULL)
|
||||||
|
data->dst = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (cmd_fill_argument(
|
||||||
|
self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
|
||||||
|
goto usage;
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_srcdst_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_srcdst_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->src != NULL)
|
||||||
|
xfree(data->src);
|
||||||
|
if (data->dst != NULL)
|
||||||
|
xfree(data->dst);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
xfree(data->arg);
|
||||||
|
if (data->arg2 != NULL)
|
||||||
|
xfree(data->arg2);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_srcdst_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_srcdst_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
off += cmd_print_flags(buf, len, off, data->chflags);
|
||||||
|
if (off < len && data->src != NULL)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -s %s", data->src);
|
||||||
|
if (off < len && data->dst != NULL)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -t %s", data->dst);
|
||||||
|
if (off < len && data->arg != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||||
|
if (off < len && data->arg2 != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_buffer_init(struct cmd *self, unused int key)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data;
|
||||||
|
|
||||||
|
self->data = data = xmalloc(sizeof *data);
|
||||||
|
data->chflags = 0;
|
||||||
|
data->target = NULL;
|
||||||
|
data->buffer = -1;
|
||||||
|
data->arg = NULL;
|
||||||
|
data->arg2 = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data;
|
||||||
|
const struct cmd_entry *entry = self->entry;
|
||||||
|
int opt, n;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
|
cmd_buffer_init(self, 0);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = cmd_getopt(argc, argv, "b:t:", entry->chflags)) != -1) {
|
||||||
|
if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
|
||||||
|
continue;
|
||||||
|
switch (opt) {
|
||||||
|
case 'b':
|
||||||
|
if (data->buffer == -1) {
|
||||||
|
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "buffer %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
data->buffer = n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (cmd_fill_argument(
|
||||||
|
self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
|
||||||
|
goto usage;
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_buffer_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
if (data->arg != NULL)
|
||||||
|
xfree(data->arg);
|
||||||
|
if (data->arg2 != NULL)
|
||||||
|
xfree(data->arg2);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_buffer_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_buffer_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
off += cmd_print_flags(buf, len, off, data->chflags);
|
||||||
|
if (off < len && data->buffer != -1)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -b %d", data->buffer);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->arg != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||||
|
if (off < len && data->arg2 != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
/* $Id: cmd-has-session.c,v 1.15 2009-11-14 17:56:39 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,19 +18,32 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <limits.h>
|
#include "tmux.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, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_has_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
getptmfd(void)
|
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
return (INT_MAX);
|
struct cmd_target_data *data = self->data;
|
||||||
}
|
|
||||||
|
|
||||||
pid_t
|
if (cmd_find_session(ctx, data->target) == NULL)
|
||||||
fdforkpty(__unused int ptmfd, int *master, char *name, struct termios *tio,
|
return (-1);
|
||||||
struct winsize *ws)
|
|
||||||
{
|
return (0);
|
||||||
return (forkpty(master, name, tio, ws));
|
|
||||||
}
|
}
|
||||||
224
cmd-if-shell.c
224
cmd-if-shell.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-if-shell.c,v 1.10 2010-08-09 21:44:25 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -20,202 +20,100 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Executes a tmux command if a shell command returns true or false.
|
* Executes a tmux command if a shell command returns true.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmdq_item *);
|
int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static void cmd_if_shell_callback(struct job *);
|
void cmd_if_shell_callback(struct job *);
|
||||||
static void cmd_if_shell_free(void *);
|
void cmd_if_shell_free(void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_if_shell_entry = {
|
const struct cmd_entry cmd_if_shell_entry = {
|
||||||
.name = "if-shell",
|
"if-shell", "if",
|
||||||
.alias = "if",
|
"shell-command command",
|
||||||
|
CMD_ARG2, "",
|
||||||
.args = { "bFt:", 2, 3 },
|
cmd_target_init,
|
||||||
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
|
cmd_target_parse,
|
||||||
"[command]",
|
cmd_if_shell_exec,
|
||||||
|
cmd_target_free,
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
cmd_target_print
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_if_shell_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_if_shell_data {
|
struct cmd_if_shell_data {
|
||||||
struct cmd_parse_input input;
|
char *cmd;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
char *cmd_if;
|
|
||||||
char *cmd_else;
|
|
||||||
|
|
||||||
struct client *client;
|
|
||||||
struct cmdq_item *item;
|
|
||||||
struct mouse_event mouse;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct mouse_event *m = &item->shared->mouse;
|
|
||||||
struct cmd_if_shell_data *cdata;
|
struct cmd_if_shell_data *cdata;
|
||||||
char *shellcmd, *cmd;
|
struct job *job;
|
||||||
struct cmdq_item *new_item;
|
|
||||||
struct cmd_find_state *fs = &item->target;
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
struct session *s = fs->s;
|
|
||||||
struct winlink *wl = fs->wl;
|
|
||||||
struct window_pane *wp = fs->wp;
|
|
||||||
struct cmd_parse_input pi;
|
|
||||||
struct cmd_parse_result *pr;
|
|
||||||
|
|
||||||
shellcmd = format_single(item, args->argv[0], c, s, wl, wp);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
if (args_has(args, 'F')) {
|
cdata->cmd = xstrdup(data->arg2);
|
||||||
if (*shellcmd != '0' && *shellcmd != '\0')
|
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||||
cmd = args->argv[1];
|
|
||||||
else if (args->argc == 3)
|
|
||||||
cmd = args->argv[2];
|
|
||||||
else
|
|
||||||
cmd = NULL;
|
|
||||||
free(shellcmd);
|
|
||||||
if (cmd == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
memset(&pi, 0, sizeof pi);
|
if (ctx->cmdclient != NULL)
|
||||||
if (self->file != NULL)
|
ctx->cmdclient->references++;
|
||||||
pi.file = self->file;
|
if (ctx->curclient != NULL)
|
||||||
pi.line = self->line;
|
ctx->curclient->references++;
|
||||||
pi.item = item;
|
|
||||||
pi.c = c;
|
|
||||||
cmd_find_copy_state(&pi.fs, fs);
|
|
||||||
|
|
||||||
pr = cmd_parse_from_string(cmd, &pi);
|
job = job_add(NULL, 0, NULL,
|
||||||
switch (pr->status) {
|
data->arg, cmd_if_shell_callback, cmd_if_shell_free, cdata);
|
||||||
case CMD_PARSE_EMPTY:
|
job_run(job);
|
||||||
break;
|
|
||||||
case CMD_PARSE_ERROR:
|
|
||||||
cmdq_error(item, "%s", pr->error);
|
|
||||||
free(pr->error);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
case CMD_PARSE_SUCCESS:
|
|
||||||
new_item = cmdq_get_command(pr->cmdlist, fs, m, 0);
|
|
||||||
cmdq_insert_after(item, new_item);
|
|
||||||
cmd_list_free(pr->cmdlist);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
return (1); /* don't let client exit */
|
||||||
|
|
||||||
cdata->cmd_if = xstrdup(args->argv[1]);
|
|
||||||
if (args->argc == 3)
|
|
||||||
cdata->cmd_else = xstrdup(args->argv[2]);
|
|
||||||
else
|
|
||||||
cdata->cmd_else = NULL;
|
|
||||||
memcpy(&cdata->mouse, m, sizeof cdata->mouse);
|
|
||||||
|
|
||||||
if (!args_has(args, 'b'))
|
|
||||||
cdata->client = item->client;
|
|
||||||
else
|
|
||||||
cdata->client = c;
|
|
||||||
if (cdata->client != NULL)
|
|
||||||
cdata->client->references++;
|
|
||||||
|
|
||||||
if (!args_has(args, 'b'))
|
|
||||||
cdata->item = item;
|
|
||||||
else
|
|
||||||
cdata->item = NULL;
|
|
||||||
|
|
||||||
memset(&cdata->input, 0, sizeof cdata->input);
|
|
||||||
if (self->file != NULL)
|
|
||||||
cdata->input.file = xstrdup(self->file);
|
|
||||||
cdata->input.line = self->line;
|
|
||||||
cdata->input.item = cdata->item;
|
|
||||||
cdata->input.c = c;
|
|
||||||
if (cdata->input.c != NULL)
|
|
||||||
cdata->input.c->references++;
|
|
||||||
cmd_find_copy_state(&cdata->input.fs, fs);
|
|
||||||
|
|
||||||
if (job_run(shellcmd, s, server_client_get_cwd(item->client, s), NULL,
|
|
||||||
cmd_if_shell_callback, cmd_if_shell_free, cdata, 0) == NULL) {
|
|
||||||
cmdq_error(item, "failed to run command: %s", shellcmd);
|
|
||||||
free(shellcmd);
|
|
||||||
free(cdata);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
free(shellcmd);
|
|
||||||
|
|
||||||
if (args_has(args, 'b'))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_if_shell_callback(struct job *job)
|
cmd_if_shell_callback(struct job *job)
|
||||||
{
|
{
|
||||||
struct cmd_if_shell_data *cdata = job_get_data(job);
|
struct cmd_if_shell_data *cdata = job->data;
|
||||||
struct client *c = cdata->client;
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
struct mouse_event *m = &cdata->mouse;
|
struct cmd_list *cmdlist;
|
||||||
struct cmdq_item *new_item = NULL;
|
char *cause;
|
||||||
char *cmd;
|
|
||||||
int status;
|
|
||||||
struct cmd_parse_result *pr;
|
|
||||||
|
|
||||||
status = job_get_status(job);
|
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
||||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
return;
|
||||||
cmd = cdata->cmd_else;
|
|
||||||
else
|
|
||||||
cmd = cdata->cmd_if;
|
|
||||||
if (cmd == NULL)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
pr = cmd_parse_from_string(cmd, &cdata->input);
|
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||||
switch (pr->status) {
|
if (cause != NULL) {
|
||||||
case CMD_PARSE_EMPTY:
|
ctx->error(ctx, "%s", cause);
|
||||||
break;
|
xfree(cause);
|
||||||
case CMD_PARSE_ERROR:
|
}
|
||||||
if (cdata->item != NULL)
|
return;
|
||||||
cmdq_error(cdata->item, "%s", pr->error);
|
|
||||||
free(pr->error);
|
|
||||||
break;
|
|
||||||
case CMD_PARSE_SUCCESS:
|
|
||||||
new_item = cmdq_get_command(pr->cmdlist, NULL, m, 0);
|
|
||||||
cmd_list_free(pr->cmdlist);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (new_item != NULL) {
|
|
||||||
if (cdata->item == NULL)
|
|
||||||
cmdq_append(c, new_item);
|
|
||||||
else
|
|
||||||
cmdq_insert_after(cdata->item, new_item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
if (cmd_list_exec(cmdlist, ctx) < 0) {
|
||||||
if (cdata->item != NULL)
|
cmd_list_free(cmdlist);
|
||||||
cmdq_continue(cdata->item);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_if_shell_free(void *data)
|
cmd_if_shell_free(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_if_shell_data *cdata = data;
|
struct cmd_if_shell_data *cdata = data;
|
||||||
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
struct msg_exit_data exitdata;
|
||||||
|
|
||||||
if (cdata->client != NULL)
|
if (ctx->cmdclient != NULL) {
|
||||||
server_client_unref(cdata->client);
|
ctx->cmdclient->references--;
|
||||||
|
exitdata.retcode = ctx->cmdclient->retcode;
|
||||||
|
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||||
|
}
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references--;
|
||||||
|
|
||||||
free(cdata->cmd_else);
|
xfree(cdata->cmd);
|
||||||
free(cdata->cmd_if);
|
xfree(cdata);
|
||||||
|
|
||||||
if (cdata->input.c != NULL)
|
|
||||||
server_client_unref(cdata->input.c);
|
|
||||||
free((void *)cdata->input.file);
|
|
||||||
|
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|||||||
308
cmd-join-pane.c
308
cmd-join-pane.c
@@ -1,8 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-join-pane.c,v 1.5 2010-08-11 22:17:32 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
* Copyright (c) 2009 Nicholas Marriott <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
|
||||||
@@ -20,149 +19,187 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Join or move a pane into another (like split/swap/kill).
|
* Join a pane into another (like split/swap/kill).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmdq_item *);
|
int cmd_join_pane_parse(struct cmd *, int, char **, char **);
|
||||||
|
int cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_join_pane_free(struct cmd *);
|
||||||
|
void cmd_join_pane_init(struct cmd *, int);
|
||||||
|
size_t cmd_join_pane_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
|
struct cmd_join_pane_data {
|
||||||
|
char *src;
|
||||||
|
char *dst;
|
||||||
|
int flag_detached;
|
||||||
|
int flag_horizontal;
|
||||||
|
int percentage;
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_join_pane_entry = {
|
const struct cmd_entry cmd_join_pane_entry = {
|
||||||
.name = "join-pane",
|
"join-pane", "joinp",
|
||||||
.alias = "joinp",
|
"[-dhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
|
||||||
|
0, "",
|
||||||
.args = { "bdfhvp:l:s:t:", 0, 0 },
|
cmd_join_pane_init,
|
||||||
.usage = "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE,
|
cmd_join_pane_parse,
|
||||||
|
cmd_join_pane_exec,
|
||||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
cmd_join_pane_free,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_join_pane_print
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_join_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_move_pane_entry = {
|
void
|
||||||
.name = "move-pane",
|
cmd_join_pane_init(struct cmd *self, int key)
|
||||||
.alias = "movep",
|
|
||||||
|
|
||||||
.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
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_join_pane_data *data;
|
||||||
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, *copy;
|
|
||||||
const char *errstr, *p;
|
|
||||||
size_t plen;
|
|
||||||
int size, percentage, dst_idx, not_same_window;
|
|
||||||
int flags;
|
|
||||||
enum layout_type type;
|
|
||||||
struct layout_cell *lc;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_join_pane_entry)
|
self->data = data = xmalloc(sizeof *data);
|
||||||
not_same_window = 1;
|
data->src = NULL;
|
||||||
else
|
data->dst = NULL;
|
||||||
not_same_window = 0;
|
data->flag_detached = 0;
|
||||||
|
data->flag_horizontal = 0;
|
||||||
|
data->percentage = -1;
|
||||||
|
data->size = -1;
|
||||||
|
|
||||||
dst_s = item->target.s;
|
switch (key) {
|
||||||
dst_wl = item->target.wl;
|
case '%':
|
||||||
dst_wp = item->target.wp;
|
data->flag_horizontal = 1;
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
data->flag_horizontal = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_join_pane_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_join_pane_data *data;
|
||||||
|
int opt;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "dhl:p:s:t:v")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'd':
|
||||||
|
data->flag_detached = 1;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
data->flag_horizontal = 1;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
if (data->src == NULL)
|
||||||
|
data->src = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->dst == NULL)
|
||||||
|
data->dst = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
if (data->percentage != -1 || data->size != -1)
|
||||||
|
break;
|
||||||
|
data->size = strtonum(optarg, 1, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "size %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
if (data->size != -1 || data->percentage != -1)
|
||||||
|
break;
|
||||||
|
data->percentage = strtonum(optarg, 1, 100, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "percentage %s", errstr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
data->flag_horizontal = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 0)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_join_pane_data *data = self->data;
|
||||||
|
struct session *dst_s;
|
||||||
|
struct winlink *src_wl, *dst_wl;
|
||||||
|
struct window *src_w, *dst_w;
|
||||||
|
struct window_pane *src_wp, *dst_wp;
|
||||||
|
int size, dst_idx;
|
||||||
|
enum layout_type type;
|
||||||
|
struct layout_cell *lc;
|
||||||
|
|
||||||
|
if ((dst_wl = cmd_find_pane(ctx, data->dst, &dst_s, &dst_wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
dst_w = dst_wl->window;
|
dst_w = dst_wl->window;
|
||||||
dst_idx = dst_wl->idx;
|
dst_idx = dst_wl->idx;
|
||||||
server_unzoom_window(dst_w);
|
|
||||||
|
|
||||||
src_wl = item->source.wl;
|
if ((src_wl = cmd_find_pane(ctx, data->src, NULL, &src_wp)) == NULL)
|
||||||
src_wp = item->source.wp;
|
return (-1);
|
||||||
src_w = src_wl->window;
|
src_w = src_wl->window;
|
||||||
server_unzoom_window(src_w);
|
|
||||||
|
|
||||||
if (not_same_window && src_w == dst_w) {
|
if (src_w == dst_w) {
|
||||||
cmdq_error(item, "can't join a pane to its own window");
|
ctx->error(ctx, "can't join a pane to its own window");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
|
||||||
if (!not_same_window && src_wp == dst_wp) {
|
|
||||||
cmdq_error(item, "source and target panes must be different");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type = LAYOUT_TOPBOTTOM;
|
type = LAYOUT_TOPBOTTOM;
|
||||||
if (args_has(args, 'h'))
|
if (data->flag_horizontal)
|
||||||
type = LAYOUT_LEFTRIGHT;
|
type = LAYOUT_LEFTRIGHT;
|
||||||
|
|
||||||
size = -1;
|
size = -1;
|
||||||
if ((p = args_get(args, 'l')) != NULL) {
|
if (data->size != -1)
|
||||||
plen = strlen(p);
|
size = data->size;
|
||||||
if (p[plen - 1] == '%') {
|
else if (data->percentage != -1) {
|
||||||
copy = xstrdup(p);
|
|
||||||
copy[plen - 1] = '\0';
|
|
||||||
percentage = strtonum(copy, 0, INT_MAX, &errstr);
|
|
||||||
free(copy);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "percentage %s", errstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (type == LAYOUT_TOPBOTTOM)
|
|
||||||
size = (dst_wp->sy * percentage) / 100;
|
|
||||||
else
|
|
||||||
size = (dst_wp->sx * percentage) / 100;
|
|
||||||
} else {
|
|
||||||
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)
|
if (type == LAYOUT_TOPBOTTOM)
|
||||||
size = (dst_wp->sy * percentage) / 100;
|
size = (dst_wp->sy * data->percentage) / 100;
|
||||||
else
|
else
|
||||||
size = (dst_wp->sx * percentage) / 100;
|
size = (dst_wp->sx * data->percentage) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = 0;
|
if ((lc = layout_split_pane(dst_wp, type, size)) == NULL) {
|
||||||
if (args_has(args, 'b'))
|
ctx->error(ctx, "create pane failed: pane too small");
|
||||||
flags |= SPAWN_BEFORE;
|
return (-1);
|
||||||
if (args_has(args, 'f'))
|
|
||||||
flags |= SPAWN_FULLSIZE;
|
|
||||||
|
|
||||||
lc = layout_split_pane(dst_wp, type, size, flags);
|
|
||||||
if (lc == NULL) {
|
|
||||||
cmdq_error(item, "create pane failed: pane too small");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
layout_close_pane(src_wp);
|
layout_close_pane(src_wp);
|
||||||
|
|
||||||
window_lost_pane(src_w, src_wp);
|
if (src_w->active == src_wp) {
|
||||||
|
src_w->active = TAILQ_PREV(src_wp, window_panes, entry);
|
||||||
|
if (src_w->active == NULL)
|
||||||
|
src_w->active = TAILQ_NEXT(src_wp, entry);
|
||||||
|
}
|
||||||
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
||||||
|
|
||||||
|
if (window_count_panes(src_w) == 0)
|
||||||
|
server_kill_window(src_w);
|
||||||
|
|
||||||
src_wp->window = dst_w;
|
src_wp->window = dst_w;
|
||||||
options_set_parent(src_wp->options, dst_w->options);
|
|
||||||
src_wp->flags |= PANE_STYLECHANGED;
|
|
||||||
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
||||||
layout_assign_pane(lc, src_wp);
|
layout_assign_pane(lc, src_wp);
|
||||||
|
|
||||||
@@ -171,19 +208,50 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
server_redraw_window(src_w);
|
server_redraw_window(src_w);
|
||||||
server_redraw_window(dst_w);
|
server_redraw_window(dst_w);
|
||||||
|
|
||||||
if (!args_has(args, 'd')) {
|
if (!data->flag_detached) {
|
||||||
window_set_active_pane(dst_w, src_wp, 1);
|
window_set_active_pane(dst_w, src_wp);
|
||||||
session_select(dst_s, dst_idx);
|
session_select(dst_s, dst_idx);
|
||||||
cmd_find_from_session(current, dst_s, 0);
|
|
||||||
server_redraw_session(dst_s);
|
server_redraw_session(dst_s);
|
||||||
} else
|
} else
|
||||||
server_status_session(dst_s);
|
server_status_session(dst_s);
|
||||||
|
|
||||||
if (window_count_panes(src_w) == 0)
|
return (0);
|
||||||
server_kill_window(src_w);
|
}
|
||||||
else
|
|
||||||
notify_window("window-layout-changed", src_w);
|
void
|
||||||
notify_window("window-layout-changed", dst_w);
|
cmd_join_pane_free(struct cmd *self)
|
||||||
|
{
|
||||||
return (CMD_RETURN_NORMAL);
|
struct cmd_join_pane_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->src != NULL)
|
||||||
|
xfree(data->src);
|
||||||
|
if (data->dst != NULL)
|
||||||
|
xfree(data->dst);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_join_pane_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_join_pane_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->flag_detached)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && data->flag_horizontal)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -h");
|
||||||
|
if (off < len && data->size > 0)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -l %d", data->size);
|
||||||
|
if (off < len && data->percentage > 0) {
|
||||||
|
off += xsnprintf(
|
||||||
|
buf + off, len - off, " -p %d", data->percentage);
|
||||||
|
}
|
||||||
|
if (off < len && data->src != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -s ", data->src);
|
||||||
|
if (off < len && data->dst != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->dst);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-kill-pane.c,v 1.15 2009-11-14 17:56:39 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,39 +26,51 @@
|
|||||||
* 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",
|
"[-a] " CMD_TARGET_PANE_USAGE,
|
||||||
|
0, "a",
|
||||||
.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 = CMD_AFTERHOOK,
|
|
||||||
.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 *loopwp, *nextwp, *wp;
|
||||||
|
|
||||||
if (args_has(self->args, 'a')) {
|
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||||
server_unzoom_window(wl->window);
|
return (-1);
|
||||||
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
|
|
||||||
if (loopwp == wp)
|
if (window_count_panes(wl->window) == 1) {
|
||||||
continue;
|
/* Only one pane, kill the window. */
|
||||||
layout_close_pane(loopwp);
|
server_kill_window(wl->window);
|
||||||
window_remove_pane(wl->window, loopwp);
|
recalculate_sizes();
|
||||||
}
|
return (0);
|
||||||
server_redraw_window(wl->window);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
server_kill_pane(wp);
|
if (cmd_check_flag(data->chflags, 'a')) {
|
||||||
return (CMD_RETURN_NORMAL);
|
loopwp = TAILQ_FIRST(&wl->window->panes);
|
||||||
|
while (loopwp != NULL) {
|
||||||
|
nextwp = TAILQ_NEXT(loopwp, entry);
|
||||||
|
if (loopwp != wp) {
|
||||||
|
layout_close_pane(loopwp);
|
||||||
|
window_remove_pane(wl->window, loopwp);
|
||||||
|
}
|
||||||
|
loopwp = nextwp;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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.11 2009-11-28 14:50:36 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,24 @@
|
|||||||
* 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, "",
|
||||||
.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 = {
|
/* ARGSUSED */
|
||||||
.name = "start-server",
|
int
|
||||||
.alias = "start",
|
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
|
|
||||||
.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)
|
kill(getpid(), SIGTERM);
|
||||||
kill(getpid(), SIGTERM);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-kill-session.c,v 1.18 2010-07-02 02:43:50 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,30 @@
|
|||||||
* Note this deliberately has no alias to make it hard to hit by accident.
|
* Note this deliberately has no alias to make it hard to hit by accident.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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, "",
|
||||||
.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;
|
|
||||||
|
|
||||||
s = item->target.s;
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
if (args_has(args, 'C')) {
|
server_destroy_session(s);
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
session_destroy(s);
|
||||||
wl->window->flags &= ~WINDOW_ALERTFLAGS;
|
|
||||||
wl->flags &= ~WINLINK_ALERTFLAGS;
|
return (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, 1, __func__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
server_destroy_session(s);
|
|
||||||
session_destroy(s, 1, __func__);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-kill-window.c,v 1.21 2009-11-14 17:56:39 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,30 @@
|
|||||||
* 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, "",
|
||||||
.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
server_kill_window(wl->window);
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
58
cmd-last-pane.c
Normal file
58
cmd-last-pane.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/* $Id: cmd-last-pane.c,v 1.1 2010-10-24 01:34:30 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move to last pane.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_last_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_last_pane_entry = {
|
||||||
|
"last-pane", "lastp",
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_last_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_last_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
|
if (w->last == NULL) {
|
||||||
|
ctx->error(ctx, "no last pane");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
window_set_active_pane(w, w->last);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
58
cmd-last-window.c
Normal file
58
cmd-last-window.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/* $Id: cmd-last-window.c,v 1.19 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move to last window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_last_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_last_window_entry = {
|
||||||
|
"last-window", "last",
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_last_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_last_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (session_last(s) == 0)
|
||||||
|
server_redraw_session(s);
|
||||||
|
else {
|
||||||
|
ctx->error(ctx, "no last window");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
66
cmd-link-window.c
Normal file
66
cmd-link-window.c
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/* $Id: cmd-link-window.c,v 1.36 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Link a window into another session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_link_window_entry = {
|
||||||
|
"link-window", "linkw",
|
||||||
|
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
|
0, "dk",
|
||||||
|
cmd_srcdst_init,
|
||||||
|
cmd_srcdst_parse,
|
||||||
|
cmd_link_window_exec,
|
||||||
|
cmd_srcdst_free,
|
||||||
|
cmd_srcdst_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_srcdst_data *data = self->data;
|
||||||
|
struct session *src, *dst;
|
||||||
|
struct winlink *wl;
|
||||||
|
char *cause;
|
||||||
|
int idx, kflag, dflag;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
kflag = cmd_check_flag(data->chflags, 'k');
|
||||||
|
dflag = cmd_check_flag(data->chflags, 'd');
|
||||||
|
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "can't link window: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-buffers.c,v 1.16 2010-06-22 23:35:20 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,38 @@
|
|||||||
* List paste buffers.
|
* List paste buffers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_BUFFERS_TEMPLATE \
|
int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\""
|
|
||||||
|
|
||||||
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, "",
|
||||||
.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;
|
||||||
const char *template;
|
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
template = LIST_BUFFERS_TEMPLATE;
|
return (-1);
|
||||||
|
|
||||||
pb = NULL;
|
idx = 0;
|
||||||
while ((pb = paste_walk(pb)) != NULL) {
|
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
tmp = paste_print(pb, 50);
|
||||||
format_defaults_paste_buffer(ft, pb);
|
ctx->print(ctx,
|
||||||
|
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||||
line = format_expand(ft, template);
|
xfree(tmp);
|
||||||
cmdq_print(item, "%s", line);
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-clients.c,v 1.20 2009-11-28 14:50:36 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,40 @@
|
|||||||
* 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, "",
|
||||||
.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
|
/* ARGSUSED */
|
||||||
cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
int
|
||||||
|
cmd_list_clients_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct client *c;
|
||||||
struct client *c;
|
u_int i;
|
||||||
struct session *s;
|
const char *s_utf8;
|
||||||
struct format_tree *ft;
|
|
||||||
const char *template;
|
|
||||||
u_int idx;
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
if (args_has(args, 't'))
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
s = 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.7 2009-11-28 14:50:36 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,33 +18,33 @@
|
|||||||
|
|
||||||
#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 *, ...);
|
|
||||||
|
|
||||||
#ifdef HAVE_PROC_PID
|
const struct cmd_entry cmd_list_commands_entry = {
|
||||||
|
"list-commands", "lscm",
|
||||||
|
"",
|
||||||
|
0, "",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_commands_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
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 = 0;
|
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");
|
|
||||||
if (glob(path, 0, NULL, &g) == 0)
|
|
||||||
n = g.gl_pathc;
|
|
||||||
globfree(&g);
|
|
||||||
return (n);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
int
|
|
||||||
getdtablecount(void)
|
|
||||||
{
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
385
cmd-list-keys.c
385
cmd-list-keys.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-keys.c,v 1.25 2010-10-24 01:31:57 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,337 +26,109 @@
|
|||||||
* 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, "",
|
||||||
.args = { "1aNP:T:", 0, 1 },
|
cmd_target_init,
|
||||||
.usage = "[-1aN] [-P prefix-string] [-T key-table] [key]",
|
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, 1 },
|
|
||||||
.usage = "[-F format] [command]",
|
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_list_keys_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static u_int
|
|
||||||
cmd_list_keys_get_width(const char *tablename, key_code only)
|
|
||||||
{
|
{
|
||||||
struct key_table *table;
|
struct cmd_target_data *data = self->data;
|
||||||
struct key_binding *bd;
|
|
||||||
u_int width, keywidth = 0;
|
|
||||||
|
|
||||||
table = key_bindings_get_table(tablename, 0);
|
|
||||||
if (table == NULL)
|
|
||||||
return (0);
|
|
||||||
bd = key_bindings_first(table);
|
|
||||||
while (bd != NULL) {
|
|
||||||
if ((only != KEYC_UNKNOWN && bd->key != only) ||
|
|
||||||
KEYC_IS_MOUSE(bd->key) ||
|
|
||||||
bd->note == NULL) {
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
width = utf8_cstrwidth(key_string_lookup_key(bd->key));
|
|
||||||
if (width > keywidth)
|
|
||||||
keywidth = width;
|
|
||||||
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
}
|
|
||||||
return (keywidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
cmd_list_keys_print_notes(struct cmdq_item *item, struct args *args,
|
|
||||||
const char *tablename, u_int keywidth, key_code only, const char *prefix)
|
|
||||||
{
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
struct key_table *table;
|
|
||||||
struct key_binding *bd;
|
struct key_binding *bd;
|
||||||
const char *key;
|
const char *key;
|
||||||
char *tmp, *note;
|
char tmp[BUFSIZ];
|
||||||
int found = 0;
|
size_t used;
|
||||||
|
int width, keywidth;
|
||||||
|
|
||||||
table = key_bindings_get_table(tablename, 0);
|
if (data->target != NULL)
|
||||||
if (table == NULL)
|
return (cmd_list_keys_table(self, ctx));
|
||||||
return (0);
|
|
||||||
bd = key_bindings_first(table);
|
width = 0;
|
||||||
while (bd != NULL) {
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
if ((only != KEYC_UNKNOWN && bd->key != only) ||
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
KEYC_IS_MOUSE(bd->key) ||
|
if (key == NULL)
|
||||||
(bd->note == NULL && !args_has(args, 'a'))) {
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
found = 1;
|
|
||||||
key = key_string_lookup_key(bd->key);
|
|
||||||
|
|
||||||
if (bd->note == NULL)
|
keywidth = strlen(key) + 1;
|
||||||
note = cmd_list_print(bd->cmdlist, 1);
|
if (!(bd->key & KEYC_PREFIX))
|
||||||
else
|
keywidth += 2;
|
||||||
note = xstrdup(bd->note);
|
if (keywidth > width)
|
||||||
tmp = utf8_padcstr(key, keywidth + 1);
|
width = keywidth;
|
||||||
if (args_has(args, '1') && c != NULL)
|
|
||||||
status_message_set(c, "%s%s%s", prefix, tmp, note);
|
|
||||||
else
|
|
||||||
cmdq_print(item, "%s%s%s", prefix, tmp, note);
|
|
||||||
free(tmp);
|
|
||||||
free(note);
|
|
||||||
|
|
||||||
if (args_has(args, '1'))
|
|
||||||
break;
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
}
|
|
||||||
return (found);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
cmd_list_keys_get_prefix(struct args *args, key_code *prefix)
|
|
||||||
{
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
*prefix = options_get_number(global_s_options, "prefix");
|
|
||||||
if (!args_has(args, 'P')) {
|
|
||||||
if (*prefix != KEYC_NONE)
|
|
||||||
xasprintf(&s, "%s ", key_string_lookup_key(*prefix));
|
|
||||||
else
|
|
||||||
s = xstrdup("");
|
|
||||||
} else
|
|
||||||
s = xstrdup(args_get(args, 'P'));
|
|
||||||
return (s);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
struct key_table *table;
|
|
||||||
struct key_binding *bd;
|
|
||||||
const char *tablename, *r;
|
|
||||||
char *key, *cp, *tmp, *start, *empty;
|
|
||||||
key_code prefix, only = KEYC_UNKNOWN;
|
|
||||||
int repeat, width, tablewidth, keywidth, found = 0;
|
|
||||||
size_t tmpsize, tmpused, cplen;
|
|
||||||
|
|
||||||
if (self->entry == &cmd_list_commands_entry)
|
|
||||||
return (cmd_list_keys_commands(self, item));
|
|
||||||
|
|
||||||
if (args->argc != 0) {
|
|
||||||
only = key_string_lookup_string(args->argv[0]);
|
|
||||||
if (only == KEYC_UNKNOWN) {
|
|
||||||
cmdq_error(item, "invalid key: %s", args->argv[0]);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tablename = args_get(args, 'T');
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) {
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
if (key == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'N')) {
|
|
||||||
if (tablename == NULL) {
|
|
||||||
start = cmd_list_keys_get_prefix(args, &prefix);
|
|
||||||
keywidth = cmd_list_keys_get_width("root", only);
|
|
||||||
if (prefix != KEYC_NONE) {
|
|
||||||
width = cmd_list_keys_get_width("prefix", only);
|
|
||||||
if (width == 0)
|
|
||||||
prefix = KEYC_NONE;
|
|
||||||
else if (width > keywidth)
|
|
||||||
keywidth = width;
|
|
||||||
}
|
|
||||||
empty = utf8_padcstr("", utf8_cstrwidth(start));
|
|
||||||
|
|
||||||
found = cmd_list_keys_print_notes(item, args, "root",
|
|
||||||
keywidth, only, empty);
|
|
||||||
if (prefix != KEYC_NONE) {
|
|
||||||
if (cmd_list_keys_print_notes(item, args,
|
|
||||||
"prefix", keywidth, only, start))
|
|
||||||
found = 1;
|
|
||||||
}
|
|
||||||
free(empty);
|
|
||||||
} else {
|
|
||||||
if (args_has(args, 'P'))
|
|
||||||
start = xstrdup(args_get(args, 'P'));
|
|
||||||
else
|
|
||||||
start = xstrdup("");
|
|
||||||
keywidth = cmd_list_keys_get_width(tablename, only);
|
|
||||||
found = cmd_list_keys_print_notes(item, args, tablename,
|
|
||||||
keywidth, only, start);
|
|
||||||
|
|
||||||
}
|
|
||||||
free(start);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
repeat = 0;
|
|
||||||
tablewidth = keywidth = 0;
|
|
||||||
table = key_bindings_first_table ();
|
|
||||||
while (table != NULL) {
|
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
|
||||||
table = key_bindings_next_table(table);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
used = xsnprintf(tmp, sizeof tmp, "%*s: ", width, key);
|
||||||
bd = key_bindings_first(table);
|
if (used >= sizeof tmp)
|
||||||
while (bd != NULL) {
|
continue;
|
||||||
if (only != KEYC_UNKNOWN && bd->key != only) {
|
|
||||||
bd = key_bindings_next(table, bd);
|
if (!(bd->key & KEYC_PREFIX)) {
|
||||||
|
used = strlcat(tmp, "(no prefix) ", sizeof tmp);
|
||||||
|
if (used >= sizeof tmp)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
key = args_escape(key_string_lookup_key(bd->key));
|
|
||||||
|
|
||||||
if (bd->flags & KEY_BINDING_REPEAT)
|
|
||||||
repeat = 1;
|
|
||||||
|
|
||||||
width = utf8_cstrwidth(table->name);
|
|
||||||
if (width > tablewidth)
|
|
||||||
tablewidth = width;
|
|
||||||
width = utf8_cstrwidth(key);
|
|
||||||
if (width > keywidth)
|
|
||||||
keywidth = width;
|
|
||||||
|
|
||||||
free(key);
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
}
|
}
|
||||||
table = key_bindings_next_table(table);
|
if (bd->can_repeat) {
|
||||||
}
|
used = strlcat(tmp, "(repeat) ", sizeof tmp);
|
||||||
|
if (used >= sizeof tmp)
|
||||||
tmpsize = 256;
|
|
||||||
tmp = xmalloc(tmpsize);
|
|
||||||
|
|
||||||
table = key_bindings_first_table ();
|
|
||||||
while (table != NULL) {
|
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
|
||||||
table = key_bindings_next_table(table);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
bd = key_bindings_first(table);
|
|
||||||
while (bd != NULL) {
|
|
||||||
if (only != KEYC_UNKNOWN && bd->key != only) {
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
found = 1;
|
|
||||||
key = args_escape(key_string_lookup_key(bd->key));
|
|
||||||
|
|
||||||
if (!repeat)
|
|
||||||
r = "";
|
|
||||||
else if (bd->flags & KEY_BINDING_REPEAT)
|
|
||||||
r = "-r ";
|
|
||||||
else
|
|
||||||
r = " ";
|
|
||||||
tmpused = xsnprintf(tmp, tmpsize, "%s-T ", r);
|
|
||||||
|
|
||||||
cp = utf8_padcstr(table->name, tablewidth);
|
|
||||||
cplen = strlen(cp) + 1;
|
|
||||||
while (tmpused + cplen + 1 >= tmpsize) {
|
|
||||||
tmpsize *= 2;
|
|
||||||
tmp = xrealloc(tmp, tmpsize);
|
|
||||||
}
|
|
||||||
tmpused = strlcat(tmp, cp, tmpsize);
|
|
||||||
tmpused = strlcat(tmp, " ", tmpsize);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
cp = utf8_padcstr(key, keywidth);
|
|
||||||
cplen = strlen(cp) + 1;
|
|
||||||
while (tmpused + cplen + 1 >= tmpsize) {
|
|
||||||
tmpsize *= 2;
|
|
||||||
tmp = xrealloc(tmp, tmpsize);
|
|
||||||
}
|
|
||||||
tmpused = strlcat(tmp, cp, tmpsize);
|
|
||||||
tmpused = strlcat(tmp, " ", tmpsize);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
cp = cmd_list_print(bd->cmdlist, 1);
|
|
||||||
cplen = strlen(cp);
|
|
||||||
while (tmpused + cplen + 1 >= tmpsize) {
|
|
||||||
tmpsize *= 2;
|
|
||||||
tmp = xrealloc(tmp, tmpsize);
|
|
||||||
}
|
|
||||||
strlcat(tmp, cp, tmpsize);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
cmdq_print(item, "bind-key %s", tmp);
|
|
||||||
|
|
||||||
free(key);
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
}
|
}
|
||||||
table = key_bindings_next_table(table);
|
cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used);
|
||||||
|
ctx->print(ctx, "%s", tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(tmp);
|
return (0);
|
||||||
|
|
||||||
out:
|
|
||||||
if (only != KEYC_UNKNOWN && !found) {
|
|
||||||
cmdq_error(item, "unknown key: %s", args->argv[0]);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, *command = NULL;
|
int width, keywidth;
|
||||||
char *line;
|
|
||||||
|
|
||||||
if (args->argc != 0)
|
if ((mtab = mode_key_findtable(data->target)) == NULL) {
|
||||||
command = args->argv[0];
|
ctx->error(ctx, "unknown key table: %s", data->target);
|
||||||
|
return (-1);
|
||||||
if ((template = args_get(args, 'F')) == NULL) {
|
|
||||||
template = "#{command_list_name}"
|
|
||||||
"#{?command_list_alias, (#{command_list_alias}),} "
|
|
||||||
"#{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)
|
||||||
if (command != NULL &&
|
width = keywidth;
|
||||||
(strcmp(entry->name, command) != 0 &&
|
|
||||||
(entry->alias == NULL ||
|
|
||||||
strcmp(entry->alias, command) != 0)))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
133
cmd-list-panes.c
133
cmd-list-panes.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-panes.c,v 1.6 2010-12-06 21:56:32 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
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -26,112 +26,51 @@
|
|||||||
* List panes on given window.
|
* List panes on given window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmdq_item *);
|
int cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
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 = {
|
const struct cmd_entry cmd_list_panes_entry = {
|
||||||
.name = "list-panes",
|
"list-panes", "lsp",
|
||||||
.alias = "lsp",
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, "",
|
||||||
.args = { "asF:t:", 0, 0 },
|
cmd_target_init,
|
||||||
.usage = "[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
|
cmd_target_parse,
|
||||||
|
cmd_list_panes_exec,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_list_panes_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s = item->target.s;
|
struct winlink *wl;
|
||||||
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;
|
struct window_pane *wp;
|
||||||
u_int n;
|
struct grid *gd;
|
||||||
struct format_tree *ft;
|
struct grid_line *gl;
|
||||||
const char *template;
|
u_int i, n;
|
||||||
char *line;
|
unsigned long long size;
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
if (template == NULL) {
|
return (-1);
|
||||||
switch (type) {
|
|
||||||
case 0:
|
|
||||||
template = "#{pane_index}: "
|
|
||||||
"[#{pane_width}x#{pane_height}] [history "
|
|
||||||
"#{history_size}/#{history_limit}, "
|
|
||||||
"#{history_bytes} bytes] #{pane_id}"
|
|
||||||
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
template = "#{window_index}.#{pane_index}: "
|
|
||||||
"[#{pane_width}x#{pane_height}] [history "
|
|
||||||
"#{history_size}/#{history_limit}, "
|
|
||||||
"#{history_bytes} bytes] #{pane_id}"
|
|
||||||
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
template = "#{session_name}:#{window_index}."
|
|
||||||
"#{pane_index}: [#{pane_width}x#{pane_height}] "
|
|
||||||
"[history #{history_size}/#{history_limit}, "
|
|
||||||
"#{history_bytes} bytes] #{pane_id}"
|
|
||||||
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
gd = wp->base.grid;
|
||||||
format_add(ft, "line", "%u", n);
|
|
||||||
format_defaults(ft, NULL, s, wl, wp);
|
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
size = 0;
|
||||||
cmdq_print(item, "%s", line);
|
for (i = 0; i < gd->hsize; i++) {
|
||||||
free(line);
|
gl = &gd->linedata[i];
|
||||||
|
size += gl->cellsize * sizeof *gl->celldata;
|
||||||
|
size += gl->utf8size * sizeof *gl->utf8data;
|
||||||
|
}
|
||||||
|
size += gd->hsize * sizeof *gd->linedata;
|
||||||
|
|
||||||
format_free(ft);
|
ctx->print(ctx, "%u: [%ux%u] [history %u/%u, %llu bytes]%s%s",
|
||||||
|
n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size,
|
||||||
|
wp == wp->window->active ? " (active)" : "",
|
||||||
|
wp->fd == -1 ? " (dead)" : "");
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-sessions.c,v 1.26 2010-12-22 15:36:44 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,53 +27,45 @@
|
|||||||
* List all sessions.
|
* List all sessions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_SESSIONS_TEMPLATE \
|
int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{session_name}: #{session_windows} windows " \
|
|
||||||
"(created #{t:session_created})" \
|
|
||||||
"#{?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, "",
|
||||||
|
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
|
/* ARGSUSED */
|
||||||
cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item)
|
int
|
||||||
|
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
|
||||||
struct session *s;
|
struct session *s;
|
||||||
u_int n;
|
struct session_group *sg;
|
||||||
struct format_tree *ft;
|
char *tim, tmp[64];
|
||||||
const char *template;
|
u_int idx;
|
||||||
char *line;
|
time_t t;
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = LIST_SESSIONS_TEMPLATE;
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
sg = session_group_find(s);
|
||||||
format_add(ft, "line", "%u", n);
|
if (sg == NULL)
|
||||||
format_defaults(ft, NULL, s, NULL, NULL);
|
*tmp = '\0';
|
||||||
|
else {
|
||||||
|
idx = session_group_index(sg);
|
||||||
|
xsnprintf(tmp, sizeof tmp, " (group %u)", idx);
|
||||||
|
}
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
t = s->creation_time.tv_sec;
|
||||||
cmdq_print(item, "%s", line);
|
tim = ctime(&t);
|
||||||
free(line);
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
format_free(ft);
|
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s",
|
||||||
n++;
|
s->name, winlink_count(&s->windows), tim, s->sx, s->sy,
|
||||||
|
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-list-windows.c,v 1.44 2010-12-06 21:56:32 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,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,93 +26,37 @@
|
|||||||
* List windows on given session.
|
* List windows on given session.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_WINDOWS_TEMPLATE \
|
int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{window_index}: #{window_name}#{window_flags} " \
|
|
||||||
"(#{window_panes} panes) " \
|
|
||||||
"[#{window_width}x#{window_height}] " \
|
|
||||||
"[layout #{window_layout}] #{window_id}" \
|
|
||||||
"#{?window_active, (active),}";
|
|
||||||
#define LIST_WINDOWS_WITH_SESSION_TEMPLATE \
|
|
||||||
"#{session_name}:" \
|
|
||||||
"#{window_index}: #{window_name}#{window_flags} " \
|
|
||||||
"(#{window_panes} panes) " \
|
|
||||||
"[#{window_width}x#{window_height}] "
|
|
||||||
|
|
||||||
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, "",
|
||||||
.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;
|
char *layout;
|
||||||
struct format_tree *ft;
|
|
||||||
const char *template;
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
if (template == NULL) {
|
return (-1);
|
||||||
switch (type) {
|
|
||||||
case 0:
|
|
||||||
template = LIST_WINDOWS_TEMPLATE;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
template = LIST_WINDOWS_WITH_SESSION_TEMPLATE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
layout = layout_dump(wl->window);
|
||||||
format_add(ft, "line", "%u", n);
|
ctx->print(ctx, "%d: %s [%ux%u] [layout %s]%s",
|
||||||
format_defaults(ft, NULL, s, wl, NULL);
|
wl->idx, wl->window->name, wl->window->sx, wl->window->sy,
|
||||||
|
layout, wl == s->curw ? " (active)" : "");
|
||||||
line = format_expand(ft, template);
|
xfree(layout);
|
||||||
cmdq_print(item, "%s", line);
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
n++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
150
cmd-list.c
Normal file
150
cmd-list.c
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
/* $Id: cmd-list.c,v 1.10 2010-12-06 21:48:56 nicm 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 "tmux.h"
|
||||||
|
|
||||||
|
struct cmd_list *
|
||||||
|
cmd_list_parse(int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd *cmd;
|
||||||
|
int i, lastsplit;
|
||||||
|
size_t arglen, new_argc;
|
||||||
|
char **copy_argv, **new_argv;
|
||||||
|
|
||||||
|
copy_argv = cmd_copy_argv(argc, argv);
|
||||||
|
|
||||||
|
cmdlist = xmalloc(sizeof *cmdlist);
|
||||||
|
cmdlist->references = 1;
|
||||||
|
TAILQ_INIT(&cmdlist->list);
|
||||||
|
|
||||||
|
lastsplit = 0;
|
||||||
|
for (i = 0; i < argc; i++) {
|
||||||
|
arglen = strlen(copy_argv[i]);
|
||||||
|
if (arglen == 0 || copy_argv[i][arglen - 1] != ';')
|
||||||
|
continue;
|
||||||
|
copy_argv[i][arglen - 1] = '\0';
|
||||||
|
|
||||||
|
if (arglen > 1 && copy_argv[i][arglen - 2] == '\\') {
|
||||||
|
copy_argv[i][arglen - 2] = ';';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_argc = i - lastsplit;
|
||||||
|
new_argv = copy_argv + lastsplit;
|
||||||
|
if (arglen != 1)
|
||||||
|
new_argc++;
|
||||||
|
|
||||||
|
cmd = cmd_parse(new_argc, new_argv, cause);
|
||||||
|
if (cmd == NULL)
|
||||||
|
goto bad;
|
||||||
|
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||||
|
|
||||||
|
lastsplit = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastsplit != argc) {
|
||||||
|
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit, cause);
|
||||||
|
if (cmd == NULL)
|
||||||
|
goto bad;
|
||||||
|
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_free_argv(argc, copy_argv);
|
||||||
|
return (cmdlist);
|
||||||
|
|
||||||
|
bad:
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
cmd_free_argv(argc, copy_argv);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
int n, retval;
|
||||||
|
|
||||||
|
retval = 0;
|
||||||
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
|
if ((n = cmd_exec(cmd, ctx)) == -1)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A 1 return value means the command client is being attached
|
||||||
|
* (sent MSG_READY).
|
||||||
|
*/
|
||||||
|
if (n == 1) {
|
||||||
|
retval = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The command client has been attached, so mangle the
|
||||||
|
* context to treat any following commands as if they
|
||||||
|
* were called from inside.
|
||||||
|
*/
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->curclient = ctx->cmdclient;
|
||||||
|
ctx->cmdclient = NULL;
|
||||||
|
|
||||||
|
ctx->error = key_bindings_error;
|
||||||
|
ctx->print = key_bindings_print;
|
||||||
|
ctx->info = key_bindings_info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_list_free(struct cmd_list *cmdlist)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
|
||||||
|
if (--cmdlist->references != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (!TAILQ_EMPTY(&cmdlist->list)) {
|
||||||
|
cmd = TAILQ_FIRST(&cmdlist->list);
|
||||||
|
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
||||||
|
cmd_free(cmd);
|
||||||
|
}
|
||||||
|
xfree(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
size_t off;
|
||||||
|
|
||||||
|
off = 0;
|
||||||
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
|
if (off >= len)
|
||||||
|
break;
|
||||||
|
off += cmd_print(cmd, buf + off, len - off);
|
||||||
|
if (off >= len)
|
||||||
|
break;
|
||||||
|
if (TAILQ_NEXT(cmd, qentry) != NULL)
|
||||||
|
off += xsnprintf(buf + off, len - off, " ; ");
|
||||||
|
}
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-load-buffer.c,v 1.18 2010-12-22 15:28:50 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -28,80 +27,159 @@
|
|||||||
#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 *);
|
||||||
|
void cmd_load_buffer_callback(struct client *, 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, "",
|
||||||
.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 {
|
struct cmd_load_buffer_cdata {
|
||||||
struct cmdq_item *item;
|
struct session *session;
|
||||||
char *name;
|
int buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
int
|
||||||
cmd_load_buffer_done(__unused struct client *c, const char *path, int error,
|
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
int closed, struct evbuffer *buffer, void *data)
|
|
||||||
{
|
{
|
||||||
struct cmd_load_buffer_data *cdata = data;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct cmdq_item *item = cdata->item;
|
struct cmd_load_buffer_cdata *cdata;
|
||||||
void *bdata = EVBUFFER_DATA(buffer);
|
struct session *s;
|
||||||
size_t bsize = EVBUFFER_LENGTH(buffer);
|
struct client *c = ctx->cmdclient;
|
||||||
void *copy;
|
FILE *f;
|
||||||
char *cause;
|
char *pdata, *new_pdata;
|
||||||
|
size_t psize;
|
||||||
|
u_int limit;
|
||||||
|
int ch;
|
||||||
|
|
||||||
if (!closed)
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
return;
|
return (-1);
|
||||||
|
|
||||||
if (error != 0)
|
if (strcmp(data->arg, "-") == 0) {
|
||||||
cmdq_error(item, "%s: %s", path, strerror(error));
|
if (c == NULL) {
|
||||||
else if (bsize != 0) {
|
ctx->error(ctx, "%s: can't read from stdin", data->arg);
|
||||||
copy = xmalloc(bsize);
|
return (-1);
|
||||||
memcpy(copy, bdata, bsize);
|
|
||||||
if (paste_set(copy, bsize, cdata->name, &cause) != 0) {
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
free(copy);
|
|
||||||
}
|
}
|
||||||
|
if (c->flags & CLIENT_TERMINAL) {
|
||||||
|
ctx->error(ctx, "%s: stdin is a tty", data->arg);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (c->stdin_fd == -1) {
|
||||||
|
ctx->error(ctx, "%s: can't read from stdin", data->arg);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
cdata->buffer = data->buffer;
|
||||||
|
c->stdin_data = cdata;
|
||||||
|
c->stdin_callback = cmd_load_buffer_callback;
|
||||||
|
|
||||||
|
c->references++;
|
||||||
|
bufferevent_enable(c->stdin_event, EV_READ);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
cmdq_continue(item);
|
|
||||||
|
|
||||||
free(cdata->name);
|
if ((f = fopen(data->arg, "rb")) == NULL) {
|
||||||
free(cdata);
|
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pdata = NULL;
|
||||||
|
psize = 0;
|
||||||
|
while ((ch = getc(f)) != EOF) {
|
||||||
|
/* Do not let the server die due to memory exhaustion. */
|
||||||
|
if ((new_pdata = realloc(pdata, psize + 2)) == NULL) {
|
||||||
|
ctx->error(ctx, "realloc error: %s", strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
pdata = new_pdata;
|
||||||
|
pdata[psize++] = ch;
|
||||||
|
}
|
||||||
|
if (ferror(f)) {
|
||||||
|
ctx->error(ctx, "%s: read error", data->arg);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (pdata != NULL)
|
||||||
|
pdata[psize] = '\0';
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
f = NULL;
|
||||||
|
|
||||||
|
limit = options_get_number(&s->options, "buffer-limit");
|
||||||
|
if (data->buffer == -1) {
|
||||||
|
paste_add(&s->buffers, pdata, psize, limit);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (paste_replace(&s->buffers, data->buffer, pdata, psize) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (pdata != NULL)
|
||||||
|
xfree(pdata);
|
||||||
|
if (f != NULL)
|
||||||
|
fclose(f);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
void
|
||||||
cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_load_buffer_callback(struct client *c, void *data)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_load_buffer_cdata *cdata = data;
|
||||||
struct cmd_load_buffer_data *cdata;
|
struct session *s = cdata->session;
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
char *pdata;
|
||||||
struct session *s = item->target.s;
|
size_t psize;
|
||||||
struct winlink *wl = item->target.wl;
|
u_int limit;
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
const char *bufname = args_get(args, 'b');
|
|
||||||
char *path;
|
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
/*
|
||||||
cdata->item = item;
|
* Event callback has already checked client is not dead and reduced
|
||||||
if (bufname != NULL)
|
* its reference count. But tell it to exit.
|
||||||
cdata->name = xstrdup(bufname);
|
*/
|
||||||
else
|
c->flags |= CLIENT_EXIT;
|
||||||
cdata->name = NULL;
|
|
||||||
|
|
||||||
path = format_single(item, args->argv[0], c, s, wl, wp);
|
/* Does the target session still exist? */
|
||||||
file_read(item->client, path, cmd_load_buffer_done, cdata);
|
if (!session_alive(s))
|
||||||
free(path);
|
goto out;
|
||||||
|
|
||||||
return (CMD_RETURN_WAIT);
|
psize = EVBUFFER_LENGTH(c->stdin_event->input);
|
||||||
|
if (psize == 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
pdata = malloc(psize + 1);
|
||||||
|
if (pdata == NULL)
|
||||||
|
goto out;
|
||||||
|
bufferevent_read(c->stdin_event, pdata, psize);
|
||||||
|
pdata[psize] = '\0';
|
||||||
|
|
||||||
|
limit = options_get_number(&s->options, "buffer-limit");
|
||||||
|
if (cdata->buffer == -1) {
|
||||||
|
paste_add(&s->buffers, pdata, psize, limit);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (paste_replace(&s->buffers, cdata->buffer, pdata, psize) != 0) {
|
||||||
|
/* No context so can't use server_client_msg_error. */
|
||||||
|
evbuffer_add_printf(
|
||||||
|
c->stderr_event->output, "no buffer %d\n", cdata->buffer);
|
||||||
|
bufferevent_enable(c->stderr_event, EV_WRITE);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
cdata->session->references--;
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
53
cmd-lock-client.c
Normal file
53
cmd-lock-client.c
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* $Id: cmd-lock-client.c,v 1.2 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lock a single client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_lock_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_lock_client_entry = {
|
||||||
|
"lock-client", "lockc",
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_lock_client_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_lock_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct client *c;
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
server_lock_client(c);
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-lock-server.c,v 1.9 2009-11-28 14:50:36 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,35 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lock commands.
|
* Lock server.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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, "",
|
||||||
.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 = {
|
/* ARGSUSED */
|
||||||
.name = "lock-session",
|
int
|
||||||
.alias = "locks",
|
cmd_lock_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
|
|
||||||
.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)
|
|
||||||
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();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
53
cmd-lock-session.c
Normal file
53
cmd-lock-session.c
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* $Id: cmd-lock-session.c,v 1.2 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lock all clients attached to a session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_lock_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_lock_session_entry = {
|
||||||
|
"lock-session", "locks",
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_lock_session_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_lock_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
server_lock_session(s);
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-move-window.c,v 1.13 2009-11-14 17:56: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
|
||||||
@@ -26,93 +26,42 @@
|
|||||||
* 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, "dk",
|
||||||
.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;
|
||||||
struct session *dst;
|
char *cause;
|
||||||
struct winlink *wl;
|
int idx, kflag, dflag;
|
||||||
char *cause;
|
|
||||||
int idx, kflag, dflag, sflag;
|
|
||||||
|
|
||||||
if (args_has(args, 'r')) {
|
if ((wl = 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);
|
kflag = cmd_check_flag(data->chflags, 'k');
|
||||||
recalculate_sizes();
|
dflag = cmd_check_flag(data->chflags, 'd');
|
||||||
server_status_session(item->target.s);
|
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "can't move window: %s", cause);
|
||||||
return (CMD_RETURN_NORMAL);
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
if (cmd_find_target(&item->target, item, tflag, CMD_FIND_WINDOW,
|
server_unlink_window(src, wl);
|
||||||
CMD_FIND_WINDOW_INDEX) != 0)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
src = item->source.s;
|
|
||||||
dst = item->target.s;
|
|
||||||
wl = item->source.wl;
|
|
||||||
idx = item->target.idx;
|
|
||||||
|
|
||||||
kflag = args_has(self->args, 'k');
|
|
||||||
dflag = args_has(self->args, 'd');
|
|
||||||
sflag = args_has(self->args, 's');
|
|
||||||
|
|
||||||
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,
|
|
||||||
&cause) != 0) {
|
|
||||||
cmdq_error(item, "can't link window: %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (self->entry == &cmd_move_window_entry)
|
|
||||||
server_unlink_window(src, wl);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Renumber the winlinks in the src session only, the destination
|
|
||||||
* session already has the correct winlink id to us, either
|
|
||||||
* automatically or specified by -s.
|
|
||||||
*/
|
|
||||||
if (!sflag && options_get_number(src->options, "renumber-windows"))
|
|
||||||
session_renumber_windows(src);
|
|
||||||
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-new-session.c,v 1.80 2010-12-22 15:31:00 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,9 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <pwd.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -31,294 +29,269 @@
|
|||||||
* 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 *target;
|
||||||
|
char *newname;
|
||||||
|
char *winname;
|
||||||
|
char *cmd;
|
||||||
|
int flag_detached;
|
||||||
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_new_session_entry = {
|
const struct cmd_entry cmd_new_session_entry = {
|
||||||
.name = "new-session",
|
"new-session", "new",
|
||||||
.alias = "new",
|
"[-d] [-n window-name] [-s session-name] [-t target-session] [command]",
|
||||||
|
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON, "",
|
||||||
.args = { "Ac:dDEF:n:Ps:t:x:Xy:", 0, -1 },
|
cmd_new_session_init,
|
||||||
.usage = "[-AdDEPX] [-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 = {
|
/* ARGSUSED */
|
||||||
.name = "has-session",
|
void
|
||||||
.alias = "has",
|
cmd_new_session_init(struct cmd *self, unused int arg)
|
||||||
|
|
||||||
.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 environ *env;
|
|
||||||
struct options *oo;
|
|
||||||
struct termios tio, *tiop;
|
|
||||||
struct session_group *sg;
|
|
||||||
const char *errstr, *template, *group, *prefix, *tmp;
|
|
||||||
char *cause, *cwd = NULL, *cp, *newname = NULL;
|
|
||||||
int detached, already_attached, is_control = 0;
|
|
||||||
u_int sx, sy, dsx, dsy;
|
|
||||||
struct spawn_context sc;
|
|
||||||
enum cmd_retval retval;
|
|
||||||
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->target = NULL;
|
||||||
* so always return success here.
|
data->newname = NULL;
|
||||||
*/
|
data->winname = NULL;
|
||||||
return (CMD_RETURN_NORMAL);
|
data->cmd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
tmp = args_get(args, 's');
|
self->entry->init(self, KEYC_NONE);
|
||||||
if (tmp != NULL) {
|
data = self->data;
|
||||||
newname = format_single(item, tmp, c, NULL, NULL, NULL);
|
|
||||||
if (!session_check_name(newname)) {
|
while ((opt = getopt(argc, argv, "ds:t:n:")) != -1) {
|
||||||
cmdq_error(item, "bad session name: %s", newname);
|
switch (opt) {
|
||||||
goto fail;
|
case 'd':
|
||||||
|
data->flag_detached = 1;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
if (data->newname == NULL)
|
||||||
|
data->newname = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
if (data->winname == NULL)
|
||||||
|
data->winname = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (args_has(args, 'A')) {
|
argc -= optind;
|
||||||
if (newname != NULL)
|
argv += optind;
|
||||||
as = session_find(newname);
|
if (argc != 0 && argc != 1)
|
||||||
else
|
goto usage;
|
||||||
as = item->target.s;
|
|
||||||
if (as != NULL) {
|
if (data->target != NULL && (argc == 1 || data->winname != NULL))
|
||||||
retval = cmd_attach_session(item, as->name,
|
goto usage;
|
||||||
args_has(args, 'D'), args_has(args, 'X'), 0, NULL,
|
|
||||||
args_has(args, 'E'));
|
if (argc == 1)
|
||||||
free(newname);
|
data->cmd = xstrdup(argv[0]);
|
||||||
return (retval);
|
|
||||||
}
|
return (0);
|
||||||
}
|
|
||||||
if (newname != NULL && session_find(newname) != NULL) {
|
usage:
|
||||||
cmdq_error(item, "duplicate session: %s", newname);
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
goto fail;
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_new_session_data *data = self->data;
|
||||||
|
struct session *s, *old_s, *groupwith;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct environ env;
|
||||||
|
struct termios tio, *tiop;
|
||||||
|
struct passwd *pw;
|
||||||
|
const char *update, *cwd;
|
||||||
|
char *overrides, *cmd, *cause;
|
||||||
|
int detached, idx;
|
||||||
|
u_int sx, sy, i;
|
||||||
|
|
||||||
|
if (data->newname != NULL && session_find(data->newname) != NULL) {
|
||||||
|
ctx->error(ctx, "duplicate session: %s", data->newname);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is this going to be part of a session group? */
|
groupwith = NULL;
|
||||||
group = args_get(args, 't');
|
if (data->target != NULL &&
|
||||||
if (group != NULL) {
|
(groupwith = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
groupwith = item->target.s;
|
return (-1);
|
||||||
if (groupwith == NULL) {
|
|
||||||
if (!session_check_name(group)) {
|
|
||||||
cmdq_error(item, "bad group name: %s", group);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
sg = session_group_find(group);
|
|
||||||
} else
|
|
||||||
sg = session_group_contains(groupwith);
|
|
||||||
if (sg != NULL)
|
|
||||||
prefix = sg->name;
|
|
||||||
else if (groupwith != NULL)
|
|
||||||
prefix = groupwith->name;
|
|
||||||
else
|
|
||||||
prefix = group;
|
|
||||||
} else {
|
|
||||||
groupwith = NULL;
|
|
||||||
sg = NULL;
|
|
||||||
prefix = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set -d if no client. */
|
|
||||||
detached = args_has(args, 'd');
|
|
||||||
if (c == NULL)
|
|
||||||
detached = 1;
|
|
||||||
else if (c->flags & CLIENT_CONTROL)
|
|
||||||
is_control = 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 ((tmp = args_get(args, 'c')) != NULL)
|
|
||||||
cwd = format_single(item, tmp, c, NULL, NULL, NULL);
|
|
||||||
else
|
|
||||||
cwd = xstrdup(server_client_get_cwd(c, NULL));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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)
|
||||||
goto fail;
|
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 fail;
|
}
|
||||||
|
|
||||||
|
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 default session size. */
|
/* Get the new session working directory. */
|
||||||
if (args_has(args, 'x')) {
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
tmp = args_get(args, 'x');
|
cwd = ctx->cmdclient->cwd;
|
||||||
if (strcmp(tmp, "-") == 0) {
|
else {
|
||||||
if (c != NULL)
|
pw = getpwuid(getuid());
|
||||||
dsx = c->tty.sx;
|
if (pw->pw_dir != NULL && *pw->pw_dir != '\0')
|
||||||
else
|
cwd = pw->pw_dir;
|
||||||
dsx = 80;
|
else
|
||||||
} else {
|
cwd = "/";
|
||||||
dsx = strtonum(tmp, 1, USHRT_MAX, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "width %s", errstr);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (args_has(args, 'y')) {
|
|
||||||
tmp = args_get(args, 'y');
|
|
||||||
if (strcmp(tmp, "-") == 0) {
|
|
||||||
if (c != NULL)
|
|
||||||
dsy = c->tty.sy;
|
|
||||||
else
|
|
||||||
dsy = 24;
|
|
||||||
} else {
|
|
||||||
dsy = strtonum(tmp, 1, USHRT_MAX, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "height %s", errstr);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find new session size. */
|
/* Find new session size. */
|
||||||
if (!detached && !is_control) {
|
if (detached) {
|
||||||
sx = c->tty.sx;
|
sx = 80;
|
||||||
sy = c->tty.sy;
|
sy = 24;
|
||||||
if (sy > 0 && options_get_number(global_s_options, "status"))
|
} else if (ctx->cmdclient != NULL) {
|
||||||
sy--;
|
sx = ctx->cmdclient->tty.sx;
|
||||||
|
sy = ctx->cmdclient->tty.sy;
|
||||||
} else {
|
} else {
|
||||||
tmp = options_get_string(global_s_options, "default-size");
|
sx = ctx->curclient->tty.sx;
|
||||||
if (sscanf(tmp, "%ux%u", &sx, &sy) != 2) {
|
sy = ctx->curclient->tty.sy;
|
||||||
sx = 80;
|
|
||||||
sy = 24;
|
|
||||||
}
|
|
||||||
if (args_has(args, 'x'))
|
|
||||||
sx = dsx;
|
|
||||||
if (args_has(args, 'y'))
|
|
||||||
sy = dsy;
|
|
||||||
}
|
}
|
||||||
|
if (sy > 0 && options_get_number(&global_s_options, "status"))
|
||||||
|
sy--;
|
||||||
if (sx == 0)
|
if (sx == 0)
|
||||||
sx = 1;
|
sx = 1;
|
||||||
if (sy == 0)
|
if (sy == 0)
|
||||||
sy = 1;
|
sy = 1;
|
||||||
|
|
||||||
|
/* Figure out the command for the new window. */
|
||||||
|
if (data->target != NULL)
|
||||||
|
cmd = NULL;
|
||||||
|
else if (data->cmd != NULL)
|
||||||
|
cmd = data->cmd;
|
||||||
|
else
|
||||||
|
cmd = options_get_string(&global_s_options, "default-command");
|
||||||
|
|
||||||
|
/* Construct the environment. */
|
||||||
|
environ_init(&env);
|
||||||
|
update = options_get_string(&global_s_options, "update-environment");
|
||||||
|
if (ctx->cmdclient != NULL)
|
||||||
|
environ_update(update, &ctx->cmdclient->environ, &env);
|
||||||
|
|
||||||
/* Create the new session. */
|
/* Create the new session. */
|
||||||
oo = options_create(global_s_options);
|
idx = -1 - options_get_number(&global_s_options, "base-index");
|
||||||
if (args_has(args, 'x') || args_has(args, 'y')) {
|
s = session_create(
|
||||||
if (!args_has(args, 'x'))
|
data->newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
||||||
dsx = sx;
|
if (s == NULL) {
|
||||||
if (!args_has(args, 'y'))
|
ctx->error(ctx, "create session failed: %s", cause);
|
||||||
dsy = sy;
|
xfree(cause);
|
||||||
options_set_string(oo, "default-size", 0, "%ux%u", dsx, dsy);
|
return (-1);
|
||||||
}
|
}
|
||||||
env = environ_create();
|
environ_free(&env);
|
||||||
if (c != NULL && !args_has(args, 'E'))
|
|
||||||
environ_update(global_s_options, c->environ, env);
|
|
||||||
s = session_create(prefix, newname, cwd, env, oo, tiop);
|
|
||||||
|
|
||||||
/* Spawn the initial window. */
|
/* Set the initial window name if one given. */
|
||||||
memset(&sc, 0, sizeof sc);
|
if (cmd != NULL && data->winname != NULL) {
|
||||||
sc.item = item;
|
w = s->curw->window;
|
||||||
sc.s = s;
|
|
||||||
sc.c = c;
|
|
||||||
|
|
||||||
sc.name = args_get(args, 'n');
|
xfree(w->name);
|
||||||
sc.argc = args->argc;
|
w->name = xstrdup(data->winname);
|
||||||
sc.argv = args->argv;
|
|
||||||
|
|
||||||
sc.idx = -1;
|
options_set_number(&w->options, "automatic-rename", 0);
|
||||||
sc.cwd = args_get(args, 'c');
|
|
||||||
|
|
||||||
sc.flags = 0;
|
|
||||||
|
|
||||||
if (spawn_window(&sc, &cause) == NULL) {
|
|
||||||
session_destroy(s, 0, __func__);
|
|
||||||
cmdq_error(item, "create window failed: %s", cause);
|
|
||||||
free(cause);
|
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If a target session is given, this is to be part of a session group,
|
* If a target session is given, this is to be part of a session group,
|
||||||
* so add it to the group and synchronize.
|
* so add it to the group and synchronize.
|
||||||
*/
|
*/
|
||||||
if (group != NULL) {
|
if (groupwith != NULL) {
|
||||||
if (sg == NULL) {
|
session_group_add(groupwith, s);
|
||||||
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_group_synchronize_to(s);
|
||||||
session_select(s, RB_MIN(winlinks, &s->windows)->idx);
|
session_select(s, RB_ROOT(&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);
|
|
||||||
} else if (c->session != NULL)
|
old_s = ctx->cmdclient->session;
|
||||||
c->last_session = c->session;
|
if (old_s != NULL)
|
||||||
c->session = s;
|
ctx->cmdclient->last_session = old_s;
|
||||||
if (~item->shared->flags & CMDQ_SHARED_REPEAT)
|
ctx->cmdclient->session = s;
|
||||||
server_client_set_key_table(c, NULL);
|
server_redraw_client(ctx->cmdclient);
|
||||||
tty_update_client_offset(c);
|
} else {
|
||||||
status_timer_start(c);
|
old_s = ctx->curclient->session;
|
||||||
notify_client("client-session-changed", c);
|
if (old_s != NULL)
|
||||||
session_update_activity(s, NULL);
|
ctx->curclient->last_session = old_s;
|
||||||
gettimeofday(&s->last_attached_time, NULL);
|
ctx->curclient->session = s;
|
||||||
server_redraw_client(c);
|
server_redraw_client(ctx->curclient);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
server_update_socket();
|
server_update_socket();
|
||||||
@@ -327,32 +300,53 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
* If there are still configuration file errors to display, put the new
|
* If there are still configuration file errors to display, put the new
|
||||||
* session's current window into more mode and display them now.
|
* session's current window into more mode and display them now.
|
||||||
*/
|
*/
|
||||||
if (cfg_finished)
|
if (cfg_finished && !ARRAY_EMPTY(&cfg_causes)) {
|
||||||
cfg_show_causes(s);
|
wp = s->curw->window->active;
|
||||||
|
window_pane_set_mode(wp, &window_copy_mode);
|
||||||
/* Print if requested. */
|
window_copy_init_for_output(wp);
|
||||||
if (args_has(args, 'P')) {
|
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
cause = ARRAY_ITEM(&cfg_causes, i);
|
||||||
template = NEW_SESSION_TEMPLATE;
|
window_copy_add(wp, "%s", cause);
|
||||||
cp = format_single(item, template, c, s, s->curw, NULL);
|
xfree(cause);
|
||||||
cmdq_print(item, "%s", cp);
|
}
|
||||||
free(cp);
|
ARRAY_FREE(&cfg_causes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!detached) {
|
return (!detached); /* 1 means don't tell command client to exit */
|
||||||
c->flags |= CLIENT_ATTACHED;
|
}
|
||||||
cmd_find_from_session(&item->shared->current, s, 0);
|
|
||||||
}
|
void
|
||||||
|
cmd_new_session_free(struct cmd *self)
|
||||||
cmd_find_from_session(&fs, s, 0);
|
{
|
||||||
cmdq_insert_hook(s, item, &fs, "after-new-session");
|
struct cmd_new_session_data *data = self->data;
|
||||||
|
|
||||||
free(cwd);
|
if (data->newname != NULL)
|
||||||
free(newname);
|
xfree(data->newname);
|
||||||
return (CMD_RETURN_NORMAL);
|
if (data->winname != NULL)
|
||||||
|
xfree(data->winname);
|
||||||
fail:
|
if (data->cmd != NULL)
|
||||||
free(cwd);
|
xfree(data->cmd);
|
||||||
free(newname);
|
xfree(data);
|
||||||
return (CMD_RETURN_ERROR);
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_new_session_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_new_session_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->flag_detached)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && data->winname != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -n ", data->winname);
|
||||||
|
if (off < len && data->newname != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -s ", data->newname);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->cmd != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
274
cmd-new-window.c
274
cmd-new-window.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-new-window.c,v 1.47 2010-07-02 02:49:19 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,93 +26,211 @@
|
|||||||
* Create a new window.
|
* Create a new window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define NEW_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
int cmd_new_window_parse(struct cmd *, int, char **, char **);
|
||||||
|
int cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_new_window_free(struct cmd *);
|
||||||
|
void cmd_new_window_init(struct cmd *, int);
|
||||||
|
size_t cmd_new_window_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
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_insert_after;
|
||||||
|
int flag_detached;
|
||||||
.args = { "ac:de:F:kn:Pt:", 0, -1 },
|
int flag_kill;
|
||||||
.usage = "[-adkP] [-c start-directory] [-e environment] [-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",
|
||||||
|
"[-adk] [-n window-name] [-t target-window] [command]",
|
||||||
|
0, "",
|
||||||
|
cmd_new_window_init,
|
||||||
|
cmd_new_window_parse,
|
||||||
|
cmd_new_window_exec,
|
||||||
|
cmd_new_window_free,
|
||||||
|
cmd_new_window_print
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
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 spawn_context sc;
|
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
int idx = item->target.idx;
|
|
||||||
struct winlink *new_wl;
|
|
||||||
char *cause = NULL, *cp;
|
|
||||||
const char *template, *add;
|
|
||||||
struct cmd_find_state fs;
|
|
||||||
struct args_value *value;
|
|
||||||
|
|
||||||
if (args_has(args, 'a') && (idx = winlink_shuffle_up(s, wl)) == -1) {
|
self->data = data = xmalloc(sizeof *data);
|
||||||
cmdq_error(item, "couldn't get a window index");
|
data->target = NULL;
|
||||||
return (CMD_RETURN_ERROR);
|
data->name = NULL;
|
||||||
|
data->cmd = NULL;
|
||||||
|
data->flag_insert_after = 0;
|
||||||
|
data->flag_detached = 0;
|
||||||
|
data->flag_kill = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_new_window_data *data;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
self->entry->init(self, KEYC_NONE);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "adkt:n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'a':
|
||||||
|
data->flag_insert_after = 1;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
data->flag_detached = 1;
|
||||||
|
break;
|
||||||
|
case 'k':
|
||||||
|
data->flag_kill = 1;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
if (data->target == NULL)
|
||||||
|
data->target = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
if (data->name == NULL)
|
||||||
|
data->name = xstrdup(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc != 0 && argc != 1)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
data->cmd = xstrdup(argv[0]);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_new_window_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
char *cmd, *cwd, *cause;
|
||||||
|
int idx, last;
|
||||||
|
|
||||||
|
if (data == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (data->flag_insert_after) {
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
idx = wl->idx + 1;
|
||||||
|
|
||||||
|
/* Find the next free index. */
|
||||||
|
for (last = idx; last < INT_MAX; last++) {
|
||||||
|
if (winlink_find_by_index(&s->windows, last) == NULL)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (last == INT_MAX) {
|
||||||
|
ctx->error(ctx, "no free window indexes");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move everything from last - 1 to idx up a bit. */
|
||||||
|
for (; last > idx; last--) {
|
||||||
|
wl = winlink_find_by_index(&s->windows, last - 1);
|
||||||
|
server_link_window(s, wl, s, last, 0, 0, NULL);
|
||||||
|
server_unlink_window(s, wl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((idx = cmd_find_index(ctx, data->target, &s)) == -2)
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&sc, 0, sizeof sc);
|
wl = NULL;
|
||||||
sc.item = item;
|
if (idx != -1)
|
||||||
sc.s = s;
|
wl = winlink_find_by_index(&s->windows, idx);
|
||||||
sc.c = c;
|
if (wl != NULL && data->flag_kill) {
|
||||||
|
/*
|
||||||
|
* Can't use session_detach as it will destroy session if this
|
||||||
|
* makes it empty.
|
||||||
|
*/
|
||||||
|
wl->flags &= ~WINLINK_ALERTFLAGS;
|
||||||
|
winlink_stack_remove(&s->lastw, wl);
|
||||||
|
winlink_remove(&s->windows, wl);
|
||||||
|
|
||||||
sc.name = args_get(args, 'n');
|
/* Force select/redraw if current. */
|
||||||
sc.argc = args->argc;
|
if (wl == s->curw) {
|
||||||
sc.argv = args->argv;
|
data->flag_detached = 0;
|
||||||
sc.environ = environ_create();
|
s->curw = NULL;
|
||||||
|
}
|
||||||
add = args_first_value(args, 'e', &value);
|
|
||||||
while (add != NULL) {
|
|
||||||
environ_put(sc.environ, add);
|
|
||||||
add = args_next_value(&value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.idx = idx;
|
cmd = data->cmd;
|
||||||
sc.cwd = args_get(args, 'c');
|
if (cmd == NULL)
|
||||||
|
cmd = options_get_string(&s->options, "default-command");
|
||||||
sc.flags = 0;
|
cwd = options_get_string(&s->options, "default-path");
|
||||||
if (args_has(args, 'd'))
|
if (*cwd == '\0') {
|
||||||
sc.flags |= SPAWN_DETACHED;
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
if (args_has(args, 'k'))
|
cwd = ctx->cmdclient->cwd;
|
||||||
sc.flags |= SPAWN_KILL;
|
else
|
||||||
|
cwd = s->cwd;
|
||||||
if ((new_wl = spawn_window(&sc, &cause)) == NULL) {
|
|
||||||
cmdq_error(item, "create window failed: %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
if (!args_has(args, 'd') || new_wl == s->curw) {
|
|
||||||
cmd_find_from_winlink(current, new_wl, 0);
|
if (idx == -1)
|
||||||
|
idx = -1 - options_get_number(&s->options, "base-index");
|
||||||
|
wl = session_new(s, data->name, cmd, cwd, idx, &cause);
|
||||||
|
if (wl == NULL) {
|
||||||
|
ctx->error(ctx, "create window failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (!data->flag_detached) {
|
||||||
|
session_select(s, wl->idx);
|
||||||
server_redraw_session_group(s);
|
server_redraw_session_group(s);
|
||||||
} else
|
} else
|
||||||
server_status_session_group(s);
|
server_status_session_group(s);
|
||||||
|
|
||||||
if (args_has(args, 'P')) {
|
return (0);
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
}
|
||||||
template = NEW_WINDOW_TEMPLATE;
|
|
||||||
cp = format_single(item, template, c, s, new_wl,
|
void
|
||||||
new_wl->window->active);
|
cmd_new_window_free(struct cmd *self)
|
||||||
cmdq_print(item, "%s", cp);
|
{
|
||||||
free(cp);
|
struct cmd_new_window_data *data = self->data;
|
||||||
}
|
|
||||||
|
if (data->target != NULL)
|
||||||
cmd_find_from_winlink(&fs, new_wl, 0);
|
xfree(data->target);
|
||||||
cmdq_insert_hook(s, item, &fs, "after-new-window");
|
if (data->name != NULL)
|
||||||
|
xfree(data->name);
|
||||||
environ_free(sc.environ);
|
if (data->cmd != NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
xfree(data->cmd);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_new_window_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_new_window_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->flag_detached)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
if (off < len && data->name != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -n ", data->name);
|
||||||
|
if (off < len && data->cmd != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
54
cmd-next-layout.c
Normal file
54
cmd-next-layout.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* $Id: cmd-next-layout.c,v 1.6 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Switch window to next layout.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_next_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_next_layout_entry = {
|
||||||
|
"next-layout", "nextl",
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_next_layout_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_next_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct winlink *wl;
|
||||||
|
u_int layout;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
layout = layout_set_next(wl->window);
|
||||||
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
76
cmd-next-window.c
Normal file
76
cmd-next-window.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/* $Id: cmd-next-window.c,v 1.21 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move to next window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_next_window_init(struct cmd *, int);
|
||||||
|
int cmd_next_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_next_window_entry = {
|
||||||
|
"next-window", "next",
|
||||||
|
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, "a",
|
||||||
|
cmd_next_window_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_next_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_next_window_init(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
if (key == ('n' | KEYC_ESCAPE))
|
||||||
|
cmd_set_flag(&data->chflags, 'a');
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
int activity;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
activity = 0;
|
||||||
|
if (cmd_check_flag(data->chflags, 'a'))
|
||||||
|
activity = 1;
|
||||||
|
|
||||||
|
if (session_next(s, activity) == 0)
|
||||||
|
server_redraw_session(s);
|
||||||
|
else {
|
||||||
|
ctx->error(ctx, "no next window");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
1567
cmd-parse.y
1567
cmd-parse.y
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-paste-buffer.c,v 1.29 2010-08-11 22:17:32 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,81 +27,196 @@
|
|||||||
* Paste paste buffer if present.
|
* Paste paste buffer if present.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmdq_item *);
|
struct cmd_paste_buffer_data {
|
||||||
|
char *target;
|
||||||
|
int buffer;
|
||||||
|
|
||||||
const struct cmd_entry cmd_paste_buffer_entry = {
|
int flag_delete;
|
||||||
.name = "paste-buffer",
|
char *sepstr;
|
||||||
.alias = "pasteb",
|
|
||||||
|
|
||||||
.args = { "db:prs:t:", 0, 0 },
|
|
||||||
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
|
|
||||||
CMD_TARGET_PANE_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_paste_buffer_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
void cmd_paste_buffer_init(struct cmd *, int);
|
||||||
cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
int cmd_paste_buffer_parse(struct cmd *, int, char **, char **);
|
||||||
|
int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_paste_buffer_filter(
|
||||||
|
struct window_pane *, const char *, size_t, char *);
|
||||||
|
void cmd_paste_buffer_free(struct cmd *);
|
||||||
|
size_t cmd_paste_buffer_print(struct cmd *, char *, size_t);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_paste_buffer_entry = {
|
||||||
|
"paste-buffer", "pasteb",
|
||||||
|
"[-dr] [-s separator] [-b buffer-index] [-t target-pane]",
|
||||||
|
0, "",
|
||||||
|
cmd_paste_buffer_init,
|
||||||
|
cmd_paste_buffer_parse,
|
||||||
|
cmd_paste_buffer_exec,
|
||||||
|
cmd_paste_buffer_free,
|
||||||
|
cmd_paste_buffer_print
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_paste_buffer_init(struct cmd *self, unused int arg)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_paste_buffer_data *data;
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
struct paste_buffer *pb;
|
|
||||||
const char *sepstr, *bufname, *bufdata, *bufend, *line;
|
|
||||||
size_t seplen, bufsize;
|
|
||||||
int bracket = args_has(args, 'p');
|
|
||||||
|
|
||||||
bufname = NULL;
|
self->data = data = xmalloc(sizeof *data);
|
||||||
if (args_has(args, 'b'))
|
data->target = NULL;
|
||||||
bufname = args_get(args, 'b');
|
data->buffer = -1;
|
||||||
|
data->flag_delete = 0;
|
||||||
if (bufname == NULL)
|
data->sepstr = xstrdup("\r");
|
||||||
pb = paste_get_top(NULL);
|
}
|
||||||
else {
|
|
||||||
pb = paste_get_name(bufname);
|
int
|
||||||
if (pb == NULL) {
|
cmd_paste_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||||
cmdq_error(item, "no buffer %s", bufname);
|
{
|
||||||
return (CMD_RETURN_ERROR);
|
struct cmd_paste_buffer_data *data;
|
||||||
}
|
int opt, n;
|
||||||
}
|
const char *errstr;
|
||||||
|
|
||||||
if (pb != NULL && ~wp->flags & PANE_INPUTOFF) {
|
cmd_paste_buffer_init(self, 0);
|
||||||
sepstr = args_get(args, 's');
|
data = self->data;
|
||||||
if (sepstr == NULL) {
|
|
||||||
if (args_has(args, 'r'))
|
while ((opt = getopt(argc, argv, "b:ds:t:r")) != -1) {
|
||||||
sepstr = "\n";
|
switch (opt) {
|
||||||
else
|
case 'b':
|
||||||
sepstr = "\r";
|
if (data->buffer == -1) {
|
||||||
}
|
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
seplen = strlen(sepstr);
|
if (errstr != NULL) {
|
||||||
|
xasprintf(cause, "buffer %s", errstr);
|
||||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
goto error;
|
||||||
bufferevent_write(wp->event, "\033[200~", 6);
|
}
|
||||||
|
data->buffer = n;
|
||||||
bufdata = paste_buffer_data(pb, &bufsize);
|
}
|
||||||
bufend = bufdata + bufsize;
|
break;
|
||||||
|
case 'd':
|
||||||
for (;;) {
|
data->flag_delete = 1;
|
||||||
line = memchr(bufdata, '\n', bufend - bufdata);
|
break;
|
||||||
if (line == NULL)
|
case 's':
|
||||||
break;
|
if (data->sepstr != NULL)
|
||||||
|
xfree(data->sepstr);
|
||||||
bufferevent_write(wp->event, bufdata, line - bufdata);
|
data->sepstr = xstrdup(optarg);
|
||||||
bufferevent_write(wp->event, sepstr, seplen);
|
break;
|
||||||
|
case 't':
|
||||||
bufdata = line + 1;
|
if (data->target == NULL)
|
||||||
}
|
data->target = xstrdup(optarg);
|
||||||
if (bufdata != bufend)
|
break;
|
||||||
bufferevent_write(wp->event, bufdata, bufend - bufdata);
|
case 'r':
|
||||||
|
if (data->sepstr != NULL)
|
||||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
xfree(data->sepstr);
|
||||||
bufferevent_write(wp->event, "\033[201~", 6);
|
data->sepstr = xstrdup("\n");
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
if (pb != NULL && args_has(args, 'd'))
|
goto usage;
|
||||||
paste_free(pb);
|
}
|
||||||
|
}
|
||||||
return (CMD_RETURN_NORMAL);
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
|
|
||||||
|
error:
|
||||||
|
self->entry->free(self);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_paste_buffer_data *data = self->data;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct session *s;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, &s, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (data->buffer == -1)
|
||||||
|
pb = paste_get_top(&s->buffers);
|
||||||
|
else {
|
||||||
|
if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pb != NULL)
|
||||||
|
cmd_paste_buffer_filter(wp, pb->data, pb->size, data->sepstr);
|
||||||
|
|
||||||
|
/* Delete the buffer if -d. */
|
||||||
|
if (data->flag_delete) {
|
||||||
|
if (data->buffer == -1)
|
||||||
|
paste_free_top(&s->buffers);
|
||||||
|
else
|
||||||
|
paste_free_index(&s->buffers, data->buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add bytes to a buffer and filter '\n' according to separator. */
|
||||||
|
void
|
||||||
|
cmd_paste_buffer_filter(
|
||||||
|
struct window_pane *wp, const char *data, size_t size, char *sep)
|
||||||
|
{
|
||||||
|
const char *end = data + size;
|
||||||
|
const char *lf;
|
||||||
|
size_t seplen;
|
||||||
|
|
||||||
|
seplen = strlen(sep);
|
||||||
|
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
||||||
|
if (lf != data)
|
||||||
|
bufferevent_write(wp->event, data, lf - data);
|
||||||
|
bufferevent_write(wp->event, sep, seplen);
|
||||||
|
data = lf + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end != data)
|
||||||
|
bufferevent_write(wp->event, data, end - data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_paste_buffer_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_paste_buffer_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
if (data->sepstr != NULL)
|
||||||
|
xfree(data->sepstr);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_paste_buffer_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_paste_buffer_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
char tmp[BUFSIZ];
|
||||||
|
int r_flag;
|
||||||
|
|
||||||
|
r_flag = 0;
|
||||||
|
if (data->sepstr != NULL)
|
||||||
|
r_flag = (data->sepstr[0] == '\n' && data->sepstr[1] == '\0');
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->flag_delete)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -d");
|
||||||
|
if (off < len && r_flag)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -r");
|
||||||
|
if (off < len && data->buffer != -1)
|
||||||
|
off += xsnprintf(buf + off, len - off, " -b %d", data->buffer);
|
||||||
|
if (off < len && data->sepstr != NULL && !r_flag) {
|
||||||
|
strnvis(
|
||||||
|
tmp, data->sepstr, sizeof tmp, VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -s ", tmp);
|
||||||
|
}
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
193
cmd-pipe-pane.c
193
cmd-pipe-pane.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-pipe-pane.c,v 1.15 2010-10-24 00:45:57 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
|
||||||
@@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -33,37 +31,35 @@
|
|||||||
* Open pipe to redirect pane output. If already open, close first.
|
* Open pipe to redirect pane output. If already open, close first.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmdq_item *);
|
int cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static void cmd_pipe_pane_read_callback(struct bufferevent *, void *);
|
void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
||||||
static void cmd_pipe_pane_write_callback(struct bufferevent *, void *);
|
|
||||||
static void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_pipe_pane_entry = {
|
const struct cmd_entry cmd_pipe_pane_entry = {
|
||||||
.name = "pipe-pane",
|
"pipe-pane", "pipep",
|
||||||
.alias = "pipep",
|
CMD_TARGET_PANE_USAGE "[-o] [command]",
|
||||||
|
CMD_ARG01, "o",
|
||||||
.args = { "IOot:", 0, 1 },
|
cmd_target_init,
|
||||||
.usage = "[-IOo] " CMD_TARGET_PANE_USAGE " [command]",
|
cmd_target_parse,
|
||||||
|
cmd_pipe_pane_exec,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_pipe_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct cmd_target_data *data = self->data;
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
struct client *c;
|
||||||
struct window_pane *wp = item->target.wp;
|
struct window_pane *wp;
|
||||||
struct session *s = item->target.s;
|
char *command;
|
||||||
struct winlink *wl = item->target.wl;
|
int old_fd, pipe_fd[2], null_fd, mode;
|
||||||
char *cmd;
|
|
||||||
int old_fd, pipe_fd[2], null_fd, in, out;
|
if ((c = cmd_find_client(ctx, NULL)) == NULL)
|
||||||
struct format_tree *ft;
|
return (-1);
|
||||||
sigset_t set, oldset;
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
/* Destroy the old pipe. */
|
/* Destroy the old pipe. */
|
||||||
old_fd = wp->pipe_fd;
|
old_fd = wp->pipe_fd;
|
||||||
@@ -71,16 +67,11 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
bufferevent_free(wp->pipe_event);
|
bufferevent_free(wp->pipe_event);
|
||||||
close(wp->pipe_fd);
|
close(wp->pipe_fd);
|
||||||
wp->pipe_fd = -1;
|
wp->pipe_fd = -1;
|
||||||
|
|
||||||
if (window_pane_destroy_ready(wp)) {
|
|
||||||
server_destroy_pane(wp, 1);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no pipe command, that is enough. */
|
/* If no pipe command, that is enough. */
|
||||||
if (args->argc == 0 || *args->argv[0] == '\0')
|
if (data->arg == NULL || *data->arg == '\0')
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* With -o, only open the new pipe if there was no previous one. This
|
* With -o, only open the new pipe if there was no previous one. This
|
||||||
@@ -88,138 +79,70 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
*
|
*
|
||||||
* bind ^p pipep -o 'cat >>~/output'
|
* bind ^p pipep -o 'cat >>~/output'
|
||||||
*/
|
*/
|
||||||
if (args_has(self->args, 'o') && old_fd != -1)
|
if (cmd_check_flag(data->chflags, 'o') && old_fd != -1)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
/* What do we want to do? Neither -I or -O is -O. */
|
|
||||||
if (args_has(self->args, 'I')) {
|
|
||||||
in = 1;
|
|
||||||
out = args_has(self->args, 'O');
|
|
||||||
} else {
|
|
||||||
in = 0;
|
|
||||||
out = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Open the new pipe. */
|
/* Open the new pipe. */
|
||||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
||||||
cmdq_error(item, "socketpair error: %s", strerror(errno));
|
ctx->error(ctx, "socketpair error: %s", strerror(errno));
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Expand the command. */
|
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
|
||||||
format_defaults(ft, c, s, wl, wp);
|
|
||||||
cmd = format_expand_time(ft, args->argv[0]);
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
/* Fork the child. */
|
/* Fork the child. */
|
||||||
sigfillset(&set);
|
|
||||||
sigprocmask(SIG_BLOCK, &set, &oldset);
|
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
ctx->error(ctx, "fork error: %s", strerror(errno));
|
||||||
cmdq_error(item, "fork error: %s", strerror(errno));
|
return (-1);
|
||||||
|
|
||||||
free(cmd);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
case 0:
|
case 0:
|
||||||
/* Child process. */
|
/* Child process. */
|
||||||
proc_clear_signals(server_proc, 1);
|
|
||||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
|
||||||
close(pipe_fd[0]);
|
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);
|
null_fd = open(_PATH_DEVNULL, O_WRONLY, 0);
|
||||||
if (out) {
|
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
||||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
_exit(1);
|
||||||
_exit(1);
|
|
||||||
} else {
|
|
||||||
if (dup2(null_fd, STDIN_FILENO) == -1)
|
|
||||||
_exit(1);
|
|
||||||
}
|
|
||||||
if (in) {
|
|
||||||
if (dup2(pipe_fd[1], STDOUT_FILENO) == -1)
|
|
||||||
_exit(1);
|
|
||||||
if (pipe_fd[1] != STDOUT_FILENO)
|
|
||||||
close(pipe_fd[1]);
|
|
||||||
} else {
|
|
||||||
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
|
||||||
_exit(1);
|
|
||||||
}
|
|
||||||
if (dup2(null_fd, STDERR_FILENO) == -1)
|
if (dup2(null_fd, STDERR_FILENO) == -1)
|
||||||
_exit(1);
|
_exit(1);
|
||||||
|
if (null_fd != STDOUT_FILENO && null_fd != STDERR_FILENO)
|
||||||
|
close(null_fd);
|
||||||
|
|
||||||
closefrom(STDERR_FILENO + 1);
|
closefrom(STDERR_FILENO + 1);
|
||||||
|
|
||||||
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
|
command = status_replace(c, NULL, data->arg, time(NULL), 0);
|
||||||
|
execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
default:
|
default:
|
||||||
/* Parent process. */
|
/* Parent process. */
|
||||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
|
||||||
close(pipe_fd[1]);
|
close(pipe_fd[1]);
|
||||||
|
|
||||||
wp->pipe_fd = pipe_fd[0];
|
wp->pipe_fd = pipe_fd[0];
|
||||||
if (wp->fd != -1)
|
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
|
||||||
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
|
|
||||||
else
|
|
||||||
wp->pipe_off = 0;
|
|
||||||
|
|
||||||
setblocking(wp->pipe_fd, 0);
|
|
||||||
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
||||||
cmd_pipe_pane_read_callback,
|
NULL, NULL, cmd_pipe_pane_error_callback, wp);
|
||||||
cmd_pipe_pane_write_callback,
|
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
||||||
cmd_pipe_pane_error_callback,
|
|
||||||
wp);
|
|
||||||
if (wp->pipe_event == NULL)
|
|
||||||
fatalx("out of memory");
|
|
||||||
if (out)
|
|
||||||
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
|
||||||
if (in)
|
|
||||||
bufferevent_enable(wp->pipe_event, EV_READ);
|
|
||||||
|
|
||||||
free(cmd);
|
if ((mode = fcntl(wp->pipe_fd, F_GETFL)) == -1)
|
||||||
return (CMD_RETURN_NORMAL);
|
fatal("fcntl failed");
|
||||||
|
if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||||
|
fatal("fcntl failed");
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
/* ARGSUSED */
|
||||||
cmd_pipe_pane_read_callback(__unused struct bufferevent *bufev, void *data)
|
void
|
||||||
|
cmd_pipe_pane_error_callback(
|
||||||
|
unused struct bufferevent *bufev, unused short what, void *data)
|
||||||
{
|
{
|
||||||
struct window_pane *wp = data;
|
struct window_pane *wp = data;
|
||||||
struct evbuffer *evb = wp->pipe_event->input;
|
|
||||||
size_t available;
|
|
||||||
|
|
||||||
available = EVBUFFER_LENGTH(evb);
|
|
||||||
log_debug("%%%u pipe read %zu", wp->id, available);
|
|
||||||
|
|
||||||
bufferevent_write(wp->event, EVBUFFER_DATA(evb), available);
|
|
||||||
evbuffer_drain(evb, available);
|
|
||||||
|
|
||||||
if (window_pane_destroy_ready(wp))
|
|
||||||
server_destroy_pane(wp, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_pipe_pane_write_callback(__unused struct bufferevent *bufev, void *data)
|
|
||||||
{
|
|
||||||
struct window_pane *wp = data;
|
|
||||||
|
|
||||||
log_debug("%%%u pipe empty", wp->id);
|
|
||||||
|
|
||||||
if (window_pane_destroy_ready(wp))
|
|
||||||
server_destroy_pane(wp, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_pipe_pane_error_callback(__unused struct bufferevent *bufev,
|
|
||||||
__unused short what, void *data)
|
|
||||||
{
|
|
||||||
struct window_pane *wp = data;
|
|
||||||
|
|
||||||
log_debug("%%%u pipe error", wp->id);
|
|
||||||
|
|
||||||
bufferevent_free(wp->pipe_event);
|
bufferevent_free(wp->pipe_event);
|
||||||
close(wp->pipe_fd);
|
close(wp->pipe_fd);
|
||||||
wp->pipe_fd = -1;
|
wp->pipe_fd = -1;
|
||||||
|
|
||||||
if (window_pane_destroy_ready(wp))
|
|
||||||
server_destroy_pane(wp, 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.6 2009-12-04 22:14:47 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Switch window to previous layout.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_previous_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_previous_layout_entry = {
|
||||||
|
"previous-layout", "prevl",
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_previous_layout_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_previous_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct winlink *wl;
|
||||||
|
u_int layout;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
layout = layout_set_previous(wl->window);
|
||||||
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
76
cmd-previous-window.c
Normal file
76
cmd-previous-window.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/* $Id: cmd-previous-window.c,v 1.21 2009-11-14 17:56:39 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move to previous window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_previous_window_init(struct cmd *, int);
|
||||||
|
int cmd_previous_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_previous_window_entry = {
|
||||||
|
"previous-window", "prev",
|
||||||
|
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
0, "a",
|
||||||
|
cmd_previous_window_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_previous_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_previous_window_init(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
|
cmd_target_init(self, key);
|
||||||
|
data = self->data;
|
||||||
|
|
||||||
|
if (key == ('p' | KEYC_ESCAPE))
|
||||||
|
cmd_set_flag(&data->chflags, 'a');
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
int activity;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
activity = 0;
|
||||||
|
if (cmd_check_flag(data->chflags, 'a'))
|
||||||
|
activity = 1;
|
||||||
|
|
||||||
|
if (session_previous(s, activity) == 0)
|
||||||
|
server_redraw_session(s);
|
||||||
|
else {
|
||||||
|
ctx->error(ctx, "no previous window");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
557
cmd-queue.c
557
cmd-queue.c
@@ -1,557 +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[256];
|
|
||||||
|
|
||||||
if (c == NULL)
|
|
||||||
return ("<global>");
|
|
||||||
if (c->name != NULL)
|
|
||||||
xsnprintf(s, sizeof s, "<%s>", c->name);
|
|
||||||
else
|
|
||||||
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. */
|
|
||||||
struct cmdq_item *
|
|
||||||
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);
|
|
||||||
log_debug("%s %s: %s", __func__, cmdq_name(c), item->name);
|
|
||||||
|
|
||||||
item = next;
|
|
||||||
} while (item != NULL);
|
|
||||||
return (TAILQ_LAST(queue, cmdq_list));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Insert an item. */
|
|
||||||
struct cmdq_item *
|
|
||||||
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 = after->next;
|
|
||||||
after->next = item;
|
|
||||||
|
|
||||||
if (c != NULL)
|
|
||||||
c->references++;
|
|
||||||
item->client = c;
|
|
||||||
|
|
||||||
item->queue = queue;
|
|
||||||
TAILQ_INSERT_AFTER(queue, after, item, entry);
|
|
||||||
log_debug("%s %s: %s after %s", __func__, cmdq_name(c),
|
|
||||||
item->name, after->name);
|
|
||||||
|
|
||||||
after = item;
|
|
||||||
item = next;
|
|
||||||
} while (item != NULL);
|
|
||||||
return (after);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Insert a hook. */
|
|
||||||
void
|
|
||||||
cmdq_insert_hook(struct session *s, struct cmdq_item *item,
|
|
||||||
struct cmd_find_state *fs, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
struct options *oo;
|
|
||||||
va_list ap;
|
|
||||||
char *name;
|
|
||||||
struct cmdq_item *new_item;
|
|
||||||
struct options_entry *o;
|
|
||||||
struct options_array_item *a;
|
|
||||||
struct cmd_list *cmdlist;
|
|
||||||
|
|
||||||
if (item->flags & CMDQ_NOHOOKS)
|
|
||||||
return;
|
|
||||||
if (s == NULL)
|
|
||||||
oo = global_s_options;
|
|
||||||
else
|
|
||||||
oo = s->options;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
xvasprintf(&name, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
o = options_get(oo, name);
|
|
||||||
if (o == NULL) {
|
|
||||||
free(name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
log_debug("running hook %s (parent %p)", name, item);
|
|
||||||
|
|
||||||
a = options_array_first(o);
|
|
||||||
while (a != NULL) {
|
|
||||||
cmdlist = options_array_item_value(a)->cmdlist;
|
|
||||||
if (cmdlist == NULL) {
|
|
||||||
a = options_array_next(a);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
new_item = cmdq_get_command(cmdlist, fs, NULL, CMDQ_NOHOOKS);
|
|
||||||
cmdq_format(new_item, "hook", "%s", name);
|
|
||||||
if (item != NULL)
|
|
||||||
item = cmdq_insert_after(item, new_item);
|
|
||||||
else
|
|
||||||
item = cmdq_append(NULL, new_item);
|
|
||||||
|
|
||||||
a = options_array_next(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Continue processing command queue. */
|
|
||||||
void
|
|
||||||
cmdq_continue(struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
item->flags &= ~CMDQ_WAITING;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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->cmdlist != NULL)
|
|
||||||
cmd_list_free(item->cmdlist);
|
|
||||||
|
|
||||||
TAILQ_REMOVE(item->queue, item, entry);
|
|
||||||
|
|
||||||
free(item->name);
|
|
||||||
free(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove all subsequent items that match this item's group. */
|
|
||||||
static void
|
|
||||||
cmdq_remove_group(struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct cmdq_item *this, *next;
|
|
||||||
|
|
||||||
if (item->group == 0)
|
|
||||||
return;
|
|
||||||
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;
|
|
||||||
struct cmdq_shared *shared = NULL;
|
|
||||||
u_int group = 0;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
|
||||||
if (cmd->group != group) {
|
|
||||||
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);
|
|
||||||
group = cmd->group;
|
|
||||||
}
|
|
||||||
|
|
||||||
item = xcalloc(1, sizeof *item);
|
|
||||||
xasprintf(&item->name, "[%s/%p]", cmd->entry->name, item);
|
|
||||||
item->type = CMDQ_COMMAND;
|
|
||||||
|
|
||||||
item->group = cmd->group;
|
|
||||||
item->flags = flags;
|
|
||||||
|
|
||||||
item->shared = shared;
|
|
||||||
item->cmdlist = cmdlist;
|
|
||||||
item->cmd = cmd;
|
|
||||||
|
|
||||||
log_debug("%s: %s group %u", __func__, item->name, item->group);
|
|
||||||
|
|
||||||
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;
|
|
||||||
const char *name = cmdq_name(c);
|
|
||||||
struct cmdq_shared *shared = item->shared;
|
|
||||||
struct cmd *cmd = item->cmd;
|
|
||||||
const struct cmd_entry *entry = cmd->entry;
|
|
||||||
enum cmd_retval retval;
|
|
||||||
struct cmd_find_state *fsp, fs;
|
|
||||||
int flags;
|
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
if (log_get_level() > 1) {
|
|
||||||
tmp = cmd_print(cmd);
|
|
||||||
log_debug("%s %s: (%u) %s", __func__, name, item->group, tmp);
|
|
||||||
free(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
flags = !!(shared->flags & CMDQ_SHARED_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) == 0)
|
|
||||||
fsp = &fs;
|
|
||||||
else
|
|
||||||
goto out;
|
|
||||||
cmdq_insert_hook(fsp->s, 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;
|
|
||||||
|
|
||||||
item = xcalloc(1, sizeof *item);
|
|
||||||
xasprintf(&item->name, "[%s/%p]", name, item);
|
|
||||||
item->type = CMDQ_CALLBACK;
|
|
||||||
|
|
||||||
item->group = 0;
|
|
||||||
item->flags = 0;
|
|
||||||
|
|
||||||
item->cb = cb;
|
|
||||||
item->data = data;
|
|
||||||
|
|
||||||
return (item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Generic error callback. */
|
|
||||||
static enum cmd_retval
|
|
||||||
cmdq_error_callback(struct cmdq_item *item, void *data)
|
|
||||||
{
|
|
||||||
char *error = data;
|
|
||||||
|
|
||||||
cmdq_error(item, "%s", error);
|
|
||||||
free(error);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get an error callback for the command queue. */
|
|
||||||
struct cmdq_item *
|
|
||||||
cmdq_get_error(const char *error)
|
|
||||||
{
|
|
||||||
return (cmdq_get_callback(cmdq_error_callback, xstrdup(error)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
long t = item->time;
|
|
||||||
u_int number = item->number;
|
|
||||||
|
|
||||||
if (c != NULL && (c->flags & CLIENT_CONTROL))
|
|
||||||
file_print(c, "%%%s %ld %u %d\n", guard, t, number, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Show message from command. */
|
|
||||||
void
|
|
||||||
cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
struct client *c = item->client;
|
|
||||||
struct window_pane *wp;
|
|
||||||
struct window_mode_entry *wme;
|
|
||||||
va_list ap;
|
|
||||||
char *tmp, *msg;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
xvasprintf(&msg, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
log_debug("%s: %s", __func__, msg);
|
|
||||||
|
|
||||||
if (c == NULL)
|
|
||||||
/* nothing */;
|
|
||||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
|
||||||
if (~c->flags & CLIENT_UTF8) {
|
|
||||||
tmp = msg;
|
|
||||||
msg = utf8_sanitize(tmp);
|
|
||||||
free(tmp);
|
|
||||||
}
|
|
||||||
file_print(c, "%s\n", msg);
|
|
||||||
} else {
|
|
||||||
wp = c->session->curw->window->active;
|
|
||||||
wme = TAILQ_FIRST(&wp->modes);
|
|
||||||
if (wme == NULL || wme->mode != &window_view_mode)
|
|
||||||
window_pane_set_mode(wp, &window_view_mode, NULL, NULL);
|
|
||||||
window_copy_add(wp, "%s", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
xvasprintf(&msg, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
log_debug("%s: %s", __func__, msg);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
if (c->flags & CLIENT_CONTROL)
|
|
||||||
file_print(c, "%s\n", msg);
|
|
||||||
else
|
|
||||||
file_error(c, "%s\n", msg);
|
|
||||||
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.11 2009-11-14 17:56:39 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,144 +18,35 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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, "",
|
||||||
.args = { "cC:DF:lLRSt:U", 0, 1 },
|
cmd_target_init,
|
||||||
.usage = "[-cDlLRSU] [-C XxY] [-F flags] " CMD_TARGET_CLIENT_USAGE
|
cmd_target_parse,
|
||||||
" [adjustment]",
|
cmd_refresh_client_exec,
|
||||||
|
cmd_target_free,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_target_print
|
||||||
.exec = cmd_refresh_client_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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;
|
||||||
struct tty *tty;
|
|
||||||
struct window *w;
|
|
||||||
const char *size, *errstr;
|
|
||||||
char *copy, *next, *s;
|
|
||||||
u_int x, y, adjust;
|
|
||||||
|
|
||||||
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);
|
||||||
tty = &c->tty;
|
|
||||||
|
|
||||||
if (args_has(args, 'c') ||
|
server_redraw_client(c);
|
||||||
args_has(args, 'L') ||
|
|
||||||
args_has(args, 'R') ||
|
|
||||||
args_has(args, 'U') ||
|
|
||||||
args_has(args, 'D'))
|
|
||||||
{
|
|
||||||
if (args->argc == 0)
|
|
||||||
adjust = 1;
|
|
||||||
else {
|
|
||||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "adjustment %s", errstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'c'))
|
return (0);
|
||||||
c->pan_window = NULL;
|
|
||||||
else {
|
|
||||||
w = c->session->curw->window;
|
|
||||||
if (c->pan_window != w) {
|
|
||||||
c->pan_window = w;
|
|
||||||
c->pan_ox = tty->oox;
|
|
||||||
c->pan_oy = tty->ooy;
|
|
||||||
}
|
|
||||||
if (args_has(args, 'L')) {
|
|
||||||
if (c->pan_ox > adjust)
|
|
||||||
c->pan_ox -= adjust;
|
|
||||||
else
|
|
||||||
c->pan_ox = 0;
|
|
||||||
} else if (args_has(args, 'R')) {
|
|
||||||
c->pan_ox += adjust;
|
|
||||||
if (c->pan_ox > w->sx - tty->osx)
|
|
||||||
c->pan_ox = w->sx - tty->osx;
|
|
||||||
} else if (args_has(args, 'U')) {
|
|
||||||
if (c->pan_oy > adjust)
|
|
||||||
c->pan_oy -= adjust;
|
|
||||||
else
|
|
||||||
c->pan_oy = 0;
|
|
||||||
} else if (args_has(args, 'D')) {
|
|
||||||
c->pan_oy += adjust;
|
|
||||||
if (c->pan_oy > w->sy - tty->osy)
|
|
||||||
c->pan_oy = w->sy - tty->osy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tty_update_client_offset(c);
|
|
||||||
server_redraw_client(c);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'l')) {
|
|
||||||
if (c->session != NULL)
|
|
||||||
tty_putcode_ptr2(&c->tty, TTYC_MS, "", "?");
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'C') || args_has(args, 'F')) {
|
|
||||||
if (args_has(args, 'C')) {
|
|
||||||
if (!(c->flags & CLIENT_CONTROL)) {
|
|
||||||
cmdq_error(item, "not a control client");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
size = args_get(args, 'C');
|
|
||||||
if (sscanf(size, "%u,%u", &x, &y) != 2 &&
|
|
||||||
sscanf(size, "%ux%u", &x, &y) != 2) {
|
|
||||||
cmdq_error(item, "bad size argument");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
|
|
||||||
y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
|
|
||||||
cmdq_error(item, "size too small or too big");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
tty_set_size(&c->tty, x, y, 0, 0);
|
|
||||||
c->flags |= CLIENT_SIZECHANGED;
|
|
||||||
recalculate_sizes();
|
|
||||||
}
|
|
||||||
if (args_has(args, 'F')) {
|
|
||||||
if (!(c->flags & CLIENT_CONTROL)) {
|
|
||||||
cmdq_error(item, "not a control client");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
s = copy = xstrdup(args_get(args, 'F'));
|
|
||||||
while ((next = strsep(&s, ",")) != NULL) {
|
|
||||||
/* Unknown flags are ignored. */
|
|
||||||
if (strcmp(next, "no-output") == 0)
|
|
||||||
c->flags |= CLIENT_CONTROL_NOOUTPUT;
|
|
||||||
}
|
|
||||||
free(copy);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-rename-session.c,v 1.21 2010-12-22 15:36:44 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,54 +26,39 @@
|
|||||||
* 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, "",
|
||||||
.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 client *c = cmd_find_client(item, NULL, 1);
|
struct session *s;
|
||||||
struct session *s = item->target.s;
|
|
||||||
char *newname;
|
|
||||||
|
|
||||||
newname = format_single(item, args->argv[0], c, s, NULL, NULL);
|
if (data->arg != NULL && session_find(data->arg) != NULL) {
|
||||||
if (strcmp(newname, s->name) == 0) {
|
ctx->error(ctx, "duplicate session: %s", data->arg);
|
||||||
free(newname);
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session_check_name(newname)) {
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
cmdq_error(item, "bad session name: %s", newname);
|
return (-1);
|
||||||
free(newname);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (session_find(newname) != NULL) {
|
|
||||||
cmdq_error(item, "duplicate session: %s", newname);
|
|
||||||
free(newname);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
RB_REMOVE(sessions, &sessions, s);
|
RB_REMOVE(sessions, &sessions, s);
|
||||||
free(s->name);
|
xfree(s->name);
|
||||||
s->name = newname;
|
s->name = xstrdup(data->arg);
|
||||||
RB_INSERT(sessions, &sessions, s);
|
RB_INSERT(sessions, &sessions, s);
|
||||||
|
|
||||||
server_status_session(s);
|
server_status_session(s);
|
||||||
notify_session("session-renamed", s);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-rename-window.c,v 1.31 2009-11-14 17:56:39 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,37 +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, "",
|
||||||
.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 client *c = cmd_find_client(item, NULL, 1);
|
struct session *s;
|
||||||
struct session *s = item->target.s;
|
struct winlink *wl;
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
char *newname;
|
|
||||||
|
|
||||||
newname = format_single(item, args->argv[0], c, s, wl, NULL);
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
window_set_name(wl->window, newname);
|
return (-1);
|
||||||
options_set_number(wl->window->options, "automatic-rename", 0);
|
|
||||||
|
xfree(wl->window->name);
|
||||||
|
wl->window->name = xstrdup(data->arg);
|
||||||
|
options_set_number(&wl->window->options, "automatic-rename", 0);
|
||||||
|
|
||||||
server_status_window(wl->window);
|
server_status_window(wl->window);
|
||||||
free(newname);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-resize-pane.c,v 1.14 2009-12-04 22:14:47 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 <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -27,203 +26,86 @@
|
|||||||
* 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",
|
"[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||||
|
CMD_ARG01, "DLRU",
|
||||||
.args = { "DLMRt:Ux:y:Z", 0, 1 },
|
cmd_resize_pane_init,
|
||||||
.usage = "[-DLMRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
|
cmd_target_parse,
|
||||||
"[adjustment]",
|
cmd_resize_pane_exec,
|
||||||
|
cmd_target_free,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
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;
|
cmd_set_flag(&data->chflags, 'U');
|
||||||
const char *errstr, *p;
|
if (key == (KEYC_DOWN | KEYC_CTRL))
|
||||||
char *cause, *copy;
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
|
if (key == (KEYC_LEFT | KEYC_CTRL))
|
||||||
|
cmd_set_flag(&data->chflags, 'L');
|
||||||
|
if (key == (KEYC_RIGHT | KEYC_CTRL))
|
||||||
|
cmd_set_flag(&data->chflags, 'R');
|
||||||
|
|
||||||
|
if (key == (KEYC_UP | KEYC_ESCAPE)) {
|
||||||
|
cmd_set_flag(&data->chflags, 'U');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
if (key == (KEYC_DOWN | KEYC_ESCAPE)) {
|
||||||
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
if (key == (KEYC_LEFT | KEYC_ESCAPE)) {
|
||||||
|
cmd_set_flag(&data->chflags, 'L');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
if (key == (KEYC_RIGHT | KEYC_ESCAPE)) {
|
||||||
|
cmd_set_flag(&data->chflags, 'R');
|
||||||
|
data->arg = xstrdup("5");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct winlink *wl;
|
||||||
|
const char *errstr;
|
||||||
|
struct window_pane *wp;
|
||||||
u_int adjust;
|
u_int adjust;
|
||||||
int x, y, percentage;
|
|
||||||
size_t plen;
|
|
||||||
|
|
||||||
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 ((p = args_get(args, 'x')) != NULL) {
|
if (cmd_check_flag(data->chflags, 'L'))
|
||||||
plen = strlen(p);
|
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
|
||||||
if (p[plen - 1] == '%') {
|
else if (cmd_check_flag(data->chflags, 'R'))
|
||||||
copy = xstrdup(p);
|
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
|
||||||
copy[plen - 1] = '\0';
|
else if (cmd_check_flag(data->chflags, 'U'))
|
||||||
percentage = strtonum(copy, 0, INT_MAX, &errstr);
|
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust);
|
||||||
free(copy);
|
else if (cmd_check_flag(data->chflags, 'D'))
|
||||||
if (errstr != NULL) {
|
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
|
||||||
cmdq_error(item, "width %s", errstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
x = (w->sx * percentage) / 100;
|
|
||||||
if (x < PANE_MINIMUM)
|
|
||||||
x = PANE_MINIMUM;
|
|
||||||
if (x > INT_MAX)
|
|
||||||
x = INT_MAX;
|
|
||||||
} else {
|
|
||||||
x = args_strtonum(args, 'x', PANE_MINIMUM, INT_MAX,
|
|
||||||
&cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(item, "width %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
|
|
||||||
}
|
|
||||||
if ((p = args_get(args, 'y')) != NULL) {
|
|
||||||
plen = strlen(p);
|
|
||||||
if (p[plen - 1] == '%') {
|
|
||||||
copy = xstrdup(p);
|
|
||||||
copy[plen - 1] = '\0';
|
|
||||||
percentage = strtonum(copy, 0, INT_MAX, &errstr);
|
|
||||||
free(copy);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "height %s", errstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
y = (w->sy * percentage) / 100;
|
|
||||||
if (y < PANE_MINIMUM)
|
|
||||||
y = PANE_MINIMUM;
|
|
||||||
if (y > INT_MAX)
|
|
||||||
y = INT_MAX;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
y = args_strtonum(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(args, 'L'))
|
|
||||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust, 1);
|
|
||||||
else if (args_has(args, 'R'))
|
|
||||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust, 1);
|
|
||||||
else if (args_has(args, 'U'))
|
|
||||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust, 1);
|
|
||||||
else if (args_has(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 *w;
|
|
||||||
u_int y, ly, x, lx;
|
|
||||||
static const int offsets[][2] = {
|
|
||||||
{ 0, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
|
|
||||||
};
|
|
||||||
struct layout_cell *cells[nitems(offsets)], *lc;
|
|
||||||
u_int ncells = 0, i, j, resizes = 0;
|
|
||||||
enum layout_type type;
|
|
||||||
|
|
||||||
wl = cmd_mouse_window(m, NULL);
|
|
||||||
if (wl == NULL) {
|
|
||||||
c->tty.mouse_drag_update = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
w = wl->window;
|
|
||||||
|
|
||||||
y = m->y + m->oy; x = m->x + m->ox;
|
|
||||||
if (m->statusat == 0 && y >= m->statuslines)
|
|
||||||
y -= m->statuslines;
|
|
||||||
else if (m->statusat > 0 && y >= (u_int)m->statusat)
|
|
||||||
y = m->statusat - 1;
|
|
||||||
ly = m->ly + m->oy; lx = m->lx + m->ox;
|
|
||||||
if (m->statusat == 0 && ly >= m->statuslines)
|
|
||||||
ly -= m->statuslines;
|
|
||||||
else if (m->statusat > 0 && ly >= (u_int)m->statusat)
|
|
||||||
ly = m->statusat - 1;
|
|
||||||
|
|
||||||
for (i = 0; i < nitems(cells); i++) {
|
|
||||||
lc = layout_search_by_border(w->layout_root, lx + offsets[i][0],
|
|
||||||
ly + offsets[i][1]);
|
|
||||||
if (lc == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (j = 0; j < ncells; j++) {
|
|
||||||
if (cells[j] == lc) {
|
|
||||||
lc = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lc == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
cells[ncells] = lc;
|
|
||||||
ncells++;
|
|
||||||
}
|
|
||||||
if (ncells == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < ncells; i++) {
|
|
||||||
type = cells[i]->parent->type;
|
|
||||||
if (y != ly && type == LAYOUT_TOPBOTTOM) {
|
|
||||||
layout_resize_layout(w, cells[i], type, y - ly, 0);
|
|
||||||
resizes++;
|
|
||||||
} else if (x != lx && type == LAYOUT_LEFTRIGHT) {
|
|
||||||
layout_resize_layout(w, cells[i], type, x - lx, 0);
|
|
||||||
resizes++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (resizes != 0)
|
|
||||||
server_redraw_window(w);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,113 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2018 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"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Increase or decrease window size.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_resize_window_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_resize_window_entry = {
|
|
||||||
.name = "resize-window",
|
|
||||||
.alias = "resizew",
|
|
||||||
|
|
||||||
.args = { "aADLRt:Ux:y:", 0, 1 },
|
|
||||||
.usage = "[-aADLRU] [-x width] [-y height] " CMD_TARGET_WINDOW_USAGE " "
|
|
||||||
"[adjustment]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_resize_window_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_resize_window_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 session *s = item->target.s;
|
|
||||||
const char *errstr;
|
|
||||||
char *cause;
|
|
||||||
u_int adjust, sx, sy;
|
|
||||||
int xpixel = -1, ypixel = -1;
|
|
||||||
|
|
||||||
if (args->argc == 0)
|
|
||||||
adjust = 1;
|
|
||||||
else {
|
|
||||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "adjustment %s", errstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sx = w->sx;
|
|
||||||
sy = w->sy;
|
|
||||||
|
|
||||||
if (args_has(args, 'x')) {
|
|
||||||
sx = args_strtonum(args, 'x', WINDOW_MINIMUM, WINDOW_MAXIMUM,
|
|
||||||
&cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(item, "width %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (args_has(args, 'y')) {
|
|
||||||
sy = args_strtonum(args, 'y', WINDOW_MINIMUM, WINDOW_MAXIMUM,
|
|
||||||
&cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(item, "height %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'L')) {
|
|
||||||
if (sx >= adjust)
|
|
||||||
sx -= adjust;
|
|
||||||
} else if (args_has(args, 'R'))
|
|
||||||
sx += adjust;
|
|
||||||
else if (args_has(args, 'U')) {
|
|
||||||
if (sy >= adjust)
|
|
||||||
sy -= adjust;
|
|
||||||
} else if (args_has(args, 'D'))
|
|
||||||
sy += adjust;
|
|
||||||
|
|
||||||
if (args_has(args, 'A')) {
|
|
||||||
default_window_size(NULL, s, w, &sx, &sy, &xpixel, &ypixel,
|
|
||||||
WINDOW_SIZE_LARGEST);
|
|
||||||
} else if (args_has(args, 'a')) {
|
|
||||||
default_window_size(NULL, s, w, &sx, &sy, &xpixel, &ypixel,
|
|
||||||
WINDOW_SIZE_SMALLEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
options_set_number(w->options, "window-size", WINDOW_SIZE_MANUAL);
|
|
||||||
resize_window(w, sx, sy, xpixel, ypixel);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
@@ -1,96 +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 <string.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 = { "c:e:kt:", 0, -1 },
|
|
||||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
|
||||||
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 spawn_context sc;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
char *cause = NULL;
|
|
||||||
const char *add;
|
|
||||||
struct args_value *value;
|
|
||||||
|
|
||||||
memset(&sc, 0, sizeof sc);
|
|
||||||
sc.item = item;
|
|
||||||
sc.s = s;
|
|
||||||
sc.wl = wl;
|
|
||||||
|
|
||||||
sc.wp0 = wp;
|
|
||||||
sc.lc = NULL;
|
|
||||||
|
|
||||||
sc.name = NULL;
|
|
||||||
sc.argc = args->argc;
|
|
||||||
sc.argv = args->argv;
|
|
||||||
sc.environ = environ_create();
|
|
||||||
|
|
||||||
add = args_first_value(args, 'e', &value);
|
|
||||||
while (add != NULL) {
|
|
||||||
environ_put(sc.environ, add);
|
|
||||||
add = args_next_value(&value);
|
|
||||||
}
|
|
||||||
|
|
||||||
sc.idx = -1;
|
|
||||||
sc.cwd = args_get(args, 'c');
|
|
||||||
|
|
||||||
sc.flags = SPAWN_RESPAWN;
|
|
||||||
if (args_has(args, 'k'))
|
|
||||||
sc.flags |= SPAWN_KILL;
|
|
||||||
|
|
||||||
if (spawn_pane(&sc, &cause) == NULL) {
|
|
||||||
cmdq_error(item, "respawn pane failed: %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
wp->flags |= PANE_REDRAW;
|
|
||||||
server_status_window(wp->window);
|
|
||||||
|
|
||||||
environ_free(sc.environ);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-respawn-window.c,v 1.25 2009-12-04 22:14:47 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,8 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -27,66 +26,70 @@
|
|||||||
* 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, "k",
|
||||||
.args = { "c:e:kt:", 0, -1 },
|
cmd_target_init,
|
||||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
cmd_target_parse,
|
||||||
CMD_TARGET_WINDOW_USAGE " [command]",
|
cmd_respawn_window_exec,
|
||||||
|
cmd_target_free,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
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 spawn_context sc;
|
struct winlink *wl;
|
||||||
struct session *s = item->target.s;
|
struct window *w;
|
||||||
struct winlink *wl = item->target.wl;
|
struct window_pane *wp;
|
||||||
char *cause = NULL;
|
struct session *s;
|
||||||
const char *add;
|
struct environ env;
|
||||||
struct args_value *value;
|
char *cause;
|
||||||
|
|
||||||
memset(&sc, 0, sizeof sc);
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
sc.item = item;
|
return (-1);
|
||||||
sc.s = s;
|
w = wl->window;
|
||||||
sc.wl = wl;
|
|
||||||
sc.c = cmd_find_client(item, NULL, 1);
|
|
||||||
|
|
||||||
sc.name = NULL;
|
if (!cmd_check_flag(data->chflags, 'k')) {
|
||||||
sc.argc = args->argc;
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
sc.argv = args->argv;
|
if (wp->fd == -1)
|
||||||
sc.environ = environ_create();
|
continue;
|
||||||
|
ctx->error(ctx,
|
||||||
add = args_first_value(args, 'e', &value);
|
"window still active: %s:%d", s->name, wl->idx);
|
||||||
while (add != NULL) {
|
return (-1);
|
||||||
environ_put(sc.environ, add);
|
}
|
||||||
add = args_next_value(&value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.idx = -1;
|
environ_init(&env);
|
||||||
sc.cwd = args_get(args, 'c');
|
environ_copy(&global_environ, &env);
|
||||||
|
environ_copy(&s->environ, &env);
|
||||||
|
server_fill_environ(s, &env);
|
||||||
|
|
||||||
sc.flags = SPAWN_RESPAWN;
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
if (args_has(args, 'k'))
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
sc.flags |= SPAWN_KILL;
|
layout_free(w);
|
||||||
|
window_destroy_panes(w);
|
||||||
if (spawn_window(&sc, &cause) == NULL) {
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
cmdq_error(item, "respawn window failed: %s", cause);
|
window_pane_resize(wp, w->sx, w->sy);
|
||||||
free(cause);
|
if (window_pane_spawn(
|
||||||
return (CMD_RETURN_ERROR);
|
wp, data->arg, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
environ_free(&env);
|
||||||
|
server_destroy_pane(wp);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
layout_init(w);
|
||||||
|
screen_reinit(&wp->base);
|
||||||
|
window_set_active_pane(w, wp);
|
||||||
|
|
||||||
server_redraw_window(wl->window);
|
recalculate_sizes();
|
||||||
|
server_redraw_window(w);
|
||||||
|
|
||||||
environ_free(sc.environ);
|
environ_free(&env);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-rotate-window.c,v 1.10 2009-11-14 17:56:39 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, "DU",
|
||||||
.args = { "Dt:UZ", 0, 0 },
|
cmd_rotate_window_init,
|
||||||
.usage = "[-DUZ] " 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))
|
||||||
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct 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;
|
||||||
|
|
||||||
window_push_zoom(w, args_has(self->args, 'Z'));
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
if (args_has(self->args, 'D')) {
|
if (cmd_check_flag(data->chflags, 'D')) {
|
||||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
@@ -77,6 +89,8 @@ 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);
|
||||||
|
server_redraw_window(w);
|
||||||
} else {
|
} else {
|
||||||
wp = TAILQ_FIRST(&w->panes);
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
@@ -102,12 +116,9 @@ 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);
|
||||||
|
server_redraw_window(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
window_set_active_pane(w, wp, 1);
|
return (0);
|
||||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
|
||||||
window_pop_zoom(w);
|
|
||||||
server_redraw_window(w);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
172
cmd-run-shell.c
172
cmd-run-shell.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-run-shell.c,v 1.9 2010-08-09 21:44:25 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -29,140 +28,117 @@
|
|||||||
* Runs a command without a window.
|
* Runs a command without a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmdq_item *);
|
int cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static void cmd_run_shell_callback(struct job *);
|
void cmd_run_shell_callback(struct job *);
|
||||||
static void cmd_run_shell_free(void *);
|
void cmd_run_shell_free(void *);
|
||||||
static void cmd_run_shell_print(struct job *, const char *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_run_shell_entry = {
|
const struct cmd_entry cmd_run_shell_entry = {
|
||||||
.name = "run-shell",
|
"run-shell", "run",
|
||||||
.alias = "run",
|
"command",
|
||||||
|
CMD_ARG1, "",
|
||||||
.args = { "bt:", 1, 1 },
|
cmd_target_init,
|
||||||
.usage = "[-b] " CMD_TARGET_PANE_USAGE " shell-command",
|
cmd_target_parse,
|
||||||
|
cmd_run_shell_exec,
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_run_shell_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_run_shell_data {
|
struct cmd_run_shell_data {
|
||||||
char *cmd;
|
char *cmd;
|
||||||
struct cmdq_item *item;
|
struct cmd_ctx ctx;
|
||||||
int wp_id;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
int
|
||||||
cmd_run_shell_print(struct job *job, const char *msg)
|
cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct cmd_run_shell_data *cdata = job_get_data(job);
|
struct cmd_target_data *data = self->data;
|
||||||
struct window_pane *wp = NULL;
|
|
||||||
struct cmd_find_state fs;
|
|
||||||
struct window_mode_entry *wme;
|
|
||||||
|
|
||||||
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) != 0)
|
|
||||||
return;
|
|
||||||
wp = fs.wp;
|
|
||||||
if (wp == NULL)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wme = TAILQ_FIRST(&wp->modes);
|
|
||||||
if (wme == NULL || wme->mode != &window_view_mode)
|
|
||||||
window_pane_set_mode(wp, &window_view_mode, NULL, NULL);
|
|
||||||
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 cmd_run_shell_data *cdata;
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
struct job *job;
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
cdata = xmalloc(sizeof *cdata);
|
||||||
cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp);
|
cdata->cmd = xstrdup(data->arg);
|
||||||
|
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||||
|
|
||||||
if (args_has(args, 't') && wp != NULL)
|
if (ctx->cmdclient != NULL)
|
||||||
cdata->wp_id = wp->id;
|
ctx->cmdclient->references++;
|
||||||
else
|
if (ctx->curclient != NULL)
|
||||||
cdata->wp_id = -1;
|
ctx->curclient->references++;
|
||||||
|
|
||||||
if (!args_has(args, 'b'))
|
job = job_add(NULL, 0, NULL,
|
||||||
cdata->item = item;
|
data->arg, cmd_run_shell_callback, cmd_run_shell_free, cdata);
|
||||||
|
job_run(job);
|
||||||
|
|
||||||
if (job_run(cdata->cmd, s, server_client_get_cwd(item->client, s), NULL,
|
return (1); /* don't let client exit */
|
||||||
cmd_run_shell_callback, cmd_run_shell_free, cdata, 0) == NULL) {
|
|
||||||
cmdq_error(item, "failed to run command: %s", cdata->cmd);
|
|
||||||
free(cdata);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'b'))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_run_shell_callback(struct job *job)
|
cmd_run_shell_callback(struct job *job)
|
||||||
{
|
{
|
||||||
struct cmd_run_shell_data *cdata = job_get_data(job);
|
struct cmd_run_shell_data *cdata = job->data;
|
||||||
struct bufferevent *event = job_get_event(job);
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
char *cmd = cdata->cmd, *msg = NULL, *line;
|
char *cmd, *msg, *line;
|
||||||
size_t size;
|
size_t size;
|
||||||
int retcode, status;
|
int retcode;
|
||||||
|
u_int lines;
|
||||||
|
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
if (ctx->curclient != NULL && ctx->curclient->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lines = 0;
|
||||||
do {
|
do {
|
||||||
if ((line = evbuffer_readline(event->input)) != NULL) {
|
if ((line = evbuffer_readline(job->event->input)) != NULL) {
|
||||||
cmd_run_shell_print(job, line);
|
ctx->print(ctx, "%s", line);
|
||||||
free(line);
|
lines++;
|
||||||
}
|
}
|
||||||
} while (line != NULL);
|
} while (line != NULL);
|
||||||
|
|
||||||
size = EVBUFFER_LENGTH(event->input);
|
size = EVBUFFER_LENGTH(job->event->input);
|
||||||
if (size != 0) {
|
if (size != 0) {
|
||||||
line = xmalloc(size + 1);
|
line = xmalloc(size + 1);
|
||||||
memcpy(line, EVBUFFER_DATA(event->input), size);
|
memcpy(line, EVBUFFER_DATA(job->event->input), size);
|
||||||
line[size] = '\0';
|
line[size] = '\0';
|
||||||
|
|
||||||
cmd_run_shell_print(job, line);
|
ctx->print(ctx, "%s", line);
|
||||||
|
lines++;
|
||||||
|
|
||||||
free(line);
|
xfree(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = job_get_status(job);
|
cmd = cdata->cmd;
|
||||||
if (WIFEXITED(status)) {
|
|
||||||
if ((retcode = WEXITSTATUS(status)) != 0)
|
msg = NULL;
|
||||||
|
if (WIFEXITED(job->status)) {
|
||||||
|
if ((retcode = WEXITSTATUS(job->status)) != 0)
|
||||||
xasprintf(&msg, "'%s' returned %d", cmd, retcode);
|
xasprintf(&msg, "'%s' returned %d", cmd, retcode);
|
||||||
} else if (WIFSIGNALED(status)) {
|
} else if (WIFSIGNALED(job->status)) {
|
||||||
retcode = WTERMSIG(status);
|
retcode = WTERMSIG(job->status);
|
||||||
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
||||||
}
|
}
|
||||||
if (msg != NULL)
|
if (msg != NULL) {
|
||||||
cmd_run_shell_print(job, msg);
|
if (lines != 0)
|
||||||
free(msg);
|
ctx->print(ctx, "%s", msg);
|
||||||
|
else
|
||||||
if (cdata->item != NULL)
|
ctx->info(ctx, "%s", msg);
|
||||||
cmdq_continue(cdata->item);
|
xfree(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_run_shell_free(void *data)
|
cmd_run_shell_free(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_run_shell_data *cdata = data;
|
struct cmd_run_shell_data *cdata = data;
|
||||||
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
|
||||||
free(cdata->cmd);
|
if (ctx->cmdclient != NULL) {
|
||||||
free(cdata);
|
ctx->cmdclient->references--;
|
||||||
|
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||||
|
}
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references--;
|
||||||
|
|
||||||
|
xfree(cdata->cmd);
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-save-buffer.c,v 1.12 2010-08-09 21:44:25 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -20,94 +20,76 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Saves a paste buffer to a file.
|
* Saves a session paste buffer to a file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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, "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 void
|
|
||||||
cmd_save_buffer_done(__unused struct client *c, const char *path, int error,
|
|
||||||
__unused int closed, __unused struct evbuffer *buffer, void *data)
|
|
||||||
{
|
{
|
||||||
struct cmdq_item *item = data;
|
struct cmd_buffer_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
if (!closed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
cmdq_error(item, "%s: %s", path, strerror(error));
|
|
||||||
cmdq_continue(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = self->args;
|
|
||||||
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;
|
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
int flags;
|
mode_t mask;
|
||||||
const char *bufname = args_get(args, 'b'), *bufdata;
|
FILE *f;
|
||||||
size_t bufsize;
|
|
||||||
char *path;
|
|
||||||
|
|
||||||
if (bufname == NULL) {
|
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 {
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bufdata = paste_buffer_data(pb, &bufsize);
|
|
||||||
|
|
||||||
if (self->entry == &cmd_show_buffer_entry)
|
if (strcmp(data->arg, "-") == 0) {
|
||||||
path = xstrdup("-");
|
if (ctx->cmdclient == NULL) {
|
||||||
else
|
ctx->error(ctx, "%s: can't write to stdout", data->arg);
|
||||||
path = format_single(item, args->argv[0], c, s, wl, wp);
|
return (-1);
|
||||||
if (args_has(self->args, 'a'))
|
}
|
||||||
flags = O_APPEND;
|
bufferevent_write(
|
||||||
else
|
ctx->cmdclient->stdout_event, pb->data, pb->size);
|
||||||
flags = 0;
|
} else {
|
||||||
file_write(item->client, path, flags, bufdata, bufsize,
|
mask = umask(S_IRWXG | S_IRWXO);
|
||||||
cmd_save_buffer_done, item);
|
if (cmd_check_flag(data->chflags, 'a'))
|
||||||
free(path);
|
f = fopen(data->arg, "ab");
|
||||||
|
else
|
||||||
|
f = fopen(data->arg, "wb");
|
||||||
|
umask(mask);
|
||||||
|
if (f == NULL) {
|
||||||
|
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
|
||||||
|
ctx->error(ctx, "%s: fwrite error", data->arg);
|
||||||
|
fclose(f);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_WAIT);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-select-layout.c,v 1.12 2010-07-02 02:54:52 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,130 +18,77 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Switch window to selected layout.
|
* Switch window to selected layout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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, "",
|
||||||
.args = { "Enopt:", 0, 1 },
|
cmd_select_layout_init,
|
||||||
.usage = "[-Enop] " CMD_TARGET_PANE_USAGE " [layout-name]",
|
cmd_target_parse,
|
||||||
|
cmd_select_layout_exec,
|
||||||
.target = { 't', CMD_FIND_PANE, 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 = wl->window;
|
|
||||||
struct window_pane *wp = item->target.wp;
|
|
||||||
const char *layoutname;
|
|
||||||
char *oldlayout;
|
|
||||||
int next, previous, layout;
|
|
||||||
|
|
||||||
server_unzoom_window(w);
|
cmd_target_init(self, key);
|
||||||
|
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
|
case ('5' | KEYC_ESCAPE):
|
||||||
layout_set_previous(w);
|
data->arg = xstrdup("tiled");
|
||||||
goto changed;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (args_has(args, 'E')) {
|
|
||||||
layout_spread_out(wp);
|
int
|
||||||
goto changed;
|
cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
}
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
if (!args_has(args, 'o')) {
|
struct winlink *wl;
|
||||||
if (args->argc == 0)
|
int layout;
|
||||||
layout = w->lastlayout;
|
|
||||||
else
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||||
layout = layout_set_lookup(args->argv[0]);
|
return (-1);
|
||||||
if (layout != -1) {
|
|
||||||
layout_set_select(w, layout);
|
if (data->arg == NULL) {
|
||||||
goto changed;
|
layout = wl->window->lastlayout;
|
||||||
}
|
if (layout == -1)
|
||||||
}
|
return (0);
|
||||||
|
} else if ((layout = layout_set_lookup(data->arg)) != -1) {
|
||||||
if (args->argc != 0)
|
layout = layout_set_select(wl->window, layout);
|
||||||
layoutname = args->argv[0];
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
else if (args_has(args, 'o'))
|
} else {
|
||||||
layoutname = oldlayout;
|
if (layout_parse(wl->window, data->arg) == -1) {
|
||||||
else
|
ctx->error(ctx, "can't set layout: %s", data->arg);
|
||||||
layoutname = NULL;
|
return (-1);
|
||||||
|
}
|
||||||
if (layoutname != NULL) {
|
ctx->info(ctx, "arranging in: %s", data->arg);
|
||||||
if (layout_parse(w, layoutname) == -1) {
|
}
|
||||||
cmdq_error(item, "can't set layout: %s", layoutname);
|
|
||||||
goto error;
|
return (0);
|
||||||
}
|
|
||||||
goto changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(oldlayout);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
changed:
|
|
||||||
free(oldlayout);
|
|
||||||
recalculate_sizes();
|
|
||||||
server_redraw_window(w);
|
|
||||||
notify_window("window-layout-changed", 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.13 2010-03-15 22:03:38 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
|
||||||
@@ -18,203 +18,77 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Select pane.
|
* Select pane.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmdq_item *);
|
void cmd_select_pane_init(struct cmd *, int);
|
||||||
|
int cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_select_pane_entry = {
|
const struct cmd_entry cmd_select_pane_entry = {
|
||||||
.name = "select-pane",
|
"select-pane", "selectp",
|
||||||
.alias = "selectp",
|
"[-DLRU] " CMD_TARGET_PANE_USAGE,
|
||||||
|
0, "DLRU",
|
||||||
.args = { "DdegLlMmP:RT:t:UZ", 0, 0 }, /* -P and -g deprecated */
|
cmd_select_pane_init,
|
||||||
.usage = "[-DdeLlMmRUZ] [-T title] " 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 = {
|
void
|
||||||
.name = "last-pane",
|
cmd_select_pane_init(struct cmd *self, int key)
|
||||||
.alias = "lastp",
|
|
||||||
|
|
||||||
.args = { "det:Z", 0, 0 },
|
|
||||||
.usage = "[-deZ] " CMD_TARGET_WINDOW_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_pane_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_select_pane_redraw(struct window *w)
|
|
||||||
{
|
{
|
||||||
struct client *c;
|
struct cmd_target_data *data;
|
||||||
|
|
||||||
/*
|
cmd_target_init(self, key);
|
||||||
* Redraw entire window if it is bigger than the client (the
|
data = self->data;
|
||||||
* offset may change), otherwise just draw borders.
|
|
||||||
*/
|
|
||||||
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
if (key == KEYC_UP)
|
||||||
if (c->session == NULL || (c->flags & CLIENT_CONTROL))
|
cmd_set_flag(&data->chflags, 'U');
|
||||||
continue;
|
if (key == KEYC_DOWN)
|
||||||
if (c->session->curw->window == w && tty_window_bigger(&c->tty))
|
cmd_set_flag(&data->chflags, 'D');
|
||||||
server_redraw_client(c);
|
if (key == KEYC_LEFT)
|
||||||
else {
|
cmd_set_flag(&data->chflags, 'L');
|
||||||
if (c->session->curw->window == w)
|
if (key == KEYC_RIGHT)
|
||||||
c->flags |= CLIENT_REDRAWBORDERS;
|
cmd_set_flag(&data->chflags, 'R');
|
||||||
if (session_has(c->session, w))
|
if (key == 'o')
|
||||||
c->flags |= CLIENT_REDRAWSTATUS;
|
data->target = xstrdup(":.+");
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_select_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 window_pane *wp;
|
||||||
struct winlink *wl = item->target.wl;
|
|
||||||
struct window *w = wl->window;
|
|
||||||
struct session *s = item->target.s;
|
|
||||||
struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
|
|
||||||
char *pane_title;
|
|
||||||
const char *style;
|
|
||||||
struct style *sy;
|
|
||||||
struct options_entry *o;
|
|
||||||
|
|
||||||
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 && window_count_panes(w) == 2) {
|
|
||||||
lastwp = TAILQ_PREV(w->active, window_panes, entry);
|
if (!window_pane_visible(wp)) {
|
||||||
if (lastwp == NULL)
|
ctx->error(ctx, "pane not visible: %s", data->target);
|
||||||
lastwp = TAILQ_NEXT(w->active, entry);
|
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 {
|
|
||||||
if (window_push_zoom(w, args_has(self->args, 'Z')))
|
|
||||||
server_redraw_window(w);
|
|
||||||
window_redraw_active_switch(w, lastwp);
|
|
||||||
if (window_set_active_pane(w, lastwp, 1)) {
|
|
||||||
cmd_find_from_winlink(current, wl, 0);
|
|
||||||
cmd_select_pane_redraw(w);
|
|
||||||
}
|
|
||||||
if (window_pop_zoom(w))
|
|
||||||
server_redraw_window(w);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'm') || args_has(args, 'M')) {
|
if (cmd_check_flag(data->chflags, 'L'))
|
||||||
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 ((style = args_get(args, 'P')) != NULL) {
|
|
||||||
o = options_set_style(wp->options, "window-style", 0,
|
|
||||||
style);
|
|
||||||
if (o == NULL) {
|
|
||||||
cmdq_error(item, "bad style: %s", style);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
options_set_style(wp->options, "window-active-style", 0,
|
|
||||||
style);
|
|
||||||
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
|
||||||
}
|
|
||||||
if (args_has(self->args, 'g')) {
|
|
||||||
sy = options_get_style(wp->options, "window-style");
|
|
||||||
cmdq_print(item, "%s", style_tostring(sy));
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(self->args, 'L')) {
|
|
||||||
window_push_zoom(w, 1);
|
|
||||||
wp = window_pane_find_left(wp);
|
wp = window_pane_find_left(wp);
|
||||||
window_pop_zoom(w);
|
else if (cmd_check_flag(data->chflags, 'R'))
|
||||||
} else if (args_has(self->args, 'R')) {
|
|
||||||
window_push_zoom(w, 1);
|
|
||||||
wp = window_pane_find_right(wp);
|
wp = window_pane_find_right(wp);
|
||||||
window_pop_zoom(w);
|
else if (cmd_check_flag(data->chflags, 'U'))
|
||||||
} else if (args_has(self->args, 'U')) {
|
|
||||||
window_push_zoom(w, 1);
|
|
||||||
wp = window_pane_find_up(wp);
|
wp = window_pane_find_up(wp);
|
||||||
window_pop_zoom(w);
|
else if (cmd_check_flag(data->chflags, 'D'))
|
||||||
} else if (args_has(self->args, 'D')) {
|
|
||||||
window_push_zoom(w, 1);
|
|
||||||
wp = window_pane_find_down(wp);
|
wp = window_pane_find_down(wp);
|
||||||
window_pop_zoom(w);
|
if (wp == NULL) {
|
||||||
}
|
ctx->error(ctx, "pane not found");
|
||||||
if (wp == NULL)
|
return (-1);
|
||||||
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 (args_has(self->args, 'T')) {
|
window_set_active_pane(wl->window, wp);
|
||||||
pane_title = format_single(item, args_get(self->args, 'T'),
|
server_status_window(wl->window);
|
||||||
c, s, wl, wp);
|
server_redraw_window_borders(wl->window);
|
||||||
if (screen_set_title(&wp->base, pane_title))
|
|
||||||
server_status_window(wp->window);
|
|
||||||
free(pane_title);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wp == w->active)
|
return (0);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
if (window_push_zoom(w, args_has(self->args, 'Z')))
|
|
||||||
server_redraw_window(w);
|
|
||||||
window_redraw_active_switch(w, wp);
|
|
||||||
if (window_set_active_pane(w, wp, 1)) {
|
|
||||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
|
||||||
cmdq_insert_hook(s, item, current, "after-select-pane");
|
|
||||||
cmd_select_pane_redraw(w);
|
|
||||||
}
|
|
||||||
if (window_pop_zoom(w))
|
|
||||||
server_redraw_window(w);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-select-window.c,v 1.24 2009-11-14 17:56:39 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,120 +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, "",
|
||||||
.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(current, s, 0);
|
|
||||||
server_redraw_session(s);
|
server_redraw_session(s);
|
||||||
cmdq_insert_hook(s, item, current, "after-select-window");
|
|
||||||
} 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, 0);
|
|
||||||
server_redraw_session(s);
|
|
||||||
} else if (session_select(s, wl->idx) == 0) {
|
|
||||||
cmd_find_from_session(current, s, 0);
|
|
||||||
server_redraw_session(s);
|
|
||||||
}
|
|
||||||
cmdq_insert_hook(s, item, current, "after-select-window");
|
|
||||||
}
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
271
cmd-send-keys.c
271
cmd-send-keys.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-send-keys.c,v 1.25 2010-05-22 21:56:04 micahcowan 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,178 +26,128 @@
|
|||||||
* 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;
|
||||||
|
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, "",
|
||||||
.args = { "FHlMN:Rt:X", 0, -1 },
|
NULL,
|
||||||
.usage = "[-FHlMRX] [-N repeat-count] " CMD_TARGET_PANE_USAGE
|
cmd_send_keys_parse,
|
||||||
" key ...",
|
cmd_send_keys_exec,
|
||||||
|
cmd_send_keys_free,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
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 struct cmdq_item *
|
|
||||||
cmd_send_keys_inject_key(struct client *c, struct cmd_find_state *fs,
|
|
||||||
struct cmdq_item *item, key_code key)
|
|
||||||
{
|
{
|
||||||
struct session *s = fs->s;
|
struct cmd_send_keys_data *data;
|
||||||
struct winlink *wl = fs->wl;
|
int opt, key;
|
||||||
struct window_pane *wp = fs->wp;
|
char *s;
|
||||||
struct window_mode_entry *wme;
|
|
||||||
struct key_table *table;
|
|
||||||
struct key_binding *bd;
|
|
||||||
|
|
||||||
wme = TAILQ_FIRST(&fs->wp->modes);
|
self->data = data = xmalloc(sizeof *data);
|
||||||
if (wme == NULL || wme->mode->key_table == NULL) {
|
data->target = NULL;
|
||||||
if (options_get_number(fs->wp->window->options, "xterm-keys"))
|
data->nkeys = 0;
|
||||||
key |= KEYC_XTERM;
|
data->keys = NULL;
|
||||||
if (window_pane_key(wp, item->client, s, wl, key, NULL) != 0)
|
|
||||||
return (NULL);
|
|
||||||
return (item);
|
|
||||||
}
|
|
||||||
table = key_bindings_get_table(wme->mode->key_table(wme), 1);
|
|
||||||
|
|
||||||
bd = key_bindings_get(table, key & ~KEYC_XTERM);
|
while ((opt = getopt(argc, argv, "t:")) != -1) {
|
||||||
if (bd != NULL) {
|
switch (opt) {
|
||||||
table->references++;
|
case 't':
|
||||||
item = key_bindings_dispatch(bd, item, c, NULL, &item->target);
|
if (data->target == NULL)
|
||||||
key_bindings_unref_table(table);
|
data->target = xstrdup(optarg);
|
||||||
}
|
break;
|
||||||
return (item);
|
default:
|
||||||
}
|
goto usage;
|
||||||
|
|
||||||
static struct cmdq_item *
|
|
||||||
cmd_send_keys_inject_string(struct client *c, struct cmd_find_state *fs,
|
|
||||||
struct cmdq_item *item, struct args *args, int i)
|
|
||||||
{
|
|
||||||
const char *s = args->argv[i];
|
|
||||||
struct cmdq_item *new_item;
|
|
||||||
struct utf8_data *ud, *uc;
|
|
||||||
wchar_t wc;
|
|
||||||
key_code key;
|
|
||||||
char *endptr;
|
|
||||||
long n;
|
|
||||||
int literal;
|
|
||||||
|
|
||||||
if (args_has(args, 'H')) {
|
|
||||||
n = strtol(s, &endptr, 16);
|
|
||||||
if (*s =='\0' || n < 0 || n > 0xff || *endptr != '\0')
|
|
||||||
return (item);
|
|
||||||
return (cmd_send_keys_inject_key(c, fs, item, KEYC_LITERAL|n));
|
|
||||||
}
|
|
||||||
|
|
||||||
literal = args_has(args, 'l');
|
|
||||||
if (!literal) {
|
|
||||||
key = key_string_lookup_string(s);
|
|
||||||
if (key != KEYC_NONE && key != KEYC_UNKNOWN) {
|
|
||||||
new_item = cmd_send_keys_inject_key(c, fs, item, key);
|
|
||||||
if (new_item != NULL)
|
|
||||||
return (new_item);
|
|
||||||
}
|
}
|
||||||
literal = 1;
|
|
||||||
}
|
}
|
||||||
if (literal) {
|
argc -= optind;
|
||||||
ud = utf8_fromcstr(s);
|
argv += optind;
|
||||||
for (uc = ud; uc->size != 0; uc++) {
|
if (argc == 0)
|
||||||
if (utf8_combine(uc, &wc) != UTF8_DONE)
|
goto usage;
|
||||||
continue;
|
|
||||||
item = cmd_send_keys_inject_key(c, fs, item, wc);
|
|
||||||
}
|
|
||||||
free(ud);
|
|
||||||
}
|
|
||||||
return (item);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
while (argc-- != 0) {
|
||||||
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
if ((key = key_string_lookup_string(*argv)) != KEYC_NONE) {
|
||||||
{
|
data->keys = xrealloc(
|
||||||
struct args *args = self->args;
|
data->keys, data->nkeys + 1, sizeof *data->keys);
|
||||||
struct client *c = cmd_find_client(item, NULL, 1);
|
data->keys[data->nkeys++] = key;
|
||||||
struct cmd_find_state *fs = &item->target;
|
} else {
|
||||||
struct window_pane *wp = item->target.wp;
|
for (s = *argv; *s != '\0'; s++) {
|
||||||
struct session *s = item->target.s;
|
data->keys = xrealloc(data->keys,
|
||||||
struct winlink *wl = item->target.wl;
|
data->nkeys + 1, sizeof *data->keys);
|
||||||
struct mouse_event *m = &item->shared->mouse;
|
data->keys[data->nkeys++] = *s;
|
||||||
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
|
||||||
int i;
|
|
||||||
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 (wme != NULL && (args_has(args, 'X') || args->argc == 0)) {
|
|
||||||
if (wme == NULL || wme->mode->command == NULL) {
|
|
||||||
cmdq_error(item, "not in a mode");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
wme->prefix = np;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'X')) {
|
return (0);
|
||||||
if (wme == NULL || wme->mode->command == NULL) {
|
|
||||||
cmdq_error(item, "not in a mode");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (!m->valid)
|
|
||||||
m = NULL;
|
|
||||||
wme->mode->command(wme, c, s, wl, args, m);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'M')) {
|
usage:
|
||||||
wp = cmd_mouse_pane(m, &s, NULL);
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||||
if (wp == NULL) {
|
|
||||||
cmdq_error(item, "no mouse target");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
window_pane_key(wp, item->client, s, wl, m->key, m);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self->entry == &cmd_send_prefix_entry) {
|
self->entry->free(self);
|
||||||
if (args_has(args, '2'))
|
return (-1);
|
||||||
key = options_get_number(s->options, "prefix2");
|
}
|
||||||
else
|
|
||||||
key = options_get_number(s->options, "prefix");
|
int
|
||||||
cmd_send_keys_inject_key(c, fs, item, key);
|
cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
return (CMD_RETURN_NORMAL);
|
{
|
||||||
}
|
struct cmd_send_keys_data *data = self->data;
|
||||||
|
struct window_pane *wp;
|
||||||
if (args_has(args, 'R')) {
|
struct session *s;
|
||||||
window_pane_reset_palette(wp);
|
u_int i;
|
||||||
input_reset(wp, 1);
|
|
||||||
}
|
if (data == NULL)
|
||||||
|
return (-1);
|
||||||
for (; np != 0; np--) {
|
|
||||||
for (i = 0; i < args->argc; i++)
|
if (cmd_find_pane(ctx, data->target, &s, &wp) == NULL)
|
||||||
item = cmd_send_keys_inject_string(c, fs, item, args, i);
|
return (-1);
|
||||||
}
|
|
||||||
|
for (i = 0; i < data->nkeys; i++)
|
||||||
return (CMD_RETURN_NORMAL);
|
window_pane_key(wp, s, data->keys[i]);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_send_keys_free(struct cmd *self)
|
||||||
|
{
|
||||||
|
struct cmd_send_keys_data *data = self->data;
|
||||||
|
|
||||||
|
if (data->target != NULL)
|
||||||
|
xfree(data->target);
|
||||||
|
xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_send_keys_print(struct cmd *self, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd_send_keys_data *data = self->data;
|
||||||
|
size_t off = 0;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||||
|
if (data == NULL)
|
||||||
|
return (off);
|
||||||
|
if (off < len && data->target != NULL)
|
||||||
|
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||||
|
|
||||||
|
for (i = 0; i < data->nkeys; i++) {
|
||||||
|
if (off >= len)
|
||||||
|
break;
|
||||||
|
off += xsnprintf(buf + off,
|
||||||
|
len - off, " %s", key_string_lookup_key(data->keys[i]));
|
||||||
|
}
|
||||||
|
return (off);
|
||||||
}
|
}
|
||||||
|
|||||||
55
cmd-send-prefix.c
Normal file
55
cmd-send-prefix.c
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/* $Id: cmd-send-prefix.c,v 1.29 2010-05-22 21:56:04 micahcowan Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send prefix key as a key.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_send_prefix_entry = {
|
||||||
|
"send-prefix", NULL,
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0, "",
|
||||||
|
cmd_target_init,
|
||||||
|
cmd_target_parse,
|
||||||
|
cmd_send_prefix_exec,
|
||||||
|
cmd_target_free,
|
||||||
|
cmd_target_print
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_target_data *data = self->data;
|
||||||
|
struct session *s;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct keylist *keylist;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, data->target, &s, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
keylist = options_get_data(&s->options, "prefix");
|
||||||
|
window_pane_key(wp, s, ARRAY_FIRST(keylist));
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
183
cmd-server-info.c
Normal file
183
cmd-server-info.c
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
/* $Id: cmd-server-info.c,v 1.38 2010-12-22 15:36:44 tcunha Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show various information about server.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_server_info_entry = {
|
||||||
|
"server-info", "info",
|
||||||
|
"",
|
||||||
|
0, "",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_server_info_exec,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct tty_term *term;
|
||||||
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct tty_code *code;
|
||||||
|
struct tty_term_code_entry *ent;
|
||||||
|
struct utsname un;
|
||||||
|
struct job *job;
|
||||||
|
struct grid *gd;
|
||||||
|
struct grid_line *gl;
|
||||||
|
u_int i, j, k;
|
||||||
|
char out[80];
|
||||||
|
char *tim;
|
||||||
|
time_t t;
|
||||||
|
u_int lines, ulines;
|
||||||
|
size_t size, usize;
|
||||||
|
|
||||||
|
tim = ctime(&start_time);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
ctx->print(ctx,
|
||||||
|
"tmux " BUILD ", pid %ld, started %s", (long) getpid(), tim);
|
||||||
|
ctx->print(
|
||||||
|
ctx, "socket path %s, debug level %d", socket_path, debug_level);
|
||||||
|
if (uname(&un) == 0) {
|
||||||
|
ctx->print(ctx, "system is %s %s %s %s",
|
||||||
|
un.sysname, un.release, un.version, un.machine);
|
||||||
|
}
|
||||||
|
if (cfg_file != NULL)
|
||||||
|
ctx->print(ctx, "configuration file is %s", cfg_file);
|
||||||
|
else
|
||||||
|
ctx->print(ctx, "configuration file not specified");
|
||||||
|
ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Clients:");
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ctx->print(ctx, "%2d: %s (%d, %d): %s [%ux%u %s] "
|
||||||
|
"[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
|
||||||
|
c->ibuf.fd, c->tty.fd, c->session->name,
|
||||||
|
c->tty.sx, c->tty.sy, c->tty.termname, c->flags,
|
||||||
|
c->tty.flags, c->references);
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Sessions: [%zu/%zu]",
|
||||||
|
sizeof (struct grid_cell), sizeof (struct grid_utf8));
|
||||||
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
|
t = s->creation_time.tv_sec;
|
||||||
|
tim = ctime(&t);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
|
||||||
|
"[flags=0x%x]", s->idx, s->name,
|
||||||
|
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
|
||||||
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
|
w = wl->window;
|
||||||
|
ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
|
||||||
|
"references=%u, last layout=%d]", wl->idx, w->name,
|
||||||
|
w->sx, w->sy, w->flags, w->references,
|
||||||
|
w->lastlayout);
|
||||||
|
j = 0;
|
||||||
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
|
lines = ulines = size = usize = 0;
|
||||||
|
gd = wp->base.grid;
|
||||||
|
for (k = 0; k < gd->hsize + gd->sy; k++) {
|
||||||
|
gl = &gd->linedata[k];
|
||||||
|
if (gl->celldata != NULL) {
|
||||||
|
lines++;
|
||||||
|
size += gl->cellsize *
|
||||||
|
sizeof *gl->celldata;
|
||||||
|
}
|
||||||
|
if (gl->utf8data != NULL) {
|
||||||
|
ulines++;
|
||||||
|
usize += gl->utf8size *
|
||||||
|
sizeof *gl->utf8data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
|
||||||
|
"bytes; UTF-8 %u/%u, %zu bytes", j,
|
||||||
|
wp->tty, (u_long) wp->pid, wp->fd, lines,
|
||||||
|
gd->hsize + gd->sy, size, ulines,
|
||||||
|
gd->hsize + gd->sy, usize);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Terminals:");
|
||||||
|
SLIST_FOREACH(term, &tty_terms, entry) {
|
||||||
|
ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
|
||||||
|
term->name, term->references, term->flags);
|
||||||
|
for (i = 0; i < NTTYCODE; i++) {
|
||||||
|
ent = &tty_term_codes[i];
|
||||||
|
code = &term->codes[ent->code];
|
||||||
|
switch (code->type) {
|
||||||
|
case TTYCODE_NONE:
|
||||||
|
ctx->print(ctx, "%2u: %s: [missing]",
|
||||||
|
ent->code, ent->name);
|
||||||
|
break;
|
||||||
|
case TTYCODE_STRING:
|
||||||
|
strnvis(out, code->value.string, sizeof out,
|
||||||
|
VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||||
|
ctx->print(ctx, "%2u: %s: (string) %s",
|
||||||
|
ent->code, ent->name, out);
|
||||||
|
break;
|
||||||
|
case TTYCODE_NUMBER:
|
||||||
|
ctx->print(ctx, "%2u: %s: (number) %d",
|
||||||
|
ent->code, ent->name, code->value.number);
|
||||||
|
break;
|
||||||
|
case TTYCODE_FLAG:
|
||||||
|
ctx->print(ctx, "%2u: %s: (flag) %s",
|
||||||
|
ent->code, ent->name,
|
||||||
|
code->value.flag ? "true" : "false");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Jobs:");
|
||||||
|
SLIST_FOREACH(job, &all_jobs, lentry) {
|
||||||
|
ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d, flags=0x%x]",
|
||||||
|
job->cmd, job->fd, job->pid, job->status, job->flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
121
cmd-set-buffer.c
121
cmd-set-buffer.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id: cmd-set-buffer.c,v 1.12 2009-11-28 14:54:12 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, "",
|
||||||
.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;
|
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user