Add Custom Template shell option to Shell plugin #4580
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughAdds a ChangesCustom template shell
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant ShellSetting
participant Settings
participant Main
participant ProcessStartInfo
User->>ShellSetting: select CustomTemplate and configure fields
ShellSetting->>Settings: store executable path and argument template
Settings->>Main: provide CustomTemplateShellConfig
Main->>ProcessStartInfo: set executable and substituted arguments
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
Flow.Launcher.Test/Plugins/ShellPluginTest.cs (1)
308-356: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd
Shell.CustomTemplateto common test cases.To ensure the new custom template behavior is fully validated against standard shell baselines (like setting the correct working directory and
UseShellExecuteflag), consider adding[TestCase(Shell.CustomTemplate)]to the shared common tests.💡 Proposed change
[TestCase(Shell.Cmd)] [TestCase(Shell.Powershell)] [TestCase(Shell.Pwsh)] [TestCase(Shell.RunCommand)] + [TestCase(Shell.CustomTemplate)] public void SetsWorkingDirectory(Shell shell) { var info = Create(shell: shell); var expected = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); Assert.That(info.WorkingDirectory, Is.EqualTo(expected)); } [TestCase(Shell.Cmd)] [TestCase(Shell.Powershell)] [TestCase(Shell.Pwsh)] [TestCase(Shell.RunCommand)] + [TestCase(Shell.CustomTemplate)] public void SetsUseShellExecute(Shell shell) { var info = Create(shell: shell); Assert.That(info.UseShellExecute, Is.True); } [TestCase(Shell.Cmd)] [TestCase(Shell.Powershell)] [TestCase(Shell.Pwsh)] [TestCase(Shell.RunCommand)] + [TestCase(Shell.CustomTemplate)] public void ExpandsEnvironmentVariables(Shell shell) { var info = Create( command: "%USERPROFILE%\\test", shell: shell); var expandedPath = Environment.ExpandEnvironmentVariables("%USERPROFILE%\\test"); switch (shell) { case Shell.Cmd: Assert.That(info.Arguments, Is.EqualTo($"/c {expandedPath}")); break; case Shell.Powershell: case Shell.Pwsh: Assert.That(info.ArgumentList, Does.Contain(expandedPath + ";")); break; case Shell.RunCommand: + case Shell.CustomTemplate: Assert.That(info.FileName, Is.EqualTo(expandedPath)); break; } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Flow.Launcher.Test/Plugins/ShellPluginTest.cs` around lines 308 - 356, Add [TestCase(Shell.CustomTemplate)] to the shared SetsWorkingDirectory, SetsUseShellExecute, and ExpandsEnvironmentVariables tests so the custom template follows the same baseline assertions as the other shell values. Preserve the existing test setup and assertions.Plugins/Flow.Launcher.Plugin.Shell/Main.cs (1)
450-456: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winExpand environment variables for custom paths and templates.
Users often rely on environment variables like
%LOCALAPPDATA%or%ProgramFiles%to define executable paths, especially for apps installed in user directories or portable setups. To provide feature parity with how commands are treated elsewhere in the plugin, consider expanding environment variables in the configuration strings.💡 Proposed change
- info.FileName = config.ExecutablePath; + info.FileName = Environment.ExpandEnvironmentVariables(config.ExecutablePath); var template = string.IsNullOrEmpty(config.ArgumentsTemplate) ? "{command}" - : config.ArgumentsTemplate; + : Environment.ExpandEnvironmentVariables(config.ArgumentsTemplate); info.Arguments = template.Replace("{command}", command);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Plugins/Flow.Launcher.Plugin.Shell/Main.cs` around lines 450 - 456, Expand environment variables in the configured executable path and arguments template before assigning them in the command setup flow. Update the logic around config.ExecutablePath, config.ArgumentsTemplate, and template so both custom configuration strings support variables such as %LOCALAPPDATA% while preserving the existing default "{command}" behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Plugins/Flow.Launcher.Plugin.Shell/Settings.cs`:
- Around line 145-150: Update CustomTemplateShellConfig to inherit BaseModel and
make ExecutablePath and ArgumentsTemplate observable by raising
OnPropertyChanged in their setters, so programmatic changes such as
BrowseExecutablePath_Click refresh the bound UI controls.
---
Nitpick comments:
In `@Flow.Launcher.Test/Plugins/ShellPluginTest.cs`:
- Around line 308-356: Add [TestCase(Shell.CustomTemplate)] to the shared
SetsWorkingDirectory, SetsUseShellExecute, and ExpandsEnvironmentVariables tests
so the custom template follows the same baseline assertions as the other shell
values. Preserve the existing test setup and assertions.
In `@Plugins/Flow.Launcher.Plugin.Shell/Main.cs`:
- Around line 450-456: Expand environment variables in the configured executable
path and arguments template before assigning them in the command setup flow.
Update the logic around config.ExecutablePath, config.ArgumentsTemplate, and
template so both custom configuration strings support variables such as
%LOCALAPPDATA% while preserving the existing default "{command}" behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aae87e58-bdb7-47ab-8a99-4dc1f541b199
📒 Files selected for processing (8)
Flow.Launcher.Test/Plugins/ShellPluginTest.csPlugins/Flow.Launcher.Plugin.Shell/Converters/LeaveShellOpenOrCloseShellAfterPressEnabledConverter.csPlugins/Flow.Launcher.Plugin.Shell/Languages/en.xamlPlugins/Flow.Launcher.Plugin.Shell/Main.csPlugins/Flow.Launcher.Plugin.Shell/Settings.csPlugins/Flow.Launcher.Plugin.Shell/ViewModels/ShellSettingViewModel.csPlugins/Flow.Launcher.Plugin.Shell/Views/ShellSetting.xamlPlugins/Flow.Launcher.Plugin.Shell/Views/ShellSetting.xaml.cs
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
a34f902 to
393aa16
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Plugins/Flow.Launcher.Plugin.Shell/Main.cs`:
- Around line 450-456: Update the custom configuration handling near the
ProcessStartInfo assignments to expand environment variables in
config.ExecutablePath and config.ArgumentsTemplate, then trim the executable
path and remove surrounding quotes before assigning info.FileName. Apply the
same variable expansion to the arguments template before replacing {command},
preserving the existing default template behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 563c3bb9-9fff-4584-81c2-fba14fed6c24
📒 Files selected for processing (8)
Flow.Launcher.Test/Plugins/ShellPluginTest.csPlugins/Flow.Launcher.Plugin.Shell/Converters/LeaveShellOpenOrCloseShellAfterPressEnabledConverter.csPlugins/Flow.Launcher.Plugin.Shell/Languages/en.xamlPlugins/Flow.Launcher.Plugin.Shell/Main.csPlugins/Flow.Launcher.Plugin.Shell/Settings.csPlugins/Flow.Launcher.Plugin.Shell/ViewModels/ShellSettingViewModel.csPlugins/Flow.Launcher.Plugin.Shell/Views/ShellSetting.xamlPlugins/Flow.Launcher.Plugin.Shell/Views/ShellSetting.xaml.cs
🚧 Files skipped from review as they are similar to previous changes (6)
- Plugins/Flow.Launcher.Plugin.Shell/Converters/LeaveShellOpenOrCloseShellAfterPressEnabledConverter.cs
- Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml
- Plugins/Flow.Launcher.Plugin.Shell/Settings.cs
- Plugins/Flow.Launcher.Plugin.Shell/Views/ShellSetting.xaml.cs
- Plugins/Flow.Launcher.Plugin.Shell/ViewModels/ShellSettingViewModel.cs
- Plugins/Flow.Launcher.Plugin.Shell/Views/ShellSetting.xaml
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Adds a "Custom Template" entry to the shell selection dropdown. Users can provide any executable path and an arguments template using {command} as a placeholder. Falls back to RunCommand behavior when no executable path is configured.
Leave Shell Open, Close After Press, and Use Windows Terminal checkboxes are disabled for Custom Template - the user has to manually implement those
Use Windows Terminal is also now correctly disabled for RunCommand, which never supported it.
…shell configuration
393aa16 to
3e16478
Compare
There was a problem hiding this comment.
2 issues found across 8 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="Plugins/Flow.Launcher.Plugin.Shell/Main.cs">
<violation number="1" location="Plugins/Flow.Launcher.Plugin.Shell/Main.cs:443">
P2: A custom executable path that expands to empty fails instead of falling back to RunCommand. Normalize the expanded path before deciding whether configuration is present.</violation>
<violation number="2" location="Plugins/Flow.Launcher.Plugin.Shell/Main.cs:452">
P2: A template that expands to whitespace runs the custom executable without the command. Apply the empty-template fallback after environment-variable expansion.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| var template = string.IsNullOrWhiteSpace(config.ArgumentsTemplate) | ||
| ? "{command}" | ||
| : Environment.ExpandEnvironmentVariables(config.ArgumentsTemplate).Trim(); |
There was a problem hiding this comment.
P2: A template that expands to whitespace runs the custom executable without the command. Apply the empty-template fallback after environment-variable expansion.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Plugins/Flow.Launcher.Plugin.Shell/Main.cs, line 452:
<comment>A template that expands to whitespace runs the custom executable without the command. Apply the empty-template fallback after environment-variable expansion.</comment>
<file context>
@@ -426,6 +435,27 @@ private static void ConfigureRunCommandStartInfo(
+
+ info.FileName = Environment.ExpandEnvironmentVariables(config.ExecutablePath).Trim().Trim('"');;
+
+ var template = string.IsNullOrWhiteSpace(config.ArgumentsTemplate)
+ ? "{command}"
+ : Environment.ExpandEnvironmentVariables(config.ArgumentsTemplate).Trim();
</file context>
| var template = string.IsNullOrWhiteSpace(config.ArgumentsTemplate) | |
| ? "{command}" | |
| : Environment.ExpandEnvironmentVariables(config.ArgumentsTemplate).Trim(); | |
| var template = config.ArgumentsTemplate is null | |
| ? string.Empty | |
| : Environment.ExpandEnvironmentVariables(config.ArgumentsTemplate).Trim(); | |
| if (string.IsNullOrWhiteSpace(template)) | |
| template = "{command}"; |
| string command, | ||
| CustomTemplateShellConfig config) | ||
| { | ||
| if (config == null || string.IsNullOrWhiteSpace(config.ExecutablePath)) |
There was a problem hiding this comment.
P2: A custom executable path that expands to empty fails instead of falling back to RunCommand. Normalize the expanded path before deciding whether configuration is present.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Plugins/Flow.Launcher.Plugin.Shell/Main.cs, line 443:
<comment>A custom executable path that expands to empty fails instead of falling back to RunCommand. Normalize the expanded path before deciding whether configuration is present.</comment>
<file context>
@@ -426,6 +435,27 @@ private static void ConfigureRunCommandStartInfo(
+ string command,
+ CustomTemplateShellConfig config)
+ {
+ if (config == null || string.IsNullOrWhiteSpace(config.ExecutablePath))
+ {
+ // No valid custom shell configured, fall back to RunCommand behavior
</file context>
Adds a "Custom Template" entry to the shell selection dropdown.
Should resolve #187 - users can fully control shell configuration with this.
Users can provide any executable path and an arguments template using {command} as a placeholder. Falls back to RunCommand behavior when no executable path is set.
Browse button calls OpenFileDialog for executable file path.
Leave Shell Open, Close After Press, and Use Windows Terminal settings are disabled for Custom Template - the user has to manually implement those.
Use Windows Terminal is also now correctly disabled for RunCommand, which never supported it.
Summary by cubic
Adds a Custom Template shell so users can run commands with any executable and a simple {command} template. Falls back to RunCommand when no executable is set and disables incompatible options.
Summary of changes
RunCommandandCustom Template. Disabled "Leave Shell Open" and "Close After Press" forCustom Template. Settings UI shows Custom Template fields only when selected.Shell.CustomTemplatewithSettings.CustomTemplateShellConfig(ExecutablePath, ArgumentsTemplate defaulting to "{command}"). Process creation supports Custom Template: expands env vars in exe path and template, trims and strips quotes from exe path, replaces{command}, and defaults empty/whitespace template to "{command}". Added Browse dialog for the executable path and new localization strings.RunCommand(now correctly hidden/disabled).RunCommand. Users can choose any executable; no new elevation paths beyond existing "Run as Admin."RunCommand, whitespace/trim handling, quote stripping, env var expansion (path and template), working directory,UseShellExecute, and admin verb.Release Note
You can now pick any terminal or app to run commands using a simple template, with a browse button to select the executable.
Written for commit 3e16478. Summary will update on new commits.