Multiple tabs with tmux / tmuxinator and iTerm2 - macos

I would like to open all my useful stuff like here in iTerm2:
Not like this:
I'm using tmuxinator I've defined some tabs. I wonder if it's possible to get the former behaviour at all.

I just tried with tmux 1.8. Not totally obvious, but it works.
Here's what you do:
Open iTerm2 (latest, be sure to have at least tmux 1.8 installed).
In iTerm2, run command tmux <your tmuxinator profile>. Then detach ^b d.
In iTerm2, run command tmux -CC attach -t <your session>. You will see your tabs open in different windows.
Open menu Shell->Tmux->Dashboard
Select and hide all the windows.
Select all the hidden windows, and click Open in Tabs.
I'd like to know how to avoid the part about hiding and opening in tabs.

Just wanted to add some comments onto what justingordon mentioned (1).
This all works great. But I found how to streamline step 4-6 so it happens automatically.
Go to iTerm2's Preferences, under General, you will see a section titled tmux. There's an option that says When attaching, open unrecognized windows in. If you change the current selection from Windows to Tabs.
Two extra tips.
If you want you could select the option Automatically hide the tmux client session after connection. This will minimize the iTerm2 window in which you typed
tmux -CC attach
I also enabled the option Focus follows mouse. You can find this option under Preferences then Pointer. It should be the first option on the bottom left.

To use tmuxinator with iterm2 panes, use the following configuration:
attach: false
in combination with
on_project_exit:
- tmux -CC attach -t way
It looks like an issue in the documentations as told here
This is an example that I normally use:
# ~/.tmuxinator/way.yml
name: way
root: ~/learn/ruby/ruby-way/
attach: false
on_project_exit:
- tmux -CC attach -t way
# Runs before everything. Use it to start daemons etc.
on_project_start:
- export EDITOR="emacsclient --server-file=way -c"
- export VISUAL=$EDITOR
- emacs --daemon=way --title=RUBY-WAY
- $EDITOR &
windows:
- console:
- echo "A currar"
- testing:
- echo "A testear"
I hope that this helps.

Add this to your tmuxinator config:
attach: false
post: tmux -CC attach
https://github.com/tmuxinator/tmuxinator/pull/293

Related

How to elegantly create a Windows shortcut that starts a WSL program under X

