Skip to content

fix(ohmyposh): ensure prompt loads last to avoid conflicts#7

Merged
rosstaco merged 3 commits intomainfrom
fix/ohmyposh/prompt-command-conflict
Nov 24, 2025
Merged

fix(ohmyposh): ensure prompt loads last to avoid conflicts#7
rosstaco merged 3 commits intomainfrom
fix/ohmyposh/prompt-command-conflict

Conversation

@rosstaco
Copy link
Copy Markdown
Owner

This PR fixes an issue where oh-my-posh fails to render in Bash when used alongside other features that modify PROMPT_COMMAND (like shell-history).

Changes:

  • Adds a postCreateCommand hook that runs a new configure-shell.sh script.
  • The script ensures the oh-my-posh configuration block is always at the end of .bashrc and .zshrc.
  • Implements migration logic for legacy configurations (replacing old eval lines with no-ops).
  • Adds a regression test legacy_config_migration and preserves reproduction scripts.

Closes: #6

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an issue where oh-my-posh fails to render in Bash when other features modify PROMPT_COMMAND. The solution adds a postCreateCommand hook that runs a helper script to ensure oh-my-posh configuration is always at the end of shell RC files.

Key Changes:

  • Adds region markers (# region / # endregion) to wrap oh-my-posh configuration blocks for reliable detection
  • Implements a configure-shell.sh script that moves oh-my-posh config to the end of RC files and migrates legacy configurations
  • Introduces a postCreateCommand hook to ensure proper ordering after all features are installed

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/ohmyposh/configure-shell.sh New helper script that ensures oh-my-posh config is at the end of shell RC files and handles legacy config migration
src/ohmyposh/install.sh Modified to install the helper script and add region markers to new configurations
src/ohmyposh/devcontainer-feature.json Added postCreateCommand hook to run the configure-shell script
test/ohmyposh/legacy_config_migration.sh New test verifying legacy configuration migration behavior
test/ohmyposh/test_sed.sh Test script for the sed replacement logic used in legacy migration
test/ohmyposh/repro_legacy.sh Reproduction script for debugging legacy configuration scenarios
test/ohmyposh/scenarios.json Added test scenario for legacy config migration
justfile Updated to copy all .sh files when building features
.devcontainer/devcontainer.json Added common-utils feature for development environment

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/ohmyposh/test_sed.sh
@@ -0,0 +1,25 @@
#!/bin/bash
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

Missing set -e directive. If any command in this test script fails (e.g., the sed command or bash syntax check), the script will continue executing instead of stopping at the failure point, potentially masking errors. Add set -e at the beginning of the script after the shebang.

Suggested change
#!/bin/bash
#!/bin/bash
set -e

Copilot uses AI. Check for mistakes.
Comment thread src/ohmyposh/configure-shell.sh Outdated
Comment on lines +47 to +68

# Remove lines containing "oh-my-posh init" and surrounding if/else block if possible
# This is harder to do reliably with regex, so we'll just comment out the old init line
# and add a new block at the end.

# Actually, let's just append the new block and assume the old one will be overridden or harmless
# if it's not setting PROMPT_COMMAND in a conflicting way.
# But the old one DOES set PROMPT_COMMAND via eval.

# Let's try to remove the old block if it matches the standard pattern
# Standard pattern:
# # Oh My Posh configuration
# if [ -s ~/.ohmyposh.json ]; then
# ...
# fi

# We'll use a simpler approach: Remove any lines containing "oh-my-posh init"
# and the specific comment "# Oh My Posh configuration"

# Use a temp file for grep output to avoid issues with reading/writing same file
# grep -v "oh-my-posh init" "$rc_file" | grep -v "# Oh My Posh configuration" > "$temp_file"

Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

[nitpick] These inline comments (lines 48-64) contain outdated reasoning and thought process that should be removed or condensed. They describe rejected approaches and internal debate about implementation, which clutters the code. Keep only the essential comment explaining what the current approach does:

# Replace lines containing "oh-my-posh init" with ":" (no-op) to disable old config
# while preserving syntax validity of surrounding if/else blocks.
sed 's/.*oh-my-posh init.*/    :/' "$rc_file" > "$temp_file"
Suggested change
# Remove lines containing "oh-my-posh init" and surrounding if/else block if possible
# This is harder to do reliably with regex, so we'll just comment out the old init line
# and add a new block at the end.
# Actually, let's just append the new block and assume the old one will be overridden or harmless
# if it's not setting PROMPT_COMMAND in a conflicting way.
# But the old one DOES set PROMPT_COMMAND via eval.
# Let's try to remove the old block if it matches the standard pattern
# Standard pattern:
# # Oh My Posh configuration
# if [ -s ~/.ohmyposh.json ]; then
# ...
# fi
# We'll use a simpler approach: Remove any lines containing "oh-my-posh init"
# and the specific comment "# Oh My Posh configuration"
# Use a temp file for grep output to avoid issues with reading/writing same file
# grep -v "oh-my-posh init" "$rc_file" | grep -v "# Oh My Posh configuration" > "$temp_file"

Copilot uses AI. Check for mistakes.
Comment thread src/ohmyposh/configure-shell.sh Outdated
Comment on lines +117 to +132
# Fish syntax is different, so we handle it separately or adapt move_to_end
# For now, let's just check if oh-my-posh init is present and move it to end
# Fish doesn't use PROMPT_COMMAND conflict in the same way, but good to be consistent.
# However, shell-history for fish uses a symlink or function override, so it might not conflict.
# But let's be safe.

FISH_CONFIG="$USER_HOME/.config/fish/config.fish"
if grep -q "oh-my-posh init" "$FISH_CONFIG"; then
echo "Ensuring Oh My Posh configuration is at the end of $FISH_CONFIG..."
# Simple move to end for fish
grep -v "oh-my-posh init" "$FISH_CONFIG" > "${FISH_CONFIG}.tmp"
echo "" >> "${FISH_CONFIG}.tmp"
echo "oh-my-posh init fish --config ~/.ohmyposh.json | source" >> "${FISH_CONFIG}.tmp" # Simplified for now, assuming standard init
# Actually, let's preserve the original logic if possible or just leave fish alone if it's not broken.
# The user issue was specifically about PROMPT_COMMAND which is Bash/Zsh.
# Let's skip fish for now to avoid breaking it with incorrect syntax assumptions.
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

[nitpick] Similarly, these comments (lines 117-132) are verbose and contain implementation debate. Condense to a clear explanation:

# Check fish
if [ -f "$USER_HOME/.config/fish/config.fish" ]; then
    # Skip fish configuration - the PROMPT_COMMAND conflict is specific to Bash/Zsh
    echo "Skipping fish configuration adjustment."
fi
Suggested change
# Fish syntax is different, so we handle it separately or adapt move_to_end
# For now, let's just check if oh-my-posh init is present and move it to end
# Fish doesn't use PROMPT_COMMAND conflict in the same way, but good to be consistent.
# However, shell-history for fish uses a symlink or function override, so it might not conflict.
# But let's be safe.
FISH_CONFIG="$USER_HOME/.config/fish/config.fish"
if grep -q "oh-my-posh init" "$FISH_CONFIG"; then
echo "Ensuring Oh My Posh configuration is at the end of $FISH_CONFIG..."
# Simple move to end for fish
grep -v "oh-my-posh init" "$FISH_CONFIG" > "${FISH_CONFIG}.tmp"
echo "" >> "${FISH_CONFIG}.tmp"
echo "oh-my-posh init fish --config ~/.ohmyposh.json | source" >> "${FISH_CONFIG}.tmp" # Simplified for now, assuming standard init
# Actually, let's preserve the original logic if possible or just leave fish alone if it's not broken.
# The user issue was specifically about PROMPT_COMMAND which is Bash/Zsh.
# Let's skip fish for now to avoid breaking it with incorrect syntax assumptions.
# Skipping fish configuration adjustment: PROMPT_COMMAND conflict is specific to Bash/Zsh, and fish syntax differs.

Copilot uses AI. Check for mistakes.
Comment thread src/ohmyposh/configure-shell.sh Outdated
USER_NAME="${USERNAME:-vscode}"
fi

USER_HOME=$(eval echo "~$USER_NAME")
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

Using eval with user input ($USER_NAME) is a potential security risk. If USER_NAME contains malicious characters or commands, they could be executed. While this is somewhat mitigated by the controlled sources of USER_NAME, it's safer to use getent or direct expansion:

USER_HOME=$(getent passwd "$USER_NAME" | cut -d: -f6)
# Or if getent is not available:
USER_HOME="$(bash -c "echo ~$USER_NAME")"
Suggested change
USER_HOME=$(eval echo "~$USER_NAME")
if command -v getent >/dev/null 2>&1; then
USER_HOME=$(getent passwd "$USER_NAME" | cut -d: -f6)
else
USER_HOME="$(bash -c "echo ~$USER_NAME")"
fi

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +40
if grep -q "$start_marker" "$rc_file"; then
echo "Ensuring Oh My Posh configuration is at the end of $rc_file..."

# Extract the block
local block=$(sed -n "/$start_marker/,/$end_marker/p" "$rc_file")

if [ -n "$block" ]; then
# Create a temp file
local temp_file=$(mktemp)

# Write file content WITHOUT the block to temp file
# We use awk to exclude the range
awk -v start="$start_marker" -v end="$end_marker" '
$0 ~ start {skip=1}
!skip {print}
$0 ~ end {skip=0}
' "$rc_file" > "$temp_file"

# Append the block to the end
echo "" >> "$temp_file"
echo "$block" >> "$temp_file"

# Replace original file
mv "$temp_file" "$rc_file"

echo "Moved Oh My Posh configuration to the end of $rc_file"
fi
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The script uses set -e at the top, which will cause it to exit on any error. However, when moving files from the marked region case (lines 14-40), if the block extraction or awk processing fails silently (e.g., empty block, file permissions), the script continues without properly handling the error. Consider adding validation:

if [ -n "$block" ]; then
    local temp_file=$(mktemp)
    
    if ! awk -v start="$start_marker" -v end="$end_marker" '...' "$rc_file" > "$temp_file"; then
        echo "Error: Failed to process $rc_file"
        rm -f "$temp_file"
        return 1
    fi
    
    # ... rest of the logic
fi

Copilot uses AI. Check for mistakes.
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
],
"postCreateCommand": "/usr/local/bin/oh-my-posh-configure-shell",
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The postCreateCommand will fail if the script doesn't exist or encounters errors, but there's no error handling or conditional execution. If other features also define postCreateCommand, this could cause conflicts. Consider:

  1. Adding error handling with || true to prevent build failures: /usr/local/bin/oh-my-posh-configure-shell || true
  2. Or checking if the script exists before executing: test -x /usr/local/bin/oh-my-posh-configure-shell && /usr/local/bin/oh-my-posh-configure-shell || true

