Skip to content

Commit

Permalink
configs: tmux: Add support for systemd-nspawn
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
  • Loading branch information
nathanchance committed Dec 24, 2024
1 parent 94f5f24 commit 7d13763
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 50 deletions.
39 changes: 4 additions & 35 deletions configs/tmux/.tmux.conf → configs/tmux/.tmux.conf.common
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
# new window using c (distrobox) and C (host)
unbind c
bind-key c new-window dbxe
# New window on host using C
bind-key C new-window

# open specific distrobox container using N
bind-key N {
command-prompt -p "distrobox container:" {
new-window 'dbxe %1; or exec fish -l'
}
}
bind-key E {
command-prompt -p "new ephemeral distrobox container:" {
new-window 'dbxeph %1'
}
}

# run commands in either host or distrobox
bind-key r {
command-prompt -p "run command (distrobox):" {
new-window 'dbxe -- fish -c "begin; %1; end; or exec fish -l"'
}
}
# Run comand on the host using R
bind-key R {
command-prompt -p "run command (host):" {
new-window 'begin; %1; end; or exec fish -l'
}
}

# split panes using | and - (distrobox) and H and V (host)
bind-key | split-window -h dbxe
bind-key - split-window -v dbxe
# Split panes on the host using H and V
bind-key V split-window -h
bind-key H split-window -v
unbind '"'
Expand Down Expand Up @@ -61,17 +40,7 @@ set-option -g history-limit 1000000

set-option -g status-style "fg=#FFFFFF,bg=default,default"
set-window-option -g window-status-style "fg=#FFFFFF,bg=default,default"
# Make certain changes if we are running in a VM, as the session might be nested
# VM: Set window style to red
# Other platforms: Set prefix to "Ctrl + Space" and set window style to blue
if-shell '[ "$LOCATION" = "vm" ]' {
set-window-option -g window-status-current-style fg=red,bg=default,bold
} {
unbind C-b; \
set-option -g prefix C-Space; \
bind-key C-Space send-prefix; \
set-window-option -g window-status-current-style fg=blue,bg=default,bold
}

set-option -g message-style "fg=#FFFFFF,bg=default,bright"
set -g status-left " "
set -g status-justify left
Expand Down
26 changes: 26 additions & 0 deletions configs/tmux/.tmux.conf.dbx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# new window using c
unbind c
bind-key c new-window dbxe

# run commands in distrobox using r
bind-key r {
command-prompt -p "run command (distrobox):" {
new-window 'dbxe -- fish -c "begin; %1; end; or exec fish -l"'
}
}

# open specific distrobox container using N
bind-key N {
command-prompt -p "distrobox container:" {
new-window 'dbxe %1; or exec fish -l'
}
}
bind-key E {
command-prompt -p "new ephemeral distrobox container:" {
new-window 'dbxeph %1'
}
}

# split panes into distrobox container using | and -
bind-key | split-window -h dbxe
bind-key - split-window -v dbxe
17 changes: 17 additions & 0 deletions configs/tmux/.tmux.conf.nspawn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# new window using c
unbind c
bind-key c new-window mchsh

# open ephemeral container using E
bind-key E new-window 'sd_nspawn -e'

# run commands in systemd-nspawn using r
bind-key r {
command-prompt -p "run command (systemd-nspawn):" {
new-window "sd_nspawn -r '%1'; or exec fish -l"
}
}

# split panes into systemd-nspawn container using | and -
bind-key | split-window -h mchsh
bind-key - split-window -v mchsh
9 changes: 9 additions & 0 deletions configs/tmux/.tmux.conf.regular
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Bind prefix to Ctrl-Space instead of Ctrl-Space on the host
unbind C-b
set-option -g prefix C-Space
bind-key C-Space send-prefix

set-window-option -g window-status-current-style fg=blue,bg=default,bold

source ~/.tmux.conf.common
source ~/.tmux.conf.container
4 changes: 4 additions & 0 deletions configs/tmux/.tmux.conf.vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set-window-option -g window-status-current-style fg=red,bg=default,bold

source ~/.tmux.conf.common
source ~/.tmux.conf.container
24 changes: 16 additions & 8 deletions configs/tmux/next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ windows:
focus: true
layout: tiled
panes:
- shell: dbxe
shell_command: cbl_upd_krnl next-llvm
- shell: mchsh
shell_command:
- cmd: cbl_upd_krnl next-llvm
sleep_before: 1
start_directory: $CBL_SRC_P/linux-next-llvm
enter: false
focus: true
- shell: dbxe
shell_command: cbl_rb_fd
- shell: mchsh
shell_command:
- cmd: cbl_rb_fd
sleep_before: 1
start_directory: $CBL_SRC_P/fedora
enter: false
- shell: dbxe
shell_command: cbl_rb_pi
- shell: mchsh
shell_command:
- cmd: cbl_rb_pi
sleep_before: 1
start_directory: $CBL_SRC_P/rpi
enter: false
- shell: dbxe
shell_command: cbl_upd_src p n
- shell: mchsh
shell_command:
- cmd: cbl_upd_src p n
sleep_before: 1
start_directory: $CBL_SRC_P/linux-next
enter: false
4 changes: 2 additions & 2 deletions configs/tmux/primary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ windows:
panes:
- shell: btop
-
- window_name: distrobox
- window_name: nspawn
focus: true
panes:
- shell: dbxe
- shell: mchsh
10 changes: 6 additions & 4 deletions configs/tmux/qemu.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
session_name: qemu
windows:
- window_name: distrobox and cbl_vmm
- window_name: nspawn and cbl_vmm
focus: true
layout: 61d8,269x53,0,0[269x41,0,0,57,269x11,0,42{134x11,0,42,58,134x11,135,42,59}]
start_directory: '~'
panes:
- shell: dbxe
- shell: mchsh
shell_command:
- cmd: ssh_vm
enter: false
- shell: dbxe
sleep_before: 1
- shell: mchsh
shell_command:
- cmd: cbl_vmm run -c (math (nproc) / 2) -m (math (nproc) x 0.75)
enter: false
sleep_before: 1
focus: true
- shell: dbxe
- shell: mchsh
11 changes: 10 additions & 1 deletion fish/functions/user_setup.fish
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ rpmbuild/' >>$gitignore

# Configuration files (vim, tmux, etc)
set configs $ENV_FOLDER/configs
ln -frsv $configs/tmux/.tmux.conf $HOME/.tmux.conf
ln -fnrsv $configs/tmux/.tmux.conf.common $HOME/.tmux.conf.common
if test "$LOCATION" = vm
ln -fnrsv $configs/tmux/.tmux.conf.vm $HOME/.tmux.conf
else
ln -fnrsv $configs/tmux/.tmux.conf.regular $HOME/.tmux.conf
end
mkdir -p $HOME/.config/tio
ln -frsv $configs/local/tio $HOME/.config/tio/config
vim_setup
Expand Down Expand Up @@ -354,10 +359,14 @@ rpmbuild/' >>$gitignore

switch $LOCATION
case hetzner workstation
ln -fnrsv $configs/tmux/.tmux.conf.nspawn $HOME/.tmux.conf.container
sd_nspawn -i

case wsl
touch $HOME/.tmux.conf.container

case '*'
ln -fnrsv $configs/tmux/.tmux.conf.dbx $HOME/.tmux.conf.container
if has_container_manager
dbxc --yes
end
Expand Down

0 comments on commit 7d13763

Please sign in to comment.