Last active
January 23, 2024 17:59
-
-
Save natesubra/346bf451c302838f13d0b107462cfedb to your computer and use it in GitHub Desktop.
Byobu Scripting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
_SESSION_NAME="dev" # arbitrary name for our session, must be unique | |
# Man pages: https://manpages.ubuntu.com/cgi-bin/search.py?q=byobu | |
# Good read: https://help.ubuntu.com/community/Byobu | |
# Understand all of the parameters for sub commands: https://fig.io/manual/tmux | |
# TL;DR: Byobu is an opinionated wrapper/config around tmux (default), or screen, two popular terminal multiplexers | |
# Everything that is applicable to tmux is generally applicable to byobu, | |
# just remember the byobu prefix is ctrl-a, tmux default is ctrl-b | |
# https://pragprog.com/titles/bhtmux2/tmux-2/ | |
# https://github.com/rothgar/awesome-tmux | |
# byobu useful hotkeys | |
# byobu-hotkeys will print them all to terminal | |
# NOTE: Windows terminal CAN hijack some function keys | |
# F2, create a new window | |
# F3/F4, move to the previous window, next window | |
# alt left arrow, alt right arrow: same as above | |
# F6, detach from the session and logout (aka disconnect SSH) | |
# Shift-F6, detach from the session but don't logout (aka drop back to the shell) | |
# F7, enter scrollback/search mode. Can use vim style find commands in terminal scrollback, /somthing, n, N | |
# Shift-F7, open scrollback for current pane in an editor | |
# F8, rename the current window | |
# shift-F8, toggle through different split layouts, continue pressing to return to original layout | |
# Alt-F9, toggle synchronize panes, aka send typed output to all windows | |
# shift-F11, toggle fullscreen on a pane (will add a little *Z to your window title) | |
# Ctrl-a ? : list prefix keybindings. | |
# NOTE: Ctrl is the default bound command/prefix key. So when you see C-<someletter>, | |
# know that it's talking about the bound prefix command key, which by default is ctrl, byobu also utilizes F12, | |
# so F12 and Ctrl can be used interchangably | |
# Some examples: | |
# C-a z : zoom the active pane | |
# C-a = : select paste buffer from list | |
# C-a q : display pane numbers | |
# C-a E : Resize all panes to balanced proportions | |
# byobu list-commands is worth looking at, we've barely scratched the surface of what's possible here | |
# most byobu commands can be sent to named sessions, or the current session (if used with the -t param) | |
# windows are the active window (aka the selected tab at the bottom) | |
# panes are the splits within the window | |
# configure the first run prompt: | |
byobu-ctrl-a screen | |
# create a new detatched (-d) named session (-s) | |
byobu new-session -d -s $_SESSION_NAME | |
# enable mouse mode | |
byobu set-option mouse on | |
byobu set-option mouse-utf8 on | |
# rename our selected window | |
byobu rename-window "${_SESSION_NAME}-window" | |
# Create our quad split, note that every time we split, the focus goes to the newly created pane | |
# usage: split-window [-bdefhIPvZ] [-c start-directory] [-e environment] [-F format] [-l size] [-t target-pane] [command] | |
byobu split-window -v # focus is now on the bottom pane | |
byobu split-window -h # focus is now on the bottom right pane | |
byobu select-pane -t 0 # focus is now on the top pane | |
byobu split-window -h # focus is now on the top right pane | |
# alternatively, we could have used the -t param to specify which pane to split | |
# alternatively, we could have used byobu-layout | |
# byobu-layout list|save|restore | |
# byobu-layout restore tiled | |
# send commands to some panes | |
byobu send-keys -t 0 "echo 'top left'" Enter | |
byobu send-keys -t 1 "echo 'top right'" Enter | |
byobu send-keys -t 2 "echo 'bottom left'" Enter | |
byobu send-keys -t 3 "echo 'bottom right'" Enter | |
# turn our bottom right pane into a clock | |
byobu clock-mode -t 3 | |
byobu send-keys -t 0 C-q | |
# attach to the session | |
# NOTE: Once we attach, this script won't continue execution until we detach or exit the active byobu process | |
byobu attach -t $_SESSION_NAME | |
# kill the session and all active panes/windows | |
# byobu kill-session -t $_SESSION_NAME | |
# or just byobu kill-session from any of the active panes/windows in that session | |
# Some other fun stuffs: | |
# Monitor a pane for a specific string, when found-- run another command | |
# while ! byobu capture-pane -p -t 1 | grep "findme" ; do sleep 1; done; echo "found it" | |
# Wait for a command to be completed before proceeding to the next scripted byobu command | |
# byobu send-keys -t work 'ping -c 5; byobu wait-for -S ping-completed' C-m\; wait-for ping-completed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment