tmux bind-key to kill all or maybe a grouping of windows/panels - bash

I've created a script that opens up tmux and splits into 4 windows/panels, but i was wondering if theres a quick way to exit them all, preferably via a key binding.
Thanks.
[Edit]
What i'm looking for is a way to exit a selection of windows via a key binding.
Something maybe i can add to my .tmux.conf file like:
bind-key C-c exit-all
Or maybe a command i can pass in after setting up the split windows etc like: tmux bind-key C-c exit-all
I'm putting exit-all as the command there as thats what im looking for, but i don't know the real name for this function or way of doing this

From man tmux:
unlink-window [-k] [-t target-window]
(alias: unlinkw)
Unlink target-window. Unless -k is given, a window may be unlinked only if it is linked to multiple ses-
sions - windows may not be linked to no sessions; if -k is specified and the window is linked to only one
session, it is unlinked and destroyed.
I think unlink-window -k is what you're after.

Related

Rebinding tmux prefix to alt key

I'd like to change the tmux prefix from ctrl+b to a single key, specifically alt. Tried set-option -g prefix M, but it said bad key.
Anyone know how to accomplish this without having to create a macro on my entire system making alt trigger ctrl+b?
I'd settle for a macro that only triggers when inside of a tmux session.
A possible workaround is to use tmux's root table instead of the prefix key table (see bind-key in man page). To do this, you need to pass the -n argument to the bind-key command. This does imply that you will have to re-bind all the commands in your .tmux.conf that you want to support.
An example of how to create a window using alt+c is:
bind -n M-c new-window

run a looping command in 10 terminals

an easy question from some of you.
I need to run a command which take into account 10 different files. For some reasons I need to run this command for each file in parallel possibly in 10 different terminals.
Is there a way to do this in a shell script? Ideally, I would open terminals in a loop i=10 then loopin into the files folder, however I do not know hot to open different terminals in a loop and assign a command to each one.
I hope it is clear, if not let me know
There are better ways to solve your problem, but if for some reason just want to open 10 terminals and in "parallel" run a command within them, you could give a try to tmux with the option synchronize-panes on, you could use this script for example:
#!/bin/sh
for i in {1..10}
do
tmux split-window
tmux select-layout tiled
done
clear
tmux select-layout tiled
tmux setw synchronize-panes on
After having tmux running just run it, it should look than something like the attached picture:

history-limit is not working after C-l in tmux

My environment is Fedora20 (32-bit) + Yakuake + fish + tmux.
Months ago, I started to use tmux, it is a great terminal multiplexer, but the scrollback (Use prefix then PageUp to scroll back) is not working as expected, the history limit is always under 2000 (around 1980 on the right above corner) even if I already set the scrollback limit to "unlimited scrollback" in Yakuake Setting.
Finally I could take it anymore and started to goole it for solution, found out that I could put set -g history-limit 30000 int my tmux.conf file, then check again, it worked, but I realized that every time I typed C-l to clear the screen(and I use it a lot), the scrollback history will be only under/around 30.
Then I found out at How do i clear tmux screen while tailing logs? that I could put bind l send-keys -R into .tmux.conf and use prefix-l to clear the terminal history buffer temporarily and still be able to scroll back, it worked just as I wanted. But What I really want is I use only C-l to do the trick without the prefix key, replacing the shell built-in C-l to do it...
Update:
Short ask, after setting a bind in .tmux.conf, in tmux, you have to type the prefix key before typing that key, then how to bind a key without the need to add the prefix key by default??
In order to bind a key without the need to add the prefix, use the -n flag for the tmux bind command.
Here's the example that should be put in tmux.conf:
bind -n C-l display-message 'foo'
The example binding is triggered when Ctrl-l is pressed (no prefix) and it displays message 'foo' in the tmux prompt.
All that said, be careful & conservative with setting these "direct" key bindings because the key will become unusable for any other terminal program.

Open a small window while in Vim for executing commands

I need to write lot of code and compile very often. I hate switching back and forth various windows just to compile the code. Is it possible to open a small window at bottom and run invoke shell and close that window when needed?
With GVim or MacVim, you can run external commands in the command-line: Gvim/MacVim comes with a (very) limited shell that will happily show you whatever the compiler outputs. The general usage pattern is:
:!command
:!command %
With CLI Vim, the same method will pause Vim and return to the shell to execute your command.
In both cases, you'll get a message asking you to press ENTER to come back to your normal editing.
Using :make | cw would be a slightly more sophisticated alternative, with the added bonus of showing the errors in the quickfix window.
An even more sophisticated approach would be to use Tim Pope's Dispatch plugin in combination with tmux or screen.
Sounds like a problem for Screen
http://www.gnu.org/software/screen/
Quick reference of commands
http://aperiodic.net/screen/quick_reference
I use tmux to achieve something like that. I have the following in my ~/.tmux.conf file:
bind s splitw -v -p 25 -c '#{pane_current_path}' '/bin/bash'
bind q kill-pane
On pressing Ctrl-b + s (prefix + s), a new pane containing a bash shell opens up at the bottom. I can run shell commands from there: find, grep, make, etc. When I'm done, I press Ctrl-b + q to close the shell.
To enable tmux on every bash session, add the following to your ~/.bashrc:
[[ -z "$TMUX" ]] && exec tmux
Maybe map a key to shell out to the compiler and run the program if compilation is successful:
:map F8 :!cc % && ./a.out
Or maybe just
:sh
make run
Ctrl-D
Another option is to suspend vi, using Ctrl-Z and do your stuff in the shell, then type fg to bring vim back to the foreground. Note that this is actually a feature of your shell, rather than vim but it produces the effect you seek.
Note this idea originates from the book "Efficient Linux at the Command Line" by Daniel Barrett. I forget the page number.

Using Alt-left/right to switch between windows in tmux

I am trying to configure tmux to switch between windows using alt-left, alt-right sequences. This is what I have in my .tmux.conf
bind-key -n M-Left previous-window
bind-key -n M-Right next-window
Unfortunately, it doesn't work. On my machine, alt-left and alt-right are bound to ^[[1;3D and ^[[1;3C respectively. I think I have to use terminfo override to tell tmux to use these sequences, but I have no idea how. So, any help will be appreciated.
Thanks!
If the xterm-keys option was off, tmux would ignore the keys (because it would recognize them and discard them when the option was not set). Users of tmux have been confused by this distinction for a while, and at the end of 2016, the developer changed the default for the option:
Change the xterm-keys option to default to on, so that tmux will generate xterm(1) escape sequences for function keys with modifiers.
With the option off most of these keys are ignored by default, except
for ctrl + arrows which use a variant that nothing else seems to use and
I don't remember why we chose. The xterm escape sequences are now the
most common.
This still relies upon the terminal description, as I pointed out in tmux on remote machine not getting correct prefix + arrow keys

Resources