How to split Windows Terminal into 8 equal panes "programmatically"? - windows-subsystem-for-linux

I am trying to split the new Windows Terminal into 8 equal panes by running one or more commands.
Recently Microsoft added support for splitting the new Windows Terminal into panes "programmatically" by using the parameters:
split-pane -H or -V (Horizontal or Vertical pane)
I have tried a dozen combinations of the parameters, but it splits the terminal windows "wrong".
Here is an example:
wt `; split-pane -V -p "pwsh" `; split-pane -H -p "pwsh" `; split-pane -V -p "pwsh"
Here is the desired result:
How would I achieve this programmatically? It's possible to do in the Windows Terminal by using hotkeys ALT+SHIFT+MINUS and ALT+SHIFT+PLUS (see screenshot).

Currenty this is simply not possible using wt.exe on its own however if you are using WSL you could do it with tmux.
In order to get equal spacing of the panes with wt.exe on its own, split-pane size control would need to be supported and that feature is currently in the backlog. Also I think you would probably need to 'nest' the split-pane commands and that is not yet possible in Window Terminal either.

A little late but here is a solution
"startupActions": "-p \"Bash\" ; split-pane -p \"Bash\" -V ; move-focus left ; split-pane -p \"Bash\" -H ; move-focus right;split-pane -p \"Bash\" -H ; move-focus up ; move-focus left ; split-pane -p \"Bash\" -V ; move-focus down ; split-pane -p \"Bash\" -V ; move-focus right ; move-focus up ; split-pane -p \"Bash\" -V move-focus down ; split-pane -p \"Bash\" -V"
It is not the prettiest but it is working.

Related

How can I bind a key to "exit copy-mode" in tmux?

I was trying to find a command for "leaving copy-mode" from this page, but it seems only the key binding prefix+q exists for this function; i.e., I can't find the associated :command-style command.
Does this mean it is impossible to bind another key to "leave copy-mode"? I'd like to bind the Esc key.
Copy mode uses its own set of commands, separate from tmux itself. Use send-keys -X to "type" commands in copy mode, as demonstrated by the default binding for exiting copy mode:
bind-key -T copy-mode q send-keys -X cancel
Note that Escape is already bound to the same command, at least in tmux 2.7.
% tmux list-keys | grep "send-keys -X cancel"
bind-key -T copy-mode C-c send-keys -X cancel
bind-key -T copy-mode Escape send-keys -X cancel
bind-key -T copy-mode q send-keys -X cancel
bind-key -T copy-mode-vi C-c send-keys -X cancel
bind-key -T copy-mode-vi q send-keys -X cancel
The page you were referring to is not a comprehensive list of tmux commands, but rather a comparison of how to accomplish some common tasks in different terminal multiplexers.

tmux bind % and " within tmux.conf

I try to map the % and " key to a new command without success.
What I tried so far are these options:
bind \% split-window -h
and
bind % split-window -h
which results in an error for \% with .tmux.conf:143: unknown key: \%
both are not working.
The reason I want to remap:
I want to highlight the active pane background.
I already did it for switching pane with these options, but in splitting the color obviously is not updated.
example for switching panes:
bind h select-pane -P 'bg=default' \; select-pane -L \; select-pane -P 'bg=black'
bind j select-pane -P 'bg=default' \; select-pane -D \; select-pane -P 'bg=black'
bind k select-pane -P 'bg=default' \; select-pane -U \; select-pane -P 'bg=black'
bind l select-pane -P 'bg=default' \; select-pane -R \; select-pane -P 'bg=black'
BTW: i have tmux version 2.6
You should not have a problem with your 2nd line, and for " you need to quote it. Eg this works for me in 2.6:
bind-key '"' split-window \; send-keys "pwd" Enter
bind-key % split-window -h \; send-keys "pwd" Enter

Busybox syslog enable/disable klogd

I know I can configure busybox to be built with klogd (CONFIG_KLOGD) and it works out of the box.
I'd like to know, though, if I can enable/disable this feature at run-time by a command-line switch or syslog-startup.conf option without need to recompile busybox.
Thanks in advance.
Well, I really rather have anyone else's response but since no one else came, I think my own solution is better than no solution, just in case someone else needs it.
I have dug into the sources and it looks like there is no command-line switch or config option to selectively enable/disable klogd.
The init-script, though, provides a very nice way of doing that.
1.Start/Stop of syslogd and klogd are separated lines:
start)
echo -n "Starting syslogd/klogd: "
start-stop-daemon -S -b -n syslogd -a /sbin/syslogd -- -n $SYSLOG_ARGS
start-stop-daemon -S -b -n klogd -a /sbin/klogd -- -n
echo "done"
The ugliest think one could think now is that, if klogd is not to be started, simply comment that line out.
/etc/syslog-startup.conf is simply sourced by /etc/init.d/syslog, before the start) case:
(basically the first thing in script)
if [ -f /etc/syslog-startup.conf ]; then
. /etc/syslog-startup.conf
Well, I can add a variable to /etc/syslog-startup.conf that I can test in the init script to selectively enable/disable the start-stop-daemon ... klog.
start)
echo -n "Starting syslogd/klogd: "
start-stop-daemon -S -b -n syslogd -a /sbin/syslogd -- -n $SYSLOG_ARGS
[ "$KLOGD_DISABLE" = "yes" ] || \
start-stop-daemon -S -b -n klogd -a /sbin/klogd -- -n
echo "done"
Since I am adding a non-standard variable to a config file, it is still very ugly but I feel it less ugly than the first one, so that's what I propose as solution.

How can I send password safely to tmux?

The following is my code in create_tmux.zsh
#!/bin/zsh
SESSIONNAME=$1
echo $SESSIONNAME
tmux has-session -t $SESSIONNAME &> /dev/null
if [ $? != 0 ]
then
tmux new-session -d -s $SESSIONNAME -n emacs
tmux new-window -t $SESSIONNAME:1 -n a
tmux send-keys -t $SESSIONNAME:1 'ssh -Y a#bc.com;$2' C-m
fi
tmux attach -t $SESSIONNAME
It's simple if I run
create_tmux.zsh ab $%^^&av1#
But in this way, it not only shows in the terminal of my password but also recorded in history.
How can I solve this?
Thank you

How do you get the size of a non-interactive tmux pane?

I have several tmux panes running in a window that have been started with syntax like:
tmux split-window -h -l {dynamic value} tail -f somefile.txt
tmux split-window -v -l {dynamic value} tail -f someotherfile.txt
tmux split-window -h -l {dynamic value} nc -l -p {random port}
As I use this script to create new panes and I need to update an array in my script with the sizes of each "window" (pane).
If the tmux panes contained interactive shells, I could just run tput cols and tput rows in them to get the size. I checked the tmux man page, but didn't see the commands I'm looking for.
If you know a pane’s id (e.g. %24) or its name (e.g. session_name:win_idx.pane_idx; see target-pane in the man page), then you can use display-message -p to query the dimensions:
tmux display-message -pt "$pane" -F '#{pane_width}x#{pane_height}'
If you do not already have a way to name to panes, then you can collect the pane ids as you split them off by using the -P option along with the -F option:
pane_a=$(tmux split-window -PF '#{pane_id}' -hl "$dynamic_value" 'tail -f somefile.txt')
⋮ # create other panes
pane_a_width=$(tmux display-message -pt "$pane_a" -F '#{pane_width}')
If you want to know about all the panes in a window, then you can use list-panes with the window’s id (e.g. #5) or name (e.g. session_name.win_idx; see target-window in the man page):
tmux list-panes -t "$window" -F '#{pane_id} #{pane_width}x#{pane_height} #{session_name}:#{window_index}.#{pane_index}'
Some of these options and format specifiers are not available on old versions of tmux, but there are usually workarounds (depending on just how old your version is).