diff --git a/dot_gitconfig.tmpl b/dot_gitconfig.tmpl index b34db61..f45f4dd 100644 --- a/dot_gitconfig.tmpl +++ b/dot_gitconfig.tmpl @@ -1,3 +1,5 @@ +{{ if not $REMOTE_CONTAINERS -}} +{{ # we do not manage git in devcontainers -}} [user] name = {{ .fullname }} email = {{ .email }} @@ -24,3 +26,4 @@ helper = /usr/local/share/gcm-core/git-credential-manager [credential "https://dev.azure.com"] useHttpPath = true +{{ end -}} diff --git a/dot_gitignore_global b/dot_gitignore_global deleted file mode 100644 index 3323b34..0000000 --- a/dot_gitignore_global +++ /dev/null @@ -1,2 +0,0 @@ -.env -.DS_Store diff --git a/dot_gitignore_global.tmpl b/dot_gitignore_global.tmpl new file mode 100644 index 0000000..70859b2 --- /dev/null +++ b/dot_gitignore_global.tmpl @@ -0,0 +1,5 @@ +{{ if not $REMOTE_CONTAINERS -}} +{{ # we do not manage git in devcontainers -}} +.env +.DS_Store +{{ end -}} diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index 7063239..c34194f --- a/install.sh +++ b/install.sh @@ -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 < $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