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
8 changes: 4 additions & 4 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1836,12 +1836,12 @@ add_opencode_plugin() {

# Check if plugin array exists and if plugin is already configured
local has_plugin_array
has_plugin_array=$(jq -e '.plugin' "$opencode_config" 2>/dev/null && echo "true" || echo "false")
has_plugin_array=$(jq -e '.plugin' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")

Choose a reason for hiding this comment

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

high

This change correctly redirects jq's standard output to /dev/null while preserving its exit code. The original 2>/dev/null only suppressed stderr, allowing jq's successful JSON output to be captured by the variable, leading to incorrect conditional evaluation. This fix directly addresses the root cause of the plugin array overwrite bug.

Suggested change
has_plugin_array=$(jq -e '.plugin' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")
has_plugin_array=$(jq -e '.plugin' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")


if [[ "$has_plugin_array" == "true" ]]; then
# Check if plugin is already in the array
local plugin_exists
plugin_exists=$(jq -e --arg p "$plugin_name" '.plugin | map(select(startswith($p))) | length > 0' "$opencode_config" 2>/dev/null && echo "true" || echo "false")
plugin_exists=$(jq -e --arg p "$plugin_name" '.plugin | map(select(startswith($p))) | length > 0' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")

Choose a reason for hiding this comment

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

high

Similar to the previous instance, redirecting both stdout and stderr (>/dev/null 2>&1) ensures that the jq command's output does not interfere with the shell variable assignment, which was causing the plugin_exists check to fail incorrectly. This is a crucial fix for the logic.

Suggested change
plugin_exists=$(jq -e --arg p "$plugin_name" '.plugin | map(select(startswith($p))) | length > 0' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")
plugin_exists=$(jq -e --arg p "$plugin_name" '.plugin | map(select(startswith($p))) | length > 0' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")


if [[ "$plugin_exists" == "true" ]]; then
# Update existing plugin to latest version
Expand Down Expand Up @@ -1965,12 +1965,12 @@ setup_oh_my_opencode() {

# Check if plugin array exists
local has_plugin_array
has_plugin_array=$(jq -e '.plugin' "$opencode_config" 2>/dev/null && echo "true" || echo "false")
has_plugin_array=$(jq -e '.plugin' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")

Choose a reason for hiding this comment

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

high

This modification correctly handles the jq command's output by redirecting both stdout and stderr to /dev/null. This prevents the JSON output from jq -e from being concatenated with echo "true", which was causing the has_plugin_array variable to hold an unexpected value and leading to incorrect conditional logic.

Suggested change
has_plugin_array=$(jq -e '.plugin' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")
has_plugin_array=$(jq -e '.plugin' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")


if [[ "$has_plugin_array" == "true" ]]; then
# Check if plugin is already in the array
local plugin_exists
plugin_exists=$(jq -e --arg p "$plugin_name" '.plugin | map(select(. == $p or startswith($p + "@"))) | length > 0' "$opencode_config" 2>/dev/null && echo "true" || echo "false")
plugin_exists=$(jq -e --arg p "$plugin_name" '.plugin | map(select(. == $p or startswith($p + "@"))) | length > 0' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")

Choose a reason for hiding this comment

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

high

The change from 2>/dev/null to >/dev/null 2>&1 is essential here. It ensures that the jq command's output is completely suppressed, allowing the plugin_exists variable to accurately reflect the success or failure of the jq expression based solely on its exit code. This resolves the bug where existing plugins were not correctly detected.

Suggested change
plugin_exists=$(jq -e --arg p "$plugin_name" '.plugin | map(select(. == $p or startswith($p + "@"))) | length > 0' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")
plugin_exists=$(jq -e --arg p "$plugin_name" '.plugin | map(select(. == $p or startswith($p + "@"))) | length > 0' "$opencode_config" >/dev/null 2>&1 && echo "true" || echo "false")


if [[ "$plugin_exists" == "true" ]]; then
print_info "Oh-My-OpenCode already configured"
Expand Down