Skip to content

Commit

Permalink
support Goland
Browse files Browse the repository at this point in the history
Change the file format to "$PATH:$LINE" when running inside a Goland
terminal.  `vgrep` already supports VSCode so drop a section to the
README to better communicate this behavior.

Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Oct 30, 2020
1 parent 017963d commit c6a6614
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ The default editor of vgrep is `vim` with the default flag to open a file at a s

Note that `vgrep` does not allow for searching and opening files at the same time. For instance, `vgrep --show=files text` should be split in two commands: `vgrep text` and `vgrep --show=files`.

## IDE Support

Note that if you run `vgrep` inside a terminal of VSCode or Goland, the format of listed files changes to "$PATH:$LINE" to allow for opening the matches in the editor via a simple mouse click.

# More Commands and the Interactive Shell

Once vgreped, you can perform certain operations on the results such as limiting the range of indexed matches, listing matching files and directories and more.
Expand Down
5 changes: 5 additions & 0 deletions docs/vgrep.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ The default editor of vgrep is `vim` with the default flag to open a file at a s

Note that `vgrep` does not allow for searching and opening files at the same time. For instance, `vgrep --show=files text` should be split in two commands: `vgrep text` and `vgrep --show=files`.

### IDE Support

Note that if you run `vgrep` inside a terminal of VSCode or Goland, the format of listed files changes to "$PATH:$LINE" to allow for opening the matches in the editor via a simple mouse click.


## Interactive Shell

Once vgreped, you can perform certain operations on the results such as limiting the range of indexed matches, listing matching files and directories and more.
Expand Down
18 changes: 12 additions & 6 deletions vgrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func isVscode() bool {
return os.Getenv("TERM_PROGRAM") == "vscode"
}

// isGoland checks if the terminal is running inside of goland or possible other JetBrains IDEs.
func isGoland() bool {
return strings.Contains(os.Getenv("TERMINAL_EMULATOR"), "JetBrains")
}

// grep (git) greps with the specified args and stores the results in v.matches.
func (v *vgrep) grep(args []string) {
var cmd []string
Expand Down Expand Up @@ -777,13 +782,14 @@ func (v *vgrep) commandPrintMatches(indices []int) bool {
toPrint = append(toPrint, []string{"Index", "File", "Line", "Content"})
}

isVscode := isVscode()
inIDE := isVscode() || isGoland()
for _, i := range indices {
if isVscode {
// If we're running inside a vscode terminal, append the line to the
// file path, so we can quick jump to the specific location. Note
// that dancing around with the indexes below is intentional - ugly
// but fast.
if inIDE {
// If we're running inside an IDE's terminal, append
// the line to the file path, so we can quick jump to
// the specific location. Note that dancing around
// with the indexes below is intentional - ugly but
// fast.
toPrint = append(toPrint, []string{v.matches[i][0], v.matches[i][1] + ":" + v.matches[i][2], v.matches[i][2], v.matches[i][3]})
} else {
toPrint = append(toPrint, v.matches[i])
Expand Down

0 comments on commit c6a6614

Please sign in to comment.