devbox/devbox.fish

35 lines
1.3 KiB
Fish
Raw Normal View History

2026-03-17 11:47:59 -07:00
# Fish utility for easily shelling into devcontainers on the host.
# Uses Apple's `container` CLI (`brew install container`).
function devbox --argument-names name
argparse 'c/cpus=?' 'm/mem=?' 'i/image=?' h/help -- $argv
or return 1
if set -ql _flag_h
echo "Usage: devbox [-c | --cpus=COUNT] [-m | --mem=LIMIT] [-i | --image=IMAGE] [-h | --help] NAME" >&2
echo " Starts and executes a new shell session in a devcontainer with given name." >&2
return 1
end
if not set -ql _flag_cpus
set -f _flag_cpus 10
end
if not set -ql _flag_mem
set -f _flag_mem 8G
end
if not set -ql _flag_image
set -f _flag_image 'devbox:questing'
end
if [ "$(container ls -a --format=json | jq '[.[] | select(.configuration.id == "'"$name"'")] | length')" = 0 ]
container run --name "$name" -it -c "$_flag_cpus" -m "$_flag_mem" -v "$(pwd):/home/brent/project" -w /home/brent/project "$_flag_image"
else
if [ "$(container ls -a --format=json | jq -r '.[] | select(.configuration.id == "'"$name"'").status')" = stopped ]
container start "$name"
end
container ls | grep "^$name\s" # Print container info
container exec -it -w /home/brent/project $name /usr/bin/fish
end
end