#!/bin/shid="$(echo "$@" | grep -Eo ' [a-zA-Z0-9]{64} ' | tr -d ' ')"PODMAN_COMMAND="$(command -v podman 2> /dev/null)"DISTROBOX_COMMAND="$(command -v distrobox 2> /dev/null)"# if we're in a flatpak, use podman-remote# else we fallback to host-spawnif [ -n "$FLATPAK_ID" ]; thenif command -v podman-remote > /dev/null 2>&1; thenPODMAN_COMMAND="podman-remote"elsePODMAN_COMMAND="flatpak-spawn --host podman"fiDISTROBOX_COMMAND="flatpak-spawn --host distrobox"fi# This little workaround is used to ensure# we use our distrobox to properly enter the containerif echo "$@" | grep -q 'exec'; then# if exec && distrobox -> use distrobox-enter --if [ "$($PODMAN_COMMAND inspect --type container --format '{{ index .Config.Labels "manager" }}' "${id}")" = "distrobox" ]; then# Ensure that our distrobox containers will use different vscode-servers by symlinking to different pathsif [ -n "${id}" ]; then$PODMAN_COMMAND exec -u "$USER" "${id}" /bin/sh -c 'if [ ! -L "${HOME}/.vscode-server" ]; then[ -e "${HOME}/.vscode-server" ] && mv "${HOME}/.vscode-server" /var/tmp[ -d /var/tmp/.vscode-server ] && mkdir /var/tmp/.vscode-serverln -sf /var/tmp/.vscode-server "$HOME"elif [ ! -e "${HOME}/.vscode-server" ]; thenmkdir /var/tmp/.vscode-serverfi'fi# Remove everything from $@ and leave only the execution part, we start# capturing after we meet our IDdbox_args="-e A=B"capture="false"for i; doif [ $capture = "true" ]; thenset -- "$@" "$i"elif echo "$i" | grep -q "VSCODE"; thendbox_args="$dbox_args -e $i"elif echo "$i" | grep -q "\-w"; thendbox_args="$dbox_args -w $2"fiif [ "$i" = "${id}" ]; thencapture="true"fishiftdone$DISTROBOX_COMMAND enter --additional-flags "${dbox_args}" "${id}" -- "$@"exit $?fifi$PODMAN_COMMAND "$@"