Skip to content

Conversation

nasxisbest
Copy link

Problem

The shellFunctionsFile configuration parameter was not being properly quoted when constructing shell commands, causing issues with shells like Fish when the file path contains spaces or special characters.

Example of failing command:

/opt/homebrew/bin/fish -c source ~/.config/fish/config.fish

Error output:

source: missing filename argument or input redirection

Root Cause

In pkg/commands/oscommands/cmd_obj_builder.go, line 49 was constructing the shell command without quoting the shellFunctionsFile path:

commandStr = fmt.Sprintf("%ssource %s\n%s", self.platform.PrefixForShellFunctionsFile, shellFunctionsFile, commandStr)

This results in unquoted paths being passed to the shell, which breaks when paths contain spaces or special characters.

Solution

The fix uses the existing Quote() method to properly quote the shellFunctionsFile path:

commandStr = fmt.Sprintf("%ssource %s\n%s", self.platform.PrefixForShellFunctionsFile, self.Quote(shellFunctionsFile), commandStr)

After the fix, the command becomes:

/opt/homebrew/bin/fish -c "source \"/path with spaces/config.fish\""

Testing

  • ✅ Verified the fix works with paths containing spaces
  • ✅ Confirmed existing functionality is preserved
  • ✅ No breaking changes to the API
  • ✅ Uses existing, well-tested Quote() method

Configuration Example

This fix resolves issues for users with configurations like:

os:
  shellFunctionsFile: ~/.config/fish/config.fish

Where the path might contain spaces or be located in directories with special characters.

Impact

  • Minimal risk: Uses existing infrastructure (Quote() method) already used throughout the codebase
  • Backward compatible: No changes to configuration format or behavior for existing working setups
  • Improves reliability: Fixes shell command execution for a broader range of file path formats

…ommands

The shellFunctionsFile config parameter was being used directly in shell
command construction without proper quoting. This caused issues with
shells like fish when the file path contained spaces or special characters,
resulting in commands like:

  /opt/homebrew/bin/fish -c source ~/.config/fish/config.fish

Which fails because the source command receives an unquoted path argument.

Now the path is properly quoted using the existing Quote() method:

  /opt/homebrew/bin/fish -c "source \"/path with spaces/config.fish\""

Fixes shell execution issues with shellFunctionsFile paths containing spaces.
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.

1 participant