Skip to content
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

Add Windows Terminal to Shell Plugins #3225

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

Azakidev
Copy link

@Azakidev Azakidev commented Feb 4, 2025

Hi!

I left a comment couple of comments on #2045, but I decided to add the changes myself in my own pull request since the original one was rather old

I've never worked in a C# or windows project before, so please excuse if I messed something up in the process
I've built it and it seems to just work, which is a win in my books.

Hope it helps!

It is a much simpler fix compared to #1116, but it gets the job done

@prlabeler prlabeler bot added the bug Something isn't working label Feb 4, 2025

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new property UseWindowsTerminal in the Settings class and modify the PrepareProcessStartInfo method in the Main class to allow command execution via Windows Terminal. The UI is updated to include a checkbox for this setting, and localization support is added for both English and Spanish. The command execution logic is enhanced to handle individual arguments more effectively, maintaining backward compatibility with existing shell options.

Changes

File(s) Change Summary
Plugins/Flow.Launcher.Plugin.Shell/Main.cs Updated PrepareProcessStartInfo to conditionally set FileName to wt.exe based on _settings.UseWindowsTerminal, modifying argument handling to use ArgumentList.
Plugins/Flow.Launcher.Plugin.Shell/Settings.cs Added a new property public bool UseWindowsTerminal { get; set; } = false;.
Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml Added a new CheckBox for "Use Windows Terminal" and adjusted layout of existing UI elements.
Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs Introduced event handlers for the new checkbox to update _settings.UseWindowsTerminal.
Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml Added string resource for "Use Windows Terminal".
Plugins/Flow.Launcher.Plugin.Shell/Languages/es-419.xaml Added Spanish string resource for "Ejecutar en la Terminal de Windows".
Plugins/Flow.Launcher.Plugin.Shell/Languages/es.xaml Added Spanish string resource for "Ejecutar en la Terminal de Windows".

Suggested labels

kind/ui, Explorer Plugin, kind/i18n

Suggested reviewers

  • jjw24

Poem

I'm a bouncy rabbit full of cheer,
Stepping into terminals far and near.
PowerShell and CMD, now part of my run,
With wt.exe, command fun has begun!
Hopping through code with a joyful dash,
New shells make my circuits splash! 🐇✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
Plugins/Flow.Launcher.Plugin.Shell/Main.cs (1)

282-308: Implementation looks good but needs additional error handling.

The Windows Terminal integration is well-implemented, following proper command-line conventions for both PowerShell and CMD scenarios.

Consider these improvements:

  1. Verify wt.exe existence before execution
  2. Add specific error handling for Windows Terminal scenarios

