I want to automatically run tmux after starting a rxvt terminal.
I used to do this by invoking tmux in my ~/.zshrc but this had the problem of having to hit ^D twice when I wanted to close my terminal.
I tried using rxvt -e tmux and rxvt -e zsh -c tmux to start tmux after starting rxvt which works.
The problem with this method is that I then don't get 256 color support in my terminal.
Any suggestions?
I think you'll need
tmux -2
See man tmux:
-2 Force tmux to assume the terminal supports 256 colours.
Related
In my normal shell I create tmux sessions for running in the background with
tmux new-session -d -s my-session my-script.sh (1)
Now I want to add logging of all output via pipe-pane to the session. I know how to do this in a not-detached session (when being inside tmux):
Ctrl-B : pipe-pane -o 'cat >>~/tmp/output.log' (2)
But how can I tell tmux on creation of a detached session -- via (1) -- to add straight away the pipe-pane tmux command?
I basically look for a way in my normal shell to create detached tmux sessions with logging. - I am using tmux 1.6.
You can always combine the two commands into one tmux command (I dont have tmux 1.6 to test this on but it works for 2.2):
tmux new-session -d -s my-session my-script.sh \; pipe-pane -o 'cat >>~/tmp/output.log'
If you were using tmux 2.9 or later you can set a hook to run a command when a new session starts. Put in your ~/.tmux.conf
set-hook -g session-created "pipe-pane -o 'cat >>~/tmp/output.log'"
To cope with many sessions, you might include the session name in the filename, e.g. output.#{session_name}.log.
I need to execute several bash scripts in background with a screen devoted to each script within byobu session.
So how to invoke a byobu window for each script like:
$byobu-multiple script1.bash script2.bash ...
Modern byobu is based on tmux, so you can simply use the tmux new-window command.
You can do one for each command:
tmux new-window script1.bash
tmux new-window script2.bash
If you really need a one-liner you could use xargs:
echo script1.bash script2.bash | xargs --max-args=1 tmux new-window
If you have multiple byobu sessions running in parallel, you can run tmux list-sessions to see them, and could append the tmux new-window command with -t to point it at a specific session.
I have a process I want to monitor by tail -f on several output files in different directories. I can use a bash script start tmux as a detached session, create multiple panes, change to the top directory and reattach. This all works. My problem comes when I want the script to send more commands later. Is there some reason why once I attach, my script can't send commands or detach/reattach later? The reason to do more commands is that some files take 45 seconds to be created before I can tail them.
My example looks like
#!/bin/bash
# this depends on some settings from my ~/.tmux.conf
TopLevel='/tsload'
SimDir=`ls -d $TopLevel/SIM_ISS*`
# create and detach session
tmux new-session -s simwatch -n Sim_Watch -d
# make left & right panes, only 1 window
tmux split-window -h -t simwatch
# change to toplevel dir
tmux send-keys -t simwatch:1.1 "cd $SimDir" C-m
tmux send-keys -t simwatch:1.2 "cd $SimDir" C-m
tmux attach -t simwatch
At this point my script fails when I try to have it do more. I've also tried 'tmux detach -t simwatch' issue commands and reattach but they don't take effect.
Not very familiar with tmux, but from my experiment with your script, it looks like that tmux 'attach -t simwatch' is a blocking operation, i.e. it starts and will end once you detach/exit from the session, which is when the script will continue.
Regarding the issue with the files that appear later, if you know their paths, you can try to follow them with "tail -F", which will wait for the files to appear.
tail --follow=name --retry missing_file
I want to do do this in tmux save-buffer - | pbcopy or some similar clone of save-buffer - | xclip -i -selection clipboard so that I can pipe the contents of the tmux clipboard to the os-x clipboard. The problem is that tmux always gives me a syntax hint when I run the command from the tmux command line, or it says save-buffer - | pbcopy returned 1 when run via keymap and does nothing useful. I've looked at the linux xclip solution on explainshell.com but that didn't help. The tmux man-page and error messages are also kinda useless. Any ideas?
Version info and the like:
tmux: 1.9a
OS-X: 10.9.4
ZSH: 5.0.5
I found an alternate solution to accomplish the same result... https://unix.stackexchange.com/questions/15715/getting-tmux-to-copy-a-buffer-to-the-clipboard
use copy-pipe on linux and os-x and I get what I'm looking for. :)
Sorry for necroposting.
As a nasty solution I suggest this:
copy text by tmux
run cat | pbcopy
paste from tmux
Ctr+D
Here you go. cat without args just gets input until EOF (which is accomplished by Ctd+D)
I solved this problem using reattach-to-user-namespace program and this configuration:
~/.tmux.conf
# Define default shell
set -g default-command "reattach-to-user-namespace -l zsh"
# Copy tmux buffer content to OS clipboard
bind-key y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
Now I can press <prefix>+y to copy text from tmux buffer to OS clipboard.
I also wanted to be able to choose which buffer to copy from:
bind y choose-buffer "run-shell \"tmux show-buffer -b %% | pbcopy\" \; display-message \"Copied to system clipboard\""
I have a script (.sh) and I want it to run in a existing tmux session. I have 1 session with 8 windows in.
Is there a command like tmux a -t session-name, which also specify the window?
And would a script like this work?
#!/bin/bash
tmux a -t session-name #What ever to write to specify window# java -jar -Xmx4G -Xms4G Spigot.jar
You can change the active window of a session before you attach to the session.
tmux -t <session-name> select-window -t <windowID>
tmux a -t <session-name>
You can combine two tmux commands as well.
tmux -t session-name select-window -t <windowID> \; a
If you really want to run java, presumably you want to create a new window with new-window, rather than select an existing one with select-window.
Newer versions of tmux (at least 1.9; did the above ever work, perhaps in 1.6?) no longer appear to have a -t option to specify the session to apply commands to. Instead, each individual command specifies the session.
tmux select-window -t <session-name>:<windowID> \; a -t <session-name>
For tmux version 2.1 this works
tmux a -t <session-name> \; select-window -t <windowID> \;
You can specify the window after the session separated by a colon.
tmux a -t session:window
You can even attach to a specific pane.
tmux a -t session:window.pane
Pane can be a number starting from 0. Window can be a number or name.
man tmux has more info about different syntaxes allowed for target-session, target-window, and target-pane.
target-window (or src-window or dst-window) specifies a window in the form session:window...
This syntax works on any other command like send-keys. If it's not working you may be on an older version of tmux and need to upgrade or try an approach suggested in the other answers.