Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

---

## 🧭 Overview

Check warning on line 18 in README.md

View workflow job for this annotation

GitHub Actions / docs-drift

doc-drift

Section "🧭 Overview" may be outdated: linked code changed but the section did not (changed code: bootstrap.sh).

The setup is split across five layers. Each layer owns one kind of thing, so
nothing is configured twice:
Expand Down Expand Up @@ -57,6 +57,9 @@
# <<< dotfiles:base <<<
```

(The `~/.bashrc` block has one more line after the `export`, `case $- in *i*) ;; *) return ;; esac`:
bash reads `~/.bashrc` for ssh commands too, and they must not load the shell setup.)

omnishell and the `shell.d` block then *append* their marker blocks to those
files. If the rc file were a stow symlink into the repo, this appends would be
written straight back into version control, so bootstrap writes a real file that
Expand All @@ -64,7 +67,7 @@

---

## 🚀 Install

Check warning on line 70 in README.md

View workflow job for this annotation

GitHub Actions / docs-drift

doc-drift

Section "🚀 Install" may be outdated: linked code changed but the section did not (changed code: bootstrap.sh).

```sh
git clone https://github.com/JtheGunner/dotfiles ~/.dotfiles
Expand Down Expand Up @@ -118,7 +121,7 @@
>
> Fix the cause (or install the packages yourself) and re-run `./bootstrap.sh`.

### Multiple checkouts

Check warning on line 124 in README.md

View workflow job for this annotation

GitHub Actions / docs-drift

doc-drift

Section "Multiple checkouts" may be outdated: linked code changed but the section did not (changed code: bootstrap.sh).

Several clones on one machine are fine, e.g. a working copy to hack on and a
second one to test the install end to end. Only one of them is live. Two things
Expand Down Expand Up @@ -161,7 +164,7 @@

---

## ⚙️ Settings file

Check warning on line 167 in README.md

View workflow job for this annotation

GitHub Actions / docs-drift

doc-drift

Section "⚙️ Settings file" may be outdated: linked code changed but the section did not (changed code: bootstrap.sh).

Every per-machine choice lives in one untracked file:
`~/.config/dotfiles/config.toml`. The first run copies
Expand Down Expand Up @@ -261,7 +264,7 @@

---

## 🪪 Git identity

Check warning on line 267 in README.md

View workflow job for this annotation

GitHub Actions / docs-drift

doc-drift

Section "🪪 Git identity" may be outdated: linked code changed but the section did not (changed code: bootstrap.sh).