Additionally, be aware that postCreateCommand can only be defined once per container. If users have other features or configurations defining this, the last one wins and yours may not run.

Suggested change
"postCreateCommand": "/usr/local/bin/oh-my-posh-configure-shell",
"postCreateCommand": "test -x /usr/local/bin/oh-my-posh-configure-shell && /usr/local/bin/oh-my-posh-configure-shell || true",

Copilot uses AI. Check for mistakes.
Comment thread test/ohmyposh/repro_legacy.sh Outdated
Comment on lines +51 to +53
$0 ~ start {skip=1}
!skip {print}
$0 ~ end {skip=0}
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

Same awk logic error as in configure-shell.sh (lines 26-30): the end marker line is not being excluded properly. The line containing the end marker sets skip=0 but is never printed because !skip is evaluated before skip is reset. Use next to skip both marker lines:

awk -v start="$start_marker" -v end="$end_marker" '
    $0 ~ start {skip=1; next}
    $0 ~ end {skip=0; next}
    !skip {print}
' "$rc_file" > "$temp_file"
Suggested change
$0 ~ start {skip=1}
!skip {print}
$0 ~ end {skip=0}
$0 ~ start {skip=1; next}
$0 ~ end {skip=0; next}
!skip {print}

Copilot uses AI. Check for mistakes.
Comment thread test/ohmyposh/repro_legacy.sh Outdated
# and the specific comment "# Oh My Posh configuration"

