Skip to content

Commit

Permalink
feat: devcontainer support
Browse files Browse the repository at this point in the history
  • Loading branch information
senz committed Apr 21, 2024
1 parent 41db0a3 commit f1330bc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
3 changes: 3 additions & 0 deletions dot_gitconfig.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{ if not $REMOTE_CONTAINERS -}}
{{ # we do not manage git in devcontainers -}}
[user]
name = {{ .fullname }}
email = {{ .email }}
Expand All @@ -24,3 +26,4 @@
helper = /usr/local/share/gcm-core/git-credential-manager
[credential "https://dev.azure.com"]
useHttpPath = true
{{ end -}}
2 changes: 0 additions & 2 deletions dot_gitignore_global

This file was deleted.

5 changes: 5 additions & 0 deletions dot_gitignore_global.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ if not $REMOTE_CONTAINERS -}}
{{ # we do not manage git in devcontainers -}}
.env
.DS_Store
{{ end -}}
66 changes: 55 additions & 11 deletions install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,19 +1,63 @@
#!/bin/bash

# if darwin and brew is not installed
if [ "$(uname)" == "Darwin" ] && [ ! -x "$(command -v brew)" ]; then
echo "Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
CHEZMOI_USER="senz"

install_homebrew() {
if [ ! -x "$(command -v brew)" ]; then
xcode-select --install

echo "Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}

# if chezmoi is installed
if [ -x "$(command -v chezmoi)" ]; then
echo "Running chezmoi init --apply --verbose"
chezmoi init --apply --verbose
install_chezmoi() {
if [ ! -x "$(command -v chezmoi)" ]; then
echo "Installing chezmoi"

if [ "$(uname)" == "Darwin" ]; then
brew install chezmoi
elif [ "$(uname)" == "Linux" ]; then
sh -c "$(curl -fsLS get.chezmoi.io)"
fi
fi
}

prepare_devcontainer() {
echo "Running in devcontainer/codespace"
if [ ! -f ~/.config/chezmoi/chezmoi.yaml ]; then
mkdir -p $HOME/.config/chezmoi
echo "pre-populating config from gitconfig"
cat <<EOF > $HOME/.config/chezmoi/chezmoi.yaml
---
data:
fullname: $(git config --get user.name)
email: $(git config --get user.email)
recipient: $(git config --get user.signingkey)
EOF
fi
}

run_chezmoi() {
if [ -n "$REMOTE_CONTAINERS" ]; then
# we have all the files in the dotfiles directory already
# so we can just run chezmoi init with the dotfiles directory and then purge
chezmoi init --debug --no-tty -S ~/dotfiles --apply --verbose
else
chezmoi init --debug --apply --verbose $CHEZMOI_USER
fi
}

# os specific pre-requisites
if [ "$(uname)" == "Darwin" ]; then
install_homebrew
fi

install_chezmoi

# in devcontainer/codespace
# REMOTE_CONTAINERS is set
if [ -n "$REMOTE_CONTAINERS" ]; then
echo "Running in devcontainer/codespace"
prepare_devcontainer
fi

run_chezmoi

0 comments on commit f1330bc

Please sign in to comment.