Skip to content

Commit

Permalink
railsware#800: proper fix for shell aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed May 22, 2017
1 parent 0aa5b6c commit 8438c06
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
10 changes: 3 additions & 7 deletions src/shell/Aliases.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {executeCommandWithShellConfig} from "../PTY";
import {loginShell} from "../utils/Shell";
import * as _ from "lodash";

export const aliasesFromConfig: Dictionary<string> = {};

export async function loadAliasesFromConfig(): Promise<void> {
try {
//const lines = await executeCommandWithShellConfig("alias");
//lines.map(parseAlias).forEach(parsed => aliasesFromConfig[parsed.name] = parsed.value);
} catch (error) {
console.error(error);
}
const lines = await loginShell.loadAliases();
lines.map(parseAlias).forEach(parsed => aliasesFromConfig[parsed.name] = parsed.value);
}

export function parseAlias(line: string) {
Expand Down
16 changes: 14 additions & 2 deletions src/utils/Shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {readFileSync, statSync} from "fs";
import * as Path from "path";
import {EOL} from "os";
import {resolveFile, io, filterAsync, homeDirectory} from "./Common";
import {executeCommandWithShellConfig} from "../PTY";
import * as _ from "lodash";

abstract class Shell {
Expand All @@ -11,6 +12,7 @@ abstract class Shell {
abstract get noConfigSwitches(): string[];
abstract get preCommandModifiers(): string[];
abstract get historyFileName(): string;
abstract loadAliases(): Promise<string[]>;

async existingConfigFiles(): Promise<string[]> {
const resolvedConfigFiles = this.configFiles.map(fileName => resolveFile(process.env.HOME, fileName));
Expand All @@ -33,7 +35,13 @@ abstract class Shell {
}
}

class Bash extends Shell {
abstract class UnixShell extends Shell {
loadAliases() {
return executeCommandWithShellConfig("alias");
}
}

class Bash extends UnixShell {
get executableName() {
return "bash";
}
Expand Down Expand Up @@ -65,7 +73,7 @@ class Bash extends Shell {
}
}

class ZSH extends Shell {
class ZSH extends UnixShell {
get executableName() {
return "zsh";
}
Expand Down Expand Up @@ -126,6 +134,10 @@ class Cmd extends Shell {
get historyFileName(): string {
return "";
}

async loadAliases() {
return [];
}
}

const supportedShells: Dictionary<Shell> = {
Expand Down
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
"preserveConstEnums": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"noImplicitAny": true,
"noEmitOnError": true,
"jsx": "react",
"outDir": "compiled/src",
"strictNullChecks": true,
"noImplicitThis": true,
"inlineSourceMap": true

"inlineSourceMap": true,
"noUnusedLocals": true,
"noUnusedParameters": true
},
"exclude": [
"node_modules",
Expand Down

0 comments on commit 8438c06

Please sign in to comment.