Skip to content
Merged
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
42 changes: 26 additions & 16 deletions install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -131,35 +131,40 @@ fi
if [ ! -d "$HOME/.shelltime/daemon" ]; then
mkdir -p "$HOME/.shelltime/daemon"
if [ $? -ne 0 ]; then
echo "Error: Failed to create $HOME/.shelltime/daemon directory."
exit 1
echo "Warning: Failed to create $HOME/.shelltime/daemon directory. Daemon functionality may be unavailable."
fi
fi

# Add $HOME/.shelltime/bin to user path
if [[ "$OS" == "Darwin" ]] || [[ "$OS" == "Linux" ]]; then
# For Zsh
if ! grep -q '$HOME/.shelltime/bin' "$HOME/.zshrc"; then
echo '# Added by shelltime' >> "$HOME/.zshrc"
echo 'export PATH="$HOME/.shelltime/bin:$PATH"' >> "$HOME/.zshrc"
if [ -f "$HOME/.zshrc" ]; then
if ! grep -q '$HOME/.shelltime/bin' "$HOME/.zshrc"; then
echo '# Added by shelltime' >> "$HOME/.zshrc"
echo 'export PATH="$HOME/.shelltime/bin:$PATH"' >> "$HOME/.zshrc"
fi
fi

# For Fish
if ! grep -q '$HOME/.shelltime/bin' "$HOME/.config/fish/config.fish"; then
if command_exists fish; then
if [ ! -d "$HOME/.config/fish" ]; then
mkdir -p "$HOME/.config/fish"
fi
if [ ! -f "$HOME/.config/fish/config.fish" ]; then
touch "$HOME/.config/fish/config.fish"
fi
echo '# Added by shelltime' >> "$HOME/.config/fish/config.fish"
echo 'fish_add_path $HOME/.shelltime/bin' >> "$HOME/.config/fish/config.fish"
if ! grep -q '$HOME/.shelltime/bin' "$HOME/.config/fish/config.fish"; then
echo '# Added by shelltime' >> "$HOME/.config/fish/config.fish"
echo 'fish_add_path $HOME/.shelltime/bin' >> "$HOME/.config/fish/config.fish"
fi
fi

# For Bash
if ! grep -q '$HOME/.shelltime/bin' "$HOME/.bashrc"; then
echo '# Added by shelltime' >> "$HOME/.bashrc"
echo 'export PATH="$HOME/.shelltime/bin:$PATH"' >> "$HOME/.bashrc"
if [ -f "$HOME/.bashrc" ]; then
if ! grep -q '$HOME/.shelltime/bin' "$HOME/.bashrc"; then
echo '# Added by shelltime' >> "$HOME/.bashrc"
echo 'export PATH="$HOME/.shelltime/bin:$PATH"' >> "$HOME/.bashrc"
fi
fi
fi

Expand Down Expand Up @@ -191,8 +196,7 @@ hooks_path="$HOME/.shelltime/hooks"
if [ ! -d "$hooks_path" ]; then
mkdir -p "$hooks_path"
if [ $? -ne 0 ]; then
echo "Error: Failed to create $hooks_path directory."
exit 1
echo "Warning: Failed to create $hooks_path directory. Shell hooks may be unavailable."
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Removing exit on hooks_path creation failure allows broken source lines to be added to shell configs

When mkdir -p "$hooks_path" fails at line 198, the old code called exit 1, preventing any further damage. The new code prints a warning and continues. The script then proceeds to: (1) attempt mkdir -p again at install.bash:238 (which also fails), (2) call process_file at install.bash:245-252 where curl -o fails because the directory doesn't exist so no hook files are written, and (3) call add_source_to_config at install.bash:255-263 which adds source ~/.shelltime/hooks/zsh.zsh (and similar) lines to the user's shell config files — pointing to files that don't exist. This causes error messages on every new shell session (e.g., no such file or directory from zsh/bash source). In shells configured with set -e or setopt err_exit, this could abort shell initialization entirely.

Prompt for agents
In install.bash, after the warning at line 199 about failing to create the hooks_path directory, the script should either (a) exit 1 as before, or (b) set a flag (e.g., hooks_failed=true) and check that flag before the add_source_to_config calls at lines 255-263, skipping those calls if hooks directory creation failed. The simplest fix is to restore the exit 1 at line 199, but if the intent is to be graceful, then guard lines 238-263 with a check like: if [ -d "$hooks_path" ]; then ... fi, or add early returns/skips when the directory doesn't exist. The key invariant to maintain: never add source lines to shell configs unless the corresponding hook files actually exist.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

fi
fi

Expand Down Expand Up @@ -248,9 +252,15 @@ process_file "bash-preexec.sh" "https://raw.githubusercontent.com/rcaloras/bash-
process_file "bash.bash" "https://raw.githubusercontent.com/malamtime/installation/master/hooks/bash.bash"

# Add source lines to config files
add_source_to_config "$HOME/.zshrc" "${hooks_path}/zsh.zsh"
add_source_to_config "$HOME/.config/fish/config.fish" "${hooks_path}/fish.fish"
add_source_to_config "$HOME/.bashrc" "${hooks_path}/bash.bash"
if [ -f "$HOME/.zshrc" ]; then
add_source_to_config "$HOME/.zshrc" "${hooks_path}/zsh.zsh"
fi
if [ -f "$HOME/.config/fish/config.fish" ]; then
add_source_to_config "$HOME/.config/fish/config.fish" "${hooks_path}/fish.fish"
fi
Comment on lines +258 to +260
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with the fish PATH setup logic (lines 149-160) and the PR description ("Guard fish blocks behind command_exists fish"), it would be clearer to use command_exists fish here as well. While the current file existence check works because the PATH setup section earlier in the script creates config.fish if fish is installed, using the same type of check improves readability and makes the intent more explicit.

Suggested change
if [ -f "$HOME/.config/fish/config.fish" ]; then
add_source_to_config "$HOME/.config/fish/config.fish" "${hooks_path}/fish.fish"
fi
if command_exists fish; then
add_source_to_config "$HOME/.config/fish/config.fish" "${hooks_path}/fish.fish"
fi

if [ -f "$HOME/.bashrc" ]; then
add_source_to_config "$HOME/.bashrc" "${hooks_path}/bash.bash"
fi

# Reinstall daemon if shelltime is available
if command_exists shelltime; then
Expand Down
Loading