-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from jupyterlite/aliases
Add support for aliases
- Loading branch information
Showing
16 changed files
with
295 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Collection of aliases that are known to a shell. | ||
*/ | ||
export class Aliases extends Map<string, string> { | ||
constructor() { | ||
super() | ||
this.set("dir", "dir --color=auto") | ||
this.set("grep", "grep --color=auto") | ||
this.set("ls", "ls --color=auto") | ||
this.set("ll", "ls -lF") | ||
this.set("vdir", "vdir --color=auto") | ||
} | ||
|
||
getRecursive(key: string): string | undefined { | ||
let alias = this.get(key) | ||
while (alias !== undefined) { | ||
const newKey = alias.split(" ")[0] | ||
if (newKey == key) { | ||
// Avoid infinite recursion. | ||
break | ||
} | ||
const newAlias = this.get(newKey) | ||
alias = (newAlias === undefined) ? newAlias : newAlias + alias!.slice(newKey.length) | ||
key = newKey | ||
} | ||
return alias | ||
} | ||
|
||
match(start: string): string[] { | ||
return [...this.keys()].filter((name) => { | ||
return name.startsWith(start) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.