diff --git a/src/chezmoi/devcontainer-feature.json b/src/chezmoi/devcontainer-feature.json index da2beb7..528b12e 100644 --- a/src/chezmoi/devcontainer-feature.json +++ b/src/chezmoi/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "chezmoi", "id": "chezmoi", - "version": "1.3.0", + "version": "1.4.0", "description": "Install chezmoi", "documentationURL": "https://github.com/ckagerer/devcontainer-features/tree/main/src/chezmoi", "options": { @@ -24,6 +24,16 @@ "type": "string", "default": "", "description": "The key to use for Atuin. Leave empty if you don't want to use Atuin." + }, + "atuin_host_name": { + "type": "string", + "default": "dev-container-${localWorkspaceFolderBasename}-${devcontainerId}", + "description": "Derive the new hostname for atuin from this string." + }, + "atuin_host_user": { + "type": "string", + "default": "", + "description": "The host user to use for Atuin. Leave empty if you don't want to change the host user." } }, "postCreateCommand": "/usr/local/share/chezmoi-atuin-init.sh", diff --git a/src/chezmoi/install.sh b/src/chezmoi/install.sh index d97fb6b..ab73222 100644 --- a/src/chezmoi/install.sh +++ b/src/chezmoi/install.sh @@ -59,6 +59,19 @@ ATUIN_USER="${ATUIN_USER}" ATUIN_PASSWORD="${ATUIN_PASSWORD}" ATUIN_KEY="${ATUIN_KEY}" +# First I tried do get "\${localWorkspaceFolderBasename}" as default via options. But it seems that this variable is not available in the context of the devcontainer-feature.json. So I decided to use the first folder in /workspaces as default. +ATUIN_HOST_NAME="dev-container-\$(basename "\$(find /workspaces -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | head -n1)")" +ATUIN_HOST_USER="${ATUIN_HOST_USER}" + +MAX_HOST_NAME_LENGTH=$(getconf HOST_NAME_MAX) +ATUIN_HOST_NAME=\$(echo "$ATUIN_HOST_NAME" | sed 's/[^a-zA-Z0-9\-]/-/g') +ATUIN_HOST_NAME=\$(echo "$ATUIN_HOST_NAME" | cut -c1-"$MAX_HOST_NAME_LENGTH") +echo "export ATUIN_HOST_NAME=${ATUIN_HOST_NAME}" >>"/etc/profile" + +if [ -n "${ATUIN_HOST_USER}" ]; then + echo "export ATUIN_HOST_USER=${ATUIN_HOST_USER}" >>"/etc/profile" +fi + # exit if required environment variables are not set if [ -n "\${ATUIN_USER}" ] && [ -n "\${ATUIN_PASSWORD}" ] && [ -n "\${ATUIN_KEY}" ]; then # If /.persist-shell-history exists, we assume that the user wants to persist also the atuin history