I'm struggling a little to launch xfce4-terminal from my WSL installation under VcXsrv from a button on the Windows taskbar. I don't want any DOS box/console/terminal other than the xfce4-terminal when I'm done. I have it working, but man is it ugly. Does anybody have a cleaner way of doing this?
Here is what I got working: I created a windows shortcut on the Desktop with this target (all in one line, broken with newlines for readability here):
C:\Windows\System32\wscript.exe
\\wsl$\Ubuntu-20.04\home\peter\bin\windows\startTerminal.vbs
startTerminal.vbs was inspired by from 10 Ways To Run Batch Files Silently And Hide The Console Window • Raymond.CC (one of the few solutions that didn't require installing a separate program for this!) and it contains:
CreateObject("Wscript.Shell").Run "C:\Windows\System32\wsl.exe -u peter --exec /home/peter/bin/windows/startTerminal.sh",0,True
and startTerminal.sh contains:
export DISPLAY=localhost:0.0
xfce4-terminal --command=/bin/zsh
Setting DISPLAY is apparently required, even though I set the DISPLAY environment in ~/.zshrc. wsl.exe apparently doesn't do that unless you run the login shell.
Once all of this is working, I can drag my shortcut to the taskbar and click on it there.
I count 3, three files cooperating to achieve this simple goal? Can I limit that to one or two without installing an external program?
Yes, I think you can do what I do in one shortcut file. I'll share what works for me then you'll have to fiddle for your program.
Try putting all your commands in the Target section of the Shortcut link file.
Step 1. Right click on desktop then New then Shortcut then name it (LaunchXFCE4)
Step 2. Right click LaunchXFCE4 select Properties
Step 3. Enter all your launch sequences in the Target section
Step 4. Right click LaunchXFCE4 select Pin to Taskbar
I'm launching Emacs 27.1 on WSL 2 with Ubuntu 20.10 on Windows 10 using this code which perhaps you can modify.
C:\Windows\System32\wsl.exe --distribution Ubuntu20 bash -c "export DISPLAY=$(ip route | awk '{print $3; exit}'):0 && export LIBGL_ALWAYS_INDIRECT=1 && export XCURSOR_SIZE=16 && setsid emacs"
The first export display is similar to your localhost:0.0 so replace it or try mine. Maybe your xfce4 replaces my emacs. Read this post about double ampersands. So possibly this
C:\Windows\System32\wsl.exe --distribution Ubuntu20 bash -c "export DISPLAY=localhost:0.0 && export LIBGL_ALWAYS_INDIRECT=1 && export XCURSOR_SIZE=16 && setsid xfce4-terminal --command=/bin/zsh"
Note, my VcXsrv starts when windows starts by putting a shortcut to config.xlaunch in my C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.
By the way, Microsoft will provide a GUI for WSL in a few months, according to their blog
GUI app support in WSL is becoming a reality! We are getting closer to
an initial preview and happy to announce a preview release for Windows
Insiders within the next couple of months.
I removed the need for a startTerminal.sh file by:
Editing startTerminal.vbs to contain:
CreateObject("Wscript.Shell").Run "C:\Windows\System32\wsl.exe -u peter bash -l -c xfce4-terminal",0,True
And then I created a ~/.bash_profile to set the $DISPLAY variable, which probably should've been done anyway:
$ cat .bash_profile
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
So now there is the shortcut and a startTerminal.vbs that starts it up. It still isn't very elegant...
One of the few good additions to Windows was WSL-2, it's much more capable now.
It's part of late Win 10 and Win 11.
Here is how to elegently create a terminal window, replace the terminal with any X app you want.
Linux: "apt-get install xfce4-terminal" (or equivalent)
Windows: Create a new Shortcut (right click in any windows folder)
2.1) Shortcut to -> C:\Windows\System32\wslg.exe -u root -- /usr/bin/xfce4-terminal
If you have multiple distributions use it like: "-d Debian"
That's it. You can give it a better icon and name it.
It will launch the application as if it was a windows application.
After experimenting with #Saj 's answer which did not work for me I resulted in the below:
C:\Windows\System32\wsl.exe --distribution Ubuntu-20.04 bash -c "export DISPLAY=$((route.exe print | Select-String 0.0.0.0 | select -first 1) -Split "\s+" | select -Index 4):0.0 && export LIBGL_ALWAYS_INDIRECT=1 && setsid emacs"
Note that my problem was that it could not use bash commands inside the parenthesis (grep, awk)
Environment: WSL2 on Windows 10

How can I see a preview of a tmux session/window from outside of tmux?

