diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 3e07adbcc09..2505fd9c161 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,7 +10,15 @@ ARG USER_GID=$USER_UID # Create the user RUN groupadd $USERNAME && useradd -s /bin/bash --gid $USER_GID -m $USERNAME -RUN apt-get update && apt-get install -y sudo curl ca-certificates +RUN apt-get update && apt-get install -y sudo curl ca-certificates xdg-utils + +# Install xdg-open wrapper for browser integration +COPY .devcontainer/xdg-open-wrapper.sh /usr/local/bin/xdg-open-wrapper.sh +RUN chmod +x /usr/local/bin/xdg-open-wrapper.sh && \ + if [ -f /usr/bin/xdg-open ]; then \ + mv /usr/bin/xdg-open /usr/bin/xdg-open.real; \ + fi && \ + ln -s /usr/local/bin/xdg-open-wrapper.sh /usr/bin/xdg-open # Give user sudo access RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/devcontaineruser && chmod 0440 /etc/sudoers.d/devcontaineruser diff --git a/.devcontainer/xdg-open-wrapper.sh b/.devcontainer/xdg-open-wrapper.sh new file mode 100755 index 00000000000..6a5309759b2 --- /dev/null +++ b/.devcontainer/xdg-open-wrapper.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# xdg-open wrapper for devcontainer +# Launches URLs using VSCode's $BROWSER environment variable +# Falls back to native xdg-open for non-URLs + +NATIVE_XDG_OPEN="/usr/bin/xdg-open.real" + +# If it's an HTTP/HTTPS URL and $BROWSER is set, use it +if [[ "$1" == http:* || "$1" == https:* ]] && [ -n "$BROWSER" ]; then + exec "$BROWSER" "$@" +fi + +# Otherwise, fall back to native xdg-open if it exists +if [ -x "$NATIVE_XDG_OPEN" ]; then + exec "$NATIVE_XDG_OPEN" "$@" +fi + +# If we get here, we couldn't handle it +echo "Error: Cannot open '$1' - no suitable handler found" >&2 +exit 1