mirror of
https://github.com/tmux/tmux.git
synced 2026-03-12 03:25:45 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
509c63b618 |
79
.github/CONTRIBUTING.md
vendored
79
.github/CONTRIBUTING.md
vendored
@@ -1,79 +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.
|
|
||||||
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,2 +0,0 @@
|
|||||||
github: nicm
|
|
||||||
liberapay: tmux
|
|
||||||
22
.github/ISSUE_TEMPLATE.md
vendored
22
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,22 +0,0 @@
|
|||||||
### Issue description
|
|
||||||
|
|
||||||
Please read https://github.com/tmux/tmux/blob/master/.github/CONTRIBUTING.md
|
|
||||||
before opening an issue.
|
|
||||||
|
|
||||||
If you have upgraded, make sure your issue is not covered in the CHANGES file
|
|
||||||
for your version: https://raw.githubusercontent.com/tmux/tmux/master/CHANGES
|
|
||||||
|
|
||||||
Describe the problem and the steps to reproduce. Add a minimal tmux config if
|
|
||||||
necessary. Screenshots can be helpful, but no more than one or two.
|
|
||||||
|
|
||||||
Do not report bugs (crashes, incorrect behaviour) without reproducing on a tmux
|
|
||||||
built from the latest code in Git.
|
|
||||||
|
|
||||||
### Required information
|
|
||||||
|
|
||||||
Please provide the following information:
|
|
||||||
|
|
||||||
* tmux version (`tmux -V`).
|
|
||||||
* Platform (`uname -sp`).
|
|
||||||
* $TERM inside and outside of tmux (`echo $TERM`).
|
|
||||||
* Logs from tmux (`tmux kill-server; tmux -vv new`).
|
|
||||||
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/imomaliev/tmux-bash-completion
|
|
||||||
|
|
||||||
For debugging, run tmux with `-v` or `-vv` to generate server and client log
|
|
||||||
files in the current directory.
|
|
||||||
|
|
||||||
## Support
|
|
||||||
|
|
||||||
The tmux mailing list for general discussion and bug reports is:
|
|
||||||
|
|
||||||
https://groups.google.com/forum/#!forum/tmux-users
|
|
||||||
|
|
||||||
Subscribe by sending an email to:
|
|
||||||
|
|
||||||
tmux-users+subscribe@googlegroups.com
|
|
||||||
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
|
|
||||||
29
.github/workflows/lock.yml
vendored
29
.github/workflows/lock.yml
vendored
@@ -1,29 +0,0 @@
|
|||||||
name: 'Lock Threads'
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '0 0 * * *'
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lock:
|
|
||||||
permissions:
|
|
||||||
issues: write # for dessant/lock-threads to lock issues
|
|
||||||
pull-requests: write # for dessant/lock-threads to lock PRs
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: dessant/lock-threads@v2
|
|
||||||
with:
|
|
||||||
github-token: ${{ github.token }}
|
|
||||||
issue-lock-inactive-days: '30'
|
|
||||||
pr-lock-inactive-days: '60'
|
|
||||||
issue-lock-comment: >
|
|
||||||
This issue has been automatically locked since there
|
|
||||||
has not been any recent activity after it was closed.
|
|
||||||
Please open a new issue for related bugs.
|
|
||||||
pr-lock-comment: >
|
|
||||||
This pull request has been automatically locked since there
|
|
||||||
has not been any recent activity after it was closed.
|
|
||||||
Please open a new issue for related bugs.
|
|
||||||
23
.gitignore
vendored
23
.gitignore
vendored
@@ -1,23 +0,0 @@
|
|||||||
*.o
|
|
||||||
*~
|
|
||||||
*.diff
|
|
||||||
*.patch
|
|
||||||
*.core
|
|
||||||
core
|
|
||||||
tags
|
|
||||||
.deps/
|
|
||||||
compat/.dirstamp
|
|
||||||
aclocal.m4
|
|
||||||
autom4te.cache/
|
|
||||||
config.log
|
|
||||||
config.status
|
|
||||||
etc/
|
|
||||||
tmux
|
|
||||||
Makefile
|
|
||||||
Makefile.in
|
|
||||||
configure
|
|
||||||
tmux.1.*
|
|
||||||
*.dSYM
|
|
||||||
cmd-parse.c
|
|
||||||
fuzz/*-fuzzer
|
|
||||||
.dirstamp
|
|
||||||
37
.mailmap
37
.mailmap
@@ -1,37 +0,0 @@
|
|||||||
Bob Beck <beck@openbsd.org> beck <beck>
|
|
||||||
Claudio Jeker <claudio@openbsd.org> claudio <claudio>
|
|
||||||
Igor Sobrado <sobrado@openbsd.org> sobrado <sobrado>
|
|
||||||
Ingo Schwarze <schwarze@openbsd.org> schwarze <schwarze>
|
|
||||||
Jacek Masiulaniec <jacekm@openbsd.org> jacekm <jacekm>
|
|
||||||
Jason McIntyre <jmc@openbsd.org> jmc <jmc>
|
|
||||||
Joel Sing <jsing@openbsd.org> jsing <jsing>
|
|
||||||
Jonathan Gray <jsg@openbsd.org> jsg <jsg>
|
|
||||||
Kenneth R Westerback <krw@openbsd.org> krw <krw>
|
|
||||||
Marc Espie <espie@openbsd.org> espie <espie>
|
|
||||||
Matthew Dempsky <matthew@openbsd.org> matthew <matthew>
|
|
||||||
Matthias Kilian <kili@openbsd.org> kili <kili>
|
|
||||||
Matthieu Herrb <matthieu@openbsd.org> matthieu <matthieu>
|
|
||||||
Michael McConville <mmcc@openbsd.org> mmcc <mmcc>
|
|
||||||
Miod Vallat <miod@openbsd.org> miod <miod>
|
|
||||||
Nicholas Marriott <nicholas.marriott@gmail.com> Nicholas Marriott <nicm@openbsd.org>
|
|
||||||
Nicholas Marriott <nicholas.marriott@gmail.com> nicm <nicm>
|
|
||||||
Nicholas Marriott <nicholas.marriott@gmail.com> no_author <no_author@example.org>
|
|
||||||
Okan Demirmen <okan@openbsd.org> okan <okan>
|
|
||||||
Philip Guenther <guenther@openbsd.org> guenther <guenther>
|
|
||||||
Pierre-Yves Ritschard <pyr@openbsd.org> pyr <pyr>
|
|
||||||
Ray Lai <ray@openbsd.org> ray <ray>
|
|
||||||
Ryan McBride <mcbride@openbsd.org> mcbride <mcbride>
|
|
||||||
Sebastian Benoit <benno@openbsd.org> benno <benno>
|
|
||||||
Sebastien Marie <semarie@openbsd.org> semarie <semarie>
|
|
||||||
Stefan Sperling <stsp@openbsd.org> stsp <stsp>
|
|
||||||
Stuart Henderson <sthen@openbsd.org> sthen <sthen>
|
|
||||||
Ted Unangst <tedu@openbsd.org> tedu <tedu>
|
|
||||||
Theo de Raadt <deraadt@openbsd.org> Theo Deraadt <deraadt@openbsd.org>
|
|
||||||
Theo de Raadt <deraadt@openbsd.org> deraadt <deraadt>
|
|
||||||
Thomas Adam <thomas@xteddy.org> Thomas <thomas@xteddy.org>
|
|
||||||
Thomas Adam <thomas@xteddy.org> Thomas Adam <thomas.adam@smoothwall.net>
|
|
||||||
Thomas Adam <thomas@xteddy.org> n6tadam <n6tadam@xteddy.org>
|
|
||||||
Tim van der Molen <tim@openbsd.org> tim <tim>
|
|
||||||
Tobias Stoeckmann <tobias@openbsd.org> tobias <tobias>
|
|
||||||
Todd C Miller <millert@openbsd.org> millert <millert>
|
|
||||||
William Yodlowsky <william@openbsd.org> william <william>
|
|
||||||
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.
|
|
||||||
413
FAQ
Normal file
413
FAQ
Normal file
@@ -0,0 +1,413 @@
|
|||||||
|
tmux frequently asked questions
|
||||||
|
|
||||||
|
******************************************************************************
|
||||||
|
* PLEASE NOTE: most display problems are due to incorrect TERM! Before *
|
||||||
|
* reporting problems make SURE that TERM settings are correct inside and *
|
||||||
|
* outside tmux. *
|
||||||
|
* *
|
||||||
|
* Inside tmux TERM must be "screen" or similar (such as "screen-256color"). *
|
||||||
|
* Don't bother reporting problems where it isn't! *
|
||||||
|
* *
|
||||||
|
* Outside, it must match your terminal: particularly, use "rxvt" for rxvt *
|
||||||
|
* and derivatives. *
|
||||||
|
******************************************************************************
|
||||||
|
|
||||||
|
* How is tmux different from GNU screen?
|
||||||
|
|
||||||
|
tmux and GNU screen have many similarities. Some of the main differences I am
|
||||||
|
aware of are (bearing in mind I haven't used screen for a few years now):
|
||||||
|
|
||||||
|
- tmux uses a client-server model. Each server has single Unix domain socket in
|
||||||
|
/tmp and within one server there are multiple sessions which may be attached
|
||||||
|
to multiple clients (terminals).
|
||||||
|
|
||||||
|
This has advantages, notably: windows may be linked simultaneously to
|
||||||
|
multiple sessions; windows may be moved freely between sessions; and a client
|
||||||
|
may be switched between sessions easily (C-b D). There is one major
|
||||||
|
disadvantage: if the server crashes, game over, all sessions die. In
|
||||||
|
practice, however, tmux is quite stable and gets more so as people report any
|
||||||
|
bugs they hit :-).
|
||||||
|
|
||||||
|
This model is different from screen, where typically each new screen instance
|
||||||
|
is independent. tmux supports the same behaviour by using multiple servers
|
||||||
|
with the -L option but it is not typically recommended.
|
||||||
|
|
||||||
|
- Different command interfaces. One of the goals of tmux is that the shell
|
||||||
|
should be easily usable as a scripting language - almost all tmux commands
|
||||||
|
can be used from the shell and behave identically whether used from the
|
||||||
|
shell, from a key binding or from the command prompt. Personally I also find
|
||||||
|
tmux's command interface much more consistent and clearer, but this is
|
||||||
|
subjective.
|
||||||
|
|
||||||
|
- tmux calls window names (what you see in the status line) "names", screen
|
||||||
|
calls them "titles".
|
||||||
|
|
||||||
|
- tmux has a multiple paste buffers. Not a major one but comes in handy quite a
|
||||||
|
lot.
|
||||||
|
|
||||||
|
- tmux supports automatically renaming windows to the running application
|
||||||
|
without gross hacks using escape sequences. Its even on by default.
|
||||||
|
|
||||||
|
- tmux has a choice of vi or emacs key layouts. Again, not major, but I use
|
||||||
|
emacs so if tmux did support only one key set it would be emacs and then all
|
||||||
|
the vi users would get humpy. Key bindings may be completely reconfigured in
|
||||||
|
any case.
|
||||||
|
|
||||||
|
- tmux has an option to limit the window size.
|
||||||
|
|
||||||
|
- tmux has search in windows (C-b f).
|
||||||
|
|
||||||
|
- The window split (pane) model is different. tmux has two objects, windows and
|
||||||
|
panes; screen has just windows. This difference has several implications:
|
||||||
|
|
||||||
|
* In screen you can have a window appear in several layouts, in tmux a pane
|
||||||
|
can only be in one window (fixing this is a big todo item but quite
|
||||||
|
invasive).
|
||||||
|
|
||||||
|
* tmux layouts are immutable and do not get changed unless you modify them.
|
||||||
|
|
||||||
|
* In tmux, all panes are closed when you kill a window.
|
||||||
|
|
||||||
|
* tmux panes do not have individual names, titles and so on.
|
||||||
|
|
||||||
|
I think tmux's model is much easier to manage and navigate within a window,
|
||||||
|
but breaking panes off from and joining them to windows is more clumsy.
|
||||||
|
|
||||||
|
tmux also has support for preset pane layouts.
|
||||||
|
|
||||||
|
- tmux's status line syntax is more readable and easier to use. I think it'd be
|
||||||
|
hard for anyone to argue with this. tmux doesn't support running a command
|
||||||
|
constantly and always using the last line of its output, commands must be run
|
||||||
|
again each time.
|
||||||
|
|
||||||
|
- tmux has modern, easily extended code. Again hard to argue screen is better
|
||||||
|
if you have looked at the code.
|
||||||
|
|
||||||
|
- tmux depends on libevent. I don't see this as a disadvantage: libevent is
|
||||||
|
small and portable, and on modern systems with current package management
|
||||||
|
systems dependencies are not an issue. libevent brings advantages in code
|
||||||
|
simplicity and performance.
|
||||||
|
|
||||||
|
- screen allows the window to be bigger than the terminal and can pan around
|
||||||
|
it. tmux limits the size to the largest attached client. This is a big todo
|
||||||
|
item for tmux but it is not trivial.
|
||||||
|
|
||||||
|
- screen has builtin serial and telnet support; this is bloat and is unlikely
|
||||||
|
to be added to tmux.
|
||||||
|
|
||||||
|
- screen has support for updating utmp. Nobody has really come up with a clean,
|
||||||
|
portable way to do this without making tmux setuid or setgid yet.
|
||||||
|
|
||||||
|
- Environment handling is different.
|
||||||
|
|
||||||
|
- tmux tends to be more demanding on the terminal so tends to show up terminal
|
||||||
|
and application bugs which screen does not.
|
||||||
|
|
||||||
|
- screen has wider platform support, for example IRIX, and for odd terminals.
|
||||||
|
|
||||||
|
* I found a bug! What do I do?
|
||||||
|
|
||||||
|
Please send bug reports by email to nicm@users.sourceforge.net or
|
||||||
|
tmux-users@lists.sourceforge.net. Please include as much of the following
|
||||||
|
information as possible:
|
||||||
|
|
||||||
|
- the version of tmux you are running;
|
||||||
|
- the operating system you are using and its version;
|
||||||
|
- the terminal emulator you are using and the TERM setting when tmux was
|
||||||
|
started;
|
||||||
|
- a description of the problem;
|
||||||
|
- if the problem is repeatable, the steps to repeat the problem;
|
||||||
|
- for screen corruption issues, a screenshot and the output of "infocmp $TERM"
|
||||||
|
from outside tmux are often very useful.
|
||||||
|
|
||||||
|
* Why doesn't tmux do $x?
|
||||||
|
|
||||||
|
Please send feature requests by email to nicm@users.sourceforge.net.
|
||||||
|
|
||||||
|
* Why do you use the screen terminal description inside tmux? It sucks.
|
||||||
|
|
||||||
|
It is already widely available. It is planned to change to something else such
|
||||||
|
as xterm-xfree86 at some point, if possible.
|
||||||
|
|
||||||
|
* I don't see any colour in my terminal! Help!
|
||||||
|
|
||||||
|
On some platforms, common terminal descriptions such as xterm do not include
|
||||||
|
colour. screen ignores this, tmux does not. If the terminal emulator in use
|
||||||
|
supports colour, use a value for TERM which correctly lists this, such as
|
||||||
|
xterm-color.
|
||||||
|
|
||||||
|
* tmux freezes my terminal when I attach to a session. I even have to kill -9
|
||||||
|
the shell it was started from to recover!
|
||||||
|
|
||||||
|
Some consoles really really don't like attempts to set the window title. Tell
|
||||||
|
tmux not to do this by turning off the "set-titles" option (you can do this
|
||||||
|
in .tmux.conf):
|
||||||
|
|
||||||
|
set -g set-titles off
|
||||||
|
|
||||||
|
If this doesn't fix it, send a bug report.
|
||||||
|
|
||||||
|
* Why is C-b the prefix key? How do I change it?
|
||||||
|
|
||||||
|
The default key is C-b because the prototype of tmux was originally developed
|
||||||
|
inside screen and C-b was chosen not to clash with the screen meta key. It
|
||||||
|
also has the advantage of not interfering with the use of C-a for start-of-line
|
||||||
|
in emacs and the shell (although it does interfere with previous-character).
|
||||||
|
|
||||||
|
Changing is simple: change the "prefix-key" option, and - if required - move
|
||||||
|
the binding of the "send-prefix" command from C-b (C-b C-b sends C-b by
|
||||||
|
default) to the new key. For example:
|
||||||
|
|
||||||
|
set -g prefix C-a
|
||||||
|
unbind C-b
|
||||||
|
bind C-a send-prefix
|
||||||
|
|
||||||
|
* How do I use UTF-8?
|
||||||
|
|
||||||
|
When running tmux in a UTF-8 capable terminal, UTF-8 must be turned on in tmux;
|
||||||
|
as of release 0.9, tmux attempts to autodetect a UTF-8-capable terminal by
|
||||||
|
checking the LC_ALL, LC_CTYPE and LANG environment variables. list-clients may
|
||||||
|
be used to check if this is detected correctly; if not, the -u command-line
|
||||||
|
flag may be specified when creating or attaching a client to a tmux session:
|
||||||
|
|
||||||
|
$ tmux -u new
|
||||||
|
|
||||||
|
Since the 1.0 release, tmux will turn on UTF-8 related options automatically
|
||||||
|
(ie status-utf8, and utf8) if the above conditions are met.
|
||||||
|
|
||||||
|
* How do I use a 256 colour terminal?
|
||||||
|
|
||||||
|
Provided the underlying terminal supports 256 colours, it is usually sufficient
|
||||||
|
to add the following to ~/.tmux.conf:
|
||||||
|
|
||||||
|
set -g default-terminal "screen-256color"
|
||||||
|
|
||||||
|
Note that some platforms do not support "screen-256color" ("infocmp
|
||||||
|
screen-256color" will return an error) - in this case see the next entry in
|
||||||
|
this FAQ.
|
||||||
|
|
||||||
|
tmux attempts to detect a 256 colour terminal both by looking at the colors
|
||||||
|
terminfo entry and by looking for the string "256col" in the TERM environment
|
||||||
|
variable.
|
||||||
|
|
||||||
|
If both these methods fail, the -2 flag may be passed to tmux when attaching
|
||||||
|
to a session to indicate the terminal supports 256 colours.
|
||||||
|
|
||||||
|
* vim or $otherprogram doesn't display 256 colours. What's up?
|
||||||
|
|
||||||
|
Some programs attempt to detect the number of colours a terminal is capable of
|
||||||
|
by checking the colors terminfo or Co termcap entry. However, this is not
|
||||||
|
reliable, and in any case is missing from the "screen" terminal description
|
||||||
|
used inside tmux.
|
||||||
|
|
||||||
|
There are two options (aside from using "screen-256color") to allow programs to
|
||||||
|
recognise they are running on a 256-colour terminal inside tmux:
|
||||||
|
|
||||||
|
- Manually force the application to use 256 colours always or if TERM is set to
|
||||||
|
screen. For vim, you can do this by overriding the t_Co option, see
|
||||||
|
http://vim.wikia.com/wiki/256_colors_in_vim.
|
||||||
|
- Creating a custom terminfo file that includes colors#256 in ~/.terminfo and
|
||||||
|
using it instead. These may be compiled with tic(1).
|
||||||
|
|
||||||
|
* How do I make Ctrl-PgUp and Ctrl-PgDn work in vim?
|
||||||
|
|
||||||
|
tmux supports passing through ctrl (and where supported by the client terminal,
|
||||||
|
alt and shift) modifiers to function keys using xterm(1)-style key sequences.
|
||||||
|
This may be enabled per window, or globally with the tmux command:
|
||||||
|
|
||||||
|
setw -g xterm-keys on
|
||||||
|
|
||||||
|
Because the TERM variable inside tmux must be set to "screen", vim will not
|
||||||
|
automatically detect these keys are available; however, the appropriate key
|
||||||
|
sequences can be overridden in .vimrc using the following:
|
||||||
|
|
||||||
|
if &term == "screen"
|
||||||
|
set t_kN=^[[6;*~
|
||||||
|
set t_kP=^[[5;*~
|
||||||
|
endif
|
||||||
|
|
||||||
|
And similarly for any other keys for which modifiers are desired.
|
||||||
|
|
||||||
|
Please note that the "xterm-keys" setting may affect other programs, in the
|
||||||
|
same way as running them in a standard xterm; for example most shells do not
|
||||||
|
expect to receive xterm(1)-style key sequences so this setting may prevent keys
|
||||||
|
such as ctrl-left and ctrl-right working correctly. tmux also passes through
|
||||||
|
the ctrl (bit 5 set, for example ^[[5~ to ^[[5^) modifier in non-xterm(1) mode;
|
||||||
|
it may be possible to configure vim to accept these, an example of how to do so
|
||||||
|
would be welcome.
|
||||||
|
|
||||||
|
vim users may also want to set the "ttyfast" option inside tmux.
|
||||||
|
|
||||||
|
* Why doesn't elinks set the window title inside tmux?
|
||||||
|
|
||||||
|
There isn't a way to detect if a terminal supports setting the window title, so
|
||||||
|
elinks attempts to guess by looking at the environment. Rather than looking for
|
||||||
|
TERM=screen, it uses the STY variable to detect if it is running in screen;
|
||||||
|
tmux does not use this so the check fails. A workaround is to set STY before
|
||||||
|
running elinks.
|
||||||
|
|
||||||
|
The following shell function does this, and also clears the window title on
|
||||||
|
exit (elinks, for some strange reason, sets it to the value of TERM):
|
||||||
|
|
||||||
|
elinks() {
|
||||||
|
STY= `which elinks` $*
|
||||||
|
echo -ne \\033]0\;\\007;
|
||||||
|
}
|
||||||
|
|
||||||
|
* What is the proper way to escape characters with #(command)?
|
||||||
|
|
||||||
|
When using the #(command) construction to include the output from a command in
|
||||||
|
the status line, the command will be parsed twice. First, when it's read by the
|
||||||
|
configuration file or the command-prompt parser, and second when the status
|
||||||
|
line is being drawn and the command is passed to the shell. For example, to
|
||||||
|
echo the string "(test)" to the status line, either single or double quotes
|
||||||
|
could be used:
|
||||||
|
|
||||||
|
set -g status-right "#(echo \\\\(test\\\\))"
|
||||||
|
set -g status-right '#(echo \\\(test\\\))'
|
||||||
|
|
||||||
|
In both cases, the status-right option will be set to the string "#(echo
|
||||||
|
\\(test\\))" and the command executed will be "echo \(test\)".
|
||||||
|
|
||||||
|
* tmux uses too much CPU. What do I do?
|
||||||
|
|
||||||
|
Automatic window renaming may use a lot of CPU, particularly on slow computers:
|
||||||
|
if this is a problem, turn it off with "setw -g automatic-rename off". If this
|
||||||
|
doesn't fix it, please report the problem.
|
||||||
|
|
||||||
|
* I use PuTTY and my tmux window pane separators are all qqqqqqqqq's!
|
||||||
|
|
||||||
|
PuTTY is using a character set translation that doesn't support ACS line
|
||||||
|
drawing. With a Unicode font, try setting PuTTY to use a different translation
|
||||||
|
on the Window -> Translation configuration page. For example, change UTF-8 to
|
||||||
|
ISO-8859-1 or CP437. It may also be necessary to adjust the way PuTTY treats
|
||||||
|
line drawing characters in the lower part of the same configuration page.
|
||||||
|
|
||||||
|
* What is the best way to display the load average? Why no #L?
|
||||||
|
|
||||||
|
It isn't possible to get the load average portably in code and it is preferable
|
||||||
|
not to add portability goop. The following works on at least Linux, *BSD and OS
|
||||||
|
X:
|
||||||
|
|
||||||
|
uptime|awk '{split(substr($0, index($0, "load")), a, ":"); print a[2]}'
|
||||||
|
|
||||||
|
* How do I attach the same session to multiple clients but with a different
|
||||||
|
current window, like screen -x?
|
||||||
|
|
||||||
|
One or more of the windows can be linked into multiple sessions manually with
|
||||||
|
link-window, or a grouped session with all the windows can be created with
|
||||||
|
new-session -t.
|
||||||
|
|
||||||
|
* Ctrl and arrow keys doesn't work in putty! What do I do?
|
||||||
|
|
||||||
|
putty inverts the sense of the cursor key mode on ctrl, which is a bit hard for
|
||||||
|
tmux to detect properly. To get ctrl keys right, change the terminfo settings
|
||||||
|
so kUP5 (Ctrl-Up etc) are the adjusted versions, and disable smkx/rmkx so tmux
|
||||||
|
doesn't change the mode. For example with this line in .tmux.conf (assuming you
|
||||||
|
have TERM set to xterm):
|
||||||
|
|
||||||
|
set -g terminal-overrides "xterm*:kLFT5=\eOD:kRIT5=\eOC:kUP5=\eOA:kDN5=\eOB:smkx@:rmkx@"
|
||||||
|
|
||||||
|
Note that this will only work in tmux 1.2 and above.
|
||||||
|
|
||||||
|
* How can I blank the tmux window?
|
||||||
|
|
||||||
|
GNU screen has a feature whereby it will blank the screen after a period of
|
||||||
|
inactivity. To do the same thing in tmux, use the lock-command setting, for
|
||||||
|
example (with GNU bash):
|
||||||
|
|
||||||
|
set -g lock-command 'tput civis && read -s -n1'
|
||||||
|
|
||||||
|
This will remove the cursor and tell the shell to quit once a key has been
|
||||||
|
pressed. For zsh, use "read -s -k1".
|
||||||
|
|
||||||
|
In addition, it's possible to have both blanking and locking (for instance via
|
||||||
|
lock(1) or vlock(1)) by using the following:
|
||||||
|
|
||||||
|
bind x set lock-command '/usr/bin/vlock' \; lock-client \; set lock-command 'tput civis && read -s -n1'
|
||||||
|
|
||||||
|
* How can I open a new window in the same directory as the current window?
|
||||||
|
|
||||||
|
One option is to just run "TMUX= tmux" in the window. However, this only works if no
|
||||||
|
command is running, so that you can input the command.
|
||||||
|
|
||||||
|
A workaround is to let tmux know about the current path through an environment
|
||||||
|
variable. To do so, use the following command:
|
||||||
|
|
||||||
|
[ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD
|
||||||
|
|
||||||
|
Which sets TMUXPWD_i (where i is the number of the current window) to the path
|
||||||
|
of the current directory. This command can be added to PS1, for example:
|
||||||
|
|
||||||
|
PS1='$([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD)\h$ '
|
||||||
|
|
||||||
|
When a new window is created, the shell should be asked to change
|
||||||
|
directory. You can define a new binding (for example, if using GNU bash):
|
||||||
|
|
||||||
|
bind-key C-c run-shell 'tmux neww "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'
|
||||||
|
|
||||||
|
This solution will work even if a command is currently running in the terminal,
|
||||||
|
but it will not work from a window that has just been swapped with another
|
||||||
|
because TMUXPWD_i will not be updated after a swap. However, once a new prompt
|
||||||
|
is displayed, TMUXPWD_i is updated properly.
|
||||||
|
|
||||||
|
* tmux doesn't start with "daemon failed"
|
||||||
|
|
||||||
|
tmux shows something similar to this when started:
|
||||||
|
|
||||||
|
fatal: server_start: daemon failed: No such file or directory
|
||||||
|
fatal: main_dispatch: imsg_read failed
|
||||||
|
|
||||||
|
A possible reason is that /dev/null is not a character device or is otherwise
|
||||||
|
inaccessible.
|
||||||
|
|
||||||
|
Check with:
|
||||||
|
|
||||||
|
file /dev/null
|
||||||
|
ls -l /dev/null
|
||||||
|
|
||||||
|
If it is not a character device or has incorrect permissions, it can typically
|
||||||
|
be recreated with:
|
||||||
|
|
||||||
|
cd /dev && rm null && ./MAKEDEV null
|
||||||
|
|
||||||
|
* vim displays reverse video instead of italics, while less displays italics
|
||||||
|
(or just regular text) instead of reverse. What's wrong?
|
||||||
|
|
||||||
|
Screen's terminfo description lacks italics mode and has standout mode in its
|
||||||
|
place, but using the same escape sequence that urxvt uses for italics. This
|
||||||
|
means applications (like vim) looking for italics will not find it and might
|
||||||
|
turn to reverse in its place, while applications (like less) asking for
|
||||||
|
standout will end up with italics instead of reverse. To make applications
|
||||||
|
aware that tmux supports italics and to use a proper escape sequence for
|
||||||
|
standout, you'll need to create a new terminfo file with modified sgr, smso,
|
||||||
|
rmso, sitm and ritm entries:
|
||||||
|
|
||||||
|
$ mkdir $HOME/.terminfo/
|
||||||
|
$ screen_terminfo="screen"
|
||||||
|
$ infocmp "$screen_terminfo" | sed \
|
||||||
|
-e 's/^screen[^|]*|[^,]*,/screen-it|screen with italics support,/' \
|
||||||
|
-e 's/%?%p1%t;3%/%?%p1%t;7%/' \
|
||||||
|
-e 's/smso=[^,]*,/smso=\\E[7m,/' \
|
||||||
|
-e 's/rmso=[^,]*,/rmso=\\E[27m,/' \
|
||||||
|
-e '$s/$/ sitm=\\E[3m, ritm=\\E[23m,/' > /tmp/screen.terminfo
|
||||||
|
$ tic /tmp/screen.terminfo
|
||||||
|
|
||||||
|
And tell tmux to use it in ~/.tmux.conf:
|
||||||
|
|
||||||
|
set -g default-terminal "screen-it"
|
||||||
|
|
||||||
|
If your terminal supports 256 colors, use:
|
||||||
|
|
||||||
|
$ screen_terminfo="screen-256color"
|
||||||
|
|
||||||
|
instead of "screen". See the FAQ entry about 256 colors support for more info.
|
||||||
|
Also note that tmux will still display reverse video on terminals that do not
|
||||||
|
support italics.
|
||||||
|
|
||||||
|
If your urxvt cannot display italics at all, make sure you have an italics
|
||||||
|
capable font enabled, for example, add to ~/.Xdefaults:
|
||||||
|
|
||||||
|
urxvt.italicFont: xft:Bitstream Vera Sans Mono:italic:autohint=true
|
||||||
|
|
||||||
|
$Id$
|
||||||
229
Makefile.am
229
Makefile.am
@@ -1,118 +1,115 @@
|
|||||||
|
# $Id$
|
||||||
|
|
||||||
# Obvious program stuff.
|
# Obvious program stuff.
|
||||||
bin_PROGRAMS = tmux
|
bin_PROGRAMS = tmux
|
||||||
CLEANFILES = tmux.1.mdoc tmux.1.man cmd-parse.c
|
dist_man1_MANS = tmux.1
|
||||||
|
|
||||||
# Distribution tarball options.
|
# Distribution tarball options.
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
CHANGES README README.ja COPYING example_tmux.conf \
|
CHANGES FAQ NOTES TODO examples compat \
|
||||||
osdep-*.c mdoc2man.awk tmux.1
|
array.h compat.h tmux.h osdep-*.c
|
||||||
dist_EXTRA_tmux_SOURCES = compat/*.[ch]
|
dist-hook:
|
||||||
|
grep "^#found_debug=" configure
|
||||||
|
find $(distdir) -name .svn -type d|xargs rm -Rf
|
||||||
|
|
||||||
# Preprocessor flags.
|
# Preprocessor flags.
|
||||||
AM_CPPFLAGS += @XOPEN_DEFINES@ \
|
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.
|
# glibc as usual does things ass-backwards and hides useful things by default,
|
||||||
LDADD = $(LIBOBJS)
|
# so everyone has to add this.
|
||||||
|
if IS_GLIBC
|
||||||
|
CFLAGS += -D_GNU_SOURCE
|
||||||
|
endif
|
||||||
|
|
||||||
# Set flags for gcc.
|
# Set flags for gcc. gcc4 whines abouts silly stuff so it needs slightly
|
||||||
|
# different flags.
|
||||||
if IS_GCC
|
if IS_GCC
|
||||||
AM_CFLAGS += -std=gnu99 -O2
|
CFLAGS += -std=c99
|
||||||
if IS_DEBUG
|
if IS_DEBUG
|
||||||
AM_CFLAGS += -g
|
CFLAGS += -g -ggdb -O0
|
||||||
AM_CFLAGS += -Wno-long-long -Wall -W -Wformat=2
|
CFLAGS += -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
|
||||||
AM_CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
|
CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
|
||||||
AM_CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
||||||
AM_CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
|
CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
|
||||||
AM_CFLAGS += -Wdeclaration-after-statement -Wno-pointer-sign -Wno-attributes
|
CPPFLAGS += -DDEBUG
|
||||||
AM_CFLAGS += -Wno-unused-result -Wno-format-y2k
|
|
||||||
if IS_DARWIN
|
|
||||||
AM_CFLAGS += -Wno-deprecated-declarations -Wno-cast-align
|
|
||||||
endif
|
endif
|
||||||
AM_CPPFLAGS += -DDEBUG
|
if IS_GCC4
|
||||||
|
CPPFLAGS += -iquote. -I/usr/local/include
|
||||||
|
if IS_DEBUG
|
||||||
|
CFLAGS += -Wno-pointer-sign
|
||||||
endif
|
endif
|
||||||
AM_CPPFLAGS += -iquote.
|
else
|
||||||
|
CPPFLAGS += -I. -I- -I/usr/local/include
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Set flags for static.
|
||||||
|
if IS_STATIC
|
||||||
|
LDFLAGS += -static
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Set flags for Solaris.
|
# Set flags for Solaris.
|
||||||
if IS_SUNOS
|
if IS_SUNOS
|
||||||
if IS_GCC
|
CPPFLAGS += -D_XPG4_2 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
|
||||||
AM_CPPFLAGS += -D_XPG6
|
|
||||||
else
|
|
||||||
AM_CPPFLAGS += -D_XPG4_2
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Set flags for Sun CC.
|
# Set flags for Sun CC.
|
||||||
if IS_SUNCC
|
if IS_SUNCC
|
||||||
AM_CFLAGS += -erroff=E_EMPTY_DECLARATION
|
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
|
endif
|
||||||
|
|
||||||
# List of sources.
|
# List of sources.
|
||||||
dist_tmux_SOURCES = \
|
dist_tmux_SOURCES = \
|
||||||
alerts.c \
|
|
||||||
arguments.c \
|
arguments.c \
|
||||||
attributes.c \
|
attributes.c \
|
||||||
cfg.c \
|
cfg.c \
|
||||||
client.c \
|
client.c \
|
||||||
|
clock.c \
|
||||||
cmd-attach-session.c \
|
cmd-attach-session.c \
|
||||||
cmd-bind-key.c \
|
cmd-bind-key.c \
|
||||||
cmd-break-pane.c \
|
cmd-break-pane.c \
|
||||||
cmd-capture-pane.c \
|
cmd-capture-pane.c \
|
||||||
cmd-choose-tree.c \
|
cmd-choose-buffer.c \
|
||||||
|
cmd-choose-client.c \
|
||||||
|
cmd-choose-session.c \
|
||||||
|
cmd-choose-window.c \
|
||||||
|
cmd-clear-history.c \
|
||||||
|
cmd-clock-mode.c \
|
||||||
cmd-command-prompt.c \
|
cmd-command-prompt.c \
|
||||||
cmd-confirm-before.c \
|
cmd-confirm-before.c \
|
||||||
cmd-copy-mode.c \
|
cmd-copy-mode.c \
|
||||||
|
cmd-delete-buffer.c \
|
||||||
cmd-detach-client.c \
|
cmd-detach-client.c \
|
||||||
cmd-display-menu.c \
|
|
||||||
cmd-display-message.c \
|
cmd-display-message.c \
|
||||||
cmd-display-panes.c \
|
cmd-display-panes.c \
|
||||||
cmd-find-window.c \
|
cmd-find-window.c \
|
||||||
cmd-find.c \
|
cmd-has-session.c \
|
||||||
cmd-if-shell.c \
|
cmd-if-shell.c \
|
||||||
cmd-join-pane.c \
|
cmd-join-pane.c \
|
||||||
cmd-kill-pane.c \
|
cmd-kill-pane.c \
|
||||||
cmd-kill-server.c \
|
cmd-kill-server.c \
|
||||||
cmd-kill-session.c \
|
cmd-kill-session.c \
|
||||||
cmd-kill-window.c \
|
cmd-kill-window.c \
|
||||||
|
cmd-link-window.c \
|
||||||
cmd-list-buffers.c \
|
cmd-list-buffers.c \
|
||||||
cmd-list-clients.c \
|
cmd-list-clients.c \
|
||||||
|
cmd-list-commands.c \
|
||||||
cmd-list-keys.c \
|
cmd-list-keys.c \
|
||||||
cmd-list-panes.c \
|
cmd-list-panes.c \
|
||||||
cmd-list-sessions.c \
|
cmd-list-sessions.c \
|
||||||
cmd-list-windows.c \
|
cmd-list-windows.c \
|
||||||
|
cmd-list.c \
|
||||||
cmd-load-buffer.c \
|
cmd-load-buffer.c \
|
||||||
cmd-lock-server.c \
|
cmd-lock-server.c \
|
||||||
cmd-move-window.c \
|
cmd-move-window.c \
|
||||||
cmd-new-session.c \
|
cmd-new-session.c \
|
||||||
cmd-new-window.c \
|
cmd-new-window.c \
|
||||||
cmd-parse.y \
|
|
||||||
cmd-paste-buffer.c \
|
cmd-paste-buffer.c \
|
||||||
cmd-pipe-pane.c \
|
cmd-pipe-pane.c \
|
||||||
cmd-queue.c \
|
|
||||||
cmd-refresh-client.c \
|
cmd-refresh-client.c \
|
||||||
cmd-rename-session.c \
|
cmd-rename-session.c \
|
||||||
cmd-rename-window.c \
|
cmd-rename-window.c \
|
||||||
cmd-resize-pane.c \
|
cmd-resize-pane.c \
|
||||||
cmd-resize-window.c \
|
|
||||||
cmd-respawn-pane.c \
|
cmd-respawn-pane.c \
|
||||||
cmd-respawn-window.c \
|
cmd-respawn-window.c \
|
||||||
cmd-rotate-window.c \
|
cmd-rotate-window.c \
|
||||||
@@ -122,34 +119,31 @@ dist_tmux_SOURCES = \
|
|||||||
cmd-select-pane.c \
|
cmd-select-pane.c \
|
||||||
cmd-select-window.c \
|
cmd-select-window.c \
|
||||||
cmd-send-keys.c \
|
cmd-send-keys.c \
|
||||||
cmd-server-access.c \
|
cmd-send-prefix.c \
|
||||||
|
cmd-server-info.c \
|
||||||
cmd-set-buffer.c \
|
cmd-set-buffer.c \
|
||||||
cmd-set-environment.c \
|
cmd-set-environment.c \
|
||||||
cmd-set-option.c \
|
cmd-set-option.c \
|
||||||
|
cmd-show-buffer.c \
|
||||||
cmd-show-environment.c \
|
cmd-show-environment.c \
|
||||||
cmd-show-messages.c \
|
cmd-show-messages.c \
|
||||||
cmd-show-options.c \
|
cmd-show-options.c \
|
||||||
cmd-show-prompt-history.c \
|
|
||||||
cmd-source-file.c \
|
cmd-source-file.c \
|
||||||
cmd-split-window.c \
|
cmd-split-window.c \
|
||||||
|
cmd-start-server.c \
|
||||||
|
cmd-string.c \
|
||||||
|
cmd-suspend-client.c \
|
||||||
cmd-swap-pane.c \
|
cmd-swap-pane.c \
|
||||||
cmd-swap-window.c \
|
cmd-swap-window.c \
|
||||||
cmd-switch-client.c \
|
cmd-switch-client.c \
|
||||||
cmd-unbind-key.c \
|
cmd-unbind-key.c \
|
||||||
cmd-wait-for.c \
|
cmd-unlink-window.c \
|
||||||
cmd.c \
|
cmd.c \
|
||||||
colour.c \
|
colour.c \
|
||||||
compat.h \
|
|
||||||
control-notify.c \
|
|
||||||
control.c \
|
|
||||||
environ.c \
|
environ.c \
|
||||||
file.c \
|
grid-utf8.c \
|
||||||
format.c \
|
|
||||||
format-draw.c \
|
|
||||||
grid-reader.c \
|
|
||||||
grid-view.c \
|
grid-view.c \
|
||||||
grid.c \
|
grid.c \
|
||||||
hyperlinks.c \
|
|
||||||
input-keys.c \
|
input-keys.c \
|
||||||
input.c \
|
input.c \
|
||||||
job.c \
|
job.c \
|
||||||
@@ -159,84 +153,91 @@ dist_tmux_SOURCES = \
|
|||||||
layout-set.c \
|
layout-set.c \
|
||||||
layout.c \
|
layout.c \
|
||||||
log.c \
|
log.c \
|
||||||
menu.c \
|
mode-key.c \
|
||||||
mode-tree.c \
|
|
||||||
names.c \
|
names.c \
|
||||||
notify.c \
|
|
||||||
options-table.c \
|
options-table.c \
|
||||||
options.c \
|
options.c \
|
||||||
paste.c \
|
paste.c \
|
||||||
popup.c \
|
|
||||||
proc.c \
|
|
||||||
regsub.c \
|
|
||||||
resize.c \
|
resize.c \
|
||||||
screen-redraw.c \
|
screen-redraw.c \
|
||||||
screen-write.c \
|
screen-write.c \
|
||||||
screen.c \
|
screen.c \
|
||||||
server-acl.c \
|
|
||||||
server-client.c \
|
server-client.c \
|
||||||
server-fn.c \
|
server-fn.c \
|
||||||
|
server-window.c \
|
||||||
server.c \
|
server.c \
|
||||||
session.c \
|
session.c \
|
||||||
spawn.c \
|
signal.c \
|
||||||
status.c \
|
status.c \
|
||||||
style.c \
|
|
||||||
tmux.c \
|
tmux.c \
|
||||||
tmux.h \
|
|
||||||
tmux-protocol.h \
|
|
||||||
tty-acs.c \
|
tty-acs.c \
|
||||||
tty-features.c \
|
|
||||||
tty-keys.c \
|
tty-keys.c \
|
||||||
tty-term.c \
|
tty-term.c \
|
||||||
tty.c \
|
tty.c \
|
||||||
utf8-combined.c \
|
|
||||||
utf8.c \
|
utf8.c \
|
||||||
window-buffer.c \
|
window-choose.c \
|
||||||
window-client.c \
|
|
||||||
window-clock.c \
|
window-clock.c \
|
||||||
window-copy.c \
|
window-copy.c \
|
||||||
window-customize.c \
|
|
||||||
window-tree.c \
|
|
||||||
window.c \
|
window.c \
|
||||||
xmalloc.c \
|
xmalloc.c \
|
||||||
xmalloc.h
|
xterm-keys.c
|
||||||
nodist_tmux_SOURCES = osdep-@PLATFORM@.c
|
nodist_tmux_SOURCES = osdep-@PLATFORM@.c
|
||||||
|
|
||||||
# Add compat file for forkpty.
|
# Pile in all the compat/ stuff that is needed.
|
||||||
if NEED_FORKPTY
|
if NO_FORKPTY
|
||||||
nodist_tmux_SOURCES += compat/forkpty-@PLATFORM@.c
|
nodist_tmux_SOURCES += compat/forkpty-@PLATFORM@.c
|
||||||
endif
|
endif
|
||||||
|
if NO_IMSG
|
||||||
# Add compat file for systemd.
|
nodist_tmux_SOURCES += compat/imsg.c compat/imsg-buffer.c
|
||||||
if HAVE_SYSTEMD
|
endif
|
||||||
nodist_tmux_SOURCES += compat/systemd.c
|
if NO_CLOSEFROM
|
||||||
|
nodist_tmux_SOURCES += compat/closefrom.c
|
||||||
|
endif
|
||||||
|
if NO_DAEMON
|
||||||
|
nodist_tmux_SOURCES += compat/daemon.c
|
||||||
|
endif
|
||||||
|
if NO_SETENV
|
||||||
|
nodist_tmux_SOURCES += compat/setenv.c
|
||||||
|
endif
|
||||||
|
if NO_STRLCAT
|
||||||
|
nodist_tmux_SOURCES += compat/strlcat.c
|
||||||
|
endif
|
||||||
|
if NO_STRLCPY
|
||||||
|
nodist_tmux_SOURCES += compat/strlcpy.c
|
||||||
|
endif
|
||||||
|
if NO_ASPRINTF
|
||||||
|
nodist_tmux_SOURCES += compat/asprintf.c
|
||||||
|
endif
|
||||||
|
if NO_FGETLN
|
||||||
|
nodist_tmux_SOURCES += compat/fgetln.c
|
||||||
|
endif
|
||||||
|
if NO_GETOPT
|
||||||
|
nodist_tmux_SOURCES += compat/getopt.c
|
||||||
|
endif
|
||||||
|
if NO_STRCASESTR
|
||||||
|
nodist_tmux_SOURCES += compat/strcasestr.c
|
||||||
|
endif
|
||||||
|
if NO_STRSEP
|
||||||
|
nodist_tmux_SOURCES += compat/strsep.c
|
||||||
|
endif
|
||||||
|
if NO_VIS
|
||||||
|
nodist_tmux_SOURCES += compat/vis.c compat/unvis.c
|
||||||
|
endif
|
||||||
|
if NO_STRTONUM
|
||||||
|
nodist_tmux_SOURCES += compat/strtonum.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Add compat file for utf8proc.
|
# Update SF web site.
|
||||||
if HAVE_UTF8PROC
|
upload-index.html: update-index.html
|
||||||
nodist_tmux_SOURCES += compat/utf8proc.c
|
scp www/index.html www/main.css www/images/*.png \
|
||||||
endif
|
${USER},tmux@web.sf.net:/home/groups/t/tm/tmux/htdocs
|
||||||
|
rm -f www/index.html www/images/small-*
|
||||||
|
|
||||||
# Enable sixel support.
|
update-index.html:
|
||||||
if ENABLE_SIXEL
|
(cd www/images && \
|
||||||
dist_tmux_SOURCES += image.c image-sixel.c
|
rm -f small-* && \
|
||||||
endif
|
for i in *.png; do \
|
||||||
|
convert "$$i" -resize 200x150 "small-$$i"; \
|
||||||
if NEED_FUZZING
|
done \
|
||||||
check_PROGRAMS = fuzz/input-fuzzer
|
)
|
||||||
fuzz_input_fuzzer_LDFLAGS = $(FUZZING_LIBS)
|
sed "s/%%VERSION%%/${VERSION}/g" www/index.html.in >www/index.html
|
||||||
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
|
|
||||||
|
|||||||
65
NOTES
Normal file
65
NOTES
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
Welcome to tmux!
|
||||||
|
|
||||||
|
tmux is a "terminal multiplexer", it enables a number of terminals (or windows)
|
||||||
|
to be accessed and controlled from a single terminal. tmux is intended to be a
|
||||||
|
simple, modern, BSD-licensed alternative to programs such as GNU screen.
|
||||||
|
|
||||||
|
This release runs on OpenBSD, FreeBSD, NetBSD, Linux and OS X and may still
|
||||||
|
run on Solaris and AIX (although they haven't been tested in a while). It is
|
||||||
|
usable, although there remain a number of missing features and some remaining
|
||||||
|
bugs are expected.
|
||||||
|
|
||||||
|
Since the 1.2 release that tmux depends on libevent. Download it from:
|
||||||
|
|
||||||
|
http://www.monkey.org/~provos/libevent/
|
||||||
|
|
||||||
|
tmux consists of a server part and multiple clients. The server is created when
|
||||||
|
required and runs continuously unless killed by the user. Clients access the
|
||||||
|
server through a socket in /tmp. Multiple sessions may be created on a single
|
||||||
|
server and attached to a number of clients. Each session may then have a number
|
||||||
|
of windows and windows may be linked to a number of sessions. Commands are
|
||||||
|
available to create, rename and destroy windows and sessions; to attach and
|
||||||
|
detach sessions from client terminals; to set configuration options; to split
|
||||||
|
windows into several simultaneously displayed panes; and to bind and unbind
|
||||||
|
command keys (invoked preceded by a prefix key, by default ctrl-b). Please see
|
||||||
|
the tmux(1) man page for further information.
|
||||||
|
|
||||||
|
A more extensive, but rough, todo list is included in the TODO file.
|
||||||
|
|
||||||
|
tmux also depends on several features of the client terminal (TERM), if these
|
||||||
|
are missing it may refuse to run, or not behave correctly.
|
||||||
|
|
||||||
|
A Vim syntax file is available in the examples directory. To install it:
|
||||||
|
|
||||||
|
- Drop the file in the syntax directory in your runtimepath (such as
|
||||||
|
~/.vim/syntax/tmux.vim).
|
||||||
|
- Make the filetype recognisable by adding the following to filetype.vim
|
||||||
|
in your runtimepath (~/.vim/filetype.vim):
|
||||||
|
|
||||||
|
augroup filetypedetect
|
||||||
|
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
- Switch on syntax highlighting by adding "syntax enable" to your vimrc file.
|
||||||
|
|
||||||
|
For debugging, running tmux with -v or -vv will generate server and client log
|
||||||
|
files in the current directory.
|
||||||
|
|
||||||
|
tmux mailing lists are available; visit:
|
||||||
|
|
||||||
|
https://sourceforge.net/mail/?group_id=200378
|
||||||
|
|
||||||
|
Bug reports, feature suggestions and especially code contributions are most
|
||||||
|
welcome. Please send by email to:
|
||||||
|
|
||||||
|
nicm@users.sf.net
|
||||||
|
|
||||||
|
This file and the CHANGES, FAQ and TODO files are licensed under the ISC
|
||||||
|
license. Files under examples/ remain copyright their authors unless otherwise
|
||||||
|
stated in the file but permission has been received to distribute them with
|
||||||
|
tmux. All other files have a license and copyright notice at their
|
||||||
|
start. Please contact me with any queries.
|
||||||
|
|
||||||
|
-- Nicholas Marriott <nicm@users.sf.net>
|
||||||
|
|
||||||
|
$Id$
|
||||||
86
README
86
README
@@ -1,86 +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
|
|
||||||
|
|
||||||
* 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/imomaliev/tmux-bash-completion
|
|
||||||
|
|
||||||
For debugging, run tmux with -v and -vv to generate server and client log files
|
|
||||||
in the current directory.
|
|
||||||
|
|
||||||
* Support
|
|
||||||
|
|
||||||
The tmux mailing list for general discussion and bug reports is:
|
|
||||||
|
|
||||||
https://groups.google.com/forum/#!forum/tmux-users
|
|
||||||
|
|
||||||
Subscribe by sending an email to:
|
|
||||||
|
|
||||||
tmux-users+subscribe@googlegroups.com
|
|
||||||
|
|
||||||
* License
|
|
||||||
|
|
||||||
This file and the CHANGES files are licensed under the ISC license. All other
|
|
||||||
files have a license and copyright notice at their start.
|
|
||||||
62
README.ja
62
README.ja
@@ -1,62 +0,0 @@
|
|||||||
tmuxへようこそ!
|
|
||||||
|
|
||||||
tmuxはターミナルマルチプレクサーです。複数のターミナルを一つのスクリーン内に作成し、操作することができます。
|
|
||||||
バックグラウンドで処理を実行中に一度スクリーンから離れて後から復帰することも可能です。
|
|
||||||
|
|
||||||
OpenBSD、FreeBSD、NetBSD、Linux、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/imomaliev/tmux-bash-completion
|
|
||||||
|
|
||||||
「-v」や「-vv」を指定することでデバッグモードでの起動が可能です。カレントディレクトリにサーバーやクライアントのログファイルが生成されます。
|
|
||||||
|
|
||||||
議論やバグレポート用のメーリングリストにはこちらから参加可能です。
|
|
||||||
|
|
||||||
https://groups.google.com/forum/#!forum/tmux-users
|
|
||||||
|
|
||||||
gitコミットについての連絡先
|
|
||||||
|
|
||||||
https://groups.google.com/forum/#!forum/tmux-git
|
|
||||||
|
|
||||||
購読は<tmux-users+subscribe@googlegroups.com>までメールをお願いします。
|
|
||||||
|
|
||||||
バグレポートや機能追加(特にコードへの貢献)は大歓迎です。こちらにご連絡ください。
|
|
||||||
|
|
||||||
tmux-users@googlegroups.com
|
|
||||||
|
|
||||||
本ファイル、CHANGES、 FAQ、SYNCINGそしてTODOはISC licenseで保護されています。
|
|
||||||
その他のファイルのライセンスや著作権については、ファイルの上部に明記されています。
|
|
||||||
|
|
||||||
-- Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
173
SYNCING
173
SYNCING
@@ -1,173 +0,0 @@
|
|||||||
Preamble
|
|
||||||
========
|
|
||||||
|
|
||||||
Tmux portable relies on repositories "tmux" and "tmux-openbsd".
|
|
||||||
Here's a description of them:
|
|
||||||
|
|
||||||
* "tmux" is the portable version, the one which contains code for other
|
|
||||||
operating systems, and autotools, etc., which isn't found or needed in the
|
|
||||||
OpenBSD base system.
|
|
||||||
|
|
||||||
* "tmux-openbsd" is the version of tmux in OpenBSD base system which provides
|
|
||||||
the basis of the portable tmux version.
|
|
||||||
|
|
||||||
Note: The "tmux-openbsd" repository is actually handled by "git cvsimport"
|
|
||||||
running at 15 minute intervals, so a commit made to OpenBSD's tmux CVS
|
|
||||||
repository will take at least that long to appear in this git repository.
|
|
||||||
(It might take longer, depending on the CVS mirror used to import the
|
|
||||||
OpenBSD code).
|
|
||||||
|
|
||||||
If you've never used git before, git tracks meta-data about the committer
|
|
||||||
and the author, as part of a commit, hence:
|
|
||||||
|
|
||||||
% git config [--global] user.name "Your name"
|
|
||||||
% git config [--global] user.email "you@yourdomain.com"
|
|
||||||
|
|
||||||
Note that, if you already have this in the global ~/.gitconfig option, then
|
|
||||||
this will be used. Setting this per-repository would involve not using the
|
|
||||||
"--global" flag above. If you wish to use the same credentials always,
|
|
||||||
pass the "--global" option, as shown.
|
|
||||||
|
|
||||||
This is a one-off operation once the repository has been cloned, assuming
|
|
||||||
this information has ever been set before.
|
|
||||||
|
|
||||||
Cloning repositories
|
|
||||||
====================
|
|
||||||
|
|
||||||
This involves having both tmux and tmux-openbsd cloned, as in:
|
|
||||||
|
|
||||||
% cd /some/where/useful
|
|
||||||
% git clone https://github.com/tmux/tmux.git
|
|
||||||
% git clone https://github.com/ThomasAdam/tmux-openbsd.git
|
|
||||||
|
|
||||||
Note that you do not need additional checkouts to manage the sync -- an
|
|
||||||
existing clone of either repositories will suffice. So if you already have
|
|
||||||
these checkouts existing, skip that.
|
|
||||||
|
|
||||||
Adding in git-remotes
|
|
||||||
=====================
|
|
||||||
|
|
||||||
Because the portable "tmux" git repository and the "tmux-openbsd"
|
|
||||||
repository do not inherently share any history between each other, the
|
|
||||||
history has been faked between them. This "faking of history" is something
|
|
||||||
which has to be told to git for the purposes of comparing the "tmux" and
|
|
||||||
"tmux-openbsd" repositories for syncing. To do this, we must reference the
|
|
||||||
clone of the "tmux-openbsd" repository from the "tmux" repository, as
|
|
||||||
shown by the following command:
|
|
||||||
|
|
||||||
% cd /path/to/tmux
|
|
||||||
% git remote add obsd-tmux file:///path/to/tmux-openbsd
|
|
||||||
|
|
||||||
So that now, the remote "obsd-tmux" can be used to reference branches and
|
|
||||||
commits from the "tmux-openbsd" repository, but from the context of the
|
|
||||||
portable "tmux" repository, which makes sense because it's the "tmux"
|
|
||||||
repository which will have the updates applied to them.
|
|
||||||
|
|
||||||
Fetching updates
|
|
||||||
================
|
|
||||||
|
|
||||||
To ensure the latest commits from "tmux-openbsd" can be found from within
|
|
||||||
"tmux", we have to ensure the "master" branch from "tmux-openbsd" is
|
|
||||||
up-to-date first, and then reference that update in "tmux", as in:
|
|
||||||
|
|
||||||
% cd /path/to/tmux-openbsd
|
|
||||||
% git checkout master
|
|
||||||
% git pull
|
|
||||||
|
|
||||||
Then back in "tmux":
|
|
||||||
|
|
||||||
% cd /path/to/tmux
|
|
||||||
% git fetch obsd-tmux
|
|
||||||
|
|
||||||
Creating the necessary branches
|
|
||||||
===============================
|
|
||||||
|
|
||||||
Now that "tmux" can see commits and branches from "tmux-openbsd" by way
|
|
||||||
of the remote name "obsd-tmux", we can now create the master branch from
|
|
||||||
"tmux-openbsd" in the "tmux" repository:
|
|
||||||
|
|
||||||
% git checkout -b obsd-master obsd-tmux/master
|
|
||||||
|
|
||||||
Adding in the fake history points
|
|
||||||
=================================
|
|
||||||
|
|
||||||
To tie both the "master" branch from "tmux" and the "obsd-master"
|
|
||||||
branch from "tmux-openbsd" together, the fake history points added to the
|
|
||||||
"tmux" repository need to be added. To do this, we must add an
|
|
||||||
additional refspec line, as in:
|
|
||||||
|
|
||||||
% cd /path/to/tmux
|
|
||||||
% git config --add remote.origin.fetch '+refs/replace/*:refs/replace/*'
|
|
||||||
% git fetch origin
|
|
||||||
|
|
||||||
Performing the Sync
|
|
||||||
===================
|
|
||||||
|
|
||||||
Make sure the "master" branch is checked out:
|
|
||||||
|
|
||||||
% git checkout master
|
|
||||||
|
|
||||||
The following will show commits on OpenBSD not yet synched with "tmux":
|
|
||||||
|
|
||||||
% git log master..obsd-master
|
|
||||||
|
|
||||||
From there, merge the result in, fixing up any conflicts which might arise.
|
|
||||||
|
|
||||||
% git merge obsd-master
|
|
||||||
|
|
||||||
Then ensure things look correct by BUILDING the result of that sync:
|
|
||||||
|
|
||||||
% make clean && ./autogen.sh && ./configure && make
|
|
||||||
|
|
||||||
Compare the git merge result with what's on origin/master -- that is, check
|
|
||||||
which commits you're about to push:
|
|
||||||
|
|
||||||
% git log origin/master..master
|
|
||||||
|
|
||||||
And if happy:
|
|
||||||
|
|
||||||
% git push origin master
|
|
||||||
|
|
||||||
Keeping an eye on libutil in OpenBSD
|
|
||||||
====================================
|
|
||||||
|
|
||||||
A lot of the compat/ code in tmux comes from libutil, especially imsg.
|
|
||||||
Sometimes the API can change, etc., which might cause interesting problems
|
|
||||||
trying to run the portable version of tmux. It's worth checking
|
|
||||||
periodically for any changes to libutil in OpenBSD and syncing those files
|
|
||||||
to compat/ as and when appropriate.
|
|
||||||
|
|
||||||
Release tmux for next version
|
|
||||||
=============================
|
|
||||||
|
|
||||||
1. Update and commit README and CHANGES. The former should be checked for
|
|
||||||
anything outdated and updated with a list of things that might break
|
|
||||||
upgrades and the latter should mention all the major changes since
|
|
||||||
the last version.
|
|
||||||
|
|
||||||
2. Make sure configure.ac has the new version number.
|
|
||||||
|
|
||||||
3. Tag with:
|
|
||||||
|
|
||||||
% git tag -a 2.X
|
|
||||||
|
|
||||||
Where "2.X" is the next version.
|
|
||||||
|
|
||||||
Push the tag out with:
|
|
||||||
|
|
||||||
% git push --tags
|
|
||||||
|
|
||||||
4. Build the tarball with 'make dist'.
|
|
||||||
|
|
||||||
5. Check the tarball. If it's good, go here to select the tag just pushed:
|
|
||||||
|
|
||||||
https://github.com/tmux/tmux/tags
|
|
||||||
|
|
||||||
Click the "Add release notes", upload the tarball and add a link in the
|
|
||||||
description field to the CHANGES file.
|
|
||||||
|
|
||||||
6. Clone the tmux.github.io repository, and change the RELEASE version in the
|
|
||||||
Makefile. Commit it, and run 'make' to replace %%RELEASE%%. Push the
|
|
||||||
result out.
|
|
||||||
|
|
||||||
7. Change version back to master in configure.ac.
|
|
||||||
140
TODO
Normal file
140
TODO
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
- implicitly add exec to the commands for new windows (switch to disable it)?
|
||||||
|
- bring back detach-session to detach all clients on a session?
|
||||||
|
- allow fnmatch for -c, so that you can, eg, detach all clients
|
||||||
|
- garbage collect window history (100 lines at a time?) if it hasn't been used
|
||||||
|
in $x time
|
||||||
|
- flags to centre screen in window
|
||||||
|
- activity/bell should be per-window not per-link? what if it is cur win in
|
||||||
|
session not being watched?
|
||||||
|
- next prev word etc in command prompt
|
||||||
|
- use a better termcap internally instead of screen, perhaps xterm
|
||||||
|
- should be able to move to a hidden pane and it would be moved into view. pane
|
||||||
|
number in status line/top-right would be cool for this
|
||||||
|
- support other mouse modes (highlight etc) and use it in copy mode
|
||||||
|
- set-remain-on-exit is a bit of a hack, some way to do it generically?
|
||||||
|
- clear window title on exit
|
||||||
|
- would be nice to be able to use "--" to mark start of command w/ neww etc
|
||||||
|
to avoid quoting
|
||||||
|
- make command sequences more usable: don't require space after ;, handle
|
||||||
|
errors better
|
||||||
|
- attach should have a flag to create session if it doesn't exist
|
||||||
|
- choice and more mode would be better per client than per window?
|
||||||
|
- hooks to which commands may be attached, for example: tmux add-hook
|
||||||
|
"new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file
|
||||||
|
$HOME/.tmux-session.conf
|
||||||
|
- get it passing all the vttest tests that don't require resizing the terminal
|
||||||
|
- way to set socket path from config file
|
||||||
|
- what about utmp etc? can tmux update it like screen? setgid?
|
||||||
|
- warts on current naming:
|
||||||
|
- display-time but message-fg/bg/attr
|
||||||
|
- list-* vs show-*
|
||||||
|
- server-info
|
||||||
|
- up-pane/down-pane/swap-pane -U/swap-pane -D vs next-*/previous-*
|
||||||
|
- split-window -> split-pane??
|
||||||
|
- a way for force-width/height to apply to only one pane (how?)
|
||||||
|
- command to list what is actually running in each window with command line,
|
||||||
|
pid (need some adaption of the osdep code)
|
||||||
|
- support for bce
|
||||||
|
- some way to force a screen to use the entire terminal even if it is forced
|
||||||
|
to be smaller by other clients. pan smaller terminal? (like screen F)
|
||||||
|
-- idea of a "view" onto a window, need base x/y offsets for redraw
|
||||||
|
- handle resize better in copy mode
|
||||||
|
- way to copy stuff that is off screen due to resize
|
||||||
|
- commands should be able to succeed or fail and have || or && for command
|
||||||
|
lists
|
||||||
|
- some way to KEEP a command running continually and just use its LAST line of
|
||||||
|
output
|
||||||
|
- UTF-8 to a non-UTF-8 terminal should not be able to balls up
|
||||||
|
the terminal - www/ruby-addressable; make regress
|
||||||
|
- support esc-esc to quit in modes
|
||||||
|
- fix ctrl+F1-F4 output. to what?
|
||||||
|
- better utf8 support: window names, prompt input, message display
|
||||||
|
- session history for client and last-session command
|
||||||
|
- option to change status line colour when current window is in a mode?
|
||||||
|
- option to move copy mode indicator into status line
|
||||||
|
- list-buffer/show-buffer should display UTF-8
|
||||||
|
- selection behaviour closer to vi in vi mode
|
||||||
|
- live update: server started with -U connects to server, requests sessions and
|
||||||
|
windows, receives fds
|
||||||
|
- command to show a tree of sessions-windows-panes (active marked with *)
|
||||||
|
- sort out inheriting config from shell on new sessions/windows:
|
||||||
|
should pick up default-path/termios/etc from client if possible,
|
||||||
|
else leave empty/default
|
||||||
|
- link panes into multiple windows
|
||||||
|
- bells should be passed between sessions with visual-bell etc
|
||||||
|
- use screen-256color when started on 256 colour terminal??
|
||||||
|
- if-shell/run-shell should block further command execution in the same command
|
||||||
|
sequence until its shell exits, to allow them to be used from the config file
|
||||||
|
- better session sharing: create-socket command to create socket somewhere (-r
|
||||||
|
flag for readonly)
|
||||||
|
- allow buffer to be specified when copying in copy mode
|
||||||
|
- multiline status line (no?)
|
||||||
|
- flag for absolute pane size to resize-pane
|
||||||
|
- sanity check input to socket
|
||||||
|
- support title stack, both internally and externally
|
||||||
|
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=1149299+0+archive/2010/freebsd-questions/20100207.freebsd-questions
|
||||||
|
- command to show status line information briefly when it is off
|
||||||
|
- some way to pad # stuff with spaces, #!2T maybe
|
||||||
|
- a binding to "scroll down and exit at bottom" copy mode
|
||||||
|
- some way to pass keystrokes in copy mode through to underlying window
|
||||||
|
- last window update time and # replacement for it for display-message
|
||||||
|
- find-window across sessions - other ways to make session handling easier?
|
||||||
|
- ' and " should be parsed the same (eg "\e" vs '\e') in config and command
|
||||||
|
prompt?
|
||||||
|
- command to toggle selection not to move it in copy-mode
|
||||||
|
- why are alerts per-winlink? try per window?
|
||||||
|
- audit of escape sequence support vs xterm
|
||||||
|
- support binding keys to mouse (mouse-select-pane -> mouse-keys or something,
|
||||||
|
mouse click == select-pane -t %%, mouse scroll up == copy-mode)
|
||||||
|
- something for -t "last window in session" so a session can be used as a stack
|
||||||
|
- synchronous commands - client sends cmd and blocks, neww/splitw saves client
|
||||||
|
ptr then when program inside died, sends MSG_SOMETHING with wait status to
|
||||||
|
client
|
||||||
|
- documentation improvements - rlpowell's tutorial - build instructions
|
||||||
|
- bind commands to key sequences? -- make it so ALL keys go through a table,
|
||||||
|
first an implicit table in which C-b is the only default binding to a
|
||||||
|
command that says "next key from $othertable" and so on. means -n can
|
||||||
|
go away as well
|
||||||
|
- monitor, bell etc should monitor /all/ panes in the window not just one
|
||||||
|
- a history of commands that can be reversed (reverse member of each command,
|
||||||
|
and a buffer) info() when changing to same window
|
||||||
|
- way to add dest for break-pane; maybe some easier way to unbreak-pane
|
||||||
|
- case insensitive searching
|
||||||
|
- pane-index option like base-index
|
||||||
|
- option to move status line to top
|
||||||
|
- configurable borders and empty space filler for when panes < window?
|
||||||
|
- mouse-select-pane will screw up with !MODE_MOUSE_STANDARD (it sets the
|
||||||
|
flag on w/o checking the others before calling tty_update_mode)
|
||||||
|
- multiple keys could be done with tables, ie have prefixes go and instead
|
||||||
|
bind -n ^A prefix-table "default"
|
||||||
|
where prefix-table sets command lookup table and sets prefix flag, then next
|
||||||
|
key is looked up in that table
|
||||||
|
- pass shell commands as argv rather than strings, allow them to be specified
|
||||||
|
in commands without quotes
|
||||||
|
- a command to choose from a generic list, so you can do eg
|
||||||
|
choose-list -l Abc,Moo,Blah "run-shell 'sh /my/choose/script %%'"
|
||||||
|
- else part for if-shell
|
||||||
|
- add general internal format for lists (key=value) and a way to output them in
|
||||||
|
different representations, use for list-windows, etc etc. see message id
|
||||||
|
20110221205346.GA1580@yelena.nicm.ath.cx
|
||||||
|
- numeric prefix in copy mode should be paste buffer for C-w
|
||||||
|
- named buffers and allow gaps in the stack
|
||||||
|
- npage/ppage/dc/ic should have aliases for more typical names
|
||||||
|
- get rid of separate UTF-8 cell stuff: add 1 byte to cell and store BMP as
|
||||||
|
uint16_t+3 bits of flags. anything <=0xffff is Unicode, higher are used to
|
||||||
|
build tree of combined characters/non-BMP (LRU dropped when full)
|
||||||
|
- entry in FAQ about what to do when someone does mkdir /tmp/tmux-1000
|
||||||
|
- show size under pane number in display-panes mode
|
||||||
|
- monitor-activity is broken in several ways with multiple clients
|
||||||
|
- monitor-activity should be more powerful (eg set a region)
|
||||||
|
- maybe a way to put pane names instead of window names in status line
|
||||||
|
- Support for borderless panes
|
||||||
|
- run-shell/if-shell should support status_replace stuff
|
||||||
|
- wait-pane command or another way to make it synchronous/wait for command to
|
||||||
|
finish
|
||||||
|
- way to get command window was started with (part of format stuff?)
|
||||||
|
- last-pane across sessions
|
||||||
|
- attach should take a pane and select it as well as attaching
|
||||||
|
* We need a tmux terminfo entry to document the extensions we are using in
|
||||||
|
upstream terminfo. Must NOT change (only add or remove) anything from
|
||||||
|
TERM=screen so we can fallback!
|
||||||
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, "%s in current window",
|
|
||||||
type);
|
|
||||||
} else {
|
|
||||||
status_message_set(c, -1, 1, 0, "%s in window %d", type,
|
|
||||||
wl->idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1107
arguments.c
1107
arguments.c
File diff suppressed because it is too large
Load Diff
121
array.h
Normal file
121
array.h
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ARRAY_H
|
||||||
|
#define ARRAY_H
|
||||||
|
|
||||||
|
#define ARRAY_INITIALIZER { NULL, 0, 0 }
|
||||||
|
|
||||||
|
#define ARRAY_DECL(n, c) \
|
||||||
|
struct n { \
|
||||||
|
c *list; \
|
||||||
|
u_int num; \
|
||||||
|
size_t space; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ARRAY_ITEM(a, i) ((a)->list[i])
|
||||||
|
#define ARRAY_ITEMSIZE(a) (sizeof *(a)->list)
|
||||||
|
#define ARRAY_INITIALSPACE(a) (10 * ARRAY_ITEMSIZE(a))
|
||||||
|
|
||||||
|
#define ARRAY_ENSURE(a, n) do { \
|
||||||
|
if (UINT_MAX - (n) < (a)->num) \
|
||||||
|
fatalx("number too big"); \
|
||||||
|
if (SIZE_MAX / ((a)->num + (n)) < ARRAY_ITEMSIZE(a)) \
|
||||||
|
fatalx("size too big"); \
|
||||||
|
if ((a)->space == 0) { \
|
||||||
|
(a)->space = ARRAY_INITIALSPACE(a); \
|
||||||
|
(a)->list = xrealloc((a)->list, 1, (a)->space); \
|
||||||
|
} \
|
||||||
|
while ((a)->space <= ((a)->num + (n)) * ARRAY_ITEMSIZE(a)) { \
|
||||||
|
(a)->list = xrealloc((a)->list, 2, (a)->space); \
|
||||||
|
(a)->space *= 2; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_EMPTY(a) (((void *) (a)) == NULL || (a)->num == 0)
|
||||||
|
#define ARRAY_LENGTH(a) ((a)->num)
|
||||||
|
#define ARRAY_DATA(a) ((a)->list)
|
||||||
|
|
||||||
|
#define ARRAY_FIRST(a) ARRAY_ITEM(a, 0)
|
||||||
|
#define ARRAY_LAST(a) ARRAY_ITEM(a, (a)->num - 1)
|
||||||
|
|
||||||
|
#define ARRAY_INIT(a) do { \
|
||||||
|
(a)->num = 0; \
|
||||||
|
(a)->list = NULL; \
|
||||||
|
(a)->space = 0; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_CLEAR(a) do { \
|
||||||
|
(a)->num = 0; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_SET(a, i, s) do { \
|
||||||
|
(a)->list[i] = s; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_ADD(a, s) do { \
|
||||||
|
ARRAY_ENSURE(a, 1); \
|
||||||
|
(a)->list[(a)->num] = s; \
|
||||||
|
(a)->num++; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_INSERT(a, i, s) do { \
|
||||||
|
ARRAY_ENSURE(a, 1); \
|
||||||
|
if ((i) < (a)->num) { \
|
||||||
|
memmove((a)->list + (i) + 1, (a)->list + (i), \
|
||||||
|
ARRAY_ITEMSIZE(a) * ((a)->num - (i))); \
|
||||||
|
} \
|
||||||
|
(a)->list[i] = s; \
|
||||||
|
(a)->num++; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_REMOVE(a, i) do { \
|
||||||
|
if ((i) < (a)->num - 1) { \
|
||||||
|
memmove((a)->list + (i), (a)->list + (i) + 1, \
|
||||||
|
ARRAY_ITEMSIZE(a) * ((a)->num - (i) - 1)); \
|
||||||
|
} \
|
||||||
|
(a)->num--; \
|
||||||
|
if ((a)->num == 0) \
|
||||||
|
ARRAY_FREE(a); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_EXPAND(a, n) do { \
|
||||||
|
ARRAY_ENSURE(a, n); \
|
||||||
|
(a)->num += n; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_TRUNC(a, n) do { \
|
||||||
|
if ((a)->num > n) \
|
||||||
|
(a)->num -= n; \
|
||||||
|
else \
|
||||||
|
ARRAY_FREE(a); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_CONCAT(a, b) do { \
|
||||||
|
ARRAY_ENSURE(a, (b)->num); \
|
||||||
|
memcpy((a)->list + (a)->num, (b)->list, (b)->num * ARRAY_ITEMSIZE(a)); \
|
||||||
|
(a)->num += (b)->num; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_FREE(a) do { \
|
||||||
|
if ((a)->list != NULL) \
|
||||||
|
xfree((a)->list); \
|
||||||
|
ARRAY_INIT(a); \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_FREEALL(a) do { \
|
||||||
|
ARRAY_FREE(a); \
|
||||||
|
xfree(a); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif
|
||||||
89
attributes.c
89
attributes.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
||||||
@@ -23,31 +23,30 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
attributes_tostring(int attr)
|
attributes_tostring(u_char attr)
|
||||||
{
|
{
|
||||||
static char buf[512];
|
static char buf[128];
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (attr == 0)
|
if (attr == 0)
|
||||||
return ("none");
|
return ("none");
|
||||||
|
|
||||||
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
|
buf[0] = '\0';
|
||||||
(attr & GRID_ATTR_CHARSET) ? "acs," : "",
|
if (attr & GRID_ATTR_BRIGHT)
|
||||||
(attr & GRID_ATTR_BRIGHT) ? "bright," : "",
|
strlcat(buf, "bright,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_DIM) ? "dim," : "",
|
if (attr & GRID_ATTR_DIM)
|
||||||
(attr & GRID_ATTR_UNDERSCORE) ? "underscore," : "",
|
strlcat(buf, "dim,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_BLINK)? "blink," : "",
|
if (attr & GRID_ATTR_UNDERSCORE)
|
||||||
(attr & GRID_ATTR_REVERSE) ? "reverse," : "",
|
strlcat(buf, "underscore,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_HIDDEN) ? "hidden," : "",
|
if (attr & GRID_ATTR_BLINK)
|
||||||
(attr & GRID_ATTR_ITALICS) ? "italics," : "",
|
strlcat(buf, "blink,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : "",
|
if (attr & GRID_ATTR_REVERSE)
|
||||||
(attr & GRID_ATTR_UNDERSCORE_2) ? "double-underscore," : "",
|
strlcat(buf, "reverse,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_UNDERSCORE_3) ? "curly-underscore," : "",
|
if (attr & GRID_ATTR_HIDDEN)
|
||||||
(attr & GRID_ATTR_UNDERSCORE_4) ? "dotted-underscore," : "",
|
strlcat(buf, "hidden,", sizeof (buf));
|
||||||
(attr & GRID_ATTR_UNDERSCORE_5) ? "dashed-underscore," : "",
|
if (attr & GRID_ATTR_ITALICS)
|
||||||
(attr & GRID_ATTR_OVERLINE) ? "overline," : "");
|
strlcat(buf, "italics,", sizeof (buf));
|
||||||
if (len > 0)
|
if (*buf != '\0')
|
||||||
buf[len - 1] = '\0';
|
*(strrchr(buf, ',')) = '\0';
|
||||||
|
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
@@ -56,29 +55,8 @@ int
|
|||||||
attributes_fromstring(const char *str)
|
attributes_fromstring(const char *str)
|
||||||
{
|
{
|
||||||
const char delimiters[] = " ,|";
|
const char delimiters[] = " ,|";
|
||||||
int attr;
|
u_char attr;
|
||||||
size_t end;
|
size_t end;
|
||||||
u_int i;
|
|
||||||
struct {
|
|
||||||
const char *name;
|
|
||||||
int attr;
|
|
||||||
} table[] = {
|
|
||||||
{ "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)
|
if (*str == '\0' || strcspn(str, delimiters) == 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
@@ -91,15 +69,22 @@ attributes_fromstring(const char *str)
|
|||||||
attr = 0;
|
attr = 0;
|
||||||
do {
|
do {
|
||||||
end = strcspn(str, delimiters);
|
end = strcspn(str, delimiters);
|
||||||
for (i = 0; i < nitems(table); i++) {
|
if ((end == 6 && strncasecmp(str, "bright", end) == 0) ||
|
||||||
if (end != strlen(table[i].name))
|
(end == 4 && strncasecmp(str, "bold", end) == 0))
|
||||||
continue;
|
attr |= GRID_ATTR_BRIGHT;
|
||||||
if (strncasecmp(str, table[i].name, end) == 0) {
|
else if (end == 3 && strncasecmp(str, "dim", end) == 0)
|
||||||
attr |= table[i].attr;
|
attr |= GRID_ATTR_DIM;
|
||||||
break;
|
else if (end == 10 && strncasecmp(str, "underscore", end) == 0)
|
||||||
}
|
attr |= GRID_ATTR_UNDERSCORE;
|
||||||
}
|
else if (end == 5 && strncasecmp(str, "blink", end) == 0)
|
||||||
if (i == nitems(table))
|
attr |= GRID_ATTR_BLINK;
|
||||||
|
else if (end == 7 && strncasecmp(str, "reverse", end) == 0)
|
||||||
|
attr |= GRID_ATTR_REVERSE;
|
||||||
|
else if (end == 6 && strncasecmp(str, "hidden", end) == 0)
|
||||||
|
attr |= GRID_ATTR_HIDDEN;
|
||||||
|
else if (end == 7 && strncasecmp(str, "italics", end) == 0)
|
||||||
|
attr |= GRID_ATTR_ITALICS;
|
||||||
|
else
|
||||||
return (-1);
|
return (-1);
|
||||||
str += end + strspn(str + end, delimiters);
|
str += end + strspn(str + end, delimiters);
|
||||||
} while (*str != '\0');
|
} while (*str != '\0');
|
||||||
|
|||||||
7
autogen.sh
Executable file → Normal file
7
autogen.sh
Executable file → Normal file
@@ -1,9 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
# $Id$
|
||||||
|
|
||||||
if [ "x$(uname)" = "xOpenBSD" ]; then
|
[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.10
|
||||||
[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.15
|
[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.65
|
||||||
[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.69
|
|
||||||
fi
|
|
||||||
|
|
||||||
die()
|
die()
|
||||||
{
|
{
|
||||||
|
|||||||
330
cfg.c
330
cfg.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -17,261 +17,127 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
struct client *cfg_client;
|
/*
|
||||||
int cfg_finished;
|
* Config file parser. Pretty quick and simple, each line is parsed into a
|
||||||
static char **cfg_causes;
|
* argv array and executed as a command.
|
||||||
static u_int cfg_ncauses;
|
*/
|
||||||
static struct cmdq_item *cfg_item;
|
|
||||||
|
|
||||||
int cfg_quiet = 1;
|
void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
|
||||||
char **cfg_files;
|
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
|
||||||
u_int cfg_nfiles;
|
|
||||||
|
|
||||||
static enum cmd_retval
|
char *cfg_cause;
|
||||||
cfg_client_done(__unused struct cmdq_item *item, __unused void *data)
|
int cfg_finished;
|
||||||
|
struct causelist cfg_causes = ARRAY_INITIALIZER;
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void printflike2
|
||||||
|
cfg_print(unused struct cmd_ctx *ctx, unused const char *fmt, ...)
|
||||||
{
|
{
|
||||||
if (!cfg_finished)
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
/* ARGSUSED */
|
||||||
cfg_done(__unused struct cmdq_item *item, __unused void *data)
|
void printflike2
|
||||||
|
cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
if (cfg_finished)
|
va_list ap;
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
cfg_finished = 1;
|
|
||||||
|
|
||||||
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_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
xvasprintf(&msg, fmt, ap);
|
xvasprintf(&cfg_cause, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printflike2
|
||||||
|
cfg_add_cause(struct causelist *causes, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char *cause;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
xvasprintf(&cause, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
cfg_ncauses++;
|
ARRAY_ADD(causes, cause);
|
||||||
cfg_causes = xreallocarray(cfg_causes, cfg_ncauses, sizeof *cfg_causes);
|
|
||||||
cfg_causes[cfg_ncauses - 1] = msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/*
|
||||||
cfg_print_causes(struct cmdq_item *item)
|
* Load configuration file. Returns -1 for an error with a list of messages in
|
||||||
|
* causes. Note that causes must be initialised by the caller!
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
||||||
{
|
{
|
||||||
u_int i;
|
FILE *f;
|
||||||
|
u_int n;
|
||||||
|
char *buf, *line, *cause;
|
||||||
|
size_t len;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
int retval;
|
||||||
|
|
||||||
for (i = 0; i < cfg_ncauses; i++) {
|
if ((f = fopen(path, "rb")) == NULL) {
|
||||||
cmdq_print(item, "%s", cfg_causes[i]);
|
cfg_add_cause(causes, "%s: %s", path, strerror(errno));
|
||||||
free(cfg_causes[i]);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
n = 0;
|
||||||
|
|
||||||
free(cfg_causes);
|
line = NULL;
|
||||||
cfg_causes = NULL;
|
retval = 0;
|
||||||
cfg_ncauses = 0;
|
while ((buf = fgetln(f, &len))) {
|
||||||
}
|
if (buf[len - 1] == '\n')
|
||||||
|
buf[len - 1] = '\0';
|
||||||
void
|
else {
|
||||||
cfg_show_causes(struct session *s)
|
line = xrealloc(line, 1, len + 1);
|
||||||
{
|
memcpy(line, buf, len);
|
||||||
struct client *c = TAILQ_FIRST(&clients);
|
line[len] = '\0';
|
||||||
struct window_pane *wp;
|
buf = line;
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
goto out;
|
n++;
|
||||||
}
|
|
||||||
|
|
||||||
if (s == NULL) {
|
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
|
||||||
if (c != NULL && c->session != NULL)
|
if (cause == NULL)
|
||||||
s = c->session;
|
continue;
|
||||||
else
|
cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
|
||||||
s = RB_MIN(sessions, &sessions);
|
xfree(cause);
|
||||||
}
|
continue;
|
||||||
if (s == NULL || s->attached == 0) /* wait for an attached session */
|
}
|
||||||
return;
|
if (cmdlist == NULL)
|
||||||
wp = s->curw->window->active;
|
continue;
|
||||||
|
cfg_cause = NULL;
|
||||||
|
|
||||||
wme = TAILQ_FIRST(&wp->modes);
|
if (ctxin == NULL) {
|
||||||
if (wme == NULL || wme->mode != &window_view_mode)
|
ctx.msgdata = NULL;
|
||||||
window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
|
ctx.curclient = NULL;
|
||||||
for (i = 0; i < cfg_ncauses; i++) {
|
ctx.cmdclient = NULL;
|
||||||
window_copy_add(wp, 0, "%s", cfg_causes[i]);
|
} else {
|
||||||
free(cfg_causes[i]);
|
ctx.msgdata = ctxin->msgdata;
|
||||||
}
|
ctx.curclient = ctxin->curclient;
|
||||||
|
ctx.cmdclient = ctxin->cmdclient;
|
||||||
|
}
|
||||||
|
|
||||||
out:
|
ctx.error = cfg_error;
|
||||||
free(cfg_causes);
|
ctx.print = cfg_print;
|
||||||
cfg_causes = NULL;
|
ctx.info = cfg_print;
|
||||||
cfg_ncauses = 0;
|
|
||||||
|
cfg_cause = NULL;
|
||||||
|
if (cmd_list_exec(cmdlist, &ctx) == 1)
|
||||||
|
retval = 1;
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
if (cfg_cause != NULL) {
|
||||||
|
cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
|
||||||
|
xfree(cfg_cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (line != NULL)
|
||||||
|
xfree(line);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return (retval);
|
||||||
}
|
}
|
||||||
|
|||||||
159
clock.c
Normal file
159
clock.c
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
const char clock_table[14][5][5] = {
|
||||||
|
{ { 1,1,1,1,1 }, /* 0 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 0,0,0,0,1 }, /* 1 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 2 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 3 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,0,0,0,1 }, /* 4 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 5 */
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 6 */
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 7 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 8 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 9 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 0,0,0,0,0 }, /* : */
|
||||||
|
{ 0,0,1,0,0 },
|
||||||
|
{ 0,0,0,0,0 },
|
||||||
|
{ 0,0,1,0,0 },
|
||||||
|
{ 0,0,0,0,0 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* A */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* P */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,0,0,0,0 } },
|
||||||
|
{ { 1,0,0,0,1 }, /* M */
|
||||||
|
{ 1,1,0,1,1 },
|
||||||
|
{ 1,0,1,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 } },
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
clock_draw(struct screen_write_ctx *ctx, int colour, int style)
|
||||||
|
{
|
||||||
|
struct screen *s = ctx->s;
|
||||||
|
struct grid_cell gc;
|
||||||
|
char tim[64], *ptr;
|
||||||
|
time_t t;
|
||||||
|
u_int i, j, x, y, idx;
|
||||||
|
|
||||||
|
t = time(NULL);
|
||||||
|
if (style == 0)
|
||||||
|
strftime(tim, sizeof tim, "%l:%M %p", localtime(&t));
|
||||||
|
else
|
||||||
|
strftime(tim, sizeof tim, "%H:%M", localtime(&t));
|
||||||
|
|
||||||
|
screen_write_clearscreen(ctx);
|
||||||
|
|
||||||
|
if (screen_size_x(s) < 6 * strlen(tim) || screen_size_y(s) < 6) {
|
||||||
|
if (screen_size_x(s) >= strlen(tim) && screen_size_y(s) != 0) {
|
||||||
|
x = (screen_size_x(s) / 2) - (strlen(tim) / 2);
|
||||||
|
y = screen_size_y(s) / 2;
|
||||||
|
screen_write_cursormove(ctx, x, y);
|
||||||
|
|
||||||
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||||
|
colour_set_fg(&gc, colour);
|
||||||
|
screen_write_puts(ctx, &gc, "%s", tim);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = (screen_size_x(s) / 2) - 3 * strlen(tim);
|
||||||
|
y = (screen_size_y(s) / 2) - 3;
|
||||||
|
|
||||||
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||||
|
colour_set_bg(&gc, colour);
|
||||||
|
for (ptr = tim; *ptr != '\0'; ptr++) {
|
||||||
|
if (*ptr >= '0' && *ptr <= '9')
|
||||||
|
idx = *ptr - '0';
|
||||||
|
else if (*ptr == ':')
|
||||||
|
idx = 10;
|
||||||
|
else if (*ptr == 'A')
|
||||||
|
idx = 11;
|
||||||
|
else if (*ptr == 'P')
|
||||||
|
idx = 12;
|
||||||
|
else if (*ptr == 'M')
|
||||||
|
idx = 13;
|
||||||
|
else {
|
||||||
|
x += 6;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < 5; j++) {
|
||||||
|
for (i = 0; i < 5; i++) {
|
||||||
|
screen_write_cursormove(ctx, x + i, y + j);
|
||||||
|
if (clock_table[idx][j][i])
|
||||||
|
screen_write_putc(ctx, &gc, ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x += 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,158 +18,95 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attach existing session to the current terminal.
|
* Attach existing session to the current terminal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_attach_session_exec(struct cmd *,
|
int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_attach_session_entry = {
|
const struct cmd_entry cmd_attach_session_entry = {
|
||||||
.name = "attach-session",
|
"attach-session", "attach",
|
||||||
.alias = "attach",
|
"drt:", 0, 0,
|
||||||
|
"[-dr] " CMD_TARGET_SESSION_USAGE,
|
||||||
.args = { "c:dEf:rt:x", 0, 0, NULL },
|
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON,
|
||||||
.usage = "[-dErx] [-c working-directory] [-f flags] "
|
NULL,
|
||||||
CMD_TARGET_SESSION_USAGE,
|
NULL,
|
||||||
|
cmd_attach_session_exec
|
||||||
/* -t is special */
|
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER|CMD_READONLY,
|
|
||||||
.exec = cmd_attach_session_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
int
|
||||||
cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
int xflag, int rflag, const char *cflag, int Eflag, const char *fflag)
|
|
||||||
{
|
{
|
||||||
struct cmd_find_state *current = cmdq_get_current(item);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state target;
|
struct session *s;
|
||||||
enum cmd_find_type type;
|
struct client *c;
|
||||||
int flags;
|
const char *update;
|
||||||
struct client *c = cmdq_get_client(item), *c_loop;
|
char *overrides, *cause;
|
||||||
struct session *s;
|
u_int i;
|
||||||
struct winlink *wl;
|
|
||||||
struct window_pane *wp;
|
|
||||||
char *cwd, *cause;
|
|
||||||
enum msgtype msgtype;
|
|
||||||
|
|
||||||
if (RB_EMPTY(&sessions)) {
|
if (RB_EMPTY(&sessions)) {
|
||||||
cmdq_error(item, "no sessions");
|
ctx->error(ctx, "no sessions");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == NULL)
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (-1);
|
||||||
|
|
||||||
if (server_client_check_nested(c)) {
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||||
cmdq_error(item, "sessions should be nested with care, "
|
return (0);
|
||||||
"unset $TMUX to force");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') {
|
if (ctx->cmdclient == NULL) {
|
||||||
type = CMD_FIND_PANE;
|
if (args_has(self->args, 'd')) {
|
||||||
flags = 0;
|
/*
|
||||||
} else {
|
* Can't use server_write_session in case attaching to
|
||||||
type = CMD_FIND_SESSION;
|
* the same session as currently attached to.
|
||||||
flags = CMD_FIND_PREFER_UNATTACHED;
|
*/
|
||||||
}
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
if (cmd_find_target(&target, item, tflag, type, flags) != 0)
|
c = ARRAY_ITEM(&clients, i);
|
||||||
return (CMD_RETURN_ERROR);
|
if (c == NULL || c->session != s)
|
||||||
s = target.s;
|
|
||||||
wl = target.wl;
|
|
||||||
wp = target.wp;
|
|
||||||
|
|
||||||
if (wl != NULL) {
|
|
||||||
if (wp != NULL)
|
|
||||||
window_set_active_pane(wp->window, wp, 1);
|
|
||||||
session_set_current(s, wl);
|
|
||||||
if (wp != NULL)
|
|
||||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
|
||||||
else
|
|
||||||
cmd_find_from_winlink(current, wl, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cflag != NULL) {
|
|
||||||
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;
|
continue;
|
||||||
server_client_detach(c_loop, msgtype);
|
if (c == ctx->curclient)
|
||||||
|
continue;
|
||||||
|
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Eflag)
|
|
||||||
environ_update(s->options, c->environ, s->environ);
|
|
||||||
|
|
||||||
server_client_set_session(c, s);
|
ctx->curclient->session = s;
|
||||||
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
session_update_activity(s);
|
||||||
server_client_set_key_table(c, NULL);
|
server_redraw_client(ctx->curclient);
|
||||||
} else {
|
} else {
|
||||||
if (server_client_open(c, &cause) != 0) {
|
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||||
cmdq_error(item, "open terminal failed: %s", cause);
|
ctx->error(ctx, "not a terminal");
|
||||||
free(cause);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dflag || xflag) {
|
overrides =
|
||||||
if (xflag)
|
options_get_string(&s->options, "terminal-overrides");
|
||||||
msgtype = MSG_DETACHKILL;
|
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||||
else
|
ctx->error(ctx, "terminal open failed: %s", cause);
|
||||||
msgtype = MSG_DETACH;
|
xfree(cause);
|
||||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
return (-1);
|
||||||
if (c_loop->session != s || c == c_loop)
|
|
||||||
continue;
|
|
||||||
server_client_detach(c_loop, msgtype);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!Eflag)
|
|
||||||
environ_update(s->options, c->environ, s->environ);
|
|
||||||
|
|
||||||
server_client_set_session(c, s);
|
if (args_has(self->args, 'r'))
|
||||||
server_client_set_key_table(c, NULL);
|
ctx->cmdclient->flags |= CLIENT_READONLY;
|
||||||
|
|
||||||
if (~c->flags & CLIENT_CONTROL)
|
if (args_has(self->args, 'd'))
|
||||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
server_write_session(s, MSG_DETACH, NULL, 0);
|
||||||
notify_client("client-attached", c);
|
|
||||||
c->flags |= CLIENT_ATTACHED;
|
ctx->cmdclient->session = s;
|
||||||
|
session_update_activity(s);
|
||||||
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
|
|
||||||
|
update = options_get_string(&s->options, "update-environment");
|
||||||
|
environ_update(update, &ctx->cmdclient->environ, &s->environ);
|
||||||
|
|
||||||
|
server_redraw_client(ctx->cmdclient);
|
||||||
}
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
server_update_socket();
|
||||||
|
|
||||||
if (cfg_finished)
|
return (1); /* 1 means don't tell command client to exit */
|
||||||
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')));
|
|
||||||
}
|
}
|
||||||
|
|||||||
147
cmd-bind-key.c
147
cmd-bind-key.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,90 +18,103 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bind a key to a command.
|
* Bind a key to a command, this recurses through cmd_*.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum args_parse_type cmd_bind_key_args_parse(struct args *, u_int,
|
int cmd_bind_key_check(struct args *);
|
||||||
char **);
|
int cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
|
||||||
static enum cmd_retval cmd_bind_key_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
int cmd_bind_key_table(struct cmd *, struct cmd_ctx *, int);
|
||||||
|
|
||||||
const struct cmd_entry cmd_bind_key_entry = {
|
const struct cmd_entry cmd_bind_key_entry = {
|
||||||
.name = "bind-key",
|
"bind-key", "bind",
|
||||||
.alias = "bind",
|
"cnrt:", 1, -1,
|
||||||
|
"[-cnr] [-t key-table] key command [arguments]",
|
||||||
.args = { "nrN:T:", 1, -1, cmd_bind_key_args_parse },
|
0,
|
||||||
.usage = "[-nr] [-T key-table] [-N note] key "
|
NULL,
|
||||||
"[command [arguments]]",
|
cmd_bind_key_check,
|
||||||
|
cmd_bind_key_exec
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_bind_key_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum args_parse_type
|
int
|
||||||
cmd_bind_key_args_parse(__unused struct args *args, __unused u_int idx,
|
cmd_bind_key_check(struct args *args)
|
||||||
__unused char **cause)
|
|
||||||
{
|
{
|
||||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
if (args_has(args, 't')) {
|
||||||
|
if (args->argc != 2)
|
||||||
|
return (-1);
|
||||||
|
} else {
|
||||||
|
if (args->argc < 2)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
key_code key;
|
char *cause;
|
||||||
const char *tablename, *note = args_get(args, 'N');
|
struct cmd_list *cmdlist;
|
||||||
struct cmd_parse_result *pr;
|
int key;
|
||||||
int repeat;
|
|
||||||
struct args_value *value;
|
|
||||||
u_int count = args_count(args);
|
|
||||||
|
|
||||||
key = key_string_lookup_string(args_string(args, 0));
|
key = key_string_lookup_string(args->argv[0]);
|
||||||
if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
|
if (key == KEYC_NONE) {
|
||||||
cmdq_error(item, "unknown key: %s", args_string(args, 0));
|
ctx->error(ctx, "unknown key: %s", args->argv[0]);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'T'))
|
if (args_has(args, 't'))
|
||||||
tablename = args_get(args, 'T');
|
return (cmd_bind_key_table(self, ctx, key));
|
||||||
else if (args_has(args, 'n'))
|
|
||||||
tablename = "root";
|
|
||||||
else
|
|
||||||
tablename = "prefix";
|
|
||||||
repeat = args_has(args, 'r');
|
|
||||||
|
|
||||||
if (count == 1) {
|
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, &cause);
|
||||||
key_bindings_add(tablename, key, note, repeat, NULL);
|
if (cmdlist == NULL) {
|
||||||
return (CMD_RETURN_NORMAL);
|
ctx->error(ctx, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = args_value(args, 1);
|
if (!args_has(args, 'n'))
|
||||||
if (count == 2 && value->type == ARGS_COMMANDS) {
|
key |= KEYC_PREFIX;
|
||||||
key_bindings_add(tablename, key, note, repeat, value->cmdlist);
|
key_bindings_add(key, args_has(args, 'r'), cmdlist);
|
||||||
value->cmdlist->references++;
|
return (0);
|
||||||
return (CMD_RETURN_NORMAL);
|
}
|
||||||
}
|
|
||||||
|
int
|
||||||
if (count == 2)
|
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
|
||||||
pr = cmd_parse_from_string(args_string(args, 1), NULL);
|
{
|
||||||
else {
|
struct args *args = self->args;
|
||||||
pr = cmd_parse_from_arguments(args_values(args) + 1, count - 1,
|
const char *tablename;
|
||||||
NULL);
|
const struct mode_key_table *mtab;
|
||||||
}
|
struct mode_key_binding *mbind, mtmp;
|
||||||
switch (pr->status) {
|
enum mode_key_cmd cmd;
|
||||||
case CMD_PARSE_ERROR:
|
|
||||||
cmdq_error(item, "%s", pr->error);
|
tablename = args_get(args, 't');
|
||||||
free(pr->error);
|
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||||
return (CMD_RETURN_ERROR);
|
ctx->error(ctx, "unknown key table: %s", tablename);
|
||||||
case CMD_PARSE_SUCCESS:
|
return (-1);
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
key_bindings_add(tablename, key, note, repeat, pr->cmdlist);
|
cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
|
||||||
return (CMD_RETURN_NORMAL);
|
if (cmd == MODEKEY_NONE) {
|
||||||
|
ctx->error(ctx, "unknown command: %s", args->argv[1]);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mtmp.key = key;
|
||||||
|
mtmp.mode = !!args_has(args, 'c');
|
||||||
|
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||||
|
mbind->cmd = cmd;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
mbind = xmalloc(sizeof *mbind);
|
||||||
|
mbind->key = mtmp.key;
|
||||||
|
mbind->mode = mtmp.mode;
|
||||||
|
mbind->cmd = cmd;
|
||||||
|
SPLAY_INSERT(mode_key_tree, mtab->tree, mbind);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
144
cmd-break-pane.c
144
cmd-break-pane.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -26,118 +26,64 @@
|
|||||||
* Break pane off into a window.
|
* Break pane off into a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_break_pane_entry = {
|
const struct cmd_entry cmd_break_pane_entry = {
|
||||||
.name = "break-pane",
|
"break-pane", "breakp",
|
||||||
.alias = "breakp",
|
"dt:", 0, 0,
|
||||||
|
"[-d] " CMD_TARGET_PANE_USAGE,
|
||||||
.args = { "abdPF:n:s:t:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-abdP] [-F format] [-n window-name] [-s src-pane] "
|
NULL,
|
||||||
"[-t dst-window]",
|
NULL,
|
||||||
|
cmd_break_pane_exec
|
||||||
.source = { 's', CMD_FIND_PANE, 0 },
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_break_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *current = cmdq_get_current(item);
|
struct winlink *wl;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct session *s;
|
||||||
struct cmd_find_state *source = cmdq_get_source(item);
|
struct window_pane *wp;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct window *w;
|
||||||
struct winlink *wl = source->wl;
|
char *cause;
|
||||||
struct session *src_s = source->s;
|
int base_idx;
|
||||||
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;
|
|
||||||
|
|
||||||
before = args_has(args, 'b');
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
||||||
if (args_has(args, 'a') || before) {
|
return (-1);
|
||||||
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 (window_count_panes(wl->window) == 1) {
|
||||||
if (server_link_window(src_s, wl, dst_s, idx, 0,
|
ctx->error(ctx, "can't break with only one pane");
|
||||||
!args_has(args, 'd'), &cause) != 0) {
|
return (-1);
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) {
|
|
||||||
cmdq_error(item, "index in use: %d", idx);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w = wl->window;
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
server_client_remove_pane(wp);
|
if (wp == w->active) {
|
||||||
window_lost_pane(w, wp);
|
w->active = w->last;
|
||||||
|
w->last = NULL;
|
||||||
|
if (w->active == NULL) {
|
||||||
|
w->active = TAILQ_PREV(wp, window_panes, entry);
|
||||||
|
if (w->active == NULL)
|
||||||
|
w->active = TAILQ_NEXT(wp, entry);
|
||||||
|
}
|
||||||
|
} else if (wp == w->last)
|
||||||
|
w->last = NULL;
|
||||||
layout_close_pane(wp);
|
layout_close_pane(wp);
|
||||||
|
|
||||||
w = wp->window = window_create(w->sx, w->sy, w->xpixel, w->ypixel);
|
w = wp->window = window_create1(s->sx, s->sy);
|
||||||
options_set_parent(wp->options, w->options);
|
|
||||||
wp->flags |= PANE_STYLECHANGED;
|
|
||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
w->active = wp;
|
w->active = wp;
|
||||||
w->latest = tc;
|
w->name = default_window_name(w);
|
||||||
|
layout_init(w);
|
||||||
|
|
||||||
if (!args_has(args, 'n')) {
|
base_idx = options_get_number(&s->options, "base-index");
|
||||||
name = default_window_name(w);
|
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
|
||||||
window_set_name(w, name);
|
if (!args_has(self->args, 'd'))
|
||||||
free(name);
|
session_select(s, wl->idx);
|
||||||
} else {
|
|
||||||
window_set_name(w, args_get(args, 'n'));
|
|
||||||
options_set_number(w->options, "automatic-rename", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
layout_init(w, wp);
|
server_redraw_session(s);
|
||||||
wp->flags |= PANE_CHANGED;
|
server_status_session_group(s);
|
||||||
colour_palette_from_option(&wp->palette, wp->options);
|
|
||||||
|
|
||||||
if (idx == -1)
|
return (0);
|
||||||
idx = -1 - options_get_number(dst_s->options, "base-index");
|
|
||||||
wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
|
|
||||||
if (!args_has(args, 'd')) {
|
|
||||||
session_select(dst_s, wl->idx);
|
|
||||||
cmd_find_from_session(current, dst_s, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
server_redraw_session(src_s);
|
|
||||||
if (src_s != dst_s)
|
|
||||||
server_redraw_session(dst_s);
|
|
||||||
server_status_session_group(src_s);
|
|
||||||
if (src_s != dst_s)
|
|
||||||
server_status_session_group(dst_s);
|
|
||||||
|
|
||||||
if (args_has(args, 'P')) {
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = BREAK_PANE_TEMPLATE;
|
|
||||||
cp = format_single(item, template, tc, dst_s, wl, wp);
|
|
||||||
cmdq_print(item, "%s", cp);
|
|
||||||
free(cp);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
|
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
|
||||||
@@ -24,144 +24,62 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write the entire contents of a pane to a buffer or stdout.
|
* Write the entire contents of a pane to a buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmdq_item *);
|
int cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
|
|
||||||
static char *cmd_capture_pane_pending(struct args *, struct window_pane *,
|
|
||||||
size_t *);
|
|
||||||
static char *cmd_capture_pane_history(struct args *, struct cmdq_item *,
|
|
||||||
struct window_pane *, size_t *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_capture_pane_entry = {
|
const struct cmd_entry cmd_capture_pane_entry = {
|
||||||
.name = "capture-pane",
|
"capture-pane", "capturep",
|
||||||
.alias = "capturep",
|
"b:E:S:t:", 0, 0,
|
||||||
|
"[-b buffer-index] [-E end-line] [-S start-line] [-t target-pane]",
|
||||||
.args = { "ab:CeE:JNpPqS:Tt:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-aCeJNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
|
NULL,
|
||||||
"[-S start-line] " CMD_TARGET_PANE_USAGE,
|
NULL,
|
||||||
|
cmd_capture_pane_exec
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_capture_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_clear_history_entry = {
|
int
|
||||||
.name = "clear-history",
|
cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "clearhist",
|
|
||||||
|
|
||||||
.args = { "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 args *args = self->args;
|
||||||
|
struct window_pane *wp;
|
||||||
|
char *buf, *line, *cause;
|
||||||
|
struct screen *s;
|
||||||
struct grid *gd;
|
struct grid *gd;
|
||||||
const struct grid_line *gl;
|
int buffer, n;
|
||||||
struct grid_cell *gc = NULL;
|
u_int i, limit, top, bottom, tmp;
|
||||||
int n, join_lines, flags = 0;
|
size_t len, linelen;
|
||||||
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 (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
if (args_has(args, 'a')) {
|
return (-1);
|
||||||
gd = wp->base.saved_grid;
|
s = &wp->base;
|
||||||
if (gd == NULL) {
|
gd = s->grid;
|
||||||
if (!args_has(args, 'q')) {
|
|
||||||
cmdq_error(item, "no alternate screen");
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
return (xstrdup(""));
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
gd = wp->base.grid;
|
|
||||||
|
|
||||||
Sflag = args_get(args, 'S');
|
buf = NULL;
|
||||||
if (Sflag != NULL && strcmp(Sflag, "-") == 0)
|
len = 0;
|
||||||
|
|
||||||
|
n = args_strtonum(args, 'S', SHRT_MIN, SHRT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
top = gd->hsize;
|
||||||
|
xfree(cause);
|
||||||
|
} else if (n < 0 && (u_int) -n > gd->hsize)
|
||||||
top = 0;
|
top = 0;
|
||||||
else {
|
else
|
||||||
n = args_strtonum_and_expand(args, 'S', INT_MIN, SHRT_MAX,
|
top = gd->hsize + n;
|
||||||
item, &cause);
|
if (top > gd->hsize + gd->sy - 1)
|
||||||
if (cause != NULL) {
|
top = gd->hsize + gd->sy - 1;
|
||||||
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');
|
n = args_strtonum(args, 'E', SHRT_MIN, SHRT_MAX, &cause);
|
||||||
if (Eflag != NULL && strcmp(Eflag, "-") == 0)
|
if (cause != NULL) {
|
||||||
|
bottom = gd->hsize + gd->sy - 1;
|
||||||
|
xfree(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;
|
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) {
|
if (bottom < top) {
|
||||||
tmp = bottom;
|
tmp = bottom;
|
||||||
@@ -169,85 +87,37 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
|||||||
top = tmp;
|
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++) {
|
for (i = top; i <= bottom; i++) {
|
||||||
line = grid_string_cells(gd, 0, i, sx, &gc, flags, wp->screen);
|
line = grid_string_cells(s->grid, 0, i, screen_size_x(s));
|
||||||
linelen = strlen(line);
|
linelen = strlen(line);
|
||||||
|
|
||||||
buf = cmd_capture_pane_append(buf, len, line, linelen);
|
buf = xrealloc(buf, 1, len + linelen + 1);
|
||||||
|
memcpy(buf + len, line, linelen);
|
||||||
|
len += linelen;
|
||||||
|
buf[len++] = '\n';
|
||||||
|
|
||||||
gl = grid_peek_line(gd, i);
|
xfree(line);
|
||||||
if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED))
|
|
||||||
buf[(*len)++] = '\n';
|
|
||||||
|
|
||||||
free(line);
|
|
||||||
}
|
}
|
||||||
return (buf);
|
|
||||||
}
|
limit = options_get_number(&global_options, "buffer-limit");
|
||||||
|
|
||||||
static enum cmd_retval
|
if (!args_has(args, 'b')) {
|
||||||
cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
|
paste_add(&global_buffers, buf, len, limit);
|
||||||
{
|
return (0);
|
||||||
struct args *args = cmd_get_args(self);
|
}
|
||||||
struct client *c = cmdq_get_client(item);
|
|
||||||
struct window_pane *wp = cmdq_get_target(item)->wp;
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
char *buf, *cause;
|
if (cause != NULL) {
|
||||||
const char *bufname;
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
size_t len;
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
if (cmd_get_entry(self) == &cmd_clear_history_entry) {
|
}
|
||||||
window_pane_reset_mode_all(wp);
|
|
||||||
grid_clear_history(wp->base.grid);
|
if (paste_replace(&global_buffers, buffer, buf, len) != 0) {
|
||||||
if (args_has(args, 'H'))
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
screen_reset_hyperlinks(wp->screen);
|
xfree(buf);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
len = 0;
|
return (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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
143
cmd-choose-buffer.c
Normal file
143
cmd-choose-buffer.c
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_buffer_callback(void *, int);
|
||||||
|
void cmd_choose_buffer_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_buffer_entry = {
|
||||||
|
"choose-buffer", NULL,
|
||||||
|
"t:", 0, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_choose_buffer_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_buffer_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_choose_buffer_data *cdata;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
u_int idx;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (paste_get_top(&global_buffers) == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
idx = 0;
|
||||||
|
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
|
||||||
|
tmp = paste_print(pb, 50);
|
||||||
|
window_choose_add(wl->window->active, idx - 1,
|
||||||
|
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||||
|
xfree(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (args->argc != 0)
|
||||||
|
cdata->template = xstrdup(args->argv[0]);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("paste-buffer -b '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
0, cmd_choose_buffer_callback, cmd_choose_buffer_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_buffer_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_buffer_data *cdata = data;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause, tmp[16];
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xsnprintf(tmp, sizeof tmp, "%u", idx);
|
||||||
|
template = cmd_template_replace(cdata->template, tmp, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_buffer_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_buffer_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
151
cmd-choose-client.c
Normal file
151
cmd-choose-client.c
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_client_callback(void *, int);
|
||||||
|
void cmd_choose_client_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_client_entry = {
|
||||||
|
"choose-client", NULL,
|
||||||
|
"t:", 0, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_choose_client_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_client_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_choose_client_data *cdata;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct client *c;
|
||||||
|
u_int i, idx, cur;
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
cur = idx = 0;
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
continue;
|
||||||
|
if (c == ctx->curclient)
|
||||||
|
cur = idx;
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active, i,
|
||||||
|
"%s: %s [%ux%u %s]%s", c->tty.path,
|
||||||
|
c->session->name, c->tty.sx, c->tty.sy,
|
||||||
|
c->tty.termname, c->tty.flags & TTY_UTF8 ? " (utf8)" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (args->argc != 0)
|
||||||
|
cdata->template = xstrdup(args->argv[0]);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("detach-client -t '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_client_callback, cmd_choose_client_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_client_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_client_data *cdata = data;
|
||||||
|
struct client *c;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ((u_int) idx > ARRAY_LENGTH(&clients) - 1)
|
||||||
|
return;
|
||||||
|
c = ARRAY_ITEM(&clients, idx);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
return;
|
||||||
|
template = cmd_template_replace(cdata->template, c->tty.path, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(c, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_client_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_client_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
156
cmd-choose-session.c
Normal file
156
cmd-choose-session.c
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_session_callback(void *, int);
|
||||||
|
void cmd_choose_session_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_session_entry = {
|
||||||
|
"choose-session", NULL,
|
||||||
|
"t:", 0, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_choose_session_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_session_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_choose_session_data *cdata;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct session *s;
|
||||||
|
struct session_group *sg;
|
||||||
|
u_int idx, sgidx, cur;
|
||||||
|
char tmp[64];
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
cur = idx = 0;
|
||||||
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
|
if (s == ctx->curclient->session)
|
||||||
|
cur = idx;
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
sg = session_group_find(s);
|
||||||
|
if (sg == NULL)
|
||||||
|
*tmp = '\0';
|
||||||
|
else {
|
||||||
|
sgidx = session_group_index(sg);
|
||||||
|
xsnprintf(tmp, sizeof tmp, " (group %u)", sgidx);
|
||||||
|
}
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active, s->idx,
|
||||||
|
"%s: %u windows [%ux%u]%s%s", s->name,
|
||||||
|
winlink_count(&s->windows), s->sx, s->sy,
|
||||||
|
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (args->argc != 0)
|
||||||
|
cdata->template = xstrdup(args->argv[0]);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("switch-client -t '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_session_callback, cmd_choose_session_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_session_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_session_data *cdata = data;
|
||||||
|
struct session *s;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
s = session_find_by_index(idx);
|
||||||
|
if (s == NULL)
|
||||||
|
return;
|
||||||
|
template = cmd_template_replace(cdata->template, s->name, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_session_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_session_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
@@ -1,117 +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:wZ", 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:Z", 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:Z", 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:Z", 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;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
169
cmd-choose-window.c
Normal file
169
cmd-choose-window.c
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_window_callback(void *, int);
|
||||||
|
void cmd_choose_window_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_window_entry = {
|
||||||
|
"choose-window", NULL,
|
||||||
|
"t:", 0, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_choose_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_window_data {
|
||||||
|
struct client *client;
|
||||||
|
struct session *session;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_choose_window_data *cdata;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl, *wm;
|
||||||
|
struct window *w;
|
||||||
|
u_int idx, cur;
|
||||||
|
char *flags, *title;
|
||||||
|
const char *left, *right;
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), 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++;
|
||||||
|
|
||||||
|
flags = window_printable_flags(s, wm);
|
||||||
|
title = w->active->screen->title;
|
||||||
|
if (wm == wl)
|
||||||
|
title = w->active->base.title;
|
||||||
|
left = " \"";
|
||||||
|
right = "\"";
|
||||||
|
if (*title == '\0')
|
||||||
|
left = right = "";
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active,
|
||||||
|
wm->idx, "%3d: %s%s [%ux%u] (%u panes%s)%s%s%s",
|
||||||
|
wm->idx, w->name, flags, w->sx, w->sy, window_count_panes(w),
|
||||||
|
w->active->fd == -1 ? ", dead" : "",
|
||||||
|
left, title, right);
|
||||||
|
|
||||||
|
xfree(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (args->argc != 0)
|
||||||
|
cdata->template = xstrdup(args->argv[0]);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("select-window -t '%%'");
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_window_callback, cmd_choose_window_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_window_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_window_data *cdata = data;
|
||||||
|
struct session *s = cdata->session;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *target, *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (!session_alive(s))
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xasprintf(&target, "%s:%d", s->name, idx);
|
||||||
|
template = cmd_template_replace(cdata->template, target, 1);
|
||||||
|
xfree(target);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_window_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_window_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->session->references--;
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
||||||
54
cmd-clear-history.c
Normal file
54
cmd-clear-history.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_clear_history_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct grid *gd;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
gd = wp->base.grid;
|
||||||
|
|
||||||
|
grid_move_lines(gd, 0, gd->hsize, gd->sy);
|
||||||
|
gd->hsize = 0;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -16,33 +18,34 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <glob.h>
|
#include "tmux.h"
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "compat.h"
|
/*
|
||||||
|
* Enter clock mode.
|
||||||
|
*/
|
||||||
|
|
||||||
void fatal(const char *, ...);
|
int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
void fatalx(const char *, ...);
|
|
||||||
|
const struct cmd_entry cmd_clock_mode_entry = {
|
||||||
|
"clock-mode", NULL,
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_clock_mode_exec
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef HAVE_PROC_PID
|
|
||||||
int
|
int
|
||||||
getdtablecount(void)
|
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
struct args *args = self->args;
|
||||||
glob_t g;
|
struct window_pane *wp;
|
||||||
int n = 0;
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
window_pane_set_mode(wp, &window_clock_mode);
|
||||||
|
|
||||||
if (snprintf(path, sizeof path, "/proc/%ld/fd/*", (long)getpid()) < 0)
|
|
||||||
fatal("snprintf overflow");
|
|
||||||
if (glob(path, 0, NULL, &g) == 0)
|
|
||||||
n = g.gl_pathc;
|
|
||||||
globfree(&g);
|
|
||||||
return (n);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
int
|
|
||||||
getdtablecount(void)
|
|
||||||
{
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@@ -29,213 +28,188 @@
|
|||||||
* Prompt for command in client.
|
* Prompt for command in client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum args_parse_type cmd_command_prompt_args_parse(struct args *,
|
void cmd_command_prompt_key_binding(struct cmd *, int);
|
||||||
u_int, char **);
|
int cmd_command_prompt_check(struct args *);
|
||||||
static enum cmd_retval cmd_command_prompt_exec(struct cmd *,
|
int cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
static int cmd_command_prompt_callback(struct client *, void *,
|
int cmd_command_prompt_callback(void *, const char *);
|
||||||
const char *, int);
|
void cmd_command_prompt_free(void *);
|
||||||
static void cmd_command_prompt_free(void *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_command_prompt_entry = {
|
const struct cmd_entry cmd_command_prompt_entry = {
|
||||||
.name = "command-prompt",
|
"command-prompt", NULL,
|
||||||
.alias = NULL,
|
"I:p:t:", 0, 1,
|
||||||
|
"[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " [template]",
|
||||||
.args = { "1bFkiI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
|
0,
|
||||||
.usage = "[-1bFkiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
|
cmd_command_prompt_key_binding,
|
||||||
" [-T type] [template]",
|
NULL,
|
||||||
|
cmd_command_prompt_exec
|
||||||
.flags = CMD_CLIENT_TFLAG,
|
|
||||||
.exec = cmd_command_prompt_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cmd_command_prompt_prompt {
|
|
||||||
char *input;
|
|
||||||
char *prompt;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_command_prompt_cdata {
|
struct cmd_command_prompt_cdata {
|
||||||
struct cmdq_item *item;
|
struct client *c;
|
||||||
struct args_command_state *state;
|
char *inputs;
|
||||||
|
char *next_input;
|
||||||
int flags;
|
char *next_prompt;
|
||||||
enum prompt_type prompt_type;
|
char *prompts;
|
||||||
|
char *template;
|
||||||
struct cmd_command_prompt_prompt *prompts;
|
int idx;
|
||||||
u_int count;
|
|
||||||
u_int current;
|
|
||||||
|
|
||||||
int argc;
|
|
||||||
char **argv;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum args_parse_type
|
void
|
||||||
cmd_command_prompt_args_parse(__unused struct args *args, __unused u_int idx,
|
cmd_command_prompt_key_binding(struct cmd *self, int key)
|
||||||
__unused char **cause)
|
|
||||||
{
|
{
|
||||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
switch (key) {
|
||||||
|
case '$':
|
||||||
|
self->args = args_create(1, "rename-session '%%'");
|
||||||
|
args_set(self->args, 'I', "#S");
|
||||||
|
break;
|
||||||
|
case ',':
|
||||||
|
self->args = args_create(1, "rename-window '%%'");
|
||||||
|
args_set(self->args, 'I', "#W");
|
||||||
|
break;
|
||||||
|
case '.':
|
||||||
|
self->args = args_create(1, "move-window -t '%%'");
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
self->args = args_create(1, "find-window '%%'");
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
self->args = args_create(1, "select-window -t ':%%'");
|
||||||
|
args_set(self->args, 'p', "index");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self->args = args_create(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
const char *inputs, *prompts;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
|
||||||
const char *type, *s, *input;
|
|
||||||
struct cmd_command_prompt_cdata *cdata;
|
struct cmd_command_prompt_cdata *cdata;
|
||||||
char *tmp, *prompts, *prompt, *next_prompt;
|
struct client *c;
|
||||||
char *inputs = NULL, *next_input;
|
char *prompt, *ptr, *input = NULL;
|
||||||
u_int count = args_count(args);
|
size_t n;
|
||||||
int wait = !args_has(args, 'b'), space = 1;
|
|
||||||
|
|
||||||
if (tc->prompt_string != NULL)
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (-1);
|
||||||
if (args_has(args, 'i'))
|
|
||||||
wait = 0;
|
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
if (c->prompt_string != NULL)
|
||||||
if (wait)
|
return (0);
|
||||||
cdata->item = item;
|
|
||||||
cdata->state = args_make_commands_prepare(self, item, 0, "%1", wait,
|
|
||||||
args_has(args, 'F'));
|
|
||||||
|
|
||||||
if ((s = args_get(args, 'p')) == NULL) {
|
cdata = xmalloc(sizeof *cdata);
|
||||||
if (count != 0) {
|
cdata->c = c;
|
||||||
tmp = args_make_commands_get_command(cdata->state);
|
cdata->idx = 1;
|
||||||
xasprintf(&prompts, "(%s)", tmp);
|
cdata->inputs = NULL;
|
||||||
free(tmp);
|
cdata->next_input = NULL;
|
||||||
} else {
|
cdata->next_prompt = NULL;
|
||||||
prompts = xstrdup(":");
|
cdata->prompts = NULL;
|
||||||
space = 0;
|
cdata->template = NULL;
|
||||||
}
|
|
||||||
next_prompt = prompts;
|
if (args->argc != 0)
|
||||||
} else
|
cdata->template = xstrdup(args->argv[0]);
|
||||||
next_prompt = prompts = xstrdup(s);
|
|
||||||
if ((s = args_get(args, 'I')) != NULL)
|
|
||||||
next_input = inputs = xstrdup(s);
|
|
||||||
else
|
else
|
||||||
next_input = NULL;
|
cdata->template = xstrdup("%1");
|
||||||
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) {
|
if ((prompts = args_get(args, 'p')) != NULL)
|
||||||
input = strsep(&next_input, ",");
|
cdata->prompts = xstrdup(prompts);
|
||||||
if (input == NULL)
|
else if (args->argc != 0) {
|
||||||
input = "";
|
n = strcspn(cdata->template, " ,");
|
||||||
} else
|
xasprintf(&cdata->prompts, "(%.*s) ", (int) n, cdata->template);
|
||||||
input = "";
|
|
||||||
cdata->prompts[cdata->count].input = xstrdup(input);
|
|
||||||
|
|
||||||
cdata->count++;
|
|
||||||
}
|
|
||||||
free(inputs);
|
|
||||||
free(prompts);
|
|
||||||
|
|
||||||
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);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
cdata->prompt_type = PROMPT_TYPE_COMMAND;
|
cdata->prompts = xstrdup(":");
|
||||||
|
|
||||||
if (args_has(args, '1'))
|
/* Get first prompt. */
|
||||||
cdata->flags |= PROMPT_SINGLE;
|
cdata->next_prompt = cdata->prompts;
|
||||||
else if (args_has(args, 'N'))
|
ptr = strsep(&cdata->next_prompt, ",");
|
||||||
cdata->flags |= PROMPT_NUMERIC;
|
if (prompts == NULL)
|
||||||
else if (args_has(args, 'i'))
|
prompt = xstrdup(ptr);
|
||||||
cdata->flags |= PROMPT_INCREMENTAL;
|
else
|
||||||
else if (args_has(args, 'k'))
|
xasprintf(&prompt, "%s ", ptr);
|
||||||
cdata->flags |= PROMPT_KEY;
|
|
||||||
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)
|
/* Get initial prompt input. */
|
||||||
return (CMD_RETURN_NORMAL);
|
if ((inputs = args_get(args, 'I')) != NULL) {
|
||||||
return (CMD_RETURN_WAIT);
|
cdata->inputs = xstrdup(inputs);
|
||||||
}
|
cdata->next_input = cdata->inputs;
|
||||||
|
input = strsep(&cdata->next_input, ",");
|
||||||
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;
|
status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
|
||||||
argv = cmd_copy_argv(cdata->argc, cdata->argv);
|
cmd_command_prompt_free, cdata, 0);
|
||||||
if (!done)
|
xfree(prompt);
|
||||||
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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
int
|
||||||
|
cmd_command_prompt_callback(void *data, const char *s)
|
||||||
|
{
|
||||||
|
struct cmd_command_prompt_cdata *cdata = data;
|
||||||
|
struct client *c = cdata->c;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *cause, *new_template, *prompt, *ptr;
|
||||||
|
char *input = NULL;
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
new_template = cmd_template_replace(cdata->template, s, cdata->idx);
|
||||||
|
xfree(cdata->template);
|
||||||
|
cdata->template = new_template;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if there are more prompts; if so, get its respective input
|
||||||
|
* and update the prompt data.
|
||||||
|
*/
|
||||||
|
if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
|
||||||
|
xasprintf(&prompt, "%s ", ptr);
|
||||||
|
input = strsep(&cdata->next_input, ",");
|
||||||
|
status_prompt_update(c, prompt, input);
|
||||||
|
|
||||||
|
xfree(prompt);
|
||||||
|
cdata->idx++;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd_string_parse(new_template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(c, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = c;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
|
||||||
|
if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
cmd_command_prompt_free(void *data)
|
cmd_command_prompt_free(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_command_prompt_cdata *cdata = data;
|
struct cmd_command_prompt_cdata *cdata = data;
|
||||||
u_int i;
|
|
||||||
|
|
||||||
for (i = 0; i < cdata->count; i++) {
|
if (cdata->inputs != NULL)
|
||||||
free(cdata->prompts[i].prompt);
|
xfree(cdata->inputs);
|
||||||
free(cdata->prompts[i].input);
|
if (cdata->prompts != NULL)
|
||||||
}
|
xfree(cdata->prompts);
|
||||||
free(cdata->prompts);
|
if (cdata->template != NULL)
|
||||||
cmd_free_argv(cdata->argc, cdata->argv);
|
xfree(cdata->template);
|
||||||
args_make_commands_free(cdata->state);
|
xfree(cdata);
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -16,10 +16,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -28,133 +25,126 @@
|
|||||||
* Asks for confirmation before executing a command.
|
* Asks for confirmation before executing a command.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum args_parse_type cmd_confirm_before_args_parse(struct args *,
|
void cmd_confirm_before_key_binding(struct cmd *, int);
|
||||||
u_int, char **);
|
int cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *);
|
||||||
static enum cmd_retval cmd_confirm_before_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
static int cmd_confirm_before_callback(struct client *, void *,
|
int cmd_confirm_before_callback(void *, const char *);
|
||||||
const char *, int);
|
void cmd_confirm_before_free(void *);
|
||||||
static void cmd_confirm_before_free(void *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_confirm_before_entry = {
|
const struct cmd_entry cmd_confirm_before_entry = {
|
||||||
.name = "confirm-before",
|
"confirm-before", "confirm",
|
||||||
.alias = "confirm",
|
"p:t:", 1, 1,
|
||||||
|
"[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
|
||||||
.args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse },
|
0,
|
||||||
.usage = "[-by] [-c confirm_key] [-p prompt] " CMD_TARGET_CLIENT_USAGE
|
cmd_confirm_before_key_binding,
|
||||||
" command",
|
NULL,
|
||||||
|
cmd_confirm_before_exec
|
||||||
.flags = CMD_CLIENT_TFLAG,
|
|
||||||
.exec = cmd_confirm_before_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_confirm_before_data {
|
struct cmd_confirm_before_data {
|
||||||
struct cmdq_item *item;
|
struct client *c;
|
||||||
struct cmd_list *cmdlist;
|
char *cmd;
|
||||||
u_char confirm_key;
|
|
||||||
int default_yes;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum args_parse_type
|
void
|
||||||
cmd_confirm_before_args_parse(__unused struct args *args, __unused u_int idx,
|
cmd_confirm_before_key_binding(struct cmd *self, int key)
|
||||||
__unused char **cause)
|
|
||||||
{
|
{
|
||||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
switch (key) {
|
||||||
|
case '&':
|
||||||
|
self->args = args_create(1, "kill-window");
|
||||||
|
args_set(self->args, 'p', "kill-window #W? (y/n)");
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
self->args = args_create(1, "kill-pane");
|
||||||
|
args_set(self->args, 'p', "kill-pane #P? (y/n)");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self->args = args_create(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_confirm_before_data *cdata;
|
struct cmd_confirm_before_data *cdata;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *c;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
char *cmd, *copy, *new_prompt, *ptr;
|
||||||
char *new_prompt;
|
const char *prompt;
|
||||||
const char *confirm_key, *prompt, *cmd;
|
|
||||||
int wait = !args_has(args, 'b');
|
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
if (ctx->curclient == NULL) {
|
||||||
cdata->cmdlist = args_make_commands_now(self, item, 0, 1);
|
ctx->error(ctx, "must be run interactively");
|
||||||
if (cdata->cmdlist == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
|
|
||||||
if (wait)
|
|
||||||
cdata->item = item;
|
|
||||||
|
|
||||||
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");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
cdata->confirm_key = 'y';
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
if ((prompt = args_get(args, 'p')) != NULL)
|
if ((prompt = args_get(args, 'p')) != NULL)
|
||||||
xasprintf(&new_prompt, "%s ", prompt);
|
xasprintf(&new_prompt, "%s ", prompt);
|
||||||
else {
|
else {
|
||||||
cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name;
|
ptr = copy = xstrdup(args->argv[0]);
|
||||||
xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ",
|
cmd = strsep(&ptr, " \t");
|
||||||
cmd, cdata->confirm_key);
|
xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
|
||||||
|
xfree(copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_prompt_set(tc, target, new_prompt, NULL,
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->cmd = xstrdup(args->argv[0]);
|
||||||
|
cdata->c = c;
|
||||||
|
status_prompt_set(cdata->c, new_prompt, NULL,
|
||||||
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
||||||
PROMPT_SINGLE, PROMPT_TYPE_COMMAND);
|
PROMPT_SINGLE);
|
||||||
free(new_prompt);
|
|
||||||
|
|
||||||
if (!wait)
|
xfree(new_prompt);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (1);
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
int
|
||||||
cmd_confirm_before_callback(struct client *c, void *data, const char *s,
|
cmd_confirm_before_callback(void *data, const char *s)
|
||||||
__unused int done)
|
|
||||||
{
|
{
|
||||||
struct cmd_confirm_before_data *cdata = data;
|
struct cmd_confirm_before_data *cdata = data;
|
||||||
struct cmdq_item *item = cdata->item, *new_item;
|
struct client *c = cdata->c;
|
||||||
int retcode = 1;
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *cause;
|
||||||
|
|
||||||
if (c->flags & CLIENT_DEAD)
|
if (s == NULL || *s == '\0')
|
||||||
goto out;
|
return (0);
|
||||||
|
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||||
|
return (0);
|
||||||
|
|
||||||
if (s == NULL)
|
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||||
goto out;
|
if (cause != NULL) {
|
||||||
if (s[0] != cdata->confirm_key && (s[0] != '\0' || !cdata->default_yes))
|
*cause = toupper((u_char) *cause);
|
||||||
goto out;
|
status_message_set(c, "%s", cause);
|
||||||
retcode = 0;
|
xfree(cause);
|
||||||
|
}
|
||||||
if (item == NULL) {
|
return (0);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
ctx.msgdata = NULL;
|
||||||
if (item != NULL) {
|
ctx.curclient = c;
|
||||||
if (cmdq_get_client(item) != NULL &&
|
|
||||||
cmdq_get_client(item)->session == NULL)
|
ctx.error = key_bindings_error;
|
||||||
cmdq_get_client(item)->retval = retcode;
|
ctx.print = key_bindings_print;
|
||||||
cmdq_continue(item);
|
ctx.info = key_bindings_info;
|
||||||
}
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_confirm_before_free(void *data)
|
cmd_confirm_before_free(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_confirm_before_data *cdata = data;
|
struct cmd_confirm_before_data *cdata = data;
|
||||||
|
|
||||||
cmd_list_free(cdata->cmdlist);
|
if (cdata->cmd != NULL)
|
||||||
free(cdata);
|
xfree(cdata->cmd);
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
102
cmd-copy-mode.c
102
cmd-copy-mode.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -21,76 +21,44 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enter copy or clock mode.
|
* Enter copy mode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmdq_item *);
|
void cmd_copy_mode_key_binding(struct cmd *, int);
|
||||||
|
int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_copy_mode_entry = {
|
const struct cmd_entry cmd_copy_mode_entry = {
|
||||||
.name = "copy-mode",
|
"copy-mode", NULL,
|
||||||
.alias = NULL,
|
"t:u", 0, 0,
|
||||||
|
"[-u] " CMD_TARGET_PANE_USAGE,
|
||||||
.args = { "eHMs:t:uq", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-eHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
|
cmd_copy_mode_key_binding,
|
||||||
|
NULL,
|
||||||
.source = { 's', CMD_FIND_PANE, 0 },
|
cmd_copy_mode_exec
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_copy_mode_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_clock_mode_entry = {
|
void
|
||||||
.name = "clock-mode",
|
cmd_copy_mode_key_binding(struct cmd *self, int key)
|
||||||
.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)
|
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
self->args = args_create(0);
|
||||||
struct key_event *event = cmdq_get_event(item);
|
if (key == KEYC_PPAGE)
|
||||||
struct cmd_find_state *source = cmdq_get_source(item);
|
args_set(self->args, 'u', NULL);
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
}
|
||||||
struct client *c = cmdq_get_client(item);
|
|
||||||
struct session *s;
|
int
|
||||||
struct window_pane *wp = target->wp, *swp;
|
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
if (args_has(args, 'q')) {
|
struct args *args = self->args;
|
||||||
window_pane_reset_mode_all(wp);
|
struct window_pane *wp;
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
if (args_has(args, 'M')) {
|
|
||||||
if ((wp = cmd_mouse_pane(&event->m, &s, NULL)) == NULL)
|
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
if (c == NULL || c->session != s)
|
window_copy_init_from_pane(wp);
|
||||||
return (CMD_RETURN_NORMAL);
|
if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
|
||||||
}
|
window_copy_pageup(wp);
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_clock_mode_entry) {
|
return (0);
|
||||||
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);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 Joshua Rubin <joshua@rubixconsulting.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -16,51 +18,49 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <utf8proc.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "compat.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",
|
||||||
|
"b:", 0, 0,
|
||||||
|
CMD_BUFFER_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_delete_buffer_exec
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
utf8proc_wcwidth(wchar_t wc)
|
cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
int cat;
|
struct args *args = self->args;
|
||||||
|
char *cause;
|
||||||
|
int buffer;
|
||||||
|
|
||||||
cat = utf8proc_category(wc);
|
if (!args_has(args, 'b')) {
|
||||||
if (cat == UTF8PROC_CATEGORY_CO) {
|
paste_free_top(&global_buffers);
|
||||||
/*
|
return (0);
|
||||||
* The private use category is where powerline and similar
|
|
||||||
* codepoints are stored, they have "ambiguous" width - use 1.
|
|
||||||
*/
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
return (utf8proc_charwidth(wc));
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
utf8proc_mbtowc(wchar_t *pwc, const char *s, size_t n)
|
if (cause != NULL) {
|
||||||
{
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
utf8proc_ssize_t slen;
|
xfree(cause);
|
||||||
|
|
||||||
if (s == NULL)
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* *pwc == -1 indicates invalid codepoint
|
|
||||||
* slen < 0 indicates an error
|
|
||||||
*/
|
|
||||||
slen = utf8proc_iterate(s, n, pwc);
|
|
||||||
if (*pwc == (wchar_t)-1 || slen < 0)
|
|
||||||
return (-1);
|
return (-1);
|
||||||
return (slen);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int
|
if (paste_free_index(&global_buffers, buffer) != 0) {
|
||||||
utf8proc_wctomb(char *s, wchar_t wc)
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
{
|
|
||||||
if (s == NULL)
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
if (!utf8proc_codepoint_valid(wc))
|
|
||||||
return (-1);
|
return (-1);
|
||||||
return (utf8proc_encode_char(wc, s));
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,56 +18,32 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Detach a client.
|
* Detach a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_detach_client_exec(struct cmd *,
|
int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_detach_client_entry = {
|
const struct cmd_entry cmd_detach_client_entry = {
|
||||||
.name = "detach-client",
|
"detach-client", "detach",
|
||||||
.alias = "detach",
|
"s:t:P", 0, 0,
|
||||||
|
"[-P] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
||||||
.args = { "aE:s:t:P", 0, 0, NULL },
|
CMD_READONLY,
|
||||||
.usage = "[-aP] [-E shell-command] "
|
NULL,
|
||||||
"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
NULL,
|
||||||
|
cmd_detach_client_exec
|
||||||
.source = { 's', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = CMD_READONLY|CMD_CLIENT_TFLAG,
|
|
||||||
.exec = cmd_detach_client_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_suspend_client_entry = {
|
int
|
||||||
.name = "suspend-client",
|
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "suspendc",
|
|
||||||
|
|
||||||
.args = { "t:", 0, 0, 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)
|
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *source = cmdq_get_source(item);
|
struct client *c;
|
||||||
struct client *tc = cmdq_get_target_client(item), *loop;
|
struct session *s;
|
||||||
struct session *s;
|
enum msgtype msgtype;
|
||||||
enum msgtype msgtype;
|
u_int i;
|
||||||
const char *cmd = args_get(args, 'E');
|
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_suspend_client_entry) {
|
|
||||||
server_client_suspend(tc);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'P'))
|
if (args_has(args, 'P'))
|
||||||
msgtype = MSG_DETACHKILL;
|
msgtype = MSG_DETACHKILL;
|
||||||
@@ -75,35 +51,22 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
msgtype = MSG_DETACH;
|
msgtype = MSG_DETACH;
|
||||||
|
|
||||||
if (args_has(args, 's')) {
|
if (args_has(args, 's')) {
|
||||||
s = source->s;
|
s = cmd_find_session(ctx, args_get(args, 's'), 0);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (-1);
|
||||||
TAILQ_FOREACH(loop, &clients, entry) {
|
|
||||||
if (loop->session == s) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
if (cmd != NULL)
|
c = ARRAY_ITEM(&clients, i);
|
||||||
server_client_exec(loop, cmd);
|
if (c != NULL && c->session == s)
|
||||||
else
|
server_write_client(c, msgtype, NULL, 0);
|
||||||
server_client_detach(loop, msgtype);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (CMD_RETURN_STOP);
|
} else {
|
||||||
|
c = cmd_find_client(ctx, args_get(args, 't'));
|
||||||
|
if (c == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
server_write_client(c, msgtype, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
return (0);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,502 +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:Ot:T:x:y:", 1, -1, cmd_display_menu_args_parse },
|
|
||||||
.usage = "[-O] [-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:s:S:t:T:w:x:y:", 0, -1, NULL },
|
|
||||||
.usage = "[-BCE] [-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]",
|
|
||||||
|
|
||||||
.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_position(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;
|
|
||||||
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);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
menu_free(menu);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
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");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (menu->count == 0) {
|
|
||||||
menu_free(menu);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
if (!cmd_display_menu_get_position(tc, item, args, &px, &py,
|
|
||||||
menu->width + 4, menu->count + 2)) {
|
|
||||||
menu_free(menu);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'O'))
|
|
||||||
flags |= MENU_STAYOPEN;
|
|
||||||
if (!event->m.valid)
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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, *cause = NULL, **argv = NULL, *title;
|
|
||||||
int flags = 0, 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 (tc->overlay_draw != NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
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);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (w > tty->sx)
|
|
||||||
w = tty->sx;
|
|
||||||
if (h > tty->sy)
|
|
||||||
h = tty->sy;
|
|
||||||
if (!cmd_display_menu_get_position(tc, item, args, &px, &py, w, h))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
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);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'T'))
|
|
||||||
title = format_single_from_target(item, args_get(args, 'T'));
|
|
||||||
else
|
|
||||||
title = xstrdup("");
|
|
||||||
if (args_has(args, 'E') > 1)
|
|
||||||
flags |= POPUP_CLOSEEXITZERO;
|
|
||||||
else if (args_has(args, 'E'))
|
|
||||||
flags |= POPUP_CLOSEEXIT;
|
|
||||||
if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc,
|
|
||||||
argv, cwd, title, tc, s, style, border_style, NULL, NULL) != 0) {
|
|
||||||
cmd_free_argv(argc, argv);
|
|
||||||
if (env != NULL)
|
|
||||||
environ_free(env);
|
|
||||||
free(cwd);
|
|
||||||
free(title);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
if (env != NULL)
|
|
||||||
environ_free(env);
|
|
||||||
free(cwd);
|
|
||||||
free(title);
|
|
||||||
cmd_free_argv(argc, argv);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,133 +26,53 @@
|
|||||||
* Displays a message in the status line.
|
* Displays a message in the status line.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DISPLAY_MESSAGE_TEMPLATE \
|
int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"[#{session_name}] #{window_index}:" \
|
|
||||||
"#{window_name}, current pane #{pane_index} " \
|
|
||||||
"- (%H:%M %d-%b-%y)"
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_display_message_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_display_message_entry = {
|
const struct cmd_entry cmd_display_message_entry = {
|
||||||
.name = "display-message",
|
"display-message", "display",
|
||||||
.alias = "display",
|
"c:pt:", 0, 1,
|
||||||
|
"[-p] [-c target-client] [-t target-pane] [message]",
|
||||||
.args = { "ac:d:lINpt:F:v", 0, 1, NULL },
|
0,
|
||||||
.usage = "[-aIlNpv] [-c target-client] [-d delay] [-F format] "
|
NULL,
|
||||||
CMD_TARGET_PANE_USAGE " [message]",
|
NULL,
|
||||||
|
cmd_display_message_exec
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG|CMD_CLIENT_CANFAIL,
|
|
||||||
.exec = cmd_display_message_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
int
|
||||||
cmd_display_message_each(const char *key, const char *value, void *arg)
|
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct cmdq_item *item = arg;
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
cmdq_print(item, "%s=%s", key, value);
|
struct session *s;
|
||||||
}
|
struct winlink *wl;
|
||||||
|
struct window_pane *wp;
|
||||||
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;
|
const char *template;
|
||||||
char *msg, *cause;
|
char *msg;
|
||||||
int delay = -1, flags, Nflag = args_has(args, 'N');
|
|
||||||
struct format_tree *ft;
|
|
||||||
u_int count = args_count(args);
|
|
||||||
struct evbuffer *evb;
|
|
||||||
|
|
||||||
if (args_has(args, 'I')) {
|
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
|
||||||
if (wp == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
switch (window_pane_start_input(wp, item, &cause)) {
|
if (args_has(args, 't') != 0) {
|
||||||
case -1:
|
wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
|
||||||
cmdq_error(item, "%s", cause);
|
if (wl == NULL)
|
||||||
free(cause);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
} else {
|
||||||
case 1:
|
s = NULL;
|
||||||
return (CMD_RETURN_NORMAL);
|
wl = NULL;
|
||||||
case 0:
|
wp = NULL;
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'F') && count != 0) {
|
if (args->argc == 0)
|
||||||
cmdq_error(item, "only one of -F or argument must be given");
|
template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)";
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
else
|
||||||
template = args_get(args, 'F');
|
template = args->argv[0];
|
||||||
if (template == NULL)
|
|
||||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
|
||||||
|
|
||||||
/*
|
msg = status_replace(c, s, wl, wp, template, time(NULL), 0);
|
||||||
* -c is intended to be the client where the message should be
|
if (args_has(self->args, 'p'))
|
||||||
* displayed if -p is not given. But it makes sense to use it for the
|
ctx->print(ctx, "%s", msg);
|
||||||
* 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
|
else
|
||||||
c = NULL;
|
status_message_set(c, "%s", msg);
|
||||||
if (args_has(args, 'v'))
|
xfree(msg);
|
||||||
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')) {
|
return (0);
|
||||||
format_each(ft, cmd_display_message_each, item);
|
|
||||||
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, "%s", msg);
|
|
||||||
free(msg);
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,295 +18,34 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display panes on a client.
|
* Display panes on a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum args_parse_type cmd_display_panes_args_parse(struct args *,
|
int cmd_display_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||||
u_int, char **);
|
|
||||||
static enum cmd_retval cmd_display_panes_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_display_panes_entry = {
|
const struct cmd_entry cmd_display_panes_entry = {
|
||||||
.name = "display-panes",
|
"display-panes", "displayp",
|
||||||
.alias = "displayp",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
.args = { "bd:Nt:", 0, 1, cmd_display_panes_args_parse },
|
0,
|
||||||
.usage = "[-bN] [-d duration] " CMD_TARGET_CLIENT_USAGE " [template]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
cmd_display_panes_exec
|
||||||
.exec = cmd_display_panes_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_display_panes_data {
|
int
|
||||||
struct cmdq_item *item;
|
cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
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);
|
struct args *args = self->args;
|
||||||
}
|
struct client *c;
|
||||||
|
|
||||||
static void
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
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);
|
return (-1);
|
||||||
|
|
||||||
wp = window_pane_at_index(w, index);
|
server_set_identify(c);
|
||||||
if (wp == NULL)
|
|
||||||
return (1);
|
|
||||||
window_unzoom(w);
|
|
||||||
|
|
||||||
xasprintf(&expanded, "%%%u", wp->id);
|
return (0);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <fnmatch.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -26,91 +27,150 @@
|
|||||||
* Find window containing text.
|
* Find window containing text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmdq_item *);
|
int cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_find_window_callback(void *, int);
|
||||||
|
void cmd_find_window_free(void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_find_window_entry = {
|
const struct cmd_entry cmd_find_window_entry = {
|
||||||
.name = "find-window",
|
"find-window", "findw",
|
||||||
.alias = "findw",
|
"t:", 1, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " match-string",
|
||||||
.args = { "CiNrt:TZ", 1, 1, NULL },
|
0,
|
||||||
.usage = "[-CiNrTZ] " CMD_TARGET_PANE_USAGE " match-string",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_find_window_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_find_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
struct cmd_find_window_data {
|
||||||
cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
struct session *session;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self), *new_args;
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct cmd_find_window_data *cdata;
|
||||||
struct window_pane *wp = target->wp;
|
struct session *s;
|
||||||
const char *s = args_string(args, 0), *suffix = "";
|
struct winlink *wl, *wm;
|
||||||
const char *star = "*";
|
struct window *w;
|
||||||
struct args_value *filter;
|
struct window_pane *wp;
|
||||||
int C, N, T;
|
ARRAY_DECL(, u_int) list_idx;
|
||||||
|
ARRAY_DECL(, char *) list_ctx;
|
||||||
|
char *str, *sres, *sctx, *searchstr;
|
||||||
|
u_int i, line;
|
||||||
|
|
||||||
C = args_has(args, 'C');
|
if (ctx->curclient == NULL) {
|
||||||
N = args_has(args, 'N');
|
ctx->error(ctx, "must be run interactively");
|
||||||
T = args_has(args, 'T');
|
return (-1);
|
||||||
|
}
|
||||||
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
if (args_has(args, 'r'))
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
star = "";
|
return (-1);
|
||||||
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 (!C && !N && !T)
|
str = args->argv[0];
|
||||||
C = N = T = 1;
|
|
||||||
|
|
||||||
filter = xcalloc(1, sizeof *filter);
|
ARRAY_INIT(&list_idx);
|
||||||
filter->type = ARGS_STRING;
|
ARRAY_INIT(&list_ctx);
|
||||||
|
|
||||||
if (C && N && T) {
|
xasprintf(&searchstr, "*%s*", str);
|
||||||
xasprintf(&filter->string,
|
RB_FOREACH(wm, winlinks, &s->windows) {
|
||||||
"#{||:"
|
i = 0;
|
||||||
"#{C%s:%s},#{||:#{m%s:%s%s%s,#{window_name}},"
|
TAILQ_FOREACH(wp, &wm->window->panes, entry) {
|
||||||
"#{m%s:%s%s%s,#{pane_title}}}}",
|
i++;
|
||||||
suffix, s, suffix, star, s, star, suffix, star, s, star);
|
|
||||||
} else if (C && N) {
|
if (fnmatch(searchstr, wm->window->name, 0) == 0)
|
||||||
xasprintf(&filter->string,
|
sctx = xstrdup("");
|
||||||
"#{||:#{C%s:%s},#{m%s:%s%s%s,#{window_name}}}",
|
else {
|
||||||
suffix, s, suffix, star, s, star);
|
sres = window_pane_search(wp, str, &line);
|
||||||
} else if (C && T) {
|
if (sres == NULL &&
|
||||||
xasprintf(&filter->string,
|
fnmatch(searchstr, wp->base.title, 0) != 0)
|
||||||
"#{||:#{C%s:%s},#{m%s:%s%s%s,#{pane_title}}}",
|
continue;
|
||||||
suffix, s, suffix, star, s, star);
|
|
||||||
} else if (N && T) {
|
if (sres == NULL) {
|
||||||
xasprintf(&filter->string,
|
xasprintf(&sctx,
|
||||||
"#{||:#{m%s:%s%s%s,#{window_name}},"
|
"pane %u title: \"%s\"", i - 1,
|
||||||
"#{m%s:%s%s%s,#{pane_title}}}",
|
wp->base.title);
|
||||||
suffix, star, s, star, suffix, star, s, star);
|
} else {
|
||||||
} else if (C) {
|
xasprintf(&sctx,
|
||||||
xasprintf(&filter->string,
|
"pane %u line %u: \"%s\"", i - 1,
|
||||||
"#{C%s:%s}",
|
line + 1, sres);
|
||||||
suffix, s);
|
xfree(sres);
|
||||||
} else if (N) {
|
}
|
||||||
xasprintf(&filter->string,
|
}
|
||||||
"#{m%s:%s%s%s,#{window_name}}",
|
|
||||||
suffix, star, s, star);
|
ARRAY_ADD(&list_idx, wm->idx);
|
||||||
} else {
|
ARRAY_ADD(&list_ctx, sctx);
|
||||||
xasprintf(&filter->string,
|
}
|
||||||
"#{m%s:%s%s%s,#{pane_title}}",
|
}
|
||||||
suffix, star, s, star);
|
xfree(searchstr);
|
||||||
|
|
||||||
|
if (ARRAY_LENGTH(&list_idx) == 0) {
|
||||||
|
ctx->error(ctx, "no windows matching: %s", str);
|
||||||
|
ARRAY_FREE(&list_idx);
|
||||||
|
ARRAY_FREE(&list_ctx);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
new_args = args_create();
|
if (ARRAY_LENGTH(&list_idx) == 1) {
|
||||||
if (args_has(args, 'Z'))
|
if (session_select(s, ARRAY_FIRST(&list_idx)) == 0)
|
||||||
args_set(new_args, 'Z', NULL, 0);
|
server_redraw_session(s);
|
||||||
args_set(new_args, 'f', filter, 0);
|
recalculate_sizes();
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args);
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
args_free(new_args);
|
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);
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
0, cmd_find_window_callback, cmd_find_window_free, cdata);
|
||||||
|
|
||||||
|
out:
|
||||||
|
ARRAY_FREE(&list_idx);
|
||||||
|
ARRAY_FREE(&list_ctx);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_find_window_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_find_window_data *cdata = data;
|
||||||
|
struct session *s = cdata->session;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (!session_alive(s))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (session_select(s, idx) == 0) {
|
||||||
|
server_redraw_session(s);
|
||||||
|
recalculate_sizes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_find_window_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_find_window_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->session->references--;
|
||||||
|
xfree(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
1314
cmd-find.c
1314
cmd-find.c
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,35 +18,31 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <kernel/OS.h>
|
|
||||||
|
|
||||||
#include "tmux.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",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_has_session_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
pid_t tid;
|
struct args *args = self->args;
|
||||||
team_info tinfo;
|
|
||||||
|
|
||||||
if ((tid = tcgetpgrp(fd)) == -1)
|
if (cmd_find_session(ctx, args_get(args, 't'), 0) == NULL)
|
||||||
return (NULL);
|
return (-1);
|
||||||
|
|
||||||
if (get_team_info(tid, &tinfo) != B_OK)
|
return (0);
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
/* Up to the first 64 characters. */
|
|
||||||
return (xstrdup(tinfo.args));
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
osdep_get_cwd(int fd)
|
|
||||||
{
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct event_base *
|
|
||||||
osdep_event_init(void)
|
|
||||||
{
|
|
||||||
return (event_init());
|
|
||||||
}
|
}
|
||||||
184
cmd-if-shell.c
184
cmd-if-shell.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -20,171 +20,93 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Executes a tmux command if a shell command returns true or false.
|
* Executes a tmux command if a shell command returns true.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum args_parse_type cmd_if_shell_args_parse(struct args *, u_int,
|
int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||||
char **);
|
|
||||||
static enum cmd_retval cmd_if_shell_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
static void cmd_if_shell_callback(struct job *);
|
void cmd_if_shell_callback(struct job *);
|
||||||
static void cmd_if_shell_free(void *);
|
void cmd_if_shell_free(void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_if_shell_entry = {
|
const struct cmd_entry cmd_if_shell_entry = {
|
||||||
.name = "if-shell",
|
"if-shell", "if",
|
||||||
.alias = "if",
|
"", 2, 2,
|
||||||
|
"shell-command command",
|
||||||
.args = { "bFt:", 2, 3, cmd_if_shell_args_parse },
|
0,
|
||||||
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
|
NULL,
|
||||||
"[command]",
|
NULL,
|
||||||
|
cmd_if_shell_exec
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_if_shell_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_if_shell_data {
|
struct cmd_if_shell_data {
|
||||||
struct args_command_state *cmd_if;
|
char *cmd;
|
||||||
struct args_command_state *cmd_else;
|
struct cmd_ctx ctx;
|
||||||
|
|
||||||
struct client *client;
|
|
||||||
struct cmdq_item *item;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum args_parse_type
|
int
|
||||||
cmd_if_shell_args_parse(__unused struct args *args, u_int idx,
|
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
__unused char **cause)
|
|
||||||
{
|
{
|
||||||
if (idx == 1 || idx == 2)
|
struct args *args = self->args;
|
||||||
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 cmd_if_shell_data *cdata;
|
||||||
struct cmdq_item *new_item;
|
const char *shellcmd = args->argv[0];
|
||||||
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));
|
cdata = xmalloc(sizeof *cdata);
|
||||||
if (args_has(args, 'F')) {
|
cdata->cmd = xstrdup(args->argv[1]);
|
||||||
if (*shellcmd != '0' && *shellcmd != '\0')
|
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||||
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);
|
if (ctx->cmdclient != NULL)
|
||||||
|
ctx->cmdclient->references++;
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references++;
|
||||||
|
|
||||||
cdata->cmd_if = args_make_commands_prepare(self, item, 1, NULL, wait,
|
job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata);
|
||||||
0);
|
|
||||||
if (count == 3) {
|
|
||||||
cdata->cmd_else = args_make_commands_prepare(self, item, 2,
|
|
||||||
NULL, wait, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wait) {
|
return (1); /* don't let client exit */
|
||||||
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);
|
|
||||||
free(cdata);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
free(shellcmd);
|
|
||||||
|
|
||||||
if (!wait)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_if_shell_callback(struct job *job)
|
cmd_if_shell_callback(struct job *job)
|
||||||
{
|
{
|
||||||
struct cmd_if_shell_data *cdata = job_get_data(job);
|
struct cmd_if_shell_data *cdata = job->data;
|
||||||
struct client *c = cdata->client;
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
struct cmdq_item *item = cdata->item, *new_item;
|
|
||||||
struct args_command_state *state;
|
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
char *error;
|
char *cause;
|
||||||
int status;
|
|
||||||
|
|
||||||
status = job_get_status(job);
|
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
||||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
return;
|
||||||
state = cdata->cmd_else;
|
|
||||||
else
|
|
||||||
state = cdata->cmd_if;
|
|
||||||
if (state == NULL)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
cmdlist = args_make_commands(state, 0, NULL, &error);
|
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||||
if (cmdlist == NULL) {
|
if (cause != NULL) {
|
||||||
if (cdata->item == NULL) {
|
ctx->error(ctx, "%s", cause);
|
||||||
*error = toupper((u_char)*error);
|
xfree(cause);
|
||||||
status_message_set(c, -1, 1, 0, "%s", error);
|
}
|
||||||
} else
|
return;
|
||||||
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:
|
cmd_list_exec(cmdlist, ctx);
|
||||||
if (cdata->item != NULL)
|
cmd_list_free(cmdlist);
|
||||||
cmdq_continue(cdata->item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_if_shell_free(void *data)
|
cmd_if_shell_free(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_if_shell_data *cdata = data;
|
struct cmd_if_shell_data *cdata = data;
|
||||||
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
struct msg_exit_data exitdata;
|
||||||
|
|
||||||
if (cdata->client != NULL)
|
if (ctx->cmdclient != NULL) {
|
||||||
server_client_unref(cdata->client);
|
ctx->cmdclient->references--;
|
||||||
|
exitdata.retcode = ctx->cmdclient->retcode;
|
||||||
|
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||||
|
}
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references--;
|
||||||
|
|
||||||
if (cdata->cmd_else != NULL)
|
xfree(cdata->cmd);
|
||||||
args_make_commands_free(cdata->cmd_else);
|
xfree(cdata);
|
||||||
args_make_commands_free(cdata->cmd_if);
|
|
||||||
|
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|||||||
177
cmd-join-pane.c
177
cmd-join-pane.c
@@ -1,8 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -20,142 +19,115 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Join or move a pane into another (like split/swap/kill).
|
* Join a pane into another (like split/swap/kill).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmdq_item *);
|
void cmd_join_pane_key_binding(struct cmd *, int);
|
||||||
|
int cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_join_pane_entry = {
|
const struct cmd_entry cmd_join_pane_entry = {
|
||||||
.name = "join-pane",
|
"join-pane", "joinp",
|
||||||
.alias = "joinp",
|
"dhvp:l:s:t:", 0, 0,
|
||||||
|
"[-dhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
|
||||||
.args = { "bdfhvp:l:s:t:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE,
|
cmd_join_pane_key_binding,
|
||||||
|
NULL,
|
||||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
cmd_join_pane_exec
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_join_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_move_pane_entry = {
|
void
|
||||||
.name = "move-pane",
|
cmd_join_pane_key_binding(struct cmd *self, int key)
|
||||||
.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);
|
switch (key) {
|
||||||
struct cmd_find_state *current = cmdq_get_current(item);
|
case '%':
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
self->args = args_create(0);
|
||||||
struct cmd_find_state *source = cmdq_get_source(item);
|
args_set(self->args, 'h', NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self->args = args_create(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
struct session *dst_s;
|
struct session *dst_s;
|
||||||
struct winlink *src_wl, *dst_wl;
|
struct winlink *src_wl, *dst_wl;
|
||||||
struct window *src_w, *dst_w;
|
struct window *src_w, *dst_w;
|
||||||
struct window_pane *src_wp, *dst_wp;
|
struct window_pane *src_wp, *dst_wp;
|
||||||
char *cause = NULL;
|
char *cause;
|
||||||
int size, dst_idx;
|
int size, percentage, dst_idx;
|
||||||
int flags;
|
|
||||||
enum layout_type type;
|
enum layout_type type;
|
||||||
struct layout_cell *lc;
|
struct layout_cell *lc;
|
||||||
u_int curval = 0;
|
|
||||||
|
|
||||||
dst_s = target->s;
|
dst_wl = cmd_find_pane(ctx, args_get(args, 't'), &dst_s, &dst_wp);
|
||||||
dst_wl = target->wl;
|
if (dst_wl == NULL)
|
||||||
dst_wp = target->wp;
|
return (-1);
|
||||||
dst_w = dst_wl->window;
|
dst_w = dst_wl->window;
|
||||||
dst_idx = dst_wl->idx;
|
dst_idx = dst_wl->idx;
|
||||||
server_unzoom_window(dst_w);
|
|
||||||
|
|
||||||
src_wl = source->wl;
|
src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp);
|
||||||
src_wp = source->wp;
|
if (src_wl == NULL)
|
||||||
|
return (-1);
|
||||||
src_w = src_wl->window;
|
src_w = src_wl->window;
|
||||||
server_unzoom_window(src_w);
|
|
||||||
|
|
||||||
if (src_wp == dst_wp) {
|
if (src_w == dst_w) {
|
||||||
cmdq_error(item, "source and target panes must be different");
|
ctx->error(ctx, "can't join a pane to its own window");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
type = LAYOUT_TOPBOTTOM;
|
type = LAYOUT_TOPBOTTOM;
|
||||||
if (args_has(args, 'h'))
|
if (args_has(args, 'h'))
|
||||||
type = LAYOUT_LEFTRIGHT;
|
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;
|
size = -1;
|
||||||
if (args_has(args, 'l')) {
|
if (args_has(args, 'l')) {
|
||||||
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
|
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
||||||
item, &cause);
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "size %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
} else if (args_has(args, 'p')) {
|
} else if (args_has(args, 'p')) {
|
||||||
size = args_strtonum_and_expand(args, 'l', 0, 100, item,
|
percentage = args_strtonum(args, 'p', 0, 100, &cause);
|
||||||
&cause);
|
if (cause != NULL) {
|
||||||
if (cause == NULL)
|
ctx->error(ctx, "percentage %s", cause);
|
||||||
size = curval * size / 100;
|
xfree(cause);
|
||||||
}
|
return (-1);
|
||||||
if (cause != NULL) {
|
}
|
||||||
cmdq_error(item, "size %s", cause);
|
if (type == LAYOUT_TOPBOTTOM)
|
||||||
free(cause);
|
size = (dst_wp->sy * percentage) / 100;
|
||||||
return (CMD_RETURN_ERROR);
|
else
|
||||||
|
size = (dst_wp->sx * percentage) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = 0;
|
if ((lc = layout_split_pane(dst_wp, type, size)) == NULL) {
|
||||||
if (args_has(args, 'b'))
|
ctx->error(ctx, "create pane failed: pane too small");
|
||||||
flags |= SPAWN_BEFORE;
|
return (-1);
|
||||||
if (args_has(args, 'f'))
|
|
||||||
flags |= SPAWN_FULLSIZE;
|
|
||||||
|
|
||||||
lc = layout_split_pane(dst_wp, type, size, flags);
|
|
||||||
if (lc == NULL) {
|
|
||||||
cmdq_error(item, "create pane failed: pane too small");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
layout_close_pane(src_wp);
|
layout_close_pane(src_wp);
|
||||||
|
|
||||||
server_client_remove_pane(src_wp);
|
if (src_w->active == src_wp) {
|
||||||
window_lost_pane(src_w, src_wp);
|
src_w->active = TAILQ_PREV(src_wp, window_panes, entry);
|
||||||
|
if (src_w->active == NULL)
|
||||||
|
src_w->active = TAILQ_NEXT(src_wp, entry);
|
||||||
|
}
|
||||||
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
||||||
|
|
||||||
|
if (window_count_panes(src_w) == 0)
|
||||||
|
server_kill_window(src_w);
|
||||||
|
|
||||||
src_wp->window = dst_w;
|
src_wp->window = dst_w;
|
||||||
options_set_parent(src_wp->options, dst_w->options);
|
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
||||||
src_wp->flags |= PANE_STYLECHANGED;
|
layout_assign_pane(lc, src_wp);
|
||||||
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();
|
recalculate_sizes();
|
||||||
|
|
||||||
@@ -163,18 +135,11 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
server_redraw_window(dst_w);
|
server_redraw_window(dst_w);
|
||||||
|
|
||||||
if (!args_has(args, 'd')) {
|
if (!args_has(args, 'd')) {
|
||||||
window_set_active_pane(dst_w, src_wp, 1);
|
window_set_active_pane(dst_w, src_wp);
|
||||||
session_select(dst_s, dst_idx);
|
session_select(dst_s, dst_idx);
|
||||||
cmd_find_from_session(current, dst_s, 0);
|
|
||||||
server_redraw_session(dst_s);
|
server_redraw_session(dst_s);
|
||||||
} else
|
} else
|
||||||
server_status_session(dst_s);
|
server_status_session(dst_s);
|
||||||
|
|
||||||
if (window_count_panes(src_w) == 0)
|
return (0);
|
||||||
server_kill_window(src_w, 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$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -26,42 +26,50 @@
|
|||||||
* Kill pane.
|
* Kill pane.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmdq_item *);
|
int cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_kill_pane_entry = {
|
const struct cmd_entry cmd_kill_pane_entry = {
|
||||||
.name = "kill-pane",
|
"kill-pane", "killp",
|
||||||
.alias = "killp",
|
"at:", 0, 0,
|
||||||
|
"[-a] " CMD_TARGET_PANE_USAGE,
|
||||||
.args = { "at:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-a] " CMD_TARGET_PANE_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_kill_pane_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_kill_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct winlink *wl;
|
||||||
struct winlink *wl = target->wl;
|
struct window_pane *loopwp, *nextwp, *wp;
|
||||||
struct window_pane *loopwp, *tmpwp, *wp = target->wp;
|
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||||
server_unzoom_window(wl->window);
|
return (-1);
|
||||||
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
|
|
||||||
if (loopwp == wp)
|
if (window_count_panes(wl->window) == 1) {
|
||||||
continue;
|
/* Only one pane, kill the window. */
|
||||||
server_client_remove_pane(loopwp);
|
server_kill_window(wl->window);
|
||||||
layout_close_pane(loopwp);
|
recalculate_sizes();
|
||||||
window_remove_pane(wl->window, loopwp);
|
return (0);
|
||||||
}
|
|
||||||
server_redraw_window(wl->window);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
server_kill_pane(wp);
|
if (args_has(self->args, 'a')) {
|
||||||
return (CMD_RETURN_NORMAL);
|
loopwp = TAILQ_FIRST(&wl->window->panes);
|
||||||
|
while (loopwp != NULL) {
|
||||||
|
nextwp = TAILQ_NEXT(loopwp, entry);
|
||||||
|
if (loopwp != wp) {
|
||||||
|
layout_close_pane(loopwp);
|
||||||
|
window_remove_pane(wl->window, loopwp);
|
||||||
|
}
|
||||||
|
loopwp = nextwp;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
layout_close_pane(wp);
|
||||||
|
window_remove_pane(wl->window, wp);
|
||||||
|
}
|
||||||
|
server_redraw_window(wl->window);
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -27,35 +27,23 @@
|
|||||||
* Kill the server and do nothing else.
|
* Kill the server and do nothing else.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmdq_item *);
|
int cmd_kill_server_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_kill_server_entry = {
|
const struct cmd_entry cmd_kill_server_entry = {
|
||||||
.name = "kill-server",
|
"kill-server", NULL,
|
||||||
.alias = NULL,
|
"", 0, 0,
|
||||||
|
"",
|
||||||
.args = { "", 0, 0, NULL },
|
0,
|
||||||
.usage = "",
|
NULL,
|
||||||
|
NULL,
|
||||||
.flags = 0,
|
cmd_kill_server_exec
|
||||||
.exec = cmd_kill_server_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_start_server_entry = {
|
/* ARGSUSED */
|
||||||
.name = "start-server",
|
int
|
||||||
.alias = "start",
|
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
|
|
||||||
.args = { "", 0, 0, 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)
|
|
||||||
{
|
{
|
||||||
if (cmd_get_entry(self) == &cmd_kill_server_entry)
|
kill(getpid(), SIGTERM);
|
||||||
kill(getpid(), SIGTERM);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -27,45 +27,29 @@
|
|||||||
* Note this deliberately has no alias to make it hard to hit by accident.
|
* Note this deliberately has no alias to make it hard to hit by accident.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmdq_item *);
|
int cmd_kill_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_kill_session_entry = {
|
const struct cmd_entry cmd_kill_session_entry = {
|
||||||
.name = "kill-session",
|
"kill-session", NULL,
|
||||||
.alias = NULL,
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
.args = { "aCt:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_kill_session_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_kill_session_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct session *s;
|
||||||
struct session *s = target->s, *sloop, *stmp;
|
|
||||||
struct winlink *wl;
|
|
||||||
|
|
||||||
if (args_has(args, 'C')) {
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
return (-1);
|
||||||
wl->window->flags &= ~WINDOW_ALERTFLAGS;
|
|
||||||
wl->flags &= ~WINLINK_ALERTFLAGS;
|
server_destroy_session(s);
|
||||||
}
|
session_destroy(s);
|
||||||
server_redraw_session(s);
|
|
||||||
} else if (args_has(args, 'a')) {
|
return (0);
|
||||||
RB_FOREACH_SAFE(sloop, sessions, &sessions, stmp) {
|
|
||||||
if (sloop != s) {
|
|
||||||
server_destroy_session(sloop);
|
|
||||||
session_destroy(sloop, 1, __func__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
server_destroy_session(s);
|
|
||||||
session_destroy(s, 1, __func__);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -24,87 +24,29 @@
|
|||||||
* Destroy window.
|
* Destroy window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmdq_item *);
|
int cmd_kill_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_kill_window_entry = {
|
const struct cmd_entry cmd_kill_window_entry = {
|
||||||
.name = "kill-window",
|
"kill-window", "killw",
|
||||||
.alias = "killw",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
.args = { "at:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-a] " CMD_TARGET_WINDOW_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_kill_window_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_kill_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_unlink_window_entry = {
|
int
|
||||||
.name = "unlink-window",
|
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "unlinkw",
|
|
||||||
|
|
||||||
.args = { "kt:", 0, 0, 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)
|
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct winlink *wl;
|
||||||
struct winlink *wl = target->wl, *loop;
|
|
||||||
struct window *w = wl->window;
|
|
||||||
struct session *s = target->s;
|
|
||||||
u_int found;
|
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_unlink_window_entry) {
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
if (!args_has(args, 'k') && !session_is_linked(s, w)) {
|
return (-1);
|
||||||
cmdq_error(item, "window only linked to one session");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
server_unlink_window(s, wl);
|
|
||||||
recalculate_sizes();
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
server_kill_window(wl->window);
|
||||||
if (RB_PREV(winlinks, &s->windows, wl) == NULL &&
|
recalculate_sizes();
|
||||||
RB_NEXT(winlinks, &s->windows, wl) == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
/* Kill all windows except the current one. */
|
return (0);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
65
cmd-link-window.c
Normal file
65
cmd-link-window.c
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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",
|
||||||
|
"dks:t:", 0, 0,
|
||||||
|
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_link_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *src, *dst;
|
||||||
|
struct winlink *wl;
|
||||||
|
char *cause;
|
||||||
|
int idx, kflag, dflag;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
kflag = args_has(self->args, 'k');
|
||||||
|
dflag = args_has(self->args, 'd');
|
||||||
|
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "can't link window: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,55 +26,33 @@
|
|||||||
* List paste buffers.
|
* List paste buffers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_BUFFERS_TEMPLATE \
|
int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\""
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_buffers_entry = {
|
const struct cmd_entry cmd_list_buffers_entry = {
|
||||||
.name = "list-buffers",
|
"list-buffers", "lsb",
|
||||||
.alias = "lsb",
|
"", 0, 0,
|
||||||
|
"",
|
||||||
.args = { "F:f:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-F format] [-f filter]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_list_buffers_exec
|
||||||
.exec = cmd_list_buffers_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item)
|
int
|
||||||
|
cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
struct format_tree *ft;
|
u_int idx;
|
||||||
const char *template, *filter;
|
char *tmp;
|
||||||
char *line, *expanded;
|
|
||||||
int flag;
|
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
idx = 0;
|
||||||
template = LIST_BUFFERS_TEMPLATE;
|
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
|
||||||
filter = args_get(args, 'f');
|
tmp = paste_print(pb, 50);
|
||||||
|
ctx->print(ctx,
|
||||||
pb = NULL;
|
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||||
while ((pb = paste_walk(pb)) != NULL) {
|
xfree(tmp);
|
||||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
|
||||||
format_defaults_paste_buffer(ft, pb);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@@ -28,75 +27,51 @@
|
|||||||
* List all clients.
|
* List all clients.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_CLIENTS_TEMPLATE \
|
int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{client_name}: #{session_name} " \
|
|
||||||
"[#{client_width}x#{client_height} #{client_termname}] " \
|
|
||||||
"#{?#{!=:#{client_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 *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_clients_entry = {
|
const struct cmd_entry cmd_list_clients_entry = {
|
||||||
.name = "list-clients",
|
"list-clients", "lsc",
|
||||||
.alias = "lsc",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
.args = { "F:f:t:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-F format] [-f filter] " CMD_TARGET_SESSION_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_list_clients_exec
|
||||||
|
|
||||||
.flags = CMD_READONLY|CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_list_clients_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
int
|
||||||
|
cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct client *c;
|
||||||
struct client *c;
|
struct session *s;
|
||||||
struct session *s;
|
u_int i;
|
||||||
struct format_tree *ft;
|
const char *s_utf8;
|
||||||
const char *template, *filter;
|
|
||||||
u_int idx;
|
|
||||||
char *line, *expanded;
|
|
||||||
int flag;
|
|
||||||
|
|
||||||
if (args_has(args, 't'))
|
if (args_has(args, 't')) {
|
||||||
s = target->s;
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
else
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
} else
|
||||||
s = NULL;
|
s = NULL;
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
template = LIST_CLIENTS_TEMPLATE;
|
c = ARRAY_ITEM(&clients, i);
|
||||||
filter = args_get(args, 'f');
|
if (c == NULL || c->session == NULL)
|
||||||
|
|
||||||
idx = 0;
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
|
||||||
if (c->session == NULL || (s != NULL && s != c->session))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
if (c->tty.flags & TTY_UTF8)
|
||||||
format_add(ft, "line", "%u", idx);
|
s_utf8 = " (utf8)";
|
||||||
format_defaults(ft, c, NULL, NULL, NULL);
|
else
|
||||||
|
s_utf8 = "";
|
||||||
|
|
||||||
if (filter != NULL) {
|
if (s != NULL && s != c->session)
|
||||||
expanded = format_expand(ft, filter);
|
continue;
|
||||||
flag = format_true(expanded);
|
ctx->print(ctx, "%s: %s [%ux%u %s]%s", c->tty.path,
|
||||||
free(expanded);
|
c->session->name, c->tty.sx, c->tty.sy,
|
||||||
} else
|
c->tty.termname, s_utf8);
|
||||||
flag = 1;
|
|
||||||
if (flag) {
|
|
||||||
line = format_expand(ft, template);
|
|
||||||
cmdq_print(item, "%s", line);
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
idx++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -16,19 +18,32 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <limits.h>
|
#include "tmux.h"
|
||||||
|
|
||||||
#include "compat.h"
|
/*
|
||||||
|
* List all commands with usages.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_list_commands_entry = {
|
||||||
|
"list-commands", "lscm",
|
||||||
|
"", 0, 0,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_commands_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
int
|
int
|
||||||
getptmfd(void)
|
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
return (INT_MAX);
|
const struct cmd_entry **entryp;
|
||||||
}
|
|
||||||
|
|
||||||
pid_t
|
for (entryp = cmd_table; *entryp != NULL; entryp++)
|
||||||
fdforkpty(__unused int ptmfd, int *master, char *name, struct termios *tio,
|
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
|
||||||
struct winsize *ws)
|
|
||||||
{
|
return (0);
|
||||||
return (forkpty(master, name, tio, ws));
|
|
||||||
}
|
}
|
||||||
405
cmd-list-keys.c
405
cmd-list-keys.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,346 +26,124 @@
|
|||||||
* List key bindings.
|
* List key bindings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *);
|
int cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_keys_commands(struct cmd *,
|
int cmd_list_keys_table(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_keys_entry = {
|
const struct cmd_entry cmd_list_keys_entry = {
|
||||||
.name = "list-keys",
|
"list-keys", "lsk",
|
||||||
.alias = "lsk",
|
"t:", 0, 0,
|
||||||
|
"[-t key-table]",
|
||||||
.args = { "1aNP:T:", 0, 1, NULL },
|
0,
|
||||||
.usage = "[-1aN] [-P prefix-string] [-T key-table] [key]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
cmd_list_keys_exec
|
||||||
.exec = cmd_list_keys_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_commands_entry = {
|
int
|
||||||
.name = "list-commands",
|
cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "lscm",
|
|
||||||
|
|
||||||
.args = { "F:", 0, 1, NULL },
|
|
||||||
.usage = "[-F format] [command]",
|
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_list_keys_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static u_int
|
|
||||||
cmd_list_keys_get_width(const char *tablename, key_code only)
|
|
||||||
{
|
{
|
||||||
struct key_table *table;
|
struct args *args = self->args;
|
||||||
struct key_binding *bd;
|
|
||||||
u_int width, keywidth = 0;
|
|
||||||
|
|
||||||
table = key_bindings_get_table(tablename, 0);
|
|
||||||
if (table == NULL)
|
|
||||||
return (0);
|
|
||||||
bd = key_bindings_first(table);
|
|
||||||
while (bd != NULL) {
|
|
||||||
if ((only != KEYC_UNKNOWN && bd->key != only) ||
|
|
||||||
KEYC_IS_MOUSE(bd->key) ||
|
|
||||||
bd->note == NULL ||
|
|
||||||
*bd->note == '\0') {
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
width = utf8_cstrwidth(key_string_lookup_key(bd->key, 0));
|
|
||||||
if (width > keywidth)
|
|
||||||
keywidth = width;
|
|
||||||
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
}
|
|
||||||
return (keywidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
cmd_list_keys_print_notes(struct cmdq_item *item, struct args *args,
|
|
||||||
const char *tablename, u_int keywidth, key_code only, const char *prefix)
|
|
||||||
{
|
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
|
||||||
struct key_table *table;
|
|
||||||
struct key_binding *bd;
|
struct key_binding *bd;
|
||||||
const char *key;
|
const char *key;
|
||||||
char *tmp, *note;
|
char tmp[BUFSIZ], flags[8];
|
||||||
int found = 0;
|
size_t used;
|
||||||
|
int width, keywidth;
|
||||||
|
|
||||||
table = key_bindings_get_table(tablename, 0);
|
if (args_has(args, 't'))
|
||||||
if (table == NULL)
|
return (cmd_list_keys_table(self, ctx));
|
||||||
return (0);
|
|
||||||
bd = key_bindings_first(table);
|
width = 0;
|
||||||
while (bd != NULL) {
|
*flags = '\0';
|
||||||
if ((only != KEYC_UNKNOWN && bd->key != only) ||
|
|
||||||
KEYC_IS_MOUSE(bd->key) ||
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
((bd->note == NULL || *bd->note == '\0') &&
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
!args_has(args, 'a'))) {
|
if (key == NULL)
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
found = 1;
|
|
||||||
key = key_string_lookup_key(bd->key, 0);
|
|
||||||
|
|
||||||
if (bd->note == NULL || *bd->note == '\0')
|
keywidth = strlen(key);
|
||||||
note = cmd_list_print(bd->cmdlist, 1);
|
if (!(bd->key & KEYC_PREFIX)) {
|
||||||
else
|
if (bd->can_repeat)
|
||||||
note = xstrdup(bd->note);
|
keywidth += 4;
|
||||||
tmp = utf8_padcstr(key, keywidth + 1);
|
|
||||||
if (args_has(args, '1') && tc != NULL) {
|
|
||||||
status_message_set(tc, -1, 1, 0, "%s%s%s", prefix, tmp,
|
|
||||||
note);
|
|
||||||
} else
|
|
||||||
cmdq_print(item, "%s%s%s", prefix, tmp, note);
|
|
||||||
free(tmp);
|
|
||||||
free(note);
|
|
||||||
|
|
||||||
if (args_has(args, '1'))
|
|
||||||
break;
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
}
|
|
||||||
return (found);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
cmd_list_keys_get_prefix(struct args *args, key_code *prefix)
|
|
||||||
{
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
*prefix = options_get_number(global_s_options, "prefix");
|
|
||||||
if (!args_has(args, 'P')) {
|
|
||||||
if (*prefix != KEYC_NONE)
|
|
||||||
xasprintf(&s, "%s ", key_string_lookup_key(*prefix, 0));
|
|
||||||
else
|
|
||||||
s = xstrdup("");
|
|
||||||
} else
|
|
||||||
s = xstrdup(args_get(args, 'P'));
|
|
||||||
return (s);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
|
||||||
struct key_table *table;
|
|
||||||
struct key_binding *bd;
|
|
||||||
const char *tablename, *r, *keystr;
|
|
||||||
char *key, *cp, *tmp, *start, *empty;
|
|
||||||
key_code prefix, only = KEYC_UNKNOWN;
|
|
||||||
int repeat, width, tablewidth, keywidth, found = 0;
|
|
||||||
size_t tmpsize, tmpused, cplen;
|
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_list_commands_entry)
|
|
||||||
return (cmd_list_keys_commands(self, item));
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
tablename = args_get(args, 'T');
|
|
||||||
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) {
|
|
||||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'N')) {
|
|
||||||
if (tablename == NULL) {
|
|
||||||
start = cmd_list_keys_get_prefix(args, &prefix);
|
|
||||||
keywidth = cmd_list_keys_get_width("root", only);
|
|
||||||
if (prefix != KEYC_NONE) {
|
|
||||||
width = cmd_list_keys_get_width("prefix", only);
|
|
||||||
if (width == 0)
|
|
||||||
prefix = KEYC_NONE;
|
|
||||||
else if (width > keywidth)
|
|
||||||
keywidth = width;
|
|
||||||
}
|
|
||||||
empty = utf8_padcstr("", utf8_cstrwidth(start));
|
|
||||||
|
|
||||||
found = cmd_list_keys_print_notes(item, args, "root",
|
|
||||||
keywidth, only, empty);
|
|
||||||
if (prefix != KEYC_NONE) {
|
|
||||||
if (cmd_list_keys_print_notes(item, args,
|
|
||||||
"prefix", keywidth, only, start))
|
|
||||||
found = 1;
|
|
||||||
}
|
|
||||||
free(empty);
|
|
||||||
} else {
|
|
||||||
if (args_has(args, 'P'))
|
|
||||||
start = xstrdup(args_get(args, 'P'));
|
|
||||||
else
|
else
|
||||||
start = xstrdup("");
|
keywidth += 3;
|
||||||
keywidth = cmd_list_keys_get_width(tablename, only);
|
} else if (bd->can_repeat)
|
||||||
found = cmd_list_keys_print_notes(item, args, tablename,
|
keywidth += 3;
|
||||||
keywidth, only, start);
|
if (keywidth > width)
|
||||||
|
width = keywidth;
|
||||||
}
|
|
||||||
free(start);
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repeat = 0;
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
tablewidth = keywidth = 0;
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
table = key_bindings_first_table();
|
if (key == NULL)
|
||||||
while (table != NULL) {
|
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
|
||||||
table = key_bindings_next_table(table);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
bd = key_bindings_first(table);
|
|
||||||
while (bd != NULL) {
|
|
||||||
if (only != KEYC_UNKNOWN && bd->key != only) {
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
key = args_escape(key_string_lookup_key(bd->key, 0));
|
|
||||||
|
|
||||||
if (bd->flags & KEY_BINDING_REPEAT)
|
if (!(bd->key & KEYC_PREFIX)) {
|
||||||
repeat = 1;
|
if (bd->can_repeat)
|
||||||
|
xsnprintf(flags, sizeof flags, "-rn ");
|
||||||
width = utf8_cstrwidth(table->name);
|
|
||||||
if (width > tablewidth)
|
|
||||||
tablewidth = width;
|
|
||||||
width = utf8_cstrwidth(key);
|
|
||||||
if (width > keywidth)
|
|
||||||
keywidth = width;
|
|
||||||
|
|
||||||
free(key);
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
}
|
|
||||||
table = key_bindings_next_table(table);
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpsize = 256;
|
|
||||||
tmp = xmalloc(tmpsize);
|
|
||||||
|
|
||||||
table = key_bindings_first_table();
|
|
||||||
while (table != NULL) {
|
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
|
||||||
table = key_bindings_next_table(table);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
bd = key_bindings_first(table);
|
|
||||||
while (bd != NULL) {
|
|
||||||
if (only != KEYC_UNKNOWN && bd->key != only) {
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
found = 1;
|
|
||||||
key = args_escape(key_string_lookup_key(bd->key, 0));
|
|
||||||
|
|
||||||
if (!repeat)
|
|
||||||
r = "";
|
|
||||||
else if (bd->flags & KEY_BINDING_REPEAT)
|
|
||||||
r = "-r ";
|
|
||||||
else
|
else
|
||||||
r = " ";
|
xsnprintf(flags, sizeof flags, "-n ");
|
||||||
tmpused = xsnprintf(tmp, tmpsize, "%s-T ", r);
|
} else if (bd->can_repeat)
|
||||||
|
xsnprintf(flags, sizeof flags, "-r ");
|
||||||
|
|
||||||
cp = utf8_padcstr(table->name, tablewidth);
|
used = xsnprintf(tmp, sizeof tmp, "%s%*s ",
|
||||||
cplen = strlen(cp) + 1;
|
flags, (int) (width - strlen(flags)), key);
|
||||||
while (tmpused + cplen + 1 >= tmpsize) {
|
if (used >= sizeof tmp)
|
||||||
tmpsize *= 2;
|
continue;
|
||||||
tmp = xrealloc(tmp, tmpsize);
|
|
||||||
}
|
|
||||||
strlcat(tmp, cp, tmpsize);
|
|
||||||
tmpused = strlcat(tmp, " ", tmpsize);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
cp = utf8_padcstr(key, keywidth);
|
cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used);
|
||||||
cplen = strlen(cp) + 1;
|
ctx->print(ctx, "bind-key %s", tmp);
|
||||||
while (tmpused + cplen + 1 >= tmpsize) {
|
|
||||||
tmpsize *= 2;
|
|
||||||
tmp = xrealloc(tmp, tmpsize);
|
|
||||||
}
|
|
||||||
strlcat(tmp, cp, tmpsize);
|
|
||||||
tmpused = strlcat(tmp, " ", tmpsize);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
cp = cmd_list_print(bd->cmdlist, 1);
|
|
||||||
cplen = strlen(cp);
|
|
||||||
while (tmpused + cplen + 1 >= tmpsize) {
|
|
||||||
tmpsize *= 2;
|
|
||||||
tmp = xrealloc(tmp, tmpsize);
|
|
||||||
}
|
|
||||||
strlcat(tmp, cp, tmpsize);
|
|
||||||
free(cp);
|
|
||||||
|
|
||||||
if (args_has(args, '1') && tc != NULL) {
|
|
||||||
status_message_set(tc, -1, 1, 0, "bind-key %s",
|
|
||||||
tmp);
|
|
||||||
} else
|
|
||||||
cmdq_print(item, "bind-key %s", tmp);
|
|
||||||
free(key);
|
|
||||||
|
|
||||||
if (args_has(args, '1'))
|
|
||||||
break;
|
|
||||||
bd = key_bindings_next(table, bd);
|
|
||||||
}
|
|
||||||
table = key_bindings_next_table(table);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(tmp);
|
return (0);
|
||||||
|
|
||||||
out:
|
|
||||||
if (only != KEYC_UNKNOWN && !found) {
|
|
||||||
cmdq_error(item, "unknown key: %s", args_string(args, 0));
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
const struct cmd_entry **entryp;
|
const char *tablename;
|
||||||
const struct cmd_entry *entry;
|
const struct mode_key_table *mtab;
|
||||||
struct format_tree *ft;
|
struct mode_key_binding *mbind;
|
||||||
const char *template, *s, *command;
|
const char *key, *cmdstr, *mode;
|
||||||
char *line;
|
int width, keywidth, any_mode;
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL) {
|
tablename = args_get(args, 't');
|
||||||
template = "#{command_list_name}"
|
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||||
"#{?command_list_alias, (#{command_list_alias}),} "
|
ctx->error(ctx, "unknown key table: %s", tablename);
|
||||||
"#{command_list_usage}";
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
width = 0;
|
||||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
any_mode = 0;
|
||||||
|
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
|
key = key_string_lookup_key(mbind->key);
|
||||||
|
if (key == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
command = args_string(args, 0);
|
if (mbind->mode != 0)
|
||||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
any_mode = 1;
|
||||||
entry = *entryp;
|
|
||||||
if (command != NULL &&
|
|
||||||
(strcmp(entry->name, command) != 0 &&
|
|
||||||
(entry->alias == NULL ||
|
|
||||||
strcmp(entry->alias, command) != 0)))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
format_add(ft, "command_list_name", "%s", entry->name);
|
keywidth = strlen(key);
|
||||||
if (entry->alias != NULL)
|
if (keywidth > width)
|
||||||
s = entry->alias;
|
width = keywidth;
|
||||||
else
|
|
||||||
s = "";
|
|
||||||
format_add(ft, "command_list_alias", "%s", s);
|
|
||||||
if (entry->usage != NULL)
|
|
||||||
s = entry->usage;
|
|
||||||
else
|
|
||||||
s = "";
|
|
||||||
format_add(ft, "command_list_usage", "%s", s);
|
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
|
||||||
if (*line != '\0')
|
|
||||||
cmdq_print(item, "%s", line);
|
|
||||||
free(line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
format_free(ft);
|
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
return (CMD_RETURN_NORMAL);
|
key = key_string_lookup_key(mbind->key);
|
||||||
|
if (key == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
mode = "";
|
||||||
|
if (mbind->mode != 0)
|
||||||
|
mode = "c";
|
||||||
|
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
|
||||||
|
if (cmdstr != NULL) {
|
||||||
|
ctx->print(ctx, "bind-key -%st %s%s %*s %s",
|
||||||
|
mode, any_mode && *mode == '\0' ? " " : "",
|
||||||
|
mtab->name, (int) width, key, cmdstr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
167
cmd-list-panes.c
167
cmd-list-panes.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -26,123 +26,112 @@
|
|||||||
* List panes on given window.
|
* List panes on given window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmdq_item *);
|
int cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static void cmd_list_panes_server(struct cmd *, struct cmdq_item *);
|
void cmd_list_panes_server(struct cmd_ctx *);
|
||||||
static void cmd_list_panes_session(struct cmd *, struct session *,
|
void cmd_list_panes_session(struct session *, struct cmd_ctx *, int);
|
||||||
struct cmdq_item *, int);
|
void cmd_list_panes_window(
|
||||||
static void cmd_list_panes_window(struct cmd *, struct session *,
|
struct session *, struct winlink *, struct cmd_ctx *, int);
|
||||||
struct winlink *, struct cmdq_item *, int);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_panes_entry = {
|
const struct cmd_entry cmd_list_panes_entry = {
|
||||||
.name = "list-panes",
|
"list-panes", "lsp",
|
||||||
.alias = "lsp",
|
"ast:", 0, 0,
|
||||||
|
"[-as] [-t target]",
|
||||||
.args = { "asF:f:t:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-as] [-F format] [-f filter] " CMD_TARGET_WINDOW_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_list_panes_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_list_panes_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct session *s;
|
||||||
struct session *s = target->s;
|
struct winlink *wl;
|
||||||
struct winlink *wl = target->wl;
|
|
||||||
|
|
||||||
if (args_has(args, 'a'))
|
if (args_has(args, 'a'))
|
||||||
cmd_list_panes_server(self, item);
|
cmd_list_panes_server(ctx);
|
||||||
else if (args_has(args, 's'))
|
else if (args_has(args, 's')) {
|
||||||
cmd_list_panes_session(self, s, item, 1);
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
else
|
if (s == NULL)
|
||||||
cmd_list_panes_window(self, s, wl, item, 0);
|
return (-1);
|
||||||
|
cmd_list_panes_session(s, ctx, 1);
|
||||||
|
} else {
|
||||||
|
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
cmd_list_panes_window(s, wl, ctx, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_list_panes_server(struct cmd *self, struct cmdq_item *item)
|
cmd_list_panes_server(struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct session *s;
|
struct session *s;
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions)
|
RB_FOREACH(s, sessions, &sessions)
|
||||||
cmd_list_panes_session(self, s, item, 2);
|
cmd_list_panes_session(s, ctx, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_list_panes_session(struct cmd *self, struct session *s,
|
cmd_list_panes_session(struct session *s, struct cmd_ctx *ctx, int type)
|
||||||
struct cmdq_item *item, int type)
|
|
||||||
{
|
{
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
|
|
||||||
RB_FOREACH(wl, winlinks, &s->windows)
|
RB_FOREACH(wl, winlinks, &s->windows)
|
||||||
cmd_list_panes_window(self, s, wl, item, type);
|
cmd_list_panes_window(s, wl, ctx, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
cmd_list_panes_window(
|
||||||
struct cmdq_item *item, int type)
|
struct session *s, struct winlink *wl, struct cmd_ctx *ctx, int type)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int n;
|
struct grid *gd;
|
||||||
struct format_tree *ft;
|
struct grid_line *gl;
|
||||||
const char *template, *filter;
|
u_int i, n;
|
||||||
char *line, *expanded;
|
unsigned long long size;
|
||||||
int flag;
|
|
||||||
|
|
||||||
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');
|
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
gd = wp->base.grid;
|
||||||
format_add(ft, "line", "%u", n);
|
|
||||||
format_defaults(ft, NULL, s, wl, wp);
|
|
||||||
|
|
||||||
if (filter != NULL) {
|
size = 0;
|
||||||
expanded = format_expand(ft, filter);
|
for (i = 0; i < gd->hsize; i++) {
|
||||||
flag = format_true(expanded);
|
gl = &gd->linedata[i];
|
||||||
free(expanded);
|
size += gl->cellsize * sizeof *gl->celldata;
|
||||||
} else
|
size += gl->utf8size * sizeof *gl->utf8data;
|
||||||
flag = 1;
|
|
||||||
if (flag) {
|
|
||||||
line = format_expand(ft, template);
|
|
||||||
cmdq_print(item, "%s", line);
|
|
||||||
free(line);
|
|
||||||
}
|
}
|
||||||
|
size += gd->hsize * sizeof *gd->linedata;
|
||||||
|
|
||||||
format_free(ft);
|
switch (type) {
|
||||||
|
case 0:
|
||||||
|
ctx->print(ctx,
|
||||||
|
"%u: [%ux%u] [history %u/%u, %llu bytes] %%%u%s%s",
|
||||||
|
n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size,
|
||||||
|
wp->id, wp == wp->window->active ? " (active)" : "",
|
||||||
|
wp->fd == -1 ? " (dead)" : "");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
ctx->print(ctx,
|
||||||
|
"%d.%u: [%ux%u] [history %u/%u, %llu bytes] "
|
||||||
|
"%%%u%s%s", wl->idx,
|
||||||
|
n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size,
|
||||||
|
wp->id, wp == wp->window->active ? " (active)" : "",
|
||||||
|
wp->fd == -1 ? " (dead)" : "");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ctx->print(ctx,
|
||||||
|
"%s:%d.%u: [%ux%u] [history %u/%u, %llu bytes] "
|
||||||
|
"%%%u%s%s", s->name, wl->idx,
|
||||||
|
n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size,
|
||||||
|
wp->id, wp == wp->window->active ? " (active)" : "",
|
||||||
|
wp->fd == -1 ? " (dead)" : "");
|
||||||
|
break;
|
||||||
|
}
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@@ -28,63 +27,45 @@
|
|||||||
* List all sessions.
|
* List all sessions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_SESSIONS_TEMPLATE \
|
int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{session_name}: #{session_windows} windows " \
|
|
||||||
"(created #{t:session_created})" \
|
|
||||||
"#{?session_grouped, (group ,}" \
|
|
||||||
"#{session_group}#{?session_grouped,),}" \
|
|
||||||
"#{?session_attached, (attached),}"
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_sessions_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_sessions_entry = {
|
const struct cmd_entry cmd_list_sessions_entry = {
|
||||||
.name = "list-sessions",
|
"list-sessions", "ls",
|
||||||
.alias = "ls",
|
"", 0, 0,
|
||||||
|
"",
|
||||||
.args = { "F:f:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-F format] [-f filter]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_list_sessions_exec
|
||||||
.exec = cmd_list_sessions_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item)
|
int
|
||||||
|
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
struct session *s;
|
struct session *s;
|
||||||
u_int n;
|
struct session_group *sg;
|
||||||
struct format_tree *ft;
|
char *tim, tmp[64];
|
||||||
const char *template, *filter;
|
u_int idx;
|
||||||
char *line, *expanded;
|
time_t t;
|
||||||
int flag;
|
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
|
||||||
template = LIST_SESSIONS_TEMPLATE;
|
|
||||||
filter = args_get(args, 'f');
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
sg = session_group_find(s);
|
||||||
format_add(ft, "line", "%u", n);
|
if (sg == NULL)
|
||||||
format_defaults(ft, NULL, s, NULL, NULL);
|
*tmp = '\0';
|
||||||
|
else {
|
||||||
if (filter != NULL) {
|
idx = session_group_index(sg);
|
||||||
expanded = format_expand(ft, filter);
|
xsnprintf(tmp, sizeof tmp, " (group %u)", idx);
|
||||||
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);
|
t = s->creation_time.tv_sec;
|
||||||
n++;
|
tim = ctime(&t);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s",
|
||||||
|
s->name, winlink_count(&s->windows), tim, s->sx, s->sy,
|
||||||
|
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -27,104 +26,67 @@
|
|||||||
* List windows on given session.
|
* List windows on given session.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIST_WINDOWS_TEMPLATE \
|
int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{window_index}: #{window_name}#{window_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 *);
|
void cmd_list_windows_server(struct cmd_ctx *);
|
||||||
|
void cmd_list_windows_session(struct session *, struct cmd_ctx *, int);
|
||||||
static void cmd_list_windows_server(struct cmd *, struct cmdq_item *);
|
|
||||||
static void cmd_list_windows_session(struct cmd *, struct session *,
|
|
||||||
struct cmdq_item *, int);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_list_windows_entry = {
|
const struct cmd_entry cmd_list_windows_entry = {
|
||||||
.name = "list-windows",
|
"list-windows", "lsw",
|
||||||
.alias = "lsw",
|
"at:", 0, 0,
|
||||||
|
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
.args = { "F:f:at:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-a] [-F format] [-f filter] " CMD_TARGET_SESSION_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_list_windows_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_list_windows_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct session *s;
|
||||||
|
|
||||||
if (args_has(args, 'a'))
|
if (args_has(args, 'a'))
|
||||||
cmd_list_windows_server(self, item);
|
cmd_list_windows_server(ctx);
|
||||||
else
|
else {
|
||||||
cmd_list_windows_session(self, target->s, item, 0);
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
cmd_list_windows_session(s, ctx, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_list_windows_server(struct cmd *self, struct cmdq_item *item)
|
cmd_list_windows_server(struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct session *s;
|
struct session *s;
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions)
|
RB_FOREACH(s, sessions, &sessions)
|
||||||
cmd_list_windows_session(self, s, item, 1);
|
cmd_list_windows_session(s, ctx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_list_windows_session(struct cmd *self, struct session *s,
|
cmd_list_windows_session(struct session *s, struct cmd_ctx *ctx, int type)
|
||||||
struct cmdq_item *item, int type)
|
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct winlink *wl;
|
||||||
struct winlink *wl;
|
char *layout;
|
||||||
u_int n;
|
|
||||||
struct format_tree *ft;
|
|
||||||
const char *template, *filter;
|
|
||||||
char *line, *expanded;
|
|
||||||
int flag;
|
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
|
||||||
if (template == NULL) {
|
|
||||||
switch (type) {
|
|
||||||
case 0:
|
|
||||||
template = LIST_WINDOWS_TEMPLATE;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
template = LIST_WINDOWS_WITH_SESSION_TEMPLATE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
filter = args_get(args, 'f');
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
layout = layout_dump(wl->window);
|
||||||
format_add(ft, "line", "%u", n);
|
if (type) {
|
||||||
format_defaults(ft, NULL, s, wl, NULL);
|
ctx->print(ctx, "%s:%d: %s [%ux%u] [layout %s]%s",
|
||||||
|
s->name, wl->idx, wl->window->name, wl->window->sx,
|
||||||
if (filter != NULL) {
|
wl->window->sy, layout,
|
||||||
expanded = format_expand(ft, filter);
|
wl == s->curw ? " (active)" : "");
|
||||||
flag = format_true(expanded);
|
} else {
|
||||||
free(expanded);
|
ctx->print(ctx, "%d: %s [%ux%u] [layout %s]%s",
|
||||||
} else
|
wl->idx, wl->window->name, wl->window->sx,
|
||||||
flag = 1;
|
wl->window->sy, layout,
|
||||||
if (flag) {
|
wl == s->curw ? " (active)" : "");
|
||||||
line = format_expand(ft, template);
|
|
||||||
cmdq_print(item, "%s", line);
|
|
||||||
free(line);
|
|
||||||
}
|
}
|
||||||
|
xfree(layout);
|
||||||
format_free(ft);
|
|
||||||
n++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
150
cmd-list.c
Normal file
150
cmd-list.c
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
struct cmd_list *
|
||||||
|
cmd_list_parse(int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd *cmd;
|
||||||
|
int i, lastsplit;
|
||||||
|
size_t arglen, new_argc;
|
||||||
|
char **copy_argv, **new_argv;
|
||||||
|
|
||||||
|
copy_argv = cmd_copy_argv(argc, argv);
|
||||||
|
|
||||||
|
cmdlist = xmalloc(sizeof *cmdlist);
|
||||||
|
cmdlist->references = 1;
|
||||||
|
TAILQ_INIT(&cmdlist->list);
|
||||||
|
|
||||||
|
lastsplit = 0;
|
||||||
|
for (i = 0; i < argc; i++) {
|
||||||
|
arglen = strlen(copy_argv[i]);
|
||||||
|
if (arglen == 0 || copy_argv[i][arglen - 1] != ';')
|
||||||
|
continue;
|
||||||
|
copy_argv[i][arglen - 1] = '\0';
|
||||||
|
|
||||||
|
if (arglen > 1 && copy_argv[i][arglen - 2] == '\\') {
|
||||||
|
copy_argv[i][arglen - 2] = ';';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_argc = i - lastsplit;
|
||||||
|
new_argv = copy_argv + lastsplit;
|
||||||
|
if (arglen != 1)
|
||||||
|
new_argc++;
|
||||||
|
|
||||||
|
cmd = cmd_parse(new_argc, new_argv, cause);
|
||||||
|
if (cmd == NULL)
|
||||||
|
goto bad;
|
||||||
|
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||||
|
|
||||||
|
lastsplit = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastsplit != argc) {
|
||||||
|
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit, cause);
|
||||||
|
if (cmd == NULL)
|
||||||
|
goto bad;
|
||||||
|
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_free_argv(argc, copy_argv);
|
||||||
|
return (cmdlist);
|
||||||
|
|
||||||
|
bad:
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
cmd_free_argv(argc, copy_argv);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
int n, retval;
|
||||||
|
|
||||||
|
retval = 0;
|
||||||
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
|
if ((n = cmd_exec(cmd, ctx)) == -1)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A 1 return value means the command client is being attached
|
||||||
|
* (sent MSG_READY).
|
||||||
|
*/
|
||||||
|
if (n == 1) {
|
||||||
|
retval = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The command client has been attached, so mangle the
|
||||||
|
* context to treat any following commands as if they
|
||||||
|
* were called from inside.
|
||||||
|
*/
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->curclient = ctx->cmdclient;
|
||||||
|
ctx->cmdclient = NULL;
|
||||||
|
|
||||||
|
ctx->error = key_bindings_error;
|
||||||
|
ctx->print = key_bindings_print;
|
||||||
|
ctx->info = key_bindings_info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_list_free(struct cmd_list *cmdlist)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
|
||||||
|
if (--cmdlist->references != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (!TAILQ_EMPTY(&cmdlist->list)) {
|
||||||
|
cmd = TAILQ_FIRST(&cmdlist->list);
|
||||||
|
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
||||||
|
cmd_free(cmd);
|
||||||
|
}
|
||||||
|
xfree(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
size_t off;
|
||||||
|
|
||||||
|
off = 0;
|
||||||
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
|
if (off >= len)
|
||||||
|
break;
|
||||||
|
off += cmd_print(cmd, buf + off, len - off);
|
||||||
|
if (off >= len)
|
||||||
|
break;
|
||||||
|
if (TAILQ_NEXT(cmd, qentry) != NULL)
|
||||||
|
off += xsnprintf(buf + off, len - off, " ; ");
|
||||||
|
}
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -28,86 +27,148 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Loads a paste buffer from a file.
|
* Loads a session paste buffer from a file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmdq_item *);
|
int cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_load_buffer_callback(struct client *, void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_load_buffer_entry = {
|
const struct cmd_entry cmd_load_buffer_entry = {
|
||||||
.name = "load-buffer",
|
"load-buffer", "loadb",
|
||||||
.alias = "loadb",
|
"b:", 1, 1,
|
||||||
|
CMD_BUFFER_USAGE " path",
|
||||||
.args = { "b:t:w", 1, 1, NULL },
|
0,
|
||||||
.usage = CMD_BUFFER_USAGE " " CMD_TARGET_CLIENT_USAGE " path",
|
NULL,
|
||||||
|
NULL,
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
|
cmd_load_buffer_exec
|
||||||
.exec = cmd_load_buffer_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_load_buffer_data {
|
int
|
||||||
struct client *client;
|
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
struct cmd_load_buffer_data *cdata = data;
|
struct args *args = self->args;
|
||||||
struct client *tc = cdata->client;
|
struct client *c = ctx->cmdclient;
|
||||||
struct cmdq_item *item = cdata->item;
|
FILE *f;
|
||||||
void *bdata = EVBUFFER_DATA(buffer);
|
const char *path;
|
||||||
size_t bsize = EVBUFFER_LENGTH(buffer);
|
char *pdata, *new_pdata, *cause;
|
||||||
void *copy;
|
size_t psize;
|
||||||
char *cause;
|
u_int limit;
|
||||||
|
int ch, buffer;
|
||||||
|
int *buffer_ptr;
|
||||||
|
|
||||||
if (!closed)
|
if (!args_has(args, 'b'))
|
||||||
|
buffer = -1;
|
||||||
|
else {
|
||||||
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
path = args->argv[0];
|
||||||
|
if (strcmp(path, "-") == 0) {
|
||||||
|
if (c == NULL) {
|
||||||
|
ctx->error(ctx, "%s: can't read from stdin", path);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (c->flags & CLIENT_TERMINAL) {
|
||||||
|
ctx->error(ctx, "%s: stdin is a tty", path);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (c->stdin_fd == -1) {
|
||||||
|
ctx->error(ctx, "%s: can't read from stdin", path);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer_ptr = xmalloc(sizeof *buffer_ptr);
|
||||||
|
*buffer_ptr = buffer;
|
||||||
|
|
||||||
|
c->stdin_data = buffer_ptr;
|
||||||
|
c->stdin_callback = cmd_load_buffer_callback;
|
||||||
|
|
||||||
|
c->references++;
|
||||||
|
bufferevent_enable(c->stdin_event, EV_READ);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((f = fopen(path, "rb")) == NULL) {
|
||||||
|
ctx->error(ctx, "%s: %s", path, strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pdata = NULL;
|
||||||
|
psize = 0;
|
||||||
|
while ((ch = getc(f)) != EOF) {
|
||||||
|
/* Do not let the server die due to memory exhaustion. */
|
||||||
|
if ((new_pdata = realloc(pdata, psize + 2)) == NULL) {
|
||||||
|
ctx->error(ctx, "realloc error: %s", strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
pdata = new_pdata;
|
||||||
|
pdata[psize++] = ch;
|
||||||
|
}
|
||||||
|
if (ferror(f)) {
|
||||||
|
ctx->error(ctx, "%s: read error", path);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (pdata != NULL)
|
||||||
|
pdata[psize] = '\0';
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
limit = options_get_number(&global_options, "buffer-limit");
|
||||||
|
if (buffer == -1) {
|
||||||
|
paste_add(&global_buffers, pdata, psize, limit);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (pdata != NULL)
|
||||||
|
xfree(pdata);
|
||||||
|
if (f != NULL)
|
||||||
|
fclose(f);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_load_buffer_callback(struct client *c, void *data)
|
||||||
|
{
|
||||||
|
int *buffer = data;
|
||||||
|
char *pdata;
|
||||||
|
size_t psize;
|
||||||
|
u_int limit;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Event callback has already checked client is not dead and reduced
|
||||||
|
* its reference count. But tell it to exit.
|
||||||
|
*/
|
||||||
|
c->flags |= CLIENT_EXIT;
|
||||||
|
|
||||||
|
psize = EVBUFFER_LENGTH(c->stdin_event->input);
|
||||||
|
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL) {
|
||||||
|
xfree(data);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
cmdq_error(item, "%s: %s", path, strerror(error));
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
cmdq_continue(item);
|
bufferevent_read(c->stdin_event, pdata, psize);
|
||||||
|
pdata[psize] = '\0';
|
||||||
|
|
||||||
free(cdata->name);
|
limit = options_get_number(&global_options, "buffer-limit");
|
||||||
free(cdata);
|
if (*buffer == -1)
|
||||||
}
|
paste_add(&global_buffers, pdata, psize, limit);
|
||||||
|
else if (paste_replace(&global_buffers, *buffer, pdata, psize) != 0) {
|
||||||
static enum cmd_retval
|
/* No context so can't use server_client_msg_error. */
|
||||||
cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
evbuffer_add_printf(
|
||||||
{
|
c->stderr_event->output, "no buffer %d\n", *buffer);
|
||||||
struct args *args = cmd_get_args(self);
|
bufferevent_enable(c->stderr_event, EV_WRITE);
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path = format_single_from_target(item, args_string(args, 0));
|
xfree(data);
|
||||||
file_read(cmdq_get_client(item), path, cmd_load_buffer_done, cdata);
|
|
||||||
free(path);
|
|
||||||
|
|
||||||
return (CMD_RETURN_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,62 +18,68 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lock commands.
|
* Lock commands.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmdq_item *);
|
int cmd_lock_server_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_lock_server_entry = {
|
const struct cmd_entry cmd_lock_server_entry = {
|
||||||
.name = "lock-server",
|
"lock-server", "lock",
|
||||||
.alias = "lock",
|
"", 0, 0,
|
||||||
|
"",
|
||||||
.args = { "", 0, 0, NULL },
|
0,
|
||||||
.usage = "",
|
NULL,
|
||||||
|
NULL,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_lock_server_exec
|
||||||
.exec = cmd_lock_server_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_lock_session_entry = {
|
const struct cmd_entry cmd_lock_session_entry = {
|
||||||
.name = "lock-session",
|
"lock-session", "locks",
|
||||||
.alias = "locks",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
.args = { "t:", 0, 0, NULL },
|
0,
|
||||||
.usage = CMD_TARGET_SESSION_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_lock_server_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_lock_server_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_lock_client_entry = {
|
const struct cmd_entry cmd_lock_client_entry = {
|
||||||
.name = "lock-client",
|
"lock-client", "lockc",
|
||||||
.alias = "lockc",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
.args = { "t:", 0, 0, NULL },
|
0,
|
||||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
cmd_lock_server_exec
|
||||||
.exec = cmd_lock_server_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
/* ARGSUSED */
|
||||||
cmd_lock_server_exec(struct cmd *self, struct cmdq_item *item)
|
int
|
||||||
|
cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct args *args = self->args;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_lock_server_entry)
|
if (self->entry == &cmd_lock_server_entry)
|
||||||
server_lock();
|
server_lock();
|
||||||
else if (cmd_get_entry(self) == &cmd_lock_session_entry)
|
else if (self->entry == &cmd_lock_session_entry) {
|
||||||
server_lock_session(target->s);
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||||
else
|
return (-1);
|
||||||
server_lock_client(tc);
|
server_lock_session(s);
|
||||||
|
} else {
|
||||||
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
server_lock_client(c);
|
||||||
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -26,97 +26,41 @@
|
|||||||
* Move a window.
|
* Move a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmdq_item *);
|
int cmd_move_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_move_window_entry = {
|
const struct cmd_entry cmd_move_window_entry = {
|
||||||
.name = "move-window",
|
"move-window", "movew",
|
||||||
.alias = "movew",
|
"dks:t:", 0, 0,
|
||||||
|
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
.args = { "abdkrs:t:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-abdkr] " CMD_SRCDST_WINDOW_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.source = { 's', CMD_FIND_WINDOW, 0 },
|
cmd_move_window_exec
|
||||||
/* -t is special */
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_move_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_link_window_entry = {
|
int
|
||||||
.name = "link-window",
|
cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "linkw",
|
|
||||||
|
|
||||||
.args = { "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)
|
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *source = cmdq_get_source(item);
|
struct session *src, *dst;
|
||||||
struct cmd_find_state target;
|
struct winlink *wl;
|
||||||
const char *tflag = args_get(args, 't');
|
char *cause;
|
||||||
struct session *src = source->s;
|
int idx, kflag, dflag;
|
||||||
struct session *dst;
|
|
||||||
struct winlink *wl = source->wl;
|
|
||||||
char *cause;
|
|
||||||
int idx, kflag, dflag, sflag, before;
|
|
||||||
|
|
||||||
if (args_has(args, 'r')) {
|
if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
|
||||||
if (cmd_find_target(&target, item, tflag, CMD_FIND_SESSION,
|
return (-1);
|
||||||
CMD_FIND_QUIET) != 0)
|
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2)
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
|
|
||||||
session_renumber_windows(target.s);
|
|
||||||
recalculate_sizes();
|
|
||||||
server_status_session(target.s);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
kflag = args_has(self->args, 'k');
|
||||||
|
dflag = args_has(self->args, 'd');
|
||||||
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||||
cmdq_error(item, "%s", cause);
|
ctx->error(ctx, "can't move window: %s", cause);
|
||||||
free(cause);
|
xfree(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (cmd_get_entry(self) == &cmd_move_window_entry)
|
server_unlink_window(src, wl);
|
||||||
server_unlink_window(src, wl);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Renumber the winlinks in the src session only, the destination
|
|
||||||
* session already has the correct winlink id to us, either
|
|
||||||
* automatically or specified by -s.
|
|
||||||
*/
|
|
||||||
if (!sflag && options_get_number(src->options, "renumber-windows"))
|
|
||||||
session_renumber_windows(src);
|
|
||||||
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <pwd.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
@@ -31,340 +30,248 @@
|
|||||||
* Create a new session and attach to the current terminal unless -d is given.
|
* Create a new session and attach to the current terminal unless -d is given.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define NEW_SESSION_TEMPLATE "#{session_name}:"
|
int cmd_new_session_check(struct args *);
|
||||||
|
int cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
static enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_new_session_entry = {
|
const struct cmd_entry cmd_new_session_entry = {
|
||||||
.name = "new-session",
|
"new-session", "new",
|
||||||
.alias = "new",
|
"dn:s:t:x:y:", 0, 1,
|
||||||
|
"[-d] [-n window-name] [-s session-name] [-t target-session] "
|
||||||
.args = { "Ac:dDe:EF:f:n:Ps:t:x:Xy:", 0, -1, NULL },
|
"[-x width] [-y height] [command]",
|
||||||
.usage = "[-AdDEPX] [-c start-directory] [-e environment] [-F format] "
|
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
|
||||||
"[-f flags] [-n window-name] [-s session-name] "
|
NULL,
|
||||||
CMD_TARGET_SESSION_USAGE " [-x width] [-y height] "
|
cmd_new_session_check,
|
||||||
"[shell-command]",
|
cmd_new_session_exec
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER,
|
|
||||||
.exec = cmd_new_session_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_has_session_entry = {
|
int
|
||||||
.name = "has-session",
|
cmd_new_session_check(struct args *args)
|
||||||
.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)
|
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n')))
|
||||||
struct cmd_find_state *current = cmdq_get_current(item);
|
return (-1);
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
return (0);
|
||||||
struct client *c = cmdq_get_client(item);
|
}
|
||||||
struct session *s, *as, *groupwith = NULL;
|
|
||||||
struct environ *env;
|
int
|
||||||
struct options *oo;
|
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s, *old_s, *groupwith;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct environ env;
|
||||||
struct termios tio, *tiop;
|
struct termios tio, *tiop;
|
||||||
struct session_group *sg = NULL;
|
struct passwd *pw;
|
||||||
const char *errstr, *template, *group, *tmp;
|
const char *newname, *target, *update, *cwd, *errstr;
|
||||||
char *cause, *cwd = NULL, *cp, *newname = NULL;
|
char *overrides, *cmd, *cause;
|
||||||
char *name, *prefix = NULL;
|
int detached, idx;
|
||||||
int detached, already_attached, is_control = 0;
|
u_int sx, sy, i;
|
||||||
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;
|
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_has_session_entry) {
|
newname = args_get(args, 's');
|
||||||
/*
|
if (newname != NULL) {
|
||||||
* cmd_find_target() will fail if the session cannot be found,
|
if (!session_check_name(newname)) {
|
||||||
* so always return success here.
|
ctx->error(ctx, "bad session name: %s", newname);
|
||||||
*/
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (session_find(newname) != NULL) {
|
||||||
}
|
ctx->error(ctx, "duplicate session: %s", newname);
|
||||||
if (args_has(args, 'A')) {
|
return (-1);
|
||||||
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, NULL,
|
|
||||||
args_has(args, 'E'), args_get(args, 'f'));
|
|
||||||
free(newname);
|
|
||||||
return (retval);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newname != NULL && session_find(newname) != NULL) {
|
|
||||||
cmdq_error(item, "duplicate session: %s", newname);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Is this going to be part of a session group? */
|
target = args_get(args, 't');
|
||||||
group = args_get(args, 't');
|
if (target != NULL) {
|
||||||
if (group != NULL) {
|
groupwith = cmd_find_session(ctx, target, 0);
|
||||||
groupwith = target->s;
|
|
||||||
if (groupwith == NULL)
|
if (groupwith == NULL)
|
||||||
sg = session_group_find(group);
|
return (-1);
|
||||||
else
|
} else
|
||||||
sg = session_group_contains(groupwith);
|
groupwith = NULL;
|
||||||
if (sg != NULL)
|
|
||||||
prefix = xstrdup(sg->name);
|
/*
|
||||||
else if (groupwith != NULL)
|
* There are three cases:
|
||||||
prefix = xstrdup(groupwith->name);
|
*
|
||||||
else {
|
* 1. If cmdclient is non-NULL, new-session has been called from the
|
||||||
prefix = session_check_name(group);
|
* command-line - cmdclient is to become a new attached, interactive
|
||||||
if (prefix == NULL) {
|
* client. Unless -d is given, the terminal must be opened and then
|
||||||
cmdq_error(item, "invalid session group: %s",
|
* the client sent MSG_READY.
|
||||||
group);
|
*
|
||||||
goto fail;
|
* 2. If cmdclient is NULL, new-session has been called from an
|
||||||
}
|
* existing client (such as a key binding).
|
||||||
}
|
*
|
||||||
}
|
* 3. Both are NULL, the command was in the configuration file. Treat
|
||||||
|
* this as if -d was given even if it was not.
|
||||||
|
*
|
||||||
|
* In all cases, a new additional session needs to be created and
|
||||||
|
* (unless -d) set as the current session for the client.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Set -d if no client. */
|
/* Set -d if no client. */
|
||||||
detached = args_has(args, 'd');
|
detached = args_has(args, 'd');
|
||||||
if (c == NULL)
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||||
detached = 1;
|
detached = 1;
|
||||||
else if (c->flags & CLIENT_CONTROL)
|
|
||||||
is_control = 1;
|
|
||||||
|
|
||||||
/* Is this client already attached? */
|
|
||||||
already_attached = 0;
|
|
||||||
if (c != NULL && c->session != NULL)
|
|
||||||
already_attached = 1;
|
|
||||||
|
|
||||||
/* Get the new session working directory. */
|
|
||||||
if ((tmp = args_get(args, 'c')) != NULL)
|
|
||||||
cwd = format_single(item, tmp, c, NULL, NULL, NULL);
|
|
||||||
else
|
|
||||||
cwd = xstrdup(server_client_get_cwd(c, NULL));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this is a new client, check for nesting and save the termios
|
* Save the termios settings, part of which is used for new windows in
|
||||||
* settings (part of which is used for new windows in this session).
|
* this session.
|
||||||
*
|
*
|
||||||
* tcgetattr() is used rather than using tty.tio since if the client is
|
* This is read again with tcgetattr() rather than using tty.tio as if
|
||||||
* detached, tty_open won't be called. It must be done before opening
|
* detached, tty_open won't be called. Because of this, it must be done
|
||||||
* the terminal as that calls tcsetattr() to prepare for tmux taking
|
* before opening the terminal as that calls tcsetattr() to prepare for
|
||||||
* over.
|
* tmux taking over.
|
||||||
*/
|
*/
|
||||||
if (!detached &&
|
if (ctx->cmdclient != NULL && ctx->cmdclient->tty.fd != -1) {
|
||||||
!already_attached &&
|
if (tcgetattr(ctx->cmdclient->tty.fd, &tio) != 0)
|
||||||
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");
|
fatal("tcgetattr failed");
|
||||||
tiop = &tio;
|
tiop = &tio;
|
||||||
} else
|
} else
|
||||||
tiop = NULL;
|
tiop = NULL;
|
||||||
|
|
||||||
/* Open the terminal if necessary. */
|
/* Open the terminal if necessary. */
|
||||||
if (!detached && !already_attached) {
|
if (!detached && ctx->cmdclient != NULL) {
|
||||||
if (server_client_open(c, &cause) != 0) {
|
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||||
cmdq_error(item, "open terminal failed: %s", cause);
|
ctx->error(ctx, "not a terminal");
|
||||||
free(cause);
|
return (-1);
|
||||||
goto fail;
|
}
|
||||||
|
|
||||||
|
overrides =
|
||||||
|
options_get_string(&global_s_options, "terminal-overrides");
|
||||||
|
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "open terminal failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get default session size. */
|
/* Get the new session working directory. */
|
||||||
if (args_has(args, 'x')) {
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
tmp = args_get(args, 'x');
|
cwd = ctx->cmdclient->cwd;
|
||||||
if (strcmp(tmp, "-") == 0) {
|
else {
|
||||||
if (c != NULL)
|
pw = getpwuid(getuid());
|
||||||
dsx = c->tty.sx;
|
if (pw->pw_dir != NULL && *pw->pw_dir != '\0')
|
||||||
else
|
cwd = pw->pw_dir;
|
||||||
dsx = 80;
|
else
|
||||||
} else {
|
cwd = "/";
|
||||||
dsx = strtonum(tmp, 1, USHRT_MAX, &errstr);
|
}
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "width %s", errstr);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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. */
|
/* Find new session size. */
|
||||||
if (!detached && !is_control) {
|
if (detached) {
|
||||||
sx = c->tty.sx;
|
sx = 80;
|
||||||
sy = c->tty.sy;
|
sy = 24;
|
||||||
if (sy > 0 && options_get_number(global_s_options, "status"))
|
if (args_has(args, 'x')) {
|
||||||
sy--;
|
sx = strtonum(
|
||||||
} else {
|
args_get(args, 'x'), 1, USHRT_MAX, &errstr);
|
||||||
tmp = options_get_string(global_s_options, "default-size");
|
if (errstr != NULL) {
|
||||||
if (sscanf(tmp, "%ux%u", &sx, &sy) != 2) {
|
ctx->error(ctx, "width %s", errstr);
|
||||||
sx = dsx;
|
return (-1);
|
||||||
sy = dsy;
|
}
|
||||||
} else {
|
|
||||||
if (args_has(args, 'x'))
|
|
||||||
sx = dsx;
|
|
||||||
if (args_has(args, 'y'))
|
|
||||||
sy = dsy;
|
|
||||||
}
|
}
|
||||||
|
if (args_has(args, 'y')) {
|
||||||
|
sy = strtonum(
|
||||||
|
args_get(args, 'y'), 1, USHRT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
ctx->error(ctx, "height %s", errstr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (ctx->cmdclient != NULL) {
|
||||||
|
sx = ctx->cmdclient->tty.sx;
|
||||||
|
sy = ctx->cmdclient->tty.sy;
|
||||||
|
} else {
|
||||||
|
sx = ctx->curclient->tty.sx;
|
||||||
|
sy = ctx->curclient->tty.sy;
|
||||||
}
|
}
|
||||||
|
if (sy > 0 && options_get_number(&global_s_options, "status"))
|
||||||
|
sy--;
|
||||||
if (sx == 0)
|
if (sx == 0)
|
||||||
sx = 1;
|
sx = 1;
|
||||||
if (sy == 0)
|
if (sy == 0)
|
||||||
sy = 1;
|
sy = 1;
|
||||||
|
|
||||||
|
/* Figure out the command for the new window. */
|
||||||
|
if (target != NULL)
|
||||||
|
cmd = NULL;
|
||||||
|
else if (args->argc != 0)
|
||||||
|
cmd = args->argv[0];
|
||||||
|
else
|
||||||
|
cmd = options_get_string(&global_s_options, "default-command");
|
||||||
|
|
||||||
|
/* Construct the environment. */
|
||||||
|
environ_init(&env);
|
||||||
|
update = options_get_string(&global_s_options, "update-environment");
|
||||||
|
if (ctx->cmdclient != NULL)
|
||||||
|
environ_update(update, &ctx->cmdclient->environ, &env);
|
||||||
|
|
||||||
/* Create the new session. */
|
/* Create the new session. */
|
||||||
oo = options_create(global_s_options);
|
idx = -1 - options_get_number(&global_s_options, "base-index");
|
||||||
if (args_has(args, 'x') || args_has(args, 'y')) {
|
s = session_create(newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
||||||
if (!args_has(args, 'x'))
|
if (s == NULL) {
|
||||||
dsx = sx;
|
ctx->error(ctx, "create session failed: %s", cause);
|
||||||
if (!args_has(args, 'y'))
|
xfree(cause);
|
||||||
dsy = sy;
|
return (-1);
|
||||||
options_set_string(oo, "default-size", 0, "%ux%u", dsx, dsy);
|
|
||||||
}
|
}
|
||||||
env = environ_create();
|
environ_free(&env);
|
||||||
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. */
|
/* Set the initial window name if one given. */
|
||||||
sc.item = item;
|
if (cmd != NULL && args_has(args, 'n')) {
|
||||||
sc.s = s;
|
w = s->curw->window;
|
||||||
if (!detached)
|
|
||||||
sc.tc = c;
|
|
||||||
|
|
||||||
sc.name = args_get(args, 'n');
|
xfree(w->name);
|
||||||
args_to_vector(args, &sc.argc, &sc.argv);
|
w->name = xstrdup(args_get(args, 'n'));
|
||||||
|
|
||||||
sc.idx = -1;
|
options_set_number(&w->options, "automatic-rename", 0);
|
||||||
sc.cwd = args_get(args, 'c');
|
|
||||||
|
|
||||||
sc.flags = 0;
|
|
||||||
|
|
||||||
if (spawn_window(&sc, &cause) == NULL) {
|
|
||||||
session_destroy(s, 0, __func__);
|
|
||||||
cmdq_error(item, "create window failed: %s", cause);
|
|
||||||
free(cause);
|
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If a target session is given, this is to be part of a session group,
|
* If a target session is given, this is to be part of a session group,
|
||||||
* so add it to the group and synchronize.
|
* so add it to the group and synchronize.
|
||||||
*/
|
*/
|
||||||
if (group != NULL) {
|
if (groupwith != NULL) {
|
||||||
if (sg == NULL) {
|
session_group_add(groupwith, s);
|
||||||
if (groupwith != NULL) {
|
|
||||||
sg = session_group_new(groupwith->name);
|
|
||||||
session_group_add(sg, groupwith);
|
|
||||||
} else
|
|
||||||
sg = session_group_new(group);
|
|
||||||
}
|
|
||||||
session_group_add(sg, s);
|
|
||||||
session_group_synchronize_to(s);
|
session_group_synchronize_to(s);
|
||||||
session_select(s, RB_MIN(winlinks, &s->windows)->idx);
|
session_select(s, RB_ROOT(&s->windows)->idx);
|
||||||
}
|
}
|
||||||
notify_session("session-created", s);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the client to the new session. If a command client exists, it is
|
* Set the client to the new session. If a command client exists, it is
|
||||||
* taking this session and needs to get MSG_READY and stay around.
|
* taking this session and needs to get MSG_READY and stay around.
|
||||||
*/
|
*/
|
||||||
if (!detached) {
|
if (!detached) {
|
||||||
if (args_has(args, 'f'))
|
if (ctx->cmdclient != NULL) {
|
||||||
server_client_set_flags(c, args_get(args, 'f'));
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
if (!already_attached) {
|
|
||||||
if (~c->flags & CLIENT_CONTROL)
|
old_s = ctx->cmdclient->session;
|
||||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
if (old_s != NULL)
|
||||||
} else if (c->session != NULL)
|
ctx->cmdclient->last_session = old_s;
|
||||||
c->last_session = c->session;
|
ctx->cmdclient->session = s;
|
||||||
server_client_set_session(c, s);
|
session_update_activity(s);
|
||||||
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
server_redraw_client(ctx->cmdclient);
|
||||||
server_client_set_key_table(c, NULL);
|
} else {
|
||||||
|
old_s = ctx->curclient->session;
|
||||||
|
if (old_s != NULL)
|
||||||
|
ctx->curclient->last_session = old_s;
|
||||||
|
ctx->curclient->session = s;
|
||||||
|
session_update_activity(s);
|
||||||
|
server_redraw_client(ctx->curclient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
server_update_socket();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If there are still configuration file errors to display, put the new
|
||||||
|
* session's current window into more mode and display them now.
|
||||||
|
*/
|
||||||
|
if (cfg_finished && !ARRAY_EMPTY(&cfg_causes)) {
|
||||||
|
wp = s->curw->window->active;
|
||||||
|
window_pane_set_mode(wp, &window_copy_mode);
|
||||||
|
window_copy_init_for_output(wp);
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
|
||||||
|
cause = ARRAY_ITEM(&cfg_causes, i);
|
||||||
|
window_copy_add(wp, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
ARRAY_FREE(&cfg_causes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print if requested. */
|
return (!detached); /* 1 means don't tell command client to exit */
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
197
cmd-new-window.c
197
cmd-new-window.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,11 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -30,130 +26,101 @@
|
|||||||
* Create a new window.
|
* Create a new window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define NEW_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
int cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_new_window_entry = {
|
const struct cmd_entry cmd_new_window_entry = {
|
||||||
.name = "new-window",
|
"new-window", "neww",
|
||||||
.alias = "neww",
|
"adkn:Pt:", 0, 1,
|
||||||
|
"[-adk] [-n window-name] [-t target-window] [command]",
|
||||||
.args = { "abc:de:F:kn:PSt:", 0, -1, NULL },
|
0,
|
||||||
.usage = "[-abdkPS] [-c start-directory] [-e environment] [-F format] "
|
NULL,
|
||||||
"[-n window-name] " CMD_TARGET_WINDOW_USAGE " [shell-command]",
|
NULL,
|
||||||
|
cmd_new_window_exec
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_new_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct client *c = cmdq_get_client(item);
|
struct session *s;
|
||||||
struct cmd_find_state *current = cmdq_get_current(item);
|
struct winlink *wl;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
char *cmd, *cwd, *cause;
|
||||||
struct spawn_context sc = { 0 };
|
int idx, last, detached;
|
||||||
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;
|
|
||||||
|
|
||||||
/*
|
if (args_has(args, 'a')) {
|
||||||
* If -S and -n are given and -t is not and a single window with this
|
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
||||||
* name already exists, select it.
|
if (wl == NULL)
|
||||||
*/
|
return (-1);
|
||||||
name = args_get(args, 'n');
|
idx = wl->idx + 1;
|
||||||
if (args_has(args, 'S') && name != NULL && target->idx == -1) {
|
|
||||||
expanded = format_single(item, name, c, s, NULL, NULL);
|
/* Find the next free index. */
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
for (last = idx; last < INT_MAX; last++) {
|
||||||
if (strcmp(wl->window->name, expanded) != 0)
|
if (winlink_find_by_index(&s->windows, last) == NULL)
|
||||||
continue;
|
break;
|
||||||
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 (last == INT_MAX) {
|
||||||
if (new_wl != NULL) {
|
ctx->error(ctx, "no free window indexes");
|
||||||
if (args_has(args, 'd'))
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
}
|
||||||
if (session_set_current(s, new_wl) == 0)
|
|
||||||
server_redraw_session(s);
|
/* Move everything from last - 1 to idx up a bit. */
|
||||||
if (c != NULL && c->session != NULL)
|
for (; last > idx; last--) {
|
||||||
s->curw->window->latest = c;
|
wl = winlink_find_by_index(&s->windows, last - 1);
|
||||||
recalculate_sizes();
|
server_link_window(s, wl, s, last, 0, 0, NULL);
|
||||||
return (CMD_RETURN_NORMAL);
|
server_unlink_window(s, wl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &s)) == -2)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
detached = args_has(args, 'd');
|
||||||
|
|
||||||
|
wl = NULL;
|
||||||
|
if (idx != -1)
|
||||||
|
wl = winlink_find_by_index(&s->windows, idx);
|
||||||
|
if (wl != NULL && args_has(args, 'k')) {
|
||||||
|
/*
|
||||||
|
* Can't use session_detach as it will destroy session if this
|
||||||
|
* makes it empty.
|
||||||
|
*/
|
||||||
|
wl->flags &= ~WINLINK_ALERTFLAGS;
|
||||||
|
winlink_stack_remove(&s->lastw, wl);
|
||||||
|
winlink_remove(&s->windows, wl);
|
||||||
|
|
||||||
|
/* Force select/redraw if current. */
|
||||||
|
if (wl == s->curw) {
|
||||||
|
detached = 0;
|
||||||
|
s->curw = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
before = args_has(args, 'b');
|
if (args->argc == 0)
|
||||||
if (args_has(args, 'a') || before) {
|
cmd = options_get_string(&s->options, "default-command");
|
||||||
idx = winlink_shuffle_up(s, wl, before);
|
else
|
||||||
if (idx == -1)
|
cmd = args->argv[0];
|
||||||
idx = target->idx;
|
cwd = options_get_string(&s->options, "default-path");
|
||||||
|
if (*cwd == '\0') {
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
|
cwd = ctx->cmdclient->cwd;
|
||||||
|
else
|
||||||
|
cwd = s->cwd;
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.item = item;
|
if (idx == -1)
|
||||||
sc.s = s;
|
idx = -1 - options_get_number(&s->options, "base-index");
|
||||||
sc.tc = tc;
|
wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause);
|
||||||
|
if (wl == NULL) {
|
||||||
sc.name = args_get(args, 'n');
|
ctx->error(ctx, "create window failed: %s", cause);
|
||||||
args_to_vector(args, &sc.argc, &sc.argv);
|
xfree(cause);
|
||||||
sc.environ = environ_create();
|
return (-1);
|
||||||
|
|
||||||
av = args_first_value(args, 'e');
|
|
||||||
while (av != NULL) {
|
|
||||||
environ_put(sc.environ, av->string, 0);
|
|
||||||
av = args_next_value(av);
|
|
||||||
}
|
}
|
||||||
|
if (!detached) {
|
||||||
sc.idx = idx;
|
session_select(s, wl->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);
|
server_redraw_session_group(s);
|
||||||
} else
|
} else
|
||||||
server_status_session_group(s);
|
server_status_session_group(s);
|
||||||
|
|
||||||
if (args_has(args, 'P')) {
|
if (args_has(args, 'P'))
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
ctx->print(ctx, "%s:%u", s->name, wl->idx);
|
||||||
template = NEW_WINDOW_TEMPLATE;
|
return (0);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
1717
cmd-parse.y
1717
cmd-parse.y
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -27,53 +27,57 @@
|
|||||||
* Paste paste buffer if present.
|
* Paste paste buffer if present.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmdq_item *);
|
int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_paste_buffer_filter(
|
||||||
|
struct window_pane *, const char *, size_t, const char *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_paste_buffer_entry = {
|
const struct cmd_entry cmd_paste_buffer_entry = {
|
||||||
.name = "paste-buffer",
|
"paste-buffer", "pasteb",
|
||||||
.alias = "pasteb",
|
"db:rs:t:", 0, 0,
|
||||||
|
"[-dr] [-s separator] [-b buffer-index] [-t target-pane]",
|
||||||
.args = { "db:prs:t:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
|
NULL,
|
||||||
CMD_TARGET_PANE_USAGE,
|
NULL,
|
||||||
|
cmd_paste_buffer_exec
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_paste_buffer_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct window_pane *wp;
|
||||||
struct window_pane *wp = target->wp;
|
struct session *s;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
const char *sepstr, *bufname, *bufdata, *bufend, *line;
|
const char *sepstr;
|
||||||
size_t seplen, bufsize;
|
char *cause;
|
||||||
int bracket = args_has(args, 'p');
|
int buffer;
|
||||||
|
|
||||||
if (window_pane_exited(wp)) {
|
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
||||||
cmdq_error(item, "target pane has exited");
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
bufname = NULL;
|
if (!args_has(args, 'b'))
|
||||||
if (args_has(args, 'b'))
|
buffer = -1;
|
||||||
bufname = args_get(args, 'b');
|
|
||||||
|
|
||||||
if (bufname == NULL)
|
|
||||||
pb = paste_get_top(NULL);
|
|
||||||
else {
|
else {
|
||||||
pb = paste_get_name(bufname);
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
if (pb == NULL) {
|
if (cause != NULL) {
|
||||||
cmdq_error(item, "no buffer %s", bufname);
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
return (CMD_RETURN_ERROR);
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pb != NULL && ~wp->flags & PANE_INPUTOFF) {
|
if (buffer == -1)
|
||||||
|
pb = paste_get_top(&global_buffers);
|
||||||
|
else {
|
||||||
|
pb = paste_get_index(&global_buffers, buffer);
|
||||||
|
if (pb == NULL) {
|
||||||
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pb != NULL) {
|
||||||
sepstr = args_get(args, 's');
|
sepstr = args_get(args, 's');
|
||||||
if (sepstr == NULL) {
|
if (sepstr == NULL) {
|
||||||
if (args_has(args, 'r'))
|
if (args_has(args, 'r'))
|
||||||
@@ -81,33 +85,37 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
else
|
else
|
||||||
sepstr = "\r";
|
sepstr = "\r";
|
||||||
}
|
}
|
||||||
seplen = strlen(sepstr);
|
cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr);
|
||||||
|
|
||||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
|
||||||
bufferevent_write(wp->event, "\033[200~", 6);
|
|
||||||
|
|
||||||
bufdata = paste_buffer_data(pb, &bufsize);
|
|
||||||
bufend = bufdata + bufsize;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
line = memchr(bufdata, '\n', bufend - bufdata);
|
|
||||||
if (line == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
bufferevent_write(wp->event, bufdata, line - bufdata);
|
|
||||||
bufferevent_write(wp->event, sepstr, seplen);
|
|
||||||
|
|
||||||
bufdata = line + 1;
|
|
||||||
}
|
|
||||||
if (bufdata != bufend)
|
|
||||||
bufferevent_write(wp->event, bufdata, bufend - bufdata);
|
|
||||||
|
|
||||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
|
||||||
bufferevent_write(wp->event, "\033[201~", 6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pb != NULL && args_has(args, 'd'))
|
/* Delete the buffer if -d. */
|
||||||
paste_free(pb);
|
if (args_has(args, 'd')) {
|
||||||
|
if (buffer == -1)
|
||||||
|
paste_free_top(&global_buffers);
|
||||||
|
else
|
||||||
|
paste_free_index(&global_buffers, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add bytes to a buffer and filter '\n' according to separator. */
|
||||||
|
void
|
||||||
|
cmd_paste_buffer_filter(
|
||||||
|
struct window_pane *wp, const char *data, size_t size, const char *sep)
|
||||||
|
{
|
||||||
|
const char *end = data + size;
|
||||||
|
const char *lf;
|
||||||
|
size_t seplen;
|
||||||
|
|
||||||
|
seplen = strlen(sep);
|
||||||
|
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
||||||
|
if (lf != data)
|
||||||
|
bufferevent_write(wp->event, data, lf - data);
|
||||||
|
bufferevent_write(wp->event, sep, seplen);
|
||||||
|
data = lf + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end != data)
|
||||||
|
bufferevent_write(wp->event, data, end - data);
|
||||||
}
|
}
|
||||||
|
|||||||
197
cmd-pipe-pane.c
197
cmd-pipe-pane.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -33,45 +31,34 @@
|
|||||||
* Open pipe to redirect pane output. If already open, close first.
|
* Open pipe to redirect pane output. If already open, close first.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmdq_item *);
|
int cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static void cmd_pipe_pane_read_callback(struct bufferevent *, void *);
|
void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
||||||
static void cmd_pipe_pane_write_callback(struct bufferevent *, void *);
|
|
||||||
static void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_pipe_pane_entry = {
|
const struct cmd_entry cmd_pipe_pane_entry = {
|
||||||
.name = "pipe-pane",
|
"pipe-pane", "pipep",
|
||||||
.alias = "pipep",
|
"ot:", 0, 1,
|
||||||
|
CMD_TARGET_PANE_USAGE "[-o] [command]",
|
||||||
.args = { "IOot:", 0, 1, NULL },
|
0,
|
||||||
.usage = "[-IOo] " CMD_TARGET_PANE_USAGE " [shell-command]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_pipe_pane_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_pipe_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct client *c;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct window_pane *wp;
|
||||||
struct window_pane *wp = target->wp;
|
char *command;
|
||||||
struct session *s = target->s;
|
int old_fd, pipe_fd[2], null_fd;
|
||||||
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 ((c = cmd_find_client(ctx, NULL)) == NULL)
|
||||||
if (window_pane_exited(wp)) {
|
return (-1);
|
||||||
cmdq_error(item, "target pane has exited");
|
|
||||||
return (CMD_RETURN_ERROR);
|
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
}
|
return (-1);
|
||||||
|
|
||||||
/* Destroy the old pipe. */
|
/* Destroy the old pipe. */
|
||||||
old_fd = wp->pipe_fd;
|
old_fd = wp->pipe_fd;
|
||||||
@@ -79,16 +66,11 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
bufferevent_free(wp->pipe_event);
|
bufferevent_free(wp->pipe_event);
|
||||||
close(wp->pipe_fd);
|
close(wp->pipe_fd);
|
||||||
wp->pipe_fd = -1;
|
wp->pipe_fd = -1;
|
||||||
|
|
||||||
if (window_pane_destroy_ready(wp)) {
|
|
||||||
server_destroy_pane(wp, 1);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no pipe command, that is enough. */
|
/* If no pipe command, that is enough. */
|
||||||
if (args_count(args) == 0 || *args_string(args, 0) == '\0')
|
if (args->argc == 0 || *args->argv[0] == '\0')
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* With -o, only open the new pipe if there was no previous one. This
|
* With -o, only open the new pipe if there was no previous one. This
|
||||||
@@ -96,135 +78,68 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
*
|
*
|
||||||
* bind ^p pipep -o 'cat >>~/output'
|
* bind ^p pipep -o 'cat >>~/output'
|
||||||
*/
|
*/
|
||||||
if (args_has(args, 'o') && old_fd != -1)
|
if (args_has(self->args, 'o') && old_fd != -1)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
|
|
||||||
/* What do we want to do? Neither -I or -O is -O. */
|
|
||||||
if (args_has(args, 'I')) {
|
|
||||||
in = 1;
|
|
||||||
out = args_has(args, 'O');
|
|
||||||
} else {
|
|
||||||
in = 0;
|
|
||||||
out = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Open the new pipe. */
|
/* Open the new pipe. */
|
||||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
||||||
cmdq_error(item, "socketpair error: %s", strerror(errno));
|
ctx->error(ctx, "socketpair error: %s", strerror(errno));
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Expand the command. */
|
|
||||||
ft = format_create(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. */
|
/* Fork the child. */
|
||||||
sigfillset(&set);
|
|
||||||
sigprocmask(SIG_BLOCK, &set, &oldset);
|
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
ctx->error(ctx, "fork error: %s", strerror(errno));
|
||||||
cmdq_error(item, "fork error: %s", strerror(errno));
|
return (-1);
|
||||||
|
|
||||||
free(cmd);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
case 0:
|
case 0:
|
||||||
/* Child process. */
|
/* Child process. */
|
||||||
proc_clear_signals(server_proc, 1);
|
|
||||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
|
||||||
close(pipe_fd[0]);
|
close(pipe_fd[0]);
|
||||||
|
clear_signals(1);
|
||||||
|
|
||||||
null_fd = open(_PATH_DEVNULL, O_WRONLY);
|
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
||||||
if (out) {
|
_exit(1);
|
||||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
if (pipe_fd[1] != STDIN_FILENO)
|
||||||
_exit(1);
|
close(pipe_fd[1]);
|
||||||
} else {
|
|
||||||
if (dup2(null_fd, STDIN_FILENO) == -1)
|
null_fd = open(_PATH_DEVNULL, O_WRONLY, 0);
|
||||||
_exit(1);
|
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
||||||
}
|
_exit(1);
|
||||||
if (in) {
|
|
||||||
if (dup2(pipe_fd[1], STDOUT_FILENO) == -1)
|
|
||||||
_exit(1);
|
|
||||||
if (pipe_fd[1] != STDOUT_FILENO)
|
|
||||||
close(pipe_fd[1]);
|
|
||||||
} else {
|
|
||||||
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
|
||||||
_exit(1);
|
|
||||||
}
|
|
||||||
if (dup2(null_fd, STDERR_FILENO) == -1)
|
if (dup2(null_fd, STDERR_FILENO) == -1)
|
||||||
_exit(1);
|
_exit(1);
|
||||||
|
if (null_fd != STDOUT_FILENO && null_fd != STDERR_FILENO)
|
||||||
|
close(null_fd);
|
||||||
|
|
||||||
closefrom(STDERR_FILENO + 1);
|
closefrom(STDERR_FILENO + 1);
|
||||||
|
|
||||||
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
|
command = status_replace(
|
||||||
|
c, NULL, NULL, NULL, args->argv[0], time(NULL), 0);
|
||||||
|
execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
default:
|
default:
|
||||||
/* Parent process. */
|
/* Parent process. */
|
||||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
|
||||||
close(pipe_fd[1]);
|
close(pipe_fd[1]);
|
||||||
|
|
||||||
wp->pipe_fd = pipe_fd[0];
|
wp->pipe_fd = pipe_fd[0];
|
||||||
memcpy(wpo, &wp->offset, sizeof *wpo);
|
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
|
||||||
|
|
||||||
|
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
||||||
|
NULL, NULL, cmd_pipe_pane_error_callback, wp);
|
||||||
|
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
||||||
|
|
||||||
setblocking(wp->pipe_fd, 0);
|
setblocking(wp->pipe_fd, 0);
|
||||||
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
return (0);
|
||||||
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
|
/* ARGSUSED */
|
||||||
cmd_pipe_pane_read_callback(__unused struct bufferevent *bufev, void *data)
|
void
|
||||||
|
cmd_pipe_pane_error_callback(
|
||||||
|
unused struct bufferevent *bufev, unused short what, void *data)
|
||||||
{
|
{
|
||||||
struct window_pane *wp = data;
|
struct window_pane *wp = data;
|
||||||
struct evbuffer *evb = wp->pipe_event->input;
|
|
||||||
size_t available;
|
|
||||||
|
|
||||||
available = EVBUFFER_LENGTH(evb);
|
|
||||||
log_debug("%%%u pipe read %zu", wp->id, available);
|
|
||||||
|
|
||||||
bufferevent_write(wp->event, EVBUFFER_DATA(evb), available);
|
|
||||||
evbuffer_drain(evb, available);
|
|
||||||
|
|
||||||
if (window_pane_destroy_ready(wp))
|
|
||||||
server_destroy_pane(wp, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_pipe_pane_write_callback(__unused struct bufferevent *bufev, void *data)
|
|
||||||
{
|
|
||||||
struct window_pane *wp = data;
|
|
||||||
|
|
||||||
log_debug("%%%u pipe empty", wp->id);
|
|
||||||
|
|
||||||
if (window_pane_destroy_ready(wp))
|
|
||||||
server_destroy_pane(wp, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_pipe_pane_error_callback(__unused struct bufferevent *bufev,
|
|
||||||
__unused short what, void *data)
|
|
||||||
{
|
|
||||||
struct window_pane *wp = data;
|
|
||||||
|
|
||||||
log_debug("%%%u pipe error", wp->id);
|
|
||||||
|
|
||||||
bufferevent_free(wp->pipe_event);
|
bufferevent_free(wp->pipe_event);
|
||||||
close(wp->pipe_fd);
|
close(wp->pipe_fd);
|
||||||
wp->pipe_fd = -1;
|
wp->pipe_fd = -1;
|
||||||
|
|
||||||
if (window_pane_destroy_ready(wp))
|
|
||||||
server_destroy_pane(wp, 1);
|
|
||||||
}
|
}
|
||||||
|
|||||||
890
cmd-queue.c
890
cmd-queue.c
@@ -1,890 +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)
|
|
||||||
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, int parse, struct evbuffer *evb)
|
|
||||||
{
|
|
||||||
server_client_print(item->client, parse, 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, 0, 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, "%s", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(msg);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,287 +18,34 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Refresh client.
|
* Refresh client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_refresh_client_exec(struct cmd *,
|
int cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_refresh_client_entry = {
|
const struct cmd_entry cmd_refresh_client_entry = {
|
||||||
.name = "refresh-client",
|
"refresh-client", "refresh",
|
||||||
.alias = "refresh",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
.args = { "A:B:cC:Df:F:l::LRSt:U", 0, 1, NULL },
|
0,
|
||||||
.usage = "[-cDlLRSU] [-A pane:state] [-B name:what:format] "
|
NULL,
|
||||||
"[-C XxY] [-f flags] " CMD_TARGET_CLIENT_USAGE " [adjustment]",
|
NULL,
|
||||||
|
cmd_refresh_client_exec
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
|
||||||
.exec = cmd_refresh_client_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
int
|
||||||
cmd_refresh_client_update_subscription(struct client *tc, const char *value)
|
cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
char *copy, *split, *name, *what;
|
struct args *args = self->args;
|
||||||
enum control_sub_type subtype;
|
struct client *c;
|
||||||
int subid = -1;
|
|
||||||
|
|
||||||
copy = name = xstrdup(value);
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
if ((split = strchr(copy, ':')) == NULL) {
|
return (-1);
|
||||||
control_remove_sub(tc, copy);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
*split++ = '\0';
|
|
||||||
|
|
||||||
what = split;
|
server_redraw_client(c);
|
||||||
if ((split = strchr(what, ':')) == NULL)
|
|
||||||
goto out;
|
|
||||||
*split++ = '\0';
|
|
||||||
|
|
||||||
if (strcmp(what, "%*") == 0)
|
return (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 enum cmd_retval
|
|
||||||
cmd_refresh_client_clipboard(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
|
||||||
const char *p;
|
|
||||||
u_int i;
|
|
||||||
struct cmd_find_state fs;
|
|
||||||
|
|
||||||
p = args_get(args, 'l');
|
|
||||||
if (p == NULL) {
|
|
||||||
if (tc->flags & CLIENT_CLIPBOARDBUFFER)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
tc->flags |= CLIENT_CLIPBOARDBUFFER;
|
|
||||||
} else {
|
|
||||||
if (cmd_find_target(&fs, item, p, CMD_FIND_PANE, 0) != 0)
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
for (i = 0; i < tc->clipboard_npanes; i++) {
|
|
||||||
if (tc->clipboard_panes[i] == fs.wp->id)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i != tc->clipboard_npanes)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
tc->clipboard_panes = xreallocarray(tc->clipboard_panes,
|
|
||||||
tc->clipboard_npanes + 1, sizeof *tc->clipboard_panes);
|
|
||||||
tc->clipboard_panes[tc->clipboard_npanes++] = fs.wp->id;
|
|
||||||
}
|
|
||||||
tty_clipboard_query(&tc->tty);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
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'))
|
|
||||||
return (cmd_refresh_client_clipboard(self, item));
|
|
||||||
|
|
||||||
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, '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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -27,55 +26,44 @@
|
|||||||
* Change session name.
|
* Change session name.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_rename_session_exec(struct cmd *,
|
int cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_rename_session_entry = {
|
const struct cmd_entry cmd_rename_session_entry = {
|
||||||
.name = "rename-session",
|
"rename-session", "rename",
|
||||||
.alias = "rename",
|
"t:", 1, 1,
|
||||||
|
CMD_TARGET_SESSION_USAGE " new-name",
|
||||||
.args = { "t:", 1, 1, NULL },
|
0,
|
||||||
.usage = CMD_TARGET_SESSION_USAGE " new-name",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_rename_session_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_rename_session_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct session *s;
|
||||||
struct session *s = target->s;
|
const char *newname;
|
||||||
char *newname, *tmp;
|
|
||||||
|
|
||||||
tmp = format_single_from_target(item, args_string(args, 0));
|
newname = args->argv[0];
|
||||||
newname = session_check_name(tmp);
|
if (!session_check_name(newname)) {
|
||||||
if (newname == NULL) {
|
ctx->error(ctx, "bad session name: %s", newname);
|
||||||
cmdq_error(item, "invalid session: %s", tmp);
|
return (-1);
|
||||||
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) {
|
if (session_find(newname) != NULL) {
|
||||||
cmdq_error(item, "duplicate session: %s", newname);
|
ctx->error(ctx, "duplicate session: %s", newname);
|
||||||
free(newname);
|
return (-1);
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
RB_REMOVE(sessions, &sessions, s);
|
RB_REMOVE(sessions, &sessions, s);
|
||||||
free(s->name);
|
xfree(s->name);
|
||||||
s->name = newname;
|
s->name = xstrdup(newname);
|
||||||
RB_INSERT(sessions, &sessions, s);
|
RB_INSERT(sessions, &sessions, s);
|
||||||
|
|
||||||
server_status_session(s);
|
server_status_session(s);
|
||||||
notify_session("session-renamed", s);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -26,37 +26,33 @@
|
|||||||
* Rename a window.
|
* Rename a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_rename_window_exec(struct cmd *,
|
int cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_rename_window_entry = {
|
const struct cmd_entry cmd_rename_window_entry = {
|
||||||
.name = "rename-window",
|
"rename-window", "renamew",
|
||||||
.alias = "renamew",
|
"t:", 1, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " new-name",
|
||||||
.args = { "t:", 1, 1, NULL },
|
0,
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE " new-name",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_rename_window_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_rename_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct session *s;
|
||||||
struct winlink *wl = target->wl;
|
struct winlink *wl;
|
||||||
char *newname;
|
|
||||||
|
|
||||||
newname = format_single_from_target(item, args_string(args, 0));
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
||||||
window_set_name(wl->window, newname);
|
return (-1);
|
||||||
options_set_number(wl->window->options, "automatic-rename", 0);
|
|
||||||
|
xfree(wl->window->name);
|
||||||
|
wl->window->name = xstrdup(args->argv[0]);
|
||||||
|
options_set_number(&wl->window->options, "automatic-rename", 0);
|
||||||
|
|
||||||
server_redraw_window_borders(wl->window);
|
|
||||||
server_status_window(wl->window);
|
server_status_window(wl->window);
|
||||||
free(newname);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -27,189 +26,92 @@
|
|||||||
* Increase or decrease pane size.
|
* Increase or decrease pane size.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmdq_item *);
|
void cmd_resize_pane_key_binding(struct cmd *, int);
|
||||||
|
int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
static void cmd_resize_pane_mouse_update(struct client *,
|
|
||||||
struct mouse_event *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_resize_pane_entry = {
|
const struct cmd_entry cmd_resize_pane_entry = {
|
||||||
.name = "resize-pane",
|
"resize-pane", "resizep",
|
||||||
.alias = "resizep",
|
"DLRt:U", 0, 1,
|
||||||
|
"[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||||
.args = { "DLMRTt:Ux:y:Z", 0, 1, NULL },
|
0,
|
||||||
.usage = "[-DLMRTUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
|
cmd_resize_pane_key_binding,
|
||||||
"[adjustment]",
|
NULL,
|
||||||
|
cmd_resize_pane_exec
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_resize_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
void
|
||||||
cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_resize_pane_key_binding(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
switch (key) {
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
case KEYC_UP | KEYC_CTRL:
|
||||||
struct key_event *event = cmdq_get_event(item);
|
self->args = args_create(0);
|
||||||
struct window_pane *wp = target->wp;
|
args_set(self->args, 'U', NULL);
|
||||||
struct winlink *wl = target->wl;
|
break;
|
||||||
struct window *w = wl->window;
|
case KEYC_DOWN | KEYC_CTRL:
|
||||||
struct client *c = cmdq_get_client(item);
|
self->args = args_create(0);
|
||||||
struct session *s = target->s;
|
args_set(self->args, 'D', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_LEFT | KEYC_CTRL:
|
||||||
|
self->args = args_create(0);
|
||||||
|
args_set(self->args, 'L', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_RIGHT | KEYC_CTRL:
|
||||||
|
self->args = args_create(0);
|
||||||
|
args_set(self->args, 'R', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_UP | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "5");
|
||||||
|
args_set(self->args, 'U', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_DOWN | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "5");
|
||||||
|
args_set(self->args, 'D', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_LEFT | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "5");
|
||||||
|
args_set(self->args, 'L', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_RIGHT | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "5");
|
||||||
|
args_set(self->args, 'R', NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self->args = args_create(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
char *cause;
|
struct window_pane *wp;
|
||||||
u_int adjust;
|
u_int adjust;
|
||||||
int x, y, status;
|
|
||||||
struct grid *gd = wp->base.grid;
|
|
||||||
|
|
||||||
if (args_has(args, 'T')) {
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||||
if (!TAILQ_EMPTY(&wp->modes))
|
return (-1);
|
||||||
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 (args_has(args, 'M')) {
|
if (args->argc == 0)
|
||||||
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);
|
|
||||||
else
|
|
||||||
window_zoom(wp);
|
|
||||||
server_redraw_window(w);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
server_unzoom_window(w);
|
|
||||||
|
|
||||||
if (args_count(args) == 0)
|
|
||||||
adjust = 1;
|
adjust = 1;
|
||||||
else {
|
else {
|
||||||
adjust = strtonum(args_string(args, 0), 1, INT_MAX, &errstr);
|
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
||||||
if (errstr != NULL) {
|
if (errstr != NULL) {
|
||||||
cmdq_error(item, "adjustment %s", errstr);
|
ctx->error(ctx, "adjustment %s", errstr);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'x')) {
|
if (args_has(self->args, 'L'))
|
||||||
x = args_percentage(args, 'x', 0, INT_MAX, w->sx, &cause);
|
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
|
||||||
if (cause != NULL) {
|
else if (args_has(self->args, 'R'))
|
||||||
cmdq_error(item, "width %s", cause);
|
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
|
||||||
free(cause);
|
else if (args_has(self->args, 'U'))
|
||||||
return (CMD_RETURN_ERROR);
|
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust);
|
||||||
}
|
else if (args_has(self->args, 'D'))
|
||||||
layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
|
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
|
||||||
}
|
|
||||||
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);
|
server_redraw_window(wl->window);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
|
|
||||||
{
|
|
||||||
struct winlink *wl;
|
|
||||||
struct window *w;
|
|
||||||
u_int y, ly, x, lx;
|
|
||||||
static const int offsets[][2] = {
|
|
||||||
{ 0, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
|
|
||||||
};
|
|
||||||
struct layout_cell *cells[nitems(offsets)], *lc;
|
|
||||||
u_int ncells = 0, i, j, resizes = 0;
|
|
||||||
enum layout_type type;
|
|
||||||
|
|
||||||
wl = cmd_mouse_window(m, NULL);
|
|
||||||
if (wl == NULL) {
|
|
||||||
c->tty.mouse_drag_update = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
w = wl->window;
|
|
||||||
|
|
||||||
y = m->y + m->oy; x = m->x + m->ox;
|
|
||||||
if (m->statusat == 0 && y >= m->statuslines)
|
|
||||||
y -= m->statuslines;
|
|
||||||
else if (m->statusat > 0 && y >= (u_int)m->statusat)
|
|
||||||
y = m->statusat - 1;
|
|
||||||
ly = m->ly + m->oy; lx = m->lx + m->ox;
|
|
||||||
if (m->statusat == 0 && ly >= m->statuslines)
|
|
||||||
ly -= m->statuslines;
|
|
||||||
else if (m->statusat > 0 && ly >= (u_int)m->statusat)
|
|
||||||
ly = m->statusat - 1;
|
|
||||||
|
|
||||||
for (i = 0; i < nitems(cells); i++) {
|
|
||||||
lc = layout_search_by_border(w->layout_root, lx + offsets[i][0],
|
|
||||||
ly + offsets[i][1]);
|
|
||||||
if (lc == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (j = 0; j < ncells; j++) {
|
|
||||||
if (cells[j] == lc) {
|
|
||||||
lc = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lc == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
cells[ncells] = lc;
|
|
||||||
ncells++;
|
|
||||||
}
|
|
||||||
if (ncells == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < ncells; i++) {
|
|
||||||
type = cells[i]->parent->type;
|
|
||||||
if (y != ly && type == LAYOUT_TOPBOTTOM) {
|
|
||||||
layout_resize_layout(w, cells[i], type, y - ly, 0);
|
|
||||||
resizes++;
|
|
||||||
} else if (x != lx && type == LAYOUT_LEFTRIGHT) {
|
|
||||||
layout_resize_layout(w, cells[i], type, x - lx, 0);
|
|
||||||
resizes++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (resizes != 0)
|
|
||||||
server_redraw_window(w);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,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,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
* Copyright (c) 2011 Marcel P. Partap <mpartap@gmx.net>
|
* Copyright (c) 2011 Marcel P. Partap <mpartap@gmx.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -28,71 +27,62 @@
|
|||||||
* Respawn a pane (restart the command). Kill existing if -k given.
|
* Respawn a pane (restart the command). Kill existing if -k given.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmdq_item *);
|
int cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_respawn_pane_entry = {
|
const struct cmd_entry cmd_respawn_pane_entry = {
|
||||||
.name = "respawn-pane",
|
"respawn-pane", "respawnp",
|
||||||
.alias = "respawnp",
|
"kt:", 0, 1,
|
||||||
|
"[-k] " CMD_TARGET_PANE_USAGE " [command]",
|
||||||
.args = { "c:e:kt:", 0, -1, NULL },
|
0,
|
||||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
NULL,
|
||||||
CMD_TARGET_PANE_USAGE " [shell-command]",
|
NULL,
|
||||||
|
cmd_respawn_pane_exec
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_respawn_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct winlink *wl;
|
||||||
struct spawn_context sc = { 0 };
|
struct window *w;
|
||||||
struct session *s = target->s;
|
struct window_pane *wp;
|
||||||
struct winlink *wl = target->wl;
|
struct session *s;
|
||||||
struct window_pane *wp = target->wp;
|
struct environ env;
|
||||||
char *cause = NULL;
|
const char *cmd;
|
||||||
struct args_value *av;
|
char *cause;
|
||||||
|
|
||||||
sc.item = item;
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
||||||
sc.s = s;
|
return (-1);
|
||||||
sc.wl = wl;
|
w = wl->window;
|
||||||
|
|
||||||
sc.wp0 = wp;
|
if (!args_has(self->args, 'k') && wp->fd != -1) {
|
||||||
|
ctx->error(ctx, "pane still active: %s:%u.%u",
|
||||||
args_to_vector(args, &sc.argc, &sc.argv);
|
s->name, wl->idx, window_pane_index(w, wp));
|
||||||
sc.environ = environ_create();
|
return (-1);
|
||||||
|
|
||||||
av = args_first_value(args, 'e');
|
|
||||||
while (av != NULL) {
|
|
||||||
environ_put(sc.environ, av->string, 0);
|
|
||||||
av = args_next_value(av);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.idx = -1;
|
environ_init(&env);
|
||||||
sc.cwd = args_get(args, 'c');
|
environ_copy(&global_environ, &env);
|
||||||
|
environ_copy(&s->environ, &env);
|
||||||
|
server_fill_environ(s, &env);
|
||||||
|
|
||||||
sc.flags = SPAWN_RESPAWN;
|
window_pane_reset_mode(wp);
|
||||||
if (args_has(args, 'k'))
|
screen_reinit(&wp->base);
|
||||||
sc.flags |= SPAWN_KILL;
|
input_init(wp);
|
||||||
|
|
||||||
if (spawn_pane(&sc, &cause) == NULL) {
|
if (args->argc != 0)
|
||||||
cmdq_error(item, "respawn pane failed: %s", cause);
|
cmd = args->argv[0];
|
||||||
free(cause);
|
else
|
||||||
if (sc.argv != NULL)
|
cmd = NULL;
|
||||||
cmd_free_argv(sc.argc, sc.argv);
|
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||||
environ_free(sc.environ);
|
ctx->error(ctx, "respawn pane failed: %s", cause);
|
||||||
return (CMD_RETURN_ERROR);
|
xfree(cause);
|
||||||
|
environ_free(&env);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
wp->flags |= PANE_REDRAW;
|
wp->flags |= PANE_REDRAW;
|
||||||
server_redraw_window_borders(wp->window);
|
server_status_window(w);
|
||||||
server_status_window(wp->window);
|
|
||||||
|
|
||||||
if (sc.argv != NULL)
|
environ_free(&env);
|
||||||
cmd_free_argv(sc.argc, sc.argv);
|
return (0);
|
||||||
environ_free(sc.environ);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -27,69 +26,75 @@
|
|||||||
* Respawn a window (restart the command). Kill existing if -k given.
|
* Respawn a window (restart the command). Kill existing if -k given.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_respawn_window_exec(struct cmd *,
|
int cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_respawn_window_entry = {
|
const struct cmd_entry cmd_respawn_window_entry = {
|
||||||
.name = "respawn-window",
|
"respawn-window", "respawnw",
|
||||||
.alias = "respawnw",
|
"kt:", 0, 1,
|
||||||
|
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
|
||||||
.args = { "c:e:kt:", 0, -1, NULL },
|
0,
|
||||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
NULL,
|
||||||
CMD_TARGET_WINDOW_USAGE " [shell-command]",
|
NULL,
|
||||||
|
cmd_respawn_window_exec
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_respawn_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct winlink *wl;
|
||||||
struct spawn_context sc = { 0 };
|
struct window *w;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct window_pane *wp;
|
||||||
struct session *s = target->s;
|
struct session *s;
|
||||||
struct winlink *wl = target->wl;
|
struct environ env;
|
||||||
char *cause = NULL;
|
const char *cmd;
|
||||||
struct args_value *av;
|
char *cause;
|
||||||
|
|
||||||
sc.item = item;
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
||||||
sc.s = s;
|
return (-1);
|
||||||
sc.wl = wl;
|
w = wl->window;
|
||||||
sc.tc = tc;
|
|
||||||
|
|
||||||
args_to_vector(args, &sc.argc, &sc.argv);
|
if (!args_has(self->args, 'k')) {
|
||||||
sc.environ = environ_create();
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
|
if (wp->fd == -1)
|
||||||
av = args_first_value(args, 'e');
|
continue;
|
||||||
while (av != NULL) {
|
ctx->error(ctx,
|
||||||
environ_put(sc.environ, av->string, 0);
|
"window still active: %s:%d", s->name, wl->idx);
|
||||||
av = args_next_value(av);
|
return (-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.idx = -1;
|
environ_init(&env);
|
||||||
sc.cwd = args_get(args, 'c');
|
environ_copy(&global_environ, &env);
|
||||||
|
environ_copy(&s->environ, &env);
|
||||||
|
server_fill_environ(s, &env);
|
||||||
|
|
||||||
sc.flags = SPAWN_RESPAWN;
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
if (args_has(args, 'k'))
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
sc.flags |= SPAWN_KILL;
|
layout_free(w);
|
||||||
|
window_destroy_panes(w);
|
||||||
if (spawn_window(&sc, &cause) == NULL) {
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
cmdq_error(item, "respawn window failed: %s", cause);
|
window_pane_resize(wp, w->sx, w->sy);
|
||||||
free(cause);
|
if (args->argc != 0)
|
||||||
if (sc.argv != NULL)
|
cmd = args->argv[0];
|
||||||
cmd_free_argv(sc.argc, sc.argv);
|
else
|
||||||
environ_free(sc.environ);
|
cmd = NULL;
|
||||||
return (CMD_RETURN_ERROR);
|
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
environ_free(&env);
|
||||||
|
server_destroy_pane(wp);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
layout_init(w);
|
||||||
|
window_pane_reset_mode(wp);
|
||||||
|
screen_reinit(&wp->base);
|
||||||
|
input_init(wp);
|
||||||
|
window_set_active_pane(w, wp);
|
||||||
|
|
||||||
server_redraw_window(wl->window);
|
recalculate_sizes();
|
||||||
|
server_redraw_window(w);
|
||||||
|
|
||||||
if (sc.argv != NULL)
|
environ_free(&env);
|
||||||
cmd_free_argv(sc.argc, sc.argv);
|
return (0);
|
||||||
environ_free(sc.environ);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -24,37 +24,42 @@
|
|||||||
* Rotate the panes in a window.
|
* Rotate the panes in a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_rotate_window_exec(struct cmd *,
|
void cmd_rotate_window_key_binding(struct cmd *, int);
|
||||||
struct cmdq_item *);
|
int cmd_rotate_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_rotate_window_entry = {
|
const struct cmd_entry cmd_rotate_window_entry = {
|
||||||
.name = "rotate-window",
|
"rotate-window", "rotatew",
|
||||||
.alias = "rotatew",
|
"Dt:U", 0, 0,
|
||||||
|
"[-DU] " CMD_TARGET_WINDOW_USAGE,
|
||||||
.args = { "Dt:UZ", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-DUZ] " CMD_TARGET_WINDOW_USAGE,
|
cmd_rotate_window_key_binding,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_rotate_window_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_rotate_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
void
|
||||||
cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_rotate_window_key_binding(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
self->args = args_create(0);
|
||||||
struct cmd_find_state *current = cmdq_get_current(item);
|
if (key == ('o' | KEYC_ESCAPE))
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
args_set(self->args, 'D', NULL);
|
||||||
struct winlink *wl = target->wl;
|
}
|
||||||
struct window *w = wl->window;
|
|
||||||
|
int
|
||||||
|
cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
struct window_pane *wp, *wp2;
|
struct window_pane *wp, *wp2;
|
||||||
struct layout_cell *lc;
|
struct layout_cell *lc;
|
||||||
u_int sx, sy, xoff, yoff;
|
u_int sx, sy, xoff, yoff;
|
||||||
|
|
||||||
window_push_zoom(w, 0, args_has(args, 'Z'));
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
if (args_has(args, 'D')) {
|
if (args_has(self->args, 'D')) {
|
||||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
@@ -79,6 +84,8 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
|
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
|
||||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||||
|
window_set_active_pane(w, wp);
|
||||||
|
server_redraw_window(w);
|
||||||
} else {
|
} else {
|
||||||
wp = TAILQ_FIRST(&w->panes);
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
@@ -104,12 +111,9 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
|
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
|
||||||
wp = TAILQ_FIRST(&w->panes);
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
|
window_set_active_pane(w, wp);
|
||||||
|
server_redraw_window(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
window_set_active_pane(w, wp, 1);
|
return (0);
|
||||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
|
||||||
window_pop_zoom(w);
|
|
||||||
server_redraw_window(w);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
287
cmd-run-shell.c
287
cmd-run-shell.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -20,8 +20,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
@@ -30,255 +28,114 @@
|
|||||||
* Runs a command without a window.
|
* Runs a command without a window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum args_parse_type cmd_run_shell_args_parse(struct args *, u_int,
|
int cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||||
char **);
|
|
||||||
static enum cmd_retval cmd_run_shell_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
static void cmd_run_shell_timer(int, short, void *);
|
void cmd_run_shell_callback(struct job *);
|
||||||
static void cmd_run_shell_callback(struct job *);
|
void cmd_run_shell_free(void *);
|
||||||
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 = {
|
const struct cmd_entry cmd_run_shell_entry = {
|
||||||
.name = "run-shell",
|
"run-shell", "run",
|
||||||
.alias = "run",
|
"", 1, 1,
|
||||||
|
"command",
|
||||||
.args = { "bd:Ct:c:", 0, 2, cmd_run_shell_args_parse },
|
0,
|
||||||
.usage = "[-bC] [-c start-directory] [-d delay] " CMD_TARGET_PANE_USAGE
|
NULL,
|
||||||
" [shell-command]",
|
NULL,
|
||||||
|
cmd_run_shell_exec
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_run_shell_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_run_shell_data {
|
struct cmd_run_shell_data {
|
||||||
struct client *client;
|
char *cmd;
|
||||||
char *cmd;
|
struct cmd_ctx ctx;
|
||||||
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
|
int
|
||||||
cmd_run_shell_args_parse(struct args *args, __unused u_int idx,
|
cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
__unused char **cause)
|
|
||||||
{
|
{
|
||||||
if (args_has(args, 'C'))
|
struct args *args = self->args;
|
||||||
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 && 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 cmd_run_shell_data *cdata;
|
||||||
struct client *c = cmdq_get_client(item);
|
const char *shellcmd = args->argv[0];
|
||||||
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) {
|
cdata = xmalloc(sizeof *cdata);
|
||||||
d = strtod(delay, &end);
|
cdata->cmd = xstrdup(args->argv[0]);
|
||||||
if (*end != '\0') {
|
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||||
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 (ctx->cmdclient != NULL)
|
||||||
if (!args_has(args, 'C')) {
|
ctx->cmdclient->references++;
|
||||||
cmd = args_string(args, 0);
|
if (ctx->curclient != NULL)
|
||||||
if (cmd != NULL)
|
ctx->curclient->references++;
|
||||||
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)
|
job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata);
|
||||||
cdata->wp_id = wp->id;
|
|
||||||
else
|
|
||||||
cdata->wp_id = -1;
|
|
||||||
|
|
||||||
if (wait) {
|
return (1); /* don't let client exit */
|
||||||
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));
|
|
||||||
|
|
||||||
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
|
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, "%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)
|
cmd_run_shell_callback(struct job *job)
|
||||||
{
|
{
|
||||||
struct cmd_run_shell_data *cdata = job_get_data(job);
|
struct cmd_run_shell_data *cdata = job->data;
|
||||||
struct bufferevent *event = job_get_event(job);
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
struct cmdq_item *item = cdata->item;
|
char *cmd, *msg, *line;
|
||||||
char *cmd = cdata->cmd, *msg = NULL, *line;
|
|
||||||
size_t size;
|
size_t size;
|
||||||
int retcode, status;
|
int retcode;
|
||||||
|
u_int lines;
|
||||||
|
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
if (ctx->curclient != NULL && ctx->curclient->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lines = 0;
|
||||||
do {
|
do {
|
||||||
line = evbuffer_readln(event->input, NULL, EVBUFFER_EOL_LF);
|
if ((line = evbuffer_readline(job->event->input)) != NULL) {
|
||||||
if (line != NULL) {
|
ctx->print(ctx, "%s", line);
|
||||||
cmd_run_shell_print(job, line);
|
lines++;
|
||||||
free(line);
|
|
||||||
}
|
}
|
||||||
} while (line != NULL);
|
} while (line != NULL);
|
||||||
|
|
||||||
size = EVBUFFER_LENGTH(event->input);
|
size = EVBUFFER_LENGTH(job->event->input);
|
||||||
if (size != 0) {
|
if (size != 0) {
|
||||||
line = xmalloc(size + 1);
|
line = xmalloc(size + 1);
|
||||||
memcpy(line, EVBUFFER_DATA(event->input), size);
|
memcpy(line, EVBUFFER_DATA(job->event->input), size);
|
||||||
line[size] = '\0';
|
line[size] = '\0';
|
||||||
|
|
||||||
cmd_run_shell_print(job, line);
|
ctx->print(ctx, "%s", line);
|
||||||
|
lines++;
|
||||||
|
|
||||||
free(line);
|
xfree(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = job_get_status(job);
|
cmd = cdata->cmd;
|
||||||
if (WIFEXITED(status)) {
|
|
||||||
if ((retcode = WEXITSTATUS(status)) != 0)
|
|
||||||
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) {
|
msg = NULL;
|
||||||
if (cmdq_get_client(item) != NULL &&
|
if (WIFEXITED(job->status)) {
|
||||||
cmdq_get_client(item)->session == NULL)
|
if ((retcode = WEXITSTATUS(job->status)) != 0)
|
||||||
cmdq_get_client(item)->retval = retcode;
|
xasprintf(&msg, "'%s' returned %d", cmd, retcode);
|
||||||
cmdq_continue(item);
|
} else if (WIFSIGNALED(job->status)) {
|
||||||
|
retcode = WTERMSIG(job->status);
|
||||||
|
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
||||||
|
}
|
||||||
|
if (msg != NULL) {
|
||||||
|
if (lines != 0)
|
||||||
|
ctx->print(ctx, "%s", msg);
|
||||||
|
else
|
||||||
|
ctx->info(ctx, "%s", msg);
|
||||||
|
xfree(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_run_shell_free(void *data)
|
cmd_run_shell_free(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_run_shell_data *cdata = data;
|
struct cmd_run_shell_data *cdata = data;
|
||||||
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
|
||||||
evtimer_del(&cdata->timer);
|
if (ctx->cmdclient != NULL) {
|
||||||
if (cdata->s != NULL)
|
ctx->cmdclient->references--;
|
||||||
session_remove_ref(cdata->s, __func__);
|
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||||
if (cdata->client != NULL)
|
}
|
||||||
server_client_unref(cdata->client);
|
if (ctx->curclient != NULL)
|
||||||
if (cdata->state != NULL)
|
ctx->curclient->references--;
|
||||||
args_make_commands_free(cdata->state);
|
|
||||||
free(cdata->cwd);
|
xfree(cdata->cmd);
|
||||||
free(cdata->cmd);
|
xfree(cdata);
|
||||||
free(cdata);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -20,101 +20,83 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Saves a paste buffer to a file.
|
* Saves a session paste buffer to a file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmdq_item *);
|
int cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_save_buffer_entry = {
|
const struct cmd_entry cmd_save_buffer_entry = {
|
||||||
.name = "save-buffer",
|
"save-buffer", "saveb",
|
||||||
.alias = "saveb",
|
"ab:", 1, 1,
|
||||||
|
"[-a] " CMD_BUFFER_USAGE,
|
||||||
.args = { "ab:", 1, 1, NULL },
|
0,
|
||||||
.usage = "[-a] " CMD_BUFFER_USAGE " path",
|
NULL,
|
||||||
|
NULL,
|
||||||
.flags = CMD_AFTERHOOK,
|
cmd_save_buffer_exec
|
||||||
.exec = cmd_save_buffer_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_buffer_entry = {
|
int
|
||||||
.name = "show-buffer",
|
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "showb",
|
|
||||||
|
|
||||||
.args = { "b:", 0, 0, 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)
|
|
||||||
{
|
{
|
||||||
struct cmdq_item *item = data;
|
struct args *args = self->args;
|
||||||
|
struct client *c = ctx->cmdclient;
|
||||||
if (!closed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
cmdq_error(item, "%s: %s", path, strerror(error));
|
|
||||||
cmdq_continue(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
struct client *c = cmdq_get_client(item);
|
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
int flags;
|
const char *path;
|
||||||
const char *bufname = args_get(args, 'b'), *bufdata;
|
char *cause;
|
||||||
size_t bufsize;
|
int buffer;
|
||||||
char *path;
|
mode_t mask;
|
||||||
struct evbuffer *evb;
|
FILE *f;
|
||||||
|
|
||||||
if (bufname == NULL) {
|
if (!args_has(args, 'b')) {
|
||||||
if ((pb = paste_get_top(NULL)) == NULL) {
|
if ((pb = paste_get_top(&global_buffers)) == NULL) {
|
||||||
cmdq_error(item, "no buffers");
|
ctx->error(ctx, "no buffers");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pb = paste_get_name(bufname);
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pb = paste_get_index(&global_buffers, buffer);
|
||||||
if (pb == NULL) {
|
if (pb == NULL) {
|
||||||
cmdq_error(item, "no buffer %s", bufname);
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bufdata = paste_buffer_data(pb, &bufsize);
|
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_show_buffer_entry) {
|
path = args->argv[0];
|
||||||
if (c->session != NULL || (c->flags & CLIENT_CONTROL)) {
|
if (strcmp(path, "-") == 0) {
|
||||||
evb = evbuffer_new();
|
if (c == NULL) {
|
||||||
if (evb == NULL)
|
ctx->error(ctx, "%s: can't write to stdout", path);
|
||||||
fatalx("out of memory");
|
return (-1);
|
||||||
evbuffer_add(evb, bufdata, bufsize);
|
|
||||||
cmdq_print_data(item, 1, evb);
|
|
||||||
evbuffer_free(evb);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
path = xstrdup("-");
|
bufferevent_write(c->stdout_event, pb->data, pb->size);
|
||||||
} else
|
} else {
|
||||||
path = format_single_from_target(item, args_string(args, 0));
|
mask = umask(S_IRWXG | S_IRWXO);
|
||||||
if (args_has(args, 'a'))
|
if (args_has(self->args, 'a'))
|
||||||
flags = O_APPEND;
|
f = fopen(path, "ab");
|
||||||
else
|
else
|
||||||
flags = O_TRUNC;
|
f = fopen(path, "wb");
|
||||||
file_write(cmdq_get_client(item), path, flags, bufdata, bufsize,
|
umask(mask);
|
||||||
cmd_save_buffer_done, item);
|
if (f == NULL) {
|
||||||
free(path);
|
ctx->error(ctx, "%s: %s", path, strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
|
||||||
|
ctx->error(ctx, "%s: fwrite error", path);
|
||||||
|
fclose(f);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
return (CMD_RETURN_WAIT);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,132 +18,116 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Switch window to selected layout.
|
* Switch window to selected layout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_select_layout_exec(struct cmd *,
|
void cmd_select_layout_key_binding(struct cmd *, int);
|
||||||
struct cmdq_item *);
|
int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_select_layout_entry = {
|
const struct cmd_entry cmd_select_layout_entry = {
|
||||||
.name = "select-layout",
|
"select-layout", "selectl",
|
||||||
.alias = "selectl",
|
"npt:", 0, 1,
|
||||||
|
"[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
||||||
.args = { "Enopt:", 0, 1, NULL },
|
0,
|
||||||
.usage = "[-Enop] " CMD_TARGET_PANE_USAGE " [layout-name]",
|
cmd_select_layout_key_binding,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_select_layout_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_select_layout_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_next_layout_entry = {
|
const struct cmd_entry cmd_next_layout_entry = {
|
||||||
.name = "next-layout",
|
"next-layout", "nextl",
|
||||||
.alias = "nextl",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
.args = { "t:", 0, 0, NULL },
|
0,
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_select_layout_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_select_layout_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_previous_layout_entry = {
|
const struct cmd_entry cmd_previous_layout_entry = {
|
||||||
.name = "previous-layout",
|
"previous-layout", "prevl",
|
||||||
.alias = "prevl",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
.args = { "t:", 0, 0, NULL },
|
0,
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_select_layout_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_select_layout_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
void
|
||||||
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_select_layout_key_binding(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
switch (key) {
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
case '1' | KEYC_ESCAPE:
|
||||||
struct winlink *wl = target->wl;
|
self->args = args_create(1, "even-horizontal");
|
||||||
struct window *w = wl->window;
|
break;
|
||||||
struct window_pane *wp = target->wp;
|
case '2' | KEYC_ESCAPE:
|
||||||
const char *layoutname;
|
self->args = args_create(1, "even-vertical");
|
||||||
char *oldlayout, *cause;
|
break;
|
||||||
int next, previous, layout;
|
case '3' | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "main-horizontal");
|
||||||
|
break;
|
||||||
|
case '4' | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "main-vertical");
|
||||||
|
break;
|
||||||
|
case '5' | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "tiled");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self->args = args_create(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
server_unzoom_window(w);
|
int
|
||||||
|
cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
const char *layoutname;
|
||||||
|
int next, previous, layout;
|
||||||
|
|
||||||
next = (cmd_get_entry(self) == &cmd_next_layout_entry);
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
if (args_has(args, 'n'))
|
return (-1);
|
||||||
|
|
||||||
|
next = self->entry == &cmd_next_layout_entry;
|
||||||
|
if (args_has(self->args, 'n'))
|
||||||
next = 1;
|
next = 1;
|
||||||
previous = (cmd_get_entry(self) == &cmd_previous_layout_entry);
|
previous = self->entry == &cmd_previous_layout_entry;
|
||||||
if (args_has(args, 'p'))
|
if (args_has(self->args, 'p'))
|
||||||
previous = 1;
|
previous = 1;
|
||||||
|
|
||||||
oldlayout = w->old_layout;
|
|
||||||
w->old_layout = layout_dump(w->layout_root);
|
|
||||||
|
|
||||||
if (next || previous) {
|
if (next || previous) {
|
||||||
if (next)
|
if (next)
|
||||||
layout_set_next(w);
|
layout = layout_set_next(wl->window);
|
||||||
else
|
else
|
||||||
layout_set_previous(w);
|
layout = layout_set_previous(wl->window);
|
||||||
goto changed;
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'E')) {
|
if (args->argc == 0)
|
||||||
layout_spread_out(wp);
|
layout = wl->window->lastlayout;
|
||||||
goto changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_count(args) != 0)
|
|
||||||
layoutname = args_string(args, 0);
|
|
||||||
else if (args_has(args, 'o'))
|
|
||||||
layoutname = oldlayout;
|
|
||||||
else
|
else
|
||||||
layoutname = NULL;
|
layout = layout_set_lookup(args->argv[0]);
|
||||||
|
if (layout != -1) {
|
||||||
if (!args_has(args, 'o')) {
|
layout = layout_set_select(wl->window, layout);
|
||||||
if (layoutname == NULL)
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
layout = w->lastlayout;
|
return (0);
|
||||||
else
|
|
||||||
layout = layout_set_lookup(layoutname);
|
|
||||||
if (layout != -1) {
|
|
||||||
layout_set_select(w, layout);
|
|
||||||
goto changed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layoutname != NULL) {
|
if (args->argc != 0) {
|
||||||
if (layout_parse(w, layoutname, &cause) == -1) {
|
layoutname = args->argv[0];
|
||||||
cmdq_error(item, "%s: %s", cause, layoutname);
|
if (layout_parse(wl->window, layoutname) == -1) {
|
||||||
free(cause);
|
ctx->error(ctx, "can't set layout: %s", layoutname);
|
||||||
goto error;
|
return (-1);
|
||||||
}
|
}
|
||||||
goto changed;
|
ctx->info(ctx, "arranging in: %s", layoutname);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(oldlayout);
|
return (0);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
changed:
|
|
||||||
free(oldlayout);
|
|
||||||
recalculate_sizes();
|
|
||||||
server_redraw_window(w);
|
|
||||||
notify_window("window-layout-changed", w);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
error:
|
|
||||||
free(w->old_layout);
|
|
||||||
w->old_layout = oldlayout;
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,225 +18,99 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Select pane.
|
* Select pane.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmdq_item *);
|
void cmd_select_pane_key_binding(struct cmd *, int);
|
||||||
|
int cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_select_pane_entry = {
|
const struct cmd_entry cmd_select_pane_entry = {
|
||||||
.name = "select-pane",
|
"select-pane", "selectp",
|
||||||
.alias = "selectp",
|
"lDLRt:U", 0, 0,
|
||||||
|
"[-lDLRU] " CMD_TARGET_PANE_USAGE,
|
||||||
.args = { "DdegLlMmP:RT:t:UZ", 0, 0, NULL }, /* -P and -g deprecated */
|
0,
|
||||||
.usage = "[-DdeLlMmRUZ] [-T title] " CMD_TARGET_PANE_USAGE,
|
cmd_select_pane_key_binding,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
cmd_select_pane_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_last_pane_entry = {
|
const struct cmd_entry cmd_last_pane_entry = {
|
||||||
.name = "last-pane",
|
"last-pane", "lastp",
|
||||||
.alias = "lastp",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
.args = { "det:Z", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-deZ] " CMD_TARGET_WINDOW_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_select_pane_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_pane_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
void
|
||||||
cmd_select_pane_redraw(struct window *w)
|
cmd_select_pane_key_binding(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct client *c;
|
self->args = args_create(0);
|
||||||
|
if (key == KEYC_UP)
|
||||||
/*
|
args_set(self->args, 'U', NULL);
|
||||||
* Redraw entire window if it is bigger than the client (the
|
if (key == KEYC_DOWN)
|
||||||
* offset may change), otherwise just draw borders.
|
args_set(self->args, 'D', NULL);
|
||||||
*/
|
if (key == KEYC_LEFT)
|
||||||
|
args_set(self->args, 'L', NULL);
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
if (key == KEYC_RIGHT)
|
||||||
if (c->session == NULL || (c->flags & CLIENT_CONTROL))
|
args_set(self->args, 'R', NULL);
|
||||||
continue;
|
if (key == 'o')
|
||||||
if (c->session->curw->window == w && tty_window_bigger(&c->tty))
|
args_set(self->args, 't', ":.+");
|
||||||
server_redraw_client(c);
|
|
||||||
else {
|
|
||||||
if (c->session->curw->window == w)
|
|
||||||
c->flags |= CLIENT_REDRAWBORDERS;
|
|
||||||
if (session_has(c->session, w))
|
|
||||||
c->flags |= CLIENT_REDRAWSTATUS;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
const struct cmd_entry *entry = cmd_get_entry(self);
|
struct winlink *wl;
|
||||||
struct cmd_find_state *current = cmdq_get_current(item);
|
struct window_pane *wp;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
|
||||||
struct client *c = cmdq_get_client(item);
|
|
||||||
struct winlink *wl = target->wl;
|
|
||||||
struct window *w = wl->window;
|
|
||||||
struct session *s = target->s;
|
|
||||||
struct window_pane *wp = target->wp, *activewp, *lastwp, *markedwp;
|
|
||||||
struct options *oo = wp->options;
|
|
||||||
char *title;
|
|
||||||
const char *style;
|
|
||||||
struct options_entry *o;
|
|
||||||
|
|
||||||
if (entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
||||||
/*
|
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
||||||
* Check for no last pane found in case the other pane was
|
if (wl == NULL)
|
||||||
* spawned without being visited (for example split-window -d).
|
return (-1);
|
||||||
*/
|
|
||||||
lastwp = TAILQ_FIRST(&w->last_panes);
|
if (wl->window->last == NULL) {
|
||||||
if (lastwp == NULL && window_count_panes(w) == 2) {
|
ctx->error(ctx, "no last pane");
|
||||||
lastwp = TAILQ_PREV(w->active, window_panes, entry);
|
return (-1);
|
||||||
if (lastwp == NULL)
|
|
||||||
lastwp = TAILQ_NEXT(w->active, entry);
|
|
||||||
}
|
}
|
||||||
if (lastwp == NULL) {
|
|
||||||
cmdq_error(item, "no last pane");
|
window_set_active_pane(wl->window, wl->window->last);
|
||||||
return (CMD_RETURN_ERROR);
|
server_status_window(wl->window);
|
||||||
}
|
server_redraw_window_borders(wl->window);
|
||||||
if (args_has(args, 'e')) {
|
|
||||||
lastwp->flags &= ~PANE_INPUTOFF;
|
return (0);
|
||||||
server_redraw_window_borders(lastwp->window);
|
|
||||||
server_status_window(lastwp->window);
|
|
||||||
} else if (args_has(args, 'd')) {
|
|
||||||
lastwp->flags |= PANE_INPUTOFF;
|
|
||||||
server_redraw_window_borders(lastwp->window);
|
|
||||||
server_status_window(lastwp->window);
|
|
||||||
} else {
|
|
||||||
if (window_push_zoom(w, 0, args_has(args, 'Z')))
|
|
||||||
server_redraw_window(w);
|
|
||||||
window_redraw_active_switch(w, lastwp);
|
|
||||||
if (window_set_active_pane(w, lastwp, 1)) {
|
|
||||||
cmd_find_from_winlink(current, wl, 0);
|
|
||||||
cmd_select_pane_redraw(w);
|
|
||||||
}
|
|
||||||
if (window_pop_zoom(w))
|
|
||||||
server_redraw_window(w);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'm') || args_has(args, 'M')) {
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||||
if (args_has(args, 'm') && !window_pane_visible(wp))
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
if (server_check_marked())
|
|
||||||
lastwp = marked_pane.wp;
|
|
||||||
else
|
|
||||||
lastwp = NULL;
|
|
||||||
|
|
||||||
if (args_has(args, 'M') || server_is_marked(s, wl, wp))
|
if (!window_pane_visible(wp)) {
|
||||||
server_clear_marked();
|
ctx->error(ctx, "pane not visible");
|
||||||
else
|
return (-1);
|
||||||
server_set_marked(s, wl, wp);
|
|
||||||
markedwp = marked_pane.wp;
|
|
||||||
|
|
||||||
if (lastwp != NULL) {
|
|
||||||
lastwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
|
||||||
server_redraw_window_borders(lastwp->window);
|
|
||||||
server_status_window(lastwp->window);
|
|
||||||
}
|
|
||||||
if (markedwp != NULL) {
|
|
||||||
markedwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
|
||||||
server_redraw_window_borders(markedwp->window);
|
|
||||||
server_status_window(markedwp->window);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
style = args_get(args, 'P');
|
if (args_has(self->args, 'L'))
|
||||||
if (style != NULL) {
|
|
||||||
o = options_set_string(oo, "window-style", 0, "%s", style);
|
|
||||||
if (o == NULL) {
|
|
||||||
cmdq_error(item, "bad style: %s", style);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
options_set_string(oo, "window-active-style", 0, "%s", style);
|
|
||||||
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
|
||||||
}
|
|
||||||
if (args_has(args, 'g')) {
|
|
||||||
cmdq_print(item, "%s", options_get_string(oo, "window-style"));
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'L')) {
|
|
||||||
window_push_zoom(w, 0, 1);
|
|
||||||
wp = window_pane_find_left(wp);
|
wp = window_pane_find_left(wp);
|
||||||
window_pop_zoom(w);
|
else if (args_has(self->args, 'R'))
|
||||||
} else if (args_has(args, 'R')) {
|
|
||||||
window_push_zoom(w, 0, 1);
|
|
||||||
wp = window_pane_find_right(wp);
|
wp = window_pane_find_right(wp);
|
||||||
window_pop_zoom(w);
|
else if (args_has(self->args, 'U'))
|
||||||
} else if (args_has(args, 'U')) {
|
|
||||||
window_push_zoom(w, 0, 1);
|
|
||||||
wp = window_pane_find_up(wp);
|
wp = window_pane_find_up(wp);
|
||||||
window_pop_zoom(w);
|
else if (args_has(self->args, 'D'))
|
||||||
} else if (args_has(args, 'D')) {
|
|
||||||
window_push_zoom(w, 0, 1);
|
|
||||||
wp = window_pane_find_down(wp);
|
wp = window_pane_find_down(wp);
|
||||||
window_pop_zoom(w);
|
if (wp == NULL) {
|
||||||
}
|
ctx->error(ctx, "pane not found");
|
||||||
if (wp == NULL)
|
return (-1);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
if (args_has(args, 'e')) {
|
|
||||||
wp->flags &= ~PANE_INPUTOFF;
|
|
||||||
server_redraw_window_borders(wp->window);
|
|
||||||
server_status_window(wp->window);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
if (args_has(args, 'd')) {
|
|
||||||
wp->flags |= PANE_INPUTOFF;
|
|
||||||
server_redraw_window_borders(wp->window);
|
|
||||||
server_status_window(wp->window);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'T')) {
|
window_set_active_pane(wl->window, wp);
|
||||||
title = format_single_from_target(item, args_get(args, 'T'));
|
server_status_window(wl->window);
|
||||||
if (screen_set_title(&wp->base, title)) {
|
server_redraw_window_borders(wl->window);
|
||||||
notify_pane("pane-title-changed", wp);
|
|
||||||
server_redraw_window_borders(wp->window);
|
|
||||||
server_status_window(wp->window);
|
|
||||||
}
|
|
||||||
free(title);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c != NULL && c->session != NULL && (c->flags & CLIENT_ACTIVEPANE))
|
return (0);
|
||||||
activewp = server_client_get_pane(c);
|
|
||||||
else
|
|
||||||
activewp = w->active;
|
|
||||||
if (wp == activewp)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
if (window_push_zoom(w, 0, args_has(args, 'Z')))
|
|
||||||
server_redraw_window(w);
|
|
||||||
window_redraw_active_switch(w, wp);
|
|
||||||
if (c != NULL && c->session != NULL && (c->flags & CLIENT_ACTIVEPANE))
|
|
||||||
server_client_set_pane(c, wp);
|
|
||||||
else if (window_set_active_pane(w, wp, 1))
|
|
||||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
|
||||||
cmdq_insert_hook(s, item, current, "after-select-pane");
|
|
||||||
cmd_select_pane_redraw(w);
|
|
||||||
if (window_pop_zoom(w))
|
|
||||||
server_redraw_window(w);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -26,125 +26,114 @@
|
|||||||
* Select window by index.
|
* Select window by index.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_select_window_exec(struct cmd *,
|
void cmd_select_window_key_binding(struct cmd *, int);
|
||||||
struct cmdq_item *);
|
int cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_select_window_entry = {
|
const struct cmd_entry cmd_select_window_entry = {
|
||||||
.name = "select-window",
|
"select-window", "selectw",
|
||||||
.alias = "selectw",
|
"lnpt:", 0, 0,
|
||||||
|
"[-lnp] " CMD_TARGET_WINDOW_USAGE,
|
||||||
.args = { "lnpTt:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-lnpT] " CMD_TARGET_WINDOW_USAGE,
|
cmd_select_window_key_binding,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
cmd_select_window_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_next_window_entry = {
|
const struct cmd_entry cmd_next_window_entry = {
|
||||||
.name = "next-window",
|
"next-window", "next",
|
||||||
.alias = "next",
|
"at:", 0, 0,
|
||||||
|
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
.args = { "at:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
cmd_select_window_key_binding,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_select_window_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_previous_window_entry = {
|
const struct cmd_entry cmd_previous_window_entry = {
|
||||||
.name = "previous-window",
|
"previous-window", "prev",
|
||||||
.alias = "prev",
|
"at:", 0, 0,
|
||||||
|
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
.args = { "at:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
cmd_select_window_key_binding,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_select_window_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_last_window_entry = {
|
const struct cmd_entry cmd_last_window_entry = {
|
||||||
.name = "last-window",
|
"last-window", "last",
|
||||||
.alias = "last",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
.args = { "t:", 0, 0, NULL },
|
0,
|
||||||
.usage = CMD_TARGET_SESSION_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
cmd_select_window_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_select_window_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
void
|
||||||
cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_select_window_key_binding(struct cmd *self, int key)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
char tmp[16];
|
||||||
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 winlink *wl = target->wl;
|
|
||||||
struct session *s = target->s;
|
|
||||||
int next, previous, last, activity;
|
|
||||||
|
|
||||||
next = (cmd_get_entry(self) == &cmd_next_window_entry);
|
self->args = args_create(0);
|
||||||
if (args_has(args, 'n'))
|
if (key >= '0' && key <= '9') {
|
||||||
|
xsnprintf(tmp, sizeof tmp, ":%d", key - '0');
|
||||||
|
args_set(self->args, 't', tmp);
|
||||||
|
}
|
||||||
|
if (key == ('n' | KEYC_ESCAPE) || key == ('p' | KEYC_ESCAPE))
|
||||||
|
args_set(self->args, 'a', NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct session *s;
|
||||||
|
int next, previous, last, activity;
|
||||||
|
|
||||||
|
next = self->entry == &cmd_next_window_entry;
|
||||||
|
if (args_has(self->args, 'n'))
|
||||||
next = 1;
|
next = 1;
|
||||||
previous = (cmd_get_entry(self) == &cmd_previous_window_entry);
|
previous = self->entry == &cmd_previous_window_entry;
|
||||||
if (args_has(args, 'p'))
|
if (args_has(self->args, 'p'))
|
||||||
previous = 1;
|
previous = 1;
|
||||||
last = (cmd_get_entry(self) == &cmd_last_window_entry);
|
last = self->entry == &cmd_last_window_entry;
|
||||||
if (args_has(args, 'l'))
|
if (args_has(self->args, 'l'))
|
||||||
last = 1;
|
last = 1;
|
||||||
|
|
||||||
if (next || previous || last) {
|
if (next || previous || last) {
|
||||||
activity = args_has(args, 'a');
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
activity = args_has(self->args, 'a');
|
||||||
if (next) {
|
if (next) {
|
||||||
if (session_next(s, activity) != 0) {
|
if (session_next(s, activity) != 0) {
|
||||||
cmdq_error(item, "no next window");
|
ctx->error(ctx, "no next window");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
} else if (previous) {
|
} else if (previous) {
|
||||||
if (session_previous(s, activity) != 0) {
|
if (session_previous(s, activity) != 0) {
|
||||||
cmdq_error(item, "no previous window");
|
ctx->error(ctx, "no previous window");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (session_last(s) != 0) {
|
if (session_last(s) != 0) {
|
||||||
cmdq_error(item, "no last window");
|
ctx->error(ctx, "no last window");
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cmd_find_from_session(current, s, 0);
|
|
||||||
server_redraw_session(s);
|
|
||||||
cmdq_insert_hook(s, item, current, "after-select-window");
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* If -T and select-window is invoked on same window as
|
|
||||||
* current, switch to previous window.
|
|
||||||
*/
|
|
||||||
if (args_has(args, 'T') && wl == s->curw) {
|
|
||||||
if (session_last(s) != 0) {
|
|
||||||
cmdq_error(item, "no last window");
|
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (current->s == s)
|
|
||||||
cmd_find_from_session(current, s, 0);
|
|
||||||
server_redraw_session(s);
|
|
||||||
} else if (session_select(s, wl->idx) == 0) {
|
|
||||||
cmd_find_from_session(current, s, 0);
|
|
||||||
server_redraw_session(s);
|
|
||||||
}
|
}
|
||||||
cmdq_insert_hook(s, item, current, "after-select-window");
|
|
||||||
|
server_redraw_session(s);
|
||||||
|
} else {
|
||||||
|
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (session_select(s, wl->idx) == 0)
|
||||||
|
server_redraw_session(s);
|
||||||
}
|
}
|
||||||
if (c != NULL && c->session != NULL)
|
|
||||||
s->curw->window->latest = c;
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
232
cmd-send-keys.c
232
cmd-send-keys.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -27,211 +26,40 @@
|
|||||||
* Send keys to client.
|
* Send keys to client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmdq_item *);
|
int cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_send_keys_entry = {
|
const struct cmd_entry cmd_send_keys_entry = {
|
||||||
.name = "send-keys",
|
"send-keys", "send",
|
||||||
.alias = "send",
|
"t:", 0, -1,
|
||||||
|
"[-t target-pane] key ...",
|
||||||
.args = { "c:FHKlMN:Rt:X", 0, -1, NULL },
|
0,
|
||||||
.usage = "[-FHKlMRX] [-c target-client] [-N repeat-count] "
|
NULL,
|
||||||
CMD_TARGET_PANE_USAGE " key ...",
|
NULL,
|
||||||
|
cmd_send_keys_exec
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG|CMD_CLIENT_CANFAIL,
|
|
||||||
.exec = cmd_send_keys_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_send_prefix_entry = {
|
int
|
||||||
.name = "send-prefix",
|
cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "2t:", 0, 0, NULL },
|
|
||||||
.usage = "[-2] " CMD_TARGET_PANE_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_send_keys_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct cmdq_item *
|
|
||||||
cmd_send_keys_inject_key(struct cmdq_item *item, struct cmdq_item *after,
|
|
||||||
struct args *args, key_code key)
|
|
||||||
{
|
{
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct args *args = self->args;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct window_pane *wp;
|
||||||
struct session *s = target->s;
|
struct session *s;
|
||||||
struct winlink *wl = target->wl;
|
const char *str;
|
||||||
struct window_pane *wp = target->wp;
|
int i, key;
|
||||||
struct window_mode_entry *wme;
|
|
||||||
struct key_table *table = NULL;
|
|
||||||
struct key_binding *bd;
|
|
||||||
struct key_event *event;
|
|
||||||
|
|
||||||
if (args_has(args, 'K')) {
|
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
||||||
if (tc == NULL)
|
return (-1);
|
||||||
return (item);
|
|
||||||
event = xmalloc(sizeof *event);
|
for (i = 0; i < args->argc; i++) {
|
||||||
event->key = key|KEYC_SENT;
|
str = args->argv[i];
|
||||||
memset(&event->m, 0, sizeof event->m);
|
|
||||||
if (server_client_handle_key(tc, event) == 0)
|
if ((key = key_string_lookup_string(str)) != KEYC_NONE) {
|
||||||
free(event);
|
window_pane_key(wp, s, key);
|
||||||
return (item);
|
} else {
|
||||||
|
for (; *str != '\0'; str++)
|
||||||
|
window_pane_key(wp, s, *str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wme = TAILQ_FIRST(&wp->modes);
|
return (0);
|
||||||
if (wme == NULL || wme->mode->key_table == NULL) {
|
|
||||||
if (window_pane_key(wp, tc, s, wl, key, NULL) != 0)
|
|
||||||
return (NULL);
|
|
||||||
return (item);
|
|
||||||
}
|
|
||||||
table = key_bindings_get_table(wme->mode->key_table(wme), 1);
|
|
||||||
|
|
||||||
bd = key_bindings_get(table, key & ~KEYC_MASK_FLAGS);
|
|
||||||
if (bd != NULL) {
|
|
||||||
table->references++;
|
|
||||||
after = key_bindings_dispatch(bd, after, tc, NULL, target);
|
|
||||||
key_bindings_unref_table(table);
|
|
||||||
}
|
|
||||||
return (after);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct cmdq_item *
|
|
||||||
cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after,
|
|
||||||
struct args *args, int i)
|
|
||||||
{
|
|
||||||
const char *s = args_string(args, i);
|
|
||||||
struct utf8_data *ud, *loop;
|
|
||||||
utf8_char uc;
|
|
||||||
key_code key;
|
|
||||||
char *endptr;
|
|
||||||
long n;
|
|
||||||
int literal;
|
|
||||||
|
|
||||||
if (args_has(args, 'H')) {
|
|
||||||
n = strtol(s, &endptr, 16);
|
|
||||||
if (*s =='\0' || n < 0 || n > 0xff || *endptr != '\0')
|
|
||||||
return (item);
|
|
||||||
return (cmd_send_keys_inject_key(item, after, args,
|
|
||||||
KEYC_LITERAL|n));
|
|
||||||
}
|
|
||||||
|
|
||||||
literal = args_has(args, 'l');
|
|
||||||
if (!literal) {
|
|
||||||
key = key_string_lookup_string(s);
|
|
||||||
if (key != KEYC_NONE && key != KEYC_UNKNOWN) {
|
|
||||||
after = cmd_send_keys_inject_key(item, after, args,
|
|
||||||
key);
|
|
||||||
if (after != NULL)
|
|
||||||
return (after);
|
|
||||||
}
|
|
||||||
literal = 1;
|
|
||||||
}
|
|
||||||
if (literal) {
|
|
||||||
ud = utf8_fromcstr(s);
|
|
||||||
for (loop = ud; loop->size != 0; loop++) {
|
|
||||||
if (loop->size == 1 && loop->data[0] <= 0x7f)
|
|
||||||
key = loop->data[0];
|
|
||||||
else {
|
|
||||||
if (utf8_from_data(loop, &uc) != UTF8_DONE)
|
|
||||||
continue;
|
|
||||||
key = uc;
|
|
||||||
}
|
|
||||||
after = cmd_send_keys_inject_key(item, after, args,
|
|
||||||
key);
|
|
||||||
}
|
|
||||||
free(ud);
|
|
||||||
}
|
|
||||||
return (after);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_send_keys_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 session *s = target->s;
|
|
||||||
struct winlink *wl = target->wl;
|
|
||||||
struct window_pane *wp = target->wp;
|
|
||||||
struct key_event *event = cmdq_get_event(item);
|
|
||||||
struct mouse_event *m = &event->m;
|
|
||||||
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
|
||||||
struct cmdq_item *after = item;
|
|
||||||
key_code key;
|
|
||||||
u_int i, np = 1;
|
|
||||||
u_int count = args_count(args);
|
|
||||||
char *cause = NULL;
|
|
||||||
|
|
||||||
if (args_has(args, 'N')) {
|
|
||||||
np = args_strtonum_and_expand(args, 'N', 1, UINT_MAX, item,
|
|
||||||
&cause);
|
|
||||||
if (cause != NULL) {
|
|
||||||
cmdq_error(item, "repeat count %s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (wme != NULL && (args_has(args, 'X') || count == 0)) {
|
|
||||||
if (wme->mode->command == NULL) {
|
|
||||||
cmdq_error(item, "not in a mode");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
wme->prefix = np;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'X')) {
|
|
||||||
if (wme == NULL || wme->mode->command == NULL) {
|
|
||||||
cmdq_error(item, "not in a mode");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (!m->valid)
|
|
||||||
m = NULL;
|
|
||||||
wme->mode->command(wme, tc, s, wl, args, m);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'M')) {
|
|
||||||
wp = cmd_mouse_pane(m, &s, NULL);
|
|
||||||
if (wp == NULL) {
|
|
||||||
cmdq_error(item, "no mouse target");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
window_pane_key(wp, tc, s, wl, m->key, m);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_send_prefix_entry) {
|
|
||||||
if (args_has(args, '2'))
|
|
||||||
key = options_get_number(s->options, "prefix2");
|
|
||||||
else
|
|
||||||
key = options_get_number(s->options, "prefix");
|
|
||||||
cmd_send_keys_inject_key(item, item, args, key);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'R')) {
|
|
||||||
colour_palette_clear(&wp->palette);
|
|
||||||
input_reset(wp->ictx, 1);
|
|
||||||
wp->flags |= (PANE_STYLECHANGED|PANE_REDRAW);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
if (args_has(args, 'N') || args_has(args, 'R'))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
for (; np != 0; np--)
|
|
||||||
cmd_send_keys_inject_key(item, NULL, args, event->key);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; np != 0; np--) {
|
|
||||||
for (i = 0; i < count; i++) {
|
|
||||||
after = cmd_send_keys_inject_string(item, after, args,
|
|
||||||
i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
54
cmd-send-prefix.c
Normal file
54
cmd-send-prefix.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send prefix key as a key.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_send_prefix_entry = {
|
||||||
|
"send-prefix", NULL,
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_send_prefix_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct keylist *keylist;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
keylist = options_get_data(&s->options, "prefix");
|
||||||
|
window_pane_key(wp, s, ARRAY_FIRST(keylist));
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2021 Dallas Lyons <dallasdlyons@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/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Controls access to session.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_server_access_exec(struct cmd *, struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_server_access_entry = {
|
|
||||||
.name = "server-access",
|
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "adlrw", 0, 1, NULL },
|
|
||||||
.usage = "[-adlrw] " CMD_TARGET_PANE_USAGE " [user]",
|
|
||||||
|
|
||||||
.flags = CMD_CLIENT_CANFAIL,
|
|
||||||
.exec = cmd_server_access_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_server_access_deny(struct cmdq_item *item, struct passwd *pw)
|
|
||||||
{
|
|
||||||
struct client *loop;
|
|
||||||
struct server_acl_user *user;
|
|
||||||
uid_t uid;
|
|
||||||
|
|
||||||
if ((user = server_acl_user_find(pw->pw_uid)) == NULL) {
|
|
||||||
cmdq_error(item, "user %s not found", pw->pw_name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
TAILQ_FOREACH(loop, &clients, entry) {
|
|
||||||
uid = proc_get_peer_uid(loop->peer);
|
|
||||||
if (uid == server_acl_get_uid(user)) {
|
|
||||||
loop->exit_message = xstrdup("access not allowed");
|
|
||||||
loop->flags |= CLIENT_EXIT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
server_acl_user_deny(pw->pw_uid);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_server_access_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
|
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
struct client *c = cmdq_get_target_client(item);
|
|
||||||
char *name;
|
|
||||||
struct passwd *pw = NULL;
|
|
||||||
|
|
||||||
if (args_has(args, 'l')) {
|
|
||||||
server_acl_display(item);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
if (args_count(args) == 0) {
|
|
||||||
cmdq_error(item, "missing user argument");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
name = format_single(item, args_string(args, 0), c, NULL, NULL, NULL);
|
|
||||||
if (*name != '\0')
|
|
||||||
pw = getpwnam(name);
|
|
||||||
if (pw == NULL) {
|
|
||||||
cmdq_error(item, "unknown user: %s", name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
free(name);
|
|
||||||
|
|
||||||
if (pw->pw_uid == 0 || pw->pw_uid == getuid()) {
|
|
||||||
cmdq_error(item, "%s owns the server, can't change access",
|
|
||||||
pw->pw_name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'a') && args_has(args, 'd')) {
|
|
||||||
cmdq_error(item, "-a and -d cannot be used together");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (args_has(args, 'w') && args_has(args, 'r')) {
|
|
||||||
cmdq_error(item, "-r and -w cannot be used together");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'd'))
|
|
||||||
return (cmd_server_access_deny(item, pw));
|
|
||||||
if (args_has(args, 'a')) {
|
|
||||||
if (server_acl_user_find(pw->pw_uid) != NULL) {
|
|
||||||
cmdq_error(item, "user %s is already added",
|
|
||||||
pw->pw_name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
server_acl_user_allow(pw->pw_uid);
|
|
||||||
/* Do not return - allow -r or -w with -a. */
|
|
||||||
} else if (args_has(args, 'r') || args_has(args, 'w')) {
|
|
||||||
/* -r or -w implies -a if user does not exist. */
|
|
||||||
if (server_acl_user_find(pw->pw_uid) == NULL)
|
|
||||||
server_acl_user_allow(pw->pw_uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'w')) {
|
|
||||||
if (server_acl_user_find(pw->pw_uid) == NULL) {
|
|
||||||
cmdq_error(item, "user %s not found", pw->pw_name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
server_acl_user_allow_write(pw->pw_uid);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'r')) {
|
|
||||||
if (server_acl_user_find(pw->pw_uid) == NULL) {
|
|
||||||
cmdq_error(item, "user %s not found", pw->pw_name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
server_acl_user_deny_write(pw->pw_uid);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
183
cmd-server-info.c
Normal file
183
cmd-server-info.c
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show various information about server.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_server_info_entry = {
|
||||||
|
"server-info", "info",
|
||||||
|
"", 0, 0,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_server_info_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct tty_term *term;
|
||||||
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct tty_code *code;
|
||||||
|
const struct tty_term_code_entry *ent;
|
||||||
|
struct utsname un;
|
||||||
|
struct job *job;
|
||||||
|
struct grid *gd;
|
||||||
|
struct grid_line *gl;
|
||||||
|
u_int i, j, k;
|
||||||
|
char out[80];
|
||||||
|
char *tim;
|
||||||
|
time_t t;
|
||||||
|
u_int lines, ulines;
|
||||||
|
size_t size, usize;
|
||||||
|
|
||||||
|
tim = ctime(&start_time);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
ctx->print(ctx,
|
||||||
|
"tmux " VERSION ", pid %ld, started %s", (long) getpid(), tim);
|
||||||
|
ctx->print(
|
||||||
|
ctx, "socket path %s, debug level %d", socket_path, debug_level);
|
||||||
|
if (uname(&un) >= 0) {
|
||||||
|
ctx->print(ctx, "system is %s %s %s %s",
|
||||||
|
un.sysname, un.release, un.version, un.machine);
|
||||||
|
}
|
||||||
|
if (cfg_file != NULL)
|
||||||
|
ctx->print(ctx, "configuration file is %s", cfg_file);
|
||||||
|
else
|
||||||
|
ctx->print(ctx, "configuration file not specified");
|
||||||
|
ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Clients:");
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho] "
|
||||||
|
"[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
|
||||||
|
c->ibuf.fd, c->tty.fd, c->session->name,
|
||||||
|
c->tty.sx, c->tty.sy, c->tty.termname,
|
||||||
|
c->tty.tio.c_cc[VERASE], c->flags,
|
||||||
|
c->tty.flags, c->references);
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Sessions: [%zu/%zu]",
|
||||||
|
sizeof (struct grid_cell), sizeof (struct grid_utf8));
|
||||||
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
|
t = s->creation_time.tv_sec;
|
||||||
|
tim = ctime(&t);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
|
||||||
|
"[flags=0x%x]", s->idx, s->name,
|
||||||
|
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
|
||||||
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
|
w = wl->window;
|
||||||
|
ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
|
||||||
|
"references=%u, last layout=%d]", wl->idx, w->name,
|
||||||
|
w->sx, w->sy, w->flags, w->references,
|
||||||
|
w->lastlayout);
|
||||||
|
j = 0;
|
||||||
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
|
lines = ulines = size = usize = 0;
|
||||||
|
gd = wp->base.grid;
|
||||||
|
for (k = 0; k < gd->hsize + gd->sy; k++) {
|
||||||
|
gl = &gd->linedata[k];
|
||||||
|
if (gl->celldata != NULL) {
|
||||||
|
lines++;
|
||||||
|
size += gl->cellsize *
|
||||||
|
sizeof *gl->celldata;
|
||||||
|
}
|
||||||
|
if (gl->utf8data != NULL) {
|
||||||
|
ulines++;
|
||||||
|
usize += gl->utf8size *
|
||||||
|
sizeof *gl->utf8data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
|
||||||
|
"bytes; UTF-8 %u/%u, %zu bytes", j,
|
||||||
|
wp->tty, (u_long) wp->pid, wp->fd, lines,
|
||||||
|
gd->hsize + gd->sy, size, ulines,
|
||||||
|
gd->hsize + gd->sy, usize);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Terminals:");
|
||||||
|
LIST_FOREACH(term, &tty_terms, entry) {
|
||||||
|
ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
|
||||||
|
term->name, term->references, term->flags);
|
||||||
|
for (i = 0; i < NTTYCODE; i++) {
|
||||||
|
ent = &tty_term_codes[i];
|
||||||
|
code = &term->codes[ent->code];
|
||||||
|
switch (code->type) {
|
||||||
|
case TTYCODE_NONE:
|
||||||
|
ctx->print(ctx, "%2u: %s: [missing]",
|
||||||
|
ent->code, ent->name);
|
||||||
|
break;
|
||||||
|
case TTYCODE_STRING:
|
||||||
|
strnvis(out, code->value.string, sizeof out,
|
||||||
|
VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||||
|
ctx->print(ctx, "%2u: %s: (string) %s",
|
||||||
|
ent->code, ent->name, out);
|
||||||
|
break;
|
||||||
|
case TTYCODE_NUMBER:
|
||||||
|
ctx->print(ctx, "%2u: %s: (number) %d",
|
||||||
|
ent->code, ent->name, code->value.number);
|
||||||
|
break;
|
||||||
|
case TTYCODE_FLAG:
|
||||||
|
ctx->print(ctx, "%2u: %s: (flag) %s",
|
||||||
|
ent->code, ent->name,
|
||||||
|
code->value.flag ? "true" : "false");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Jobs:");
|
||||||
|
LIST_FOREACH(job, &all_jobs, lentry) {
|
||||||
|
ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d]",
|
||||||
|
job->cmd, job->fd, job->pid, job->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
134
cmd-set-buffer.c
134
cmd-set-buffer.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,120 +18,58 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add, set, append to or delete a paste buffer.
|
* Add or set a session paste buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmdq_item *);
|
int cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_buffer_entry = {
|
const struct cmd_entry cmd_set_buffer_entry = {
|
||||||
.name = "set-buffer",
|
"set-buffer", "setb",
|
||||||
.alias = "setb",
|
"b:", 1, 1,
|
||||||
|
CMD_BUFFER_USAGE " data",
|
||||||
.args = { "ab:t:n:w", 0, 1, NULL },
|
0,
|
||||||
.usage = "[-aw] " CMD_BUFFER_USAGE " [-n new-buffer-name] "
|
NULL,
|
||||||
CMD_TARGET_CLIENT_USAGE " data",
|
NULL,
|
||||||
|
cmd_set_buffer_exec
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
|
|
||||||
.exec = cmd_set_buffer_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_delete_buffer_entry = {
|
int
|
||||||
.name = "delete-buffer",
|
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = "deleteb",
|
|
||||||
|
|
||||||
.args = { "b:", 0, 0, NULL },
|
|
||||||
.usage = CMD_BUFFER_USAGE,
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_set_buffer_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
u_int limit;
|
||||||
struct paste_buffer *pb;
|
char *pdata, *cause;
|
||||||
char *bufdata, *cause;
|
size_t psize;
|
||||||
const char *bufname, *olddata;
|
int buffer;
|
||||||
size_t bufsize, newsize;
|
|
||||||
|
|
||||||
bufname = args_get(args, 'b');
|
limit = options_get_number(&global_options, "buffer-limit");
|
||||||
if (bufname == NULL)
|
|
||||||
pb = NULL;
|
|
||||||
else
|
|
||||||
pb = paste_get_name(bufname);
|
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_delete_buffer_entry) {
|
pdata = xstrdup(args->argv[0]);
|
||||||
if (pb == NULL) {
|
psize = strlen(pdata);
|
||||||
if (bufname != NULL) {
|
|
||||||
cmdq_error(item, "unknown buffer: %s", bufname);
|
if (!args_has(args, 'b')) {
|
||||||
return (CMD_RETURN_ERROR);
|
paste_add(&global_buffers, pdata, psize, limit);
|
||||||
}
|
return (0);
|
||||||
pb = paste_get_top(&bufname);
|
|
||||||
}
|
|
||||||
if (pb == NULL) {
|
|
||||||
cmdq_error(item, "no buffer");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
paste_free(pb);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'n')) {
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
if (pb == NULL) {
|
if (cause != NULL) {
|
||||||
if (bufname != NULL) {
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
cmdq_error(item, "unknown buffer: %s", bufname);
|
xfree(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
xfree(pdata);
|
||||||
}
|
return (-1);
|
||||||
pb = paste_get_top(&bufname);
|
|
||||||
}
|
|
||||||
if (pb == NULL) {
|
|
||||||
cmdq_error(item, "no buffer");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) {
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_count(args) != 1) {
|
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
|
||||||
cmdq_error(item, "no data specified");
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
return (CMD_RETURN_ERROR);
|
xfree(pdata);
|
||||||
}
|
return (-1);
|
||||||
if ((newsize = strlen(args_string(args, 0))) == 0)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
bufsize = 0;
|
|
||||||
bufdata = NULL;
|
|
||||||
|
|
||||||
if (args_has(args, 'a') && pb != NULL) {
|
|
||||||
olddata = paste_buffer_data(pb, &bufsize);
|
|
||||||
bufdata = xmalloc(bufsize);
|
|
||||||
memcpy(bufdata, olddata, bufsize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bufdata = xrealloc(bufdata, bufsize + newsize);
|
return (0);
|
||||||
memcpy(bufdata + bufsize, args_string(args, 0), newsize);
|
|
||||||
bufsize += newsize;
|
|
||||||
|
|
||||||
if (paste_set(bufdata, bufsize, bufname, &cause) != 0) {
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(bufdata);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (args_has(args, 'w') && tc != NULL)
|
|
||||||
tty_set_selection(&tc->tty, "", bufdata, bufsize);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -27,93 +27,68 @@
|
|||||||
* Set an environment variable.
|
* Set an environment variable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_set_environment_exec(struct cmd *,
|
int cmd_set_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_environment_entry = {
|
const struct cmd_entry cmd_set_environment_entry = {
|
||||||
.name = "set-environment",
|
"set-environment", "setenv",
|
||||||
.alias = "setenv",
|
"grt:u", 1, 2,
|
||||||
|
"[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
||||||
.args = { "Fhgrt:u", 1, 2, NULL },
|
0,
|
||||||
.usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
cmd_set_environment_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_set_environment_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct session *s;
|
||||||
struct environ *env;
|
struct environ *env;
|
||||||
const char *name = args_string(args, 0), *value;
|
const char *name, *value;
|
||||||
const char *tflag;
|
|
||||||
char *expanded = NULL;
|
|
||||||
enum cmd_retval retval = CMD_RETURN_NORMAL;
|
|
||||||
|
|
||||||
|
name = args->argv[0];
|
||||||
if (*name == '\0') {
|
if (*name == '\0') {
|
||||||
cmdq_error(item, "empty variable name");
|
ctx->error(ctx, "empty variable name");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (strchr(name, '=') != NULL) {
|
if (strchr(name, '=') != NULL) {
|
||||||
cmdq_error(item, "variable name contains =");
|
ctx->error(ctx, "variable name contains =");
|
||||||
return (CMD_RETURN_ERROR);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_count(args) < 2)
|
if (args->argc < 1)
|
||||||
value = NULL;
|
value = NULL;
|
||||||
else
|
else
|
||||||
value = args_string(args, 1);
|
value = args->argv[1];
|
||||||
if (value != NULL && args_has(args, 'F')) {
|
|
||||||
expanded = format_single_from_target(item, value);
|
if (args_has(self->args, 'g'))
|
||||||
value = expanded;
|
env = &global_environ;
|
||||||
}
|
|
||||||
if (args_has(args, 'g'))
|
|
||||||
env = global_environ;
|
|
||||||
else {
|
else {
|
||||||
if (target->s == NULL) {
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||||
tflag = args_get(args, 't');
|
return (-1);
|
||||||
if (tflag != NULL)
|
env = &s->environ;
|
||||||
cmdq_error(item, "no such session: %s", tflag);
|
|
||||||
else
|
|
||||||
cmdq_error(item, "no current session");
|
|
||||||
retval = CMD_RETURN_ERROR;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
env = target->s->environ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'u')) {
|
if (args_has(self->args, 'u')) {
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
cmdq_error(item, "can't specify a value with -u");
|
ctx->error(ctx, "can't specify a value with -u");
|
||||||
retval = CMD_RETURN_ERROR;
|
return (-1);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
environ_unset(env, name);
|
environ_unset(env, name);
|
||||||
} else if (args_has(args, 'r')) {
|
} else if (args_has(self->args, 'r')) {
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
cmdq_error(item, "can't specify a value with -r");
|
ctx->error(ctx, "can't specify a value with -r");
|
||||||
retval = CMD_RETURN_ERROR;
|
return (-1);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
environ_clear(env, name);
|
environ_set(env, name, NULL);
|
||||||
} else {
|
} else {
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
cmdq_error(item, "no value specified");
|
ctx->error(ctx, "no value specified");
|
||||||
retval = CMD_RETURN_ERROR;
|
return (-1);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
environ_set(env, name, value);
|
||||||
if (args_has(args, 'h'))
|
|
||||||
environ_set(env, name, ENVIRON_HIDDEN, "%s", value);
|
|
||||||
else
|
|
||||||
environ_set(env, name, 0, "%s", value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
return (0);
|
||||||
free(expanded);
|
|
||||||
return (retval);
|
|
||||||
}
|
}
|
||||||
|
|||||||
546
cmd-set-option.c
546
cmd-set-option.c
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -27,213 +27,385 @@
|
|||||||
* Set an option.
|
* Set an option.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum args_parse_type cmd_set_option_args_parse(struct args *,
|
int cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
||||||
u_int, char **);
|
|
||||||
static enum cmd_retval cmd_set_option_exec(struct cmd *,
|
int cmd_set_option_find(const char *, const struct options_table_entry **,
|
||||||
struct cmdq_item *);
|
const struct options_table_entry **);
|
||||||
|
|
||||||
|
int cmd_set_option_unset(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
int cmd_set_option_set(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
|
||||||
|
struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_keys(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_option_entry = {
|
const struct cmd_entry cmd_set_option_entry = {
|
||||||
.name = "set-option",
|
"set-option", "set",
|
||||||
.alias = "set",
|
"agst:uw", 1, 2,
|
||||||
|
"[-agsuw] [-t target-session|target-window] option [value]",
|
||||||
.args = { "aFgopqst:uUw", 1, 2, cmd_set_option_args_parse },
|
0,
|
||||||
.usage = "[-aFgopqsuUw] " CMD_TARGET_PANE_USAGE " option [value]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
cmd_set_option_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_set_option_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_window_option_entry = {
|
const struct cmd_entry cmd_set_window_option_entry = {
|
||||||
.name = "set-window-option",
|
"set-window-option", "setw",
|
||||||
.alias = "setw",
|
"agt:u", 1, 2,
|
||||||
|
"[-agu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||||
.args = { "aFgoqt:u", 1, 2, cmd_set_option_args_parse },
|
0,
|
||||||
.usage = "[-aFgoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
cmd_set_option_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_set_option_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_set_hook_entry = {
|
/* Look for an option in all three tables. */
|
||||||
.name = "set-hook",
|
int
|
||||||
.alias = NULL,
|
cmd_set_option_find(
|
||||||
|
const char *optstr, const struct options_table_entry **table,
|
||||||
.args = { "agpRt:uw", 1, 2, cmd_set_option_args_parse },
|
const struct options_table_entry **oe)
|
||||||
.usage = "[-agpRuw] " CMD_TARGET_PANE_USAGE " hook [command]",
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_set_option_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum args_parse_type
|
|
||||||
cmd_set_option_args_parse(__unused struct args *args, u_int idx,
|
|
||||||
__unused char **cause)
|
|
||||||
{
|
{
|
||||||
if (idx == 1)
|
static const struct options_table_entry *tables[] = {
|
||||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
server_options_table,
|
||||||
return (ARGS_PARSE_STRING);
|
window_options_table,
|
||||||
|
session_options_table
|
||||||
|
};
|
||||||
|
const struct options_table_entry *oe_loop;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
for (i = 0; i < nitems(tables); i++) {
|
||||||
|
for (oe_loop = tables[i]; oe_loop->name != NULL; oe_loop++) {
|
||||||
|
if (strncmp(oe_loop->name, optstr, strlen(optstr)) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* If already found, ambiguous. */
|
||||||
|
if (*oe != NULL)
|
||||||
|
return (-1);
|
||||||
|
*oe = oe_loop;
|
||||||
|
*table = tables[i];
|
||||||
|
|
||||||
|
/* Bail now if an exact match. */
|
||||||
|
if (strcmp((*oe)->name, optstr) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
int
|
||||||
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
int append = args_has(args, 'a');
|
const struct options_table_entry *table, *oe;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct session *s;
|
||||||
struct window_pane *loop;
|
struct winlink *wl;
|
||||||
struct options *oo;
|
struct client *c;
|
||||||
struct options_entry *parent, *o, *po;
|
struct options *oo;
|
||||||
char *name, *argument, *expanded = NULL;
|
const char *optstr, *valstr;
|
||||||
char *cause;
|
u_int i;
|
||||||
const char *value;
|
|
||||||
int window, idx, already, error, ambiguous;
|
|
||||||
int scope;
|
|
||||||
|
|
||||||
window = (cmd_get_entry(self) == &cmd_set_window_option_entry);
|
/* Get the option name and value. */
|
||||||
|
optstr = args->argv[0];
|
||||||
/* Expand argument. */
|
if (*optstr == '\0') {
|
||||||
argument = format_single_from_target(item, args_string(args, 0));
|
ctx->error(ctx, "invalid option");
|
||||||
|
return (-1);
|
||||||
/* If set-hook -R, fire the hook straight away. */
|
|
||||||
if (cmd_get_entry(self) == &cmd_set_hook_entry && args_has(args, 'R')) {
|
|
||||||
notify_hook(item, argument);
|
|
||||||
free(argument);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
if (args->argc < 2)
|
||||||
/* Parse option name and index. */
|
valstr = NULL;
|
||||||
name = options_match(argument, &idx, &ambiguous);
|
|
||||||
if (name == NULL) {
|
|
||||||
if (args_has(args, 'q'))
|
|
||||||
goto out;
|
|
||||||
if (ambiguous)
|
|
||||||
cmdq_error(item, "ambiguous option: %s", argument);
|
|
||||||
else
|
|
||||||
cmdq_error(item, "invalid option: %s", argument);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
if (args_count(args) < 2)
|
|
||||||
value = NULL;
|
|
||||||
else
|
else
|
||||||
value = args_string(args, 1);
|
valstr = args->argv[1];
|
||||||
if (value != NULL && args_has(args, 'F')) {
|
|
||||||
expanded = format_single_from_target(item, value);
|
/* Find the option entry, try each table. */
|
||||||
value = expanded;
|
table = oe = NULL;
|
||||||
|
if (cmd_set_option_find(optstr, &table, &oe) != 0) {
|
||||||
|
ctx->error(ctx, "ambiguous option: %s", optstr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (oe == NULL) {
|
||||||
|
ctx->error(ctx, "unknown option: %s", optstr);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the scope and table for the option .*/
|
/* Work out the tree from the table. */
|
||||||
scope = options_scope_from_name(args, window, name, target, &oo,
|
if (table == server_options_table)
|
||||||
&cause);
|
oo = &global_options;
|
||||||
if (scope == OPTIONS_TABLE_NONE) {
|
else if (table == window_options_table) {
|
||||||
if (args_has(args, 'q'))
|
if (args_has(self->args, 'g'))
|
||||||
goto out;
|
oo = &global_w_options;
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
o = options_get_only(oo, name);
|
|
||||||
parent = options_get(oo, name);
|
|
||||||
|
|
||||||
/* Check that array options and indexes match up. */
|
|
||||||
if (idx != -1 && (*name == '@' || !options_is_array(parent))) {
|
|
||||||
cmdq_error(item, "not an array: %s", argument);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* With -o, check this option is not already set. */
|
|
||||||
if (!args_has(args, 'u') && args_has(args, 'o')) {
|
|
||||||
if (idx == -1)
|
|
||||||
already = (o != NULL);
|
|
||||||
else {
|
else {
|
||||||
if (o == NULL)
|
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
||||||
already = 0;
|
if (wl == NULL)
|
||||||
else
|
return (-1);
|
||||||
already = (options_array_get(o, idx) != NULL);
|
oo = &wl->window->options;
|
||||||
}
|
}
|
||||||
if (already) {
|
} else if (table == session_options_table) {
|
||||||
if (args_has(args, 'q'))
|
if (args_has(self->args, 'g'))
|
||||||
goto out;
|
oo = &global_s_options;
|
||||||
cmdq_error(item, "already set: %s", argument);
|
else {
|
||||||
goto fail;
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
}
|
if (s == NULL)
|
||||||
}
|
return (-1);
|
||||||
|
oo = &s->options;
|
||||||
/* Change the option. */
|
|
||||||
if (args_has(args, 'U') && scope == OPTIONS_TABLE_WINDOW) {
|
|
||||||
TAILQ_FOREACH(loop, &target->w->panes, entry) {
|
|
||||||
po = options_get_only(loop->options, name);
|
|
||||||
if (po == NULL)
|
|
||||||
continue;
|
|
||||||
if (options_remove_or_default(po, idx, &cause) != 0) {
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (args_has(args, 'u') || args_has(args, 'U')) {
|
|
||||||
if (o == NULL)
|
|
||||||
goto out;
|
|
||||||
if (options_remove_or_default(o, idx, &cause) != 0) {
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
} else if (*name == '@') {
|
|
||||||
if (value == NULL) {
|
|
||||||
cmdq_error(item, "empty value");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
options_set_string(oo, name, append, "%s", value);
|
|
||||||
} else if (idx == -1 && !options_is_array(parent)) {
|
|
||||||
error = options_from_string(oo, options_table_entry(parent),
|
|
||||||
options_table_entry(parent)->name, value,
|
|
||||||
args_has(args, 'a'), &cause);
|
|
||||||
if (error != 0) {
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (value == NULL) {
|
ctx->error(ctx, "unknown table");
|
||||||
cmdq_error(item, "empty value");
|
return (-1);
|
||||||
goto fail;
|
}
|
||||||
|
|
||||||
|
/* Unset or set the option. */
|
||||||
|
if (args_has(args, 'u')) {
|
||||||
|
if (cmd_set_option_unset(self, ctx, oe, oo, valstr) != 0)
|
||||||
|
return (-1);
|
||||||
|
} else {
|
||||||
|
if (cmd_set_option_set(self, ctx, oe, oo, valstr) != 0)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update sizes and redraw. May not need it but meh. */
|
||||||
|
recalculate_sizes();
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c != NULL && c->session != NULL)
|
||||||
|
server_redraw_client(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unset an option. */
|
||||||
|
int
|
||||||
|
cmd_set_option_unset(struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
|
||||||
|
if (args_has(args, 'g')) {
|
||||||
|
ctx->error(ctx, "can't unset global option: %s", oe->name);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (value != NULL) {
|
||||||
|
ctx->error(ctx, "value passed to unset option: %s", oe->name);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
options_remove(oo, oe->name);
|
||||||
|
ctx->info(ctx, "unset option: %s", oe->name);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set an option. */
|
||||||
|
int
|
||||||
|
cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
struct options_entry *o;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
|
if (oe->type != OPTIONS_TABLE_FLAG && value == NULL) {
|
||||||
|
ctx->error(ctx, "empty value");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
o = NULL;
|
||||||
|
switch (oe->type) {
|
||||||
|
case OPTIONS_TABLE_STRING:
|
||||||
|
o = cmd_set_option_string(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_NUMBER:
|
||||||
|
o = cmd_set_option_number(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_KEYS:
|
||||||
|
o = cmd_set_option_keys(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_COLOUR:
|
||||||
|
o = cmd_set_option_colour(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_ATTRIBUTES:
|
||||||
|
o = cmd_set_option_attributes(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_FLAG:
|
||||||
|
o = cmd_set_option_flag(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_CHOICE:
|
||||||
|
o = cmd_set_option_choice(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (o == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
s = options_table_print_entry(oe, o);
|
||||||
|
ctx->info(ctx, "set option: %s -> %s", oe->name, s);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a string option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_string(struct cmd *self, unused struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct options_entry *o;
|
||||||
|
char *oldval, *newval;
|
||||||
|
|
||||||
|
if (args_has(args, 'a')) {
|
||||||
|
oldval = options_get_string(oo, oe->name);
|
||||||
|
xasprintf(&newval, "%s%s", oldval, value);
|
||||||
|
} else
|
||||||
|
newval = xstrdup(value);
|
||||||
|
|
||||||
|
o = options_set_string(oo, oe->name, "%s", newval);
|
||||||
|
|
||||||
|
xfree(newval);
|
||||||
|
return (o);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a number option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
long long ll;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
|
ll = strtonum(value, oe->minimum, oe->maximum, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
ctx->error(ctx, "value is %s: %s", errstr, value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (options_set_number(oo, oe->name, ll));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a keys option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_keys(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
struct keylist *keylist;
|
||||||
|
char *copy, *ptr, *s;
|
||||||
|
int key;
|
||||||
|
|
||||||
|
keylist = xmalloc(sizeof *keylist);
|
||||||
|
ARRAY_INIT(keylist);
|
||||||
|
|
||||||
|
ptr = copy = xstrdup(value);
|
||||||
|
while ((s = strsep(&ptr, ",")) != NULL) {
|
||||||
|
if ((key = key_string_lookup_string(s)) == KEYC_NONE) {
|
||||||
|
ctx->error(ctx, "unknown key: %s", s);
|
||||||
|
xfree(copy);
|
||||||
|
xfree(keylist);
|
||||||
|
return (NULL);
|
||||||
}
|
}
|
||||||
if (o == NULL)
|
ARRAY_ADD(keylist, key);
|
||||||
o = options_empty(oo, options_table_entry(parent));
|
}
|
||||||
if (idx == -1) {
|
xfree(copy);
|
||||||
if (!append)
|
|
||||||
options_array_clear(o);
|
return (options_set_data(oo, oe->name, keylist, xfree));
|
||||||
if (options_array_assign(o, value, &cause) != 0) {
|
}
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
/* Set a colour option. */
|
||||||
goto fail;
|
struct options_entry *
|
||||||
}
|
cmd_set_option_colour(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
} else if (options_array_set(o, idx, value, append,
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
&cause) != 0) {
|
{
|
||||||
cmdq_error(item, "%s", cause);
|
int colour;
|
||||||
free(cause);
|
|
||||||
goto fail;
|
if ((colour = colour_fromstring(value)) == -1) {
|
||||||
|
ctx->error(ctx, "bad colour: %s", value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (options_set_number(oo, oe->name, colour));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set an attributes option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_attributes(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
int attr;
|
||||||
|
|
||||||
|
if ((attr = attributes_fromstring(value)) == -1) {
|
||||||
|
ctx->error(ctx, "bad attributes: %s", value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (options_set_number(oo, oe->name, attr));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a flag option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
int flag;
|
||||||
|
|
||||||
|
if (value == NULL || *value == '\0')
|
||||||
|
flag = !options_get_number(oo, oe->name);
|
||||||
|
else {
|
||||||
|
if ((value[0] == '1' && value[1] == '\0') ||
|
||||||
|
strcasecmp(value, "on") == 0 ||
|
||||||
|
strcasecmp(value, "yes") == 0)
|
||||||
|
flag = 1;
|
||||||
|
else if ((value[0] == '0' && value[1] == '\0') ||
|
||||||
|
strcasecmp(value, "off") == 0 ||
|
||||||
|
strcasecmp(value, "no") == 0)
|
||||||
|
flag = 0;
|
||||||
|
else {
|
||||||
|
ctx->error(ctx, "bad value: %s", value);
|
||||||
|
return (NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
options_push_changes(name);
|
return (options_set_number(oo, oe->name, flag));
|
||||||
|
}
|
||||||
out:
|
|
||||||
free(argument);
|
/* Set a choice option. */
|
||||||
free(expanded);
|
struct options_entry *
|
||||||
free(name);
|
cmd_set_option_choice(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
return (CMD_RETURN_NORMAL);
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
fail:
|
const char **choicep;
|
||||||
free(argument);
|
int n, choice = -1;
|
||||||
free(expanded);
|
|
||||||
free(name);
|
n = 0;
|
||||||
return (CMD_RETURN_ERROR);
|
for (choicep = oe->choices; *choicep != NULL; choicep++) {
|
||||||
|
n++;
|
||||||
|
if (strncmp(*choicep, value, strlen(value)) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (choice != -1) {
|
||||||
|
ctx->error(ctx, "ambiguous value: %s", value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
choice = n - 1;
|
||||||
|
}
|
||||||
|
if (choice == -1) {
|
||||||
|
ctx->error(ctx, "unknown value: %s", value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (options_set_number(oo, oe->name, choice));
|
||||||
}
|
}
|
||||||
|
|||||||
109
cmd-show-buffer.c
Normal file
109
cmd-show-buffer.c
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show a session paste buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_show_buffer_entry = {
|
||||||
|
"show-buffer", "showb",
|
||||||
|
"b:", 0, 0,
|
||||||
|
CMD_BUFFER_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_show_buffer_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
int buffer;
|
||||||
|
char *in, *buf, *ptr, *cause;
|
||||||
|
size_t size, len;
|
||||||
|
u_int width;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, NULL, 0)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (!args_has(args, 'b')) {
|
||||||
|
if ((pb = paste_get_top(&global_buffers)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffers");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pb = paste_get_index(&global_buffers, buffer);
|
||||||
|
if (pb == NULL) {
|
||||||
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size = pb->size;
|
||||||
|
if (size > SIZE_MAX / 4 - 1)
|
||||||
|
size = SIZE_MAX / 4 - 1;
|
||||||
|
in = xmalloc(size * 4 + 1);
|
||||||
|
strvisx(in, pb->data, size, VIS_OCTAL|VIS_TAB);
|
||||||
|
|
||||||
|
width = s->sx;
|
||||||
|
if (ctx->cmdclient != NULL)
|
||||||
|
width = ctx->cmdclient->tty.sx;
|
||||||
|
|
||||||
|
buf = xmalloc(width + 1);
|
||||||
|
len = 0;
|
||||||
|
|
||||||
|
ptr = in;
|
||||||
|
do {
|
||||||
|
buf[len++] = *ptr++;
|
||||||
|
|
||||||
|
if (len == width || buf[len - 1] == '\n') {
|
||||||
|
if (buf[len - 1] == '\n')
|
||||||
|
len--;
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%s", buf);
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
} while (*ptr != '\0');
|
||||||
|
|
||||||
|
if (len != 0) {
|
||||||
|
buf[len] = '\0';
|
||||||
|
ctx->print(ctx, "%s", buf);
|
||||||
|
}
|
||||||
|
xfree(buf);
|
||||||
|
|
||||||
|
xfree(in);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -27,117 +27,40 @@
|
|||||||
* Show environment.
|
* Show environment.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_show_environment_exec(struct cmd *,
|
int cmd_show_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
static char *cmd_show_environment_escape(struct environ_entry *);
|
|
||||||
static void cmd_show_environment_print(struct cmd *, struct cmdq_item *,
|
|
||||||
struct environ_entry *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_environment_entry = {
|
const struct cmd_entry cmd_show_environment_entry = {
|
||||||
.name = "show-environment",
|
"show-environment", "showenv",
|
||||||
.alias = "showenv",
|
"gt:", 0, 0,
|
||||||
|
"[-g] " CMD_TARGET_SESSION_USAGE,
|
||||||
.args = { "hgst:", 0, 1, NULL },
|
0,
|
||||||
.usage = "[-hgs] " CMD_TARGET_SESSION_USAGE " [name]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
cmd_show_environment_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_show_environment_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *
|
int
|
||||||
cmd_show_environment_escape(struct environ_entry *envent)
|
cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
const char *value = envent->value;
|
struct args *args = self->args;
|
||||||
char c, *out, *ret;
|
struct session *s;
|
||||||
|
|
||||||
out = ret = xmalloc(strlen(value) * 2 + 1); /* at most twice the size */
|
|
||||||
while ((c = *value++) != '\0') {
|
|
||||||
/* POSIX interprets $ ` " and \ in double quotes. */
|
|
||||||
if (c == '$' || c == '`' || c == '"' || c == '\\')
|
|
||||||
*out++ = '\\';
|
|
||||||
*out++ = c;
|
|
||||||
}
|
|
||||||
*out = '\0';
|
|
||||||
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_show_environment_print(struct cmd *self, struct cmdq_item *item,
|
|
||||||
struct environ_entry *envent)
|
|
||||||
{
|
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
char *escaped;
|
|
||||||
|
|
||||||
if (!args_has(args, 'h') && (envent->flags & ENVIRON_HIDDEN))
|
|
||||||
return;
|
|
||||||
if (args_has(args, 'h') && (~envent->flags & ENVIRON_HIDDEN))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!args_has(args, 's')) {
|
|
||||||
if (envent->value != NULL)
|
|
||||||
cmdq_print(item, "%s=%s", envent->name, envent->value);
|
|
||||||
else
|
|
||||||
cmdq_print(item, "-%s", envent->name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (envent->value != NULL) {
|
|
||||||
escaped = cmd_show_environment_escape(envent);
|
|
||||||
cmdq_print(item, "%s=\"%s\"; export %s;", envent->name, escaped,
|
|
||||||
envent->name);
|
|
||||||
free(escaped);
|
|
||||||
} else
|
|
||||||
cmdq_print(item, "unset %s;", envent->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_show_environment_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 environ *env;
|
struct environ *env;
|
||||||
struct environ_entry *envent;
|
struct environ_entry *envent;
|
||||||
const char *tflag, *name = args_string(args, 0);
|
|
||||||
|
|
||||||
if ((tflag = args_get(args, 't')) != NULL) {
|
if (args_has(self->args, 'g'))
|
||||||
if (target->s == NULL) {
|
env = &global_environ;
|
||||||
cmdq_error(item, "no such session: %s", tflag);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'g'))
|
|
||||||
env = global_environ;
|
|
||||||
else {
|
else {
|
||||||
if (target->s == NULL) {
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||||
tflag = args_get(args, 't');
|
return (-1);
|
||||||
if (tflag != NULL)
|
env = &s->environ;
|
||||||
cmdq_error(item, "no such session: %s", tflag);
|
|
||||||
else
|
|
||||||
cmdq_error(item, "no current session");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
env = target->s->environ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name != NULL) {
|
RB_FOREACH(envent, environ, env) {
|
||||||
envent = environ_find(env, name);
|
if (envent->value != NULL)
|
||||||
if (envent == NULL) {
|
ctx->print(ctx, "%s=%s", envent->name, envent->value);
|
||||||
cmdq_error(item, "unknown variable: %s", name);
|
else
|
||||||
return (CMD_RETURN_ERROR);
|
ctx->print(ctx, "-%s", envent->name);
|
||||||
}
|
|
||||||
cmd_show_environment_print(self, item, envent);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
envent = environ_first(env);
|
return (0);
|
||||||
while (envent != NULL) {
|
|
||||||
cmd_show_environment_print(self, item, envent);
|
|
||||||
envent = environ_next(envent);
|
|
||||||
}
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -18,90 +18,47 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Show message log.
|
* Show client message log.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SHOW_MESSAGES_TEMPLATE \
|
int cmd_show_messages_exec(struct cmd *, struct cmd_ctx *);
|
||||||
"#{t/p:message_time}: #{message_text}"
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_show_messages_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_messages_entry = {
|
const struct cmd_entry cmd_show_messages_entry = {
|
||||||
.name = "show-messages",
|
"show-messages", "showmsgs",
|
||||||
.alias = "showmsgs",
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
.args = { "JTt:", 0, 0, NULL },
|
0,
|
||||||
.usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
|
NULL,
|
||||||
|
NULL,
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
cmd_show_messages_exec
|
||||||
.exec = cmd_show_messages_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
int
|
||||||
cmd_show_messages_terminals(struct cmd *self, struct cmdq_item *item, int blank)
|
cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *c;
|
||||||
struct tty_term *term;
|
|
||||||
u_int i, n;
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
LIST_FOREACH(term, &tty_terms, entry) {
|
|
||||||
if (args_has(args, 't') && term != tc->tty.term)
|
|
||||||
continue;
|
|
||||||
if (blank) {
|
|
||||||
cmdq_print(item, "%s", "");
|
|
||||||
blank = 0;
|
|
||||||
}
|
|
||||||
cmdq_print(item, "Terminal %u: %s for %s, flags=0x%x:", n,
|
|
||||||
term->name, term->tty->client->name, term->flags);
|
|
||||||
n++;
|
|
||||||
for (i = 0; i < tty_term_ncodes(); i++)
|
|
||||||
cmdq_print(item, "%s", tty_term_describe(term, i));
|
|
||||||
}
|
|
||||||
return (n != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
struct message_entry *msg;
|
struct message_entry *msg;
|
||||||
char *s;
|
char *tim;
|
||||||
int done, blank;
|
u_int i;
|
||||||
struct format_tree *ft;
|
|
||||||
|
|
||||||
done = blank = 0;
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
if (args_has(args, 'T')) {
|
return (-1);
|
||||||
blank = cmd_show_messages_terminals(self, item, blank);
|
|
||||||
done = 1;
|
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
|
||||||
|
msg = &ARRAY_ITEM(&c->message_log, i);
|
||||||
|
|
||||||
|
tim = ctime(&msg->msg_time);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%s %s", tim, msg->msg);
|
||||||
}
|
}
|
||||||
if (args_has(args, 'J')) {
|
|
||||||
job_print_summary(item, blank);
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
if (done)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
ft = format_create_from_target(item);
|
return (0);
|
||||||
TAILQ_FOREACH_REVERSE(msg, &message_log, message_list, entry) {
|
|
||||||
format_add(ft, "message_text", "%s", msg->msg);
|
|
||||||
format_add(ft, "message_number", "%u", msg->msg_num);
|
|
||||||
format_add_tv(ft, "message_time", &msg->msg_time);
|
|
||||||
|
|
||||||
s = format_expand(ft, SHOW_MESSAGES_TEMPLATE);
|
|
||||||
cmdq_print(item, "%s", s);
|
|
||||||
free(s);
|
|
||||||
}
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -27,234 +27,71 @@
|
|||||||
* Show options.
|
* Show options.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *);
|
int cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
static void cmd_show_options_print(struct cmd *, struct cmdq_item *,
|
|
||||||
struct options_entry *, int, int);
|
|
||||||
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *,
|
|
||||||
int, struct options *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_options_entry = {
|
const struct cmd_entry cmd_show_options_entry = {
|
||||||
.name = "show-options",
|
"show-options", "show",
|
||||||
.alias = "show",
|
"gst:w", 0, 0,
|
||||||
|
"[-gsw] [-t target-session|target-window]",
|
||||||
.args = { "AgHpqst:vw", 0, 1, NULL },
|
0,
|
||||||
.usage = "[-AgHpqsvw] " CMD_TARGET_PANE_USAGE " [option]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
cmd_show_options_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_show_options_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_window_options_entry = {
|
const struct cmd_entry cmd_show_window_options_entry = {
|
||||||
.name = "show-window-options",
|
"show-window-options", "showw",
|
||||||
.alias = "showw",
|
"gt:", 0, 0,
|
||||||
|
"[-g] " CMD_TARGET_WINDOW_USAGE,
|
||||||
.args = { "gvt:", 0, 1, NULL },
|
0,
|
||||||
.usage = "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
cmd_show_options_exec
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_show_options_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_hooks_entry = {
|
int
|
||||||
.name = "show-hooks",
|
cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
.alias = NULL,
|
|
||||||
|
|
||||||
.args = { "gpt:w", 0, 1, NULL },
|
|
||||||
.usage = "[-gpw] " CMD_TARGET_PANE_USAGE,
|
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_show_options_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
const struct options_table_entry *table, *oe;
|
||||||
struct options *oo;
|
struct session *s;
|
||||||
char *argument, *name = NULL, *cause;
|
struct winlink *wl;
|
||||||
int window, idx, ambiguous, parent, scope;
|
struct options *oo;
|
||||||
struct options_entry *o;
|
|
||||||
|
|
||||||
window = (cmd_get_entry(self) == &cmd_show_window_options_entry);
|
|
||||||
|
|
||||||
if (args_count(args) == 0) {
|
|
||||||
scope = options_scope_from_flags(args, window, target, &oo,
|
|
||||||
&cause);
|
|
||||||
if (scope == OPTIONS_TABLE_NONE) {
|
|
||||||
if (args_has(args, 'q'))
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
return (cmd_show_options_all(self, item, scope, oo));
|
|
||||||
}
|
|
||||||
argument = format_single_from_target(item, args_string(args, 0));
|
|
||||||
|
|
||||||
name = options_match(argument, &idx, &ambiguous);
|
|
||||||
if (name == NULL) {
|
|
||||||
if (args_has(args, 'q'))
|
|
||||||
goto out;
|
|
||||||
if (ambiguous)
|
|
||||||
cmdq_error(item, "ambiguous option: %s", argument);
|
|
||||||
else
|
|
||||||
cmdq_error(item, "invalid option: %s", argument);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
scope = options_scope_from_name(args, window, name, target, &oo,
|
|
||||||
&cause);
|
|
||||||
if (scope == OPTIONS_TABLE_NONE) {
|
|
||||||
if (args_has(args, 'q'))
|
|
||||||
goto out;
|
|
||||||
cmdq_error(item, "%s", cause);
|
|
||||||
free(cause);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
o = options_get_only(oo, name);
|
|
||||||
if (args_has(args, 'A') && o == NULL) {
|
|
||||||
o = options_get(oo, name);
|
|
||||||
parent = 1;
|
|
||||||
} else
|
|
||||||
parent = 0;
|
|
||||||
if (o != NULL)
|
|
||||||
cmd_show_options_print(self, item, o, idx, parent);
|
|
||||||
else if (*name == '@') {
|
|
||||||
if (args_has(args, 'q'))
|
|
||||||
goto out;
|
|
||||||
cmdq_error(item, "invalid option: %s", argument);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
free(name);
|
|
||||||
free(argument);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
|
||||||
fail:
|
|
||||||
free(name);
|
|
||||||
free(argument);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
|
|
||||||
struct options_entry *o, int idx, int parent)
|
|
||||||
{
|
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
struct options_array_item *a;
|
|
||||||
const char *name = options_name(o);
|
|
||||||
char *value, *tmp = NULL, *escaped;
|
|
||||||
|
|
||||||
if (idx != -1) {
|
|
||||||
xasprintf(&tmp, "%s[%d]", name, idx);
|
|
||||||
name = tmp;
|
|
||||||
} else {
|
|
||||||
if (options_is_array(o)) {
|
|
||||||
a = options_array_first(o);
|
|
||||||
if (a == NULL) {
|
|
||||||
if (!args_has(args, 'v'))
|
|
||||||
cmdq_print(item, "%s", name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (a != NULL) {
|
|
||||||
idx = options_array_item_index(a);
|
|
||||||
cmd_show_options_print(self, item, o, idx,
|
|
||||||
parent);
|
|
||||||
a = options_array_next(a);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
value = options_to_string(o, idx, 0);
|
|
||||||
if (args_has(args, 'v'))
|
|
||||||
cmdq_print(item, "%s", value);
|
|
||||||
else if (options_is_string(o)) {
|
|
||||||
escaped = args_escape(value);
|
|
||||||
if (parent)
|
|
||||||
cmdq_print(item, "%s* %s", name, escaped);
|
|
||||||
else
|
|
||||||
cmdq_print(item, "%s %s", name, escaped);
|
|
||||||
free(escaped);
|
|
||||||
} else {
|
|
||||||
if (parent)
|
|
||||||
cmdq_print(item, "%s* %s", name, value);
|
|
||||||
else
|
|
||||||
cmdq_print(item, "%s %s", name, value);
|
|
||||||
}
|
|
||||||
free(value);
|
|
||||||
|
|
||||||
free(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_show_options_all(struct cmd *self, struct cmdq_item *item, int scope,
|
|
||||||
struct options *oo)
|
|
||||||
{
|
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
const struct options_table_entry *oe;
|
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
struct options_array_item *a;
|
const char *optval;
|
||||||
const char *name;
|
|
||||||
u_int idx;
|
|
||||||
int parent;
|
|
||||||
|
|
||||||
if (cmd_get_entry(self) != &cmd_show_hooks_entry) {
|
if (args_has(self->args, 's')) {
|
||||||
o = options_first(oo);
|
oo = &global_options;
|
||||||
while (o != NULL) {
|
table = server_options_table;
|
||||||
if (options_table_entry(o) == NULL)
|
} else if (args_has(self->args, 'w') ||
|
||||||
cmd_show_options_print(self, item, o, -1, 0);
|
self->entry == &cmd_show_window_options_entry) {
|
||||||
o = options_next(o);
|
table = window_options_table;
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
oo = &global_w_options;
|
||||||
|
else {
|
||||||
|
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
oo = &wl->window->options;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
table = session_options_table;
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
oo = &global_s_options;
|
||||||
|
else {
|
||||||
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
oo = &s->options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (oe = options_table; oe->name != NULL; oe++) {
|
|
||||||
if (~oe->scope & scope)
|
for (oe = table; oe->name != NULL; oe++) {
|
||||||
|
if ((o = options_find1(oo, oe->name)) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
optval = options_table_print_entry(oe, o);
|
||||||
if ((cmd_get_entry(self) != &cmd_show_hooks_entry &&
|
ctx->print(ctx, "%s %s", oe->name, optval);
|
||||||
!args_has(args, 'H') &&
|
|
||||||
(oe->flags & OPTIONS_TABLE_IS_HOOK)) ||
|
|
||||||
(cmd_get_entry(self) == &cmd_show_hooks_entry &&
|
|
||||||
(~oe->flags & OPTIONS_TABLE_IS_HOOK)))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
o = options_get_only(oo, oe->name);
|
|
||||||
if (o == NULL) {
|
|
||||||
if (!args_has(args, 'A'))
|
|
||||||
continue;
|
|
||||||
o = options_get(oo, oe->name);
|
|
||||||
if (o == NULL)
|
|
||||||
continue;
|
|
||||||
parent = 1;
|
|
||||||
} else
|
|
||||||
parent = 0;
|
|
||||||
|
|
||||||
if (!options_is_array(o))
|
|
||||||
cmd_show_options_print(self, item, o, -1, parent);
|
|
||||||
else if ((a = options_array_first(o)) == NULL) {
|
|
||||||
if (!args_has(args, 'v')) {
|
|
||||||
name = options_name(o);
|
|
||||||
if (parent)
|
|
||||||
cmdq_print(item, "%s*", name);
|
|
||||||
else
|
|
||||||
cmdq_print(item, "%s", name);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (a != NULL) {
|
|
||||||
idx = options_array_item_index(a);
|
|
||||||
cmd_show_options_print(self, item, o, idx,
|
|
||||||
parent);
|
|
||||||
a = options_array_next(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
/* $OpenBSD$ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2021 Anindya Mukherjee <anindya49@hotmail.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 "tmux.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Show or clear prompt history.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static enum cmd_retval cmd_show_prompt_history_exec(struct cmd *,
|
|
||||||
struct cmdq_item *);
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_show_prompt_history_entry = {
|
|
||||||
.name = "show-prompt-history",
|
|
||||||
.alias = "showphist",
|
|
||||||
|
|
||||||
.args = { "T:", 0, 0, NULL },
|
|
||||||
.usage = "[-T type]",
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_show_prompt_history_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct cmd_entry cmd_clear_prompt_history_entry = {
|
|
||||||
.name = "clear-prompt-history",
|
|
||||||
.alias = "clearphist",
|
|
||||||
|
|
||||||
.args = { "T:", 0, 0, NULL },
|
|
||||||
.usage = "[-T type]",
|
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
|
||||||
.exec = cmd_show_prompt_history_exec
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_show_prompt_history_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
const char *typestr = args_get(args, 'T');
|
|
||||||
enum prompt_type type;
|
|
||||||
u_int tidx, hidx;
|
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_clear_prompt_history_entry) {
|
|
||||||
if (typestr == NULL) {
|
|
||||||
for (tidx = 0; tidx < PROMPT_NTYPES; tidx++) {
|
|
||||||
free(status_prompt_hlist[tidx]);
|
|
||||||
status_prompt_hlist[tidx] = NULL;
|
|
||||||
status_prompt_hsize[tidx] = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
type = status_prompt_type(typestr);
|
|
||||||
if (type == PROMPT_TYPE_INVALID) {
|
|
||||||
cmdq_error(item, "invalid type: %s", typestr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
free(status_prompt_hlist[type]);
|
|
||||||
status_prompt_hlist[type] = NULL;
|
|
||||||
status_prompt_hsize[type] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typestr == NULL) {
|
|
||||||
for (tidx = 0; tidx < PROMPT_NTYPES; tidx++) {
|
|
||||||
cmdq_print(item, "History for %s:\n",
|
|
||||||
status_prompt_type_string(tidx));
|
|
||||||
for (hidx = 0; hidx < status_prompt_hsize[tidx];
|
|
||||||
hidx++) {
|
|
||||||
cmdq_print(item, "%d: %s", hidx + 1,
|
|
||||||
status_prompt_hlist[tidx][hidx]);
|
|
||||||
}
|
|
||||||
cmdq_print(item, "%s", "");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
type = status_prompt_type(typestr);
|
|
||||||
if (type == PROMPT_TYPE_INVALID) {
|
|
||||||
cmdq_error(item, "invalid type: %s", typestr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
cmdq_print(item, "History for %s:\n",
|
|
||||||
status_prompt_type_string(type));
|
|
||||||
for (hidx = 0; hidx < status_prompt_hsize[type]; hidx++) {
|
|
||||||
cmdq_print(item, "%d: %s", hidx + 1,
|
|
||||||
status_prompt_hlist[type][hidx]);
|
|
||||||
}
|
|
||||||
cmdq_print(item, "%s", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -18,191 +18,57 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <glob.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sources a configuration file.
|
* Sources a configuration file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmdq_item *);
|
int cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_source_file_entry = {
|
const struct cmd_entry cmd_source_file_entry = {
|
||||||
.name = "source-file",
|
"source-file", "source",
|
||||||
.alias = "source",
|
"", 1, 1,
|
||||||
|
"path",
|
||||||
.args = { "t:Fnqv", 1, -1, NULL },
|
0,
|
||||||
.usage = "[-Fnqv] " CMD_TARGET_PANE_USAGE " path ...",
|
NULL,
|
||||||
|
NULL,
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
cmd_source_file_exec
|
||||||
|
|
||||||
.flags = 0,
|
|
||||||
.exec = cmd_source_file_exec
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_source_file_data {
|
int
|
||||||
struct cmdq_item *item;
|
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
int flags;
|
|
||||||
|
|
||||||
struct cmdq_item *after;
|
|
||||||
enum cmd_retval retval;
|
|
||||||
|
|
||||||
u_int current;
|
|
||||||
char **files;
|
|
||||||
u_int nfiles;
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_source_file_complete_cb(struct cmdq_item *item, __unused void *data)
|
|
||||||
{
|
{
|
||||||
cfg_print_causes(item);
|
struct args *args = self->args;
|
||||||
return (CMD_RETURN_NORMAL);
|
struct causelist causes;
|
||||||
}
|
char *cause;
|
||||||
|
struct window_pane *wp;
|
||||||
static void
|
int retval;
|
||||||
cmd_source_file_complete(struct client *c, struct cmd_source_file_data *cdata)
|
|
||||||
{
|
|
||||||
struct cmdq_item *new_item;
|
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
if (cfg_finished) {
|
ARRAY_INIT(&causes);
|
||||||
if (cdata->retval == CMD_RETURN_ERROR &&
|
|
||||||
c != NULL &&
|
|
||||||
c->session == NULL)
|
|
||||||
c->retval = 1;
|
|
||||||
new_item = cmdq_get_callback(cmd_source_file_complete_cb, NULL);
|
|
||||||
cmdq_insert_after(cdata->after, new_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < cdata->nfiles; i++)
|
retval = load_cfg(args->argv[0], ctx, &causes);
|
||||||
free(cdata->files[i]);
|
if (ARRAY_EMPTY(&causes))
|
||||||
free(cdata->files);
|
return (retval);
|
||||||
free(cdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
if (retval == 1 && !RB_EMPTY(&sessions) && ctx->cmdclient != NULL) {
|
||||||
cmd_source_file_done(struct client *c, const char *path, int error,
|
wp = RB_MIN(sessions, &sessions)->curw->window->active;
|
||||||
int closed, struct evbuffer *buffer, void *data)
|
window_pane_set_mode(wp, &window_copy_mode);
|
||||||
{
|
window_copy_init_for_output(wp);
|
||||||
struct cmd_source_file_data *cdata = data;
|
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
|
||||||
struct cmdq_item *item = cdata->item;
|
cause = ARRAY_ITEM(&causes, i);
|
||||||
void *bdata = EVBUFFER_DATA(buffer);
|
window_copy_add(wp, "%s", cause);
|
||||||
size_t bsize = EVBUFFER_LENGTH(buffer);
|
xfree(cause);
|
||||||
u_int n;
|
|
||||||
struct cmdq_item *new_item;
|
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
|
||||||
|
|
||||||
if (!closed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
cmdq_error(item, "%s: %s", path, strerror(error));
|
|
||||||
else if (bsize != 0) {
|
|
||||||
if (load_cfg_from_buffer(bdata, bsize, path, c, cdata->after,
|
|
||||||
target, cdata->flags, &new_item) < 0)
|
|
||||||
cdata->retval = CMD_RETURN_ERROR;
|
|
||||||
else if (new_item != NULL)
|
|
||||||
cdata->after = new_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
n = ++cdata->current;
|
|
||||||
if (n < cdata->nfiles)
|
|
||||||
file_read(c, cdata->files[n], cmd_source_file_done, cdata);
|
|
||||||
else {
|
|
||||||
cmd_source_file_complete(c, cdata);
|
|
||||||
cmdq_continue(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_source_file_add(struct cmd_source_file_data *cdata, const char *path)
|
|
||||||
{
|
|
||||||
log_debug("%s: %s", __func__, path);
|
|
||||||
cdata->files = xreallocarray(cdata->files, cdata->nfiles + 1,
|
|
||||||
sizeof *cdata->files);
|
|
||||||
cdata->files[cdata->nfiles++] = xstrdup(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
|
||||||
{
|
|
||||||
struct args *args = cmd_get_args(self);
|
|
||||||
struct cmd_source_file_data *cdata;
|
|
||||||
struct client *c = cmdq_get_client(item);
|
|
||||||
enum cmd_retval retval = CMD_RETURN_NORMAL;
|
|
||||||
char *pattern, *cwd, *expanded = NULL;
|
|
||||||
const char *path, *error;
|
|
||||||
glob_t g;
|
|
||||||
int result;
|
|
||||||
u_int i, j;
|
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
|
||||||
cdata->item = item;
|
|
||||||
|
|
||||||
if (args_has(args, 'q'))
|
|
||||||
cdata->flags |= CMD_PARSE_QUIET;
|
|
||||||
if (args_has(args, 'n'))
|
|
||||||
cdata->flags |= CMD_PARSE_PARSEONLY;
|
|
||||||
if (args_has(args, 'v'))
|
|
||||||
cdata->flags |= CMD_PARSE_VERBOSE;
|
|
||||||
|
|
||||||
utf8_stravis(&cwd, server_client_get_cwd(c, NULL), VIS_GLOB);
|
|
||||||
|
|
||||||
for (i = 0; i < args_count(args); i++) {
|
|
||||||
path = args_string(args, i);
|
|
||||||
if (args_has(args, 'F')) {
|
|
||||||
free(expanded);
|
|
||||||
expanded = format_single_from_target(item, path);
|
|
||||||
path = expanded;
|
|
||||||
}
|
}
|
||||||
if (strcmp(path, "-") == 0) {
|
} else {
|
||||||
cmd_source_file_add(cdata, "-");
|
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
|
||||||
continue;
|
cause = ARRAY_ITEM(&causes, i);
|
||||||
|
ctx->print(ctx, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*path == '/')
|
|
||||||
pattern = xstrdup(path);
|
|
||||||
else
|
|
||||||
xasprintf(&pattern, "%s/%s", cwd, path);
|
|
||||||
log_debug("%s: %s", __func__, pattern);
|
|
||||||
|
|
||||||
if ((result = glob(pattern, 0, NULL, &g)) != 0) {
|
|
||||||
if (result != GLOB_NOMATCH ||
|
|
||||||
(~cdata->flags & CMD_PARSE_QUIET)) {
|
|
||||||
if (result == GLOB_NOMATCH)
|
|
||||||
error = strerror(ENOENT);
|
|
||||||
else if (result == GLOB_NOSPACE)
|
|
||||||
error = strerror(ENOMEM);
|
|
||||||
else
|
|
||||||
error = strerror(EINVAL);
|
|
||||||
cmdq_error(item, "%s: %s", path, error);
|
|
||||||
retval = CMD_RETURN_ERROR;
|
|
||||||
}
|
|
||||||
globfree(&g);
|
|
||||||
free(pattern);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
free(pattern);
|
|
||||||
|
|
||||||
for (j = 0; j < g.gl_pathc; j++)
|
|
||||||
cmd_source_file_add(cdata, g.gl_pathv[j]);
|
|
||||||
globfree(&g);
|
|
||||||
}
|
}
|
||||||
free(expanded);
|
ARRAY_FREE(&causes);
|
||||||
|
|
||||||
cdata->after = item;
|
|
||||||
cdata->retval = retval;
|
|
||||||
|
|
||||||
if (cdata->nfiles != 0) {
|
|
||||||
file_read(c, cdata->files[0], cmd_source_file_done, cdata);
|
|
||||||
retval = CMD_RETURN_WAIT;
|
|
||||||
} else
|
|
||||||
cmd_source_file_complete(c, cdata);
|
|
||||||
|
|
||||||
free(cwd);
|
|
||||||
return (retval);
|
return (retval);
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user