# Use a temp file for grep output to avoid issues with reading/writing same file
grep -v "oh-my-posh init" "$rc_file" | grep -v "# Oh My Posh configuration" > "$temp_file"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The repro script uses grep -v to remove oh-my-posh lines (line 91), but the actual configure-shell.sh implementation uses sed to replace them with : (line 71 in configure-shell.sh). This inconsistency means the repro script doesn't accurately reproduce the actual behavior. The repro script should use the same sed approach:

sed 's/.*oh-my-posh init.*/    :/' "$rc_file" > "$temp_file"
Suggested change
grep -v "oh-my-posh init" "$rc_file" | grep -v "# Oh My Posh configuration" > "$temp_file"
sed 's/.*oh-my-posh init.*/ :/' "$rc_file" | grep -v "# Oh My Posh configuration" > "$temp_file"

Copilot uses AI. Check for mistakes.
Comment thread src/ohmyposh/configure-shell.sh Outdated
Comment on lines +27 to +29
$0 ~ start {skip=1}
!skip {print}
$0 ~ end {skip=0}
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The awk script has a logic error: it sets skip=1 when it encounters the start marker, but doesn't print that line or the end marker line. The line containing the end marker sets skip=0 but is never printed because !skip is evaluated before skip is reset. This means the extracted block at line 18 will include both markers, but when removing the block, the end marker line won't be excluded, leaving a duplicate end marker in the file.

Fix the awk script to properly exclude both the start and end marker lines:

awk -v start="$start_marker" -v end="$end_marker" '
    $0 ~ start {skip=1; next}
    $0 ~ end {skip=0; next}
    !skip {print}
' "$rc_file" > "$temp_file"
Suggested change
$0 ~ start {skip=1}
!skip {print}
$0 ~ end {skip=0}
$0 ~ start {skip=1; next}
$0 ~ end {skip=0; next}
!skip {print}

Copilot uses AI. Check for mistakes.
Comment thread src/ohmyposh/configure-shell.sh Outdated

# Replace lines containing "oh-my-posh init" with ":" (no-op) to disable old config
# while preserving syntax validity of surrounding if/else blocks.
sed 's/.*oh-my-posh init.*/ :/' "$rc_file" > "$temp_file"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The sed command replaces oh-my-posh init lines with 4 spaces followed by a colon, but this assumes a specific indentation level. If the original line has different indentation (e.g., no indentation, or more than 4 spaces), the resulting code will have inconsistent indentation. Consider using sed 's/.*oh-my-posh init.*/:/ to replace with just a colon, or better yet, preserve the original indentation:

sed 's/\(^[[:space:]]*\).*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"
Suggested change
sed 's/.*oh-my-posh init.*/ :/' "$rc_file" > "$temp_file"
sed 's/^\([[:space:]]*\).*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"

Copilot uses AI. Check for mistakes.
Ross Miles added 2 commits November 24, 2025 16:59
- Add postCreateCommand to run configure-shell.sh
- Implement configure-shell.sh to move config to end of RC files
- Add migration logic for legacy configurations
- Add tests and reproduction scripts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ohmyposh/install.sh
cat >> "$RC_FILE" << EOF

# Oh My Posh configuration
# region Oh My Posh configuration
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The comment marker has been changed from "# Oh My Posh configuration" to "# region Oh My Posh configuration" to support the new migration logic. However, existing users who already have the old marker will end up with both the old configuration block (with "# Oh My Posh configuration") and the new one (with "# region Oh My Posh configuration") since the check on line 146 uses grep -q "oh-my-posh init" which will match the old block and skip adding a new one.

The migration logic in configure-shell.sh is supposed to handle this, but it won't run automatically without a lifecycle hook.

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +72
# Use echo to append to avoid issues with cat and EOF in some environments or if file is empty
echo "" >> "$rc_file"
echo "$start_marker" >> "$rc_file"
echo "if [ -s ~/.ohmyposh.json ]; then" >> "$rc_file"
echo " eval \"\$(oh-my-posh init $shell_name --config ~/.ohmyposh.json)\"" >> "$rc_file"
echo "else" >> "$rc_file"
echo " eval \"\$(oh-my-posh init $shell_name --config jandedobbeleer)\"" >> "$rc_file"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The theme is hardcoded to "jandedobbeleer" in the legacy migration logic, but the feature supports custom themes via the theme option in devcontainer-feature.json. When migrating legacy configurations, users who had configured a custom theme will lose that configuration and get the hardcoded theme instead.

Consider passing the configured theme value to this script (perhaps via an environment variable or config file) and using it instead of the hardcoded value.

Suggested change
# Use echo to append to avoid issues with cat and EOF in some environments or if file is empty
echo "" >> "$rc_file"
echo "$start_marker" >> "$rc_file"
echo "if [ -s ~/.ohmyposh.json ]; then" >> "$rc_file"
echo " eval \"\$(oh-my-posh init $shell_name --config ~/.ohmyposh.json)\"" >> "$rc_file"
echo "else" >> "$rc_file"
echo " eval \"\$(oh-my-posh init $shell_name --config jandedobbeleer)\"" >> "$rc_file"
# Determine theme from environment variable or default to "jandedobbeleer"
local oh_my_posh_theme="${OH_MY_POSH_THEME:-jandedobbeleer}"
# Use echo to append to avoid issues with cat and EOF in some environments or if file is empty
echo "" >> "$rc_file"
echo "$start_marker" >> "$rc_file"
echo "if [ -s ~/.ohmyposh.json ]; then" >> "$rc_file"
echo " eval \"\$(oh-my-posh init $shell_name --config ~/.ohmyposh.json)\"" >> "$rc_file"
echo "else" >> "$rc_file"
echo " eval \"\$(oh-my-posh init $shell_name --config \$oh_my_posh_theme)\"" >> "$rc_file"

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +54
# Replace lines containing "oh-my-posh init" with ":" (no-op) to disable old config
# while preserving syntax validity of surrounding if/else blocks.
sed 's/^\([[:space:]]*\).*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The sed command preserves indentation with \1 but doesn't account for the case where the matched line might be inside a complex if/else/fi block. If the eval line is the only statement in an if/else branch, replacing it with : preserves syntax but leaves behind empty-looking conditional blocks (e.g., if [...]; then :; fi), which could be confusing.

Consider also removing or commenting out the surrounding conditional comments (lines containing "Use custom theme if mounted", "Use built-in theme") to make it clearer that this is a no-op block.

Suggested change
# Replace lines containing "oh-my-posh init" with ":" (no-op) to disable old config
# while preserving syntax validity of surrounding if/else blocks.
sed 's/^\([[:space:]]*\).*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"
# Comment out the entire legacy oh-my-posh block (including comments and conditionals) for clarity.
# This avoids leaving behind confusing empty if/else/fi blocks.
awk '
BEGIN {in_block=0}
/Use custom theme if mounted/ {in_block=1; print "# [oh-my-posh legacy config commented out] " $0; next}
/Use built-in theme/ {if (in_block) {print "# [oh-my-posh legacy config commented out] " $0; next}}
/oh-my-posh init/ {if (in_block) {print "# [oh-my-posh legacy config commented out] " $0; next}}
/fi/ {if (in_block) {print "# [oh-my-posh legacy config commented out] " $0; in_block=0; next}}
{if (in_block) {print "# [oh-my-posh legacy config commented out] " $0} else {print $0}}
' "$rc_file" > "$temp_file"

Copilot uses AI. Check for mistakes.
Comment thread src/ohmyposh/install.sh
Comment on lines +81 to +84
# Install the configure script
HELPER_SCRIPT="/usr/local/bin/oh-my-posh-configure-shell"
cp "$(dirname "$0")/configure-shell.sh" "$HELPER_SCRIPT"
chmod +x "$HELPER_SCRIPT"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The configure-shell.sh script is copied to /usr/local/bin/oh-my-posh-configure-shell, but there's no mechanism to actually invoke it after the feature installation completes. The PR description mentions adding a postCreateCommand hook, but this is not present in the feature configuration.

Without a lifecycle hook or explicit invocation mechanism, this script will never run automatically, meaning the legacy configuration migration and the "ensure prompt loads last" functionality won't work as intended. Users would need to manually run the script.

Copilot uses AI. Check for mistakes.

# Replace lines containing "oh-my-posh init" with ":" (no-op) to disable old config
# while preserving syntax validity of surrounding if/else blocks.
sed 's/^\([[:space:]]*\).*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The regex pattern in sed uses .*oh-my-posh init.* which could match unintended lines. For example, if a user has a comment like # Don't use oh-my-posh init directly, this line would also be replaced with :.

Consider making the pattern more specific to match only actual eval statements, such as:

sed 's/^\([[:space:]]*\)eval.*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"
Suggested change
sed 's/^\([[:space:]]*\).*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"
sed 's/^\([[:space:]]*\)eval.*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"

Copilot uses AI. Check for mistakes.

# Replace lines containing "oh-my-posh init" with ":" (no-op) to disable old config
# while preserving syntax validity of surrounding if/else blocks.
sed 's/^\([[:space:]]*\).*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

Missing error handling for the sed command. If the sed operation fails, the temp file will still be moved over the original RC file (line 57), potentially corrupting the user's configuration.

Consider checking the exit status of sed before moving the temp file, similar to the error handling in the region marker path (lines 26-34).

Suggested change
sed 's/^\([[:space:]]*\).*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"
if ! sed 's/^\([[:space:]]*\).*oh-my-posh init.*/\1:/' "$rc_file" > "$temp_file"; then
echo "Error: Failed to process $rc_file with sed"
rm -f "$temp_file"
return 1
fi

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +48
# We removed lines with "oh-my-posh init" and "# Oh My Posh configuration"
# But we added them back at the end.
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The comment on line 47 states "Check if old config is gone (or at least the comment)" but the actual migration in configure-shell.sh does not remove the old "# Oh My Posh configuration" comment - it only replaces the oh-my-posh init lines with :. This means the old comment will remain, making this test comment misleading.

Consider updating the comment to accurately reflect what the migration does, or update the migration logic to also remove the old comment.

Suggested change
# We removed lines with "oh-my-posh init" and "# Oh My Posh configuration"
# But we added them back at the end.
# We removed lines with "oh-my-posh init" (replaced with ":") but the old "# Oh My Posh configuration" comment may remain.
# But we added the new block (with markers) at the end.

Copilot uses AI. Check for mistakes.
Comment thread justfile
mkdir -p .devcontainer/{{feature}}
cp src/{{feature}}/devcontainer-feature.json .devcontainer/{{feature}}/
cp src/{{feature}}/install.sh .devcontainer/{{feature}}/
cp src/{{feature}}/*.sh .devcontainer/{{feature}}/
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The wildcard copy pattern cp src/{{feature}}/*.sh will fail if there are no .sh files in the directory (in shells without nullglob set), or could inadvertently copy unintended files if additional shell scripts are added to the feature directory in the future.

Consider being more explicit about which files to copy, such as:

cp src/{{feature}}/install.sh src/{{feature}}/configure-shell.sh .devcontainer/{{feature}}/
Suggested change
cp src/{{feature}}/*.sh .devcontainer/{{feature}}/
cp src/{{feature}}/install.sh src/{{feature}}/configure-shell.sh .devcontainer/{{feature}}/

Copilot uses AI. Check for mistakes.
Comment thread test/ohmyposh/test_sed.sh
fi
EOF

sed 's/.*oh-my-posh init.*/ :/' test.sh > test.sh.tmp
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The sed command preserves indentation but the result will have inconsistent indentation. The original code has eval statements indented with 4 spaces inside the if/else block, but after replacement with :, these become lines with just whitespace followed by :. While syntactically correct, this creates odd-looking code.

Consider if this test should verify that the indentation is preserved correctly, or if the migration strategy should be adjusted.

Suggested change
sed 's/.*oh-my-posh init.*/ :/' test.sh > test.sh.tmp
sed 's/^\([[:space:]]*\)oh-my-posh init.*/\1:/' test.sh > test.sh.tmp

Copilot uses AI. Check for mistakes.
Comment thread test/ohmyposh/test_sed.sh
fi
EOF

sed 's/.*oh-my-posh init.*/ :/' test.sh > test.sh.tmp
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The regex pattern .*oh-my-posh init.* could match unintended lines, such as comments that mention "oh-my-posh init". For consistency and safety, consider using a more specific pattern that matches only actual eval statements, as this is a test verifying the migration behavior.

Suggested change
sed 's/.*oh-my-posh init.*/ :/' test.sh > test.sh.tmp
sed 's/^[[:space:]]*eval[[:space:]]*"\$\(oh-my-posh init[^"]*\)"/ :/' test.sh > test.sh.tmp

Copilot uses AI. Check for mistakes.
@rosstaco rosstaco merged commit 6d5a1c8 into main Nov 24, 2025
14 checks passed
@rosstaco rosstaco deleted the fix/ohmyposh/prompt-command-conflict branch November 24, 2025 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants