Skip to content

Instantly share code, notes, and snippets.

@givensuman
Created December 4, 2025 20:58
Show Gist options
  • Select an option

  • Save givensuman/0797920fcd40b149e4c2afaa45087f3f to your computer and use it in GitHub Desktop.

Select an option

Save givensuman/0797920fcd40b149e4c2afaa45087f3f to your computer and use it in GitHub Desktop.
fish shell wrapper for distrobox on ublue systems
##? We can create a wrapper function for Distrobox that makes our lives much easier.
##?
##? For one, it adds an is-inside subcommand for checking whether you're in a container.
##? It also modifies the enter subcommand to remember the last container we were in, which turns out to be super useful.
##? Most importantly, though, it changes our create command to add packages layered to our immutable system, and mount the
##? install location of ublue-brew (e.g. Linuxbrew)
##?
function box
set -l cmd $argv[1]
if test -z "$cmd"
echo "Usage: box <command> [args...]"
echo "Available commands: create, enter, list, rm, stop, export, etc."
echo "For 'enter' with no args, enters the last used container."
return 1
end
switch $cmd
case enter
if test (count $argv) -eq 1
# No container specified, use last used
if not set -q last_distrobox_container
echo "Error: No container specified and no last used container found."
echo "Available containers:"
distrobox list
return 1
end
set container $last_distrobox_container
echo "Entering last container: $container"
else
set container $argv[2]
set -U last_distrobox_container $container
end
distrobox enter $container $argv[3..-1]
case create
set layered (rpm-ostree status --json | jq -r '.deployments[0]."requested-packages"[]?' | string join ',')
distrobox create --additional-packages "$layered" --volume $HOME/.linuxbrew:$HOME/.linuxbrew $argv[2..-1]
# Set last container if --name was provided
set -l name_index (contains --name $argv 2>/dev/null)
if test $status -eq 0
set -l name_arg_index (math $name_index + 1)
if test $name_arg_index -le (count $argv)
set -U last_distrobox_container $argv[$name_arg_index]
end
end
case is-inside
if test -n "$CONTAINER_ID"
echo "You are inside a distrobox container."
return 0
else
echo "You are on the host system."
return 1
end
case host-exec
if test (count $argv) -lt 2
echo "Usage: box host-exec <command> [args...]"
return 1
end
distrobox-host-exec $argv[2..-1]
case '*'
distrobox $argv
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment