-
Notifications
You must be signed in to change notification settings - Fork 6
Fix OpenCode plugin array overwrite bug #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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") | ||||||
|
|
||||||
| 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") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous instance, redirecting both stdout and stderr (
Suggested change
|
||||||
|
|
||||||
| if [[ "$plugin_exists" == "true" ]]; then | ||||||
| # Update existing plugin to latest version | ||||||
|
|
@@ -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") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This modification correctly handles the
Suggested change
|
||||||
|
|
||||||
| 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") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change from
Suggested change
|
||||||
|
|
||||||
| if [[ "$plugin_exists" == "true" ]]; then | ||||||
| print_info "Oh-My-OpenCode already configured" | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change correctly redirects
jq's standard output to/dev/nullwhile preserving its exit code. The original2>/dev/nullonly suppressed stderr, allowingjq'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.