wfxr/code-minimap

Option to specify start and end lines

mirryi opened this issue · 5 comments

It would be nice if there were options to specify the line numbers of the file on which to start and end creation of the minimap. These values could be passed into core::write as Option<usize>?

The command-line option -S or --start-line could be used to set the line to start on. Thus, -S 5 would make the minmap start on and include line 5 of the file. Any value less than 1 defaults to 1. If the value is greater than the total number of lines in the file, the minimap is empty.

Likewise, the option -E or --end-line could be used to set the line to end on. -E 25 would make the minimap end on and include line 25. If the value is less than the start line value, then the minimap can simply be empty. An out of bounds end value would maybe just make the minimap include the rest of the file?

I've created a PR (see above) to see what the implementation might look like.

Alternatively, a syntax similar to that of the -r or --line-range option in bat could be used. The two options could then be condensed into one like -R <M:N>, where M is the start line and N is the end line.

  • -R 5:25 would show lines 5 to 25.
  • -R 5: would show from line 5 to the end
  • -R :25 would show from the beginning to line 25.
wfxr commented

@Dophin2009 Thank you, but I don’t think this option is very useful for minimap. There are already special tools head and tail to do this. I prefer to use these tools in combination instead.

eg: pick 10 lines from line 80th

$ seq 100 | tail +80 | head -10
80
81
82
83
84
85
86
87
88
89

You can easily combine them with code-minimap:

$ seq 100 | tail +80 | head -10 | code-minimap

That makes sense. Though I wonder if this option could still maybe be useful to Windows users, where head, tail, and other coreutil tools are not easily accessible or convenient?

Feel free to close.

wfxr commented

@Dophin2009 Your idea is good. I do not adopt this change simply because in my opinion it does not follow the philosophy of “KISS” and “Do one thing and do it well”.

For this non-daily used tool, I think it is not worth considering the applicability of each platform for a non-core function. I prefer to implement head or tail command independly if it is really necessary for many users.

Anyway, thank you for your contribution!