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

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:

Related

is there any way I can open multiple terminals on the xfce4 window automatically every time I start xfce4?

I'm doing some experiments and while I do it I have to turn a board off and on frequently (a program doesn't get killed properly probably with unclosed socket .. I installed signal handler and it worked and now it doesn't..) . Every time I turn on the board, I start vnc window (it starts xfce4 ) and have to open terminals in specific location. Is there any setup method through which the terminals are open automatically in specific locations? Or further with specific number of tabs? (I know how to give xwindow location and size : xwininfo -all. and use -geometry 1000x1000+300+300 for example).
From what I understand, you could add commands to the application autostart menu in Settings > Session and startup and give the command the working directory as an option as follows:
xfce4-terminal --default-working-directory="/home/$USER/Desktop"
The different options available are:
OPTIONS
Option Summary
Here is a summary of all the options, grouped by type. Explanations are in the following sections.
General Options
-h, --help; -V, --version; --disable-server; --color-table; --default-display=display;
--default-working-directory=directory
Window or Tab Separators
--tab; --window
Tab Options
-x, --execute; -e, --command=command; -T, --title=title; --dynamic-title-mode=mode;
--initial-title=title; --working-directory=directory; -H, --hold; --active-tab;
--color-text=color; --color-bg=color
Window Options
--display=display; --drop-down; --geometry=geometry; --role=role; --startup-id=string; -I,
--icon=icon; --fullscreen; --maximize; --minimize; --show-menubar, --hide-menubar;
--show-borders, --hide-borders; --show-toolbar, --hide-toolbar; --show-scrollbar,
--hide-scrollbar; --font=font; --zoom=zoom
Refer to the man page for more settings related to tabs and windows.
man xfce4-terminal

How do you scroll up/down using your mouse/keyboard in Git Bash?

I'm running windows 10 and I've just installed Git version 2.29.2.windows.2
I'm trying to learn Git on Udemy and the instructor can clear his screen by typing clear. However, he can also scroll up and down to see the commands he'd previous typed after he's cleared them. I'm unable to do that. I can't scroll with the mouse. Page up/Down don't do anything and nor do the arrow keys. Once I've typed clear, all my previous commands seem to disappear and I can't access them. I've had a look at the Git Bash options and I can't see anything which would fix this. I've also searched this site for answers but the most recent one I could find was from 2016 and is out of date and doesn't work.
Could anyone explain how I can scroll once I've entered clear so that I can see my previous commands? Thanks.
It's not normal for the mouse scroll to retrieve history entries. It usually scrolls up the terminal window. Here are a few things to try.
Make sure you're using the Git Bash terminal using Mintty, not the Windows command prompt running bash.
Up-arrow and down-arrow are the same as Ctrl-P and Ctrl-N.
Run stty sane.
Do bind -p |less and look at the entries for next-history and previous-history. They should look like:
"\C-n": next-history
"\eOB": next-history
"\e[B": next-history
"\C-p": previous-history
"\eOA": previous-history
"\e[A": previous-history
Check your ~./inputrc and /etc/inputrc files.
Read the Bash man page sections for READLINE and bind.

Wait for screen window to end

I'm writing a shell script which utilises screen to display several things at once (split screens)
One of the windows will be the "gui" code which will ask the user questions while other windows display various progress items.
Part way through the script I have a need to vim a file. But this part of the code is within a subshell with redirected inputs. vim does not work well here*
So I figured I could open up a new screen window and load vim in there screen -X screen vim file
The problem is I need the gui code to wait until vim has quit before continuing.
So how can I wait for a specific screen window to end, from within screen?
screen -ls will not work here because it is only one of several windows within the whole session which I need to monitor.
I've also looked at screen -QX windows but this would appear to interrupt the vim session
* Relating to vim and the subshell: I've tried using exec 3<&1; cat file1 | ( read whatever; vim file2 <&3 ) but this has some major issues (e.g. can't see the first few lines of the file!)
Based on #William's comment this code:
screen -X screen vim --servername MYSERVER`
sleep 1
vim --servername MYSERVER --remote-wait file.txt
opens up vim in a separate window (and focusses it)
and then opens the file into that session and waits until the user quits vim
The sleep would appear to be required to give them vim session time to start up, otherwise the 2nd command can't find the vim server and instead tries to edit locally (which won't work inside the redirected subshell)

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.

Multiple tabs with tmux / tmuxinator and iTerm2

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

Resources