Skip to content

Commit

Permalink
fix(chezmoi): store atuin database persistant if also persist-shell-h…
Browse files Browse the repository at this point in the history
…istory feature is used
  • Loading branch information
ckagerer committed May 25, 2024
1 parent 0ce7b46 commit a3f9bd8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
8 changes: 2 additions & 6 deletions 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.2.1",
"version": "1.3.0",
"description": "Install chezmoi",
"documentationURL": "https://github.com/ckagerer/devcontainer-features/tree/main/src/chezmoi",
"options": {
Expand All @@ -24,13 +24,9 @@
"type": "string",
"default": "",
"description": "The key to use for Atuin. Leave empty if you don't want to use Atuin."
},
"atuin_import_history": {
"type": "boolean",
"default": false,
"description": "Import existing history from bash and zsh."
}
},
"postCreateCommand": "/usr/local/share/chezmoi-atuin-init.sh",
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils",
"ghcr.io/devcontainers/features/python"
Expand Down
32 changes: 20 additions & 12 deletions src/chezmoi/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,26 @@ sudo --user "${CHEZMOI_USER}" bash -c "cd ${CHEZMOI_USER_HOME} && REMOTE_CONTAIN

# Atuin login and sync
if [ -n "${ATUIN_USER}" ] && [ -n "${ATUIN_PASSWORD}" ] && [ -n "${ATUIN_KEY}" ]; then
sudo --user "${CHEZMOI_USER}" atuin login --username "${ATUIN_USER}" --password "${ATUIN_PASSWORD}" --key "${ATUIN_KEY}"
sudo --user "${CHEZMOI_USER}" atuin sync

# Import history if configured
if [ -n "${ATUIN_IMPORT_HISTORY}" ]; then
if command -v bash &>/dev/null; then
sudo --user "${CHEZMOI_USER}" atuin import bash || true
fi
if command -v zsh &>/dev/null; then
sudo --user "${CHEZMOI_USER}" atuin import zsh || true
fi
fi
# --- Generate a 'pull-git-lfs-artifacts.sh' script to be executed by the 'postCreateCommand' lifecycle hook
INIT_ATUIN_SCRIPT_PATH="/usr/local/share/chezmoi-atuin-init.sh"

tee "$INIT_ATUIN_SCRIPT_PATH" >/dev/null \
<<EOF
#!/usr/bin/env bash
set -ex
# If /.persist-shell-history exists, we assume that the user wants to persist also the atuin history
if [ -d "/.persist-shell-history" ]; then
mkdir -p "/.persist-shell-history/atuin"
mkdir -p "~/.local/share/atuin"
ln -s "/.persist-shell-history/atuin" "~/.local/share/atuin"
fi
atuin login --username "${ATUIN_USER}" --password "${ATUIN_PASSWORD}" --key "${ATUIN_KEY}"
atuin sync
EOF

chmod 755 "$INIT_ATUIN_SCRIPT_PATH"
fi

echo "Done"

0 comments on commit a3f9bd8

Please sign in to comment.