Skip to content

Commit bd889d5

Browse files
committed
fix activation when missing ~/.zshrc
1 parent 6fed45c commit bd889d5

2 files changed

Lines changed: 28 additions & 31 deletions

File tree

lib/mise_setup.sh

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,19 @@ else
2020
export PATH="$HOME/.local/bin:$PATH"
2121
fi
2222

23-
# Ensure mise is activated in shell RC files
24-
activate_mise_in_shell() {
25-
local rc_file="$1"
26-
# shellcheck disable=SC2016 # Intentionally single-quoted: written literally to RC file
27-
local activation_line='eval "$(mise activate)"'
28-
29-
if [ -f "$rc_file" ]; then
30-
if ! grep -qF "mise activate" "$rc_file"; then
31-
{
32-
echo ""
33-
echo "# mise version manager"
34-
echo "$activation_line"
35-
} >> "$rc_file"
36-
echo " Added mise activation to $rc_file"
37-
fi
38-
fi
39-
}
40-
41-
# Detect which shell RC files exist and activate mise in them
42-
if [ -f "$HOME/.zshrc" ]; then
43-
activate_mise_in_shell "$HOME/.zshrc"
44-
fi
45-
46-
if [ -f "$HOME/.bashrc" ]; then
47-
activate_mise_in_shell "$HOME/.bashrc"
23+
# Ensure mise is activated in ~/.zshrc
24+
if [ ! -f "$HOME/.zshrc" ]; then
25+
touch "$HOME/.zshrc"
4826
fi
4927

50-
# If neither exists, create .bashrc with mise activation (Linux default)
51-
if [ ! -f "$HOME/.zshrc" ] && [ ! -f "$HOME/.bashrc" ]; then
52-
echo '# mise version manager' > "$HOME/.bashrc"
53-
# shellcheck disable=SC2016 # Intentionally single-quoted: written literally to RC file
54-
echo 'eval "$(mise activate)"' >> "$HOME/.bashrc"
55-
echo " Created $HOME/.bashrc with mise activation"
28+
if ! grep -qF "mise activate" "$HOME/.zshrc"; then
29+
{
30+
echo ""
31+
echo "# mise version manager"
32+
# shellcheck disable=SC2016 # Intentionally single-quoted: written literally to RC file
33+
echo 'eval "$(mise activate)"'
34+
} >> "$HOME/.zshrc"
35+
echo " Added mise activation to ~/.zshrc"
5636
fi
5737

5838
# Activate mise for this session

lib/packages_setup.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ case "$OS" in
3131
eval "$(/usr/local/bin/brew shellenv)"
3232
fi
3333
fi
34+
35+
# Ensure Homebrew activation is persisted in ~/.zshrc
36+
if cmd_exists brew; then
37+
if [ ! -f "$HOME/.zshrc" ]; then
38+
touch "$HOME/.zshrc"
39+
fi
40+
41+
if ! grep -qF "brew shellenv" "$HOME/.zshrc"; then
42+
{
43+
echo ""
44+
echo "# Homebrew"
45+
# shellcheck disable=SC2016 # Intentionally single-quoted: written literally to RC file
46+
echo 'eval "$(brew shellenv)"'
47+
} >> "$HOME/.zshrc"
48+
echo " Added Homebrew activation to ~/.zshrc"
49+
fi
50+
fi
3451
;;
3552
ubuntu)
3653
fmt_install "Updating apt package index"

0 commit comments

Comments
 (0)