tag icon indicating copy to clipboard operation
tag copied to clipboard

Filename incorrect when `--before` and `--after` used

Open andrewhowdencom opened this issue 8 years ago • 2 comments

andrewhowdencom avatar Aug 11 '17 09:08 andrewhowdencom

related to https://github.com/aykamko/tag/issues/29

I don't have the bandwidth to fix this issue so I'm calling out to whoever would like to take this on. It's going to require another refactor of how tag parses the search backend's output, yay.

aykamko avatar Oct 23 '17 00:10 aykamko

This isn't a permanent solution, but I was encountering this problem as well using ag as the backend and came up with a quick fix:

diff --git a/tag.go b/tag.go
index b54e9e2..09f8679 100644
--- a/tag.go
+++ b/tag.go
@@ -59,10 +59,12 @@ func getEnvDefault(key, fallback string) string {
 }

 var (
-       red          = color.RedString
-       blue         = color.BlueString
-       lineNumberRe = regexp.MustCompile(`^(\d+):(\d+):.*`)
-       ansi         = regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`) // Source: https://superuser.com/a/380778
+       red                = color.RedString
+       blue               = color.BlueString
+       lineNumberRe       = regexp.MustCompile(`^(\d+):(\d+):.*`)
+       lineContinuationRe = regexp.MustCompile(`^(\d+)-.*`)
+       lineSeperatorRe    = regexp.MustCompile(`^--`)
+       ansi               = regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`) // Source: https://superuser.com/a/380778
 )

 type AliasFile struct {
@@ -156,9 +158,12 @@ func generateTags(cmd *exec.Cmd) int {
                        fmt.Printf("%s %s\n", tagPrefix(aliasIndex), string(line))
                        aliasIndex++
                } else {
-                       // Empty line. End of grouping, reset curPath context
                        fmt.Println(string(line))
-                       curPath = ""
+
+                       // If not continuation or context boundary seperation, reset path context
+                       if !lineContinuationRe.Match(colorlessLine) && !lineSeperatorRe.Match(colorlessLine) {
+                               curPath = ""
+                       }
                }
        }

This is working well for the ag backend, but the rg backend is broken.

Potentially later I'll fix this the correct way and make it work with rg, but for now I thought I'd at least contribute this workaround as a comment.

bturrubiates avatar Nov 26 '18 23:11 bturrubiates