feat(REPL): Make shell command handling extensible via dispatch; add Nushell #58523
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
See #58525 for an alternative approach.
This PR cleans up the branching over shells for better extensibility and maintainability. It also adds a more compatible interface with nushell. This is an alternative to #58413 by @sandyspiers and supersedes it (if desired). Also supersedes #58518.
Fixes #54291.
It introduces a function
prepare_shell_commandwhich dispatches on a structShellSpecification{is_windows, shell_sym}. This is a bit cleaner than the manual handling ofif !Sys.iswindows()andif shell_name == "fish". It also allows users to customize REPL logic for new shells, should they wish to. This addresses the issue I had with #54291 where there was simply no way to customize the REPL shell command handling. Now, the next time a user wants to interface with their shell, they can just overload(Another idea I had was passing the full
Sys.KERNELas the third type parameter, for customizations on other OSes. I thought it probably wasn't needed though.)Note that
repl_cmdnow receives the raw command string as the second argument. This also means Nushell, which takes the raw string, can correctly handle pipes (e.g.,ls | sort-by name).Here's the main logic of this change:
Another design I considered was having a dictionary
SHELL_COMMANDSbut I thought the method dispatch version was ultimately cleaner and more extensible.If you want to try this without re-compiling Julia, here's some code you can put in your startup.jl. (This code also works on 1.11 so this lets you use nushell on stable Julia!)
Code: (click me)