<commit_before>/*
 * Copyright (C) 2017 TypeFox and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 */

import { openSocket } from '../../messaging/node';
import { BackendApplicationContribution } from '../../application/node';
import { getRootDir } from '../../filesystem/node/filesystem-server-module';
import * as express from 'express';
import * as http from 'http';
import { ContainerModule, injectable } from 'inversify';
import URI from "../../application/common/uri";

const pty = require("node-pty")

export default new ContainerModule(bind => {
    bind(BackendApplicationContribution).to(TerminalExpressContribution)
})

@injectable()
class TerminalExpressContribution implements BackendApplicationContribution {
    private terminals: Map<number, any> = new Map()

    configure(app: express.Application): void {
        app.post('/terminals', (req, res) => {
            let cols = parseInt(req.query.cols, 10),
                rows = parseInt(req.query.rows, 10),
                term = pty.spawn(process.platform === 'win32' ? 'cmd.exe' : 'bash', [], {
                    name: 'xterm-color',
                    cols: cols || 80,
                    rows: rows || 24,
                    cwd: process.env.PWD,
                    env: process.env
                })
            term.write(`cd ${getRootDir()} && `)
            term.write("source ~/.profile\n")

            this.terminals.set(term.pid, term)
            res.send(term.pid.toString());
            res.end();
        });
<commit_msg>Find the user's prefered shell rather than defaulting to bash<commit_after>/*
 * Copyright (C) 2017 TypeFox and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 */

import { openSocket } from '../../messaging/node';
import { BackendApplicationContribution } from '../../application/node';
import { getRootDir } from '../../filesystem/node/filesystem-server-module';
import * as express from 'express';
import * as http from 'http';
import { ContainerModule, injectable } from 'inversify';
import URI from "../../application/common/uri";
import { isWindows } from "../../application/common/os";

const pty = require("node-pty")

export default new ContainerModule(bind => {
    bind(BackendApplicationContribution).to(TerminalExpressContribution)
})

@injectable()
class TerminalExpressContribution implements BackendApplicationContribution {
    private terminals: Map<number, any> = new Map()

    private getShellExecutablePath(): string {
        if (isWindows) {
            return 'cmd.exe';
        } else {
            return process.env.SHELL;
        }
    }

    configure(app: express.Application): void {
        app.post('/terminals', (req, res) => {
            let cols = parseInt(req.query.cols, 10),
                rows = parseInt(req.query.rows, 10),
                term = pty.spawn(this.getShellExecutablePath(), [], {
                    name: 'xterm-color',
                    cols: cols || 80,
                    rows: rows || 24,
                    cwd: process.env.PWD,
                    env: process.env
                })
            term.write(`cd ${getRootDir()} && `)
            term.write("source ~/.profile\n")

            this.terminals.set(term.pid, term)
            res.send(term.pid.toString());
            res.end();
        });

{'fraction_non_alphanumeric': 0.13679890560875513, 'fraction_numerical': 0.009302325581395349, 'mean_word_length': 2.369585253456221, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4323113', 'n_tokens_mistral': 1045, 'n_tokens_neox': 990, 'n_words': 272}