the_silver_searcher
the_silver_searcher copied to clipboard
ag should include line number after the filename
In order to improve accessibility of the tool and allow users to open files at exact position where the match was found, ag should include the linenumber and eventually even the column number just after the filename, using the :
separator.
This notation is something we can already call defacto standard for most, in not all tools like compiliers, linters and other tools returning matches.
If we do this people would be able to click the filename in the terminal and open it directly at the right position.
Current behaviour:
ag "yncing the local repository to the remote host" [10:07:11]
rtox/rtox.py
165-
166- # Clone the repository we're working on to the remote machine.
167: print('Syncing the local repository to the remote host...')
168- subprocess.check_call([
169- 'rsync',
Proposed behaviour:
ag "Syncing" [10:07:11]
rtox/rtox.py:167:11
165-
166- # Clone the repository we're working on to the remote machine.
167: print('Syncing the local repository to the remote host...')
168- subprocess.check_call([
169- 'rsync',
Note: on multiple matches on same file, filename should be repeated.
ag has lots of output options, including for the filename. Have you looked at the help and man page?
Unfortunately, it still seems to have bugs that cause it to not output the filename even when --filename
is specified...
I think that adding the line number after the filename would greatly increase the usability of ag as we could click on results and open them in the editor directly.
![ag-search-results](https://user-images.githubusercontent.com/102495/41991089-3c16d942-7a3c-11e8-9f71-bf2705f37228.png)
Have you considered the --ackmate
option? Or you might consider using another tool, like rg
.
@alphapapa I tried the --ackmate
option but the outcome is not the desired one, is much harder to read and it does not solve the problem of clicking on the filename:line
or filename:line:colum
to open the file in you reditor at the right place.
In addition to that it also disables the coloring which is a very useful feature of ag
as it improves readability, a lot.
I think that a tunning of the default output that would include the line after filename would sortout the problem just fine.
I would not mind trying to add the described feature myself but I would first like to hear if this kind of contribution would be accepted.
I agree, due to the fact that I often open a file using Iterm2 on macOS, I need to scroll to the line number by myself >_<. In fact grep
's output is better for opening a file but it's slower than ag
.
Just following up on this.. is there really still no way to do this yet? Would love to be able to click on a file and be taken right to the result. 😆
Sorry but I switched to ripgrep one or two years ago, nothing last forever.
Indeed. Thanks.. will give that a shot 👍
It a bit disappointing that this feature has been ignored.
For those coming here for a solution, a tiny little bit of scripting will do - the output structure is regular, so it can be trivially processed. This is a possible approach:
ag "$pattern" | perl -lne 'if (/^(.+?):(\d+)/ && !$files{$1}) { print "$1:$2"; $files{$1} = "printed" }'
The Perl script extracts filename and line, and, if they aren't in a hashmap that tracks them, prints the filename and line, and puts the filename into the hashmap (so that it isn't printed again).