This repo ships **no** `user.name` / `user.email`. The git config sets
`user.useConfigOnly = true` instead, so git refuses to commit until you set an
Expand All @@ -277,7 +280,7 @@
git config --file ~/.gitconfig.local user.email "12345+you@users.noreply.github.com"
```

### ✍️ Signing commits with SSH (optional)

Check warning on line 283 in README.md

View workflow job for this annotation

GitHub Actions / docs-drift

doc-drift

Section "✍️ Signing commits with SSH (optional)" may be outdated: linked code changed but the section did not (changed code: bootstrap.sh).

`bootstrap.sh` also asks for the path to your **public** SSH key. Give just the
path and the rest of the signing setup is derived from it. Leave it empty to
Expand Down Expand Up @@ -305,7 +308,7 @@

---

## ⚙️ Configuring

Check warning on line 311 in README.md

View workflow job for this annotation

GitHub Actions / docs-drift

doc-drift

Section "⚙️ Configuring" may be outdated: linked code changed but the section did not (changed code: bootstrap.sh).

Every setting lives in **one** of five places. None of this needs `bootstrap.sh`
re-run (though re-running it is always safe); the "Apply with" column says how
Expand Down Expand Up @@ -355,7 +358,7 @@
`DOCKER_STACKS_DIR` in `~/.<shell>rc.local` to use another directory.
`dsr <stack>` removes one.

### 3. omnishell: `omnishell/config.toml`

Check warning on line 361 in README.md

View workflow job for this annotation

GitHub Actions / docs-drift

doc-drift

Section "3. omnishell: omnishell/config.toml" may be outdated: linked code changed but the section did not (changed code: bootstrap.sh).

Version-controlled here, copied to `~/.config/omnishell/config.toml` by
`bootstrap.sh`. It owns rc *lines*: plugin inits, history/completion options,
Expand Down Expand Up @@ -408,7 +411,7 @@
shells start outside it. Flip it to `true` to attach to (or create) the
`default` session on every shell start.

### 4. Stow packages: standalone config files

Check warning on line 414 in README.md

View workflow job for this annotation

GitHub Actions / docs-drift

doc-drift

Section "4. Stow packages: standalone config files" may be outdated: linked code changed but the section did not (changed code: bootstrap.sh).

`stow` symlinks these into `$HOME`, so **editing the file in the repo changes the
live config immediately** (you may still need to reload the target app). After
Expand Down Expand Up @@ -450,7 +453,7 @@

---

## 🎨 Colours: Root Loops

Check warning on line 456 in README.md

View workflow job for this annotation

GitHub Actions / docs-drift

doc-drift

Section "🎨 Colours: Root Loops" may be outdated: linked code changed but the section did not (changed code: bootstrap.sh).

Terminal colours are defined **once**; everything else inherits the 16 ANSI
colours. See [`rootloops`](rootloops):
Expand Down
20 changes: 13 additions & 7 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,20 @@ install_omnishell() {
# rc file (relative to $HOME) : the rc library its base block sources
RC_BASES=(".zshrc:zsh/zshrc.zsh" ".bashrc:bash/bashrc.bash")

# the dotfiles:base block that points an rc file at this checkout
# the dotfiles:base block that points an rc file at this checkout. bash reads ~/.bashrc
# for non-interactive shells too (sshd starts every remote command through it), so the
# bash block returns early there: nothing below it is meant for ssh commands, and
# Ansible's become prompt detection breaks when it runs.
_rc_base_block() {
cat <<EOF
# >>> dotfiles:base >>>
export DOTFILES="$DOTFILES"
[ -r "\$DOTFILES/$1" ] && . "\$DOTFILES/$1"
# <<< dotfiles:base <<<
EOF
printf '%s\n' '# >>> dotfiles:base >>>'
printf 'export DOTFILES="%s"\n' "$DOTFILES"
case "$1" in
bash/*)
# shellcheck disable=SC2016 # literal text for the rc file, not an expansion here
printf '%s\n' 'case $- in *i*) ;; *) return ;; esac' ;;
esac
printf '[ -r "$DOTFILES/%s" ] && . "$DOTFILES/%s"\n' "$1" "$1"
printf '%s\n' '# <<< dotfiles:base <<<'
}

# the DOTFILES= path inside an rc file's base block; empty without a block
Expand Down
50 changes: 50 additions & 0 deletions tests/test-bashrc-noninteractive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# bootstrap.sh write_rc_base: ~/.bashrc stops early in non-interactive shells. bash reads
# ~/.bashrc for every ssh command, and running the rc libraries there breaks callers that
# expect a quiet shell (Ansible's become prompt detection); ~/.zshrc is interactive-only
# and gets no guard.
# shellcheck disable=SC2034 # variables are read inside the eval'd check expressions
set -euo pipefail

REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
failures=0

pass() { printf ' ok %s\n' "$1"; }
fail() { printf ' FAIL %s\n' "$1"; failures=$((failures + 1)); }
check() { if eval "$2"; then pass "$1"; else fail "$1"; fi; }

# a fake checkout whose rc libraries only leave a marker file behind
CHECKOUT="$WORK/checkout"
mkdir -p "$CHECKOUT/bash" "$CHECKOUT/zsh"
cp "$REPO/bootstrap.sh" "$CHECKOUT/"
cp -R "$REPO/lib" "$CHECKOUT/"
printf 'touch "$MARK"\n' > "$CHECKOUT/bash/bashrc.bash"
printf 'touch "$MARK"\n' > "$CHECKOUT/zsh/zshrc.zsh"

H="$WORK/home"
mkdir -p "$H"
env HOME="$H" BOOTSTRAP_SOURCE_ONLY=1 "$BASH" -c ". '$CHECKOUT/bootstrap.sh'; write_rc_base" > "$WORK/out" 2>&1

echo ">> generated rc files"
check "bashrc has one base block" "[ \"\$(grep -c '^# >>> dotfiles:base >>>\$' '$H/.bashrc')\" = 1 ]"
check "bashrc returns early when not interactive" "grep -qxF 'case \$- in *i*) ;; *) return ;; esac' '$H/.bashrc'"
check "the guard sits after DOTFILES is exported and before the library is sourced" \
"awk '/^export DOTFILES=/{e=NR} /^case /{g=NR} /^\\[ -r /{s=NR} END{exit !(e<g && g<s)}' '$H/.bashrc'"
check "zshrc has no guard" "! grep -q 'return' '$H/.zshrc'"
check "the checkout path in the block is unchanged" "[ \"\$(grep -c '^export DOTFILES=\"$CHECKOUT\"\$' '$H/.bashrc')\" = 1 ]"

echo ">> behaviour"
MARK="$WORK/mark-noninteractive"
env HOME="$H" MARK="$MARK" "$BASH" -c ". '$H/.bashrc'; echo sourced-ok" > "$WORK/ni.out" 2>&1
check "a non-interactive shell does not load the rc library" "[ ! -e '$MARK' ] && grep -q sourced-ok '$WORK/ni.out'"
MARK="$WORK/mark-interactive"
env HOME="$H" MARK="$MARK" "$BASH" -ic ". '$H/.bashrc'" > /dev/null 2>&1 || true
check "an interactive shell loads the rc library" "[ -e '$MARK' ]"

if [ "$failures" -ne 0 ]; then
printf 'FAILED: %s\n' "$failures"
exit 1
fi
echo "PASS: bashrc guard"