iTerm2 to attach to tmux session using tabs instead of windows? - tmux

I got tmuxinator to work with iTerm2 the following: https://stackoverflow.com/a/19747819/1009332
However, each tab initially opens in a different window. Is there any way to attach to an existing tmux session using tabs rather than new windows?
There's some more info about this cool feature here: https://code.google.com/p/iterm2/wiki/TmuxIntegration
My motivation for this was:
1. copy/paste/find locks the process in tmux, whereas with iterm2, you can find in a tail of logs and not lock the process.
2. key bindings are simpler in iTerm2.
3. I like tmuxinator to start many shell windows (tabs) when doing rails web development, so that my stdout of different processes goes to different windows, rather than mixing together when using foreman.

It is an option in iTerm2: Preferences > general Open tmux windows as native tabs in a new window, but you have to disconnect then reconnect.
Solution found here

Related

What is merit of terminal multiplexer compared to standard terminal app and job control?

I don't know what is a merit of a terminal multiplexer like screen or tmux compared to combination of a standard terminal application and a job control feature of a shell.
Typically good features of a terminal multiplexer are cited as follows:
persistance
multiple windows
session sharing
First two features are, however, achieved with a terminal application like iTerm2 and a job control feature of a shell like bash.
Session sharing is a novel feature but it seems to be required in a quite rare situation.
What is a merit of terminal multiplexer? Why do you use it?
I'm interested especially in its merit in daily task.
I can tell you from my perspective as a devops/developer.
Almost every day I have to deploy a bunch of apps (a particular version) on multiple servers. Handling that without something like Terminator or Tmux would be a real pain.
On a single window I can put something like 4 panes (four windows in one) and monitor stuff on 4 different servers...which by it self is a huge deal...without tabs or other terminal instances and what not....
On the first pane I can shutdown nginx, on the second server I can shut down all the processes with supervisord (process manager), and on the third pane I can do the deploy process...if I quickly need to jump to some other server I just use the fourth pane...
Some colleagues that only use a bunch of terminal instances can get really confused when they have to do a bunch of things quickly, constantly ssh-ing in and out ...and if they are not careful they can go to the wrong server because they switched to the wrong terminal instance and entered a command that wasn't meant for that particular server :)...
A terminal multiplexer like Tmux really does help me to be quick and accurate.
There is an package manager for Tmux, which lets you install plugins and really supercharge you terminal even more!
On a different note, a lot of people are using Tmux in combination with Vim...which lets you create some awesome things together...
All in all, those were my two cents on the benefit of using a terminal multiplexer...

Duplicate a window in tmux

I have a nice window in my tmux session that has a number of panes nicely arranged. Is it possible to duplicate a session, preserving the current panes layout?
Check out some of the tmux plugins. tmux-resurrect allows you to save then later restore a set of windows and even the commands running there (out of a limited set you can configure). You may want to start by first installing the Tmux Plugin Manager that it mentions in the guide if you want to easily try out other plugins.

How to stop ZSH from merging history for all closing tabs?

I use combination of zsh with oh-my-zsh and iTerm2 for development on Mac.
I'm frustrated with the following issue:
N tabs opened
close the terminal
reopen it (with Use system Window Restoration Setting)
the history from all previously opened tabs got merged into one for every reopened tab
The question: How to preserve separated history for every reopened tab?
Per https://github.com/robbyrussell/oh-my-zsh/issues/2537,
Add unsetopt share_history to your .zshrc file.
Unless iTerm2 actually just hides a tab on closing and keeps the shell session running in the background (which, according to the iTerm2 website, seems to be an option), it is not possible to completely restore a shell session. In your case It seems like a new shell session is created when restoring a tab, which leads to the history being read form HISTFILE.
If you want to prevent any merging of history, you have to ensure that of the options APPEND_HISTORY, INC_APPEND_HISTORY and SHARE_HISTORY only the first one is set:
setopt noincappendhistory
setopt nosharehistory
setopt appendhistory
This will lead to new entries in the history (i.e. commands run during the session) only being appended to the history file when the shell exits. So when you close a session, the next shell (re-)opened will have lines of the just previously closed shell on the bottom of the history.
Another option could be to have separate history files for each shell session and device your own method of loading a history from these files using the fc builtin. This would at least in part depend on whether it is possible to differentiate between iTerm2 tabs from within a shell session (for example via some environment variable) and whether this holds true when re-opening a tab.

Is it possible to display a browser window inside a Tmux Pane?

I'm using Tmux / Vim on Mac OSX and I like to split the windows for testing and development. I would like to know if its possible to dock safari or another browser inside a tmux window so I would have code on the left side and the browser on the right.
Cheers!
If you can make the browser show in your terminal, then the answer to your question is YES. otherwise: NO.
From tmux homepage:
tmux is a terminal multiplexer
What is a terminal multiplexer? It lets you switch easily between several
programs in one terminal, detach them (they keep running in the background) and
reattach them to a different terminal.
Notable web browsers you could actually use in the terminal are elinks, w3m or for a complete graphical interface, NetSurf.

Consoles and Tabs

When I start the tomcat server from console using the startup.bat script, a new command window opens which is filled with java logging statements.
I use Console2 which leverages tabs for each open console window. Is it possible to let the java system create a new tab within console2 instead of just opening a new command window?
This has nothing to do with java, its merely down to the way the catalina.bat is called from startup.bat
catalina.bat can be called with either a "start" argument or a "run" argument.
run Start Catalina in the current window
start Start Catalina in a separate window
So open startup.bat, scroll to the bottom you should see
"%EXECUTABLE%" start %CMD_LINE_ARGS%
change that to
"%EXECUTABLE%" run %CMD_LINE_ARGS%
exit
I add an exit after to close the calling window.
Unless Console2 hooks any APIs that create console windows – no. And that's also highly unlikely that they do or even can. Console2 does nothing more than hook up input and output of console windows. What the programs in those do is beyond what it's interested in.

Resources