mirror of
https://github.com/tmux/tmux.git
synced 2026-03-11 19:15:45 +00:00
Compare commits
1 Commits
ta/kitty-i
...
0.9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc2b811476 |
84
.github/CONTRIBUTING.md
vendored
84
.github/CONTRIBUTING.md
vendored
@@ -1,84 +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, macOS, 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). Please attach logs to the issue directly rather
|
||||
than using a download site or pastebin. Put in a zip file if necessary.
|
||||
|
||||
- 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.
|
||||
|
||||
## What does it mean if an issue is closed?
|
||||
|
||||
All it means is that work on the issue is not planned for the near future. See
|
||||
the issue's comments to find out if contributions would be welcome.
|
||||
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,2 +0,0 @@
|
||||
github: nicm
|
||||
liberapay: tmux
|
||||
1
.github/ISSUE_TEMPLATE/config.yml
vendored
1
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1 +0,0 @@
|
||||
blank_issues_enabled: false
|
||||
@@ -1,33 +0,0 @@
|
||||
---
|
||||
name: Use this issue template
|
||||
about: Please read https://github.com/tmux/tmux/blob/master/.github/CONTRIBUTING.md
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### 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. These are **required**. Note that bug reports without logs may be ignored or closed without comment.
|
||||
|
||||
* tmux version (`tmux -V`).
|
||||
* Platform (`uname -sp`).
|
||||
* Terminal in use (xterm, rxvt, etc).
|
||||
* $TERM *inside* tmux (`echo $TERM`).
|
||||
* $TERM *outside* tmux (`echo $TERM`).
|
||||
* Logs from tmux (`tmux kill-server; tmux -vv new`).
|
||||
95
.github/README.md
vendored
95
.github/README.md
vendored
@@ -1,95 +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, macOS 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/).
|
||||
|
||||
To build tmux, a C compiler (for example gcc or clang), make, pkg-config and a
|
||||
suitable yacc (yacc or bison) are needed.
|
||||
|
||||
## Installation
|
||||
|
||||
### Binary packages
|
||||
|
||||
Some platforms provide binary packages for tmux, although these are sometimes
|
||||
out of date. Examples are listed on
|
||||
[this page](https://github.com/tmux/tmux/wiki/Installing).
|
||||
|
||||
### 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.
|
||||
|
||||
For more detailed instructions on building and installing tmux, see
|
||||
[this page](https://github.com/tmux/tmux/wiki/Installing).
|
||||
|
||||
### 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/scop/bash-completion/blob/main/completions-core/tmux.bash
|
||||
|
||||
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
|
||||
24
.github/travis/before-install.sh
vendored
24
.github/travis/before-install.sh
vendored
@@ -1,24 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get -y install bison \
|
||||
autotools-dev \
|
||||
libncurses5-dev \
|
||||
libevent-dev \
|
||||
pkg-config \
|
||||
libutempter-dev \
|
||||
build-essential
|
||||
|
||||
if [ "$BUILD" = "musl" -o "$BUILD" = "musl-static" ]; then
|
||||
sudo apt-get -y install musl-dev \
|
||||
musl-tools
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$TRAVIS_OS_NAME" = "freebsd" ]; then
|
||||
sudo pkg install -y \
|
||||
automake \
|
||||
libevent \
|
||||
pkgconf
|
||||
fi
|
||||
38
.github/travis/build-all.sh
vendored
38
.github/travis/build-all.sh
vendored
@@ -1,38 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
BUILD=$PWD/build
|
||||
|
||||
LIBEVENT=https://github.com/libevent/libevent/releases/download/release-2.1.11-stable/libevent-2.1.11-stab\
|
||||
le.tar.gz
|
||||
NCURSES=https://ftp.gnu.org/gnu/ncurses/ncurses-6.2.tar.gz
|
||||
|
||||
wget -4q $LIBEVENT || exit 1
|
||||
tar -zxf libevent-*.tar.gz || exit 1
|
||||
(cd libevent-*/ &&
|
||||
./configure --prefix=$BUILD \
|
||||
--enable-shared \
|
||||
--disable-libevent-regress \
|
||||
--disable-samples &&
|
||||
make && make install) || exit 1
|
||||
|
||||
wget -4q $NCURSES || exit 1
|
||||
tar -zxf ncurses-*.tar.gz || exit 1
|
||||
(cd ncurses-*/ &&
|
||||
CPPFLAGS=-P ./configure --prefix=$BUILD \
|
||||
--with-shared \
|
||||
--with-termlib \
|
||||
--without-ada \
|
||||
--without-cxx \
|
||||
--without-manpages \
|
||||
--without-progs \
|
||||
--without-tests \
|
||||
--without-tack \
|
||||
--disable-database \
|
||||
--enable-termcap \
|
||||
--enable-pc-files \
|
||||
--with-pkg-config-libdir=$BUILD/lib/pkgconfig &&
|
||||
make && make install) || exit 1
|
||||
|
||||
sh autogen.sh || exit 1
|
||||
PKG_CONFIG_PATH=$BUILD/lib/pkgconfig ./configure --prefix=$BUILD "$@"
|
||||
make && make install || (cat config.log; exit 1)
|
||||
25
.github/travis/build.sh
vendored
25
.github/travis/build.sh
vendored
@@ -1,25 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
sh autogen.sh || exit 1
|
||||
case "$BUILD" in
|
||||
static)
|
||||
./configure --enable-static || exit 1
|
||||
exec make
|
||||
;;
|
||||
all)
|
||||
sh $(dirname $0)/build-all.sh
|
||||
exec make
|
||||
;;
|
||||
musl)
|
||||
CC=musl-gcc sh $(dirname $0)/build-all.sh
|
||||
exec make
|
||||
;;
|
||||
musl-static)
|
||||
CC=musl-gcc sh $(dirname $0)/build-all.sh --enable-static
|
||||
exec make
|
||||
;;
|
||||
*)
|
||||
./configure || exit 1
|
||||
exec make
|
||||
;;
|
||||
esac
|
||||
34
.github/workflows/lock.yml
vendored
34
.github/workflows/lock.yml
vendored
@@ -1,34 +0,0 @@
|
||||
name: 'Lock Threads'
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
discussions: write
|
||||
|
||||
concurrency:
|
||||
group: lock-threads
|
||||
|
||||
jobs:
|
||||
action:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v5
|
||||
with:
|
||||
github-token: ${{ github.token }}
|
||||
issue-inactive-days: '30'
|
||||
issue-comment: >
|
||||
This issue has been automatically locked since there
|
||||
has not been any recent activity after it was closed.
|
||||
pr-inactive-days: '60'
|
||||
pr-comment: >
|
||||
This pull request has been automatically locked since there
|
||||
has not been any recent activity after it was closed.
|
||||
discussion-inactive-days: '60'
|
||||
discussion-comment: >
|
||||
This discussion has been automatically locked since there
|
||||
has not been any recent activity after it was closed.
|
||||
24
.gitignore
vendored
24
.gitignore
vendored
@@ -1,24 +0,0 @@
|
||||
*.core
|
||||
*.dSYM
|
||||
*.diff
|
||||
*.o
|
||||
*.patch
|
||||
*.swp
|
||||
*~
|
||||
.deps/
|
||||
.dirstamp
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
autom4te.cache/
|
||||
cmd-parse.c
|
||||
compat/.dirstamp
|
||||
config.log
|
||||
config.status
|
||||
configure
|
||||
core
|
||||
etc/
|
||||
fuzz/*-fuzzer
|
||||
tags
|
||||
tmux
|
||||
tmux.1.*
|
||||
38
.mailmap
38
.mailmap
@@ -1,38 +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.adam22@gmail.com>
|
||||
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>
|
||||
88
.travis.yml
88
.travis.yml
@@ -1,88 +0,0 @@
|
||||
language: c
|
||||
|
||||
os:
|
||||
- linux
|
||||
- freebsd
|
||||
- osx
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
arch:
|
||||
- amd64
|
||||
- arm64
|
||||
|
||||
env:
|
||||
- BUILD=
|
||||
- BUILD=static
|
||||
- BUILD=all
|
||||
- BUILD=musl
|
||||
- BUILD=musl-static
|
||||
|
||||
jobs:
|
||||
exclude:
|
||||
# Static builds are broken on OS X (by Apple)
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
env: BUILD=static
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: BUILD=static
|
||||
# No musl on FreeBSD
|
||||
- os: freebsd
|
||||
compiler: gcc
|
||||
env: BUILD=musl
|
||||
- os: freebsd
|
||||
compiler: clang
|
||||
env: BUILD=musl
|
||||
- os: freebsd
|
||||
compiler: gcc
|
||||
env: BUILD=musl-static
|
||||
- os: freebsd
|
||||
compiler: clang
|
||||
env: BUILD=musl-static
|
||||
# No musl on OS X
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
env: BUILD=musl
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: BUILD=musl
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
env: BUILD=musl-static
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: BUILD=musl-static
|
||||
# arm64 doesn't link ncurses
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
arch: arm64
|
||||
env: BUILD=all
|
||||
- os: linux
|
||||
compiler: clang
|
||||
arch: arm64
|
||||
env: BUILD=all
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
arch: arm64
|
||||
env: BUILD=musl
|
||||
- os: linux
|
||||
compiler: clang
|
||||
arch: arm64
|
||||
env: BUILD=musl
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
arch: arm64
|
||||
env: BUILD=musl-static
|
||||
- os: linux
|
||||
compiler: clang
|
||||
arch: arm64
|
||||
env: BUILD=musl-static
|
||||
|
||||
before_install:
|
||||
- sh .github/travis/before-install.sh
|
||||
|
||||
script:
|
||||
- sh .github/travis/build.sh
|
||||
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.
|
||||
197
FAQ
Normal file
197
FAQ
Normal file
@@ -0,0 +1,197 @@
|
||||
tmux frequently asked questions
|
||||
|
||||
* How is tmux different from GNU screen? What else does it offer?
|
||||
|
||||
tmux offers several advantages over screen:
|
||||
|
||||
- a clearly-defined client-server model: windows are independent entities which
|
||||
may be attached simultaneously to multiple sessions and viewed from multiple
|
||||
clients (terminals), as well as moved freely between sessions within the same
|
||||
tmux server;
|
||||
- a consistent, well-documented command interface, with the same syntax
|
||||
whether used interactively, as a key binding, or from the shell;
|
||||
- easily scriptable from the shell;
|
||||
- multiple paste buffers;
|
||||
- choice of vi or emacs key layouts;
|
||||
- an option to limit the window size;
|
||||
- a more usable status line syntax, with the ability to display the first line
|
||||
of output of a specific command;
|
||||
- a cleaner, modern, easily extended, BSD-licensed codebase.
|
||||
|
||||
There are still a few features screen includes that tmux omits:
|
||||
|
||||
- builtin serial and telnet support; this is bloat and is unlikely to be added
|
||||
to tmux;
|
||||
- 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. 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 termcap inside tmux? It sucks.
|
||||
|
||||
It is already widely available. It is planned to change to something else
|
||||
such as xterm-color at some point, if possible.
|
||||
|
||||
* I don't see any colour in my terminal! Help!
|
||||
|
||||
On some platforms, common termcaps such as xterm do not include colour. screen
|
||||
ignores this, tmux does not. If the terminal emulator in use supports colour,
|
||||
use a termcap 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, two things must be done to
|
||||
enable support. UTF-8 must be turned on in tmux; this may be done separately
|
||||
for each tmux window or globally by setting the "utf8" flag:
|
||||
|
||||
setw -g utf8 on
|
||||
|
||||
As of release 0.9, tmux attempts to autodetect a UTF-8-capable terminal by
|
||||
checking the LC_ALL, LC_CTYPE and LANG environment variables. list-clients may
|
||||
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
|
||||
|
||||
* How do I use a 256 colour terminal?
|
||||
|
||||
tmux will attempt to detect a 256 colour terminal both by looking at the Co
|
||||
termcap entry and, as this is broken for some terminals such as xterm-256color,
|
||||
by looking for the string "256col" in the termcap name.
|
||||
|
||||
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 Co termcap entry. However, this is not reliable, and in any
|
||||
case is missing from the "screen" termcap used inside tmux.
|
||||
|
||||
There are three options 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.
|
||||
- If the platform includes it, using the "screen-256color" termcap (set
|
||||
TERM=screen-256color). "infocmp screen-256color" can be used to check if this
|
||||
is supported. It is not currently possible to set this globally inside tmux
|
||||
but it may be done in a shell startup script by checking if TERM is screen
|
||||
and exporting TERM=screen-256color instead.
|
||||
- Creating a custom terminfo file that includes Co#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.
|
||||
|
||||
* 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.
|
||||
|
||||
* How do I prevent tmux from resizing my PuTTY window?
|
||||
|
||||
This isn't tmux's fault, but happens because the initialisation strings for the
|
||||
terminal in use (set through TERM) request it. PuTTY can be told to ignore such
|
||||
requests: in the configuration window under Terminal -> Features, check the
|
||||
"Disable remote-controlled terminal resizing" box.
|
||||
|
||||
$Id: FAQ,v 1.23 2009-07-01 19:49:56 nicm Exp $
|
||||
57
GNUmakefile
Normal file
57
GNUmakefile
Normal file
@@ -0,0 +1,57 @@
|
||||
# $Id: GNUmakefile,v 1.107 2009-07-01 22:10:06 nicm Exp $
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
VERSION= 0.9
|
||||
|
||||
#FDEBUG= 1
|
||||
|
||||
CC?= gcc
|
||||
CFLAGS+= -DBUILD="\"$(VERSION)\""
|
||||
LDFLAGS+= -L/usr/local/lib
|
||||
LIBS+= -lncurses
|
||||
|
||||
# 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/') || true), )
|
||||
CPPFLAGS:= -I. -I- $(CPPFLAGS)
|
||||
else
|
||||
CPPFLAGS:= -iquote. $(CPPFLAGS)
|
||||
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
|
||||
|
||||
PREFIX?= /usr/local
|
||||
INSTALLDIR= install -d
|
||||
INSTALLBIN= install -g bin -o root -m 555
|
||||
INSTALLMAN= install -g bin -o root -m 444
|
||||
|
||||
SRCS= $(shell echo *.c|sed 's|osdep-[a-z0-9]*.c||g')
|
||||
include config.mk
|
||||
OBJS= $(patsubst %.c,%.o,$(SRCS))
|
||||
|
||||
all: tmux
|
||||
|
||||
tmux: $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o tmux $+ $(LIBS)
|
||||
|
||||
depend: $(SRCS)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -MM $(SRCS) > .depend
|
||||
|
||||
clean:
|
||||
rm -f tmux *.o .depend *~ *.core *.log compat/*.o
|
||||
|
||||
clean-all: clean
|
||||
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
|
||||
62
Makefile
Normal file
62
Makefile
Normal file
@@ -0,0 +1,62 @@
|
||||
# $Id: Makefile,v 1.142 2009-07-01 22:10:06 nicm Exp $
|
||||
|
||||
.SUFFIXES: .c .o
|
||||
.PHONY: clean
|
||||
|
||||
VERSION= 0.9
|
||||
|
||||
#FDEBUG= 1
|
||||
|
||||
CC?= cc
|
||||
CFLAGS+= -DBUILD="\"$(VERSION)\""
|
||||
LDFLAGS+= -L/usr/local/lib
|
||||
LIBS+= -lncurses
|
||||
|
||||
# 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/') || true
|
||||
.if empty(CCV)
|
||||
CPPFLAGS:= -I. -I- -I/usr/local/include ${CPPFLAGS}
|
||||
.else
|
||||
CPPFLAGS:= -iquote. -I/usr/local/include ${CPPFLAGS}
|
||||
.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
|
||||
|
||||
PREFIX?= /usr/local
|
||||
INSTALLDIR= install -d
|
||||
INSTALLBIN= install -g bin -o root -m 555
|
||||
INSTALLMAN= install -g bin -o root -m 444
|
||||
|
||||
SRCS!= echo *.c|sed 's|osdep-[a-z0-9]*.c||g'
|
||||
.include "config.mk"
|
||||
OBJS= ${SRCS:S/.c/.o/}
|
||||
|
||||
.c.o:
|
||||
${CC} ${CPPFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
|
||||
|
||||
all: tmux
|
||||
|
||||
tmux: ${OBJS}
|
||||
${CC} ${LDFLAGS} -o tmux ${OBJS} ${LIBS}
|
||||
|
||||
depend:
|
||||
mkdep ${CPPFLAGS} ${CFLAGS} ${SRCS:M*.c}
|
||||
|
||||
clean:
|
||||
rm -f tmux *.o .depend *~ *.core *.log compat/*.o
|
||||
|
||||
clean-all: clean
|
||||
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/
|
||||
266
Makefile.am
266
Makefile.am
@@ -1,266 +0,0 @@
|
||||
# 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:$$XDG_CONFIG_HOME/tmux/tmux.conf:~/.config/tmux/tmux.conf"' \
|
||||
-DTMUX_LOCK_CMD='"@DEFAULT_LOCK_CMD@"' \
|
||||
-DTMUX_TERM='"@DEFAULT_TERM@"'
|
||||
|
||||
# Additional object files.
|
||||
LDADD = $(LIBOBJS)
|
||||
|
||||
# Set flags for gcc.
|
||||
if IS_GCC
|
||||
AM_CFLAGS += -std=gnu99
|
||||
if IS_OPTIMIZED
|
||||
AM_CFLAGS += -O2
|
||||
else
|
||||
AM_CFLAGS += -O0
|
||||
endif
|
||||
if IS_DEBUG
|
||||
AM_CFLAGS += -g
|
||||
AM_CFLAGS += -Wno-long-long -Wall -W -Wformat=2 -Wno-use-after-free
|
||||
AM_CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
|
||||
AM_CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
||||
AM_CFLAGS += -Wundef -Wbad-function-cast -Winline -Wno-cast-align
|
||||
AM_CFLAGS += -Wdeclaration-after-statement -Wno-pointer-sign -Wno-attributes
|
||||
AM_CFLAGS += -Wno-unused-result -Wno-format-y2k -Wno-unknown-warning-option
|
||||
AM_CFLAGS += -Wno-maybe-uninitialized
|
||||
if IS_DARWIN
|
||||
AM_CFLAGS += -Wno-deprecated-declarations -Wno-macro-redefined
|
||||
endif
|
||||
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
|
||||
|
||||
# Set flags for Haiku.
|
||||
if IS_HAIKU
|
||||
AM_CPPFLAGS += -D_BSD_SOURCE
|
||||
endif
|
||||
|
||||
# Set flags for Cygwin.
|
||||
if IS_CYGWIN
|
||||
AM_CPPFLAGS += -DTMUX_SOCK_PERM=0
|
||||
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-commands.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-server-access.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-show-prompt-history.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-reader.c \
|
||||
grid-view.c \
|
||||
grid.c \
|
||||
hyperlinks.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 \
|
||||
popup.c \
|
||||
proc.c \
|
||||
regsub.c \
|
||||
resize.c \
|
||||
screen-redraw.c \
|
||||
screen-write.c \
|
||||
screen.c \
|
||||
server-acl.c \
|
||||
server-client.c \
|
||||
server-fn.c \
|
||||
server.c \
|
||||
session.c \
|
||||
sort.c \
|
||||
spawn.c \
|
||||
status.c \
|
||||
style.c \
|
||||
tmux.c \
|
||||
tmux.h \
|
||||
tmux-protocol.h \
|
||||
tty-acs.c \
|
||||
tty-draw.c \
|
||||
tty-features.c \
|
||||
tty-keys.c \
|
||||
tty-term.c \
|
||||
tty.c \
|
||||
utf8-combined.c \
|
||||
utf8.c \
|
||||
window-buffer.c \
|
||||
window-client.c \
|
||||
window-clock.c \
|
||||
window-copy.c \
|
||||
window-customize.c \
|
||||
window-tree.c \
|
||||
window.c \
|
||||
xmalloc.c \
|
||||
xmalloc.h
|
||||
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 systemd.
|
||||
if HAVE_SYSTEMD
|
||||
nodist_tmux_SOURCES += compat/systemd.c
|
||||
endif
|
||||
|
||||
# Add compat file for utf8proc.
|
||||
if HAVE_UTF8PROC
|
||||
nodist_tmux_SOURCES += compat/utf8proc.c
|
||||
endif
|
||||
|
||||
# Enable sixel support.
|
||||
if ENABLE_SIXEL_IMAGES
|
||||
dist_tmux_SOURCES += image.c image-sixel.c
|
||||
else
|
||||
# If not sixel, still need image.c for kitty.
|
||||
if ENABLE_KITTY_IMAGES
|
||||
dist_tmux_SOURCES += image.c
|
||||
endif
|
||||
endif
|
||||
|
||||
# Enable kitty graphics protocol support.
|
||||
if ENABLE_KITTY_IMAGES
|
||||
dist_tmux_SOURCES += image-kitty.c
|
||||
endif
|
||||
|
||||
if NEED_FUZZING
|
||||
check_PROGRAMS = fuzz/input-fuzzer
|
||||
fuzz_input_fuzzer_LDFLAGS = $(FUZZING_LIBS)
|
||||
fuzz_input_fuzzer_LDADD = $(LDADD) $(tmux_OBJECTS)
|
||||
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
|
||||
90
NOTES
Normal file
90
NOTES
Normal file
@@ -0,0 +1,90 @@
|
||||
Welcome to tmux!
|
||||
|
||||
tmux is a "terminal multiplexer", it enables a number of terminals (or windows)
|
||||
to be accessed and controlled from a single terminal. tmux is intended to be a
|
||||
simple, modern, BSD-licensed alternative to programs such as GNU screen.
|
||||
|
||||
This 0.9 release runs on OpenBSD, FreeBSD, NetBSD, Linux and OS X and may still
|
||||
run on Solaris and AIX (although they hasn't been tested in a while). It is
|
||||
usable, although there remain a number of missing features and some remaining
|
||||
bugs are expected.
|
||||
|
||||
If upgrading from 0.5, PLEASE NOTE the following configuration file changes: it
|
||||
is now required to pass the -g flag to set-option or set-window-option to set
|
||||
global options; remain-by-default and utf8-default are now gone, use global
|
||||
window options (set-window-option -g) instead.
|
||||
|
||||
tmux consists of a server part and multiple clients. The server is created when
|
||||
required and runs continuously unless killed by the user. Clients access the
|
||||
server through a socket in /tmp. Multiple sessions may be created on a single
|
||||
server and attached to a number of clients. Each session may then have a number
|
||||
of windows and windows may be linked to a number of sessions. Commands are
|
||||
available to create, rename and destroy windows and sessions; to attach and
|
||||
detach sessions from client terminals; to set configuration options; to split
|
||||
windows into several simultaneously displayed panes; and to bind and unbind
|
||||
command keys (invoked preceded by a prefix key, by default ctrl-b). Please see
|
||||
the tmux(1) man page for further information.
|
||||
|
||||
The following is a summary of major features implemented in this version:
|
||||
|
||||
- Basic multiplexing, window switching, attaching and detaching.
|
||||
- Window listing and renaming.
|
||||
- Key binding.
|
||||
- Handling of client terminal resize.
|
||||
- Terminal emulation sufficient to handle most curses applications.
|
||||
- A optional status line (enabled by default).
|
||||
- Window history and copy and paste.
|
||||
- Support for VT100 line drawing characters.
|
||||
- A large command set.
|
||||
- Vertical window splitting and layout.
|
||||
- Automatic server locking on inactivity.
|
||||
- A configuration file.
|
||||
- UTF-8 support.
|
||||
|
||||
And major missing features:
|
||||
|
||||
- No support for programs changing termios(4) settings or other tty(4) ioctls.
|
||||
|
||||
A more extensive, but rough, todo list is included in the TODO file.
|
||||
|
||||
tmux also depends on several features of the client terminal (TERM), if these
|
||||
are missing it may refuse to run, or not behave correctly. Known working are
|
||||
TERM=screen (tmux in screen), xterm, xterm-color and rxvt. Note that TERM=xterm
|
||||
does not support colour on OpenBSD. screen ignores this, tmux does not: use
|
||||
xterm-color or rxvt for colour.
|
||||
|
||||
tmux supports UTF-8. To use it, the utf8 option must be set on each window;
|
||||
this may be turned on for all windows by setting it as a global option, see
|
||||
tmux(1) and the FAQ file. As of 0.9, tmux attempts to autodetect a
|
||||
UTF-8-capable terminal by checking the LC_ALL, LC_CTYPE and LANG environment
|
||||
variables. list-clients may be used to check if this is detected correctly; if
|
||||
not, the -u command-line flag may be specified.
|
||||
|
||||
A Vim syntax file is available in the examples directory. To install it:
|
||||
|
||||
- Drop the file in the syntax directory in your runtimepath (such as
|
||||
~/.vim/syntax/tmux.vim).
|
||||
- Make the filetype recognisable by adding the following to filetype.vim
|
||||
in your runtimepath (~/.vim/filetype.vim):
|
||||
|
||||
augroup filetypedetect
|
||||
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
|
||||
augroup END
|
||||
|
||||
- Switch on syntax highlighting by adding "syntax enable" to your vimrc file.
|
||||
|
||||
For debugging, running tmux with -v or -vv will generate server and client log
|
||||
files in the current directory.
|
||||
|
||||
tmux mailing lists are available; visit:
|
||||
|
||||
https://sourceforge.net/mail/?group_id=200378
|
||||
|
||||
Bug reports, feature suggestions and especially code contributions are most
|
||||
welcome. Please send by email to:
|
||||
|
||||
nicm@users.sf.net
|
||||
|
||||
-- Nicholas Marriott <nicm@users.sf.net>
|
||||
|
||||
$Id: NOTES,v 1.48 2009-07-01 19:49:56 nicm Exp $
|
||||
87
README
87
README
@@ -1,87 +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, macOS 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/
|
||||
|
||||
To build tmux, a C compiler (for example gcc or clang), make, pkg-config and a
|
||||
suitable yacc (yacc or bison) are needed.
|
||||
|
||||
* 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
|
||||
$ sudo make install
|
||||
|
||||
* 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.
|
||||
|
||||
Other documentation is available in the wiki:
|
||||
|
||||
https://github.com/tmux/tmux/wiki
|
||||
|
||||
Also see the tmux FAQ at:
|
||||
|
||||
https://github.com/tmux/tmux/wiki/FAQ
|
||||
|
||||
A bash(1) completion file is at:
|
||||
|
||||
https://github.com/scop/bash-completion/blob/main/completions/tmux
|
||||
|
||||
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、macOS、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/scop/bash-completion/blob/main/completions/tmux
|
||||
|
||||
「-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-obsd".
|
||||
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-obsd" is the version of tmux in OpenBSD base system which provides
|
||||
the basis of the portable tmux version.
|
||||
|
||||
Note: The "tmux-obsd" 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-obsd cloned, as in:
|
||||
|
||||
% cd /some/where/useful
|
||||
% git clone https://github.com/tmux/tmux.git
|
||||
% git clone https://github.com/ThomasAdam/tmux-obsd.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-obsd"
|
||||
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-obsd" repositories for syncing. To do this, we must reference the
|
||||
clone of the "tmux-obsd" repository from the "tmux" repository, as
|
||||
shown by the following command:
|
||||
|
||||
% cd /path/to/tmux
|
||||
% git remote add obsd-tmux file:///path/to/tmux-obsd
|
||||
|
||||
So that now, the remote "obsd-tmux" can be used to reference branches and
|
||||
commits from the "tmux-obsd" 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-obsd" can be found from within
|
||||
"tmux", we have to ensure the "master" branch from "tmux-obsd" is
|
||||
up-to-date first, and then reference that update in "tmux", as in:
|
||||
|
||||
% cd /path/to/tmux-obsd
|
||||
% 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-obsd" by way
|
||||
of the remote name "obsd-tmux", we can now create the master branch from
|
||||
"tmux-obsd" 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-obsd" 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.
|
||||
92
TODO
Normal file
92
TODO
Normal file
@@ -0,0 +1,92 @@
|
||||
- window creation/idle time
|
||||
- could use bsearch all over the place or get rid of smaller tables (clientmsg)
|
||||
- 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
|
||||
- bind non prefix keys
|
||||
- garbage collect window history (100 lines at a time?) if it hasn't been used
|
||||
in $x time (need window creation/use times)
|
||||
- lift SHRT_MAX limits for history?
|
||||
- audit copy/scroll and other modes for problems with very small windows
|
||||
- better mode features: search, back word, forward word, etc
|
||||
- flags to centre screen in window
|
||||
- better terminal emulation (identify, insert mode, some other bits)
|
||||
- audit for leftover/unused code
|
||||
- activity/bell should be per-window not per-link? what if it is cur win in
|
||||
session not being watched?
|
||||
- tidy up window modes
|
||||
- next prev word etc in command prompt; also ^K
|
||||
- many more info() displays for various things
|
||||
- vi half page scroll
|
||||
- backspace should perhaps wrap backwards over newlines which were not moved
|
||||
down by a newline: screen and the OS X terminal does this but xterm and most
|
||||
others do not. this might be hard: a flag for each grid line (top bit of size
|
||||
maybe)? a single flag is insufficient as can't then tell when to /stop/
|
||||
unwrapping
|
||||
- input.c is too complicated. simplify?
|
||||
- use a better termcap internally instead of screen, perhaps xterm
|
||||
- kill all but current pane
|
||||
- fix rxvt cursor fg issue (text under cursor can have non-white fg)
|
||||
- key handling sucks a bit and may need to be reworked
|
||||
- some people find first window being 0 rather than 1 is awkward on the
|
||||
keyboard
|
||||
- client sx/sy should be in tty, then can let the terminal wrap at edge
|
||||
to allow xterm to pick up it should be one line for its c/p
|
||||
- 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
|
||||
- command to run something without a window at all - output to
|
||||
window-more. what for? isnt this the same as doing it w/ splitw/neww now?
|
||||
- would be nice if tmux could be the shell (tmux attach, but hard link to tmux
|
||||
binary as "tmuxsh" or wrapper script?) problems with tty dev permissions
|
||||
- support other mouse modes (highlight etc) and use it in copy mode
|
||||
- set-remain-on-exit is a bit of a hack, some way to do it generically?
|
||||
- set-option should be set-session-option and should be overall global options
|
||||
for stuff like mode keys?
|
||||
also quiet, utf8 and maybe other flags?
|
||||
-g is a bit unexpected in conf file
|
||||
- clear window title on exit
|
||||
- refer to windows by name etc (duplicates? fnmatch?)
|
||||
- the output code (tty.c) could do with optimisation depending on term
|
||||
capibilities
|
||||
- would be nice to be able to use "--" to mark start of command w/ neww etc
|
||||
to avoid quoting
|
||||
|
||||
- goto line and search history in copy/scroll modes
|
||||
- a command to display the status line briefly when it is turned off
|
||||
- clone session command
|
||||
- make command sequences more usable: don't require space after ;, handle
|
||||
errors better
|
||||
- might be nice if attach-session behaved like switch-client inside an
|
||||
existing client
|
||||
- key to switch to copy mode from scroll mode
|
||||
- attach should have a flag to create session if it doesn't exist
|
||||
- layout/split stuff:
|
||||
** NEW layout design:
|
||||
1. finish rewrite manual with tree of layout_cell
|
||||
2. convert automatic layout modes to produce a tree and make
|
||||
them one-off operations
|
||||
3. move any size/position details from window_pane to layout_cell
|
||||
3.5. fix -p/-l on split
|
||||
4. a way to address panes by name ("top-left") and position ("0,0")
|
||||
TO TEST: force-width/height OK, respawn-window, rotate-window OK, break-pane??
|
||||
** rename split-window -> split-pane
|
||||
- fix UTF-8 guesswork on sparc64, improve tty checks
|
||||
- choice and more mode would be better per client than per window?
|
||||
- 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)
|
||||
- close/redirect stderr when popen to child proc for #() in status line
|
||||
- if-shell-command command to run a tmux command if a shell command returns true
|
||||
- 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
|
||||
- does tmux require a exmple conf? where does it go?
|
||||
- there are an awful lot of commands. maybe separate man page for conf
|
||||
file/commands -similar to ssh/ssh_config?
|
||||
- esc seq to set window title should be documented and should set automatic-rename
|
||||
- *** get rid of PANE_HIDDEN -- initially just check for outside window
|
||||
- way to set socket path from config file
|
||||
- the "window with one pane" vs window distinction is weird, eg you can't kill-pane the last pane
|
||||
325
alerts.c
325
alerts.c
@@ -1,325 +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 <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 || s->attached == 0) {
|
||||
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 || s->attached == 0) {
|
||||
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 || s->attached == 0) {
|
||||
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, -1, 1, 0, 0,
|
||||
"%s in current window", type);
|
||||
} else {
|
||||
status_message_set(c, -1, 1, 0, 0,
|
||||
"%s in window %d", type, wl->idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
194
arg.c
Normal file
194
arg.c
Normal file
@@ -0,0 +1,194 @@
|
||||
/* $Id: arg.c,v 1.6 2009-06-25 15:25:45 nicm 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 <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
struct client *arg_lookup_client(const char *);
|
||||
struct session *arg_lookup_session(const char *);
|
||||
|
||||
struct client *
|
||||
arg_lookup_client(const char *name)
|
||||
{
|
||||
struct client *c;
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c != NULL && strcmp(name, c->tty.path) == 0)
|
||||
return (c);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
struct session *
|
||||
arg_lookup_session(const char *name)
|
||||
{
|
||||
struct session *s, *newest = NULL;
|
||||
struct timeval *tv;
|
||||
u_int i;
|
||||
|
||||
tv = NULL;
|
||||
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||
s = ARRAY_ITEM(&sessions, i);
|
||||
if (s == NULL || fnmatch(name, s->name, 0) != 0)
|
||||
continue;
|
||||
|
||||
if (tv == NULL || timercmp(&s->tv, tv, >)) {
|
||||
newest = s;
|
||||
tv = &s->tv;
|
||||
}
|
||||
}
|
||||
|
||||
return (newest);
|
||||
}
|
||||
|
||||
struct client *
|
||||
arg_parse_client(const char *arg)
|
||||
{
|
||||
struct client *c;
|
||||
char *arg2;
|
||||
size_t n;
|
||||
|
||||
if (arg != NULL && (arg[0] != ':' || arg[1] != '\0')) {
|
||||
arg2 = xstrdup(arg);
|
||||
|
||||
/* Trim a trailing : if any from the argument. */
|
||||
n = strlen(arg2);
|
||||
if (n && arg2[n - 1] == ':')
|
||||
arg2[n - 1] = '\0';
|
||||
|
||||
/* Try and look up the client name. */
|
||||
c = arg_lookup_client(arg2);
|
||||
xfree(arg2);
|
||||
return (c);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
struct session *
|
||||
arg_parse_session(const char *arg)
|
||||
{
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
char *arg2;
|
||||
size_t n;
|
||||
|
||||
if (arg != NULL && (arg[0] != ':' || arg[1] != '\0')) {
|
||||
arg2 = xstrdup(arg);
|
||||
|
||||
/* Trim a trailing : if any from the argument. */
|
||||
n = strlen(arg2);
|
||||
if (n && arg2[n - 1] == ':')
|
||||
arg2[n - 1] = '\0';
|
||||
|
||||
/* See if the argument matches a session. */
|
||||
if ((s = arg_lookup_session(arg2)) != NULL) {
|
||||
xfree(arg2);
|
||||
return (s);
|
||||
}
|
||||
|
||||
/* If not try a client. */
|
||||
if ((c = arg_lookup_client(arg2)) != NULL) {
|
||||
xfree(arg2);
|
||||
return (c->session);
|
||||
}
|
||||
|
||||
xfree(arg2);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
arg_parse_window(const char *arg, struct session **s, int *idx)
|
||||
{
|
||||
char *arg2, *ptr;
|
||||
const char *errstr;
|
||||
|
||||
*idx = -1;
|
||||
|
||||
/* Handle no argument or a single :. */
|
||||
if (arg == NULL || (arg[0] == ':' && arg[1] == '\0')) {
|
||||
*s = arg_parse_session(NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find the separator if any. */
|
||||
arg2 = xstrdup(arg);
|
||||
ptr = strrchr(arg2, ':');
|
||||
|
||||
/*
|
||||
* If it is first, this means no session name, so use current session
|
||||
* and try to convert the rest as index.
|
||||
*/
|
||||
if (ptr == arg2) {
|
||||
*idx = strtonum(ptr + 1, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xfree(arg2);
|
||||
return (1);
|
||||
}
|
||||
|
||||
xfree(arg2);
|
||||
*s = arg_parse_session(NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* If missing, try as an index, else look up immediately. */
|
||||
if (ptr == NULL) {
|
||||
*idx = strtonum(arg2, 0, INT_MAX, &errstr);
|
||||
if (errstr == NULL) {
|
||||
/* This is good as an index; use current session. */
|
||||
xfree(arg2);
|
||||
*s = arg_parse_session(NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
*idx = -1;
|
||||
goto lookup;
|
||||
}
|
||||
|
||||
/* If last, strip it and look up as a session. */
|
||||
if (ptr[1] == '\0') {
|
||||
*ptr = '\0';
|
||||
goto lookup;
|
||||
}
|
||||
|
||||
/* Present but not first and not last. Break and convert both. */
|
||||
*ptr = '\0';
|
||||
*idx = strtonum(ptr + 1, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xfree(arg2);
|
||||
return (1);
|
||||
}
|
||||
|
||||
lookup:
|
||||
/* Look up as session. */
|
||||
*s = arg_parse_session(arg2);
|
||||
xfree(arg2);
|
||||
if (*s == NULL)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
1097
arguments.c
1097
arguments.c
File diff suppressed because it is too large
Load Diff
119
array.h
Normal file
119
array.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/* $Id: array.h,v 1.7 2008-09-29 16:58:02 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
|
||||
#define ARRAY_DECL(n, c) \
|
||||
struct n { \
|
||||
c *list; \
|
||||
u_int num; \
|
||||
size_t space; \
|
||||
}
|
||||
|
||||
#define ARRAY_ITEM(a, i) ((a)->list[i])
|
||||
#define ARRAY_ITEMSIZE(a) (sizeof *(a)->list)
|
||||
#define ARRAY_INITIALSPACE(a) (10 * ARRAY_ITEMSIZE(a))
|
||||
|
||||
#define ARRAY_ENSURE(a, n) do { \
|
||||
if (UINT_MAX - (n) < (a)->num) \
|
||||
fatalx("number too big"); \
|
||||
if (SIZE_MAX / ((a)->num + (n)) < ARRAY_ITEMSIZE(a)) \
|
||||
fatalx("size too big"); \
|
||||
if ((a)->space == 0) { \
|
||||
(a)->space = ARRAY_INITIALSPACE(a); \
|
||||
(a)->list = xrealloc((a)->list, 1, (a)->space); \
|
||||
} \
|
||||
while ((a)->space <= ((a)->num + (n)) * ARRAY_ITEMSIZE(a)) { \
|
||||
(a)->list = xrealloc((a)->list, 2, (a)->space); \
|
||||
(a)->space *= 2; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ARRAY_EMPTY(a) ((a) == NULL || (a)->num == 0)
|
||||
#define ARRAY_LENGTH(a) ((a)->num)
|
||||
#define ARRAY_DATA(a) ((a)->list)
|
||||
|
||||
#define ARRAY_FIRST(a) ARRAY_ITEM(a, 0)
|
||||
#define ARRAY_LAST(a) ARRAY_ITEM(a, (a)->num - 1)
|
||||
|
||||
#define ARRAY_INIT(a) do { \
|
||||
(a)->num = 0; \
|
||||
(a)->list = NULL; \
|
||||
(a)->space = 0; \
|
||||
} while (0)
|
||||
#define ARRAY_CLEAR(a) do { \
|
||||
(a)->num = 0; \
|
||||
} while (0)
|
||||
|
||||
#define ARRAY_SET(a, i, s) do { \
|
||||
(a)->list[i] = s; \
|
||||
} while (0)
|
||||
|
||||
#define ARRAY_ADD(a, s) do { \
|
||||
ARRAY_ENSURE(a, 1); \
|
||||
(a)->list[(a)->num] = s; \
|
||||
(a)->num++; \
|
||||
} while (0)
|
||||
#define ARRAY_INSERT(a, i, s) do { \
|
||||
ARRAY_ENSURE(a, 1); \
|
||||
if ((i) < (a)->num) { \
|
||||
memmove((a)->list + (i) + 1, (a)->list + (i), \
|
||||
ARRAY_ITEMSIZE(a) * ((a)->num - (i))); \
|
||||
} \
|
||||
(a)->list[i] = s; \
|
||||
(a)->num++; \
|
||||
} while (0)
|
||||
#define ARRAY_REMOVE(a, i) do { \
|
||||
if ((i) < (a)->num - 1) { \
|
||||
memmove((a)->list + (i), (a)->list + (i) + 1, \
|
||||
ARRAY_ITEMSIZE(a) * ((a)->num - (i) - 1)); \
|
||||
} \
|
||||
(a)->num--; \
|
||||
if ((a)->num == 0) \
|
||||
ARRAY_FREE(a); \
|
||||
} while (0)
|
||||
|
||||
#define ARRAY_EXPAND(a, n) do { \
|
||||
ARRAY_ENSURE(a, n); \
|
||||
(a)->num += n; \
|
||||
} while (0)
|
||||
#define ARRAY_TRUNC(a, n) do { \
|
||||
if ((a)->num > n) \
|
||||
(a)->num -= n; \
|
||||
else \
|
||||
ARRAY_FREE(a); \
|
||||
} while (0)
|
||||
|
||||
#define ARRAY_CONCAT(a, b) do { \
|
||||
ARRAY_ENSURE(a, (b)->num); \
|
||||
memcpy((a)->list + (a)->num, (b)->list, (b)->num * ARRAY_ITEMSIZE(a)) \
|
||||
(a)->num += (b)->num; \
|
||||
} while (0)
|
||||
|
||||
#define ARRAY_FREE(a) do { \
|
||||
if ((a)->list != NULL) \
|
||||
xfree((a)->list); \
|
||||
ARRAY_INIT(a); \
|
||||
} while (0)
|
||||
#define ARRAY_FREEALL(a) do { \
|
||||
ARRAY_FREE(a); \
|
||||
xfree(a); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
100
attributes.c
100
attributes.c
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: attributes.c,v 1.2 2009-06-25 15:25:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
||||
@@ -23,32 +23,30 @@
|
||||
#include "tmux.h"
|
||||
|
||||
const char *
|
||||
attributes_tostring(int attr)
|
||||
attributes_tostring(u_char ch)
|
||||
{
|
||||
static char buf[512];
|
||||
size_t len;
|
||||
static char buf[128];
|
||||
|
||||
if (attr == 0)
|
||||
return ("none");
|
||||
if (ch == 0)
|
||||
return ("default");
|
||||
|
||||
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
|
||||
(attr & GRID_ATTR_CHARSET) ? "acs," : "",
|
||||
(attr & GRID_ATTR_BRIGHT) ? "bright," : "",
|
||||
(attr & GRID_ATTR_DIM) ? "dim," : "",
|
||||
(attr & GRID_ATTR_UNDERSCORE) ? "underscore," : "",
|
||||
(attr & GRID_ATTR_BLINK)? "blink," : "",
|
||||
(attr & GRID_ATTR_REVERSE) ? "reverse," : "",
|
||||
(attr & GRID_ATTR_HIDDEN) ? "hidden," : "",
|
||||
(attr & GRID_ATTR_ITALICS) ? "italics," : "",
|
||||
(attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : "",
|
||||
(attr & GRID_ATTR_UNDERSCORE_2) ? "double-underscore," : "",
|
||||
(attr & GRID_ATTR_UNDERSCORE_3) ? "curly-underscore," : "",
|
||||
(attr & GRID_ATTR_UNDERSCORE_4) ? "dotted-underscore," : "",
|
||||
(attr & GRID_ATTR_UNDERSCORE_5) ? "dashed-underscore," : "",
|
||||
(attr & GRID_ATTR_OVERLINE) ? "overline," : "",
|
||||
(attr & GRID_ATTR_NOATTR) ? "noattr," : "");
|
||||
if (len > 0)
|
||||
buf[len - 1] = '\0';
|
||||
buf[0] = '\0';
|
||||
if (ch & GRID_ATTR_BRIGHT)
|
||||
strlcat(buf, "bright,", sizeof (buf));
|
||||
if (ch & GRID_ATTR_DIM)
|
||||
strlcat(buf, "dim,", sizeof (buf));
|
||||
if (ch & GRID_ATTR_UNDERSCORE)
|
||||
strlcat(buf, "underscore,", sizeof (buf));
|
||||
if (ch & GRID_ATTR_BLINK)
|
||||
strlcat(buf, "blink,", sizeof (buf));
|
||||
if (ch & GRID_ATTR_REVERSE)
|
||||
strlcat(buf, "reverse,", sizeof (buf));
|
||||
if (ch & GRID_ATTR_HIDDEN)
|
||||
strlcat(buf, "hidden,", sizeof (buf));
|
||||
if (ch & GRID_ATTR_ITALICS)
|
||||
strlcat(buf, "italics,", sizeof (buf));
|
||||
if (*buf)
|
||||
*(strrchr(buf, ',')) = '\0';
|
||||
|
||||
return (buf);
|
||||
}
|
||||
@@ -57,53 +55,39 @@ int
|
||||
attributes_fromstring(const char *str)
|
||||
{
|
||||
const char delimiters[] = " ,|";
|
||||
int attr;
|
||||
u_char ch;
|
||||
size_t end;
|
||||
u_int i;
|
||||
struct {
|
||||
const char *name;
|
||||
int attr;
|
||||
} table[] = {
|
||||
{ "acs", GRID_ATTR_CHARSET },
|
||||
{ "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)
|
||||
return (-1);
|
||||
if (strchr(delimiters, str[strlen(str) - 1]) != NULL)
|
||||
return (-1);
|
||||
|
||||
if (strcasecmp(str, "default") == 0 || strcasecmp(str, "none") == 0)
|
||||
if (strcasecmp(str, "default") == 0)
|
||||
return (0);
|
||||
|
||||
attr = 0;
|
||||
ch = 0;
|
||||
do {
|
||||
end = strcspn(str, delimiters);
|
||||
for (i = 0; i < nitems(table); i++) {
|
||||
if (end != strlen(table[i].name))
|
||||
continue;
|
||||
if (strncasecmp(str, table[i].name, end) == 0) {
|
||||
attr |= table[i].attr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == nitems(table))
|
||||
if ((end == 6 && strncasecmp(str, "bright", end) == 0) ||
|
||||
(end == 4 && strncasecmp(str, "bold", end) == 0))
|
||||
ch |= GRID_ATTR_BRIGHT;
|
||||
else if (end == 3 && strncasecmp(str, "dim", end) == 0)
|
||||
ch |= GRID_ATTR_DIM;
|
||||
else if (end == 10 && strncasecmp(str, "underscore", end) == 0)
|
||||
ch |= GRID_ATTR_UNDERSCORE;
|
||||
else if (end == 5 && strncasecmp(str, "blink", end) == 0)
|
||||
ch |= GRID_ATTR_BLINK;
|
||||
else if (end == 7 && strncasecmp(str, "reverse", end) == 0)
|
||||
ch |= GRID_ATTR_REVERSE;
|
||||
else if (end == 6 && strncasecmp(str, "hidden", end) == 0)
|
||||
ch |= GRID_ATTR_HIDDEN;
|
||||
else if (end == 7 && strncasecmp(str, "italics", end) == 0)
|
||||
ch |= GRID_ATTR_ITALICS;
|
||||
else
|
||||
return (-1);
|
||||
str += end + strspn(str + end, delimiters);
|
||||
} while (*str != '\0');
|
||||
|
||||
return (attr);
|
||||
return (ch);
|
||||
}
|
||||
|
||||
17
autogen.sh
17
autogen.sh
@@ -1,17 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "x$(uname)" = "xOpenBSD" ]; then
|
||||
[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.15
|
||||
[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.69
|
||||
fi
|
||||
|
||||
die()
|
||||
{
|
||||
echo "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
mkdir -p etc
|
||||
aclocal || die "aclocal failed"
|
||||
automake --add-missing --force-missing --copy --foreign || die "automake failed"
|
||||
autoreconf || die "autoreconf failed"
|
||||
56
buffer-poll.c
Normal file
56
buffer-poll.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/* $Id: buffer-poll.c,v 1.14 2009-06-25 16:22:36 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/* Fill buffers from socket based on poll results. */
|
||||
int
|
||||
buffer_poll(struct pollfd *pfd, struct buffer *in, struct buffer *out)
|
||||
{
|
||||
ssize_t n;
|
||||
|
||||
#ifdef HAVE_POLL
|
||||
if (pfd->revents & (POLLERR|POLLNVAL|POLLHUP))
|
||||
return (-1);
|
||||
#endif
|
||||
if (pfd->revents & POLLIN) {
|
||||
buffer_ensure(in, BUFSIZ);
|
||||
n = read(pfd->fd, BUFFER_IN(in), BUFFER_FREE(in));
|
||||
if (n == 0)
|
||||
return (-1);
|
||||
if (n == -1) {
|
||||
if (errno != EINTR && errno != EAGAIN)
|
||||
return (-1);
|
||||
} else
|
||||
buffer_add(in, n);
|
||||
}
|
||||
if (BUFFER_USED(out) > 0 && pfd->revents & POLLOUT) {
|
||||
n = write(pfd->fd, BUFFER_OUT(out), BUFFER_USED(out));
|
||||
if (n == -1) {
|
||||
if (errno != EINTR && errno != EAGAIN)
|
||||
return (-1);
|
||||
} else
|
||||
buffer_remove(out, n);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
142
buffer.c
Normal file
142
buffer.c
Normal file
@@ -0,0 +1,142 @@
|
||||
/* $Id: buffer.c,v 1.7 2009-06-25 16:21:32 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/* Create a buffer. */
|
||||
struct buffer *
|
||||
buffer_create(size_t size)
|
||||
{
|
||||
struct buffer *b;
|
||||
|
||||
if (size == 0)
|
||||
fatalx("zero size");
|
||||
|
||||
b = xcalloc(1, sizeof *b);
|
||||
|
||||
b->base = xmalloc(size);
|
||||
b->space = size;
|
||||
|
||||
return (b);
|
||||
}
|
||||
|
||||
/* Destroy a buffer. */
|
||||
void
|
||||
buffer_destroy(struct buffer *b)
|
||||
{
|
||||
xfree(b->base);
|
||||
xfree(b);
|
||||
}
|
||||
|
||||
/* Ensure free space for size in buffer. */
|
||||
void
|
||||
buffer_ensure(struct buffer *b, size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
fatalx("zero size");
|
||||
|
||||
if (BUFFER_FREE(b) >= size)
|
||||
return;
|
||||
|
||||
if (b->off > 0) {
|
||||
if (b->size > 0)
|
||||
memmove(b->base, b->base + b->off, b->size);
|
||||
b->off = 0;
|
||||
}
|
||||
|
||||
if (SIZE_MAX - b->size < size)
|
||||
fatalx("size too big");
|
||||
while (b->space < b->size + size) {
|
||||
b->base = xrealloc(b->base, 2, b->space);
|
||||
b->space *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Adjust buffer after data appended. */
|
||||
void
|
||||
buffer_add(struct buffer *b, size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
fatalx("zero size");
|
||||
if (size > b->space - b->size)
|
||||
fatalx("overflow");
|
||||
|
||||
b->size += size;
|
||||
}
|
||||
|
||||
/* Adjust buffer after data removed. */
|
||||
void
|
||||
buffer_remove(struct buffer *b, size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
fatalx("zero size");
|
||||
if (size > b->size)
|
||||
fatalx("underflow");
|
||||
|
||||
b->size -= size;
|
||||
b->off += size;
|
||||
}
|
||||
|
||||
/* Copy data into a buffer. */
|
||||
void
|
||||
buffer_write(struct buffer *b, const void *data, size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
fatalx("zero size");
|
||||
|
||||
buffer_ensure(b, size);
|
||||
memcpy(BUFFER_IN(b), data, size);
|
||||
buffer_add(b, size);
|
||||
}
|
||||
|
||||
/* Copy data out of a buffer. */
|
||||
void
|
||||
buffer_read(struct buffer *b, void *data, size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
fatalx("zero size");
|
||||
if (size > b->size)
|
||||
fatalx("underflow");
|
||||
|
||||
memcpy(data, BUFFER_OUT(b), size);
|
||||
buffer_remove(b, size);
|
||||
}
|
||||
|
||||
/* Store an 8-bit value. */
|
||||
void
|
||||
buffer_write8(struct buffer *b, uint8_t n)
|
||||
{
|
||||
buffer_ensure(b, 1);
|
||||
BUFFER_IN(b)[0] = n;
|
||||
buffer_add(b, 1);
|
||||
}
|
||||
|
||||
/* Extract an 8-bit value. */
|
||||
uint8_t
|
||||
buffer_read8(struct buffer *b)
|
||||
{
|
||||
uint8_t n;
|
||||
|
||||
n = BUFFER_OUT(b)[0];
|
||||
buffer_remove(b, 1);
|
||||
return (n);
|
||||
}
|
||||
322
cfg.c
322
cfg.c
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cfg.c,v 1.18 2009-06-25 16:21:32 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -17,265 +17,115 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
struct client *cfg_client;
|
||||
int cfg_finished;
|
||||
static char **cfg_causes;
|
||||
static u_int cfg_ncauses;
|
||||
static struct cmdq_item *cfg_item;
|
||||
/*
|
||||
* Config file parser. Pretty quick and simple, each line is parsed into a
|
||||
* argv array and executed as a command.
|
||||
*/
|
||||
|
||||
int cfg_quiet = 1;
|
||||
char **cfg_files;
|
||||
u_int cfg_nfiles;
|
||||
void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
|
||||
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
|
||||
|
||||
static enum cmd_retval
|
||||
cfg_client_done(__unused struct cmdq_item *item, __unused void *data)
|
||||
char *cfg_cause;
|
||||
|
||||
void printflike2
|
||||
cfg_print(unused struct cmd_ctx *ctx, unused const char *fmt, ...)
|
||||
{
|
||||
if (!cfg_finished)
|
||||
return (CMD_RETURN_WAIT);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
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)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cfg_finished = 1;
|
||||
|
||||
cfg_show_causes(NULL);
|
||||
|
||||
if (cfg_item != NULL)
|
||||
cmdq_continue(cfg_item);
|
||||
|
||||
status_prompt_load_history();
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
start_cfg(void)
|
||||
{
|
||||
struct client *c;
|
||||
u_int i;
|
||||
int flags = 0;
|
||||
|
||||
/*
|
||||
* 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_quiet)
|
||||
flags = CMD_PARSE_QUIET;
|
||||
for (i = 0; i < cfg_nfiles; i++)
|
||||
load_cfg(cfg_files[i], c, NULL, NULL, flags, NULL);
|
||||
|
||||
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
|
||||
}
|
||||
|
||||
int
|
||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item,
|
||||
struct cmd_find_state *current, int flags, struct cmdq_item **new_item)
|
||||
{
|
||||
FILE *f;
|
||||
struct cmd_parse_input pi;
|
||||
struct cmd_parse_result *pr;
|
||||
struct cmdq_item *new_item0;
|
||||
struct cmdq_state *state;
|
||||
|
||||
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_ERROR) {
|
||||
cfg_add_cause("%s", pr->error);
|
||||
free(pr->error);
|
||||
return (-1);
|
||||
}
|
||||
if (flags & CMD_PARSE_PARSEONLY) {
|
||||
cmd_list_free(pr->cmdlist);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (item != NULL)
|
||||
state = cmdq_copy_state(cmdq_get_state(item), current);
|
||||
else
|
||||
state = cmdq_new_state(NULL, NULL, 0);
|
||||
cmdq_add_format(state, "current_file", "%s", pi.file);
|
||||
|
||||
new_item0 = cmdq_get_command(pr->cmdlist, state);
|
||||
if (item != NULL)
|
||||
new_item0 = cmdq_insert_after(item, new_item0);
|
||||
else
|
||||
new_item0 = cmdq_append(NULL, new_item0);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
cmdq_free_state(state);
|
||||
|
||||
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, struct cmd_find_state *current,
|
||||
int flags, struct cmdq_item **new_item)
|
||||
{
|
||||
struct cmd_parse_input pi;
|
||||
struct cmd_parse_result *pr;
|
||||
struct cmdq_item *new_item0;
|
||||
struct cmdq_state *state;
|
||||
|
||||
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_ERROR) {
|
||||
cfg_add_cause("%s", pr->error);
|
||||
free(pr->error);
|
||||
return (-1);
|
||||
}
|
||||
if (flags & CMD_PARSE_PARSEONLY) {
|
||||
cmd_list_free(pr->cmdlist);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (item != NULL)
|
||||
state = cmdq_copy_state(cmdq_get_state(item), current);
|
||||
else
|
||||
state = cmdq_new_state(NULL, NULL, 0);
|
||||
cmdq_add_format(state, "current_file", "%s", pi.file);
|
||||
|
||||
new_item0 = cmdq_get_command(pr->cmdlist, state);
|
||||
if (item != NULL)
|
||||
new_item0 = cmdq_insert_after(item, new_item0);
|
||||
else
|
||||
new_item0 = cmdq_append(NULL, new_item0);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
cmdq_free_state(state);
|
||||
|
||||
if (new_item != NULL)
|
||||
*new_item = new_item0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cfg_add_cause(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *msg;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&msg, fmt, ap);
|
||||
xvasprintf(&cfg_cause, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
cfg_ncauses++;
|
||||
cfg_causes = xreallocarray(cfg_causes, cfg_ncauses, sizeof *cfg_causes);
|
||||
cfg_causes[cfg_ncauses - 1] = msg;
|
||||
}
|
||||
|
||||
void
|
||||
cfg_print_causes(struct cmdq_item *item)
|
||||
int
|
||||
load_cfg(const char *path, char **cause)
|
||||
{
|
||||
struct client *c = cmdq_get_client(item);
|
||||
u_int i;
|
||||
FILE *f;
|
||||
u_int n;
|
||||
struct stat sb;
|
||||
char *buf, *line, *ptr;
|
||||
size_t len;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
|
||||
for (i = 0; i < cfg_ncauses; i++) {
|
||||
if (c != NULL && (c->flags & CLIENT_CONTROL))
|
||||
control_write(c, "%%config-error %s", cfg_causes[i]);
|
||||
else
|
||||
cmdq_print(item, "%s", cfg_causes[i]);
|
||||
free(cfg_causes[i]);
|
||||
if (stat(path, &sb) != 0) {
|
||||
xasprintf(cause, "%s: %s", path, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
if (!S_ISREG(sb.st_mode)) {
|
||||
xasprintf(cause, "%s: not a regular file", path);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
free(cfg_causes);
|
||||
cfg_causes = NULL;
|
||||
cfg_ncauses = 0;
|
||||
}
|
||||
if ((f = fopen(path, "rb")) == NULL) {
|
||||
xasprintf(cause, "%s: %s", path, strerror(errno));
|
||||
return (1);
|
||||
}
|
||||
n = 0;
|
||||
|
||||
void
|
||||
cfg_show_causes(struct session *s)
|
||||
{
|
||||
struct client *c = TAILQ_FIRST(&clients);
|
||||
struct window_pane *wp;
|
||||
struct window_mode_entry *wme;
|
||||
u_int i;
|
||||
|
||||
if (cfg_ncauses == 0)
|
||||
return;
|
||||
|
||||
if (c != NULL && (c->flags & CLIENT_CONTROL)) {
|
||||
for (i = 0; i < cfg_ncauses; i++) {
|
||||
control_write(c, "%%config-error %s", cfg_causes[i]);
|
||||
free(cfg_causes[i]);
|
||||
line = NULL;
|
||||
while ((buf = fgetln(f, &len))) {
|
||||
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;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
n++;
|
||||
|
||||
if (s == NULL) {
|
||||
if (c != NULL && c->session != NULL)
|
||||
s = c->session;
|
||||
else
|
||||
s = RB_MIN(sessions, &sessions);
|
||||
}
|
||||
if (s == NULL || s->attached == 0) /* wait for an attached session */
|
||||
return;
|
||||
wp = s->curw->window->active;
|
||||
if (cmd_string_parse(buf, &cmdlist, cause) != 0) {
|
||||
if (*cause == NULL)
|
||||
continue;
|
||||
goto error;
|
||||
}
|
||||
if (cmdlist == NULL)
|
||||
continue;
|
||||
cfg_cause = NULL;
|
||||
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme == NULL || wme->mode != &window_view_mode)
|
||||
window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
|
||||
for (i = 0; i < cfg_ncauses; i++) {
|
||||
window_copy_add(wp, 0, "%s", cfg_causes[i]);
|
||||
free(cfg_causes[i]);
|
||||
}
|
||||
ctx.msgdata = NULL;
|
||||
ctx.cursession = NULL;
|
||||
ctx.curclient = NULL;
|
||||
|
||||
out:
|
||||
free(cfg_causes);
|
||||
cfg_causes = NULL;
|
||||
cfg_ncauses = 0;
|
||||
ctx.error = cfg_error;
|
||||
ctx.print = cfg_print;
|
||||
ctx.info = cfg_print;
|
||||
|
||||
ctx.cmdclient = NULL;
|
||||
|
||||
cfg_cause = NULL;
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
cmd_list_free(cmdlist);
|
||||
if (cfg_cause != NULL) {
|
||||
*cause = cfg_cause;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (line != NULL)
|
||||
xfree(line);
|
||||
fclose(f);
|
||||
|
||||
return (0);
|
||||
|
||||
error:
|
||||
fclose(f);
|
||||
|
||||
xasprintf(&ptr, "%s: %s at line %u", path, *cause, n);
|
||||
xfree(*cause);
|
||||
*cause = ptr;
|
||||
return (1);
|
||||
}
|
||||
|
||||
92
client-fn.c
Normal file
92
client-fn.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/* $Id: client-fn.c,v 1.6 2009-03-04 17:24:07 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
void
|
||||
client_fill_session(struct msg_command_data *data)
|
||||
{
|
||||
char *env, *ptr1, *ptr2, buf[256];
|
||||
size_t len;
|
||||
const char *errstr;
|
||||
long long ll;
|
||||
|
||||
data->pid = -1;
|
||||
if ((env = getenv("TMUX")) == NULL)
|
||||
return;
|
||||
|
||||
if ((ptr2 = strrchr(env, ',')) == NULL || ptr2 == env)
|
||||
return;
|
||||
for (ptr1 = ptr2 - 1; ptr1 > env && *ptr1 != ','; ptr1--)
|
||||
;
|
||||
if (*ptr1 != ',')
|
||||
return;
|
||||
ptr1++;
|
||||
ptr2++;
|
||||
|
||||
len = ptr2 - ptr1 - 1;
|
||||
if (len > (sizeof buf) - 1)
|
||||
return;
|
||||
memcpy(buf, ptr1, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
ll = strtonum(buf, 0, LONG_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return;
|
||||
data->pid = ll;
|
||||
|
||||
ll = strtonum(ptr2, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return;
|
||||
data->idx = ll;
|
||||
}
|
||||
|
||||
void
|
||||
client_write_server(
|
||||
struct client_ctx *cctx, enum hdrtype type, void *buf, size_t len)
|
||||
{
|
||||
struct hdr hdr;
|
||||
|
||||
hdr.type = type;
|
||||
hdr.size = len;
|
||||
buffer_write(cctx->srv_out, &hdr, sizeof hdr);
|
||||
|
||||
if (buf != NULL && len > 0)
|
||||
buffer_write(cctx->srv_out, buf, len);
|
||||
}
|
||||
|
||||
void
|
||||
client_write_server2(struct client_ctx *cctx,
|
||||
enum hdrtype type, void *buf1, size_t len1, void *buf2, size_t len2)
|
||||
{
|
||||
struct hdr hdr;
|
||||
|
||||
hdr.type = type;
|
||||
hdr.size = len1 + len2;
|
||||
buffer_write(cctx->srv_out, &hdr, sizeof hdr);
|
||||
|
||||
if (buf1 != NULL && len1 > 0)
|
||||
buffer_write(cctx->srv_out, buf1, len1);
|
||||
if (buf2 != NULL && len2 > 0)
|
||||
buffer_write(cctx->srv_out, buf2, len2);
|
||||
}
|
||||
159
client-msg.c
Normal file
159
client-msg.c
Normal file
@@ -0,0 +1,159 @@
|
||||
/* $Id: client-msg.c,v 1.19 2009-06-25 15:25:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
int client_msg_fn_detach(struct hdr *, struct client_ctx *, char **);
|
||||
int client_msg_fn_error(struct hdr *, struct client_ctx *, char **);
|
||||
int client_msg_fn_shutdown(struct hdr *, struct client_ctx *, char **);
|
||||
int client_msg_fn_exit(struct hdr *, struct client_ctx *, char **);
|
||||
int client_msg_fn_exited(struct hdr *, struct client_ctx *, char **);
|
||||
int client_msg_fn_suspend(struct hdr *, struct client_ctx *, char **);
|
||||
|
||||
struct client_msg {
|
||||
enum hdrtype type;
|
||||
int (*fn)(struct hdr *, struct client_ctx *, char **);
|
||||
};
|
||||
struct client_msg client_msg_table[] = {
|
||||
{ MSG_DETACH, client_msg_fn_detach },
|
||||
{ MSG_ERROR, client_msg_fn_error },
|
||||
{ MSG_EXIT, client_msg_fn_exit },
|
||||
{ MSG_EXITED, client_msg_fn_exited },
|
||||
{ MSG_SHUTDOWN, client_msg_fn_shutdown },
|
||||
{ MSG_SUSPEND, client_msg_fn_suspend },
|
||||
};
|
||||
|
||||
int
|
||||
client_msg_dispatch(struct client_ctx *cctx, char **error)
|
||||
{
|
||||
struct hdr hdr;
|
||||
struct client_msg *msg;
|
||||
u_int i;
|
||||
|
||||
if (BUFFER_USED(cctx->srv_in) < sizeof hdr)
|
||||
return (1);
|
||||
memcpy(&hdr, BUFFER_OUT(cctx->srv_in), sizeof hdr);
|
||||
if (BUFFER_USED(cctx->srv_in) < (sizeof hdr) + hdr.size)
|
||||
return (1);
|
||||
buffer_remove(cctx->srv_in, sizeof hdr);
|
||||
|
||||
for (i = 0; i < nitems(client_msg_table); i++) {
|
||||
msg = client_msg_table + i;
|
||||
if (msg->type == hdr.type) {
|
||||
if (msg->fn(&hdr, cctx, error) != 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
fatalx("unexpected message");
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx, char **error)
|
||||
{
|
||||
if (hdr->size == SIZE_MAX)
|
||||
fatalx("bad MSG_ERROR size");
|
||||
|
||||
*error = xmalloc(hdr->size + 1);
|
||||
buffer_read(cctx->srv_in, *error, hdr->size);
|
||||
(*error)[hdr->size] = '\0';
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_detach(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_DETACH size");
|
||||
|
||||
client_write_server(cctx, MSG_EXITING, NULL, 0);
|
||||
cctx->flags |= CCTX_DETACH;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_shutdown(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_SHUTDOWN size");
|
||||
|
||||
client_write_server(cctx, MSG_EXITING, NULL, 0);
|
||||
cctx->flags |= CCTX_SHUTDOWN;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_exit(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_EXIT size");
|
||||
|
||||
client_write_server(cctx, MSG_EXITING, NULL, 0);
|
||||
cctx->flags |= CCTX_EXIT;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_exited(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_EXITED size");
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_suspend(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_SUSPEND size");
|
||||
|
||||
memset(&act, 0, sizeof act);
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = SA_RESTART;
|
||||
|
||||
act.sa_handler = SIG_DFL;
|
||||
if (sigaction(SIGTSTP, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
|
||||
act.sa_handler = sighandler;
|
||||
if (sigaction(SIGCONT, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
|
||||
kill(getpid(), SIGTSTP);
|
||||
|
||||
return (0);
|
||||
}
|
||||
892
client.c
892
client.c
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: client.c,v 1.53 2009-07-01 23:06: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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -17,793 +17,217 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <pwd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
static struct tmuxproc *client_proc;
|
||||
static struct tmuxpeer *client_peer;
|
||||
static uint64_t client_flags;
|
||||
static int client_suspended;
|
||||
static enum {
|
||||
CLIENT_EXIT_NONE,
|
||||
CLIENT_EXIT_DETACHED,
|
||||
CLIENT_EXIT_DETACHED_HUP,
|
||||
CLIENT_EXIT_LOST_TTY,
|
||||
CLIENT_EXIT_TERMINATED,
|
||||
CLIENT_EXIT_LOST_SERVER,
|
||||
CLIENT_EXIT_EXITED,
|
||||
CLIENT_EXIT_SERVER_EXITED,
|
||||
CLIENT_EXIT_MESSAGE_PROVIDED
|
||||
} client_exitreason = CLIENT_EXIT_NONE;
|
||||
static int client_exitflag;
|
||||
static int client_exitval;
|
||||
static enum msgtype client_exittype;
|
||||
static const char *client_exitsession;
|
||||
static char *client_exitmessage;
|
||||
static const char *client_execshell;
|
||||
static const char *client_execcmd;
|
||||
static int client_attached;
|
||||
static struct client_files client_files = RB_INITIALIZER(&client_files);
|
||||
void client_handle_winch(struct client_ctx *);
|
||||
|
||||
static __dead void client_exec(const char *,const char *);
|
||||
static int client_get_lock(char *);
|
||||
static int client_connect(struct event_base *, const char *,
|
||||
uint64_t);
|
||||
static void client_send_identify(const char *, const char *,
|
||||
char **, u_int, const char *, int);
|
||||
static void client_signal(int);
|
||||
static void client_dispatch(struct imsg *, void *);
|
||||
static void client_dispatch_attached(struct imsg *);
|
||||
static void client_dispatch_wait(struct imsg *);
|
||||
static const char *client_exit_message(void);
|
||||
|
||||
/*
|
||||
* Get server create lock. If already held then server start is happening in
|
||||
* another client, so block until the lock is released and return -2 to
|
||||
* retry. Return -1 on failure to continue and start the server anyway.
|
||||
*/
|
||||
static int
|
||||
client_get_lock(char *lockfile)
|
||||
int
|
||||
client_init(char *path, struct client_ctx *cctx, int start_server, int flags)
|
||||
{
|
||||
int lockfd;
|
||||
struct sockaddr_un sa;
|
||||
struct stat sb;
|
||||
struct msg_identify_data data;
|
||||
struct winsize ws;
|
||||
size_t size;
|
||||
int mode;
|
||||
struct buffer *b;
|
||||
char *name;
|
||||
#ifdef HAVE_SETPROCTITLE
|
||||
char rpathbuf[MAXPATHLEN];
|
||||
#endif
|
||||
|
||||
log_debug("lock file is %s", lockfile);
|
||||
#ifdef HAVE_SETPROCTITLE
|
||||
if (realpath(path, rpathbuf) == NULL)
|
||||
strlcpy(rpathbuf, path, sizeof rpathbuf);
|
||||
setproctitle("client (%s)", rpathbuf);
|
||||
#endif
|
||||
|
||||
if ((lockfd = open(lockfile, O_WRONLY|O_CREAT, 0600)) == -1) {
|
||||
log_debug("open failed: %s", strerror(errno));
|
||||
return (-1);
|
||||
if (lstat(path, &sb) != 0) {
|
||||
if (start_server && errno == ENOENT) {
|
||||
if ((cctx->srv_fd = server_start(path)) == -1)
|
||||
goto start_failed;
|
||||
goto server_started;
|
||||
}
|
||||
goto not_found;
|
||||
}
|
||||
|
||||
if (flock(lockfd, LOCK_EX|LOCK_NB) == -1) {
|
||||
log_debug("flock failed: %s", strerror(errno));
|
||||
if (errno != EAGAIN)
|
||||
return (lockfd);
|
||||
while (flock(lockfd, LOCK_EX) == -1 && errno == EINTR)
|
||||
/* nothing */;
|
||||
close(lockfd);
|
||||
return (-2);
|
||||
if (!S_ISSOCK(sb.st_mode)) {
|
||||
errno = ENOTSOCK;
|
||||
goto not_found;
|
||||
}
|
||||
log_debug("flock succeeded");
|
||||
|
||||
return (lockfd);
|
||||
}
|
||||
|
||||
/* Connect client to server. */
|
||||
static int
|
||||
client_connect(struct event_base *base, const char *path, uint64_t flags)
|
||||
{
|
||||
struct sockaddr_un sa;
|
||||
size_t size;
|
||||
int fd, lockfd = -1, locked = 0;
|
||||
char *lockfile = NULL;
|
||||
|
||||
memset(&sa, 0, sizeof sa);
|
||||
sa.sun_family = AF_UNIX;
|
||||
size = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
|
||||
if (size >= sizeof sa.sun_path) {
|
||||
errno = ENAMETOOLONG;
|
||||
return (-1);
|
||||
}
|
||||
log_debug("socket is %s", path);
|
||||
|
||||
retry:
|
||||
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||
return (-1);
|
||||
|
||||
log_debug("trying connect");
|
||||
if (connect(fd, (struct sockaddr *)&sa, sizeof sa) == -1) {
|
||||
log_debug("connect failed: %s", strerror(errno));
|
||||
if (errno != ECONNREFUSED && errno != ENOENT)
|
||||
goto failed;
|
||||
if (flags & CLIENT_NOSTARTSERVER)
|
||||
goto failed;
|
||||
if (~flags & CLIENT_STARTSERVER)
|
||||
goto failed;
|
||||
close(fd);
|
||||
|
||||
if (!locked) {
|
||||
xasprintf(&lockfile, "%s.lock", path);
|
||||
if ((lockfd = client_get_lock(lockfile)) < 0) {
|
||||
log_debug("didn't get lock (%d)", lockfd);
|
||||
|
||||
free(lockfile);
|
||||
lockfile = NULL;
|
||||
|
||||
if (lockfd == -2)
|
||||
goto retry;
|
||||
}
|
||||
log_debug("got lock (%d)", lockfd);
|
||||
|
||||
/*
|
||||
* Always retry at least once, even if we got the lock,
|
||||
* because another client could have taken the lock,
|
||||
* started the server and released the lock between our
|
||||
* connect() and flock().
|
||||
*/
|
||||
locked = 1;
|
||||
goto retry;
|
||||
}
|
||||
|
||||
if (lockfd >= 0 && unlink(path) != 0 && errno != ENOENT) {
|
||||
free(lockfile);
|
||||
close(lockfd);
|
||||
return (-1);
|
||||
}
|
||||
fd = server_start(client_proc, flags, base, lockfd, lockfile);
|
||||
goto not_found;
|
||||
}
|
||||
|
||||
if (locked && lockfd >= 0) {
|
||||
free(lockfile);
|
||||
close(lockfd);
|
||||
}
|
||||
setblocking(fd, 0);
|
||||
return (fd);
|
||||
if ((cctx->srv_fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||
fatal("socket");
|
||||
|
||||
failed:
|
||||
if (locked) {
|
||||
free(lockfile);
|
||||
close(lockfd);
|
||||
}
|
||||
close(fd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Get exit string from reason number. */
|
||||
const char *
|
||||
client_exit_message(void)
|
||||
{
|
||||
static char msg[256];
|
||||
|
||||
switch (client_exitreason) {
|
||||
case CLIENT_EXIT_NONE:
|
||||
break;
|
||||
case CLIENT_EXIT_DETACHED:
|
||||
if (client_exitsession != NULL) {
|
||||
xsnprintf(msg, sizeof msg, "detached "
|
||||
"(from session %s)", client_exitsession);
|
||||
return (msg);
|
||||
}
|
||||
return ("detached");
|
||||
case CLIENT_EXIT_DETACHED_HUP:
|
||||
if (client_exitsession != NULL) {
|
||||
xsnprintf(msg, sizeof msg, "detached and SIGHUP "
|
||||
"(from session %s)", client_exitsession);
|
||||
return (msg);
|
||||
}
|
||||
return ("detached and SIGHUP");
|
||||
case CLIENT_EXIT_LOST_TTY:
|
||||
return ("lost tty");
|
||||
case CLIENT_EXIT_TERMINATED:
|
||||
return ("terminated");
|
||||
case CLIENT_EXIT_LOST_SERVER:
|
||||
return ("server exited unexpectedly");
|
||||
case CLIENT_EXIT_EXITED:
|
||||
return ("exited");
|
||||
case CLIENT_EXIT_SERVER_EXITED:
|
||||
return ("server exited");
|
||||
case CLIENT_EXIT_MESSAGE_PROVIDED:
|
||||
return (client_exitmessage);
|
||||
}
|
||||
return ("unknown reason");
|
||||
}
|
||||
|
||||
/* Exit if all streams flushed. */
|
||||
static void
|
||||
client_exit(void)
|
||||
{
|
||||
if (!file_write_left(&client_files))
|
||||
proc_exit(client_proc);
|
||||
}
|
||||
|
||||
/* Client main loop. */
|
||||
int
|
||||
client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
|
||||
int feat)
|
||||
{
|
||||
struct cmd_parse_result *pr;
|
||||
struct msg_command *data;
|
||||
int fd, i;
|
||||
const char *ttynam, *termname, *cwd;
|
||||
pid_t ppid;
|
||||
enum msgtype msg;
|
||||
struct termios tio, saved_tio;
|
||||
size_t size, linesize = 0;
|
||||
ssize_t linelen;
|
||||
char *line = NULL, **caps = NULL, *cause;
|
||||
u_int ncaps = 0;
|
||||
struct args_value *values;
|
||||
|
||||
/* Set up the initial command. */
|
||||
if (shell_command != NULL) {
|
||||
msg = MSG_SHELL;
|
||||
flags |= CLIENT_STARTSERVER;
|
||||
} else if (argc == 0) {
|
||||
msg = MSG_COMMAND;
|
||||
flags |= CLIENT_STARTSERVER;
|
||||
} else {
|
||||
msg = MSG_COMMAND;
|
||||
|
||||
/*
|
||||
* It's annoying parsing the command string twice (in client
|
||||
* and later in server) but it is necessary to get the start
|
||||
* server flag.
|
||||
*/
|
||||
values = args_from_vector(argc, argv);
|
||||
pr = cmd_parse_from_arguments(values, argc, NULL);
|
||||
if (pr->status == CMD_PARSE_SUCCESS) {
|
||||
if (cmd_list_any_have(pr->cmdlist, CMD_STARTSERVER))
|
||||
flags |= CLIENT_STARTSERVER;
|
||||
cmd_list_free(pr->cmdlist);
|
||||
} else
|
||||
free(pr->error);
|
||||
args_free_values(values, argc);
|
||||
free(values);
|
||||
}
|
||||
|
||||
/* Create client process structure (starts logging). */
|
||||
client_proc = proc_start("client");
|
||||
proc_set_signals(client_proc, client_signal);
|
||||
|
||||
/* Save the flags. */
|
||||
client_flags = flags;
|
||||
log_debug("flags are %#llx", (unsigned long long)client_flags);
|
||||
|
||||
/* Initialize the client socket and start the server. */
|
||||
#ifdef HAVE_SYSTEMD
|
||||
if (systemd_activated()) {
|
||||
/* socket-based activation, do not even try to be a client. */
|
||||
fd = server_start(client_proc, flags, base, 0, NULL);
|
||||
} else
|
||||
#endif
|
||||
fd = client_connect(base, socket_path, client_flags);
|
||||
if (fd == -1) {
|
||||
if (connect(
|
||||
cctx->srv_fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
|
||||
if (errno == ECONNREFUSED) {
|
||||
fprintf(stderr, "no server running on %s\n",
|
||||
socket_path);
|
||||
} else {
|
||||
fprintf(stderr, "error connecting to %s (%s)\n",
|
||||
socket_path, strerror(errno));
|
||||
if (unlink(path) != 0 || !start_server)
|
||||
goto not_found;
|
||||
if ((cctx->srv_fd = server_start(path)) == -1)
|
||||
goto start_failed;
|
||||
goto server_started;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
client_peer = proc_add_peer(client_proc, fd, client_dispatch, NULL);
|
||||
|
||||
/* Save these before pledge(). */
|
||||
if ((cwd = find_cwd()) == NULL && (cwd = find_home()) == NULL)
|
||||
cwd = "/";
|
||||
if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
|
||||
ttynam = "";
|
||||
if ((termname = getenv("TERM")) == NULL)
|
||||
termname = "";
|
||||
|
||||
/*
|
||||
* Drop privileges for client. "proc exec" is needed for -c and for
|
||||
* locking (which uses system(3)).
|
||||
*
|
||||
* "tty" is needed to restore termios(4) and also for some reason -CC
|
||||
* does not work properly without it (input is not recognised).
|
||||
*
|
||||
* "sendfd" is dropped later in client_dispatch_wait().
|
||||
*/
|
||||
if (pledge(
|
||||
"stdio rpath wpath cpath unix sendfd proc exec tty",
|
||||
NULL) != 0)
|
||||
fatal("pledge failed");
|
||||
|
||||
/* Load terminfo entry if any. */
|
||||
if (isatty(STDIN_FILENO) &&
|
||||
*termname != '\0' &&
|
||||
tty_term_read_list(termname, STDIN_FILENO, &caps, &ncaps,
|
||||
&cause) != 0) {
|
||||
fprintf(stderr, "%s\n", cause);
|
||||
free(cause);
|
||||
return (1);
|
||||
goto not_found;
|
||||
}
|
||||
|
||||
/* Free stuff that is not used in the client. */
|
||||
if (ptm_fd != -1)
|
||||
close(ptm_fd);
|
||||
options_free(global_options);
|
||||
options_free(global_s_options);
|
||||
options_free(global_w_options);
|
||||
environ_free(global_environ);
|
||||
server_started:
|
||||
if ((mode = fcntl(cctx->srv_fd, F_GETFL)) == -1)
|
||||
fatal("fcntl failed");
|
||||
if (fcntl(cctx->srv_fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||
fatal("fcntl failed");
|
||||
cctx->srv_in = buffer_create(BUFSIZ);
|
||||
cctx->srv_out = buffer_create(BUFSIZ);
|
||||
|
||||
/* Set up control mode. */
|
||||
if (client_flags & CLIENT_CONTROLCONTROL) {
|
||||
if (tcgetattr(STDIN_FILENO, &saved_tio) != 0) {
|
||||
fprintf(stderr, "tcgetattr failed: %s\n",
|
||||
strerror(errno));
|
||||
return (1);
|
||||
}
|
||||
cfmakeraw(&tio);
|
||||
tio.c_iflag = ICRNL|IXANY;
|
||||
tio.c_oflag = OPOST|ONLCR;
|
||||
#ifdef NOKERNINFO
|
||||
tio.c_lflag = NOKERNINFO;
|
||||
#endif
|
||||
tio.c_cflag = CREAD|CS8|HUPCL;
|
||||
tio.c_cc[VMIN] = 1;
|
||||
tio.c_cc[VTIME] = 0;
|
||||
cfsetispeed(&tio, cfgetispeed(&saved_tio));
|
||||
cfsetospeed(&tio, cfgetospeed(&saved_tio));
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &tio);
|
||||
if (isatty(STDIN_FILENO)) {
|
||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1)
|
||||
fatal("ioctl(TIOCGWINSZ)");
|
||||
data.version = PROTOCOL_VERSION;
|
||||
data.flags = flags;
|
||||
data.sx = ws.ws_col;
|
||||
data.sy = ws.ws_row;
|
||||
*data.tty = '\0';
|
||||
if (getcwd(data.cwd, sizeof data.cwd) == NULL)
|
||||
*data.cwd = '\0';
|
||||
|
||||
if ((name = ttyname(STDIN_FILENO)) == NULL)
|
||||
fatal("ttyname failed");
|
||||
if (strlcpy(data.tty, name, sizeof data.tty) >= sizeof data.tty)
|
||||
fatalx("ttyname failed");
|
||||
|
||||
b = buffer_create(BUFSIZ);
|
||||
cmd_send_string(b, getenv("TERM"));
|
||||
client_write_server2(cctx, MSG_IDENTIFY,
|
||||
&data, sizeof data, BUFFER_OUT(b), BUFFER_USED(b));
|
||||
buffer_destroy(b);
|
||||
}
|
||||
|
||||
/* Send identify messages. */
|
||||
client_send_identify(ttynam, termname, caps, ncaps, cwd, feat);
|
||||
tty_term_free_list(caps, ncaps);
|
||||
proc_flush_peer(client_peer);
|
||||
return (0);
|
||||
|
||||
/* Send first command. */
|
||||
if (msg == MSG_COMMAND) {
|
||||
/* How big is the command? */
|
||||
size = 0;
|
||||
for (i = 0; i < argc; i++)
|
||||
size += strlen(argv[i]) + 1;
|
||||
if (size > MAX_IMSGSIZE - (sizeof *data)) {
|
||||
fprintf(stderr, "command too long\n");
|
||||
return (1);
|
||||
}
|
||||
data = xmalloc((sizeof *data) + size);
|
||||
start_failed:
|
||||
log_warnx("server failed to start");
|
||||
return (1);
|
||||
|
||||
/* Prepare command for server. */
|
||||
data->argc = argc;
|
||||
if (cmd_pack_argv(argc, argv, (char *)(data + 1), size) != 0) {
|
||||
fprintf(stderr, "command too long\n");
|
||||
free(data);
|
||||
return (1);
|
||||
}
|
||||
size += sizeof *data;
|
||||
|
||||
/* Send the command. */
|
||||
if (proc_send(client_peer, msg, -1, data, size) != 0) {
|
||||
fprintf(stderr, "failed to send command\n");
|
||||
free(data);
|
||||
return (1);
|
||||
}
|
||||
free(data);
|
||||
} else if (msg == MSG_SHELL)
|
||||
proc_send(client_peer, msg, -1, NULL, 0);
|
||||
|
||||
/* Start main loop. */
|
||||
proc_loop(client_proc, NULL);
|
||||
|
||||
/* Run command if user requested exec, instead of exiting. */
|
||||
if (client_exittype == MSG_EXEC) {
|
||||
if (client_flags & CLIENT_CONTROLCONTROL)
|
||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
|
||||
client_exec(client_execshell, client_execcmd);
|
||||
}
|
||||
|
||||
/* Restore streams to blocking. */
|
||||
setblocking(STDIN_FILENO, 1);
|
||||
setblocking(STDOUT_FILENO, 1);
|
||||
setblocking(STDERR_FILENO, 1);
|
||||
|
||||
/* Print the exit message, if any, and exit. */
|
||||
if (client_attached) {
|
||||
if (client_exitreason != CLIENT_EXIT_NONE)
|
||||
printf("[%s]\n", client_exit_message());
|
||||
|
||||
ppid = getppid();
|
||||
if (client_exittype == MSG_DETACHKILL && ppid > 1)
|
||||
kill(ppid, SIGHUP);
|
||||
} else if (client_flags & CLIENT_CONTROL) {
|
||||
if (client_exitreason != CLIENT_EXIT_NONE)
|
||||
printf("%%exit %s\n", client_exit_message());
|
||||
else
|
||||
printf("%%exit\n");
|
||||
fflush(stdout);
|
||||
if (client_flags & CLIENT_CONTROL_WAITEXIT) {
|
||||
setvbuf(stdin, NULL, _IOLBF, 0);
|
||||
for (;;) {
|
||||
linelen = getline(&line, &linesize, stdin);
|
||||
if (linelen <= 1)
|
||||
break;
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
if (client_flags & CLIENT_CONTROLCONTROL) {
|
||||
printf("\033\\");
|
||||
fflush(stdout);
|
||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
|
||||
}
|
||||
} else if (client_exitreason != CLIENT_EXIT_NONE)
|
||||
fprintf(stderr, "%s\n", client_exit_message());
|
||||
return (client_exitval);
|
||||
not_found:
|
||||
log_warn("server not found");
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Send identify messages to server. */
|
||||
static void
|
||||
client_send_identify(const char *ttynam, const char *termname, char **caps,
|
||||
u_int ncaps, const char *cwd, int feat)
|
||||
int
|
||||
client_main(struct client_ctx *cctx)
|
||||
{
|
||||
char **ss;
|
||||
size_t sslen;
|
||||
int fd;
|
||||
uint64_t flags = client_flags;
|
||||
pid_t pid;
|
||||
u_int i;
|
||||
struct pollfd pfd;
|
||||
char *error;
|
||||
int xtimeout; /* Yay for ncurses namespace! */
|
||||
|
||||
proc_send(client_peer, MSG_IDENTIFY_LONGFLAGS, -1, &flags, sizeof flags);
|
||||
proc_send(client_peer, MSG_IDENTIFY_LONGFLAGS, -1, &client_flags,
|
||||
sizeof client_flags);
|
||||
siginit();
|
||||
|
||||
proc_send(client_peer, MSG_IDENTIFY_TERM, -1, termname,
|
||||
strlen(termname) + 1);
|
||||
proc_send(client_peer, MSG_IDENTIFY_FEATURES, -1, &feat, sizeof feat);
|
||||
logfile("client");
|
||||
|
||||
proc_send(client_peer, MSG_IDENTIFY_TTYNAME, -1, ttynam,
|
||||
strlen(ttynam) + 1);
|
||||
proc_send(client_peer, MSG_IDENTIFY_CWD, -1, cwd, strlen(cwd) + 1);
|
||||
|
||||
for (i = 0; i < ncaps; i++) {
|
||||
proc_send(client_peer, MSG_IDENTIFY_TERMINFO, -1,
|
||||
caps[i], strlen(caps[i]) + 1);
|
||||
}
|
||||
|
||||
if ((fd = dup(STDIN_FILENO)) == -1)
|
||||
fatal("dup failed");
|
||||
proc_send(client_peer, MSG_IDENTIFY_STDIN, fd, NULL, 0);
|
||||
if ((fd = dup(STDOUT_FILENO)) == -1)
|
||||
fatal("dup failed");
|
||||
proc_send(client_peer, MSG_IDENTIFY_STDOUT, fd, NULL, 0);
|
||||
|
||||
pid = getpid();
|
||||
proc_send(client_peer, MSG_IDENTIFY_CLIENTPID, -1, &pid, sizeof pid);
|
||||
|
||||
for (ss = environ; *ss != NULL; ss++) {
|
||||
sslen = strlen(*ss) + 1;
|
||||
if (sslen > MAX_IMSGSIZE - IMSG_HEADER_SIZE)
|
||||
continue;
|
||||
proc_send(client_peer, MSG_IDENTIFY_ENVIRON, -1, *ss, sslen);
|
||||
}
|
||||
|
||||
proc_send(client_peer, MSG_IDENTIFY_DONE, -1, NULL, 0);
|
||||
}
|
||||
|
||||
/* Run command in shell; used for -c. */
|
||||
static __dead void
|
||||
client_exec(const char *shell, const char *shellcmd)
|
||||
{
|
||||
char *argv0;
|
||||
|
||||
log_debug("shell %s, command %s", shell, shellcmd);
|
||||
argv0 = shell_argv0(shell, !!(client_flags & CLIENT_LOGIN));
|
||||
setenv("SHELL", shell, 1);
|
||||
|
||||
proc_clear_signals(client_proc, 1);
|
||||
|
||||
setblocking(STDIN_FILENO, 1);
|
||||
setblocking(STDOUT_FILENO, 1);
|
||||
setblocking(STDERR_FILENO, 1);
|
||||
closefrom(STDERR_FILENO + 1);
|
||||
|
||||
execl(shell, argv0, "-c", shellcmd, (char *) NULL);
|
||||
fatal("execl failed");
|
||||
}
|
||||
|
||||
/* Callback to handle signals in the client. */
|
||||
static void
|
||||
client_signal(int sig)
|
||||
{
|
||||
struct sigaction sigact;
|
||||
int status;
|
||||
pid_t pid;
|
||||
|
||||
log_debug("%s: %s", __func__, strsignal(sig));
|
||||
if (sig == SIGCHLD) {
|
||||
for (;;) {
|
||||
pid = waitpid(WAIT_ANY, &status, WNOHANG);
|
||||
if (pid == 0)
|
||||
break;
|
||||
if (pid == -1) {
|
||||
if (errno == ECHILD)
|
||||
break;
|
||||
log_debug("waitpid failed: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
error = NULL;
|
||||
while (!sigterm) {
|
||||
if (sigchld) {
|
||||
waitpid(WAIT_ANY, NULL, WNOHANG);
|
||||
sigchld = 0;
|
||||
}
|
||||
} else if (!client_attached) {
|
||||
if (sig == SIGTERM || sig == SIGHUP)
|
||||
proc_exit(client_proc);
|
||||
} else {
|
||||
switch (sig) {
|
||||
case SIGHUP:
|
||||
client_exitreason = CLIENT_EXIT_LOST_TTY;
|
||||
client_exitval = 1;
|
||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
||||
if (sigwinch)
|
||||
client_handle_winch(cctx);
|
||||
if (sigcont) {
|
||||
siginit();
|
||||
client_write_server(cctx, MSG_WAKEUP, NULL, 0);
|
||||
sigcont = 0;
|
||||
}
|
||||
|
||||
switch (client_msg_dispatch(cctx, &error)) {
|
||||
case -1:
|
||||
goto out;
|
||||
case 0:
|
||||
/* May be more in buffer, don't let poll block. */
|
||||
xtimeout = 0;
|
||||
break;
|
||||
case SIGTERM:
|
||||
if (!client_suspended)
|
||||
client_exitreason = CLIENT_EXIT_TERMINATED;
|
||||
client_exitval = 1;
|
||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
||||
break;
|
||||
case SIGWINCH:
|
||||
proc_send(client_peer, MSG_RESIZE, -1, NULL, 0);
|
||||
break;
|
||||
case SIGCONT:
|
||||
memset(&sigact, 0, sizeof sigact);
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
sigact.sa_flags = SA_RESTART;
|
||||
sigact.sa_handler = SIG_IGN;
|
||||
if (sigaction(SIGTSTP, &sigact, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
proc_send(client_peer, MSG_WAKEUP, -1, NULL, 0);
|
||||
client_suspended = 0;
|
||||
default:
|
||||
/* Out of data, poll may block. */
|
||||
xtimeout = INFTIM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Callback for file write error or close. */
|
||||
static void
|
||||
client_file_check_cb(__unused struct client *c, __unused const char *path,
|
||||
__unused int error, __unused int closed, __unused struct evbuffer *buffer,
|
||||
__unused void *data)
|
||||
{
|
||||
if (client_exitflag)
|
||||
client_exit();
|
||||
}
|
||||
pfd.fd = cctx->srv_fd;
|
||||
pfd.events = POLLIN;
|
||||
if (BUFFER_USED(cctx->srv_out) > 0)
|
||||
pfd.events |= POLLOUT;
|
||||
|
||||
/* Callback for client read events. */
|
||||
static void
|
||||
client_dispatch(struct imsg *imsg, __unused void *arg)
|
||||
{
|
||||
if (imsg == NULL) {
|
||||
if (!client_exitflag) {
|
||||
client_exitreason = CLIENT_EXIT_LOST_SERVER;
|
||||
client_exitval = 1;
|
||||
if (poll(&pfd, 1, xtimeout) == -1) {
|
||||
if (errno == EAGAIN || errno == EINTR)
|
||||
continue;
|
||||
fatal("poll failed");
|
||||
}
|
||||
proc_exit(client_proc);
|
||||
return;
|
||||
|
||||
if (buffer_poll(&pfd, cctx->srv_in, cctx->srv_out) != 0)
|
||||
goto server_dead;
|
||||
}
|
||||
|
||||
if (client_attached)
|
||||
client_dispatch_attached(imsg);
|
||||
else
|
||||
client_dispatch_wait(imsg);
|
||||
out:
|
||||
if (sigterm) {
|
||||
printf("[terminated]\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (cctx->flags & CCTX_SHUTDOWN) {
|
||||
printf("[server exited]\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (cctx->flags & CCTX_EXIT) {
|
||||
printf("[exited]\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (cctx->flags & CCTX_DETACH) {
|
||||
printf("[detached]\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
printf("[error: %s]\n", error);
|
||||
return (1);
|
||||
|
||||
server_dead:
|
||||
printf("[lost server]\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Process an exit message. */
|
||||
static void
|
||||
client_dispatch_exit_message(char *data, size_t datalen)
|
||||
void
|
||||
client_handle_winch(struct client_ctx *cctx)
|
||||
{
|
||||
int retval;
|
||||
struct msg_resize_data data;
|
||||
struct winsize ws;
|
||||
|
||||
if (datalen < sizeof retval && datalen != 0)
|
||||
fatalx("bad MSG_EXIT size");
|
||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1)
|
||||
fatal("ioctl failed");
|
||||
|
||||
if (datalen >= sizeof retval) {
|
||||
memcpy(&retval, data, sizeof retval);
|
||||
client_exitval = retval;
|
||||
}
|
||||
data.sx = ws.ws_col;
|
||||
data.sy = ws.ws_row;
|
||||
client_write_server(cctx, MSG_RESIZE, &data, sizeof data);
|
||||
|
||||
if (datalen > sizeof retval) {
|
||||
datalen -= sizeof retval;
|
||||
data += sizeof retval;
|
||||
|
||||
client_exitmessage = xmalloc(datalen);
|
||||
memcpy(client_exitmessage, data, datalen);
|
||||
client_exitmessage[datalen - 1] = '\0';
|
||||
|
||||
client_exitreason = CLIENT_EXIT_MESSAGE_PROVIDED;
|
||||
}
|
||||
}
|
||||
|
||||
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
||||
static void
|
||||
client_dispatch_wait(struct imsg *imsg)
|
||||
{
|
||||
char *data;
|
||||
ssize_t datalen;
|
||||
static int pledge_applied;
|
||||
|
||||
/*
|
||||
* "sendfd" is no longer required once all of the identify messages
|
||||
* have been sent. We know the server won't send us anything until that
|
||||
* point (because we don't ask it to), so we can drop "sendfd" once we
|
||||
* get the first message from the server.
|
||||
*/
|
||||
if (!pledge_applied) {
|
||||
if (pledge(
|
||||
"stdio rpath wpath cpath unix proc exec tty",
|
||||
NULL) != 0)
|
||||
fatal("pledge failed");
|
||||
pledge_applied = 1;
|
||||
}
|
||||
|
||||
data = imsg->data;
|
||||
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
|
||||
|
||||
switch (imsg->hdr.type) {
|
||||
case MSG_EXIT:
|
||||
case MSG_SHUTDOWN:
|
||||
client_dispatch_exit_message(data, datalen);
|
||||
client_exitflag = 1;
|
||||
client_exit();
|
||||
break;
|
||||
case MSG_READY:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_READY size");
|
||||
|
||||
client_attached = 1;
|
||||
proc_send(client_peer, MSG_RESIZE, -1, NULL, 0);
|
||||
break;
|
||||
case MSG_VERSION:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_VERSION size");
|
||||
|
||||
fprintf(stderr, "protocol version mismatch "
|
||||
"(client %d, server %u)\n", PROTOCOL_VERSION,
|
||||
imsg->hdr.peerid & 0xff);
|
||||
client_exitval = 1;
|
||||
proc_exit(client_proc);
|
||||
break;
|
||||
case MSG_FLAGS:
|
||||
if (datalen != sizeof client_flags)
|
||||
fatalx("bad MSG_FLAGS string");
|
||||
|
||||
memcpy(&client_flags, data, sizeof client_flags);
|
||||
log_debug("new flags are %#llx",
|
||||
(unsigned long long)client_flags);
|
||||
break;
|
||||
case MSG_SHELL:
|
||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
||||
fatalx("bad MSG_SHELL string");
|
||||
|
||||
client_exec(data, shell_command);
|
||||
/* NOTREACHED */
|
||||
case MSG_DETACH:
|
||||
case MSG_DETACHKILL:
|
||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
||||
break;
|
||||
case MSG_EXITED:
|
||||
proc_exit(client_proc);
|
||||
break;
|
||||
case MSG_READ_OPEN:
|
||||
file_read_open(&client_files, client_peer, imsg, 1,
|
||||
!(client_flags & CLIENT_CONTROL), client_file_check_cb,
|
||||
NULL);
|
||||
break;
|
||||
case MSG_READ_CANCEL:
|
||||
file_read_cancel(&client_files, imsg);
|
||||
break;
|
||||
case MSG_WRITE_OPEN:
|
||||
file_write_open(&client_files, client_peer, imsg, 1,
|
||||
!(client_flags & CLIENT_CONTROL), client_file_check_cb,
|
||||
NULL);
|
||||
break;
|
||||
case MSG_WRITE:
|
||||
file_write_data(&client_files, imsg);
|
||||
break;
|
||||
case MSG_WRITE_CLOSE:
|
||||
file_write_close(&client_files, imsg);
|
||||
break;
|
||||
case MSG_OLDSTDERR:
|
||||
case MSG_OLDSTDIN:
|
||||
case MSG_OLDSTDOUT:
|
||||
fprintf(stderr, "server version is too old for client\n");
|
||||
proc_exit(client_proc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Dispatch imsgs in attached state (after MSG_READY). */
|
||||
static void
|
||||
client_dispatch_attached(struct imsg *imsg)
|
||||
{
|
||||
struct sigaction sigact;
|
||||
char *data;
|
||||
ssize_t datalen;
|
||||
|
||||
data = imsg->data;
|
||||
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
|
||||
|
||||
switch (imsg->hdr.type) {
|
||||
case MSG_FLAGS:
|
||||
if (datalen != sizeof client_flags)
|
||||
fatalx("bad MSG_FLAGS string");
|
||||
|
||||
memcpy(&client_flags, data, sizeof client_flags);
|
||||
log_debug("new flags are %#llx",
|
||||
(unsigned long long)client_flags);
|
||||
break;
|
||||
case MSG_DETACH:
|
||||
case MSG_DETACHKILL:
|
||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
||||
fatalx("bad MSG_DETACH string");
|
||||
|
||||
client_exitsession = xstrdup(data);
|
||||
client_exittype = imsg->hdr.type;
|
||||
if (imsg->hdr.type == MSG_DETACHKILL)
|
||||
client_exitreason = CLIENT_EXIT_DETACHED_HUP;
|
||||
else
|
||||
client_exitreason = CLIENT_EXIT_DETACHED;
|
||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
||||
break;
|
||||
case MSG_EXEC:
|
||||
if (datalen == 0 || data[datalen - 1] != '\0' ||
|
||||
strlen(data) + 1 == (size_t)datalen)
|
||||
fatalx("bad MSG_EXEC string");
|
||||
client_execcmd = xstrdup(data);
|
||||
client_execshell = xstrdup(data + strlen(data) + 1);
|
||||
|
||||
client_exittype = imsg->hdr.type;
|
||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
||||
break;
|
||||
case MSG_EXIT:
|
||||
client_dispatch_exit_message(data, datalen);
|
||||
if (client_exitreason == CLIENT_EXIT_NONE)
|
||||
client_exitreason = CLIENT_EXIT_EXITED;
|
||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
||||
break;
|
||||
case MSG_EXITED:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_EXITED size");
|
||||
|
||||
proc_exit(client_proc);
|
||||
break;
|
||||
case MSG_SHUTDOWN:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_SHUTDOWN size");
|
||||
|
||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
||||
client_exitreason = CLIENT_EXIT_SERVER_EXITED;
|
||||
client_exitval = 1;
|
||||
break;
|
||||
case MSG_SUSPEND:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_SUSPEND size");
|
||||
|
||||
memset(&sigact, 0, sizeof sigact);
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
sigact.sa_flags = SA_RESTART;
|
||||
sigact.sa_handler = SIG_DFL;
|
||||
if (sigaction(SIGTSTP, &sigact, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
client_suspended = 1;
|
||||
kill(getpid(), SIGTSTP);
|
||||
break;
|
||||
case MSG_LOCK:
|
||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
||||
fatalx("bad MSG_LOCK string");
|
||||
|
||||
system(data);
|
||||
proc_send(client_peer, MSG_UNLOCK, -1, NULL, 0);
|
||||
break;
|
||||
}
|
||||
sigwinch = 0;
|
||||
}
|
||||
|
||||
161
clock.c
Normal file
161
clock.c
Normal file
@@ -0,0 +1,161 @@
|
||||
/* $Id: clock.c,v 1.4 2009-05-04 17:58:25 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 <time.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
const char clock_table[14][5][5] = {
|
||||
{ { 1,1,1,1,1 }, /* 0 */
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,1,1,1,1 } },
|
||||
{ { 0,0,0,0,1 }, /* 1 */
|
||||
{ 0,0,0,0,1 },
|
||||
{ 0,0,0,0,1 },
|
||||
{ 0,0,0,0,1 },
|
||||
{ 0,0,0,0,1 } },
|
||||
{ { 1,1,1,1,1 }, /* 2 */
|
||||
{ 0,0,0,0,1 },
|
||||
{ 1,1,1,1,1 },
|
||||
{ 1,0,0,0,0 },
|
||||
{ 1,1,1,1,1 } },
|
||||
{ { 1,1,1,1,1 }, /* 3 */
|
||||
{ 0,0,0,0,1 },
|
||||
{ 1,1,1,1,1 },
|
||||
{ 0,0,0,0,1 },
|
||||
{ 1,1,1,1,1 } },
|
||||
{ { 1,0,0,0,1 }, /* 4 */
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,1,1,1,1 },
|
||||
{ 0,0,0,0,1 },
|
||||
{ 0,0,0,0,1 } },
|
||||
{ { 1,1,1,1,1 }, /* 5 */
|
||||
{ 1,0,0,0,0 },
|
||||
{ 1,1,1,1,1 },
|
||||
{ 0,0,0,0,1 },
|
||||
{ 1,1,1,1,1 } },
|
||||
{ { 1,1,1,1,1 }, /* 6 */
|
||||
{ 1,0,0,0,0 },
|
||||
{ 1,1,1,1,1 },
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,1,1,1,1 } },
|
||||
{ { 1,1,1,1,1 }, /* 7 */
|
||||
{ 0,0,0,0,1 },
|
||||
{ 0,0,0,0,1 },
|
||||
{ 0,0,0,0,1 },
|
||||
{ 0,0,0,0,1 } },
|
||||
{ { 1,1,1,1,1 }, /* 8 */
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,1,1,1,1 },
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,1,1,1,1 } },
|
||||
{ { 1,1,1,1,1 }, /* 9 */
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,1,1,1,1 },
|
||||
{ 0,0,0,0,1 },
|
||||
{ 1,1,1,1,1 } },
|
||||
{ { 0,0,0,0,0 }, /* : */
|
||||
{ 0,0,1,0,0 },
|
||||
{ 0,0,0,0,0 },
|
||||
{ 0,0,1,0,0 },
|
||||
{ 0,0,0,0,0 } },
|
||||
{ { 1,1,1,1,1 }, /* A */
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,1,1,1,1 },
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,0,0,0,1 } },
|
||||
{ { 1,1,1,1,1 }, /* P */
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,1,1,1,1 },
|
||||
{ 1,0,0,0,0 },
|
||||
{ 1,0,0,0,0 } },
|
||||
{ { 1,0,0,0,1 }, /* M */
|
||||
{ 1,1,0,1,1 },
|
||||
{ 1,0,1,0,1 },
|
||||
{ 1,0,0,0,1 },
|
||||
{ 1,0,0,0,1 } },
|
||||
};
|
||||
|
||||
void
|
||||
clock_draw(struct screen_write_ctx *ctx, u_int colour, int style)
|
||||
{
|
||||
struct screen *s = ctx->s;
|
||||
struct grid_cell gc;
|
||||
char tim[64], *ptr;
|
||||
time_t t;
|
||||
u_int i, j, x, y, idx;
|
||||
|
||||
t = time(NULL);
|
||||
if (style == 0)
|
||||
strftime(tim, sizeof tim, "%l:%M %p", localtime(&t));
|
||||
else
|
||||
strftime(tim, sizeof tim, "%H:%M", localtime(&t));
|
||||
|
||||
screen_write_clearscreen(ctx);
|
||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||
gc.fg = colour;
|
||||
|
||||
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);
|
||||
|
||||
gc.fg = 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;
|
||||
|
||||
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++) {
|
||||
screen_write_cursormove(ctx, x, y + j);
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (clock_table[idx][j][i])
|
||||
gc.attr |= GRID_ATTR_REVERSE;
|
||||
else
|
||||
gc.attr &= ~GRID_ATTR_REVERSE;
|
||||
screen_write_putc(ctx, &gc, ' ');
|
||||
}
|
||||
}
|
||||
x += 6;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-attach-session.c,v 1.26 2009-06-25 16:34:50 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,158 +18,62 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Attach existing session to the current terminal.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_attach_session_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_attach_session_entry = {
|
||||
.name = "attach-session",
|
||||
.alias = "attach",
|
||||
|
||||
.args = { "c:dEf:rt:x", 0, 0, NULL },
|
||||
.usage = "[-dErx] [-c working-directory] [-f flags] "
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
/* -t is special */
|
||||
|
||||
.flags = CMD_STARTSERVER|CMD_READONLY,
|
||||
.exec = cmd_attach_session_exec
|
||||
"attach-session", "attach",
|
||||
"[-d] " CMD_TARGET_SESSION_USAGE,
|
||||
CMD_DFLAG|CMD_CANTNEST|CMD_STARTSERVER,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_attach_session_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
int xflag, int rflag, const char *cflag, int Eflag, const char *fflag)
|
||||
int
|
||||
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_find_state *current = cmdq_get_current(item);
|
||||
struct cmd_find_state target;
|
||||
enum cmd_find_type type;
|
||||
int flags;
|
||||
struct client *c = cmdq_get_client(item), *c_loop;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
char *cwd, *cause;
|
||||
enum msgtype msgtype;
|
||||
char *cause;
|
||||
|
||||
if (RB_EMPTY(&sessions)) {
|
||||
cmdq_error(item, "no sessions");
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (ctx->curclient != NULL)
|
||||
return (0);
|
||||
|
||||
if (ARRAY_LENGTH(&sessions) == 0) {
|
||||
ctx->error(ctx, "no sessions");
|
||||
return (-1);
|
||||
}
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||
ctx->error(ctx, "not a terminal");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (c == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (server_client_check_nested(c)) {
|
||||
cmdq_error(item, "sessions should be nested with care, "
|
||||
"unset $TMUX to force");
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (tty_open(&ctx->cmdclient->tty, &cause) != 0) {
|
||||
ctx->error(ctx, "terminal open failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') {
|
||||
type = CMD_FIND_PANE;
|
||||
flags = 0;
|
||||
} else {
|
||||
type = CMD_FIND_SESSION;
|
||||
flags = CMD_FIND_PREFER_UNATTACHED;
|
||||
}
|
||||
if (cmd_find_target(&target, item, tflag, type, flags) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
s = target.s;
|
||||
wl = target.wl;
|
||||
wp = target.wp;
|
||||
if (data->flags & CMD_DFLAG)
|
||||
server_write_session(s, MSG_DETACH, NULL, 0);
|
||||
ctx->cmdclient->session = s;
|
||||
|
||||
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);
|
||||
}
|
||||
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||
recalculate_sizes();
|
||||
server_redraw_client(ctx->cmdclient);
|
||||
|
||||
if (cflag != NULL) {
|
||||
cwd = format_single(item, cflag, c, s, wl, wp);
|
||||
free((void *)s->cwd);
|
||||
s->cwd = cwd;
|
||||
}
|
||||
if (fflag)
|
||||
server_client_set_flags(c, fflag);
|
||||
if (rflag)
|
||||
c->flags |= (CLIENT_READONLY|CLIENT_IGNORESIZE);
|
||||
|
||||
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;
|
||||
server_client_detach(c_loop, msgtype);
|
||||
}
|
||||
}
|
||||
if (!Eflag)
|
||||
environ_update(s->options, c->environ, s->environ);
|
||||
|
||||
server_client_set_session(c, s);
|
||||
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
||||
server_client_set_key_table(c, NULL);
|
||||
} else {
|
||||
if (server_client_open(c, &cause) != 0) {
|
||||
cmdq_error(item, "open terminal failed: %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
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;
|
||||
server_client_detach(c_loop, msgtype);
|
||||
}
|
||||
}
|
||||
if (!Eflag)
|
||||
environ_update(s->options, c->environ, s->environ);
|
||||
|
||||
server_client_set_session(c, s);
|
||||
server_client_set_key_table(c, NULL);
|
||||
|
||||
if (~c->flags & CLIENT_CONTROL)
|
||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
||||
notify_client("client-attached", c);
|
||||
c->flags |= CLIENT_ATTACHED;
|
||||
}
|
||||
|
||||
if (cfg_finished)
|
||||
cfg_show_causes(s);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
|
||||
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'), args_get(args, 'f')));
|
||||
return (1);
|
||||
}
|
||||
|
||||
196
cmd-bind-key.c
196
cmd-bind-key.c
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-bind-key.c,v 1.21 2009-05-04 17:58:26 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,90 +18,140 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Bind a key to a command.
|
||||
* Bind a key to a command, this recurses through cmd_*.
|
||||
*/
|
||||
|
||||
static enum args_parse_type cmd_bind_key_args_parse(struct args *, u_int,
|
||||
char **);
|
||||
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_send(struct cmd *, struct buffer *);
|
||||
void cmd_bind_key_recv(struct cmd *, struct buffer *);
|
||||
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 = {
|
||||
.name = "bind-key",
|
||||
.alias = "bind",
|
||||
|
||||
.args = { "nrN:T:", 1, -1, cmd_bind_key_args_parse },
|
||||
.usage = "[-nr] [-T key-table] [-N note] key "
|
||||
"[command [argument ...]]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_bind_key_exec
|
||||
struct cmd_bind_key_data {
|
||||
int key;
|
||||
int can_repeat;
|
||||
struct cmd_list *cmdlist;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_bind_key_args_parse(__unused struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
const struct cmd_entry cmd_bind_key_entry = {
|
||||
"bind-key", "bind",
|
||||
"[-r] key command [arguments]",
|
||||
0,
|
||||
NULL,
|
||||
cmd_bind_key_parse,
|
||||
cmd_bind_key_exec,
|
||||
cmd_bind_key_send,
|
||||
cmd_bind_key_recv,
|
||||
cmd_bind_key_free,
|
||||
cmd_bind_key_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_bind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
struct cmd_bind_key_data *data;
|
||||
int opt;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->can_repeat = 0;
|
||||
data->cmdlist = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "r")) != -1) {
|
||||
switch (opt) {
|
||||
case 'r':
|
||||
data->can_repeat = 1;
|
||||
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;
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if ((data->cmdlist = cmd_list_parse(argc, argv, cause)) == NULL)
|
||||
goto error;
|
||||
|
||||
return (0);
|
||||
|
||||
usage:
|
||||
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||
|
||||
error:
|
||||
self->entry->free(self);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_bind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
key_code key;
|
||||
const char *tablename, *note = args_get(args, 'N');
|
||||
struct cmd_parse_result *pr;
|
||||
int repeat;
|
||||
struct args_value *value;
|
||||
u_int count = args_count(args);
|
||||
struct cmd_bind_key_data *data = self->data;
|
||||
|
||||
key = key_string_lookup_string(args_string(args, 0));
|
||||
if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
|
||||
cmdq_error(item, "unknown key: %s", args_string(args, 0));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (data == NULL)
|
||||
return (0);
|
||||
|
||||
if (args_has(args, 'T'))
|
||||
tablename = args_get(args, 'T');
|
||||
else if (args_has(args, 'n'))
|
||||
tablename = "root";
|
||||
else
|
||||
tablename = "prefix";
|
||||
repeat = args_has(args, 'r');
|
||||
key_bindings_add(data->key, data->can_repeat, data->cmdlist);
|
||||
data->cmdlist = NULL; /* avoid free */
|
||||
|
||||
if (count == 1) {
|
||||
key_bindings_add(tablename, key, note, repeat, NULL);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
value = args_value(args, 1);
|
||||
if (count == 2 && value->type == ARGS_COMMANDS) {
|
||||
key_bindings_add(tablename, key, note, repeat, value->cmdlist);
|
||||
value->cmdlist->references++;
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (count == 2)
|
||||
pr = cmd_parse_from_string(args_string(args, 1), NULL);
|
||||
else {
|
||||
pr = cmd_parse_from_arguments(args_values(args) + 1, count - 1,
|
||||
NULL);
|
||||
}
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_ERROR:
|
||||
cmdq_error(item, "%s", pr->error);
|
||||
free(pr->error);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_PARSE_SUCCESS:
|
||||
break;
|
||||
}
|
||||
key_bindings_add(tablename, key, note, repeat, pr->cmdlist);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_bind_key_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_bind_key_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_list_send(data->cmdlist, b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_bind_key_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_bind_key_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->cmdlist = cmd_list_recv(b);
|
||||
}
|
||||
|
||||
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);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_bind_key_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_bind_key_data *data = self->data;
|
||||
size_t off = 0;
|
||||
const char *skey;
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return (off);
|
||||
if (off < len) {
|
||||
skey = key_string_lookup_key(data->key);
|
||||
off += xsnprintf(buf + off, len - off, " %s ", skey);
|
||||
}
|
||||
if (off < len)
|
||||
off += cmd_list_print(data->cmdlist, buf + off, len - off);
|
||||
return (off);
|
||||
}
|
||||
|
||||
157
cmd-break-pane.c
157
cmd-break-pane.c
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-break-pane.c,v 1.3 2009-05-18 21:01: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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -26,122 +26,67 @@
|
||||
* Break pane off into a window.
|
||||
*/
|
||||
|
||||
#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
||||
|
||||
static enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_break_pane_entry = {
|
||||
.name = "break-pane",
|
||||
.alias = "breakp",
|
||||
|
||||
.args = { "abdPF:n:s:t:", 0, 0, NULL },
|
||||
.usage = "[-abdP] [-F format] [-n window-name] [-s src-pane] "
|
||||
"[-t dst-window]",
|
||||
|
||||
.source = { 's', CMD_FIND_PANE, 0 },
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_break_pane_exec
|
||||
"break-pane", "breakp",
|
||||
CMD_PANE_WINDOW_USAGE " [-d]",
|
||||
CMD_DFLAG,
|
||||
cmd_pane_init,
|
||||
cmd_pane_parse,
|
||||
cmd_break_pane_exec,
|
||||
cmd_pane_send,
|
||||
cmd_pane_recv,
|
||||
cmd_pane_free,
|
||||
cmd_pane_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *current = cmdq_get_current(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct cmd_find_state *source = cmdq_get_source(item);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct winlink *wl = source->wl;
|
||||
struct session *src_s = source->s;
|
||||
struct session *dst_s = target->s;
|
||||
struct window_pane *wp = source->wp;
|
||||
struct window *w = wl->window;
|
||||
char *name, *cause, *cp;
|
||||
int idx = target->idx, before;
|
||||
const char *template;
|
||||
struct cmd_pane_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
struct window_pane *wp;
|
||||
struct window *w;
|
||||
char *cause;
|
||||
|
||||
before = args_has(args, 'b');
|
||||
if (args_has(args, 'a') || before) {
|
||||
if (target->wl != NULL)
|
||||
idx = winlink_shuffle_up(dst_s, target->wl, before);
|
||||
else
|
||||
idx = winlink_shuffle_up(dst_s, dst_s->curw, before);
|
||||
if (idx == -1)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
server_unzoom_window(w);
|
||||
|
||||
if (window_count_panes(w) == 1) {
|
||||
if (server_link_window(src_s, wl, dst_s, idx, 0,
|
||||
!args_has(args, 'd'), &cause) != 0) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
return (-1);
|
||||
if (data->pane == -1)
|
||||
wp = wl->window->active;
|
||||
else {
|
||||
wp = window_pane_at_index(wl->window, data->pane);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
if (args_has(args, 'n')) {
|
||||
window_set_name(w, args_get(args, 'n'));
|
||||
options_set_number(w->options, "automatic-rename", 0);
|
||||
}
|
||||
server_unlink_window(src_s, wl);
|
||||
wl = winlink_find_by_window(&dst_s->windows, w);
|
||||
if (wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto out;
|
||||
}
|
||||
if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) {
|
||||
cmdq_error(item, "index in use: %d", idx);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
server_client_remove_pane(wp);
|
||||
window_lost_pane(w, wp);
|
||||
layout_close_pane(wp);
|
||||
|
||||
w = wp->window = window_create(w->sx, w->sy, w->xpixel, w->ypixel);
|
||||
options_set_parent(wp->options, w->options);
|
||||
wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
w->active = wp;
|
||||
w->latest = tc;
|
||||
|
||||
if (!args_has(args, 'n')) {
|
||||
name = default_window_name(w);
|
||||
window_set_name(w, name);
|
||||
free(name);
|
||||
} else {
|
||||
window_set_name(w, args_get(args, 'n'));
|
||||
options_set_number(w->options, "automatic-rename", 0);
|
||||
if (window_count_panes(wl->window) == 1) {
|
||||
ctx->error(ctx, "can't break pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
layout_init(w, wp);
|
||||
wp->flags |= PANE_CHANGED;
|
||||
colour_palette_from_option(&wp->palette, wp->options);
|
||||
|
||||
if (idx == -1)
|
||||
idx = -1 - options_get_number(dst_s->options, "base-index");
|
||||
wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
|
||||
if (!args_has(args, 'd')) {
|
||||
session_select(dst_s, wl->idx);
|
||||
cmd_find_from_session(current, dst_s, 0);
|
||||
TAILQ_REMOVE(&wl->window->panes, wp, entry);
|
||||
if (wl->window->active == wp) {
|
||||
wl->window->active = TAILQ_PREV(wp, window_panes, entry);
|
||||
if (wl->window->active == NULL)
|
||||
wl->window->active = TAILQ_NEXT(wp, entry);
|
||||
}
|
||||
layout_refresh(wl->window, 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);
|
||||
w = wp->window = window_create1(s->sx, s->sy);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
w->active = wp;
|
||||
w->name = default_window_name(w);
|
||||
|
||||
out:
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = BREAK_PANE_TEMPLATE;
|
||||
cp = format_single(item, template, tc, dst_s, wl, wp);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
wl = session_attach(s, w, -1, &cause); /* can't fail */
|
||||
if (!(data->flags & CMD_DFLAG))
|
||||
session_select(s, wl->idx);
|
||||
layout_refresh(w, 0);
|
||||
|
||||
server_redraw_session(s);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,267 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Write the entire contents of a pane to a buffer or stdout.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
|
||||
static char *cmd_capture_pane_pending(struct args *, struct window_pane *,
|
||||
size_t *);
|
||||
static char *cmd_capture_pane_history(struct args *, struct cmdq_item *,
|
||||
struct window_pane *, size_t *);
|
||||
|
||||
const struct cmd_entry cmd_capture_pane_entry = {
|
||||
.name = "capture-pane",
|
||||
.alias = "capturep",
|
||||
|
||||
.args = { "ab:CeE:JMNpPqS:Tt:", 0, 0, NULL },
|
||||
.usage = "[-aCeJMNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
|
||||
"[-S start-line] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_capture_pane_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_clear_history_entry = {
|
||||
.name = "clear-history",
|
||||
.alias = "clearhist",
|
||||
|
||||
.args = { "Ht:", 0, 0, NULL },
|
||||
.usage = "[-H] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_capture_pane_exec
|
||||
};
|
||||
|
||||
static char *
|
||||
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
|
||||
{
|
||||
buf = xrealloc(buf, *len + linelen + 1);
|
||||
memcpy(buf + *len, line, linelen);
|
||||
*len += linelen;
|
||||
return (buf);
|
||||
}
|
||||
|
||||
static char *
|
||||
cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
|
||||
size_t *len)
|
||||
{
|
||||
struct evbuffer *pending;
|
||||
char *buf, *line, tmp[5];
|
||||
size_t linelen;
|
||||
u_int i;
|
||||
|
||||
pending = input_pending(wp->ictx);
|
||||
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 screen *s;
|
||||
struct grid_cell *gc = NULL;
|
||||
struct window_mode_entry *wme;
|
||||
int n, join_lines, flags = 0;
|
||||
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->base.saved_grid;
|
||||
if (gd == NULL) {
|
||||
if (!args_has(args, 'q')) {
|
||||
cmdq_error(item, "no alternate screen");
|
||||
return (NULL);
|
||||
}
|
||||
return (xstrdup(""));
|
||||
}
|
||||
s = &wp->base;
|
||||
} else if (args_has(args, 'M')) {
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme != NULL && wme->mode->get_screen != NULL) {
|
||||
s = wme->mode->get_screen (wme);
|
||||
gd = s->grid;
|
||||
} else {
|
||||
s = &wp->base;
|
||||
gd = wp->base.grid;
|
||||
}
|
||||
} else {
|
||||
s = &wp->base;
|
||||
gd = wp->base.grid;
|
||||
}
|
||||
|
||||
Sflag = args_get(args, 'S');
|
||||
if (Sflag != NULL && strcmp(Sflag, "-") == 0)
|
||||
top = 0;
|
||||
else {
|
||||
n = args_strtonum_and_expand(args, 'S', INT_MIN, SHRT_MAX,
|
||||
item, &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_and_expand(args, 'E', INT_MIN, SHRT_MAX,
|
||||
item, &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;
|
||||
}
|
||||
|
||||
join_lines = args_has(args, 'J');
|
||||
if (args_has(args, 'e'))
|
||||
flags |= GRID_STRING_WITH_SEQUENCES;
|
||||
if (args_has(args, 'C'))
|
||||
flags |= GRID_STRING_ESCAPE_SEQUENCES;
|
||||
if (!join_lines && !args_has(args, 'T'))
|
||||
flags |= GRID_STRING_EMPTY_CELLS;
|
||||
if (!join_lines && !args_has(args, 'N'))
|
||||
flags |= GRID_STRING_TRIM_SPACES;
|
||||
|
||||
buf = NULL;
|
||||
for (i = top; i <= bottom; i++) {
|
||||
line = grid_string_cells(gd, 0, i, sx, &gc, flags, s);
|
||||
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 = cmd_get_args(self);
|
||||
struct client *c = cmdq_get_client(item);
|
||||
struct window_pane *wp = cmdq_get_target(item)->wp;
|
||||
char *buf, *cause;
|
||||
const char *bufname;
|
||||
size_t len;
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_clear_history_entry) {
|
||||
window_pane_reset_mode_all(wp);
|
||||
grid_clear_history(wp->base.grid);
|
||||
if (args_has(args, 'H'))
|
||||
screen_reset_hyperlinks(wp->screen);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
len = 0;
|
||||
if (args_has(args, 'P'))
|
||||
buf = cmd_capture_pane_pending(args, wp, &len);
|
||||
else
|
||||
buf = cmd_capture_pane_history(args, item, wp, &len);
|
||||
if (buf == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (args_has(args, 'p')) {
|
||||
if (len > 0 && buf[len - 1] == '\n')
|
||||
len--;
|
||||
if (c->flags & CLIENT_CONTROL)
|
||||
control_write(c, "%.*s", (int)len, buf);
|
||||
else {
|
||||
if (!file_can_print(c)) {
|
||||
cmdq_error(item, "can't write to client");
|
||||
free(buf);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
file_print_buffer(c, buf, len);
|
||||
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) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
free(buf);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
107
cmd-choose-session.c
Normal file
107
cmd-choose-session.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/* $Id: cmd-choose-session.c,v 1.7 2009-05-04 17:58:26 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 "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);
|
||||
|
||||
const struct cmd_entry cmd_choose_session_entry = {
|
||||
"choose-session", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_choose_session_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
struct cmd_choose_session_data {
|
||||
u_int client;
|
||||
};
|
||||
|
||||
int
|
||||
cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct cmd_choose_session_data *cdata;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
u_int i, idx, cur;
|
||||
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||
return (0);
|
||||
|
||||
cur = idx = 0;
|
||||
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||
s = ARRAY_ITEM(&sessions, i);
|
||||
if (s == NULL)
|
||||
continue;
|
||||
if (s == ctx->curclient->session)
|
||||
cur = idx;
|
||||
idx++;
|
||||
|
||||
window_choose_add(wl->window->active, i,
|
||||
"%s: %u windows [%ux%u]%s", s->name,
|
||||
winlink_count(&s->windows), s->sx, s->sy,
|
||||
s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||
}
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->client = server_client_index(ctx->curclient);
|
||||
|
||||
window_choose_ready(
|
||||
wl->window->active, cur, cmd_choose_session_callback, cdata);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_session_callback(void *data, int idx)
|
||||
{
|
||||
struct cmd_choose_session_data *cdata = data;
|
||||
struct client *c;
|
||||
|
||||
if (idx != -1 && cdata->client <= ARRAY_LENGTH(&clients) - 1) {
|
||||
c = ARRAY_ITEM(&clients, cdata->client);
|
||||
if (c != NULL && (u_int) idx <= ARRAY_LENGTH(&sessions) - 1) {
|
||||
c->session = ARRAY_ITEM(&sessions, idx);
|
||||
recalculate_sizes();
|
||||
server_redraw_client(c);
|
||||
}
|
||||
}
|
||||
xfree(cdata);
|
||||
}
|
||||
@@ -1,124 +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 args_parse_type cmd_choose_tree_args_parse(struct args *args,
|
||||
u_int idx, char **cause);
|
||||
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:f:GK:NO:rst:wyZ", 0, 1, cmd_choose_tree_args_parse },
|
||||
.usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] "
|
||||
"[-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:K:NO:rt:yZ", 0, 1, cmd_choose_tree_args_parse },
|
||||
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
|
||||
"[-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:K:NO:rt:yZ", 0, 1, cmd_choose_tree_args_parse },
|
||||
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
|
||||
"[-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_customize_mode_entry = {
|
||||
.name = "customize-mode",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:f:Nt:yZ", 0, 0, NULL },
|
||||
.usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_choose_tree_exec
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_choose_tree_args_parse(__unused struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct window_pane *wp = target->wp;
|
||||
const struct window_mode *mode;
|
||||
enum sort_order order;
|
||||
|
||||
order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_choose_buffer_entry) {
|
||||
if (paste_is_empty())
|
||||
return (CMD_RETURN_NORMAL);
|
||||
mode = &window_buffer_mode;
|
||||
} else if (cmd_get_entry(self) == &cmd_choose_client_entry) {
|
||||
if (server_client_how_many() == 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
mode = &window_client_mode;
|
||||
} else if (cmd_get_entry(self) == &cmd_customize_mode_entry)
|
||||
mode = &window_customize_mode;
|
||||
else
|
||||
mode = &window_tree_mode;
|
||||
|
||||
window_pane_set_mode(wp, NULL, mode, target, args);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
106
cmd-choose-window.c
Normal file
106
cmd-choose-window.c
Normal file
@@ -0,0 +1,106 @@
|
||||
/* $Id: cmd-choose-window.c,v 1.9 2009-05-04 17:58:26 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 "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);
|
||||
|
||||
const struct cmd_entry cmd_choose_window_entry = {
|
||||
"choose-window", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_choose_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
struct cmd_choose_window_data {
|
||||
u_int session;
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
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++;
|
||||
|
||||
window_choose_add(wl->window->active,
|
||||
wm->idx, "%3d: %s [%ux%u %s] (%u panes)", wm->idx, w->name,
|
||||
w->sx, w->sy, layout_name(w), window_count_panes(w));
|
||||
}
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
if (session_index(s, &cdata->session) != 0)
|
||||
fatalx("session not found");
|
||||
|
||||
window_choose_ready(
|
||||
wl->window->active, cur, cmd_choose_window_callback, cdata);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_window_callback(void *data, int idx)
|
||||
{
|
||||
struct cmd_choose_window_data *cdata = data;
|
||||
struct session *s;
|
||||
|
||||
if (idx != -1 && cdata->session <= ARRAY_LENGTH(&sessions) - 1) {
|
||||
s = ARRAY_ITEM(&sessions, cdata->session);
|
||||
if (s != NULL && session_select(s, idx) == 0)
|
||||
server_redraw_session(s);
|
||||
recalculate_sizes();
|
||||
}
|
||||
xfree(cdata);
|
||||
}
|
||||
67
cmd-clear-history.c
Normal file
67
cmd-clear-history.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/* $Id: cmd-clear-history.c,v 1.3 2009-06-25 16:21:32 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 "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_PANE_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_pane_init,
|
||||
cmd_pane_parse,
|
||||
cmd_clear_history_exec,
|
||||
cmd_pane_send,
|
||||
cmd_pane_recv,
|
||||
cmd_pane_free,
|
||||
cmd_pane_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
struct grid *gd;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
if (data->pane == -1)
|
||||
wp = wl->window->active;
|
||||
else {
|
||||
wp = window_pane_at_index(wl->window, data->pane);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
gd = wp->base.grid;
|
||||
|
||||
grid_move_lines(gd, 0, gd->hsize, gd->sy);
|
||||
gd->hsize = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
/* $Id: cmd-clock-mode.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010 Dagobert Michelsen
|
||||
* Copyright (c) 2010 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -17,33 +18,37 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "tmux.h"
|
||||
|
||||
#include "compat.h"
|
||||
/*
|
||||
* Enter clock mode.
|
||||
*/
|
||||
|
||||
int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_clock_mode_entry = {
|
||||
"clock-mode", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_clock_mode_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
setenv(const char *name, const char *value, __unused int overwrite)
|
||||
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
char *newval;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
|
||||
xasprintf(&newval, "%s=%s", name, value);
|
||||
return (putenv(newval));
|
||||
}
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
int
|
||||
unsetenv(const char *name)
|
||||
{
|
||||
char **envptr;
|
||||
int namelen;
|
||||
window_pane_set_mode(wl->window->active, &window_clock_mode);
|
||||
|
||||
namelen = strlen(name);
|
||||
for (envptr = environ; *envptr != NULL; envptr++) {
|
||||
if (strncmp(name, *envptr, namelen) == 0 &&
|
||||
((*envptr)[namelen] == '=' || (*envptr)[namelen] == '\0'))
|
||||
break;
|
||||
}
|
||||
for (; *envptr != NULL; envptr++)
|
||||
*envptr = *(envptr + 1);
|
||||
return (0);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-command-prompt.c,v 1.16 2009-02-16 18:58:14 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -19,9 +19,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -29,222 +27,152 @@
|
||||
* Prompt for command in client.
|
||||
*/
|
||||
|
||||
static enum args_parse_type cmd_command_prompt_args_parse(struct args *,
|
||||
u_int, char **);
|
||||
static enum cmd_retval cmd_command_prompt_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
void cmd_command_prompt_init(struct cmd *, int);
|
||||
int cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
static int cmd_command_prompt_callback(struct client *, void *,
|
||||
const char *, int);
|
||||
static void cmd_command_prompt_free(void *);
|
||||
int cmd_command_prompt_callback(void *, const char *);
|
||||
|
||||
const struct cmd_entry cmd_command_prompt_entry = {
|
||||
.name = "command-prompt",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "1beFiklI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
|
||||
.usage = "[-1beFiklN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
|
||||
" [-T prompt-type] [template]",
|
||||
|
||||
.flags = CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_command_prompt_exec
|
||||
"command-prompt", NULL,
|
||||
CMD_TARGET_CLIENT_USAGE " [template]",
|
||||
CMD_ARG01,
|
||||
cmd_command_prompt_init,
|
||||
cmd_target_parse,
|
||||
cmd_command_prompt_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
struct cmd_command_prompt_prompt {
|
||||
char *input;
|
||||
char *prompt;
|
||||
struct cmd_command_prompt_data {
|
||||
struct client *c;
|
||||
char *template;
|
||||
};
|
||||
|
||||
struct cmd_command_prompt_cdata {
|
||||
struct cmdq_item *item;
|
||||
struct args_command_state *state;
|
||||
|
||||
int flags;
|
||||
enum prompt_type prompt_type;
|
||||
|
||||
struct cmd_command_prompt_prompt *prompts;
|
||||
u_int count;
|
||||
u_int current;
|
||||
|
||||
int argc;
|
||||
char **argv;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_command_prompt_args_parse(__unused struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
void
|
||||
cmd_command_prompt_init(struct cmd *self, int key)
|
||||
{
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
struct cmd_target_data *data;
|
||||
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
switch (key) {
|
||||
case ',':
|
||||
data->arg = xstrdup("rename-window '%%'");
|
||||
break;
|
||||
case '.':
|
||||
data->arg = xstrdup("move-window -t '%%'");
|
||||
break;
|
||||
case 'f':
|
||||
data->arg = xstrdup("find-window '%%'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
const char *type, *s, *input;
|
||||
struct cmd_command_prompt_cdata *cdata;
|
||||
char *tmp, *prompts, *prompt, *next_prompt;
|
||||
char *inputs = NULL, *next_input;
|
||||
u_int count = args_count(args);
|
||||
int wait = !args_has(args, 'b'), space = 1;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct cmd_command_prompt_data *cdata;
|
||||
struct client *c;
|
||||
char *hdr, *ptr;
|
||||
|
||||
if (tc->prompt_string != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (args_has(args, 'i'))
|
||||
wait = 0;
|
||||
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
if (wait)
|
||||
cdata->item = item;
|
||||
cdata->state = args_make_commands_prepare(self, item, 0, "%1", wait,
|
||||
args_has(args, 'F'));
|
||||
if (c->prompt_string != NULL)
|
||||
return (0);
|
||||
|
||||
if ((s = args_get(args, 'p')) == NULL) {
|
||||
if (count != 0) {
|
||||
tmp = args_make_commands_get_command(cdata->state);
|
||||
xasprintf(&prompts, "(%s)", tmp);
|
||||
free(tmp);
|
||||
} else {
|
||||
prompts = xstrdup(":");
|
||||
space = 0;
|
||||
}
|
||||
next_prompt = prompts;
|
||||
} else
|
||||
next_prompt = prompts = xstrdup(s);
|
||||
if ((s = args_get(args, 'I')) != NULL)
|
||||
next_input = inputs = xstrdup(s);
|
||||
else
|
||||
next_input = NULL;
|
||||
if (args_has(args, 'l')) {
|
||||
cdata->prompts = xcalloc(1, sizeof *cdata->prompts);
|
||||
cdata->prompts[0].prompt = prompts;
|
||||
cdata->prompts[0].input = inputs;
|
||||
cdata->count = 1;
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->c = c;
|
||||
if (data->arg != NULL) {
|
||||
cdata->template = xstrdup(data->arg);
|
||||
if ((ptr = strchr(data->arg, ' ')) == NULL)
|
||||
ptr = strchr(data->arg, '\0');
|
||||
xasprintf(&hdr, "(%.*s) ", (int) (ptr - data->arg), data->arg);
|
||||
} else {
|
||||
while ((prompt = strsep(&next_prompt, ",")) != NULL) {
|
||||
cdata->prompts = xreallocarray(cdata->prompts,
|
||||
cdata->count + 1, sizeof *cdata->prompts);
|
||||
if (!space)
|
||||
tmp = xstrdup(prompt);
|
||||
else
|
||||
xasprintf(&tmp, "%s ", prompt);
|
||||
cdata->prompts[cdata->count].prompt = tmp;
|
||||
|
||||
if (next_input != NULL) {
|
||||
input = strsep(&next_input, ",");
|
||||
if (input == NULL)
|
||||
input = "";
|
||||
} else
|
||||
input = "";
|
||||
cdata->prompts[cdata->count].input = xstrdup(input);
|
||||
cdata->count++;
|
||||
}
|
||||
free(inputs);
|
||||
free(prompts);
|
||||
cdata->template = NULL;
|
||||
hdr = xstrdup(":");
|
||||
}
|
||||
status_prompt_set(c, hdr, cmd_command_prompt_callback, cdata, 0);
|
||||
xfree(hdr);
|
||||
|
||||
if ((type = args_get(args, 'T')) != NULL) {
|
||||
cdata->prompt_type = status_prompt_type(type);
|
||||
if (cdata->prompt_type == PROMPT_TYPE_INVALID) {
|
||||
cmdq_error(item, "unknown type: %s", type);
|
||||
cmd_command_prompt_free(cdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else
|
||||
cdata->prompt_type = PROMPT_TYPE_COMMAND;
|
||||
|
||||
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;
|
||||
else if (args_has(args, 'e'))
|
||||
cdata->flags |= PROMPT_BSPACE_EXIT;
|
||||
status_prompt_set(tc, target, cdata->prompts[0].prompt,
|
||||
cdata->prompts[0].input, cmd_command_prompt_callback,
|
||||
cmd_command_prompt_free, cdata, cdata->flags, cdata->prompt_type);
|
||||
|
||||
if (!wait)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_command_prompt_callback(struct client *c, void *data, const char *s,
|
||||
int done)
|
||||
{
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
char *error;
|
||||
struct cmdq_item *item = cdata->item, *new_item;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_command_prompt_prompt *prompt;
|
||||
int argc = 0;
|
||||
char **argv = NULL;
|
||||
|
||||
if (s == NULL)
|
||||
goto out;
|
||||
|
||||
if (done) {
|
||||
if (cdata->flags & PROMPT_INCREMENTAL)
|
||||
goto out;
|
||||
cmd_append_argv(&cdata->argc, &cdata->argv, s);
|
||||
if (++cdata->current != cdata->count) {
|
||||
prompt = &cdata->prompts[cdata->current];
|
||||
status_prompt_update(c, prompt->prompt, prompt->input);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
argc = cdata->argc;
|
||||
argv = cmd_copy_argv(cdata->argc, cdata->argv);
|
||||
if (!done)
|
||||
cmd_append_argv(&argc, &argv, s);
|
||||
|
||||
if (done) {
|
||||
cmd_free_argv(cdata->argc, cdata->argv);
|
||||
cdata->argc = argc;
|
||||
cdata->argv = cmd_copy_argv(argc, argv);
|
||||
}
|
||||
|
||||
cmdlist = args_make_commands(cdata->state, argc, argv, &error);
|
||||
if (cmdlist == NULL) {
|
||||
cmdq_append(c, cmdq_get_error(error));
|
||||
free(error);
|
||||
} else if (item == NULL) {
|
||||
new_item = cmdq_get_command(cmdlist, NULL);
|
||||
cmdq_append(c, new_item);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
cmd_free_argv(argc, argv);
|
||||
|
||||
if (c->prompt_inputcb != cmd_command_prompt_callback)
|
||||
return (1);
|
||||
|
||||
out:
|
||||
if (item != NULL)
|
||||
cmdq_continue(item);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_command_prompt_free(void *data)
|
||||
int
|
||||
cmd_command_prompt_callback(void *data, const char *s)
|
||||
{
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
u_int i;
|
||||
struct cmd_command_prompt_data *cdata = data;
|
||||
struct client *c = cdata->c;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
char *cause, *ptr, *buf, ch;
|
||||
size_t len, slen;
|
||||
|
||||
for (i = 0; i < cdata->count; i++) {
|
||||
free(cdata->prompts[i].prompt);
|
||||
free(cdata->prompts[i].input);
|
||||
if (s == NULL) {
|
||||
xfree(cdata);
|
||||
return (0);
|
||||
}
|
||||
free(cdata->prompts);
|
||||
cmd_free_argv(cdata->argc, cdata->argv);
|
||||
args_make_commands_free(cdata->state);
|
||||
free(cdata);
|
||||
slen = strlen(s);
|
||||
|
||||
len = 0;
|
||||
buf = NULL;
|
||||
if (cdata->template != NULL) {
|
||||
ptr = cdata->template;
|
||||
while (*ptr != '\0') {
|
||||
switch (ch = *ptr++) {
|
||||
case '%':
|
||||
if (*ptr != '%')
|
||||
break;
|
||||
ptr++;
|
||||
|
||||
buf = xrealloc(buf, 1, len + slen + 1);
|
||||
memcpy(buf + len, s, slen);
|
||||
len += slen;
|
||||
break;
|
||||
default:
|
||||
buf = xrealloc(buf, 1, len + 2);
|
||||
buf[len++] = ch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
xfree(cdata->template);
|
||||
|
||||
buf[len] = '\0';
|
||||
s = buf;
|
||||
}
|
||||
xfree(cdata);
|
||||
|
||||
if (cmd_string_parse(s, &cmdlist, &cause) != 0) {
|
||||
if (cause == NULL)
|
||||
return (0);
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(c, cause);
|
||||
xfree(cause);
|
||||
cmdlist = NULL;
|
||||
}
|
||||
if (buf != NULL)
|
||||
xfree(buf);
|
||||
if (cmdlist == NULL)
|
||||
return (0);
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.cursession = c->session;
|
||||
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);
|
||||
|
||||
if (c->prompt_callback != (void *) &cmd_command_prompt_callback)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-confirm-before.c,v 1.4 2009-04-28 18:29:44 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
@@ -28,137 +25,117 @@
|
||||
* Asks for confirmation before executing a command.
|
||||
*/
|
||||
|
||||
static enum args_parse_type cmd_confirm_before_args_parse(struct args *,
|
||||
u_int, char **);
|
||||
static enum cmd_retval cmd_confirm_before_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
int cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_confirm_before_init(struct cmd *, int);
|
||||
|
||||
static int cmd_confirm_before_callback(struct client *, void *,
|
||||
const char *, int);
|
||||
static void cmd_confirm_before_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_confirm_before_entry = {
|
||||
.name = "confirm-before",
|
||||
.alias = "confirm",
|
||||
|
||||
.args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse },
|
||||
.usage = "[-by] [-c confirm-key] [-p prompt] " CMD_TARGET_CLIENT_USAGE
|
||||
" command",
|
||||
|
||||
.flags = CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_confirm_before_exec
|
||||
};
|
||||
int cmd_confirm_before_callback(void *, const char *);
|
||||
|
||||
struct cmd_confirm_before_data {
|
||||
struct cmdq_item *item;
|
||||
struct cmd_list *cmdlist;
|
||||
u_char confirm_key;
|
||||
int default_yes;
|
||||
struct client *c;
|
||||
char *cmd;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_confirm_before_args_parse(__unused struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
const struct cmd_entry cmd_confirm_before_entry = {
|
||||
"confirm-before", "confirm",
|
||||
CMD_TARGET_CLIENT_USAGE " command",
|
||||
CMD_ARG1,
|
||||
cmd_confirm_before_init,
|
||||
cmd_target_parse,
|
||||
cmd_confirm_before_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
void
|
||||
cmd_confirm_before_init(struct cmd *self, int key)
|
||||
{
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_confirm_before_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct cmd_confirm_before_data *cdata;
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
char *new_prompt;
|
||||
const char *confirm_key, *prompt, *cmd;
|
||||
int wait = !args_has(args, 'b');
|
||||
struct client *c;
|
||||
char *buf, *cmd, *ptr;
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->cmdlist = args_make_commands_now(self, item, 0, 1);
|
||||
if (cdata->cmdlist == NULL) {
|
||||
free(cdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (wait)
|
||||
cdata->item = item;
|
||||
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
cdata->default_yes = args_has(args, 'y');
|
||||
if ((confirm_key = args_get(args, 'c')) != NULL) {
|
||||
if (confirm_key[1] == '\0' &&
|
||||
confirm_key[0] > 31 &&
|
||||
confirm_key[0] < 127)
|
||||
cdata->confirm_key = confirm_key[0];
|
||||
else {
|
||||
cmdq_error(item, "invalid confirm key");
|
||||
cmd_list_free(cdata->cmdlist);
|
||||
free(cdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
cdata->confirm_key = 'y';
|
||||
ptr = xstrdup(data->arg);
|
||||
if ((cmd = strtok(ptr, " \t")) == NULL)
|
||||
cmd = ptr;
|
||||
xasprintf(&buf, "Confirm '%s'? (y/n) ", cmd);
|
||||
xfree(ptr);
|
||||
|
||||
if ((prompt = args_get(args, 'p')) != NULL)
|
||||
xasprintf(&new_prompt, "%s ", prompt);
|
||||
else {
|
||||
cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name;
|
||||
xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ", cmd,
|
||||
cdata->confirm_key);
|
||||
}
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->cmd = xstrdup(data->arg);
|
||||
cdata->c = c;
|
||||
status_prompt_set(
|
||||
cdata->c, buf, cmd_confirm_before_callback, cdata, PROMPT_SINGLE);
|
||||
|
||||
status_prompt_set(tc, target, new_prompt, NULL,
|
||||
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
||||
PROMPT_SINGLE, PROMPT_TYPE_COMMAND);
|
||||
free(new_prompt);
|
||||
|
||||
if (!wait)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
xfree(buf);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_confirm_before_callback(struct client *c, void *data, const char *s,
|
||||
__unused int done)
|
||||
int
|
||||
cmd_confirm_before_callback(void *data, const char *s)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
struct cmdq_item *item = cdata->item, *new_item;
|
||||
int retcode = 1;
|
||||
struct client *c = cdata->c;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
char *cause;
|
||||
|
||||
if (c->flags & CLIENT_DEAD)
|
||||
if (s == NULL || tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||
goto out;
|
||||
|
||||
if (s == NULL)
|
||||
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(c, cause);
|
||||
xfree(cause);
|
||||
}
|
||||
goto out;
|
||||
if (s[0] != cdata->confirm_key && (s[0] != '\r' || !cdata->default_yes))
|
||||
goto out;
|
||||
retcode = 0;
|
||||
|
||||
if (item == NULL) {
|
||||
new_item = cmdq_get_command(cdata->cmdlist, NULL);
|
||||
cmdq_append(c, new_item);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cdata->cmdlist,
|
||||
cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.cursession = c->session;
|
||||
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);
|
||||
|
||||
out:
|
||||
if (item != NULL) {
|
||||
if (cmdq_get_client(item) != NULL &&
|
||||
cmdq_get_client(item)->session == NULL)
|
||||
cmdq_get_client(item)->retval = retcode;
|
||||
cmdq_continue(item);
|
||||
}
|
||||
if (cdata->cmd != NULL)
|
||||
xfree(cdata->cmd);
|
||||
xfree(cdata);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_confirm_before_free(void *data)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
|
||||
cmd_list_free(cdata->cmdlist);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
222
cmd-copy-buffer.c
Normal file
222
cmd-copy-buffer.c
Normal file
@@ -0,0 +1,222 @@
|
||||
/* $Id: cmd-copy-buffer.c,v 1.1 2009-02-03 17:21:19 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 <stdlib.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_send(struct cmd *, struct buffer *);
|
||||
void cmd_copy_buffer_recv(struct cmd *, struct buffer *);
|
||||
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_send,
|
||||
cmd_copy_buffer_recv,
|
||||
cmd_copy_buffer_free,
|
||||
cmd_copy_buffer_print
|
||||
};
|
||||
|
||||
void
|
||||
cmd_copy_buffer_init(struct cmd *self, unused int arg)
|
||||
{
|
||||
struct cmd_copy_buffer_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->dst_session = NULL;
|
||||
data->src_session = NULL;
|
||||
data->dst_idx = -1;
|
||||
data->src_idx = -1;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_copy_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_copy_buffer_data *data;
|
||||
const char *errstr;
|
||||
int n, opt;
|
||||
|
||||
self->entry->init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "a:b:s:t:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
if (data->src_idx == -1) {
|
||||
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(cause, "buffer %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
data->src_idx = n;
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
if (data->dst_idx == -1) {
|
||||
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(cause, "buffer %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
data->dst_idx = n;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if (data->src_session == NULL)
|
||||
data->src_session = xstrdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
if (data->dst_session == NULL)
|
||||
data->dst_session = xstrdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
return (0);
|
||||
|
||||
usage:
|
||||
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||
|
||||
error:
|
||||
self->entry->free(self);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_copy_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_copy_buffer_data *data = self->data;
|
||||
struct paste_buffer *pb;
|
||||
struct 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);
|
||||
|
||||
if (data->src_idx == -1) {
|
||||
if ((pb = paste_get_top(&src_session->buffers)) == NULL) {
|
||||
ctx->error(ctx, "no buffers");
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
if ((pb = paste_get_index(&src_session->buffers,
|
||||
data->src_idx)) == NULL) {
|
||||
ctx->error(ctx, "no buffer %d", data->src_idx);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
limit = options_get_number(&dst_session->options, "buffer-limit");
|
||||
if (data->dst_idx == -1) {
|
||||
paste_add(&dst_session->buffers, xstrdup(pb->data), limit);
|
||||
return (0);
|
||||
}
|
||||
if (paste_replace(&dst_session->buffers, data->dst_idx,
|
||||
xstrdup(pb->data)) != 0) {
|
||||
ctx->error(ctx, "no buffer %d", data->dst_idx);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_copy_buffer_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_copy_buffer_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->dst_session);
|
||||
cmd_send_string(b, data->src_session);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_copy_buffer_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_copy_buffer_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->dst_session = cmd_recv_string(b);
|
||||
data->src_session = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
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.19 2009-07-01 23:06: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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -21,83 +21,38 @@
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Enter copy or clock mode.
|
||||
* Enter copy mode.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmdq_item *);
|
||||
int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_copy_mode_entry = {
|
||||
.name = "copy-mode",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "deHMqSs:t:u", 0, 0, NULL },
|
||||
.usage = "[-deHMqSu] [-s src-pane] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_PANE, 0 },
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_READONLY,
|
||||
.exec = cmd_copy_mode_exec
|
||||
"copy-mode", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
CMD_UFLAG,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_copy_mode_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
NULL
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_clock_mode_entry = {
|
||||
.name = "clock-mode",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.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)
|
||||
int
|
||||
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct key_event *event = cmdq_get_event(item);
|
||||
struct cmd_find_state *source = cmdq_get_source(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct client *c = cmdq_get_client(item);
|
||||
struct session *s;
|
||||
struct window_pane *wp = target->wp, *swp;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
|
||||
if (args_has(args, 'q')) {
|
||||
window_pane_reset_mode_all(wp);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
wp = wl->window->active;
|
||||
|
||||
if (args_has(args, 'M')) {
|
||||
if ((wp = cmd_mouse_pane(&event->m, &s, NULL)) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (c == NULL || c->session != s)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
window_pane_set_mode(wp, &window_copy_mode);
|
||||
if (wp->mode == &window_copy_mode && data->flags & CMD_UFLAG)
|
||||
window_copy_pageup(wp);
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_clock_mode_entry) {
|
||||
window_pane_set_mode(wp, NULL, &window_clock_mode, NULL, NULL);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 's'))
|
||||
swp = source->wp;
|
||||
else
|
||||
swp = wp;
|
||||
if (!window_pane_set_mode(wp, swp, &window_copy_mode, NULL, args)) {
|
||||
if (args_has(args, 'M'))
|
||||
window_copy_start_drag(c, &event->m);
|
||||
}
|
||||
if (args_has(args, 'u'))
|
||||
window_copy_pageup(wp, 0);
|
||||
if (args_has(args, 'd'))
|
||||
window_copy_pagedown(wp, 0, args_has(args, 'e'));
|
||||
if (args_has(args, 'S')) {
|
||||
window_copy_scroll(wp, c->tty.mouse_slider_mpos, event->m.y,
|
||||
args_has(args, 'e'));
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
61
cmd-delete-buffer.c
Normal file
61
cmd-delete-buffer.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* $Id: cmd-delete-buffer.c,v 1.5 2009-05-04 17:58:26 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <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_send,
|
||||
cmd_buffer_recv,
|
||||
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.7 2009-01-19 18:23:40 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,92 +18,37 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Detach a client.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_detach_client_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_detach_client_entry = {
|
||||
.name = "detach-client",
|
||||
.alias = "detach",
|
||||
|
||||
.args = { "aE:s:t:P", 0, 0, NULL },
|
||||
.usage = "[-aP] [-E shell-command] "
|
||||
"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_READONLY|CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_detach_client_exec
|
||||
"detach-client", "detach",
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_detach_client_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_suspend_client_entry = {
|
||||
.name = "suspend-client",
|
||||
.alias = "suspendc",
|
||||
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.flags = CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_detach_client_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *source = cmdq_get_source(item);
|
||||
struct client *tc = cmdq_get_target_client(item), *loop;
|
||||
struct session *s;
|
||||
enum msgtype msgtype;
|
||||
const char *cmd = args_get(args, 'E');
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct client *c;
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_suspend_client_entry) {
|
||||
server_client_suspend(tc);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (args_has(args, 'P'))
|
||||
msgtype = MSG_DETACHKILL;
|
||||
else
|
||||
msgtype = MSG_DETACH;
|
||||
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||
|
||||
if (args_has(args, 's')) {
|
||||
s = source->s;
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
TAILQ_FOREACH(loop, &clients, entry) {
|
||||
if (loop->session == s) {
|
||||
if (cmd != NULL)
|
||||
server_client_exec(loop, cmd);
|
||||
else
|
||||
server_client_detach(loop, msgtype);
|
||||
}
|
||||
}
|
||||
return (CMD_RETURN_STOP);
|
||||
}
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
TAILQ_FOREACH(loop, &clients, entry) {
|
||||
if (loop->session != NULL && loop != tc) {
|
||||
if (cmd != NULL)
|
||||
server_client_exec(loop, cmd);
|
||||
else
|
||||
server_client_detach(loop, msgtype);
|
||||
}
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (cmd != NULL)
|
||||
server_client_exec(tc, cmd);
|
||||
else
|
||||
server_client_detach(tc, msgtype);
|
||||
return (CMD_RETURN_STOP);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,534 +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 args_parse_type cmd_display_menu_args_parse(struct args *,
|
||||
u_int, char **);
|
||||
static enum cmd_retval cmd_display_menu_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
static enum cmd_retval cmd_display_popup_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_display_menu_entry = {
|
||||
.name = "display-menu",
|
||||
.alias = "menu",
|
||||
|
||||
.args = { "b:c:C:H:s:S:MOt:T:x:y:", 1, -1, cmd_display_menu_args_parse },
|
||||
.usage = "[-MO] [-b border-lines] [-c target-client] "
|
||||
"[-C starting-choice] [-H selected-style] [-s style] "
|
||||
"[-S border-style] " CMD_TARGET_PANE_USAGE " [-T title] "
|
||||
"[-x position] [-y position] name [key] [command] ...",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG,
|
||||
.exec = cmd_display_menu_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_display_popup_entry = {
|
||||
.name = "display-popup",
|
||||
.alias = "popup",
|
||||
|
||||
.args = { "Bb:Cc:d:e:Eh:kNs:S:t:T:w:x:y:", 0, -1, NULL },
|
||||
.usage = "[-BCEkN] [-b border-lines] [-c target-client] "
|
||||
"[-d start-directory] [-e environment] [-h height] "
|
||||
"[-s style] [-S border-style] " CMD_TARGET_PANE_USAGE
|
||||
" [-T title] [-w width] [-x position] [-y position] "
|
||||
"[shell-command [argument ...]]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG,
|
||||
.exec = cmd_display_popup_exec
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_display_menu_args_parse(struct args *args, u_int idx, __unused char **cause)
|
||||
{
|
||||
u_int i = 0;
|
||||
enum args_parse_type type = ARGS_PARSE_STRING;
|
||||
|
||||
for (;;) {
|
||||
type = ARGS_PARSE_STRING;
|
||||
if (i == idx)
|
||||
break;
|
||||
if (*args_string(args, i++) == '\0')
|
||||
continue;
|
||||
|
||||
type = ARGS_PARSE_STRING;
|
||||
if (i++ == idx)
|
||||
break;
|
||||
|
||||
type = ARGS_PARSE_COMMANDS_OR_STRING;
|
||||
if (i++ == idx)
|
||||
break;
|
||||
}
|
||||
return (type);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_display_menu_get_pos(struct client *tc, struct cmdq_item *item,
|
||||
struct args *args, u_int *px, u_int *py, u_int w, u_int h)
|
||||
{
|
||||
struct tty *tty = &tc->tty;
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct key_event *event = cmdq_get_event(item);
|
||||
struct session *s = tc->session;
|
||||
struct winlink *wl = target->wl;
|
||||
struct window_pane *wp = target->wp;
|
||||
struct style_ranges *ranges = NULL;
|
||||
struct style_range *sr = NULL;
|
||||
const char *xp, *yp;
|
||||
char *p;
|
||||
int top;
|
||||
u_int line, ox, oy, sx, sy, lines, position;
|
||||
long n;
|
||||
struct format_tree *ft;
|
||||
|
||||
/*
|
||||
* Work out the position from the -x and -y arguments. This is the
|
||||
* bottom-left position.
|
||||
*/
|
||||
|
||||
/* If the popup is too big, stop now. */
|
||||
if (w > tty->sx || h > tty->sy)
|
||||
return (0);
|
||||
|
||||
/* Create format with mouse position if any. */
|
||||
ft = format_create_from_target(item);
|
||||
if (event->m.valid) {
|
||||
format_add(ft, "popup_mouse_x", "%u", event->m.x);
|
||||
format_add(ft, "popup_mouse_y", "%u", event->m.y);
|
||||
}
|
||||
|
||||
/*
|
||||
* If there are any status lines, add this window position and the
|
||||
* status line position.
|
||||
*/
|
||||
top = status_at_line(tc);
|
||||
if (top != -1) {
|
||||
lines = status_line_size(tc);
|
||||
if (top == 0)
|
||||
top = lines;
|
||||
else
|
||||
top = 0;
|
||||
position = options_get_number(s->options, "status-position");
|
||||
|
||||
for (line = 0; line < lines; line++) {
|
||||
ranges = &tc->status.entries[line].ranges;
|
||||
TAILQ_FOREACH(sr, ranges, entry) {
|
||||
if (sr->type != STYLE_RANGE_WINDOW)
|
||||
continue;
|
||||
if (sr->argument == (u_int)wl->idx)
|
||||
break;
|
||||
}
|
||||
if (sr != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
if (sr != NULL) {
|
||||
format_add(ft, "popup_window_status_line_x", "%u",
|
||||
sr->start);
|
||||
if (position == 0) {
|
||||
format_add(ft, "popup_window_status_line_y",
|
||||
"%u", line + 1 + h);
|
||||
} else {
|
||||
format_add(ft, "popup_window_status_line_y",
|
||||
"%u", tty->sy - lines + line);
|
||||
}
|
||||
}
|
||||
|
||||
if (position == 0)
|
||||
format_add(ft, "popup_status_line_y", "%u", lines + h);
|
||||
else {
|
||||
format_add(ft, "popup_status_line_y", "%u",
|
||||
tty->sy - lines);
|
||||
}
|
||||
} else
|
||||
top = 0;
|
||||
|
||||
/* Popup width and height. */
|
||||
format_add(ft, "popup_width", "%u", w);
|
||||
format_add(ft, "popup_height", "%u", h);
|
||||
|
||||
/* Position so popup is in the centre. */
|
||||
n = (long)(tty->sx - 1) / 2 - w / 2;
|
||||
if (n < 0)
|
||||
format_add(ft, "popup_centre_x", "%u", 0);
|
||||
else
|
||||
format_add(ft, "popup_centre_x", "%ld", n);
|
||||
n = (tty->sy - 1) / 2 + h / 2;
|
||||
if (n >= tty->sy)
|
||||
format_add(ft, "popup_centre_y", "%u", tty->sy - h);
|
||||
else
|
||||
format_add(ft, "popup_centre_y", "%ld", n);
|
||||
|
||||
/* Position of popup relative to mouse. */
|
||||
if (event->m.valid) {
|
||||
n = (long)event->m.x - w / 2;
|
||||
if (n < 0)
|
||||
format_add(ft, "popup_mouse_centre_x", "%u", 0);
|
||||
else
|
||||
format_add(ft, "popup_mouse_centre_x", "%ld", n);
|
||||
n = event->m.y - h / 2;
|
||||
if (n + h >= tty->sy) {
|
||||
format_add(ft, "popup_mouse_centre_y", "%u",
|
||||
tty->sy - h);
|
||||
} else
|
||||
format_add(ft, "popup_mouse_centre_y", "%ld", n);
|
||||
n = (long)event->m.y + h;
|
||||
if (n >= tty->sy)
|
||||
format_add(ft, "popup_mouse_top", "%u", tty->sy - 1);
|
||||
else
|
||||
format_add(ft, "popup_mouse_top", "%ld", n);
|
||||
n = event->m.y - h;
|
||||
if (n < 0)
|
||||
format_add(ft, "popup_mouse_bottom", "%u", 0);
|
||||
else
|
||||
format_add(ft, "popup_mouse_bottom", "%ld", n);
|
||||
}
|
||||
|
||||
/* Position in pane. */
|
||||
tty_window_offset(&tc->tty, &ox, &oy, &sx, &sy);
|
||||
n = top + wp->yoff - oy + h;
|
||||
if (n >= tty->sy)
|
||||
format_add(ft, "popup_pane_top", "%u", tty->sy - h);
|
||||
else
|
||||
format_add(ft, "popup_pane_top", "%ld", n);
|
||||
format_add(ft, "popup_pane_bottom", "%u", top + wp->yoff + wp->sy - oy);
|
||||
format_add(ft, "popup_pane_left", "%u", wp->xoff - ox);
|
||||
n = (long)wp->xoff + wp->sx - ox - w;
|
||||
if (n < 0)
|
||||
format_add(ft, "popup_pane_right", "%u", 0);
|
||||
else
|
||||
format_add(ft, "popup_pane_right", "%ld", n);
|
||||
|
||||
/* Expand horizontal position. */
|
||||
xp = args_get(args, 'x');
|
||||
if (xp == NULL || strcmp(xp, "C") == 0)
|
||||
xp = "#{popup_centre_x}";
|
||||
else if (strcmp(xp, "R") == 0)
|
||||
xp = "#{popup_pane_right}";
|
||||
else if (strcmp(xp, "P") == 0)
|
||||
xp = "#{popup_pane_left}";
|
||||
else if (strcmp(xp, "M") == 0)
|
||||
xp = "#{popup_mouse_centre_x}";
|
||||
else if (strcmp(xp, "W") == 0)
|
||||
xp = "#{popup_window_status_line_x}";
|
||||
p = format_expand(ft, xp);
|
||||
n = strtol(p, NULL, 10);
|
||||
if (n + w >= tty->sx)
|
||||
n = tty->sx - w;
|
||||
else if (n < 0)
|
||||
n = 0;
|
||||
*px = n;
|
||||
log_debug("%s: -x: %s = %s = %u (-w %u)", __func__, xp, p, *px, w);
|
||||
free(p);
|
||||
|
||||
/* Expand vertical position */
|
||||
yp = args_get(args, 'y');
|
||||
if (yp == NULL || strcmp(yp, "C") == 0)
|
||||
yp = "#{popup_centre_y}";
|
||||
else if (strcmp(yp, "P") == 0)
|
||||
yp = "#{popup_pane_bottom}";
|
||||
else if (strcmp(yp, "M") == 0)
|
||||
yp = "#{popup_mouse_top}";
|
||||
else if (strcmp(yp, "S") == 0)
|
||||
yp = "#{popup_status_line_y}";
|
||||
else if (strcmp(yp, "W") == 0)
|
||||
yp = "#{popup_window_status_line_y}";
|
||||
p = format_expand(ft, yp);
|
||||
n = strtol(p, NULL, 10);
|
||||
if (n < h)
|
||||
n = 0;
|
||||
else
|
||||
n -= h;
|
||||
if (n + h >= tty->sy)
|
||||
n = tty->sy - h;
|
||||
else if (n < 0)
|
||||
n = 0;
|
||||
*py = n;
|
||||
log_debug("%s: -y: %s = %s = %u (-h %u)", __func__, yp, p, *py, h);
|
||||
free(p);
|
||||
|
||||
format_free(ft);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct key_event *event = cmdq_get_event(item);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct menu *menu = NULL;
|
||||
struct menu_item menu_item;
|
||||
const char *key, *name, *value;
|
||||
const char *style = args_get(args, 's');
|
||||
const char *border_style = args_get(args, 'S');
|
||||
const char *selected_style = args_get(args, 'H');
|
||||
enum box_lines lines = BOX_LINES_DEFAULT;
|
||||
char *title, *cause = NULL;
|
||||
int flags = 0, starting_choice = 0;
|
||||
u_int px, py, i, count = args_count(args);
|
||||
struct options *o = target->s->curw->window->options;
|
||||
struct options_entry *oe;
|
||||
|
||||
|
||||
if (tc->overlay_draw != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (args_has(args, 'C')) {
|
||||
if (strcmp(args_get(args, 'C'), "-") == 0)
|
||||
starting_choice = -1;
|
||||
else {
|
||||
starting_choice = args_strtonum(args, 'C', 0, UINT_MAX,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "starting choice %s", cause);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'T'))
|
||||
title = format_single_from_target(item, args_get(args, 'T'));
|
||||
else
|
||||
title = xstrdup("");
|
||||
menu = menu_create(title);
|
||||
free(title);
|
||||
|
||||
for (i = 0; i != count; /* nothing */) {
|
||||
name = args_string(args, i++);
|
||||
if (*name == '\0') {
|
||||
menu_add_item(menu, NULL, item, tc, target);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (count - i < 2) {
|
||||
cmdq_error(item, "not enough arguments");
|
||||
goto fail;
|
||||
}
|
||||
key = args_string(args, i++);
|
||||
|
||||
menu_item.name = name;
|
||||
menu_item.key = key_string_lookup_string(key);
|
||||
menu_item.command = args_string(args, i++);
|
||||
|
||||
menu_add_item(menu, &menu_item, item, tc, target);
|
||||
}
|
||||
if (menu == NULL) {
|
||||
cmdq_error(item, "invalid menu arguments");
|
||||
goto fail;
|
||||
}
|
||||
if (menu->count == 0)
|
||||
goto out;
|
||||
if (!cmd_display_menu_get_pos(tc, item, args, &px, &py, menu->width + 4,
|
||||
menu->count + 2))
|
||||
goto out;
|
||||
|
||||
value = args_get(args, 'b');
|
||||
if (value != NULL) {
|
||||
oe = options_get(o, "menu-border-lines");
|
||||
lines = options_find_choice(options_table_entry(oe), value,
|
||||
&cause);
|
||||
if (lines == -1) {
|
||||
cmdq_error(item, "menu-border-lines %s", cause);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'O'))
|
||||
flags |= MENU_STAYOPEN;
|
||||
if (!event->m.valid && !args_has(args, 'M'))
|
||||
flags |= MENU_NOMOUSE;
|
||||
if (menu_display(menu, flags, starting_choice, item, px, py, tc, lines,
|
||||
style, selected_style, border_style, target, NULL, NULL) != 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
|
||||
out:
|
||||
menu_free(menu);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
fail:
|
||||
free(cause);
|
||||
menu_free(menu);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct session *s = target->s;
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct tty *tty = &tc->tty;
|
||||
const char *value, *shell, *shellcmd = NULL;
|
||||
const char *style = args_get(args, 's');
|
||||
const char *border_style = args_get(args, 'S');
|
||||
char *cwd = NULL, *cause = NULL, **argv = NULL;
|
||||
char *title = NULL;
|
||||
int modify = popup_present(tc);
|
||||
int flags = -1, argc = 0;
|
||||
enum box_lines lines = BOX_LINES_DEFAULT;
|
||||
u_int px, py, w, h, count = args_count(args);
|
||||
struct args_value *av;
|
||||
struct environ *env = NULL;
|
||||
struct options *o = s->curw->window->options;
|
||||
struct options_entry *oe;
|
||||
|
||||
if (args_has(args, 'C')) {
|
||||
server_client_clear_overlay(tc);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (!modify && tc->overlay_draw != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (!modify) {
|
||||
h = tty->sy / 2;
|
||||
if (args_has(args, 'h')) {
|
||||
h = args_percentage(args, 'h', 1, tty->sy, tty->sy,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "height %s", cause);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
w = tty->sx / 2;
|
||||
if (args_has(args, 'w')) {
|
||||
w = args_percentage(args, 'w', 1, tty->sx, tty->sx,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "width %s", cause);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (w > tty->sx)
|
||||
w = tty->sx;
|
||||
if (h > tty->sy)
|
||||
h = tty->sy;
|
||||
if (!cmd_display_menu_get_pos(tc, item, args, &px, &py, w, h))
|
||||
goto out;
|
||||
|
||||
value = args_get(args, 'd');
|
||||
if (value != NULL)
|
||||
cwd = format_single_from_target(item, value);
|
||||
else
|
||||
cwd = xstrdup(server_client_get_cwd(tc, s));
|
||||
if (count == 0) {
|
||||
shellcmd = options_get_string(s->options,
|
||||
"default-command");
|
||||
} else if (count == 1)
|
||||
shellcmd = args_string(args, 0);
|
||||
if (count <= 1 && (shellcmd == NULL || *shellcmd == '\0')) {
|
||||
shellcmd = NULL;
|
||||
shell = options_get_string(s->options, "default-shell");
|
||||
if (!checkshell(shell))
|
||||
shell = _PATH_BSHELL;
|
||||
cmd_append_argv(&argc, &argv, shell);
|
||||
} else
|
||||
args_to_vector(args, &argc, &argv);
|
||||
|
||||
if (args_has(args, 'e') >= 1) {
|
||||
env = environ_create();
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(env, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value = args_get(args, 'b');
|
||||
if (args_has(args, 'B'))
|
||||
lines = BOX_LINES_NONE;
|
||||
else if (value != NULL) {
|
||||
oe = options_get(o, "popup-border-lines");
|
||||
lines = options_find_choice(options_table_entry(oe), value,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "popup-border-lines %s", cause);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'T'))
|
||||
title = format_single_from_target(item, args_get(args, 'T'));
|
||||
else
|
||||
title = xstrdup("");
|
||||
|
||||
if (args_has(args, 'N') || !modify)
|
||||
flags = 0;
|
||||
if (args_has(args, 'E') > 1) {
|
||||
if (flags == -1)
|
||||
flags = 0;
|
||||
flags |= POPUP_CLOSEEXITZERO;
|
||||
} else if (args_has(args, 'E')) {
|
||||
if (flags == -1)
|
||||
flags = 0;
|
||||
flags |= POPUP_CLOSEEXIT;
|
||||
}
|
||||
if (args_has(args, 'k')) {
|
||||
if (flags == -1)
|
||||
flags = 0;
|
||||
flags |= POPUP_CLOSEANYKEY;
|
||||
}
|
||||
|
||||
if (modify) {
|
||||
popup_modify(tc, title, style, border_style, lines, flags);
|
||||
goto out;
|
||||
}
|
||||
if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc,
|
||||
argv, cwd, title, tc, s, style, border_style, NULL, NULL) != 0)
|
||||
goto out;
|
||||
environ_free(env);
|
||||
free(cwd);
|
||||
free(title);
|
||||
cmd_free_argv(argc, argv);
|
||||
return (CMD_RETURN_WAIT);
|
||||
|
||||
out:
|
||||
cmd_free_argv(argc, argv);
|
||||
environ_free(env);
|
||||
free(cwd);
|
||||
free(title);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
fail:
|
||||
free(cause);
|
||||
cmd_free_argv(argc, argv);
|
||||
environ_free(env);
|
||||
free(cwd);
|
||||
free(title);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* 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 <time.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Displays a message in the status line.
|
||||
*/
|
||||
|
||||
#define DISPLAY_MESSAGE_TEMPLATE \
|
||||
"[#{session_name}] #{window_index}:" \
|
||||
"#{window_name}, current pane #{pane_index} " \
|
||||
"- (%H:%M %d-%b-%y)"
|
||||
|
||||
static enum cmd_retval cmd_display_message_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_display_message_entry = {
|
||||
.name = "display-message",
|
||||
.alias = "display",
|
||||
|
||||
.args = { "aCc:d:lINpt:F:v", 0, 1, NULL },
|
||||
.usage = "[-aCIlNpv] [-c target-client] [-d delay] [-F format] "
|
||||
CMD_TARGET_PANE_USAGE " [message]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG|CMD_CLIENT_CANFAIL,
|
||||
.exec = cmd_display_message_exec
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_display_message_each(const char *key, const char *value, void *arg)
|
||||
{
|
||||
struct cmdq_item *item = arg;
|
||||
|
||||
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 = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct client *tc = cmdq_get_target_client(item), *c;
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl;
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *template;
|
||||
char *msg, *cause;
|
||||
int delay = -1, flags, Nflag = args_has(args, 'N');
|
||||
int Cflag = args_has(args, 'C');
|
||||
struct format_tree *ft;
|
||||
u_int count = args_count(args);
|
||||
struct evbuffer *evb;
|
||||
|
||||
if (args_has(args, 'I')) {
|
||||
if (wp == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
switch (window_pane_start_input(wp, item, &cause)) {
|
||||
case -1:
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case 1:
|
||||
return (CMD_RETURN_NORMAL);
|
||||
case 0:
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'F') && count != 0) {
|
||||
cmdq_error(item, "only one of -F or argument must be given");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (count != 0)
|
||||
template = args_string(args, 0);
|
||||
else
|
||||
template = args_get(args, 'F');
|
||||
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.
|
||||
*/
|
||||
if (tc != NULL && tc->session == s)
|
||||
c = tc;
|
||||
else if (s != NULL)
|
||||
c = cmd_find_best_client(s);
|
||||
else
|
||||
c = NULL;
|
||||
if (args_has(args, 'v'))
|
||||
flags = FORMAT_VERBOSE;
|
||||
else
|
||||
flags = 0;
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, flags);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
format_each(ft, cmd_display_message_each, item);
|
||||
format_free(ft);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'l'))
|
||||
msg = xstrdup(template);
|
||||
else
|
||||
msg = format_expand_time(ft, template);
|
||||
|
||||
if (cmdq_get_client(item) == NULL)
|
||||
cmdq_error(item, "%s", msg);
|
||||
else if (args_has(args, 'p'))
|
||||
cmdq_print(item, "%s", msg);
|
||||
else if (tc != NULL && (tc->flags & CLIENT_CONTROL)) {
|
||||
evb = evbuffer_new();
|
||||
if (evb == NULL)
|
||||
fatalx("out of memory");
|
||||
evbuffer_add_printf(evb, "%%message %s", msg);
|
||||
server_client_print(tc, 0, evb);
|
||||
evbuffer_free(evb);
|
||||
} else if (tc != NULL)
|
||||
status_message_set(tc, delay, 0, Nflag, Cflag, "%s", msg);
|
||||
free(msg);
|
||||
|
||||
format_free(ft);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -1,312 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Display panes on a client.
|
||||
*/
|
||||
|
||||
static enum args_parse_type cmd_display_panes_args_parse(struct args *,
|
||||
u_int, char **);
|
||||
static enum cmd_retval cmd_display_panes_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_display_panes_entry = {
|
||||
.name = "display-panes",
|
||||
.alias = "displayp",
|
||||
|
||||
.args = { "bd:Nt:", 0, 1, cmd_display_panes_args_parse },
|
||||
.usage = "[-bN] [-d duration] " CMD_TARGET_CLIENT_USAGE " [template]",
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_display_panes_exec
|
||||
};
|
||||
|
||||
struct cmd_display_panes_data {
|
||||
struct cmdq_item *item;
|
||||
struct args_command_state *state;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_display_panes_args_parse(__unused struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
||||
struct window_pane *wp)
|
||||
{
|
||||
struct client *c = ctx->c;
|
||||
struct tty *tty = &c->tty;
|
||||
struct session *s = c->session;
|
||||
struct options *oo = s->options;
|
||||
struct window *w = wp->window;
|
||||
struct grid_cell fgc, bgc;
|
||||
u_int pane, idx, px, py, i, j, xoff, yoff, sx, sy;
|
||||
int colour, active_colour;
|
||||
char buf[16], lbuf[16], rbuf[16], *ptr;
|
||||
size_t len, llen, rlen;
|
||||
|
||||
if (wp->xoff + wp->sx <= ctx->ox ||
|
||||
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, &pane) != 0)
|
||||
fatalx("index not found");
|
||||
len = xsnprintf(buf, sizeof buf, "%u", pane);
|
||||
|
||||
if (sx < len)
|
||||
return;
|
||||
colour = options_get_number(oo, "display-panes-colour");
|
||||
active_colour = options_get_number(oo, "display-panes-active-colour");
|
||||
|
||||
memcpy(&fgc, &grid_default_cell, sizeof fgc);
|
||||
memcpy(&bgc, &grid_default_cell, sizeof bgc);
|
||||
if (w->active == wp) {
|
||||
fgc.fg = active_colour;
|
||||
bgc.bg = active_colour;
|
||||
} else {
|
||||
fgc.fg = colour;
|
||||
bgc.bg = colour;
|
||||
}
|
||||
|
||||
rlen = xsnprintf(rbuf, sizeof rbuf, "%ux%u", wp->sx, wp->sy);
|
||||
if (pane > 9 && pane < 35)
|
||||
llen = xsnprintf(lbuf, sizeof lbuf, "%c", 'a' + (pane - 10));
|
||||
else
|
||||
llen = 0;
|
||||
|
||||
if (sx < len * 6 || sy < 5) {
|
||||
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL);
|
||||
if (sx >= len + llen + 1) {
|
||||
len += llen + 1;
|
||||
tty_cursor(tty, xoff + px - len / 2, yoff + py);
|
||||
tty_putn(tty, buf, len, len);
|
||||
tty_putn(tty, " ", 1, 1);
|
||||
tty_putn(tty, lbuf, llen, llen);
|
||||
} else {
|
||||
tty_cursor(tty, xoff + px - len / 2, yoff + py);
|
||||
tty_putn(tty, buf, len, len);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
px -= len * 3;
|
||||
py -= 2;
|
||||
|
||||
tty_attributes(tty, &bgc, &grid_default_cell, NULL, NULL);
|
||||
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;
|
||||
}
|
||||
|
||||
if (sy <= 6)
|
||||
goto out;
|
||||
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL);
|
||||
if (rlen != 0 && sx >= rlen) {
|
||||
tty_cursor(tty, xoff + sx - rlen, yoff);
|
||||
tty_putn(tty, rbuf, rlen, rlen);
|
||||
}
|
||||
if (llen != 0) {
|
||||
tty_cursor(tty, xoff + sx / 2 + len * 3 - llen - 1,
|
||||
yoff + py + 5);
|
||||
tty_putn(tty, lbuf, llen, llen);
|
||||
}
|
||||
|
||||
out:
|
||||
tty_cursor(tty, 0, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_display_panes_draw(struct client *c, __unused void *data,
|
||||
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(__unused struct client *c, void *data)
|
||||
{
|
||||
struct cmd_display_panes_data *cdata = data;
|
||||
|
||||
if (cdata->item != NULL)
|
||||
cmdq_continue(cdata->item);
|
||||
args_make_commands_free(cdata->state);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_display_panes_key(struct client *c, void *data, struct key_event *event)
|
||||
{
|
||||
struct cmd_display_panes_data *cdata = data;
|
||||
char *expanded, *error;
|
||||
struct cmdq_item *item = cdata->item, *new_item;
|
||||
struct cmd_list *cmdlist;
|
||||
struct window *w = c->session->curw->window;
|
||||
struct window_pane *wp;
|
||||
u_int index;
|
||||
key_code key;
|
||||
|
||||
if (event->key >= '0' && event->key <= '9')
|
||||
index = event->key - '0';
|
||||
else if ((event->key & KEYC_MASK_MODIFIERS) == 0) {
|
||||
key = (event->key & KEYC_MASK_KEY);
|
||||
if (key >= 'a' && key <= 'z')
|
||||
index = 10 + (key - 'a');
|
||||
else
|
||||
return (-1);
|
||||
} else
|
||||
return (-1);
|
||||
|
||||
wp = window_pane_at_index(w, index);
|
||||
if (wp == NULL)
|
||||
return (1);
|
||||
window_unzoom(w, 1);
|
||||
|
||||
xasprintf(&expanded, "%%%u", wp->id);
|
||||
|
||||
cmdlist = args_make_commands(cdata->state, 1, &expanded, &error);
|
||||
if (cmdlist == NULL) {
|
||||
cmdq_append(c, cmdq_get_error(error));
|
||||
free(error);
|
||||
} else if (item == NULL) {
|
||||
new_item = cmdq_get_command(cmdlist, NULL);
|
||||
cmdq_append(c, new_item);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
free(expanded);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = tc->session;
|
||||
u_int delay;
|
||||
char *cause;
|
||||
struct cmd_display_panes_data *cdata;
|
||||
int wait = !args_has(args, 'b');
|
||||
|
||||
if (tc->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 = xcalloc(1, sizeof *cdata);
|
||||
if (wait)
|
||||
cdata->item = item;
|
||||
cdata->state = args_make_commands_prepare(self, item, 0,
|
||||
"select-pane -t \"%%%\"", wait, 0);
|
||||
|
||||
if (args_has(args, 'N')) {
|
||||
server_client_set_overlay(tc, delay, NULL, NULL,
|
||||
cmd_display_panes_draw, NULL, cmd_display_panes_free, NULL,
|
||||
cdata);
|
||||
} else {
|
||||
server_client_set_overlay(tc, delay, NULL, NULL,
|
||||
cmd_display_panes_draw, cmd_display_panes_key,
|
||||
cmd_display_panes_free, NULL, cdata);
|
||||
}
|
||||
|
||||
if (!wait)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
61
cmd-down-pane.c
Normal file
61
cmd-down-pane.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* $Id: cmd-down-pane.c,v 1.7 2009-04-01 21:10:08 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 "tmux.h"
|
||||
|
||||
/*
|
||||
* Move down a pane.
|
||||
*/
|
||||
|
||||
int cmd_down_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_down_pane_entry = {
|
||||
"down-pane", "downp",
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_down_pane_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
w = wl->window;
|
||||
|
||||
do {
|
||||
w->active = TAILQ_NEXT(w->active, entry);
|
||||
if (w->active == NULL)
|
||||
w->active = TAILQ_FIRST(&w->panes);
|
||||
layout_refresh(w, 1);
|
||||
} while (w->active->flags & PANE_HIDDEN);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-find-window.c,v 1.10 2009-06-25 16:21: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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,7 +18,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <fnmatch.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -26,91 +27,139 @@
|
||||
* 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);
|
||||
|
||||
const struct cmd_entry cmd_find_window_entry = {
|
||||
.name = "find-window",
|
||||
.alias = "findw",
|
||||
|
||||
.args = { "CiNrt:TZ", 1, 1, NULL },
|
||||
.usage = "[-CiNrTZ] " CMD_TARGET_PANE_USAGE " match-string",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_find_window_exec
|
||||
"find-window", "findw",
|
||||
CMD_TARGET_WINDOW_USAGE " match-string",
|
||||
CMD_ARG1,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_find_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct cmd_find_window_data {
|
||||
u_int session;
|
||||
};
|
||||
|
||||
int
|
||||
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self), *new_args;
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *s = args_string(args, 0), *suffix = "";
|
||||
const char *star = "*";
|
||||
struct args_value *filter;
|
||||
int C, N, T;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct cmd_find_window_data *cdata;
|
||||
struct session *s;
|
||||
struct winlink *wl, *wm;
|
||||
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');
|
||||
N = args_has(args, 'N');
|
||||
T = args_has(args, 'T');
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
return (-1);
|
||||
}
|
||||
s = ctx->curclient->session;
|
||||
|
||||
if (args_has(args, 'r'))
|
||||
star = "";
|
||||
if (args_has(args, 'r') && args_has(args, 'i'))
|
||||
suffix = "/ri";
|
||||
else if (args_has(args, 'r'))
|
||||
suffix = "/r";
|
||||
else if (args_has(args, 'i'))
|
||||
suffix = "/i";
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (!C && !N && !T)
|
||||
C = N = T = 1;
|
||||
ARRAY_INIT(&list_idx);
|
||||
ARRAY_INIT(&list_ctx);
|
||||
|
||||
filter = xcalloc(1, sizeof *filter);
|
||||
filter->type = ARGS_STRING;
|
||||
xasprintf(&searchstr, "*%s*", data->arg);
|
||||
RB_FOREACH(wm, winlinks, &s->windows) {
|
||||
i = 0;
|
||||
TAILQ_FOREACH(wp, &wm->window->panes, entry) {
|
||||
i++;
|
||||
|
||||
if (C && N && T) {
|
||||
xasprintf(&filter->string,
|
||||
"#{||:"
|
||||
"#{C%s:%s},#{||:#{m%s:%s%s%s,#{window_name}},"
|
||||
"#{m%s:%s%s%s,#{pane_title}}}}",
|
||||
suffix, s, suffix, star, s, star, suffix, star, s, star);
|
||||
} else if (C && N) {
|
||||
xasprintf(&filter->string,
|
||||
"#{||:#{C%s:%s},#{m%s:%s%s%s,#{window_name}}}",
|
||||
suffix, s, suffix, star, s, star);
|
||||
} else if (C && T) {
|
||||
xasprintf(&filter->string,
|
||||
"#{||:#{C%s:%s},#{m%s:%s%s%s,#{pane_title}}}",
|
||||
suffix, s, suffix, star, s, star);
|
||||
} else if (N && T) {
|
||||
xasprintf(&filter->string,
|
||||
"#{||:#{m%s:%s%s%s,#{window_name}},"
|
||||
"#{m%s:%s%s%s,#{pane_title}}}",
|
||||
suffix, star, s, star, suffix, star, s, star);
|
||||
} else if (C) {
|
||||
xasprintf(&filter->string,
|
||||
"#{C%s:%s}",
|
||||
suffix, s);
|
||||
} else if (N) {
|
||||
xasprintf(&filter->string,
|
||||
"#{m%s:%s%s%s,#{window_name}}",
|
||||
suffix, star, s, star);
|
||||
} else {
|
||||
xasprintf(&filter->string,
|
||||
"#{m%s:%s%s%s,#{pane_title}}",
|
||||
suffix, star, s, star);
|
||||
if (fnmatch(searchstr, wm->window->name, 0) == 0)
|
||||
sctx = xstrdup("");
|
||||
else {
|
||||
sres = window_pane_search(wp, data->arg, &line);
|
||||
if (sres == NULL &&
|
||||
fnmatch(searchstr, wp->base.title, 0) != 0)
|
||||
continue;
|
||||
|
||||
if (sres == NULL) {
|
||||
xasprintf(&sctx,
|
||||
"pane %u title: \"%s\"", i - 1,
|
||||
wp->base.title);
|
||||
} else {
|
||||
xasprintf(&sctx,
|
||||
"pane %u line %u: \"%s\"", i - 1,
|
||||
line + 1, sres);
|
||||
xfree(sres);
|
||||
}
|
||||
}
|
||||
|
||||
ARRAY_ADD(&list_idx, wm->idx);
|
||||
ARRAY_ADD(&list_ctx, sctx);
|
||||
}
|
||||
}
|
||||
xfree(searchstr);
|
||||
|
||||
if (ARRAY_LENGTH(&list_idx) == 0) {
|
||||
ctx->error(ctx, "no windows matching: %s", data->arg);
|
||||
ARRAY_FREE(&list_idx);
|
||||
ARRAY_FREE(&list_ctx);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
new_args = args_create();
|
||||
if (args_has(args, 'Z'))
|
||||
args_set(new_args, 'Z', NULL, 0);
|
||||
args_set(new_args, 'f', filter, 0);
|
||||
if (ARRAY_LENGTH(&list_idx) == 1) {
|
||||
if (session_select(s, ARRAY_FIRST(&list_idx)) == 0)
|
||||
server_redraw_session(s);
|
||||
recalculate_sizes();
|
||||
goto out;
|
||||
}
|
||||
|
||||
window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args);
|
||||
args_free(new_args);
|
||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||
goto out;
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
for (i = 0; i < ARRAY_LENGTH(&list_idx); i++) {
|
||||
wm = winlink_find_by_index(
|
||||
&s->windows, ARRAY_ITEM(&list_idx, i));
|
||||
w = wm->window;
|
||||
|
||||
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);
|
||||
if (session_index(s, &cdata->session) != 0)
|
||||
fatalx("session not found");
|
||||
|
||||
window_choose_ready(
|
||||
wl->window->active, 0, cmd_find_window_callback, 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;
|
||||
|
||||
if (idx != -1 && cdata->session <= ARRAY_LENGTH(&sessions) - 1) {
|
||||
s = ARRAY_ITEM(&sessions, cdata->session);
|
||||
if (s != NULL && session_select(s, idx) == 0)
|
||||
server_redraw_session(s);
|
||||
recalculate_sizes();
|
||||
}
|
||||
xfree(cdata);
|
||||
}
|
||||
|
||||
1329
cmd-find.c
1329
cmd-find.c
File diff suppressed because it is too large
Load Diff
694
cmd-generic.c
Normal file
694
cmd-generic.c
Normal file
@@ -0,0 +1,694 @@
|
||||
/* $Id: cmd-generic.c,v 1.28 2009-05-21 19:47:57 nicm 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"
|
||||
|
||||
#define CMD_FLAGS "adDgkuU"
|
||||
#define CMD_FLAGMASK (CMD_AFLAG|CMD_DFLAG|CMD_BIGDFLAG|CMD_GFLAG|CMD_KFLAG| \
|
||||
CMD_UFLAG|CMD_BIGUFLAG)
|
||||
|
||||
int cmd_do_flags(int, int, int *);
|
||||
size_t cmd_print_flags(char *, size_t, size_t, int);
|
||||
int cmd_fill_argument(int, 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));
|
||||
}
|
||||
|
||||
int
|
||||
cmd_do_flags(int opt, int iflags, int *oflags)
|
||||
{
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
if (iflags & CMD_AFLAG) {
|
||||
(*oflags) |= CMD_AFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'd':
|
||||
if (iflags & CMD_DFLAG) {
|
||||
(*oflags) |= CMD_DFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'D':
|
||||
if (iflags & CMD_BIGDFLAG) {
|
||||
(*oflags) |= CMD_BIGDFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'g':
|
||||
if (iflags & CMD_GFLAG) {
|
||||
(*oflags) |= CMD_GFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'k':
|
||||
if (iflags & CMD_KFLAG) {
|
||||
(*oflags) |= CMD_KFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'u':
|
||||
if (iflags & CMD_UFLAG) {
|
||||
(*oflags) |= CMD_UFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'U':
|
||||
if (iflags & CMD_BIGUFLAG) {
|
||||
(*oflags) |= CMD_BIGUFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_print_flags(char *buf, size_t len, size_t off, int flags)
|
||||
{
|
||||
size_t boff = off;
|
||||
|
||||
if ((flags & CMD_FLAGMASK) == 0)
|
||||
return (0);
|
||||
off += xsnprintf(buf + off, len - off, " -");
|
||||
if (off < len && flags & CMD_AFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "a");
|
||||
if (off < len && flags & CMD_BIGDFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "D");
|
||||
if (off < len && flags & CMD_DFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "d");
|
||||
if (off < len && flags & CMD_GFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "g");
|
||||
if (off < len && flags & CMD_KFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "k");
|
||||
if (off < len && flags & CMD_UFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "u");
|
||||
if (off < len && flags & CMD_BIGUFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "U");
|
||||
return (off - boff);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_fill_argument(int flags, char **arg, int argc, char **argv)
|
||||
{
|
||||
*arg = 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 (argc != 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_target_init(struct cmd *self, unused int key)
|
||||
{
|
||||
struct cmd_target_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flags = 0;
|
||||
data->target = NULL;
|
||||
data->arg = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_target_data *data;
|
||||
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 = getopt(argc, argv, CMD_FLAGS "t:")) != -1) {
|
||||
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
|
||||
case -1:
|
||||
goto usage;
|
||||
case 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, 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_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->arg);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_target_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_target_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->arg = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
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);
|
||||
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->flags);
|
||||
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);
|
||||
return (off);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_srcdst_init(struct cmd *self, unused int key)
|
||||
{
|
||||
struct cmd_srcdst_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flags = 0;
|
||||
data->src = NULL;
|
||||
data->dst = NULL;
|
||||
data->arg = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_srcdst_data *data;
|
||||
int opt;
|
||||
|
||||
cmd_srcdst_init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, CMD_FLAGS "s:t:")) != -1) {
|
||||
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
|
||||
case -1:
|
||||
goto usage;
|
||||
case 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, 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_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_srcdst_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->src);
|
||||
cmd_send_string(b, data->dst);
|
||||
cmd_send_string(b, data->arg);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_srcdst_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_srcdst_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->src = cmd_recv_string(b);
|
||||
data->dst = cmd_recv_string(b);
|
||||
data->arg = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
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);
|
||||
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->flags);
|
||||
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);
|
||||
return (off);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_buffer_init(struct cmd *self, unused int key)
|
||||
{
|
||||
struct cmd_buffer_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flags = 0;
|
||||
data->target = NULL;
|
||||
data->buffer = -1;
|
||||
data->arg = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_buffer_data *data;
|
||||
int opt, n;
|
||||
const char *errstr;
|
||||
|
||||
cmd_buffer_init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, CMD_FLAGS "b:t:")) != -1) {
|
||||
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
|
||||
case -1:
|
||||
goto usage;
|
||||
case 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, 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_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_buffer_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->arg);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_buffer_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_buffer_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->arg = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
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);
|
||||
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->flags);
|
||||
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);
|
||||
return (off);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_option_init(struct cmd *self, unused int key)
|
||||
{
|
||||
struct cmd_option_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flags = 0;
|
||||
data->target = NULL;
|
||||
data->option = NULL;
|
||||
data->value = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_option_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_option_data *data;
|
||||
int opt;
|
||||
|
||||
/* Don't use the entry version since it may be dependent on key. */
|
||||
cmd_option_init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, CMD_FLAGS "t:")) != -1) {
|
||||
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
|
||||
case -1:
|
||||
goto usage;
|
||||
case 0:
|
||||
continue;
|
||||
}
|
||||
switch (opt) {
|
||||
case 't':
|
||||
if (data->target == NULL)
|
||||
data->target = xstrdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc == 2) {
|
||||
data->option = xstrdup(argv[0]);
|
||||
data->value = xstrdup(argv[1]);
|
||||
} else if (argc == 1)
|
||||
data->option = xstrdup(argv[0]);
|
||||
else
|
||||
goto usage;
|
||||
return (0);
|
||||
|
||||
usage:
|
||||
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||
|
||||
self->entry->free(self);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_option_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_option_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->option);
|
||||
cmd_send_string(b, data->value);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_option_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_option_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->option = cmd_recv_string(b);
|
||||
data->value = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_option_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_option_data *data = self->data;
|
||||
|
||||
if (data->target != NULL)
|
||||
xfree(data->target);
|
||||
if (data->option != NULL)
|
||||
xfree(data->option);
|
||||
if (data->value != NULL)
|
||||
xfree(data->value);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_option_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_option_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->flags);
|
||||
if (off < len && data->target != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->option != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->option);
|
||||
if (off < len && data->value != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->value);
|
||||
return (off);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_pane_init(struct cmd *self, unused int key)
|
||||
{
|
||||
struct cmd_pane_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flags = 0;
|
||||
data->target = NULL;
|
||||
data->arg = NULL;
|
||||
data->pane = -1;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_pane_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_pane_data *data;
|
||||
int opt, n;
|
||||
const char *errstr;
|
||||
|
||||
/* Don't use the entry version since it may be dependent on key. */
|
||||
cmd_pane_init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, CMD_FLAGS "p:t:")) != -1) {
|
||||
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
|
||||
case -1:
|
||||
goto usage;
|
||||
case 0:
|
||||
continue;
|
||||
}
|
||||
switch (opt) {
|
||||
case 'p':
|
||||
if (data->pane == -1) {
|
||||
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(cause, "pane %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
data->pane = 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, 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_pane_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->arg);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_pane_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_pane_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->arg = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_pane_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
|
||||
if (data->target != NULL)
|
||||
xfree(data->target);
|
||||
if (data->arg != NULL)
|
||||
xfree(data->arg);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_pane_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_pane_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->flags);
|
||||
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);
|
||||
return (off);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-has-session.c,v 1.12 2009-01-19 18:23:40 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,35 +18,34 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <kernel/OS.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
char *
|
||||
osdep_get_name(int fd, __unused char *tty)
|
||||
/*
|
||||
* 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_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
pid_t tid;
|
||||
team_info tinfo;
|
||||
struct cmd_target_data *data = self->data;
|
||||
|
||||
if ((tid = tcgetpgrp(fd)) == -1)
|
||||
return (NULL);
|
||||
if (cmd_find_session(ctx, data->target) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (get_team_info(tid, &tinfo) != B_OK)
|
||||
return (NULL);
|
||||
|
||||
/* Up to the first 64 characters. */
|
||||
return (xstrdup(tinfo.args));
|
||||
}
|
||||
|
||||
char *
|
||||
osdep_get_cwd(__unused int fd)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
struct event_base *
|
||||
osdep_event_init(void)
|
||||
{
|
||||
return (event_init());
|
||||
return (0);
|
||||
}
|
||||
190
cmd-if-shell.c
190
cmd-if-shell.c
@@ -1,190 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Executes a tmux command if a shell command returns true or false.
|
||||
*/
|
||||
|
||||
static enum args_parse_type cmd_if_shell_args_parse(struct args *, u_int,
|
||||
char **);
|
||||
static enum cmd_retval cmd_if_shell_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static void cmd_if_shell_callback(struct job *);
|
||||
static void cmd_if_shell_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_if_shell_entry = {
|
||||
.name = "if-shell",
|
||||
.alias = "if",
|
||||
|
||||
.args = { "bFt:", 2, 3, cmd_if_shell_args_parse },
|
||||
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
|
||||
"[command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_if_shell_exec
|
||||
};
|
||||
|
||||
struct cmd_if_shell_data {
|
||||
struct args_command_state *cmd_if;
|
||||
struct args_command_state *cmd_else;
|
||||
|
||||
struct client *client;
|
||||
struct cmdq_item *item;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_if_shell_args_parse(__unused struct args *args, u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
if (idx == 1 || idx == 2)
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
return (ARGS_PARSE_STRING);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct cmd_if_shell_data *cdata;
|
||||
struct cmdq_item *new_item;
|
||||
char *shellcmd;
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = target->s;
|
||||
struct cmd_list *cmdlist;
|
||||
u_int count = args_count(args);
|
||||
int wait = !args_has(args, 'b');
|
||||
|
||||
shellcmd = format_single_from_target(item, args_string(args, 0));
|
||||
if (args_has(args, 'F')) {
|
||||
if (*shellcmd != '0' && *shellcmd != '\0')
|
||||
cmdlist = args_make_commands_now(self, item, 1, 0);
|
||||
else if (count == 3)
|
||||
cmdlist = args_make_commands_now(self, item, 2, 0);
|
||||
else {
|
||||
free(shellcmd);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
free(shellcmd);
|
||||
if (cmdlist == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
|
||||
cdata->cmd_if = args_make_commands_prepare(self, item, 1, NULL, wait,
|
||||
0);
|
||||
if (count == 3) {
|
||||
cdata->cmd_else = args_make_commands_prepare(self, item, 2,
|
||||
NULL, wait, 0);
|
||||
}
|
||||
|
||||
if (wait) {
|
||||
cdata->client = cmdq_get_client(item);
|
||||
cdata->item = item;
|
||||
} else
|
||||
cdata->client = tc;
|
||||
if (cdata->client != NULL)
|
||||
cdata->client->references++;
|
||||
|
||||
if (job_run(shellcmd, 0, NULL, NULL, s,
|
||||
server_client_get_cwd(cmdq_get_client(item), s), NULL,
|
||||
cmd_if_shell_callback, cmd_if_shell_free, cdata, 0, -1,
|
||||
-1) == NULL) {
|
||||
cmdq_error(item, "failed to run command: %s", shellcmd);
|
||||
free(shellcmd);
|
||||
cmd_if_shell_free(cdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(shellcmd);
|
||||
|
||||
if (!wait)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_if_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = job_get_data(job);
|
||||
struct client *c = cdata->client;
|
||||
struct cmdq_item *item = cdata->item, *new_item;
|
||||
struct args_command_state *state;
|
||||
struct cmd_list *cmdlist;
|
||||
char *error;
|
||||
int status;
|
||||
|
||||
status = job_get_status(job);
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
state = cdata->cmd_else;
|
||||
else
|
||||
state = cdata->cmd_if;
|
||||
if (state == NULL)
|
||||
goto out;
|
||||
|
||||
cmdlist = args_make_commands(state, 0, NULL, &error);
|
||||
if (cmdlist == NULL) {
|
||||
if (cdata->item == NULL) {
|
||||
*error = toupper((u_char)*error);
|
||||
status_message_set(c, -1, 1, 0, 0, "%s", error);
|
||||
} else
|
||||
cmdq_error(cdata->item, "%s", error);
|
||||
free(error);
|
||||
} else if (item == NULL) {
|
||||
new_item = cmdq_get_command(cmdlist, NULL);
|
||||
cmdq_append(c, new_item);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
out:
|
||||
if (cdata->item != NULL)
|
||||
cmdq_continue(cdata->item);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_if_shell_free(void *data)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = data;
|
||||
|
||||
if (cdata->client != NULL)
|
||||
server_client_unref(cdata->client);
|
||||
|
||||
if (cdata->cmd_else != NULL)
|
||||
args_make_commands_free(cdata->cmd_else);
|
||||
args_make_commands_free(cdata->cmd_if);
|
||||
|
||||
free(cdata);
|
||||
}
|
||||
180
cmd-join-pane.c
180
cmd-join-pane.c
@@ -1,180 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Join or move a pane into another (like split/swap/kill).
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_join_pane_entry = {
|
||||
.name = "join-pane",
|
||||
.alias = "joinp",
|
||||
|
||||
.args = { "bdfhvp:l:s:t:", 0, 0, NULL },
|
||||
.usage = "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_join_pane_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_move_pane_entry = {
|
||||
.name = "move-pane",
|
||||
.alias = "movep",
|
||||
|
||||
.args = { "bdfhvp:l:s:t:", 0, 0, NULL },
|
||||
.usage = "[-bdfhv] [-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 = cmd_get_args(self);
|
||||
struct cmd_find_state *current = cmdq_get_current(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct cmd_find_state *source = cmdq_get_source(item);
|
||||
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 = NULL;
|
||||
int size, dst_idx;
|
||||
int flags;
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
u_int curval = 0;
|
||||
|
||||
dst_s = target->s;
|
||||
dst_wl = target->wl;
|
||||
dst_wp = target->wp;
|
||||
dst_w = dst_wl->window;
|
||||
dst_idx = dst_wl->idx;
|
||||
server_unzoom_window(dst_w);
|
||||
|
||||
src_wl = source->wl;
|
||||
src_wp = source->wp;
|
||||
src_w = src_wl->window;
|
||||
server_unzoom_window(src_w);
|
||||
|
||||
if (src_wp == dst_wp) {
|
||||
cmdq_error(item, "source and target panes must be different");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
type = LAYOUT_TOPBOTTOM;
|
||||
if (args_has(args, 'h'))
|
||||
type = LAYOUT_LEFTRIGHT;
|
||||
|
||||
/* If the 'p' flag is dropped then this bit can be moved into 'l'. */
|
||||
if (args_has(args, 'l') || args_has(args, 'p')) {
|
||||
if (args_has(args, 'f')) {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
curval = dst_w->sy;
|
||||
else
|
||||
curval = dst_w->sx;
|
||||
} else {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
curval = dst_wp->sy;
|
||||
else
|
||||
curval = dst_wp->sx;
|
||||
}
|
||||
}
|
||||
|
||||
size = -1;
|
||||
if (args_has(args, 'l')) {
|
||||
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
|
||||
item, &cause);
|
||||
} else if (args_has(args, 'p')) {
|
||||
size = args_strtonum_and_expand(args, 'l', 0, 100, item,
|
||||
&cause);
|
||||
if (cause == NULL)
|
||||
size = curval * size / 100;
|
||||
}
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "size %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
flags = 0;
|
||||
if (args_has(args, 'b'))
|
||||
flags |= SPAWN_BEFORE;
|
||||
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);
|
||||
|
||||
server_client_remove_pane(src_wp);
|
||||
window_lost_pane(src_w, src_wp);
|
||||
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
||||
|
||||
src_wp->window = dst_w;
|
||||
options_set_parent(src_wp->options, dst_w->options);
|
||||
src_wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
|
||||
if (flags & SPAWN_BEFORE)
|
||||
TAILQ_INSERT_BEFORE(dst_wp, src_wp, entry);
|
||||
else
|
||||
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
||||
layout_assign_pane(lc, src_wp, 0);
|
||||
colour_palette_from_option(&src_wp->palette, src_wp->options);
|
||||
|
||||
recalculate_sizes();
|
||||
|
||||
server_redraw_window(src_w);
|
||||
server_redraw_window(dst_w);
|
||||
|
||||
if (!args_has(args, 'd')) {
|
||||
window_set_active_pane(dst_w, src_wp, 1);
|
||||
session_select(dst_s, dst_idx);
|
||||
cmd_find_from_session(current, dst_s, 0);
|
||||
server_redraw_session(dst_s);
|
||||
} else
|
||||
server_status_session(dst_s);
|
||||
|
||||
if (window_count_panes(src_w) == 0)
|
||||
server_kill_window(src_w, 1);
|
||||
else
|
||||
notify_window("window-layout-changed", src_w);
|
||||
notify_window("window-layout-changed", dst_w);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-kill-pane.c,v 1.7 2009-05-04 17:58:26 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -26,42 +26,47 @@
|
||||
* 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 = {
|
||||
.name = "kill-pane",
|
||||
.alias = "killp",
|
||||
|
||||
.args = { "at:", 0, 0, NULL },
|
||||
.usage = "[-a] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_kill_pane_exec
|
||||
"kill-pane", "killp",
|
||||
CMD_PANE_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_pane_init,
|
||||
cmd_pane_parse,
|
||||
cmd_kill_pane_exec,
|
||||
cmd_pane_send,
|
||||
cmd_pane_recv,
|
||||
cmd_pane_free,
|
||||
cmd_pane_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct winlink *wl = target->wl;
|
||||
struct window_pane *loopwp, *tmpwp, *wp = target->wp;
|
||||
struct cmd_pane_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
server_unzoom_window(wl->window);
|
||||
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
|
||||
if (loopwp == wp)
|
||||
continue;
|
||||
server_client_remove_pane(loopwp);
|
||||
layout_close_pane(loopwp);
|
||||
window_remove_pane(wl->window, loopwp);
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
if (data->pane == -1)
|
||||
wp = wl->window->active;
|
||||
else {
|
||||
wp = window_pane_at_index(wl->window, data->pane);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
server_redraw_window(wl->window);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
server_kill_pane(wp);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (window_count_panes(wl->window) == 1) {
|
||||
ctx->error(ctx, "can't kill pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
window_remove_pane(wl->window, wp);
|
||||
server_redraw_window(wl->window);
|
||||
layout_refresh(wl->window, 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-kill-server.c,v 1.6 2009-01-19 18:23:40 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -27,35 +27,25 @@
|
||||
* 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 = {
|
||||
.name = "kill-server",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "", 0, 0, NULL },
|
||||
.usage = "",
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_kill_server_exec
|
||||
"kill-server", NULL,
|
||||
"",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_kill_server_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_start_server_entry = {
|
||||
.name = "start-server",
|
||||
.alias = "start",
|
||||
|
||||
.args = { "", 0, 0, NULL },
|
||||
.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)
|
||||
int
|
||||
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
{
|
||||
if (cmd_get_entry(self) == &cmd_kill_server_entry)
|
||||
kill(getpid(), SIGTERM);
|
||||
sigterm = 1;
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-kill-session.c,v 1.12 2009-01-19 18:23:40 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -27,45 +27,42 @@
|
||||
* 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 = {
|
||||
.name = "kill-session",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "aCt:", 0, 0, NULL },
|
||||
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_kill_session_exec
|
||||
"kill-session", NULL,
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_kill_session_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct session *s = target->s, *sloop, *stmp;
|
||||
struct winlink *wl;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
u_int i;
|
||||
|
||||
if (args_has(args, 'C')) {
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
wl->window->flags &= ~WINDOW_ALERTFLAGS;
|
||||
wl->flags &= ~WINLINK_ALERTFLAGS;
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c->session == s) {
|
||||
c->session = NULL;
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
}
|
||||
server_redraw_session(s);
|
||||
} else if (args_has(args, 'a')) {
|
||||
RB_FOREACH_SAFE(sloop, sessions, &sessions, stmp) {
|
||||
if (sloop != s) {
|
||||
server_destroy_session(sloop);
|
||||
session_destroy(sloop, 1, __func__);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
server_destroy_session(s);
|
||||
session_destroy(s, 1, __func__);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
recalculate_sizes();
|
||||
|
||||
session_destroy(s);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-kill-window.c,v 1.15 2009-01-19 18:23:40 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -24,87 +24,46 @@
|
||||
* 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 = {
|
||||
.name = "kill-window",
|
||||
.alias = "killw",
|
||||
|
||||
.args = { "at:", 0, 0, NULL },
|
||||
.usage = "[-a] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_kill_window_exec
|
||||
"kill-window", "killw",
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_kill_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_unlink_window_entry = {
|
||||
.name = "unlink-window",
|
||||
.alias = "unlinkw",
|
||||
|
||||
.args = { "kt:", 0, 0, NULL },
|
||||
.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)
|
||||
int
|
||||
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct winlink *wl = target->wl, *loop;
|
||||
struct window *w = wl->window;
|
||||
struct session *s = target->s;
|
||||
u_int found;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
u_int i;
|
||||
int destroyed;
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_unlink_window_entry) {
|
||||
if (!args_has(args, 'k') && !session_is_linked(s, w)) {
|
||||
cmdq_error(item, "window only linked to one session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
server_unlink_window(s, wl);
|
||||
recalculate_sizes();
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
return (-1);
|
||||
|
||||
destroyed = session_detach(s, wl);
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session != s)
|
||||
continue;
|
||||
if (destroyed) {
|
||||
c->session = NULL;
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
} else
|
||||
server_redraw_client(c);
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
if (RB_PREV(winlinks, &s->windows, wl) == NULL &&
|
||||
RB_NEXT(winlinks, &s->windows, wl) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
/* Kill all windows except the current one. */
|
||||
do {
|
||||
found = 0;
|
||||
RB_FOREACH(loop, winlinks, &s->windows) {
|
||||
if (loop->window != wl->window) {
|
||||
server_kill_window(loop->window, 0);
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (found != 0);
|
||||
|
||||
/*
|
||||
* If the current window appears in the session more than once,
|
||||
* kill it as well.
|
||||
*/
|
||||
found = 0;
|
||||
RB_FOREACH(loop, winlinks, &s->windows) {
|
||||
if (loop->window == wl->window)
|
||||
found++;
|
||||
}
|
||||
if (found > 1)
|
||||
server_kill_window(wl->window, 0);
|
||||
|
||||
server_renumber_all();
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
server_kill_window(wl->window, 1);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
60
cmd-last-window.c
Normal file
60
cmd-last-window.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* $Id: cmd-last-window.c,v 1.16 2009-01-19 18:23:40 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "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_send,
|
||||
cmd_target_recv,
|
||||
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);
|
||||
}
|
||||
109
cmd-link-window.c
Normal file
109
cmd-link-window.c
Normal file
@@ -0,0 +1,109 @@
|
||||
/* $Id: cmd-link-window.c,v 1.28 2009-01-23 16:59:14 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <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,
|
||||
CMD_DFLAG|CMD_KFLAG,
|
||||
cmd_srcdst_init,
|
||||
cmd_srcdst_parse,
|
||||
cmd_link_window_exec,
|
||||
cmd_srcdst_send,
|
||||
cmd_srcdst_recv,
|
||||
cmd_srcdst_free,
|
||||
cmd_srcdst_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_srcdst_data *data = self->data;
|
||||
struct session *dst;
|
||||
struct winlink *wl_src, *wl_dst;
|
||||
char *cause;
|
||||
int idx;
|
||||
|
||||
if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (arg_parse_window(data->dst, &dst, &idx) != 0) {
|
||||
ctx->error(ctx, "bad window: %s", data->dst);
|
||||
return (-1);
|
||||
}
|
||||
if (dst == NULL)
|
||||
dst = ctx->cursession;
|
||||
if (dst == NULL)
|
||||
dst = cmd_current_session(ctx);
|
||||
if (dst == NULL) {
|
||||
ctx->error(ctx, "session not found: %s", data->dst);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
wl_dst = NULL;
|
||||
if (idx != -1)
|
||||
wl_dst = winlink_find_by_index(&dst->windows, idx);
|
||||
if (wl_dst != NULL) {
|
||||
if (wl_dst->window == wl_src->window)
|
||||
return (0);
|
||||
|
||||
if (data->flags & CMD_KFLAG) {
|
||||
/*
|
||||
* Can't use session_detach as it will destroy session
|
||||
* if this makes it empty.
|
||||
*/
|
||||
session_alert_cancel(dst, wl_dst);
|
||||
winlink_stack_remove(&dst->lastw, wl_dst);
|
||||
winlink_remove(&dst->windows, wl_dst);
|
||||
|
||||
/* Force select/redraw if current. */
|
||||
if (wl_dst == dst->curw) {
|
||||
data->flags &= ~CMD_DFLAG;
|
||||
dst->curw = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wl_dst = session_attach(dst, wl_src->window, idx, &cause);
|
||||
if (wl_dst == NULL) {
|
||||
ctx->error(ctx, "create session failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (data->flags & CMD_DFLAG)
|
||||
server_status_session(dst);
|
||||
else {
|
||||
session_select(dst, wl_dst->idx);
|
||||
server_redraw_session(dst);
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-list-buffers.c,v 1.7 2009-01-19 18:23:40 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
@@ -27,64 +26,66 @@
|
||||
* List paste buffers.
|
||||
*/
|
||||
|
||||
#define LIST_BUFFERS_TEMPLATE \
|
||||
"#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\""
|
||||
|
||||
static enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmdq_item *);
|
||||
int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_list_buffers_entry = {
|
||||
.name = "list-buffers",
|
||||
.alias = "lsb",
|
||||
|
||||
.args = { "F:f:O:r", 0, 0, NULL },
|
||||
.usage = "[-F format] [-f filter] [-O order]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_buffers_exec
|
||||
"list-buffers", "lsb",
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_list_buffers_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct paste_buffer **l;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
u_int i, n;
|
||||
struct sort_criteria sort_crit;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
struct paste_buffer *pb;
|
||||
u_int idx;
|
||||
char *tmp;
|
||||
size_t size, in, out;
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = LIST_BUFFERS_TEMPLATE;
|
||||
filter = args_get(args, 'f');
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (s->sx > 35) { /* leave three for ... */
|
||||
size = s->sx - 32;
|
||||
tmp = xmalloc(size + 1);
|
||||
} else {
|
||||
size = 0;
|
||||
tmp = NULL;
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
l = sort_get_buffers(&n, &sort_crit);
|
||||
for (i = 0; i < n; i++) {
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_defaults_paste_buffer(ft, l[i]);
|
||||
idx = 0;
|
||||
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
||||
if (tmp != NULL) {
|
||||
in = out = 0;
|
||||
while (out < size && pb->data[in] != '\0') {
|
||||
if (pb->data[in] > 31 && pb->data[in] != 127)
|
||||
tmp[out++] = pb->data[in];
|
||||
in++;
|
||||
}
|
||||
tmp[out] = '\0';
|
||||
if (out == size) {
|
||||
tmp[out - 1] = '.';
|
||||
tmp[out - 2] = '.';
|
||||
tmp[out - 3] = '.';
|
||||
}
|
||||
|
||||
if (filter != NULL) {
|
||||
expanded = format_expand(ft, filter);
|
||||
flag = format_true(expanded);
|
||||
free(expanded);
|
||||
ctx->print(ctx, "%d: %zu bytes: \"%s\"",
|
||||
idx - 1, strlen(pb->data), tmp);
|
||||
} else
|
||||
flag = 1;
|
||||
if (flag) {
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
format_free(ft);
|
||||
ctx->print(ctx, "%d: %zu bytes", idx, strlen(pb->data));
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (tmp != NULL)
|
||||
xfree(tmp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-list-clients.c,v 1.16 2009-06-25 16:34:50 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -28,81 +27,41 @@
|
||||
* List all clients.
|
||||
*/
|
||||
|
||||
#define LIST_CLIENTS_TEMPLATE \
|
||||
"#{client_name}: #{session_name} " \
|
||||
"[#{client_width}x#{client_height} #{client_termname}] " \
|
||||
"#{?#{!=:#{client_uid},#{uid}}," \
|
||||
"[user #{?client_user,#{client_user},#{client_uid},}] ,}" \
|
||||
"#{?client_flags,(,}#{client_flags}#{?client_flags,),}"
|
||||
|
||||
static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmdq_item *);
|
||||
int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_list_clients_entry = {
|
||||
.name = "list-clients",
|
||||
.alias = "lsc",
|
||||
|
||||
.args = { "F:f:O:rt:", 0, 0, NULL },
|
||||
.usage = "[-F format] [-f filter] [-O order]" CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = CMD_READONLY|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_clients_exec
|
||||
"list-clients", "lsc",
|
||||
"",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_clients_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
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 = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct client **l;
|
||||
struct session *s;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
u_int i, n;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
struct sort_criteria sort_crit;
|
||||
struct client *c;
|
||||
u_int i;
|
||||
const char *s_utf8;
|
||||
|
||||
if (args_has(args, 't'))
|
||||
s = target->s;
|
||||
else
|
||||
s = NULL;
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = LIST_CLIENTS_TEMPLATE;
|
||||
filter = args_get(args, 'f');
|
||||
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
l = sort_get_clients(&n, &sort_crit);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (l[i]->session == NULL || (s != NULL && s != l[i]->session))
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session == NULL)
|
||||
continue;
|
||||
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", i);
|
||||
format_defaults(ft, l[i], NULL, NULL, NULL);
|
||||
|
||||
if (filter != NULL) {
|
||||
expanded = format_expand(ft, filter);
|
||||
flag = format_true(expanded);
|
||||
free(expanded);
|
||||
} else
|
||||
flag = 1;
|
||||
if (flag) {
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
format_free(ft);
|
||||
if (c->tty.flags & TTY_UTF8)
|
||||
s_utf8 = " (utf8)";
|
||||
else
|
||||
s_utf8 = "";
|
||||
ctx->print(ctx, "%s: %s [%ux%u %s]%s", c->tty.path,
|
||||
c->session->name, c->tty.sx, c->tty.sy,
|
||||
c->tty.termname, s_utf8);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-list-commands.c,v 1.3 2009-01-19 18:23:40 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,90 +18,34 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* List all commands.
|
||||
* List all commands with usages.
|
||||
*/
|
||||
|
||||
#define LIST_COMMANDS_TEMPLATE \
|
||||
"#{command_list_name}" \
|
||||
"#{?command_list_alias, (#{command_list_alias}),} " \
|
||||
"#{command_list_usage}"
|
||||
|
||||
static enum cmd_retval cmd_list_commands(struct cmd *, struct cmdq_item *);
|
||||
int cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_list_commands_entry = {
|
||||
.name = "list-commands",
|
||||
.alias = "lscm",
|
||||
|
||||
.args = { "F:", 0, 1, NULL },
|
||||
.usage = "[-F format] [command]",
|
||||
|
||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_commands
|
||||
"list-commands", "lscm",
|
||||
"",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_commands_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_list_single_command(const struct cmd_entry *entry, struct format_tree *ft,
|
||||
const char *template, struct cmdq_item *item)
|
||||
int
|
||||
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
const char *s;
|
||||
char *line;
|
||||
const struct cmd_entry **entryp;
|
||||
|
||||
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);
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++)
|
||||
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
if (*line != '\0')
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_commands(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
const struct cmd_entry **entryp;
|
||||
const struct cmd_entry *entry;
|
||||
struct format_tree *ft;
|
||||
const char *template, *command;
|
||||
char *cause;
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = LIST_COMMANDS_TEMPLATE;
|
||||
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
||||
|
||||
command = args_string(args, 0);
|
||||
if (command == NULL) {
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++)
|
||||
cmd_list_single_command(*entryp, ft, template, item);
|
||||
} else {
|
||||
entry = cmd_find(command, &cause);
|
||||
if (entry != NULL)
|
||||
cmd_list_single_command(entry, ft, template, item);
|
||||
else {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
format_free(ft);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
format_free(ft);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
244
cmd-list-keys.c
244
cmd-list-keys.c
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-list-keys.c,v 1.14 2009-05-04 17:58:26 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,234 +18,42 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* List key bindings.
|
||||
*/
|
||||
|
||||
#define LIST_KEYS_TEMPLATE \
|
||||
"#{?notes_only," \
|
||||
"#{key_prefix} " \
|
||||
"#{p|#{key_string_width}:key_string} " \
|
||||
"#{?key_note,#{key_note},#{key_command}}" \
|
||||
"," \
|
||||
"bind-key #{?key_has_repeat,#{?key_repeat,-r, },} " \
|
||||
"-T #{p|#{key_table_width}:key_table} " \
|
||||
"#{p|#{key_string_width}:key_string} " \
|
||||
"#{key_command}}"
|
||||
|
||||
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *);
|
||||
int cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_list_keys_entry = {
|
||||
.name = "list-keys",
|
||||
.alias = "lsk",
|
||||
|
||||
.args = { "1aF:NO:P:rT:", 0, 1, NULL },
|
||||
.usage = "[-1aNr] [-F format] [-O order] [-P prefix-string]"
|
||||
"[-T key-table] [key]",
|
||||
|
||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_keys_exec
|
||||
"list-keys", "lsk",
|
||||
"",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_keys_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *
|
||||
cmd_list_keys_get_prefix(struct args *args)
|
||||
int
|
||||
cmd_list_keys_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
key_code prefix;
|
||||
struct key_binding *bd;
|
||||
const char *key;
|
||||
char tmp[BUFSIZ];
|
||||
|
||||
if (args_has(args, 'P'))
|
||||
return (xstrdup(args_get(args, 'P')));
|
||||
|
||||
prefix = options_get_number(global_s_options, "prefix");
|
||||
if (prefix == KEYC_NONE)
|
||||
return (xstrdup(""));
|
||||
return (xstrdup(key_string_lookup_key(prefix, 0)));
|
||||
}
|
||||
|
||||
static u_int
|
||||
cmd_list_keys_get_width(struct key_binding **l, u_int n)
|
||||
{
|
||||
u_int i, width, keywidth = 0;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
width = utf8_cstrwidth(key_string_lookup_key(l[i]->key, 0));
|
||||
if (width > keywidth)
|
||||
keywidth = width;
|
||||
}
|
||||
return (keywidth);
|
||||
}
|
||||
|
||||
static u_int
|
||||
cmd_list_keys_get_table_width(struct key_binding **l, u_int n)
|
||||
{
|
||||
u_int i, width, tablewidth = 0;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
width = utf8_cstrwidth(l[i]->tablename);
|
||||
if (width > tablewidth)
|
||||
tablewidth = width;
|
||||
}
|
||||
return (tablewidth);
|
||||
}
|
||||
|
||||
static struct key_binding **
|
||||
cmd_get_root_and_prefix(u_int *n, struct sort_criteria *sort_crit)
|
||||
{
|
||||
const char *tables[] = { "prefix", "root" };
|
||||
struct key_table *t;
|
||||
struct key_binding **lt;
|
||||
u_int i, ltsz, len = 0, offset = 0;
|
||||
static struct key_binding **l = NULL;
|
||||
static u_int lsz = 0;
|
||||
|
||||
for (i = 0; i < nitems(tables); i++) {
|
||||
t = key_bindings_get_table(tables[i], 0);
|
||||
lt = sort_get_key_bindings_table(t, <sz, sort_crit);
|
||||
len += ltsz;
|
||||
if (lsz <= len) {
|
||||
lsz = len + 100;
|
||||
l = xreallocarray(l, lsz, sizeof *l);
|
||||
}
|
||||
memcpy(l + offset, lt, ltsz * sizeof *l);
|
||||
offset += ltsz;
|
||||
}
|
||||
|
||||
*n = len;
|
||||
return (l);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_filter_key_list(int filter_notes, int filter_key, key_code only,
|
||||
struct key_binding **l, u_int *n)
|
||||
{
|
||||
key_code key;
|
||||
u_int i, j = 0;
|
||||
|
||||
for (i = 0; i < *n; i++) {
|
||||
key = l[i]->key & (KEYC_MASK_KEY|KEYC_MASK_MODIFIERS);
|
||||
if (filter_key && only != key)
|
||||
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||
if ((key = key_string_lookup_key(bd->key)) == NULL)
|
||||
continue;
|
||||
if (filter_notes && l[i]->note == NULL)
|
||||
continue;
|
||||
l[j++] = l[i];
|
||||
|
||||
*tmp = '\0';
|
||||
cmd_list_print(bd->cmdlist, tmp, sizeof tmp);
|
||||
ctx->print(ctx, "%11s: %s", key, tmp);
|
||||
}
|
||||
*n = j;
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_format_add_key_binding(struct format_tree *ft,
|
||||
const struct key_binding *bd, const char *prefix)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
if (bd->flags & KEY_BINDING_REPEAT)
|
||||
format_add(ft, "key_repeat", "1");
|
||||
else
|
||||
format_add(ft, "key_repeat", "0");
|
||||
|
||||
if (bd->note != NULL)
|
||||
format_add(ft, "key_note", "%s", bd->note);
|
||||
else
|
||||
format_add(ft, "key_note", "%s", "");
|
||||
|
||||
format_add(ft, "key_prefix", "%s", prefix);
|
||||
format_add(ft, "key_table", "%s", bd->tablename);
|
||||
|
||||
s = key_string_lookup_key(bd->key, 0);
|
||||
format_add(ft, "key_string", "%s", s);
|
||||
|
||||
s = cmd_list_print(bd->cmdlist,
|
||||
CMD_LIST_PRINT_ESCAPED|CMD_LIST_PRINT_NO_GROUPS);
|
||||
format_add(ft, "key_command", "%s", s);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct format_tree *ft;
|
||||
struct key_table *table = NULL;
|
||||
struct key_binding **l;
|
||||
key_code only = KEYC_UNKNOWN;
|
||||
const char *template, *tablename, *keystr;
|
||||
char *line;
|
||||
char *prefix = NULL;
|
||||
u_int i, n;
|
||||
int single, notes_only, filter_notes, filter_key;
|
||||
struct sort_criteria sort_crit;
|
||||
|
||||
if ((keystr = args_string(args, 0)) != NULL) {
|
||||
only = key_string_lookup_string(keystr);
|
||||
if (only == KEYC_UNKNOWN) {
|
||||
cmdq_error(item, "invalid key: %s", keystr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
only &= (KEYC_MASK_KEY|KEYC_MASK_MODIFIERS);
|
||||
}
|
||||
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
prefix = cmd_list_keys_get_prefix(args);
|
||||
single = args_has(args, '1');
|
||||
notes_only = args_has(args, 'N');
|
||||
|
||||
if ((tablename = args_get(args, 'T')) != NULL) {
|
||||
table = key_bindings_get_table(tablename, 0);
|
||||
if (table == NULL) {
|
||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = LIST_KEYS_TEMPLATE;
|
||||
|
||||
if (table)
|
||||
l = sort_get_key_bindings_table(table, &n, &sort_crit);
|
||||
else if (notes_only)
|
||||
l = cmd_get_root_and_prefix(&n, &sort_crit);
|
||||
else
|
||||
l = sort_get_key_bindings(&n, &sort_crit);
|
||||
|
||||
filter_notes = notes_only && !args_has(args, 'a');
|
||||
filter_key = only != KEYC_UNKNOWN;
|
||||
if (filter_notes || filter_key)
|
||||
cmd_filter_key_list(filter_notes, filter_key, only, l, &n);
|
||||
if (single)
|
||||
n = 1;
|
||||
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
||||
format_add(ft, "notes_only", "%d", notes_only);
|
||||
format_add(ft, "key_has_repeat", "%d", key_bindings_has_repeat(l, n));
|
||||
format_add(ft, "key_string_width", "%u", cmd_list_keys_get_width(l, n));
|
||||
format_add(ft, "key_table_width", "%u",
|
||||
cmd_list_keys_get_table_width(l, n));
|
||||
for (i = 0; i < n; i++) {
|
||||
cmd_format_add_key_binding(ft, l[i], prefix);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
if ((single && tc != NULL) || n == 1)
|
||||
status_message_set(tc, -1, 1, 0, 0, "%s", line);
|
||||
else if (*line != '\0')
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
|
||||
if (single)
|
||||
break;
|
||||
}
|
||||
format_free(ft);
|
||||
free(prefix);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
160
cmd-list-panes.c
160
cmd-list-panes.c
@@ -1,160 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* List panes on given window.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static void cmd_list_panes_server(struct cmd *, struct cmdq_item *);
|
||||
static void cmd_list_panes_session(struct cmd *, struct session *,
|
||||
struct cmdq_item *, int);
|
||||
static void cmd_list_panes_window(struct cmd *, struct session *,
|
||||
struct winlink *, struct cmdq_item *, int);
|
||||
|
||||
const struct cmd_entry cmd_list_panes_entry = {
|
||||
.name = "list-panes",
|
||||
.alias = "lsp",
|
||||
|
||||
.args = { "aF:f:O:rst:", 0, 0, NULL },
|
||||
.usage = "[-asr] [-F format] [-f filter] [-O order]"
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_panes_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl;
|
||||
enum sort_order order;
|
||||
|
||||
order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
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 = cmd_get_args(self);
|
||||
struct window_pane *wp, **l;
|
||||
u_int i, n;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
struct sort_criteria sort_crit;
|
||||
|
||||
template = args_get(args, 'F');
|
||||
if (template == NULL) {
|
||||
switch (type) {
|
||||
case 0:
|
||||
template = "#{pane_index}: "
|
||||
"[#{pane_width}x#{pane_height}] [history "
|
||||
"#{history_size}/#{history_limit}, "
|
||||
"#{history_bytes} bytes] #{pane_id}"
|
||||
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
|
||||
break;
|
||||
case 1:
|
||||
template = "#{window_index}.#{pane_index}: "
|
||||
"[#{pane_width}x#{pane_height}] [history "
|
||||
"#{history_size}/#{history_limit}, "
|
||||
"#{history_bytes} bytes] #{pane_id}"
|
||||
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
|
||||
break;
|
||||
case 2:
|
||||
template = "#{session_name}:#{window_index}."
|
||||
"#{pane_index}: [#{pane_width}x#{pane_height}] "
|
||||
"[history #{history_size}/#{history_limit}, "
|
||||
"#{history_bytes} bytes] #{pane_id}"
|
||||
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
filter = args_get(args, 'f');
|
||||
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
l = sort_get_panes_window(wl->window, &n, &sort_crit);
|
||||
for (i = 0; i < n; i++) {
|
||||
wp = l[i];
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, wl, wp);
|
||||
|
||||
if (filter != NULL) {
|
||||
expanded = format_expand(ft, filter);
|
||||
flag = format_true(expanded);
|
||||
free(expanded);
|
||||
} else
|
||||
flag = 1;
|
||||
if (flag) {
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-list-sessions.c,v 1.19 2009-01-19 18:23:40 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -28,70 +27,41 @@
|
||||
* List all sessions.
|
||||
*/
|
||||
|
||||
#define LIST_SESSIONS_TEMPLATE \
|
||||
"#{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 *);
|
||||
int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_list_sessions_entry = {
|
||||
.name = "list-sessions",
|
||||
.alias = "ls",
|
||||
|
||||
.args = { "F:f:O:r", 0, 0, NULL },
|
||||
.usage = "[-r] [-F format] [-f filter] [-O order]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_sessions_exec
|
||||
"list-sessions", "ls", "",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_sessions_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
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 = cmd_get_args(self);
|
||||
struct session **l;
|
||||
u_int n, i;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
struct sort_criteria sort_crit;
|
||||
struct session *s;
|
||||
char *tim;
|
||||
u_int i;
|
||||
time_t t;
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = LIST_SESSIONS_TEMPLATE;
|
||||
filter = args_get(args, 'f');
|
||||
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||
s = ARRAY_ITEM(&sessions, i);
|
||||
if (s == NULL)
|
||||
continue;
|
||||
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
t = s->tv.tv_sec;
|
||||
tim = ctime(&t);
|
||||
*strchr(tim, '\n') = '\0';
|
||||
|
||||
l = sort_get_sessions(&n, &sort_crit);
|
||||
for (i = 0; i < n; i++) {
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", i);
|
||||
format_defaults(ft, NULL, l[i], NULL, NULL);
|
||||
|
||||
if (filter != NULL) {
|
||||
expanded = format_expand(ft, filter);
|
||||
flag = format_true(expanded);
|
||||
free(expanded);
|
||||
} else
|
||||
flag = 1;
|
||||
if (flag) {
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
format_free(ft);
|
||||
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s",
|
||||
s->name, winlink_count(&s->windows), tim, s->sx, s->sy,
|
||||
s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-list-windows.c,v 1.35 2009-05-04 17:58:26 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
@@ -27,89 +26,63 @@
|
||||
* List windows on given session.
|
||||
*/
|
||||
|
||||
#define LIST_WINDOWS_TEMPLATE \
|
||||
"#{window_index}: #{window_name}#{window_raw_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_raw_flags} " \
|
||||
"(#{window_panes} panes) " \
|
||||
"[#{window_width}x#{window_height}] "
|
||||
|
||||
static enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmdq_item *);
|
||||
int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_list_windows_entry = {
|
||||
.name = "list-windows",
|
||||
.alias = "lsw",
|
||||
|
||||
.args = { "aF:f:O:rt:", 0, 0, NULL },
|
||||
.usage = "[-ar] [-F format] [-f filter] [-O order]"
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_windows_exec
|
||||
"list-windows", "lsw",
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_list_windows_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct winlink *wl, **l;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
u_int i, n;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
struct sort_criteria sort_crit;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
struct grid *gd;
|
||||
u_int i;
|
||||
unsigned long long size;
|
||||
const char *name;
|
||||
|
||||
template = args_get(args, 'F');
|
||||
filter = args_get(args, 'f');
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
w = wl->window;
|
||||
ctx->print(ctx,
|
||||
"%3d: %s [%ux%u]", wl->idx, w->name, w->sx, w->sy);
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
l = sort_get_winlinks(&n, &sort_crit);
|
||||
if (template == NULL)
|
||||
template = LIST_WINDOWS_WITH_SESSION_TEMPLATE;
|
||||
} else {
|
||||
l = sort_get_winlinks_session(target->s, &n, &sort_crit);
|
||||
if (template == NULL)
|
||||
template = LIST_WINDOWS_TEMPLATE;
|
||||
}
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
gd = wp->base.grid;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
wl = l[i];
|
||||
s = wl->session;
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, wl, NULL);
|
||||
size = 0;
|
||||
for (i = 0; i < gd->hsize; i++) {
|
||||
size += gd->size[i] * sizeof **gd->data;
|
||||
size += gd->usize[i] * sizeof **gd->udata;
|
||||
}
|
||||
size += gd->hsize * (sizeof *gd->data);
|
||||
size += gd->hsize * (sizeof *gd->size);
|
||||
|
||||
if (filter != NULL) {
|
||||
expanded = format_expand(ft, filter);
|
||||
flag = format_true(expanded);
|
||||
free(expanded);
|
||||
} else
|
||||
flag = 1;
|
||||
if (flag) {
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
if (wp->fd != -1)
|
||||
name = ttyname(wp->fd);
|
||||
else
|
||||
name = "unknown";
|
||||
ctx->print(ctx,
|
||||
" %s [%ux%u %s] [history %u/%u, %llu bytes]",
|
||||
name, wp->sx, wp->sy, layout_name(w), gd->hsize,
|
||||
gd->hlimit, size);
|
||||
}
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
154
cmd-list.c
Normal file
154
cmd-list.c
Normal file
@@ -0,0 +1,154 @@
|
||||
/* $Id: cmd-list.c,v 1.5 2009-05-04 17:58:26 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 **new_argv;
|
||||
|
||||
cmdlist = xmalloc(sizeof *cmdlist);
|
||||
TAILQ_INIT(cmdlist);
|
||||
|
||||
lastsplit = 0;
|
||||
for (i = 0; i < argc; i++) {
|
||||
arglen = strlen(argv[i]);
|
||||
if (arglen == 0 || argv[i][arglen - 1] != ';')
|
||||
continue;
|
||||
argv[i][arglen - 1] = '\0';
|
||||
|
||||
if (arglen > 1 && argv[i][arglen - 2] == '\\') {
|
||||
argv[i][arglen - 2] = ';';
|
||||
continue;
|
||||
}
|
||||
|
||||
new_argc = i - lastsplit;
|
||||
new_argv = argv + lastsplit;
|
||||
if (arglen != 1)
|
||||
new_argc++;
|
||||
|
||||
cmd = cmd_parse(new_argc, new_argv, cause);
|
||||
if (cmd == NULL)
|
||||
goto bad;
|
||||
TAILQ_INSERT_TAIL(cmdlist, cmd, qentry);
|
||||
|
||||
lastsplit = i + 1;
|
||||
}
|
||||
|
||||
if (lastsplit != argc) {
|
||||
cmd = cmd_parse(argc - lastsplit, argv + lastsplit, cause);
|
||||
if (cmd == NULL)
|
||||
goto bad;
|
||||
TAILQ_INSERT_TAIL(cmdlist, cmd, qentry);
|
||||
}
|
||||
|
||||
return (cmdlist);
|
||||
|
||||
bad:
|
||||
cmd_list_free(cmdlist);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
int n;
|
||||
|
||||
TAILQ_FOREACH(cmd, cmdlist, qentry) {
|
||||
if ((n = cmd_exec(cmd, ctx)) != 0)
|
||||
return (n);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_send(struct cmd_list *cmdlist, struct buffer *b)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
u_int n;
|
||||
|
||||
n = 0;
|
||||
TAILQ_FOREACH(cmd, cmdlist, qentry)
|
||||
n++;
|
||||
|
||||
buffer_write(b, &n, sizeof n);
|
||||
TAILQ_FOREACH(cmd, cmdlist, qentry)
|
||||
cmd_send(cmd, b);
|
||||
}
|
||||
|
||||
struct cmd_list *
|
||||
cmd_list_recv(struct buffer *b)
|
||||
{
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd *cmd;
|
||||
u_int n;
|
||||
|
||||
buffer_read(b, &n, sizeof n);
|
||||
|
||||
cmdlist = xmalloc(sizeof *cmdlist);
|
||||
TAILQ_INIT(cmdlist);
|
||||
|
||||
while (n-- > 0) {
|
||||
cmd = cmd_recv(b);
|
||||
TAILQ_INSERT_TAIL(cmdlist, cmd, qentry);
|
||||
}
|
||||
|
||||
return (cmdlist);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_free(struct cmd_list *cmdlist)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
while (!TAILQ_EMPTY(cmdlist)) {
|
||||
cmd = TAILQ_FIRST(cmdlist);
|
||||
TAILQ_REMOVE(cmdlist, 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, 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.4 2009-05-21 19:38:51 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
@@ -17,10 +17,9 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@@ -28,86 +27,80 @@
|
||||
#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 *);
|
||||
|
||||
const struct cmd_entry cmd_load_buffer_entry = {
|
||||
.name = "load-buffer",
|
||||
.alias = "loadb",
|
||||
|
||||
.args = { "b:t:w", 1, 1, NULL },
|
||||
.usage = CMD_BUFFER_USAGE " " CMD_TARGET_CLIENT_USAGE " path",
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
|
||||
.exec = cmd_load_buffer_exec
|
||||
"load-buffer", "loadb",
|
||||
CMD_BUFFER_SESSION_USAGE " path",
|
||||
CMD_ARG1,
|
||||
cmd_buffer_init,
|
||||
cmd_buffer_parse,
|
||||
cmd_load_buffer_exec,
|
||||
cmd_buffer_send,
|
||||
cmd_buffer_recv,
|
||||
cmd_buffer_free,
|
||||
cmd_buffer_print
|
||||
};
|
||||
|
||||
struct cmd_load_buffer_data {
|
||||
struct client *client;
|
||||
struct cmdq_item *item;
|
||||
char *name;
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_load_buffer_done(__unused struct client *c, const char *path, int error,
|
||||
int closed, struct evbuffer *buffer, void *data)
|
||||
int
|
||||
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_load_buffer_data *cdata = data;
|
||||
struct client *tc = cdata->client;
|
||||
struct cmdq_item *item = cdata->item;
|
||||
void *bdata = EVBUFFER_DATA(buffer);
|
||||
size_t bsize = EVBUFFER_LENGTH(buffer);
|
||||
void *copy;
|
||||
char *cause;
|
||||
struct cmd_buffer_data *data = self->data;
|
||||
struct session *s;
|
||||
struct stat statbuf;
|
||||
FILE *f;
|
||||
char *buf;
|
||||
u_int limit;
|
||||
|
||||
if (!closed)
|
||||
return;
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (error != 0)
|
||||
cmdq_error(item, "%s: %s", strerror(error), path);
|
||||
else if (bsize != 0) {
|
||||
copy = xmalloc(bsize);
|
||||
memcpy(copy, bdata, bsize);
|
||||
if (paste_set(copy, bsize, cdata->name, &cause) != 0) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
free(copy);
|
||||
} else if (tc != NULL &&
|
||||
tc->session != NULL &&
|
||||
(~tc->flags & CLIENT_DEAD))
|
||||
tty_set_selection(&tc->tty, "", copy, bsize);
|
||||
if (tc != NULL)
|
||||
server_client_unref(tc);
|
||||
if (stat(data->arg, &statbuf) < 0) {
|
||||
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
cmdq_continue(item);
|
||||
|
||||
free(cdata->name);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct cmd_load_buffer_data *cdata;
|
||||
const char *bufname = args_get(args, 'b');
|
||||
char *path;
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->item = item;
|
||||
if (bufname != NULL)
|
||||
cdata->name = xstrdup(bufname);
|
||||
if (args_has(args, 'w') && tc != NULL) {
|
||||
cdata->client = tc;
|
||||
cdata->client->references++;
|
||||
if (!S_ISREG(statbuf.st_mode)) {
|
||||
ctx->error(ctx, "%s: not a regular file", data->arg);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
path = format_single_from_target(item, args_string(args, 0));
|
||||
file_read(cmdq_get_client(item), path, cmd_load_buffer_done, cdata);
|
||||
free(path);
|
||||
if ((f = fopen(data->arg, "rb")) == NULL) {
|
||||
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_WAIT);
|
||||
/*
|
||||
* We don't want to die due to memory exhaustion, hence xmalloc can't
|
||||
* be used here.
|
||||
*/
|
||||
if ((buf = malloc(statbuf.st_size + 1)) == NULL) {
|
||||
ctx->error(ctx, "malloc error: %s", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (fread(buf, 1, statbuf.st_size, f) != (size_t) statbuf.st_size) {
|
||||
ctx->error(ctx, "%s: fread error", data->arg);
|
||||
xfree(buf);
|
||||
fclose(f);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
buf[statbuf.st_size] = '\0';
|
||||
fclose(f);
|
||||
|
||||
limit = options_get_number(&s->options, "buffer-limit");
|
||||
if (data->buffer == -1) {
|
||||
paste_add(&s->buffers, buf, limit);
|
||||
return (0);
|
||||
}
|
||||
if (paste_replace(&s->buffers, data->buffer, buf) != 0) {
|
||||
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||
xfree(buf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-lock-server.c,v 1.4 2009-06-25 16:21:32 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,62 +18,35 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <string.h>
|
||||
#include <unistd.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 = {
|
||||
.name = "lock-server",
|
||||
.alias = "lock",
|
||||
|
||||
.args = { "", 0, 0, NULL },
|
||||
.usage = "",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_lock_server_exec
|
||||
"lock-server", "lock",
|
||||
"",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_lock_server_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_lock_session_entry = {
|
||||
.name = "lock-session",
|
||||
.alias = "locks",
|
||||
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.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, NULL },
|
||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_lock_server_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_lock_server_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_lock_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
server_lock();
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_lock_server_entry)
|
||||
server_lock();
|
||||
else if (cmd_get_entry(self) == &cmd_lock_session_entry)
|
||||
server_lock_session(target->s);
|
||||
else
|
||||
server_lock_client(tc);
|
||||
recalculate_sizes();
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-move-window.c,v 1.5 2009-01-23 16:59:14 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -26,97 +26,98 @@
|
||||
* 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 = {
|
||||
.name = "move-window",
|
||||
.alias = "movew",
|
||||
|
||||
.args = { "abdkrs:t:", 0, 0, NULL },
|
||||
.usage = "[-abdkr] " CMD_SRCDST_WINDOW_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_WINDOW, 0 },
|
||||
/* -t is special */
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_move_window_exec
|
||||
"move-window", "movew",
|
||||
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||
CMD_DFLAG|CMD_KFLAG,
|
||||
cmd_srcdst_init,
|
||||
cmd_srcdst_parse,
|
||||
cmd_move_window_exec,
|
||||
cmd_srcdst_send,
|
||||
cmd_srcdst_recv,
|
||||
cmd_srcdst_free,
|
||||
cmd_srcdst_print
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_link_window_entry = {
|
||||
.name = "link-window",
|
||||
.alias = "linkw",
|
||||
|
||||
.args = { "abdks:t:", 0, 0, NULL },
|
||||
.usage = "[-abdk] " 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)
|
||||
int
|
||||
cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *source = cmdq_get_source(item);
|
||||
struct cmd_find_state target;
|
||||
const char *tflag = args_get(args, 't');
|
||||
struct session *src = source->s;
|
||||
struct session *dst;
|
||||
struct winlink *wl = source->wl;
|
||||
struct cmd_srcdst_data *data = self->data;
|
||||
struct session *src, *dst;
|
||||
struct winlink *wl_src, *wl_dst;
|
||||
struct client *c;
|
||||
u_int i;
|
||||
int destroyed, idx;
|
||||
char *cause;
|
||||
int idx, kflag, dflag, sflag, before;
|
||||
|
||||
if (args_has(args, 'r')) {
|
||||
if (cmd_find_target(&target, item, tflag, CMD_FIND_SESSION,
|
||||
CMD_FIND_QUIET) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||
return (-1);
|
||||
|
||||
session_renumber_windows(target.s);
|
||||
recalculate_sizes();
|
||||
server_status_session(target.s);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (arg_parse_window(data->dst, &dst, &idx) != 0) {
|
||||
ctx->error(ctx, "bad window: %s", data->dst);
|
||||
return (-1);
|
||||
}
|
||||
if (cmd_find_target(&target, item, tflag, CMD_FIND_WINDOW,
|
||||
CMD_FIND_WINDOW_INDEX) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
dst = target.s;
|
||||
idx = target.idx;
|
||||
|
||||
kflag = args_has(args, 'k');
|
||||
dflag = args_has(args, 'd');
|
||||
sflag = args_has(args, 's');
|
||||
|
||||
before = args_has(args, 'b');
|
||||
if (args_has(args, 'a') || before) {
|
||||
if (target.wl != NULL)
|
||||
idx = winlink_shuffle_up(dst, target.wl, before);
|
||||
else
|
||||
idx = winlink_shuffle_up(dst, dst->curw, before);
|
||||
if (idx == -1)
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (dst == NULL)
|
||||
dst = ctx->cursession;
|
||||
if (dst == NULL)
|
||||
dst = cmd_current_session(ctx);
|
||||
if (dst == NULL) {
|
||||
ctx->error(ctx, "session not found: %s", data->dst);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
wl_dst = NULL;
|
||||
if (idx != -1)
|
||||
wl_dst = winlink_find_by_index(&dst->windows, idx);
|
||||
if (wl_dst != NULL) {
|
||||
if (wl_dst->window == wl_src->window)
|
||||
return (0);
|
||||
|
||||
if (data->flags & CMD_KFLAG) {
|
||||
/*
|
||||
* Can't use session_detach as it will destroy session
|
||||
* if this makes it empty.
|
||||
*/
|
||||
session_alert_cancel(dst, wl_dst);
|
||||
winlink_stack_remove(&dst->lastw, wl_dst);
|
||||
winlink_remove(&dst->windows, wl_dst);
|
||||
|
||||
/* Force select/redraw if current. */
|
||||
if (wl_dst == dst->curw) {
|
||||
data->flags &= ~CMD_DFLAG;
|
||||
dst->curw = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cmd_get_entry(self) == &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);
|
||||
wl_dst = session_attach(dst, wl_src->window, idx, &cause);
|
||||
if (wl_dst == NULL) {
|
||||
ctx->error(ctx, "attach window failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
destroyed = session_detach(src, wl_src);
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session != src)
|
||||
continue;
|
||||
if (destroyed) {
|
||||
c->session = NULL;
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
} else
|
||||
server_redraw_client(c);
|
||||
}
|
||||
|
||||
if (data->flags & CMD_DFLAG)
|
||||
server_status_session(dst);
|
||||
else {
|
||||
session_select(dst, wl_dst->idx);
|
||||
server_redraw_session(dst);
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-new-session.c,v 1.41 2009-05-04 17:58:26 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,354 +18,231 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* 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_send(struct cmd *, struct buffer *);
|
||||
void cmd_new_session_recv(struct cmd *, struct buffer *);
|
||||
void cmd_new_session_free(struct cmd *);
|
||||
void cmd_new_session_init(struct cmd *, int);
|
||||
size_t cmd_new_session_print(struct cmd *, char *, size_t);
|
||||
|
||||
static enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmdq_item *);
|
||||
struct cmd_new_session_data {
|
||||
char *newname;
|
||||
char *winname;
|
||||
char *cmd;
|
||||
int flag_detached;
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_new_session_entry = {
|
||||
.name = "new-session",
|
||||
.alias = "new",
|
||||
|
||||
.args = { "Ac:dDe:EF:f:n:Ps:t:x:Xy:", 0, -1, NULL },
|
||||
.usage = "[-AdDEPX] [-c start-directory] [-e environment] [-F format] "
|
||||
"[-f flags] [-n window-name] [-s session-name] "
|
||||
CMD_TARGET_SESSION_USAGE " [-x width] [-y height] "
|
||||
"[shell-command [argument ...]]",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_STARTSERVER,
|
||||
.exec = cmd_new_session_exec
|
||||
"new-session", "new",
|
||||
"[-d] [-n window-name] [-s session-name] [command]",
|
||||
CMD_STARTSERVER|CMD_CANTNEST,
|
||||
cmd_new_session_init,
|
||||
cmd_new_session_parse,
|
||||
cmd_new_session_exec,
|
||||
cmd_new_session_send,
|
||||
cmd_new_session_recv,
|
||||
cmd_new_session_free,
|
||||
cmd_new_session_print
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_has_session_entry = {
|
||||
.name = "has-session",
|
||||
.alias = "has",
|
||||
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.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)
|
||||
void
|
||||
cmd_new_session_init(struct cmd *self, unused int arg)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *current = cmdq_get_current(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct client *c = cmdq_get_client(item);
|
||||
struct session *s, *as, *groupwith = NULL;
|
||||
struct environ *env;
|
||||
struct options *oo;
|
||||
struct termios tio, *tiop;
|
||||
struct session_group *sg = NULL;
|
||||
const char *errstr, *template, *group, *tmp;
|
||||
char *cause, *cwd = NULL, *cp, *newname = NULL;
|
||||
char *name, *prefix = NULL;
|
||||
int detached, already_attached, is_control = 0;
|
||||
u_int sx, sy, dsx, dsy, count = args_count(args);
|
||||
struct spawn_context sc = { 0 };
|
||||
enum cmd_retval retval;
|
||||
struct cmd_find_state fs;
|
||||
struct args_value *av;
|
||||
struct cmd_new_session_data *data;
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_has_session_entry) {
|
||||
/*
|
||||
* cmd_find_target() will fail if the session cannot be found,
|
||||
* so always return success here.
|
||||
*/
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flag_detached = 0;
|
||||
data->newname = NULL;
|
||||
data->winname = NULL;
|
||||
data->cmd = NULL;
|
||||
}
|
||||
|
||||
if (args_has(args, 't') && (count != 0 || args_has(args, 'n'))) {
|
||||
cmdq_error(item, "command or window name given with target");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
int
|
||||
cmd_new_session_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_new_session_data *data;
|
||||
int opt;
|
||||
|
||||
tmp = args_get(args, 's');
|
||||
if (tmp != NULL) {
|
||||
name = format_single(item, tmp, c, NULL, NULL, NULL);
|
||||
newname = session_check_name(name);
|
||||
if (newname == NULL) {
|
||||
cmdq_error(item, "invalid session: %s", name);
|
||||
free(name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(name);
|
||||
}
|
||||
if (args_has(args, 'A')) {
|
||||
if (newname != NULL)
|
||||
as = session_find(newname);
|
||||
else
|
||||
as = target->s;
|
||||
if (as != NULL) {
|
||||
retval = cmd_attach_session(item, as->name,
|
||||
args_has(args, 'D'), args_has(args, 'X'), 0,
|
||||
args_get(args, 'c'), args_has(args, 'E'),
|
||||
args_get(args, 'f'));
|
||||
free(newname);
|
||||
return (retval);
|
||||
self->entry->init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "ds:n:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
data->flag_detached = 1;
|
||||
break;
|
||||
case 's':
|
||||
if (data->newname == NULL)
|
||||
data->newname = xstrdup(optarg);
|
||||
break;
|
||||
case 'n':
|
||||
if (data->winname == NULL)
|
||||
data->winname = xstrdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
if (newname != NULL && session_find(newname) != NULL) {
|
||||
cmdq_error(item, "duplicate session: %s", newname);
|
||||
goto fail;
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc != 0 && argc != 1)
|
||||
goto usage;
|
||||
|
||||
/* Is this going to be part of a session group? */
|
||||
group = args_get(args, 't');
|
||||
if (group != NULL) {
|
||||
groupwith = target->s;
|
||||
if (groupwith == NULL)
|
||||
sg = session_group_find(group);
|
||||
else
|
||||
sg = session_group_contains(groupwith);
|
||||
if (sg != NULL)
|
||||
prefix = xstrdup(sg->name);
|
||||
else if (groupwith != NULL)
|
||||
prefix = xstrdup(groupwith->name);
|
||||
else {
|
||||
prefix = session_check_name(group);
|
||||
if (prefix == NULL) {
|
||||
cmdq_error(item, "invalid session group: %s",
|
||||
group);
|
||||
goto fail;
|
||||
}
|
||||
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_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_new_session_data *data = self->data;
|
||||
struct client *c = ctx->cmdclient;
|
||||
struct session *s;
|
||||
char *cmd, *cwd, *cause;
|
||||
u_int sx, sy;
|
||||
|
||||
if (ctx->curclient != NULL)
|
||||
return (0);
|
||||
|
||||
if (!data->flag_detached) {
|
||||
if (c == NULL) {
|
||||
ctx->error(ctx, "no client to attach to");
|
||||
return (-1);
|
||||
}
|
||||
if (!(c->flags & CLIENT_TERMINAL)) {
|
||||
ctx->error(ctx, "not a terminal");
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set -d if no client. */
|
||||
detached = args_has(args, 'd');
|
||||
if (c == NULL)
|
||||
detached = 1;
|
||||
else if (c->flags & CLIENT_CONTROL)
|
||||
is_control = 1;
|
||||
if (data->newname != NULL && session_find(data->newname) != NULL) {
|
||||
ctx->error(ctx, "duplicate session: %s", data->newname);
|
||||
return (-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);
|
||||
cmd = data->cmd;
|
||||
if (cmd == NULL)
|
||||
cmd = options_get_string(&global_options, "default-command");
|
||||
if (c == NULL || c->cwd == NULL)
|
||||
cwd = options_get_string(&global_options, "default-path");
|
||||
else
|
||||
cwd = xstrdup(server_client_get_cwd(c, NULL));
|
||||
cwd = c->cwd;
|
||||
|
||||
/*
|
||||
* If this is a new client, check for nesting and save the termios
|
||||
* 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
|
||||
* detached, tty_open won't be called. It must be done before opening
|
||||
* the terminal as that calls tcsetattr() to prepare for tmux taking
|
||||
* over.
|
||||
*/
|
||||
if (!detached &&
|
||||
!already_attached &&
|
||||
c->fd != -1 &&
|
||||
(~c->flags & CLIENT_CONTROL)) {
|
||||
if (server_client_check_nested(cmdq_get_client(item))) {
|
||||
cmdq_error(item, "sessions should be nested with care, "
|
||||
"unset $TMUX to force");
|
||||
goto fail;
|
||||
}
|
||||
if (tcgetattr(c->fd, &tio) != 0)
|
||||
fatal("tcgetattr failed");
|
||||
tiop = &tio;
|
||||
} else
|
||||
tiop = NULL;
|
||||
|
||||
/* Open the terminal if necessary. */
|
||||
if (!detached && !already_attached) {
|
||||
if (server_client_open(c, &cause) != 0) {
|
||||
cmdq_error(item, "open terminal failed: %s", cause);
|
||||
free(cause);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get default session size. */
|
||||
if (args_has(args, 'x')) {
|
||||
tmp = args_get(args, 'x');
|
||||
if (strcmp(tmp, "-") == 0) {
|
||||
if (c != NULL)
|
||||
dsx = c->tty.sx;
|
||||
else
|
||||
dsx = 80;
|
||||
} else {
|
||||
dsx = strtonum(tmp, 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "width %s", errstr);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
} else
|
||||
dsx = 80;
|
||||
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;
|
||||
}
|
||||
}
|
||||
} else
|
||||
dsy = 24;
|
||||
|
||||
/* Find new session size. */
|
||||
if (!detached && !is_control) {
|
||||
sx = 80;
|
||||
sy = 25;
|
||||
if (!data->flag_detached) {
|
||||
sx = c->tty.sx;
|
||||
sy = c->tty.sy;
|
||||
if (sy > 0 && options_get_number(global_s_options, "status"))
|
||||
}
|
||||
|
||||
if (options_get_number(&global_options, "status")) {
|
||||
if (sy == 0)
|
||||
sy = 1;
|
||||
else
|
||||
sy--;
|
||||
}
|
||||
|
||||
if (!data->flag_detached && tty_open(&c->tty, &cause) != 0) {
|
||||
ctx->error(ctx, "open terminal failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
s = session_create(data->newname, cmd, cwd, sx, sy, &cause);
|
||||
if (s == NULL) {
|
||||
ctx->error(ctx, "create session failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
if (data->winname != NULL) {
|
||||
xfree(s->curw->window->name);
|
||||
s->curw->window->name = xstrdup(data->winname);
|
||||
options_set_number(
|
||||
&s->curw->window->options, "automatic-rename", 0);
|
||||
}
|
||||
|
||||
if (data->flag_detached) {
|
||||
if (c != NULL)
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
} else {
|
||||
tmp = options_get_string(global_s_options, "default-size");
|
||||
if (sscanf(tmp, "%ux%u", &sx, &sy) != 2) {
|
||||
sx = dsx;
|
||||
sy = dsy;
|
||||
} else {
|
||||
if (args_has(args, 'x'))
|
||||
sx = dsx;
|
||||
if (args_has(args, 'y'))
|
||||
sy = dsy;
|
||||
}
|
||||
c->session = s;
|
||||
server_write_client(c, MSG_READY, NULL, 0);
|
||||
server_redraw_client(c);
|
||||
}
|
||||
if (sx == 0)
|
||||
sx = 1;
|
||||
if (sy == 0)
|
||||
sy = 1;
|
||||
recalculate_sizes();
|
||||
|
||||
/* Create the new session. */
|
||||
oo = options_create(global_s_options);
|
||||
if (args_has(args, 'x') || args_has(args, 'y')) {
|
||||
if (!args_has(args, 'x'))
|
||||
dsx = sx;
|
||||
if (!args_has(args, 'y'))
|
||||
dsy = sy;
|
||||
options_set_string(oo, "default-size", 0, "%ux%u", dsx, dsy);
|
||||
}
|
||||
env = environ_create();
|
||||
if (c != NULL && !args_has(args, 'E'))
|
||||
environ_update(global_s_options, c->environ, env);
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(env, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
s = session_create(prefix, newname, cwd, env, oo, tiop);
|
||||
|
||||
/* Spawn the initial window. */
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
if (!detached)
|
||||
sc.tc = c;
|
||||
|
||||
sc.name = args_get(args, 'n');
|
||||
args_to_vector(args, &sc.argc, &sc.argv);
|
||||
|
||||
sc.idx = -1;
|
||||
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,
|
||||
* so add it to the group and synchronize.
|
||||
*/
|
||||
if (group != NULL) {
|
||||
if (sg == NULL) {
|
||||
if (groupwith != NULL) {
|
||||
sg = session_group_new(groupwith->name);
|
||||
session_group_add(sg, groupwith);
|
||||
} else
|
||||
sg = session_group_new(group);
|
||||
}
|
||||
session_group_add(sg, s);
|
||||
session_group_synchronize_to(s);
|
||||
session_select(s, RB_MIN(winlinks, &s->windows)->idx);
|
||||
}
|
||||
notify_session("session-created", s);
|
||||
|
||||
/*
|
||||
* Set the client to the new session. If a command client exists, it is
|
||||
* taking this session and needs to get MSG_READY and stay around.
|
||||
*/
|
||||
if (!detached) {
|
||||
if (args_has(args, 'f'))
|
||||
server_client_set_flags(c, args_get(args, 'f'));
|
||||
if (!already_attached) {
|
||||
if (~c->flags & CLIENT_CONTROL)
|
||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
||||
} else if (c->session != NULL)
|
||||
c->last_session = c->session;
|
||||
server_client_set_session(c, s);
|
||||
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
||||
server_client_set_key_table(c, NULL);
|
||||
}
|
||||
|
||||
/* Print if requested. */
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = NEW_SESSION_TEMPLATE;
|
||||
cp = format_single(item, template, c, s, s->curw, NULL);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
}
|
||||
|
||||
if (!detached)
|
||||
c->flags |= CLIENT_ATTACHED;
|
||||
if (!args_has(args, 'd'))
|
||||
cmd_find_from_session(current, s, 0);
|
||||
|
||||
cmd_find_from_session(&fs, s, 0);
|
||||
cmdq_insert_hook(s, item, &fs, "after-new-session");
|
||||
|
||||
if (cfg_finished)
|
||||
cfg_show_causes(s);
|
||||
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
free(cwd);
|
||||
free(newname);
|
||||
free(prefix);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
fail:
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
free(cwd);
|
||||
free(newname);
|
||||
free(prefix);
|
||||
return (CMD_RETURN_ERROR);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_session_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_new_session_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->newname);
|
||||
cmd_send_string(b, data->winname);
|
||||
cmd_send_string(b, data->cmd);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_session_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_new_session_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->newname = cmd_recv_string(b);
|
||||
data->winname = cmd_recv_string(b);
|
||||
data->cmd = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_session_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_new_session_data *data = self->data;
|
||||
|
||||
if (data->newname != NULL)
|
||||
xfree(data->newname);
|
||||
if (data->winname != NULL)
|
||||
xfree(data->winname);
|
||||
if (data->cmd != NULL)
|
||||
xfree(data->cmd);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_new_session_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_new_session_data *data = self->data;
|
||||
size_t off = 0;
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return (off);
|
||||
if (off < len && data->flag_detached)
|
||||
off += xsnprintf(buf + off, len - off, " -d");
|
||||
if (off < len && data->newname != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -s ", data->newname);
|
||||
if (off < len && data->winname != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -n ", data->winname);
|
||||
if (off < len && data->cmd != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->cmd);
|
||||
return (off);
|
||||
}
|
||||
|
||||
337
cmd-new-window.c
337
cmd-new-window.c
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-new-window.c,v 1.31 2009-01-23 16:59:14 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,11 +18,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -30,131 +26,216 @@
|
||||
* 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_send(struct cmd *, struct buffer *);
|
||||
void cmd_new_window_recv(struct cmd *, struct buffer *);
|
||||
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 *);
|
||||
|
||||
const struct cmd_entry cmd_new_window_entry = {
|
||||
.name = "new-window",
|
||||
.alias = "neww",
|
||||
|
||||
.args = { "abc:de:F:kn:PSt:", 0, -1, NULL },
|
||||
.usage = "[-abdkPS] [-c start-directory] [-e environment] [-F format] "
|
||||
"[-n window-name] " CMD_TARGET_WINDOW_USAGE
|
||||
" [shell-command [argument ...]]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_new_window_exec
|
||||
struct cmd_new_window_data {
|
||||
char *target;
|
||||
char *name;
|
||||
char *cmd;
|
||||
int flag_detached;
|
||||
int flag_kill;
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
const struct cmd_entry cmd_new_window_entry = {
|
||||
"new-window", "neww",
|
||||
"[-dk] [-n window-name] [-t target-window] [command]",
|
||||
0,
|
||||
cmd_new_window_init,
|
||||
cmd_new_window_parse,
|
||||
cmd_new_window_exec,
|
||||
cmd_new_window_send,
|
||||
cmd_new_window_recv,
|
||||
cmd_new_window_free,
|
||||
cmd_new_window_print
|
||||
};
|
||||
|
||||
void
|
||||
cmd_new_window_init(struct cmd *self, unused int arg)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c = cmdq_get_client(item);
|
||||
struct cmd_find_state *current = cmdq_get_current(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct spawn_context sc = { 0 };
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl, *new_wl = NULL;
|
||||
int idx = target->idx, before;
|
||||
char *cause = NULL, *cp, *expanded;
|
||||
const char *template, *name;
|
||||
struct cmd_find_state fs;
|
||||
struct args_value *av;
|
||||
struct cmd_new_window_data *data;
|
||||
|
||||
/*
|
||||
* If -S and -n are given and -t is not and a single window with this
|
||||
* name already exists, select it.
|
||||
*/
|
||||
name = args_get(args, 'n');
|
||||
if (args_has(args, 'S') && name != NULL && target->idx == -1) {
|
||||
expanded = format_single(item, name, c, s, NULL, NULL);
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
if (strcmp(wl->window->name, expanded) != 0)
|
||||
continue;
|
||||
if (new_wl == NULL) {
|
||||
new_wl = wl;
|
||||
continue;
|
||||
}
|
||||
cmdq_error(item, "multiple windows named %s", name);
|
||||
free(expanded);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(expanded);
|
||||
if (new_wl != NULL) {
|
||||
if (args_has(args, 'd'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (session_set_current(s, new_wl) == 0)
|
||||
server_redraw_session(s);
|
||||
if (c != NULL && c->session != NULL)
|
||||
s->curw->window->latest = c;
|
||||
recalculate_sizes();
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
before = args_has(args, 'b');
|
||||
if (args_has(args, 'a') || before) {
|
||||
idx = winlink_shuffle_up(s, wl, before);
|
||||
if (idx == -1)
|
||||
idx = target->idx;
|
||||
}
|
||||
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.tc = tc;
|
||||
|
||||
sc.name = args_get(args, 'n');
|
||||
args_to_vector(args, &sc.argc, &sc.argv);
|
||||
sc.environ = environ_create();
|
||||
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(sc.environ, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
|
||||
sc.idx = idx;
|
||||
sc.cwd = args_get(args, 'c');
|
||||
|
||||
sc.flags = 0;
|
||||
if (args_has(args, 'd'))
|
||||
sc.flags |= SPAWN_DETACHED;
|
||||
if (args_has(args, 'k'))
|
||||
sc.flags |= SPAWN_KILL;
|
||||
|
||||
if ((new_wl = spawn_window(&sc, &cause)) == NULL) {
|
||||
cmdq_error(item, "create window failed: %s", cause);
|
||||
free(cause);
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (!args_has(args, 'd') || new_wl == s->curw) {
|
||||
cmd_find_from_winlink(current, new_wl, 0);
|
||||
server_redraw_session_group(s);
|
||||
} else
|
||||
server_status_session_group(s);
|
||||
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = NEW_WINDOW_TEMPLATE;
|
||||
cp = format_single(item, template, tc, s, new_wl,
|
||||
new_wl->window->active);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
}
|
||||
|
||||
cmd_find_from_winlink(&fs, new_wl, 0);
|
||||
cmdq_insert_hook(s, item, &fs, "after-new-window");
|
||||
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->target = NULL;
|
||||
data->name = NULL;
|
||||
data->cmd = NULL;
|
||||
data->flag_detached = 0;
|
||||
data->flag_kill = 0;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_new_window_data *data;
|
||||
int opt;
|
||||
|
||||
self->entry->init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "dkt:n:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
data->flag_detached = 1;
|
||||
break;
|
||||
case 'k':
|
||||
data->flag_kill = 1;
|
||||
break;
|
||||
case 't':
|
||||
if (data->target == NULL)
|
||||
data->target = xstrdup(optarg);
|
||||
break;
|
||||
case 'n':
|
||||
if (data->name == NULL)
|
||||
data->name = xstrdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
if (data == NULL)
|
||||
return (0);
|
||||
|
||||
if (arg_parse_window(data->target, &s, &idx) != 0) {
|
||||
ctx->error(ctx, "bad window: %s", data->target);
|
||||
return (-1);
|
||||
}
|
||||
if (s == NULL)
|
||||
s = ctx->cursession;
|
||||
if (s == NULL)
|
||||
s = cmd_current_session(ctx);
|
||||
if (s == NULL) {
|
||||
ctx->error(ctx, "session not found: %s", data->target);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
wl = NULL;
|
||||
if (idx != -1)
|
||||
wl = winlink_find_by_index(&s->windows, idx);
|
||||
if (wl != NULL) {
|
||||
if (data->flag_kill) {
|
||||
/*
|
||||
* Can't use session_detach as it will destroy session
|
||||
* if this makes it empty.
|
||||
*/
|
||||
session_alert_cancel(s, wl);
|
||||
winlink_stack_remove(&s->lastw, wl);
|
||||
winlink_remove(&s->windows, wl);
|
||||
|
||||
/* Force select/redraw if current. */
|
||||
if (wl == s->curw) {
|
||||
data->flag_detached = 0;
|
||||
s->curw = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cmd = data->cmd;
|
||||
if (cmd == NULL)
|
||||
cmd = options_get_string(&s->options, "default-command");
|
||||
if (ctx->cmdclient == NULL || ctx->cmdclient->cwd == NULL)
|
||||
cwd = options_get_string(&global_options, "default-path");
|
||||
else
|
||||
cwd = ctx->cmdclient->cwd;
|
||||
|
||||
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(s);
|
||||
} else
|
||||
server_status_session(s);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_window_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_new_window_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->name);
|
||||
cmd_send_string(b, data->cmd);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_window_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_new_window_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->name = cmd_recv_string(b);
|
||||
data->cmd = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_window_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_new_window_data *data = self->data;
|
||||
|
||||
if (data->target != NULL)
|
||||
xfree(data->target);
|
||||
if (data->name != NULL)
|
||||
xfree(data->name);
|
||||
if (data->cmd != NULL)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-next-layout.c,v 1.2 2009-04-30 21:17:06 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -20,20 +20,36 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
char *
|
||||
osdep_get_name(__unused int fd, __unused char *tty)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
/*
|
||||
* Switch window to next layout.
|
||||
*/
|
||||
|
||||
char *
|
||||
osdep_get_cwd(__unused int fd)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
int cmd_next_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
struct event_base *
|
||||
osdep_event_init(void)
|
||||
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_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_next_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
return (event_init());
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
layout_next(wl->window);
|
||||
ctx->info(ctx, "layout now: %s", layout_name(wl->window));
|
||||
|
||||
return (0);
|
||||
}
|
||||
78
cmd-next-window.c
Normal file
78
cmd-next-window.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/* $Id: cmd-next-window.c,v 1.17 2009-06-25 15:29:34 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "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,
|
||||
CMD_AFLAG,
|
||||
cmd_next_window_init,
|
||||
cmd_target_parse,
|
||||
cmd_next_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
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 == KEYC_ADDESC('n'))
|
||||
data->flags |= CMD_AFLAG;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
int activity;
|
||||
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
activity = 0;
|
||||
if (data->flags & CMD_AFLAG)
|
||||
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);
|
||||
}
|
||||
1748
cmd-parse.y
1748
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.16 2009-07-02 16:23:54 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
@@ -27,106 +26,53 @@
|
||||
* Paste paste buffer if present.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmdq_item *);
|
||||
int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
.name = "paste-buffer",
|
||||
.alias = "pasteb",
|
||||
|
||||
.args = { "db:prSs:t:", 0, 0, NULL },
|
||||
.usage = "[-dprS] [-s separator] " CMD_BUFFER_USAGE " "
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_paste_buffer_exec
|
||||
"paste-buffer", "pasteb",
|
||||
"[-d] " CMD_BUFFER_WINDOW_USAGE,
|
||||
CMD_DFLAG,
|
||||
cmd_buffer_init,
|
||||
cmd_buffer_parse,
|
||||
cmd_paste_buffer_exec,
|
||||
cmd_buffer_send,
|
||||
cmd_buffer_recv,
|
||||
cmd_buffer_free,
|
||||
cmd_buffer_print
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_paste_buffer_paste(struct window_pane *wp, const char *buf, size_t len)
|
||||
int
|
||||
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
char *cp;
|
||||
size_t n;
|
||||
|
||||
n = utf8_stravisx(&cp, buf, len, VIS_SAFE|VIS_NOSLASH);
|
||||
bufferevent_write(wp->event, cp, n);
|
||||
free(cp);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct window_pane *wp = target->wp;
|
||||
struct cmd_buffer_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
struct session *s;
|
||||
struct paste_buffer *pb;
|
||||
const char *sepstr, *bufname, *bufdata, *bufend, *line;
|
||||
size_t seplen, bufsize, len;
|
||||
int bracket = args_has(args, 'p');
|
||||
|
||||
if (window_pane_exited(wp)) {
|
||||
cmdq_error(item, "target pane has exited");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
return (-1);
|
||||
w = wl->window;
|
||||
|
||||
bufname = NULL;
|
||||
if (args_has(args, 'b'))
|
||||
bufname = args_get(args, 'b');
|
||||
|
||||
if (bufname == NULL)
|
||||
pb = paste_get_top(NULL);
|
||||
if (data->buffer == -1)
|
||||
pb = paste_get_top(&s->buffers);
|
||||
else {
|
||||
pb = paste_get_name(bufname);
|
||||
if (pb == NULL) {
|
||||
cmdq_error(item, "no buffer %s", bufname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
|
||||
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (pb != NULL && ~wp->flags & PANE_INPUTOFF) {
|
||||
sepstr = args_get(args, 's');
|
||||
if (sepstr == NULL) {
|
||||
if (args_has(args, 'r'))
|
||||
sepstr = "\n";
|
||||
else
|
||||
sepstr = "\r";
|
||||
}
|
||||
seplen = strlen(sepstr);
|
||||
if (pb != NULL && *pb->data != '\0')
|
||||
buffer_write(w->active->out, pb->data, strlen(pb->data));
|
||||
|
||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
||||
bufferevent_write(wp->event, "\033[200~", 6);
|
||||
|
||||
bufdata = paste_buffer_data(pb, &bufsize);
|
||||
bufend = bufdata + bufsize;
|
||||
|
||||
for (;;) {
|
||||
line = memchr(bufdata, '\n', bufend - bufdata);
|
||||
if (line == NULL)
|
||||
break;
|
||||
len = line - bufdata;
|
||||
if (args_has(args, 'S'))
|
||||
bufferevent_write(wp->event, bufdata, len);
|
||||
else
|
||||
cmd_paste_buffer_paste(wp, bufdata, len);
|
||||
bufferevent_write(wp->event, sepstr, seplen);
|
||||
|
||||
bufdata = line + 1;
|
||||
}
|
||||
if (bufdata != bufend) {
|
||||
len = bufend - bufdata;
|
||||
if (args_has(args, 'S'))
|
||||
bufferevent_write(wp->event, bufdata, len);
|
||||
else
|
||||
cmd_paste_buffer_paste(wp, bufdata, len);
|
||||
}
|
||||
|
||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
||||
bufferevent_write(wp->event, "\033[201~", 6);
|
||||
/* Delete the buffer if -d. */
|
||||
if (data->flags & CMD_DFLAG) {
|
||||
if (data->buffer == -1)
|
||||
paste_free_top(&s->buffers);
|
||||
else
|
||||
paste_free_index(&s->buffers, data->buffer);
|
||||
}
|
||||
|
||||
if (pb != NULL && args_has(args, 'd'))
|
||||
paste_free(pb);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
233
cmd-pipe-pane.c
233
cmd-pipe-pane.c
@@ -1,233 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Open pipe to redirect pane output. If already open, close first.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static void cmd_pipe_pane_read_callback(struct bufferevent *, 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 = {
|
||||
.name = "pipe-pane",
|
||||
.alias = "pipep",
|
||||
|
||||
.args = { "IOot:", 0, 1, NULL },
|
||||
.usage = "[-IOo] " CMD_TARGET_PANE_USAGE " [shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_pipe_pane_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct window_pane *wp = target->wp;
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl;
|
||||
struct window_pane_offset *wpo = &wp->pipe_offset;
|
||||
char *cmd;
|
||||
int old_fd, pipe_fd[2], null_fd, in, out;
|
||||
struct format_tree *ft;
|
||||
sigset_t set, oldset;
|
||||
|
||||
/* Do nothing if pane is dead. */
|
||||
if (window_pane_exited(wp)) {
|
||||
cmdq_error(item, "target pane has exited");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Destroy the old pipe. */
|
||||
old_fd = wp->pipe_fd;
|
||||
if (wp->pipe_fd != -1) {
|
||||
bufferevent_free(wp->pipe_event);
|
||||
close(wp->pipe_fd);
|
||||
wp->pipe_fd = -1;
|
||||
|
||||
if (window_pane_destroy_ready(wp)) {
|
||||
server_destroy_pane(wp, 1);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
/* If no pipe command, that is enough. */
|
||||
if (args_count(args) == 0 || *args_string(args, 0) == '\0')
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
/*
|
||||
* With -o, only open the new pipe if there was no previous one. This
|
||||
* allows a pipe to be toggled with a single key, for example:
|
||||
*
|
||||
* bind ^p pipep -o 'cat >>~/output'
|
||||
*/
|
||||
if (args_has(args, 'o') && old_fd != -1)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
/* What do we want to do? Neither -I or -O is -O. */
|
||||
if (args_has(args, 'I')) {
|
||||
in = 1;
|
||||
out = args_has(args, 'O');
|
||||
} else {
|
||||
in = 0;
|
||||
out = 1;
|
||||
}
|
||||
|
||||
/* Open the new pipe. */
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
||||
cmdq_error(item, "socketpair error: %s", strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Expand the command. */
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, tc, s, wl, wp);
|
||||
cmd = format_expand_time(ft, args_string(args, 0));
|
||||
format_free(ft);
|
||||
|
||||
/* Fork the child. */
|
||||
sigfillset(&set);
|
||||
sigprocmask(SIG_BLOCK, &set, &oldset);
|
||||
switch ((wp->pipe_pid = fork())) {
|
||||
case -1:
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
cmdq_error(item, "fork error: %s", strerror(errno));
|
||||
|
||||
free(cmd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case 0:
|
||||
/* Child process. */
|
||||
proc_clear_signals(server_proc, 1);
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
close(pipe_fd[0]);
|
||||
|
||||
if (setpgid(0, 0) == -1)
|
||||
_exit(1);
|
||||
|
||||
null_fd = open(_PATH_DEVNULL, O_WRONLY);
|
||||
if (out) {
|
||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -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)
|
||||
_exit(1);
|
||||
closefrom(STDERR_FILENO + 1);
|
||||
|
||||
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
|
||||
_exit(1);
|
||||
default:
|
||||
/* Parent process. */
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
close(pipe_fd[1]);
|
||||
|
||||
wp->pipe_fd = pipe_fd[0];
|
||||
memcpy(wpo, &wp->offset, sizeof *wpo);
|
||||
|
||||
setblocking(wp->pipe_fd, 0);
|
||||
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
||||
cmd_pipe_pane_read_callback,
|
||||
cmd_pipe_pane_write_callback,
|
||||
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);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_pipe_pane_read_callback(__unused struct bufferevent *bufev, void *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);
|
||||
close(wp->pipe_fd);
|
||||
wp->pipe_fd = -1;
|
||||
|
||||
if (window_pane_destroy_ready(wp))
|
||||
server_destroy_pane(wp, 1);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
/* $Id: cmd-previous-layout.c,v 1.1 2009-04-30 21:17:06 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -15,43 +17,39 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "tmux.h"
|
||||
|
||||
#ifdef HAVE_UCRED_H
|
||||
#include <ucred.h>
|
||||
#endif
|
||||
/*
|
||||
* Switch window to previous layout.
|
||||
*/
|
||||
|
||||
#include "compat.h"
|
||||
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_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
getpeereid(int s, uid_t *uid, gid_t *gid)
|
||||
cmd_previous_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
#ifdef HAVE_SO_PEERCRED
|
||||
struct ucred uc;
|
||||
int len = sizeof uc;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
|
||||
if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &uc, &len) == -1)
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
*uid = uc.uid;
|
||||
*gid = uc.gid;
|
||||
return (0);
|
||||
#elif defined(HAVE_GETPEERUCRED)
|
||||
ucred_t *ucred = NULL;
|
||||
|
||||
if (getpeerucred(s, &ucred) == -1)
|
||||
return (-1);
|
||||
if ((*uid = ucred_geteuid(ucred)) == -1)
|
||||
return (-1);
|
||||
if ((*gid = ucred_getrgid(ucred)) == -1)
|
||||
return (-1);
|
||||
ucred_free(ucred);
|
||||
return (0);
|
||||
#else
|
||||
*uid = geteuid();
|
||||
*gid = getegid();
|
||||
layout_previous(wl->window);
|
||||
ctx->info(ctx, "layout now: %s", layout_name(wl->window));
|
||||
|
||||
return (0);
|
||||
#endif
|
||||
}
|
||||
78
cmd-previous-window.c
Normal file
78
cmd-previous-window.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/* $Id: cmd-previous-window.c,v 1.17 2009-06-25 15:29:34 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "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,
|
||||
CMD_AFLAG,
|
||||
cmd_previous_window_init,
|
||||
cmd_target_parse,
|
||||
cmd_previous_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
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 == KEYC_ADDESC('p'))
|
||||
data->flags |= CMD_AFLAG;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
int activity;
|
||||
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
activity = 0;
|
||||
if (data->flags & CMD_AFLAG)
|
||||
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);
|
||||
}
|
||||
899
cmd-queue.c
899
cmd-queue.c
@@ -1,899 +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 <pwd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/* Command queue flags. */
|
||||
#define CMDQ_FIRED 0x1
|
||||
#define CMDQ_WAITING 0x2
|
||||
|
||||
/* Command queue item type. */
|
||||
enum cmdq_type {
|
||||
CMDQ_COMMAND,
|
||||
CMDQ_CALLBACK,
|
||||
};
|
||||
|
||||
/* Command queue item. */
|
||||
struct cmdq_item {
|
||||
char *name;
|
||||
struct cmdq_list *queue;
|
||||
struct cmdq_item *next;
|
||||
|
||||
struct client *client;
|
||||
struct client *target_client;
|
||||
|
||||
enum cmdq_type type;
|
||||
u_int group;
|
||||
|
||||
u_int number;
|
||||
time_t time;
|
||||
|
||||
int flags;
|
||||
|
||||
struct cmdq_state *state;
|
||||
struct cmd_find_state source;
|
||||
struct cmd_find_state target;
|
||||
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd *cmd;
|
||||
|
||||
cmdq_cb cb;
|
||||
void *data;
|
||||
|
||||
TAILQ_ENTRY(cmdq_item) entry;
|
||||
};
|
||||
TAILQ_HEAD(cmdq_item_list, cmdq_item);
|
||||
|
||||
/*
|
||||
* Command queue state. This is the context for commands on the command queue.
|
||||
* It holds information about how the commands were fired (the key and flags),
|
||||
* any additional formats for the commands, and the current default target.
|
||||
* Multiple commands can share the same state and a command may update the
|
||||
* default target.
|
||||
*/
|
||||
struct cmdq_state {
|
||||
int references;
|
||||
int flags;
|
||||
|
||||
struct format_tree *formats;
|
||||
|
||||
struct key_event event;
|
||||
struct cmd_find_state current;
|
||||
};
|
||||
|
||||
/* Command queue. */
|
||||
struct cmdq_list {
|
||||
struct cmdq_item *item;
|
||||
struct cmdq_item_list list;
|
||||
};
|
||||
|
||||
/* 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)
|
||||
{
|
||||
static struct cmdq_list *global_queue;
|
||||
|
||||
if (c == NULL) {
|
||||
if (global_queue == NULL)
|
||||
global_queue = cmdq_new();
|
||||
return (global_queue);
|
||||
}
|
||||
return (c->queue);
|
||||
}
|
||||
|
||||
/* Create a queue. */
|
||||
struct cmdq_list *
|
||||
cmdq_new(void)
|
||||
{
|
||||
struct cmdq_list *queue;
|
||||
|
||||
queue = xcalloc(1, sizeof *queue);
|
||||
TAILQ_INIT (&queue->list);
|
||||
return (queue);
|
||||
}
|
||||
|
||||
/* Free a queue. */
|
||||
void
|
||||
cmdq_free(struct cmdq_list *queue)
|
||||
{
|
||||
if (!TAILQ_EMPTY(&queue->list))
|
||||
fatalx("queue not empty");
|
||||
free(queue);
|
||||
}
|
||||
|
||||
/* Get item name. */
|
||||
const char *
|
||||
cmdq_get_name(struct cmdq_item *item)
|
||||
{
|
||||
return (item->name);
|
||||
}
|
||||
|
||||
/* Get item client. */
|
||||
struct client *
|
||||
cmdq_get_client(struct cmdq_item *item)
|
||||
{
|
||||
return (item->client);
|
||||
}
|
||||
|
||||
/* Get item target client. */
|
||||
struct client *
|
||||
cmdq_get_target_client(struct cmdq_item *item)
|
||||
{
|
||||
return (item->target_client);
|
||||
}
|
||||
|
||||
/* Get item state. */
|
||||
struct cmdq_state *
|
||||
cmdq_get_state(struct cmdq_item *item)
|
||||
{
|
||||
return (item->state);
|
||||
}
|
||||
|
||||
/* Get item target. */
|
||||
struct cmd_find_state *
|
||||
cmdq_get_target(struct cmdq_item *item)
|
||||
{
|
||||
return (&item->target);
|
||||
}
|
||||
|
||||
/* Get item source. */
|
||||
struct cmd_find_state *
|
||||
cmdq_get_source(struct cmdq_item *item)
|
||||
{
|
||||
return (&item->source);
|
||||
}
|
||||
|
||||
/* Get state event. */
|
||||
struct key_event *
|
||||
cmdq_get_event(struct cmdq_item *item)
|
||||
{
|
||||
return (&item->state->event);
|
||||
}
|
||||
|
||||
/* Get state current target. */
|
||||
struct cmd_find_state *
|
||||
cmdq_get_current(struct cmdq_item *item)
|
||||
{
|
||||
return (&item->state->current);
|
||||
}
|
||||
|
||||
/* Get state flags. */
|
||||
int
|
||||
cmdq_get_flags(struct cmdq_item *item)
|
||||
{
|
||||
return (item->state->flags);
|
||||
}
|
||||
|
||||
/* Create a new state. */
|
||||
struct cmdq_state *
|
||||
cmdq_new_state(struct cmd_find_state *current, struct key_event *event,
|
||||
int flags)
|
||||
{
|
||||
struct cmdq_state *state;
|
||||
|
||||
state = xcalloc(1, sizeof *state);
|
||||
state->references = 1;
|
||||
state->flags = flags;
|
||||
|
||||
if (event != NULL)
|
||||
memcpy(&state->event, event, sizeof state->event);
|
||||
else
|
||||
state->event.key = KEYC_NONE;
|
||||
if (current != NULL && cmd_find_valid_state(current))
|
||||
cmd_find_copy_state(&state->current, current);
|
||||
else
|
||||
cmd_find_clear_state(&state->current, 0);
|
||||
|
||||
return (state);
|
||||
}
|
||||
|
||||
/* Add a reference to a state. */
|
||||
struct cmdq_state *
|
||||
cmdq_link_state(struct cmdq_state *state)
|
||||
{
|
||||
state->references++;
|
||||
return (state);
|
||||
}
|
||||
|
||||
/* Make a copy of a state. */
|
||||
struct cmdq_state *
|
||||
cmdq_copy_state(struct cmdq_state *state, struct cmd_find_state *current)
|
||||
{
|
||||
if (current != NULL)
|
||||
return (cmdq_new_state(current, &state->event, state->flags));
|
||||
return (cmdq_new_state(&state->current, &state->event, state->flags));
|
||||
}
|
||||
|
||||
/* Free a state. */
|
||||
void
|
||||
cmdq_free_state(struct cmdq_state *state)
|
||||
{
|
||||
if (--state->references != 0)
|
||||
return;
|
||||
|
||||
if (state->formats != NULL)
|
||||
format_free(state->formats);
|
||||
free(state);
|
||||
}
|
||||
|
||||
/* Add a format to command queue. */
|
||||
void
|
||||
cmdq_add_format(struct cmdq_state *state, const char *key, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *value;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&value, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (state->formats == NULL)
|
||||
state->formats = format_create(NULL, NULL, FORMAT_NONE, 0);
|
||||
format_add(state->formats, key, "%s", value);
|
||||
|
||||
free(value);
|
||||
}
|
||||
|
||||
/* Add formats to command queue. */
|
||||
void
|
||||
cmdq_add_formats(struct cmdq_state *state, struct format_tree *ft)
|
||||
{
|
||||
if (state->formats == NULL)
|
||||
state->formats = format_create(NULL, NULL, FORMAT_NONE, 0);
|
||||
format_merge(state->formats, ft);
|
||||
}
|
||||
|
||||
/* Merge formats from item. */
|
||||
void
|
||||
cmdq_merge_formats(struct cmdq_item *item, struct format_tree *ft)
|
||||
{
|
||||
const struct cmd_entry *entry;
|
||||
|
||||
if (item->cmd != NULL) {
|
||||
entry = cmd_get_entry(item->cmd);
|
||||
format_add(ft, "command", "%s", entry->name);
|
||||
}
|
||||
if (item->state->formats != NULL)
|
||||
format_merge(ft, item->state->formats);
|
||||
}
|
||||
|
||||
/* 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->list, item, entry);
|
||||
log_debug("%s %s: %s", __func__, cmdq_name(c), item->name);
|
||||
|
||||
item = next;
|
||||
} while (item != NULL);
|
||||
return (TAILQ_LAST(&queue->list, cmdq_item_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->list, 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 *current, const char *fmt, ...)
|
||||
{
|
||||
struct cmdq_state *state = item->state;
|
||||
struct cmd *cmd = item->cmd;
|
||||
struct args *args = cmd_get_args(cmd);
|
||||
struct args_entry *ae;
|
||||
struct args_value *av;
|
||||
struct options *oo;
|
||||
va_list ap;
|
||||
char *name, tmp[32], flag, *arguments;
|
||||
u_int i;
|
||||
const char *value;
|
||||
struct cmdq_item *new_item;
|
||||
struct cmdq_state *new_state;
|
||||
struct options_entry *o;
|
||||
struct options_array_item *a;
|
||||
struct cmd_list *cmdlist;
|
||||
|
||||
if (item->state->flags & CMDQ_STATE_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);
|
||||
|
||||
/*
|
||||
* The hooks get a new state because they should not update the current
|
||||
* target or formats for any subsequent commands.
|
||||
*/
|
||||
new_state = cmdq_new_state(current, &state->event, CMDQ_STATE_NOHOOKS);
|
||||
cmdq_add_format(new_state, "hook", "%s", name);
|
||||
|
||||
arguments = args_print(args);
|
||||
cmdq_add_format(new_state, "hook_arguments", "%s", arguments);
|
||||
free(arguments);
|
||||
|
||||
for (i = 0; i < args_count(args); i++) {
|
||||
xsnprintf(tmp, sizeof tmp, "hook_argument_%d", i);
|
||||
cmdq_add_format(new_state, tmp, "%s", args_string(args, i));
|
||||
}
|
||||
flag = args_first(args, &ae);
|
||||
while (flag != 0) {
|
||||
value = args_get(args, flag);
|
||||
if (value == NULL) {
|
||||
xsnprintf(tmp, sizeof tmp, "hook_flag_%c", flag);
|
||||
cmdq_add_format(new_state, tmp, "1");
|
||||
} else {
|
||||
xsnprintf(tmp, sizeof tmp, "hook_flag_%c", flag);
|
||||
cmdq_add_format(new_state, tmp, "%s", value);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
av = args_first_value(args, flag);
|
||||
while (av != NULL) {
|
||||
xsnprintf(tmp, sizeof tmp, "hook_flag_%c_%d", flag, i);
|
||||
cmdq_add_format(new_state, tmp, "%s", av->string);
|
||||
i++;
|
||||
av = args_next_value(av);
|
||||
}
|
||||
|
||||
flag = args_next(&ae);
|
||||
}
|
||||
|
||||
a = options_array_first(o);
|
||||
while (a != NULL) {
|
||||
cmdlist = options_array_item_value(a)->cmdlist;
|
||||
if (cmdlist != NULL) {
|
||||
new_item = cmdq_get_command(cmdlist, new_state);
|
||||
if (item != NULL)
|
||||
item = cmdq_insert_after(item, new_item);
|
||||
else
|
||||
item = cmdq_append(NULL, new_item);
|
||||
}
|
||||
a = options_array_next(a);
|
||||
}
|
||||
|
||||
cmdq_free_state(new_state);
|
||||
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->client != NULL)
|
||||
server_client_unref(item->client);
|
||||
if (item->cmdlist != NULL)
|
||||
cmd_list_free(item->cmdlist);
|
||||
cmdq_free_state(item->state);
|
||||
|
||||
TAILQ_REMOVE(&item->queue->list, 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;
|
||||
}
|
||||
}
|
||||
|
||||
/* Empty command callback. */
|
||||
static enum cmd_retval
|
||||
cmdq_empty_command(__unused struct cmdq_item *item, __unused void *data)
|
||||
{
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
/* Get a command for the command queue. */
|
||||
struct cmdq_item *
|
||||
cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state)
|
||||
{
|
||||
struct cmdq_item *item, *first = NULL, *last = NULL;
|
||||
struct cmd *cmd;
|
||||
const struct cmd_entry *entry;
|
||||
int created = 0;
|
||||
|
||||
if ((cmd = cmd_list_first(cmdlist)) == NULL)
|
||||
return (cmdq_get_callback(cmdq_empty_command, NULL));
|
||||
|
||||
if (state == NULL) {
|
||||
state = cmdq_new_state(NULL, NULL, 0);
|
||||
created = 1;
|
||||
}
|
||||
|
||||
while (cmd != NULL) {
|
||||
entry = cmd_get_entry(cmd);
|
||||
|
||||
item = xcalloc(1, sizeof *item);
|
||||
xasprintf(&item->name, "[%s/%p]", entry->name, item);
|
||||
item->type = CMDQ_COMMAND;
|
||||
|
||||
item->group = cmd_get_group(cmd);
|
||||
item->state = cmdq_link_state(state);
|
||||
|
||||
item->cmdlist = cmdlist;
|
||||
item->cmd = cmd;
|
||||
|
||||
cmdlist->references++;
|
||||
log_debug("%s: %s group %u", __func__, item->name, item->group);
|
||||
|
||||
if (first == NULL)
|
||||
first = item;
|
||||
if (last != NULL)
|
||||
last->next = item;
|
||||
last = item;
|
||||
|
||||
cmd = cmd_list_next(cmd);
|
||||
}
|
||||
|
||||
if (created)
|
||||
cmdq_free_state(state);
|
||||
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_from_client(fs, item->target_client, 0);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
value = args_get(cmd_get_args(item->cmd), 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);
|
||||
}
|
||||
|
||||
/* Add message with command. */
|
||||
static void
|
||||
cmdq_add_message(struct cmdq_item *item)
|
||||
{
|
||||
struct client *c = item->client;
|
||||
struct cmdq_state *state = item->state;
|
||||
const char *key;
|
||||
char *tmp;
|
||||
uid_t uid;
|
||||
struct passwd *pw;
|
||||
char *user = NULL;
|
||||
|
||||
tmp = cmd_print(item->cmd);
|
||||
if (c != NULL) {
|
||||
uid = proc_get_peer_uid(c->peer);
|
||||
if (uid != (uid_t)-1 && uid != getuid()) {
|
||||
if ((pw = getpwuid(uid)) != NULL)
|
||||
xasprintf(&user, "[%s]", pw->pw_name);
|
||||
else
|
||||
user = xstrdup("[unknown]");
|
||||
} else
|
||||
user = xstrdup("");
|
||||
if (c->session != NULL && state->event.key != KEYC_NONE) {
|
||||
key = key_string_lookup_key(state->event.key, 0);
|
||||
server_add_message("%s%s key %s: %s", c->name, user,
|
||||
key, tmp);
|
||||
} else {
|
||||
server_add_message("%s%s command: %s", c->name, user,
|
||||
tmp);
|
||||
}
|
||||
free(user);
|
||||
} else
|
||||
server_add_message("command: %s", tmp);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
/* Fire command on command queue. */
|
||||
static enum cmd_retval
|
||||
cmdq_fire_command(struct cmdq_item *item)
|
||||
{
|
||||
const char *name = cmdq_name(item->client);
|
||||
struct cmdq_state *state = item->state;
|
||||
struct cmd *cmd = item->cmd;
|
||||
struct args *args = cmd_get_args(cmd);
|
||||
const struct cmd_entry *entry = cmd_get_entry(cmd);
|
||||
struct client *tc, *saved = item->client;
|
||||
enum cmd_retval retval;
|
||||
struct cmd_find_state *fsp, fs;
|
||||
int flags, quiet = 0;
|
||||
char *tmp;
|
||||
|
||||
if (cfg_finished)
|
||||
cmdq_add_message(item);
|
||||
if (log_get_level() > 1) {
|
||||
tmp = cmd_print(cmd);
|
||||
log_debug("%s %s: (%u) %s", __func__, name, item->group, tmp);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
flags = !!(state->flags & CMDQ_STATE_CONTROL);
|
||||
cmdq_guard(item, "begin", flags);
|
||||
|
||||
if (item->client == NULL)
|
||||
item->client = cmd_find_client(item, NULL, 1);
|
||||
|
||||
if (entry->flags & CMD_CLIENT_CANFAIL)
|
||||
quiet = 1;
|
||||
if (entry->flags & CMD_CLIENT_CFLAG) {
|
||||
tc = cmd_find_client(item, args_get(args, 'c'), quiet);
|
||||
if (tc == NULL && !quiet) {
|
||||
retval = CMD_RETURN_ERROR;
|
||||
goto out;
|
||||
}
|
||||
} else if (entry->flags & CMD_CLIENT_TFLAG) {
|
||||
tc = cmd_find_client(item, args_get(args, 't'), quiet);
|
||||
if (tc == NULL && !quiet) {
|
||||
retval = CMD_RETURN_ERROR;
|
||||
goto out;
|
||||
}
|
||||
} else
|
||||
tc = cmd_find_client(item, NULL, 1);
|
||||
item->target_client = tc;
|
||||
|
||||
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->state->current))
|
||||
fsp = &item->state->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 = saved;
|
||||
if (retval == CMD_RETURN_ERROR) {
|
||||
fsp = NULL;
|
||||
if (cmd_find_valid_state(&item->target))
|
||||
fsp = &item->target;
|
||||
else if (cmd_find_valid_state(&item->state->current))
|
||||
fsp = &item->state->current;
|
||||
else if (cmd_find_from_client(&fs, item->client, 0) == 0)
|
||||
fsp = &fs;
|
||||
cmdq_insert_hook(fsp != NULL ? fsp->s : NULL, item, fsp,
|
||||
"command-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->state = cmdq_new_state(NULL, NULL, 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));
|
||||
}
|
||||
|
||||
/* 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->list)) {
|
||||
log_debug("%s %s: empty", __func__, name);
|
||||
return (0);
|
||||
}
|
||||
if (TAILQ_FIRST(&queue->list)->flags & CMDQ_WAITING) {
|
||||
log_debug("%s %s: waiting", __func__, name);
|
||||
return (0);
|
||||
}
|
||||
|
||||
log_debug("%s %s: enter", __func__, name);
|
||||
for (;;) {
|
||||
item = queue->item = TAILQ_FIRST(&queue->list);
|
||||
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);
|
||||
}
|
||||
queue->item = NULL;
|
||||
|
||||
log_debug("%s %s: exit (empty)", __func__, name);
|
||||
return (items);
|
||||
|
||||
waiting:
|
||||
log_debug("%s %s: exit (wait)", __func__, name);
|
||||
return (items);
|
||||
}
|
||||
|
||||
/* Get running item if any. */
|
||||
struct cmdq_item *
|
||||
cmdq_running(struct client *c)
|
||||
{
|
||||
struct cmdq_list *queue = cmdq_get(c);
|
||||
|
||||
if (queue->item == NULL)
|
||||
return (NULL);
|
||||
if (queue->item->flags & CMDQ_WAITING)
|
||||
return (NULL);
|
||||
return (queue->item);
|
||||
}
|
||||
|
||||
/* 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))
|
||||
control_write(c, "%%%s %ld %u %d", guard, t, number, flags);
|
||||
}
|
||||
|
||||
/* Show message from command. */
|
||||
void
|
||||
cmdq_print_data(struct cmdq_item *item, struct evbuffer *evb)
|
||||
{
|
||||
server_client_print(item->client, 1, evb);
|
||||
}
|
||||
|
||||
/* Show message from command. */
|
||||
void
|
||||
cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct evbuffer *evb;
|
||||
|
||||
evb = evbuffer_new();
|
||||
if (evb == NULL)
|
||||
fatalx("out of memory");
|
||||
|
||||
va_start(ap, fmt);
|
||||
evbuffer_add_vprintf(evb, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
cmdq_print_data(item, evb);
|
||||
evbuffer_free(evb);
|
||||
}
|
||||
|
||||
/* 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, *tmp;
|
||||
const char *file;
|
||||
u_int line;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&msg, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
log_debug("%s: %s", __func__, msg);
|
||||
|
||||
if (c == NULL) {
|
||||
cmd_get_source(cmd, &file, &line);
|
||||
cfg_add_cause("%s:%u: %s", file, line, msg);
|
||||
} else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
server_add_message("%s message: %s", c->name, msg);
|
||||
if (~c->flags & CLIENT_UTF8) {
|
||||
tmp = msg;
|
||||
msg = utf8_sanitize(tmp);
|
||||
free(tmp);
|
||||
}
|
||||
if (c->flags & CLIENT_CONTROL)
|
||||
control_write(c, "%s", msg);
|
||||
else
|
||||
file_error(c, "%s\n", msg);
|
||||
c->retval = 1;
|
||||
} else {
|
||||
*msg = toupper((u_char) *msg);
|
||||
status_message_set(c, -1, 1, 0, 0, "%s", msg);
|
||||
}
|
||||
|
||||
free(msg);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-refresh-client.c,v 1.8 2009-01-19 18:23:40 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,289 +18,37 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Refresh client.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_refresh_client_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
int cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_refresh_client_entry = {
|
||||
.name = "refresh-client",
|
||||
.alias = "refresh",
|
||||
|
||||
.args = { "A:B:cC:Df:r:F:lLRSt:U", 0, 1, NULL },
|
||||
.usage = "[-cDlLRSU] [-A pane:state] [-B name:what:format] "
|
||||
"[-C XxY] [-f flags] [-r pane:report] " CMD_TARGET_CLIENT_USAGE
|
||||
" [adjustment]",
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_refresh_client_exec
|
||||
"refresh-client", "refresh",
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_refresh_client_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_refresh_client_update_subscription(struct client *tc, const char *value)
|
||||
int
|
||||
cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
char *copy, *split, *name, *what;
|
||||
enum control_sub_type subtype;
|
||||
int subid = -1;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct client *c;
|
||||
|
||||
copy = name = xstrdup(value);
|
||||
if ((split = strchr(copy, ':')) == NULL) {
|
||||
control_remove_sub(tc, copy);
|
||||
goto out;
|
||||
}
|
||||
*split++ = '\0';
|
||||
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
what = split;
|
||||
if ((split = strchr(what, ':')) == NULL)
|
||||
goto out;
|
||||
*split++ = '\0';
|
||||
server_redraw_client(c);
|
||||
|
||||
if (strcmp(what, "%*") == 0)
|
||||
subtype = CONTROL_SUB_ALL_PANES;
|
||||
else if (sscanf(what, "%%%d", &subid) == 1 && subid >= 0)
|
||||
subtype = CONTROL_SUB_PANE;
|
||||
else if (strcmp(what, "@*") == 0)
|
||||
subtype = CONTROL_SUB_ALL_WINDOWS;
|
||||
else if (sscanf(what, "@%d", &subid) == 1 && subid >= 0)
|
||||
subtype = CONTROL_SUB_WINDOW;
|
||||
else
|
||||
subtype = CONTROL_SUB_SESSION;
|
||||
control_add_sub(tc, name, subtype, subid, split);
|
||||
|
||||
out:
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_refresh_client_control_client_size(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
const char *size = args_get(args, 'C');
|
||||
u_int w, x, y;
|
||||
struct client_window *cw;
|
||||
|
||||
if (sscanf(size, "@%u:%ux%u", &w, &x, &y) == 3) {
|
||||
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);
|
||||
}
|
||||
log_debug("%s: client %s window @%u: size %ux%u", __func__,
|
||||
tc->name, w, x, y);
|
||||
cw = server_client_add_client_window(tc, w);
|
||||
cw->sx = x;
|
||||
cw->sy = y;
|
||||
tc->flags |= CLIENT_WINDOWSIZECHANGED;
|
||||
recalculate_sizes_now(1);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (sscanf(size, "@%u:", &w) == 1) {
|
||||
cw = server_client_get_client_window(tc, w);
|
||||
if (cw != NULL) {
|
||||
log_debug("%s: client %s window @%u: no size", __func__,
|
||||
tc->name, w);
|
||||
cw->sx = 0;
|
||||
cw->sy = 0;
|
||||
recalculate_sizes_now(1);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
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(&tc->tty, x, y, 0, 0);
|
||||
tc->flags |= CLIENT_SIZECHANGED;
|
||||
recalculate_sizes_now(1);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_refresh_client_update_offset(struct client *tc, const char *value)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
char *copy, *split;
|
||||
u_int pane;
|
||||
|
||||
if (*value != '%')
|
||||
return;
|
||||
copy = xstrdup(value);
|
||||
if ((split = strchr(copy, ':')) == NULL)
|
||||
goto out;
|
||||
*split++ = '\0';
|
||||
|
||||
if (sscanf(copy, "%%%u", &pane) != 1)
|
||||
goto out;
|
||||
wp = window_pane_find_by_id(pane);
|
||||
if (wp == NULL)
|
||||
goto out;
|
||||
|
||||
if (strcmp(split, "on") == 0)
|
||||
control_set_pane_on(tc, wp);
|
||||
else if (strcmp(split, "off") == 0)
|
||||
control_set_pane_off(tc, wp);
|
||||
else if (strcmp(split, "continue") == 0)
|
||||
control_continue_pane(tc, wp);
|
||||
else if (strcmp(split, "pause") == 0)
|
||||
control_pause_pane(tc, wp);
|
||||
|
||||
out:
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_refresh_report(struct tty *tty, const char *value)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
u_int pane;
|
||||
size_t size = 0;
|
||||
char *copy, *split;
|
||||
|
||||
if (*value != '%')
|
||||
return;
|
||||
copy = xstrdup(value);
|
||||
if ((split = strchr(copy, ':')) == NULL)
|
||||
goto out;
|
||||
*split++ = '\0';
|
||||
|
||||
if (sscanf(copy, "%%%u", &pane) != 1)
|
||||
goto out;
|
||||
wp = window_pane_find_by_id(pane);
|
||||
if (wp == NULL)
|
||||
goto out;
|
||||
|
||||
tty_keys_colours(tty, split, strlen(split), &size, &wp->control_fg,
|
||||
&wp->control_bg);
|
||||
|
||||
out:
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct tty *tty = &tc->tty;
|
||||
struct window *w;
|
||||
const char *errstr;
|
||||
u_int adjust;
|
||||
struct args_value *av;
|
||||
|
||||
if (args_has(args, 'c') ||
|
||||
args_has(args, 'L') ||
|
||||
args_has(args, 'R') ||
|
||||
args_has(args, 'U') ||
|
||||
args_has(args, 'D'))
|
||||
{
|
||||
if (args_count(args) == 0)
|
||||
adjust = 1;
|
||||
else {
|
||||
adjust = strtonum(args_string(args, 0), 1, INT_MAX,
|
||||
&errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "adjustment %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'c'))
|
||||
tc->pan_window = NULL;
|
||||
else {
|
||||
w = tc->session->curw->window;
|
||||
if (tc->pan_window != w) {
|
||||
tc->pan_window = w;
|
||||
tc->pan_ox = tty->oox;
|
||||
tc->pan_oy = tty->ooy;
|
||||
}
|
||||
if (args_has(args, 'L')) {
|
||||
if (tc->pan_ox > adjust)
|
||||
tc->pan_ox -= adjust;
|
||||
else
|
||||
tc->pan_ox = 0;
|
||||
} else if (args_has(args, 'R')) {
|
||||
tc->pan_ox += adjust;
|
||||
if (tc->pan_ox > w->sx - tty->osx)
|
||||
tc->pan_ox = w->sx - tty->osx;
|
||||
} else if (args_has(args, 'U')) {
|
||||
if (tc->pan_oy > adjust)
|
||||
tc->pan_oy -= adjust;
|
||||
else
|
||||
tc->pan_oy = 0;
|
||||
} else if (args_has(args, 'D')) {
|
||||
tc->pan_oy += adjust;
|
||||
if (tc->pan_oy > w->sy - tty->osy)
|
||||
tc->pan_oy = w->sy - tty->osy;
|
||||
}
|
||||
}
|
||||
tty_update_client_offset(tc);
|
||||
server_redraw_client(tc);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'l')) {
|
||||
tty_clipboard_query(&tc->tty);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'F')) /* -F is an alias for -f */
|
||||
server_client_set_flags(tc, args_get(args, 'F'));
|
||||
if (args_has(args, 'f'))
|
||||
server_client_set_flags(tc, args_get(args, 'f'));
|
||||
if (args_has(args, 'r'))
|
||||
cmd_refresh_report(tty, args_get(args, 'r'));
|
||||
|
||||
if (args_has(args, 'A')) {
|
||||
if (~tc->flags & CLIENT_CONTROL)
|
||||
goto not_control_client;
|
||||
av = args_first_value(args, 'A');
|
||||
while (av != NULL) {
|
||||
cmd_refresh_client_update_offset(tc, av->string);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (args_has(args, 'B')) {
|
||||
if (~tc->flags & CLIENT_CONTROL)
|
||||
goto not_control_client;
|
||||
av = args_first_value(args, 'B');
|
||||
while (av != NULL) {
|
||||
cmd_refresh_client_update_subscription(tc, av->string);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (args_has(args, 'C')) {
|
||||
if (~tc->flags & CLIENT_CONTROL)
|
||||
goto not_control_client;
|
||||
return (cmd_refresh_client_control_client_size(self, item));
|
||||
}
|
||||
|
||||
if (args_has(args, 'S')) {
|
||||
tc->flags |= CLIENT_STATUSFORCE;
|
||||
server_status_client(tc);
|
||||
} else {
|
||||
tc->flags |= CLIENT_STATUSFORCE;
|
||||
server_redraw_client(tc);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
not_control_client:
|
||||
cmdq_error(item, "not a control client");
|
||||
return (CMD_RETURN_ERROR);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-rename-session.c,v 1.15 2009-01-19 18:23:40 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -27,55 +26,32 @@
|
||||
* Change session name.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_rename_session_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
int cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_rename_session_entry = {
|
||||
.name = "rename-session",
|
||||
.alias = "rename",
|
||||
|
||||
.args = { "t:", 1, 1, NULL },
|
||||
.usage = CMD_TARGET_SESSION_USAGE " new-name",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_rename_session_exec
|
||||
"rename-session", "rename",
|
||||
CMD_TARGET_SESSION_USAGE " new-name",
|
||||
CMD_ARG1,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_rename_session_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct session *s = target->s;
|
||||
char *newname, *tmp;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
|
||||
tmp = format_single_from_target(item, args_string(args, 0));
|
||||
newname = session_check_name(tmp);
|
||||
if (newname == NULL) {
|
||||
cmdq_error(item, "invalid session: %s", tmp);
|
||||
free(tmp);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(tmp);
|
||||
if (strcmp(newname, s->name) == 0) {
|
||||
free(newname);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (session_find(newname) != NULL) {
|
||||
cmdq_error(item, "duplicate session: %s", newname);
|
||||
free(newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
RB_REMOVE(sessions, &sessions, s);
|
||||
free(s->name);
|
||||
s->name = newname;
|
||||
RB_INSERT(sessions, &sessions, s);
|
||||
xfree(s->name);
|
||||
s->name = xstrdup(data->arg);
|
||||
|
||||
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.27 2009-05-04 17:58:26 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -26,37 +26,36 @@
|
||||
* Rename a window.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_rename_window_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
int cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_rename_window_entry = {
|
||||
.name = "rename-window",
|
||||
.alias = "renamew",
|
||||
|
||||
.args = { "t:", 1, 1, NULL },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE " new-name",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_rename_window_exec
|
||||
"rename-window", "renamew",
|
||||
CMD_TARGET_WINDOW_USAGE " new-name",
|
||||
CMD_ARG1,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_rename_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct winlink *wl = target->wl;
|
||||
char *newname;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
|
||||
newname = format_single_from_target(item, args_string(args, 0));
|
||||
window_set_name(wl->window, newname);
|
||||
options_set_number(wl->window->options, "automatic-rename", 0);
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
return (-1);
|
||||
|
||||
server_redraw_window_borders(wl->window);
|
||||
server_status_window(wl->window);
|
||||
free(newname);
|
||||
xfree(wl->window->name);
|
||||
wl->window->name = xstrdup(data->arg);
|
||||
options_set_number(&wl->window->options, "automatic-rename", 0);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
server_status_session(s);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-resize-pane.c,v 1.7 2009-05-21 19:46:00 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -27,189 +26,80 @@
|
||||
* Increase or decrease pane size.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static void cmd_resize_pane_mouse_update(struct client *,
|
||||
struct mouse_event *);
|
||||
void cmd_resize_pane_init(struct cmd *, int);
|
||||
int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_resize_pane_entry = {
|
||||
.name = "resize-pane",
|
||||
.alias = "resizep",
|
||||
|
||||
.args = { "DLMRTt:Ux:y:Z", 0, 1, NULL },
|
||||
.usage = "[-DLMRTUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
|
||||
"[adjustment]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_resize_pane_exec
|
||||
"resize-pane", "resizep",
|
||||
CMD_PANE_WINDOW_USAGE "[-DU] [adjustment]",
|
||||
CMD_ARG01|CMD_BIGUFLAG|CMD_BIGDFLAG,
|
||||
cmd_resize_pane_init,
|
||||
cmd_pane_parse,
|
||||
cmd_resize_pane_exec,
|
||||
cmd_pane_send,
|
||||
cmd_pane_recv,
|
||||
cmd_pane_free,
|
||||
cmd_pane_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
void
|
||||
cmd_resize_pane_init(struct cmd *self, int key)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct key_event *event = cmdq_get_event(item);
|
||||
struct window_pane *wp = target->wp;
|
||||
struct winlink *wl = target->wl;
|
||||
struct window *w = wl->window;
|
||||
struct client *c = cmdq_get_client(item);
|
||||
struct session *s = target->s;
|
||||
struct cmd_pane_data *data;
|
||||
|
||||
cmd_pane_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
if (key == KEYC_ADDCTL(KEYC_DOWN))
|
||||
data->flags |= CMD_BIGDFLAG;
|
||||
|
||||
if (key == KEYC_ADDESC(KEYC_UP))
|
||||
data->arg = xstrdup("5");
|
||||
if (key == KEYC_ADDESC(KEYC_DOWN)) {
|
||||
data->flags |= CMD_BIGDFLAG;
|
||||
data->arg = xstrdup("5");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
const char *errstr;
|
||||
char *cause;
|
||||
struct window_pane *wp;
|
||||
u_int adjust;
|
||||
int x, y, status;
|
||||
struct grid *gd = wp->base.grid;
|
||||
|
||||
if (args_has(args, 'T')) {
|
||||
if (!TAILQ_EMPTY(&wp->modes))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
adjust = screen_size_y(&wp->base) - 1 - wp->base.cy;
|
||||
if (adjust > gd->hsize)
|
||||
adjust = gd->hsize;
|
||||
grid_remove_history(gd, adjust);
|
||||
wp->base.cy += adjust;
|
||||
wp->flags |= PANE_REDRAW;
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
if (data->pane == -1)
|
||||
wp = wl->window->active;
|
||||
else {
|
||||
wp = window_pane_at_index(wl->window, data->pane);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'M')) {
|
||||
if (!event->m.valid || cmd_mouse_window(&event->m, &s) == NULL)
|
||||
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, &event->m);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'Z')) {
|
||||
if (w->flags & WINDOW_ZOOMED)
|
||||
window_unzoom(w, 1);
|
||||
else
|
||||
window_zoom(wp);
|
||||
server_redraw_window(w);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
server_unzoom_window(w);
|
||||
|
||||
if (args_count(args) == 0)
|
||||
if (data->arg == NULL)
|
||||
adjust = 1;
|
||||
else {
|
||||
adjust = strtonum(args_string(args, 0), 1, INT_MAX, &errstr);
|
||||
adjust = strtonum(data->arg, 1, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "adjustment %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
ctx->error(ctx, "adjustment %s: %s", errstr, data->arg);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'x')) {
|
||||
x = args_percentage(args, 'x', 0, INT_MAX, w->sx, &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 (!(data->flags & CMD_BIGDFLAG))
|
||||
adjust = -adjust;
|
||||
if (layout_resize(wp, adjust) != 0) {
|
||||
ctx->error(ctx, "layout %s "
|
||||
"does not support resizing", layout_name(wp->window));
|
||||
return (-1);
|
||||
}
|
||||
if (args_has(args, 'y')) {
|
||||
y = args_percentage(args, 'y', 0, INT_MAX, w->sy, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "height %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
status = options_get_number(w->options, "pane-border-status");
|
||||
switch (status) {
|
||||
case PANE_STATUS_TOP:
|
||||
if (y != INT_MAX && wp->yoff == 1)
|
||||
y++;
|
||||
break;
|
||||
case PANE_STATUS_BOTTOM:
|
||||
if (y != INT_MAX && wp->yoff + wp->sy == w->sy - 1)
|
||||
y++;
|
||||
break;
|
||||
}
|
||||
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);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
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);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,115 +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, NULL },
|
||||
.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 = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct winlink *wl = target->wl;
|
||||
struct window *w = wl->window;
|
||||
struct session *s = target->s;
|
||||
const char *errstr;
|
||||
char *cause;
|
||||
u_int adjust, sx, sy, xpixel = 0, ypixel = 0;
|
||||
|
||||
if (args_count(args) == 0)
|
||||
adjust = 1;
|
||||
else {
|
||||
adjust = strtonum(args_string(args, 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);
|
||||
w->manual_sx = sx;
|
||||
w->manual_sy = sy;
|
||||
recalculate_size(w, 1);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -1,98 +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, NULL },
|
||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
||||
CMD_TARGET_PANE_USAGE " [shell-command [argument ...]]",
|
||||
|
||||
.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 = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct spawn_context sc = { 0 };
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl;
|
||||
struct window_pane *wp = target->wp;
|
||||
char *cause = NULL;
|
||||
struct args_value *av;
|
||||
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.wl = wl;
|
||||
|
||||
sc.wp0 = wp;
|
||||
|
||||
args_to_vector(args, &sc.argc, &sc.argv);
|
||||
sc.environ = environ_create();
|
||||
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(sc.environ, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
|
||||
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);
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
wp->flags |= PANE_REDRAW;
|
||||
server_redraw_window_borders(wp->window);
|
||||
server_status_window(wp->window);
|
||||
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-respawn-window.c,v 1.14 2009-03-04 17:24:07 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,8 +18,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -27,69 +26,62 @@
|
||||
* Respawn a window (restart the command). Kill existing if -k given.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_respawn_window_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
int cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_respawn_window_entry = {
|
||||
.name = "respawn-window",
|
||||
.alias = "respawnw",
|
||||
|
||||
.args = { "c:e:kt:", 0, -1, NULL },
|
||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
||||
CMD_TARGET_WINDOW_USAGE " [shell-command [argument ...]]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_respawn_window_exec
|
||||
"respawn-window", "respawnw",
|
||||
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
CMD_ARG01|CMD_KFLAG,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_respawn_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int
|
||||
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct spawn_context sc = { 0 };
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl;
|
||||
char *cause = NULL;
|
||||
struct args_value *av;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
struct session *s;
|
||||
const char **env;
|
||||
char *cause;
|
||||
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.wl = wl;
|
||||
sc.tc = tc;
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
return (-1);
|
||||
w = wl->window;
|
||||
|
||||
args_to_vector(args, &sc.argc, &sc.argv);
|
||||
sc.environ = environ_create();
|
||||
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(sc.environ, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
if (!(data->flags & CMD_KFLAG)) {
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (wp->fd == -1)
|
||||
continue;
|
||||
ctx->error(ctx,
|
||||
"window still active: %s:%d", s->name, wl->idx);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
sc.idx = -1;
|
||||
sc.cwd = args_get(args, 'c');
|
||||
env = server_fill_environ(s);
|
||||
|
||||
sc.flags = SPAWN_RESPAWN;
|
||||
if (args_has(args, 'k'))
|
||||
sc.flags |= SPAWN_KILL;
|
||||
|
||||
if (spawn_window(&sc, &cause) == NULL) {
|
||||
cmdq_error(item, "respawn window failed: %s", cause);
|
||||
free(cause);
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_ERROR);
|
||||
wp = TAILQ_FIRST(&w->panes);
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
window_destroy_panes(w);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
window_pane_resize(wp, w->sx, w->sy);
|
||||
if (window_pane_spawn(wp, data->arg, NULL, env, &cause) != 0) {
|
||||
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
screen_reinit(&wp->base);
|
||||
|
||||
server_redraw_window(wl->window);
|
||||
recalculate_sizes();
|
||||
server_redraw_window(w);
|
||||
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-rotate-window.c,v 1.4 2009-06-25 15:28:08 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -24,92 +24,99 @@
|
||||
* Rotate the panes in a window.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_rotate_window_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
void cmd_rotate_window_init(struct cmd *, int);
|
||||
int cmd_rotate_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_rotate_window_entry = {
|
||||
.name = "rotate-window",
|
||||
.alias = "rotatew",
|
||||
|
||||
.args = { "Dt:UZ", 0, 0, NULL },
|
||||
.usage = "[-DUZ] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_rotate_window_exec
|
||||
"rotate-window", "rotatew",
|
||||
"[-DU] " CMD_TARGET_WINDOW_USAGE,
|
||||
CMD_BIGUFLAG|CMD_BIGDFLAG,
|
||||
cmd_rotate_window_init,
|
||||
cmd_target_parse,
|
||||
cmd_rotate_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
void
|
||||
cmd_rotate_window_init(struct cmd *self, int key)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *current = cmdq_get_current(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct winlink *wl = target->wl;
|
||||
struct window *w = wl->window;
|
||||
struct cmd_target_data *data;
|
||||
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
if (key == KEYC_ADDESC('o'))
|
||||
data->flags |= CMD_BIGDFLAG;
|
||||
}
|
||||
|
||||
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 layout_cell *lc;
|
||||
u_int sx, sy, xoff, yoff;
|
||||
int flags;
|
||||
|
||||
window_push_zoom(w, 0, args_has(args, 'Z'));
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
w = wl->window;
|
||||
|
||||
if (args_has(args, 'D')) {
|
||||
if (data->flags & CMD_BIGDFLAG) {
|
||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
|
||||
lc = wp->layout_cell;
|
||||
xoff = wp->xoff; yoff = wp->yoff;
|
||||
sx = wp->sx; sy = wp->sy;
|
||||
flags = wp->flags;
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if ((wp2 = TAILQ_NEXT(wp, entry)) == NULL)
|
||||
break;
|
||||
wp->layout_cell = wp2->layout_cell;
|
||||
if (wp->layout_cell != NULL)
|
||||
wp->layout_cell->wp = wp;
|
||||
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
|
||||
wp->flags &= ~PANE_HIDDEN;
|
||||
wp->flags |= wp2->flags & PANE_HIDDEN;
|
||||
window_pane_resize(wp, wp2->sx, wp2->sy);
|
||||
}
|
||||
wp->layout_cell = lc;
|
||||
if (wp->layout_cell != NULL)
|
||||
wp->layout_cell->wp = wp;
|
||||
wp->xoff = xoff; wp->yoff = yoff;
|
||||
wp->flags &= ~PANE_HIDDEN;
|
||||
wp->flags |= flags & PANE_HIDDEN;
|
||||
window_pane_resize(wp, sx, sy);
|
||||
|
||||
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
|
||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||
window_set_active_pane(w, wp);
|
||||
} else {
|
||||
wp = TAILQ_FIRST(&w->panes);
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
TAILQ_INSERT_TAIL(&w->panes, wp, entry);
|
||||
|
||||
lc = wp->layout_cell;
|
||||
xoff = wp->xoff; yoff = wp->yoff;
|
||||
sx = wp->sx; sy = wp->sy;
|
||||
flags = wp->flags;
|
||||
TAILQ_FOREACH_REVERSE(wp, &w->panes, window_panes, entry) {
|
||||
if ((wp2 = TAILQ_PREV(wp, window_panes, entry)) == NULL)
|
||||
break;
|
||||
wp->layout_cell = wp2->layout_cell;
|
||||
if (wp->layout_cell != NULL)
|
||||
wp->layout_cell->wp = wp;
|
||||
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
|
||||
wp->flags &= ~PANE_HIDDEN;
|
||||
wp->flags |= wp2->flags & PANE_HIDDEN;
|
||||
window_pane_resize(wp, wp2->sx, wp2->sy);
|
||||
}
|
||||
wp->layout_cell = lc;
|
||||
if (wp->layout_cell != NULL)
|
||||
wp->layout_cell->wp = wp;
|
||||
wp->xoff = xoff; wp->yoff = yoff;
|
||||
wp->flags &= ~PANE_HIDDEN;
|
||||
wp->flags |= flags & PANE_HIDDEN;
|
||||
window_pane_resize(wp, sx, sy);
|
||||
|
||||
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
|
||||
wp = TAILQ_FIRST(&w->panes);
|
||||
window_set_active_pane(w, wp);
|
||||
}
|
||||
|
||||
window_set_active_pane(w, wp, 1);
|
||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
||||
window_pop_zoom(w);
|
||||
server_redraw_window(w);
|
||||
layout_refresh(w, 0);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
293
cmd-run-shell.c
293
cmd-run-shell.c
@@ -1,293 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Runs a command without a window.
|
||||
*/
|
||||
|
||||
static enum args_parse_type cmd_run_shell_args_parse(struct args *, u_int,
|
||||
char **);
|
||||
static enum cmd_retval cmd_run_shell_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static void cmd_run_shell_timer(int, short, void *);
|
||||
static void cmd_run_shell_callback(struct job *);
|
||||
static void cmd_run_shell_free(void *);
|
||||
static void cmd_run_shell_print(struct job *, const char *);
|
||||
|
||||
const struct cmd_entry cmd_run_shell_entry = {
|
||||
.name = "run-shell",
|
||||
.alias = "run",
|
||||
|
||||
.args = { "bd:Ct:Es:c:", 0, 1, cmd_run_shell_args_parse },
|
||||
.usage = "[-bCE] [-c start-directory] [-d delay] " CMD_TARGET_PANE_USAGE
|
||||
" [shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_run_shell_exec
|
||||
};
|
||||
|
||||
struct cmd_run_shell_data {
|
||||
struct client *client;
|
||||
char *cmd;
|
||||
struct args_command_state *state;
|
||||
char *cwd;
|
||||
struct cmdq_item *item;
|
||||
struct session *s;
|
||||
int wp_id;
|
||||
struct event timer;
|
||||
int flags;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_run_shell_args_parse(struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
if (args_has(args, 'C'))
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
return (ARGS_PARSE_STRING);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_run_shell_print(struct job *job, const char *msg)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = job_get_data(job);
|
||||
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 (cdata->item != NULL && cdata->client != NULL)
|
||||
wp = server_client_get_pane(cdata->client);
|
||||
if (wp == NULL && cmd_find_from_nothing(&fs, 0) == 0)
|
||||
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, NULL, &window_view_mode, NULL, NULL);
|
||||
window_copy_add(wp, 1, "%s", msg);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct cmd_run_shell_data *cdata;
|
||||
struct client *c = cmdq_get_client(item);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = target->s;
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *delay, *cmd;
|
||||
double d;
|
||||
struct timeval tv;
|
||||
char *end;
|
||||
int wait = !args_has(args, 'b');
|
||||
|
||||
if ((delay = args_get(args, 'd')) != NULL) {
|
||||
d = strtod(delay, &end);
|
||||
if (*end != '\0') {
|
||||
cmdq_error(item, "invalid delay time: %s", delay);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (args_count(args) == 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
if (!args_has(args, 'C')) {
|
||||
cmd = args_string(args, 0);
|
||||
if (cmd != NULL)
|
||||
cdata->cmd = format_single_from_target(item, cmd);
|
||||
} else {
|
||||
cdata->state = args_make_commands_prepare(self, item, 0, NULL,
|
||||
wait, 1);
|
||||
}
|
||||
|
||||
if (args_has(args, 't') && wp != NULL)
|
||||
cdata->wp_id = wp->id;
|
||||
else
|
||||
cdata->wp_id = -1;
|
||||
|
||||
if (wait) {
|
||||
cdata->client = c;
|
||||
cdata->item = item;
|
||||
} else {
|
||||
cdata->client = tc;
|
||||
cdata->flags |= JOB_NOWAIT;
|
||||
}
|
||||
if (cdata->client != NULL)
|
||||
cdata->client->references++;
|
||||
if (args_has(args, 'c'))
|
||||
cdata->cwd = xstrdup(args_get(args, 'c'));
|
||||
else
|
||||
cdata->cwd = xstrdup(server_client_get_cwd(c, s));
|
||||
|
||||
if (args_has(args, 'E'))
|
||||
cdata->flags |= JOB_SHOWSTDERR;
|
||||
|
||||
cdata->s = s;
|
||||
if (s != NULL)
|
||||
session_add_ref(s, __func__);
|
||||
|
||||
evtimer_set(&cdata->timer, cmd_run_shell_timer, cdata);
|
||||
if (delay != NULL) {
|
||||
timerclear(&tv);
|
||||
tv.tv_sec = (time_t)d;
|
||||
tv.tv_usec = (d - (double)tv.tv_sec) * 1000000U;
|
||||
evtimer_add(&cdata->timer, &tv);
|
||||
} else
|
||||
event_active(&cdata->timer, EV_TIMEOUT, 1);
|
||||
|
||||
if (!wait)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = arg;
|
||||
struct client *c = cdata->client;
|
||||
const char *cmd = cdata->cmd;
|
||||
struct cmdq_item *item = cdata->item, *new_item;
|
||||
struct cmd_list *cmdlist;
|
||||
char *error;
|
||||
|
||||
if (cdata->state == NULL) {
|
||||
if (cmd == NULL) {
|
||||
if (cdata->item != NULL)
|
||||
cmdq_continue(cdata->item);
|
||||
cmd_run_shell_free(cdata);
|
||||
return;
|
||||
}
|
||||
if (job_run(cmd, 0, NULL, NULL, cdata->s, cdata->cwd, NULL,
|
||||
cmd_run_shell_callback, cmd_run_shell_free, cdata,
|
||||
cdata->flags, -1, -1) == NULL)
|
||||
cmd_run_shell_free(cdata);
|
||||
return;
|
||||
}
|
||||
|
||||
cmdlist = args_make_commands(cdata->state, 0, NULL, &error);
|
||||
if (cmdlist == NULL) {
|
||||
if (cdata->item == NULL) {
|
||||
*error = toupper((u_char)*error);
|
||||
status_message_set(c, -1, 1, 0, 0, "%s", error);
|
||||
} else
|
||||
cmdq_error(cdata->item, "%s", error);
|
||||
free(error);
|
||||
} else if (item == NULL) {
|
||||
new_item = cmdq_get_command(cmdlist, NULL);
|
||||
cmdq_append(c, new_item);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
if (cdata->item != NULL)
|
||||
cmdq_continue(cdata->item);
|
||||
cmd_run_shell_free(cdata);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_run_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = job_get_data(job);
|
||||
struct bufferevent *event = job_get_event(job);
|
||||
struct cmdq_item *item = cdata->item;
|
||||
char *cmd = cdata->cmd, *msg = NULL, *line;
|
||||
size_t size;
|
||||
int retcode, status;
|
||||
|
||||
do {
|
||||
line = evbuffer_readln(event->input, NULL, EVBUFFER_EOL_LF);
|
||||
if (line != NULL) {
|
||||
cmd_run_shell_print(job, line);
|
||||
free(line);
|
||||
}
|
||||
} while (line != NULL);
|
||||
|
||||
size = EVBUFFER_LENGTH(event->input);
|
||||
if (size != 0) {
|
||||
line = xmalloc(size + 1);
|
||||
memcpy(line, EVBUFFER_DATA(event->input), size);
|
||||
line[size] = '\0';
|
||||
|
||||
cmd_run_shell_print(job, line);
|
||||
|
||||
free(line);
|
||||
}
|
||||
|
||||
status = job_get_status(job);
|
||||
if (WIFEXITED(status)) {
|
||||
if ((retcode = WEXITSTATUS(status)) != 0)
|
||||
xasprintf(&msg, "'%s' returned %d", cmd, retcode);
|
||||
} else if (WIFSIGNALED(status)) {
|
||||
retcode = WTERMSIG(status);
|
||||
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
||||
retcode += 128;
|
||||
} else
|
||||
retcode = 0;
|
||||
if (msg != NULL)
|
||||
cmd_run_shell_print(job, msg);
|
||||
free(msg);
|
||||
|
||||
if (item != NULL) {
|
||||
if (cmdq_get_client(item) != NULL &&
|
||||
cmdq_get_client(item)->session == NULL)
|
||||
cmdq_get_client(item)->retval = retcode;
|
||||
cmdq_continue(item);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_run_shell_free(void *data)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = data;
|
||||
|
||||
evtimer_del(&cdata->timer);
|
||||
if (cdata->s != NULL)
|
||||
session_remove_ref(cdata->s, __func__);
|
||||
if (cdata->client != NULL)
|
||||
server_client_unref(cdata->client);
|
||||
if (cdata->state != NULL)
|
||||
args_make_commands_free(cdata->state);
|
||||
free(cdata->cwd);
|
||||
free(cdata->cmd);
|
||||
free(cdata);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-save-buffer.c,v 1.5 2009-05-18 16:22:30 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
@@ -20,101 +20,71 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.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 = {
|
||||
.name = "save-buffer",
|
||||
.alias = "saveb",
|
||||
|
||||
.args = { "ab:", 1, 1, NULL },
|
||||
.usage = "[-a] " CMD_BUFFER_USAGE " path",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_save_buffer_exec
|
||||
"save-buffer", "saveb",
|
||||
"[-a] " CMD_BUFFER_SESSION_USAGE " path",
|
||||
CMD_AFLAG|CMD_ARG1,
|
||||
cmd_buffer_init,
|
||||
cmd_buffer_parse,
|
||||
cmd_save_buffer_exec,
|
||||
cmd_buffer_send,
|
||||
cmd_buffer_recv,
|
||||
cmd_buffer_free,
|
||||
cmd_buffer_print
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_show_buffer_entry = {
|
||||
.name = "show-buffer",
|
||||
.alias = "showb",
|
||||
|
||||
.args = { "b:", 0, 0, NULL },
|
||||
.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)
|
||||
int
|
||||
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmdq_item *item = data;
|
||||
|
||||
if (!closed)
|
||||
return;
|
||||
|
||||
if (error != 0)
|
||||
cmdq_error(item, "%s: %s", strerror(error), path);
|
||||
cmdq_continue(item);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c = cmdq_get_client(item);
|
||||
struct cmd_buffer_data *data = self->data;
|
||||
struct session *s;
|
||||
struct paste_buffer *pb;
|
||||
int flags;
|
||||
const char *bufname = args_get(args, 'b'), *bufdata;
|
||||
size_t bufsize;
|
||||
char *path;
|
||||
struct evbuffer *evb;
|
||||
mode_t mask;
|
||||
FILE *f;
|
||||
|
||||
if (bufname == NULL) {
|
||||
if ((pb = paste_get_top(NULL)) == NULL) {
|
||||
cmdq_error(item, "no buffers");
|
||||
return (CMD_RETURN_ERROR);
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (data->buffer == -1) {
|
||||
if ((pb = paste_get_top(&s->buffers)) == NULL) {
|
||||
ctx->error(ctx, "no buffers");
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
pb = paste_get_name(bufname);
|
||||
if (pb == NULL) {
|
||||
cmdq_error(item, "no buffer %s", bufname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
|
||||
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
bufdata = paste_buffer_data(pb, &bufsize);
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_show_buffer_entry) {
|
||||
if (c->session != NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
evb = evbuffer_new();
|
||||
if (evb == NULL)
|
||||
fatalx("out of memory");
|
||||
evbuffer_add(evb, bufdata, bufsize);
|
||||
cmdq_print_data(item, evb);
|
||||
evbuffer_free(evb);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
path = xstrdup("-");
|
||||
} else
|
||||
path = format_single_from_target(item, args_string(args, 0));
|
||||
if (args_has(args, 'a'))
|
||||
flags = O_APPEND;
|
||||
mask = umask(S_IRWXG | S_IRWXO);
|
||||
if (data->flags & CMD_AFLAG)
|
||||
f = fopen(data->arg, "ab");
|
||||
else
|
||||
flags = O_TRUNC;
|
||||
file_write(cmdq_get_client(item), path, flags, bufdata, bufsize,
|
||||
cmd_save_buffer_done, item);
|
||||
free(path);
|
||||
f = fopen(data->arg, "wb");
|
||||
if (f == NULL) {
|
||||
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_WAIT);
|
||||
if (fwrite(pb->data, 1, strlen(pb->data), f) != strlen(pb->data)) {
|
||||
ctx->error(ctx, "%s: fwrite error", data->arg);
|
||||
fclose(f);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
umask(mask);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
74
cmd-scroll-mode.c
Normal file
74
cmd-scroll-mode.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/* $Id: cmd-scroll-mode.c,v 1.19 2009-07-01 23:06:32 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Enter scroll mode.
|
||||
*/
|
||||
|
||||
void cmd_scroll_mode_init(struct cmd *, int);
|
||||
int cmd_scroll_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_scroll_mode_entry = {
|
||||
"scroll-mode", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
CMD_UFLAG,
|
||||
cmd_scroll_mode_init,
|
||||
cmd_target_parse,
|
||||
cmd_scroll_mode_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
void
|
||||
cmd_scroll_mode_init(struct cmd *self, int key)
|
||||
{
|
||||
struct cmd_target_data *data;
|
||||
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
switch (key) {
|
||||
case KEYC_PPAGE:
|
||||
data->flags |= CMD_UFLAG;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
cmd_scroll_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
wp = wl->window->active;
|
||||
|
||||
window_pane_set_mode(wp, &window_scroll_mode);
|
||||
if (wp->mode == &window_scroll_mode && data->flags & CMD_UFLAG)
|
||||
window_scroll_pageup(wp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $OpenBSD$ */
|
||||
/* $Id: cmd-select-layout.c,v 1.3 2009-06-25 16:34:50 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,132 +18,69 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Switch window to selected layout.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_select_layout_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
void cmd_select_layout_init(struct cmd *, int);
|
||||
int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_select_layout_entry = {
|
||||
.name = "select-layout",
|
||||
.alias = "selectl",
|
||||
|
||||
.args = { "Enopt:", 0, 1, NULL },
|
||||
.usage = "[-Enop] " CMD_TARGET_PANE_USAGE " [layout-name]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_select_layout_exec
|
||||
"select-layout", "selectl",
|
||||
CMD_TARGET_WINDOW_USAGE " layout-name",
|
||||
CMD_ARG1,
|
||||
cmd_select_layout_init,
|
||||
cmd_target_parse,
|
||||
cmd_select_layout_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_next_layout_entry = {
|
||||
.name = "next-layout",
|
||||
.alias = "nextl",
|
||||
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.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, NULL },
|
||||
.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)
|
||||
void
|
||||
cmd_select_layout_init(struct cmd *self, int key)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct winlink *wl = target->wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *layoutname;
|
||||
char *oldlayout, *cause;
|
||||
int next, previous, layout;
|
||||
struct cmd_target_data *data;
|
||||
|
||||
server_unzoom_window(w);
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
next = (cmd_get_entry(self) == &cmd_next_layout_entry);
|
||||
if (args_has(args, 'n'))
|
||||
next = 1;
|
||||
previous = (cmd_get_entry(self) == &cmd_previous_layout_entry);
|
||||
if (args_has(args, 'p'))
|
||||
previous = 1;
|
||||
|
||||
oldlayout = w->old_layout;
|
||||
w->old_layout = layout_dump(w->layout_root);
|
||||
|
||||
if (next || previous) {
|
||||
if (next)
|
||||
layout_set_next(w);
|
||||
else
|
||||
layout_set_previous(w);
|
||||
goto changed;
|
||||
switch (key) {
|
||||
case KEYC_ADDESC('0'):
|
||||
data->arg = xstrdup("manual-vertical");
|
||||
break;
|
||||
case KEYC_ADDESC('1'):
|
||||
data->arg = xstrdup("even-horizontal");
|
||||
break;
|
||||
case KEYC_ADDESC('2'):
|
||||
data->arg = xstrdup("even-vertical");
|
||||
break;
|
||||
case KEYC_ADDESC('9'):
|
||||
data->arg = xstrdup("active-only");
|
||||
break;
|
||||
}
|
||||
|
||||
if (args_has(args, 'E')) {
|
||||
layout_spread_out(wp);
|
||||
goto changed;
|
||||
}
|
||||
|
||||
if (args_count(args) != 0)
|
||||
layoutname = args_string(args, 0);
|
||||
else if (args_has(args, 'o'))
|
||||
layoutname = oldlayout;
|
||||
else
|
||||
layoutname = NULL;
|
||||
|
||||
if (!args_has(args, 'o')) {
|
||||
if (layoutname == NULL)
|
||||
layout = w->lastlayout;
|
||||
else
|
||||
layout = layout_set_lookup(layoutname);
|
||||
if (layout != -1) {
|
||||
layout_set_select(w, layout);
|
||||
goto changed;
|
||||
}
|
||||
}
|
||||
|
||||
if (layoutname != NULL) {
|
||||
if (layout_parse(w, layoutname, &cause) == -1) {
|
||||
cmdq_error(item, "%s: %s", cause, layoutname);
|
||||
free(cause);
|
||||
goto error;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
int layout;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if ((layout = layout_lookup(data->arg)) == -1) {
|
||||
ctx->error(ctx, "unknown or ambiguous layout: %s", data->arg);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (layout_select(wl->window, layout) == 0)
|
||||
ctx->info(ctx, "layout now: %s", layout_name(wl->window));
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user