Skip to content

Commit

Permalink
Add the pulldown options for the WSL shells in the session editor #86
Browse files Browse the repository at this point in the history
  • Loading branch information
sedwards2009 committed May 10, 2018
1 parent f28dd25 commit 0ad3285
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
38 changes: 36 additions & 2 deletions extensions/ProxySessionEditor/src/WslProxySessionEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as _ from 'lodash';
import * as fse from 'fs-extra';
import * as constants from 'constants';
import * as child_process from 'child_process';

import {ExtensionContext, Logger, SessionConfiguration} from 'extraterm-extension-api';
import {WslProxySessionEditorUi} from './WslProxySessionEditorUi';
Expand All @@ -16,11 +17,14 @@ interface WslProxySessionConfiguration extends SessionConfiguration {
shell?: string;
}

let log: Logger = null;

export function getWslProxySessionEditorClass(context: ExtensionContext): any {
const log = context.logger;
log = context.logger;

log.info("WslProxySessionEditorExtension activate");

readEtcShellsSpawn();

class WslProxySessionEditor extends context.workspace.extensionSessionEditorBaseConstructor {
private _ui: WslProxySessionEditorUi = null;
private _debouncedDataChanged: ()=> void = null;
Expand Down Expand Up @@ -59,6 +63,7 @@ export function getWslProxySessionEditorClass(context: ExtensionContext): any {
this._ui.name = fixedConfig.name;
this._ui.useDefaultShell = fixedConfig.useDefaultShell ? 1 :0;
this._ui.shell = fixedConfig.shell;
this._ui.etcShells = [...etcShells];
}

_dataChanged(): void {
Expand Down Expand Up @@ -108,3 +113,32 @@ export function getWslProxySessionEditorClass(context: ExtensionContext): any {

return WslProxySessionEditor;
}

let etcShells: string[] = [];

function readEtcShellsSpawn(): void {
// For some reason child_process.exec() doesn't want to work properly on Windows.
// spawn still does though, but it is a bit more fiddly to use.

const wslProcess = child_process.spawn("wsl.exe", ["cat", "/etc/shells"], {shell: false, stdio: 'pipe'});

let text = "";
wslProcess.stdout.on("data", data => {
text += data;
});
wslProcess.on("exit", (msg) => {
etcShells = splitEtcShells(text);
});
wslProcess.stdin.end();
}

function splitEtcShells(shellText: string): string[] {
const lines = shellText.split("\n");
const result: string[] = [];
for (const line of lines) {
if ( ! line.startsWith("#") && line.trim() !== "") {
result.push(line);
}
}
return result;
}
6 changes: 5 additions & 1 deletion extensions/ProxySessionEditor/src/WslProxySessionEditorUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import Vue from 'vue';
<div class="input-group col-sm-8 form-inline" v-bind:class="{'has-error': shellErrorMsg != ''}">
<input class="input-radio" type="radio" value="0" v-model.number="useDefaultShell">
<div class="inline-text">Other</div>
<input id="other_shell" type="text" class="form-control" :disabled="useDefaultShell===1" v-model="shell">
<input id="other_shell" type="text" class="form-control" :disabled="useDefaultShell===1" v-model="shell" list="etcShells">
<div v-if="shellErrorMsg != ''" class="text-center"><i class="fas fa-exclamation-triangle"></i> {{ shellErrorMsg }}</div>
<datalist id="etcShells">
<option v-for="item in etcShells" :value="item"></option>
</datalist>
</div>
</div>
</div>
Expand All @@ -41,4 +44,5 @@ export class WslProxySessionEditorUi extends Vue {
shell: string = "";
useDefaultShell: number = 1;
shellErrorMsg = "";
etcShells = [];
}

0 comments on commit 0ad3285

Please sign in to comment.