Add this verification before the Windows Terminal cases:

 case Shell.TerminalPWSH:
 {
+    if (!ExistInPath("wt.exe"))
+    {
+        throw new FileNotFoundException("Windows Terminal (wt.exe) is not installed.");
+    }
     info.FileName = "wt.exe";
     // ... rest of the code
 }
 case Shell.TerminalCMD:
 {
+    if (!ExistInPath("wt.exe"))
+    {
+        throw new FileNotFoundException("Windows Terminal (wt.exe) is not installed.");
+    }
     info.FileName = "wt.exe";
     // ... rest of the code
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6cf7674 and 3596a77.

📒 Files selected for processing (4)
  • Plugins/Flow.Launcher.Plugin.Shell/Main.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Shell/Settings.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs (2 hunks)
👮 Files not reviewed due to content moderation or server errors (4)
  • Plugins/Flow.Launcher.Plugin.Shell/Settings.cs
  • Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml
  • Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs
  • Plugins/Flow.Launcher.Plugin.Shell/Main.cs
🔇 Additional comments (7)
Plugins/Flow.Launcher.Plugin.Shell/Settings.cs (3)

42-43: LGTM! Enum values are properly defined.

The new enum values for Windows Terminal integration follow consistent naming patterns and are correctly sequenced.


42-43: LGTM! Enum values are well-defined.

The new enum values for Windows Terminal integration follow consistent naming conventions and are properly ordered.


42-43: LGTM! Enum values are properly defined.

The new shell types for Windows Terminal are correctly added with unique values and follow the existing naming convention.

Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs (3)

94-95: LGTM! Selection logic is properly implemented.

The selection handling for new Terminal options is correctly implemented and maintains consistency with existing shell options.

Also applies to: 106-107


94-95: LGTM! Selection logic properly handles new terminal options.

The switch expressions are correctly updated to handle the new Windows Terminal options while maintaining existing functionality.

Also applies to: 106-107


94-95: LGTM! Selection logic is properly implemented.

The selection handling for Windows Terminal options is correctly integrated in both the initial selection and change event handlers.

Also applies to: 106-107

Plugins/Flow.Launcher.Plugin.Shell/Main.cs (1)

282-308: Verify Windows Terminal command-line compatibility.

Let's confirm the command-line argument syntax for Windows Terminal.

✅ Verification successful

🌐 Web query:

What are the supported command-line arguments for Windows Terminal?

Length of output: 5531


Windows Terminal Command-Line Arguments Are Compatible

  • The implementation uses wt.exe with shell identifiers (pwsh for PowerShell and cmd for Command Prompt), which is in line with Windows Terminal’s flexible argument parsing.
  • For PowerShell, using -Command with an optional -NoExit flag (when leaving the shell open) matches PowerShell’s standard argument scheme.
  • For CMD, the use of /c (to close after execution) and /k (to keep the shell open) is consistent with CMD’s typical behavior.
  • According to official documentation and external guides, Windows Terminal supports these patterns when launching specific shells.

Comment on lines 282 to 308
case Shell.TerminalPWSH:
{
info.FileName = "wt.exe";
info.ArgumentList.Add("pwsh");
if (_settings.LeaveShellOpen)
{
info.ArgumentList.Add("-NoExit");
}
info.ArgumentList.Add("-Command");
info.ArgumentList.Add(command);
break;
}
case Shell.TerminalCMD:
{
info.FileName = "wt.exe";
info.ArgumentList.Add("cmd");
if (_settings.LeaveShellOpen)
{
info.ArgumentList.Add("/k");
}
else
{
info.ArgumentList.Add("/c");
}
info.ArgumentList.Add(command);
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify Windows Terminal availability.

The code assumes wt.exe is available but doesn't handle cases where Windows Terminal isn't installed.

Run this script to check how the code handles missing Windows Terminal:

Consider implementing CloseShellAfterPress behavior.

The new Terminal cases don't implement the CloseShellAfterPress behavior that's available for other shells.

Consider adding the pause behavior similar to other shells:

 case Shell.TerminalPWSH:
 {
     info.FileName = "wt.exe";
     info.ArgumentList.Add("pwsh");
     if (_settings.LeaveShellOpen)
     {
         info.ArgumentList.Add("-NoExit");
     }
     info.ArgumentList.Add("-Command");
-    info.ArgumentList.Add(command);
+    info.ArgumentList.Add($"{command}; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'; [System.Console]::ReadKey(); exit" : "")}");
     break;
 }
 case Shell.TerminalCMD:
 {
     info.FileName = "wt.exe";
     info.ArgumentList.Add("cmd");
     if (_settings.LeaveShellOpen)
     {
         info.ArgumentList.Add("/k");
     }
     else
     {
         info.ArgumentList.Add("/c");
     }
-    info.ArgumentList.Add(command);
+    info.ArgumentList.Add($"{command} {(_settings.CloseShellAfterPress ? $"&& echo {context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")} && pause > nul" : "")}");
     break;
 }

🏁 Script executed:

#!/bin/bash
# Search for error handling related to wt.exe
rg -A 5 "wt\.exe" 
rg -A 5 "FileNotFoundException"

Length of output: 10564

Issues Detected in Windows Terminal Handling

  • The code unconditionally uses wt.exe without explicitly checking for its presence. Although a generic FileNotFoundException is caught later, there is no proactive verification or more graceful handling if Windows Terminal isn’t installed.
  • The new cases for TerminalPWSH and TerminalCMD lack implementation for the CloseShellAfterPress behavior, which is otherwise available for other shell types.

💡 Verification agent

🧩 Analysis chain

Verify Windows Terminal installation.

Let's check if Windows Terminal is properly installed in the system.


🏁 Script executed:

#!/bin/bash
# Description: Check if Windows Terminal is installed by searching for wt.exe in PATH

# Test: Search for wt.exe in common installation paths
echo "Checking for Windows Terminal installation..."
rg -l "wt\.exe" 

Length of output: 161

Action Required: Add a Runtime Check for Windows Terminal Availability

The current implementation simply hardcodes the use of "wt.exe" without verifying if Windows Terminal is installed on the system. The shell script output only confirms that the string "wt.exe" appears in the code (in Plugins/Flow.Launcher.Plugin.Shell/Main.cs), but it does not verify that Windows Terminal is actually available at runtime.

• The code in Plugins/Flow.Launcher.Plugin.Shell/Main.cs uses "wt.exe" to launch Windows Terminal without checking for its existence, which could lead to failures on systems where Windows Terminal is not installed.

Please add a runtime check (for example, using Windows system API calls or checking the system PATH) to verify the availability of "wt.exe" before attempting to launch it.


💡 Verification agent

🧩 Analysis chain

LGTM! Windows Terminal integration is well implemented.

The implementation correctly handles both PowerShell and CMD execution through Windows Terminal.

However, we should verify that Windows Terminal is available before attempting to use it. Run this script to check for Windows Terminal availability:

Consider adding a check for Windows Terminal availability and appropriate error handling:

 case Shell.TerminalPWSH:
 {
+    if (!ExistInPath("wt.exe"))
+    {
+        throw new FileNotFoundException("Windows Terminal (wt.exe) is not installed");
+    }
     info.FileName = "wt.exe";
     info.ArgumentList.Add("pwsh");

🏁 Script executed:

#!/bin/bash
# Description: Check if Windows Terminal is available in the system

# Search for wt.exe in the PATH
rg -l "where.*wt\.exe" || echo "No existing checks for wt.exe found"

# Search for any Windows Terminal related error handling
rg -l "WindowsTerminal|wt\.exe.*not.*found" || echo "No existing error handling for Windows Terminal found"

Length of output: 268

Windows Terminal Availability Check is Missing

The integration works as intended for both PowerShell and CMD, but our check confirms there’s no verification for the existence of wt.exe. This could lead to runtime failures if Windows Terminal is not installed.

  • Location: Plugins/Flow.Launcher.Plugin.Shell/Main.cs (lines 282–308)
  • Issue: No error handling or pre-execution check to verify that wt.exe exists in the system’s PATH.
  • Recommendation: Add a check (e.g., using a helper function like ExistInPath("wt.exe")) and throw a descriptive exception if wt.exe is not available.

Copy link

github-actions bot commented Feb 5, 2025

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 22
⚠️ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3596a77 and 5bb3d72.

📒 Files selected for processing (7)
  • Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Shell/Languages/es-419.xaml (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Shell/Languages/es.xaml (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Shell/Main.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Shell/Settings.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • Plugins/Flow.Launcher.Plugin.Shell/Settings.cs
  • Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs
  • Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml
  • Plugins/Flow.Launcher.Plugin.Shell/Main.cs
🔇 Additional comments (2)
Plugins/Flow.Launcher.Plugin.Shell/Languages/es-419.xaml (1)

9-9: LGTM!

The translation is accurate and the resource key is consistent with other Spanish language files.

Plugins/Flow.Launcher.Plugin.Shell/Languages/es.xaml (1)

9-9: LGTM!

The translation is accurate and the resource key is consistent with other Spanish language files.

@Azakidev
Copy link
Author

Azakidev commented Feb 5, 2025

I was left unsatisfied by my work of yesterday, so I switched things around a little bit, using a checkbox for using the windows terminal instead of separate entries in the combobox
image

I'm not quite sure how the different language localization works, but I did add English and Spanish strings, which are the languages I know

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for those translations. However, language files other than English need to be added by Crowdin. So you have to revert all changes in those files...

@Jack251970 Jack251970 added enhancement New feature or request and removed bug Something isn't working labels Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants