This repository has been archived by the owner on May 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Parser] Improve
cd
suggestions performance.
- Loading branch information
1 parent
10d2740
commit c405c83
Showing
3 changed files
with
57 additions
and
58 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
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 |
---|---|---|
@@ -1,41 +1,27 @@ | ||
import {executable, sequence, decorate, string, noisySuggestions, runtime, choice} from "../../Parser"; | ||
import {directoryAlias, pathPart} from "./Common"; | ||
import {expandHistoricalDirectory} from "../../Command"; | ||
import {description, styles, style} from "./Suggestions"; | ||
import * as _ from "lodash"; | ||
import {relativeDirectoryPath} from "./File"; | ||
import {pathIn} from "./Common"; | ||
|
||
const historicalDirectory = runtime(async (context) => | ||
noisySuggestions( | ||
decorate( | ||
choice( | ||
_.take(["-", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"], context.historicalCurrentDirectoriesStack.length - 1) | ||
.map(alias => decorate(string(alias), description(expandHistoricalDirectory(alias, context.historicalCurrentDirectoriesStack)))) | ||
), | ||
style(styles.directory) | ||
) | ||
decorate( | ||
choice( | ||
_.take(["-", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"], context.historicalCurrentDirectoriesStack.length - 1) | ||
.map(alias => decorate(string(alias), description(expandHistoricalDirectory(alias, context.historicalCurrentDirectoriesStack)))) | ||
), | ||
style(styles.directory) | ||
) | ||
); | ||
|
||
const cdpathDirectory = runtime( | ||
async (context) => { | ||
const directoriesToBe = context.environment.cdpath(context.directory).map(async (directory) => { | ||
const file = await pathPart(directory, info => info.stat.isDirectory()); | ||
|
||
if (directory === context.directory) { | ||
return file; | ||
} else { | ||
return noisySuggestions(decorate(file, description(`In ${directory}`))); | ||
} | ||
}); | ||
|
||
return choice(await Promise.all(directoriesToBe)); | ||
} | ||
async (context) => choice(context.environment.cdpath(context.directory).filter(directory => directory !== context.directory).map(directory => | ||
decorate(pathIn(directory, info => info.stat.isDirectory()), description(`In ${directory}`)))) | ||
); | ||
|
||
export const cd = sequence(decorate(executable("cd"), description("Change the working directory")), choice([ | ||
historicalDirectory, | ||
directoryAlias, | ||
cdpathDirectory, | ||
noisySuggestions(historicalDirectory), | ||
noisySuggestions(cdpathDirectory), | ||
relativeDirectoryPath, | ||
])); |
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