-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 isWsl
flag to session/action objects
#3046
Conversation
The `isWsl` flag denotes if the running shell is a Windows Subsystem for Linux (WSL) shell by pattern matching the user configurable `shell` property. This flag has support for invoking WSL with multiple executables: - bash.exe - debian.exe - kali.exe - opensuse.exe - ubuntu.exe - wsl.exe
app/ui/window.js
Outdated
@@ -93,6 +93,7 @@ module.exports = class Window { | |||
cwd: process.argv[1] && isAbsolute(process.argv[1]) ? process.argv[1] : cfgDir, | |||
splitDirection: undefined, | |||
shell: cfg.shell, | |||
isWsl: /(?:bash|debian|kali|opensuse|ubuntu|wsl)\.exe$/.test(cfg.shell), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there is also ubuntu1804.exe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must admit I added these by intuition because I couldn't find a document with all the distros exectuables. I only use Debian myself. I'll add that version to the list soon.
However, as the number of distros may grow and some of them may have multiple executables (case in point), a regex is probably not the best approach. But I honestly can't think of another way to detect if Hyper is running a WSL shell.
Any other ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes actually 😄
I only know about that exe because I recently did something very similar in vscode. Check out the list I came up with https://github.com/Microsoft/vscode/blob/86adb527f12c12c1c04806cfa0cd435f98475a6f/src/vs/workbench/parts/terminal/node/windowsShellHelper.ts#L13 (which also includes powershell and cmd, everything else is wsl).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on your list, I guess I have a couple of entries to fix 😄
I might follow your approach instead of regex, it will be easier to maintain in the long run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tyriar Changed the implementation, could you please re-review? I've also took the liberty of using path.sep
instead of the hard-coded /
in one other instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the code base too well so can't give a full review, the list of exes looks good though 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me neither, I'm just digging through code and making small changes here and there 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would invert the way WSL is detected to be easier to maintain
'debian.exe', | ||
'opensuse-42.exe', | ||
'sles-12.exe' | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you transform this into something like:
const WIN_SHELLL_EXECUTABLES = [
'cmd.exe',
'powershell.exe'
]
function isWslShell(shell) {
return process.platform === 'win32' && !WIN_SHELL_EXECUTABLES.indexOf(shell.split(path.sep).pop()) !== -1;
}
Be careful with empty/missing shell config.
It would be easier to maintain like @Tyriar suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, there are many other non-WSL shells: git bash, python, gchi, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, either we have a full list for valid WSL shells, or non-WSL shells. Since the function is called isWslShell
and the property is isWsl
, I think it makes more sense to have a list of valid WSL shells. Let me know how you want me to proceed @chabou.
I'll handle the empty/missing shell configuration though :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, you're right.
But, in this case, it will take some effort to keep this list up to date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might, it all depends on how frequent new Linux distros are going to be supported by WSL and if any of them will include different exes than the default ones. But I honestly can't think of any other way to detect if the active/running shell is WSL or not. If you have a suggestion, I'm all hears :)
Can you give some examples of plugins that need to know if current shell is running WSL or not? |
@chabou Plugins like To give a more in-depth context, lets use This plugin opens new tabs with the same directory as the current tab in Hyper. It does this by reading the current tab directory with The Windows technique does not work for WSL because it's a Linux prompt with color codes in the mix and one could always be using a prompt configuration to show a relative path, for instance. You can't also rely on In other words, WSL needs special handling and |
@chabou What do you think of the current implementation? Could we get this merged? It would help immensely to have this implemented so I could start working on fixing some plugins WSL issues. |
@@ -41,7 +43,8 @@ const reducer = (state = initialState, action) => { | |||
cols: action.cols, | |||
rows: action.rows, | |||
uid: action.uid, | |||
shell: action.shell.split('/').pop(), | |||
shell: action.shell.split(path.sep).pop(), | |||
isWsl: action.isWsl, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you determine if this is a WSL shell here?
This is better to let plugins modify the action.shell
value (in a middleware for example). In this case, this is better to call isWslShell
later in the reducer than in the action creator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be sure, are you suggesting I change this to isWsl: isWslShell(action.shell)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
This is a derivated data and derivation should occur in the reducer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chabou There's a little problem with that I'm not sure how to handle given that I don't know the code base so well. The isWsl
function was created as an app
util function and this reducer is inside the lib
folder. I'm not sure I can/should import stuff from app
into lib
(and vice-versa for that matter). How should I proceed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to move app/utils/wsl.js
to lib/utils/wsl.js
or move your function directly into lib/reducers/sessions.js
because your function will not be used anywhere else.
according to microsoft/WSL#2715 (comment), |
@rfgamaral : any updates on this thread/PR? |
Instead of hardcoding exe names, could we do something like this instead? microsoft/terminal#1050 |
The
isWsl
flag denotes if the running shell is a Windows Subsystem for Linux (WSL) shell by pattern matching the user configurableshell
property.This flag has support for invoking WSL with multiple executables:
bash.exe
debian.exe
kali.exe
opensuse.exe
ubuntu.exe
wsl.exe
I'm not sure if this is something you guys want to add to Hyper core but it's just a small flag to help plugin developers easily know if the running shell is WSL or not, just like they currently need to know if the host OS is Windows and Linux (provided by
process.platform
) to properly do their plugin magic. This will come in handy to better support WSL within plugins.Let me know if you have any questions or a better idea to implement this.