Skip to content

Commit

Permalink
feat(chezmoi): set ATUIN_HOST_NAME and ATUIN_HOST_USER
Browse files Browse the repository at this point in the history
  • Loading branch information
ckagerer committed May 25, 2024
1 parent 156fe37 commit 85129e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/chezmoi/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions src/chezmoi/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 85129e7

Please sign in to comment.