From 14d11942e072fa3bb6202927713b2b0cb5aec751 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Fri, 20 Dec 2024 01:43:22 -0700 Subject: [PATCH] fish: Initial systemd-nspawn tweaks Signed-off-by: Nathan Chancellor --- fish/config.fish | 26 ++++++++++++++++++------- fish/functions/_hydro_addon_nathan.fish | 14 ++++++++++++- fish/functions/in_dbx.fish | 8 ++++++++ fish/functions/in_nspawn.fish | 7 +++++++ 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 fish/functions/in_dbx.fish create mode 100644 fish/functions/in_nspawn.fish diff --git a/fish/config.fish b/fish/config.fish index 85ec23f7..96a15103 100644 --- a/fish/config.fish +++ b/fish/config.fish @@ -16,6 +16,15 @@ if test "$LOCATION" = mac set -gx SHELL /opt/homebrew/bin/fish else + # If /tmp/tmux-1000 is a mountpoint, it means we are in a systemd-nspawn + # container. If TMUX is not already set, we should set it so that we can + # interact with the host's tmux server. This needs to be done before the + # call to start_tmux below so that a tmux session is not started in the + # container. + if mountpoint -q /tmp/tmux-1000; and not set -q TMUX + set -gx TMUX /tmp/tmux-1000/default + end + if not string match -qr tty (tty); and status is-interactive start_tmux end @@ -23,17 +32,20 @@ else if in_container # distrobox may add duplicates to PATH, clean it up :/ # https://github.com/89luca89/distrobox/issues/1145 - set --local --path deduplicated_path - set --local item + if in_dbx + set --local --path deduplicated_path + set --local item - for item in $PATH - if not contains $item $deduplicated_path - set -a deduplicated_path $item + for item in $PATH + if not contains $item $deduplicated_path + set -a deduplicated_path $item + end end + set --export --global --path PATH $deduplicated_pathi end - set --export --global --path PATH $deduplicated_path - if test "$USE_CBL" = 1 + # distrobox uses $USE_CBL, systemd-spawn uses /etc/use-cbl + if test -r /use-cbl; or test "$USE_CBL" = 1 for item in $CBL_QEMU_BIN $CBL_TC_BNTL $CBL_TC_LLVM fish_add_path -gm $item end diff --git a/fish/functions/_hydro_addon_nathan.fish b/fish/functions/_hydro_addon_nathan.fish index 28ad7267..36201a00 100644 --- a/fish/functions/_hydro_addon_nathan.fish +++ b/fish/functions/_hydro_addon_nathan.fish @@ -16,7 +16,7 @@ function _hydro_addon_nathan -d "Hydro prompt customizations" end # Print symbol if we are in a container (like default toolbox prompt) - if in_container + if in_dbx # If CONTAINER_ID is a part of the hostname (i.e., distrobox prior to # https://github.com/89luca89/distrobox/commit/d626559baaa4e6ccb35b3bb0befc9d46b7aa837e), # just show a symbol to know we are in a distrobox. @@ -25,6 +25,18 @@ function _hydro_addon_nathan -d "Hydro prompt customizations" else set container_str "($CONTAINER_ID)" end + end + if in_nspawn + if set incoming (findmnt -n -o FSROOT /run/host/incoming) + set container_str '('(string split -f 2 -m 1 -r / $incoming)')' + else if set image_id (string match -gr 'IMAGE_ID="?([^"]+)' /dev/null) = systemd-nspawn +end