fix(install): create ~/.zshrc when it's missing so opencode lands on PATH (#57348)

This commit is contained in:
Kit Langton
2026-10-20 15:01:34 -07:00
committed by GitHub
Unverified
parent 2cb963c6a7
commit 442439183d
+17
View File
@@ -366,6 +366,7 @@ fi
install_legacy_shim
path_added=false
add_to_path() {
local config_file=$1
local command=$2
@@ -375,6 +376,7 @@ add_to_path() {
elif [[ -w $config_file ]]; then
echo -e "\n# opencode" >> "$config_file"
echo "$command" >> "$config_file"
path_added=true
print_message info "${MUTED}Successfully added ${NC}opencode ${MUTED}to \$PATH in ${NC}$config_file"
else
print_message warning "Manually add the directory to $config_file (or similar):"
@@ -416,6 +418,18 @@ if [[ "$no_modify_path" != "true" ]]; then
fi
done
# A new Mac has no ~/.zshrc, so create the shell's main config file rather than leaving opencode off PATH.
if [[ -z $config_file ]]; then
case $current_shell in
zsh) new_config_file="${ZDOTDIR:-$HOME}/.zshrc" ;;
fish) new_config_file="$HOME/.config/fish/config.fish" ;;
*) new_config_file="" ;;
esac
if [[ -n $new_config_file ]] && mkdir -p "$(dirname "$new_config_file")" 2>/dev/null && touch "$new_config_file" 2>/dev/null; then
config_file=$new_config_file
fi
fi
if [[ -z $config_file ]]; then
print_message warning "No config file found for $current_shell. You may need to manually add to PATH:"
print_message info " export PATH=$INSTALL_DIR:\$PATH"
@@ -459,6 +473,9 @@ echo -e ""
echo -e ""
echo -e "${MUTED}OpenCode includes free models, to start:${NC}"
echo -e ""
if [[ $path_added == "true" ]]; then
echo -e "exec \$SHELL ${MUTED}# Reload PATH (or open a new terminal)${NC}"
fi
echo -e "cd <project> ${MUTED}# Open directory${NC}"
echo -e "opencode ${MUTED}# Run command${NC}"
echo -e ""