chubin / cheat.sheets

cheat.sh cheat sheets repository
MIT License
598 stars 209 forks source link

Add lenchk (tester to replace max_length) #133

Closed ghost closed 3 years ago

ghost commented 3 years ago

Please refer to the commit message.

If this isn't what you had in mind, like if it's not meant to be interactive at all, but you still want to have it as an additional tester, let me know, and I'll restore the original file in the next commit.

If you use this file, I only ask that the header (my GitHub & E-Mail) remain; beyond that, I'm not bothered, as long as you guys are happy. :)

chubin commented 3 years ago

Wow! This is a cool script. The colorization part looks especially impressive. Of course, it is already perfect as it is, but I would make add several minor suggestions:

  1. If terminal is attached ([-t 1]), automatically pipe it less -EXFR;
  2. Exit with exitcode 1 if there are lines with exceeding length (for CI);
  3. Add some options to make it not descend into the sub-directories (and make it possible to add directories as cli args);
  4. Add some "whitelisting" flag for a file, à la # pylint disable=..., because there will be some sheets that must be longer than 80 characters, and lenchk should be able to skip them.
  5. It would be great if it would be possible to call the script from any location, and it would scan $(dirname "${BASH_SOURCE[0]}")"/sheets/ by default (but the directory could be overridden, see 3).

Very cool script without a doubt. We will bind it to CI-checks, and this colorization feature will shine even brighter in CI-reports :)

ghost commented 3 years ago

I'm glad you're so happy with it! :D

  1. Oh, so you basically think using a pager should be the default setting? Can do.

  2. Oh yeah, thanks; forgot about that.

  3. It's already non-recursive; were it so, I'd have used the ** syntax in the main for loop. Unless you meant something else. The adding of directories per args sounds like a solid idea, so I'll get on that.

  4. That's a good idea. I'll add a whitelisting flag.

  5. Woah. Mind blown. I'm surprised I'd never really come across the $BASH_SOURCE array variable, but I'll get on using that; that's really gonna be useful in all my projects!

Thanks, Chubin. If there are any other tests needed, let me know.

BTW, can you test using the -c flag with less? Reason being, I'm seeing some weirdness on my end, but it's probably because of my less configuration (TERMCAP stuff) and/or version.

Screenshot_2020-11-16_22:24:54

Notice some output got 'stuck', as it were? Weirdly, though, if you scroll away then back, that line(s) vanishes and the rest displays normally. This only occurs if colorization is enabled.

chubin commented 3 years ago
  1. It is like git does it (but only in case terminal is attached, of course).
  2. I mean, sometimes you don't want do descend into subdirectories; how you can specify it?
  3. ${BASH_SOURCE[0]} is not portable, but it has that advantage comparing to $0, that if you source the script with source (or .), it points to the real filename, and not to the base script where source is called, that's why I prefer it.

Regarding your question about garbage: I suppose you mean the "found lines" output, that goes to stderr; if you run it with 2>&1, it will be piped into less too, and this unpleasant effect will disappear

ghost commented 3 years ago

Thank you. That sorted out my garbage issue. I guess that's a side-effect of less-ing.

Still not clear on 2 -- sorry. No descending occurs due to the way in which the for loop works. Are you saying that you want the option to descend into subdirectories? If so, I can add the ability to do that via the usual -R/-r flag.

chubin commented 3 years ago

In my case it descends by default (as if this future option -r already exists and specified)

Selection_071

You see those _scala/..., _swift/..., etc?

ghost commented 3 years ago

That's normal, but I think I see what you're looking for, now. See, when you were talking about descending, I thought you meant beyond what was supplied in the for loop (../sheets/* and ../sheets/*/*). Now that I know what you're after, I can sort that.