While inside of tmux, I can press PREFIX w, which runs tmux choose-tree.
This brings up an interactive session/window/pane selector that also displays a
preview of the highlighted node.
From a normal shell outside of tmux, I can run tmux attach -t '$1:1' to attach
to any session or window by name or index (see man tmux section "Clients And
Sessions").
Is there command similar to tmux attach -t where I can pass in a session/window
name/index and see a preview of it, like to the one used in tmux choose-tree? Ideally this command would just show the lower portion of this
image:
The goal here is to pipe a list of tmux windows from all sessions to
fzf, and pass a separate command in fzf's
--preview flag to show a preview of the session/window currently highlighted
while fuzzy finding.
I have a draft working
here.
It populates a preview with the session/window index in a tmux-compliant format
and will switch to the selected session.
This can be partially implemented by means of this recent commit: https://github.com/tmux/tmux/commit/2628af573d98f7bdd4db02c7a80c860b867a45fb
I do so here: https://github.com/petobens/dotfiles/commit/c21c306660142d93d283186210ad9d301a2f5186 in order to get the following:

System default voice doesn't change on `say` command within tmux sessions

Recently I've changed my default system voice via "System Preferences > Dictation & Speech > Text to Speech > System Voice". If I open a new Terminal window and use the say command, the correct voice is used. However, the previous voice is still used if I use the say command within a tmux session.
I've tried restarting, shutting down tmux completely, and opening an entirely new tmux session with tmux new-session -s foobar and still it doesn't pick up the new preferred voice.
This is really a minor issue, but it eats at me that I have no idea why it's happening. Any ideas?
I'm pretty sure this is the same root cause as that other issue: many tools that need to interact with the UI (graphics, sounds...) fail within a tmux session: say, pbcopy/pbpaste, nohup, launchctl export|getenv|setenv, subl (Sublime Text command line tool), Retina rendering of apps launched under tmux, tools trying to access KeyChain (curl, ssh...), etc.
I remember GNU screen used to have the same problem but Apple patched it and now it works fine, but tmux still has the problem.
Solution (2017-05)
Borrowing from answers in linked issue, for tmux you can do this if you have Homebrew:
brew install reattach-to-user-namespace
Then put the following in your ~/.tmux.conf:
set-option -g default-command "reattach-to-user-namespace -l $SHELL"
I reproduced your issue on macOS 10.11.4, and the above fixed it.
See here for more info on the nature of the problem, and its workaround (using undocumented macOS APIs)
Better solution soon?
As mentioned in comment, future versions of tmux might do this dance natively, at least it's being worked on, and current master has the fix.

Use Ctrl + Left/Right to move forward/back one word in tmux within Mobaxterm

When using tmux within Mobaxterm, Ctrl + Left/Right just moves the cursor forward/back one character, not one word.
In the following cases, Ctrl + Left/Right does behave as expected:
in bash within Mobaxterm
in screen within Mobaxterm
in tmux within Cygwin
in screen or bash within Cygwin
So it seems to be an issue only when combining tmux with Mobaxterm.
In all cases, I am ssh-ing to a remote linux machine, within either Cygwin or Mobaxterm. My /etc/inputrc is set as it should for the shortcuts to work.
Any clue?
Old question. But in case someone find his way here. This is sgzmd's answer:
Edit your ~/.tmux.conf and add lines:
set-window-option -g xterm-keys on
If you don’t want to make it permanent just yet, do:
C-b :set-window-option xterm-keys on
Reload your config in tmux by doing:
C-b :source-file ~/.tmux.conf
It worked for me.
original answer here

Working on multiple terminals

I am using ubuntu terminal for my project and at times I need more than 5 terminals to be open at the same time and kind of juggle between them to see outputs of multiple programs running simultaneously. I am having hard time toggling between the terminals. Is there something that will hold all terminals together in one window and make my life simpler? I read somewhere that konsole does that for me, but I cannot bring up konsole for some reason and I am getting an error : bash: konsole: command not found.
Any kind of info/help is greatly appreciated.
Use tmux (and eventually, tmuxinator). It may have a slight learning curve but it'll be worth it, once you have it mastered!
Here's what an example session looks like.
If you want to try Konsole, try installing it first. It's part of KDE if that helps.
http://konsole.kde.org/
Ubuntu comes with gnome iirc. It has gnome-terminal as jasonspiro pointed out.
Have you tried using multiple workspaces? I'm using ubuntu 11 and if I find that I have a terminal layout I like to keep intact I simply place all of those terminals on a 2nd workspace. This can me done by right clicking on the terminal and clicking "Move to another workspace".
Use gnome-terminal instead. http://packages.ubuntu.com/ubuntu-desktop indicates to me that it comes with Ubuntu. It lets you open multiple tabs. Press Ctrl+Shift+T or click the appropriate menu command to open a new tab.
First, consider switching to ubuntu classic desktop. In clasic desktop you can move and resize windows like in um, windows, and then have multiple terminals visible at once.
Second, consider creating new terminals in the one terminal window. This can be done with CTRLSHIFTT
Third, alhough not much more useful for your purposes than the previous suggestion, have a look at screen(1), which is old, featureful, and no longer maintained, or tmux(1), which is still maintained. Either one can be run from a terminal. Both are installable from Software Center or synaptic.
You can use gnome-terminal. The script below will open 3 tabs running the respective commands..
tab="--tab"
cmd01="bash -c 'command in 1st terminal';bash"
cmd02="bash -c 'command in 2nd terminal';bash"
cmd03="bash -c 'command in 3rd terminal';bash"
foo=""
foo+=($tab -e "$cmd01")
foo+=($tab -e "$cmd02")
foo+=($tab -e "$cmd03")
gnome-terminal "${foo[#]}"
exit 0

Resources