Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 4060e04

Browse files
authored
Add GitGrep plugin that makes the filename a link (#854)
* Add GitGrep plugin * Fix lint
1 parent ad10bb2 commit 4060e04

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/plugins/GitGrep.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from "react";
2+
import {PluginManager} from "../PluginManager";
3+
import {Job} from "../shell/Job";
4+
import Link from "../utils/Link";
5+
import {join} from "path";
6+
import {colors} from "../views/css/colors";
7+
8+
PluginManager.registerOutputDecorator({
9+
decorate: (job: Job): React.ReactElement<any> => {
10+
return <div style={{
11+
padding: "10px",
12+
lineHeight: "18px",
13+
}}>{job.screenBuffer.toLines().map((line, index) => {
14+
const match = line.match(/^(.*?):(\d+):(.*)$/);
15+
if (match) {
16+
const [, path, lineNum, rest] = match;
17+
if (path && lineNum && rest) {
18+
const absolutePath = join(job.environment.pwd, path);
19+
return <div key={index.toString()}>
20+
<Link absolutePath={absolutePath}>{path}</Link>
21+
<span style={{color: colors.cyan}}>:</span>
22+
{lineNum}
23+
<span style={{color: colors.cyan}}>:</span>
24+
<span style={{whiteSpace: "pre"}}>{rest}</span>
25+
</div>;
26+
}
27+
}
28+
return <div key={index.toString()}>{line}</div>;
29+
})}</div>;
30+
},
31+
32+
isApplicable: (job: Job): boolean => {
33+
try {
34+
const promptWords = job.prompt.expandedTokens.map(t => t.escapedValue);
35+
return promptWords.length === 3 && promptWords[0] === "git" && promptWords[1] === "grep";
36+
} catch (e) {
37+
return false;
38+
}
39+
},
40+
});

0 commit comments

Comments
 (0)