24 comments

[ 2.7 ms ] story [ 62.0 ms ] thread
Maybe rg or fzf and bat
That's what I do with this bit of built-in FZF configuration:

    export FZF_CTRL_T_OPTS="--preview='less {}' --height=100% --bind shift-up:preview-page-up,shift-down:preview-page-down"
This lets you hit CTRL+t and immediately start previewing files in a directory with an ability to page between results.

A video walk through and demo of that is here: https://nickjanetakis.com/blog/customize-fzf-ctrl-t-binding-...

This was super helpful actually, I somehow totally missed Ctrl-T being a thing and this makes it even nicer.
No problem, if you want to invoke it with a raw command instead of a hotkey you can set up an alias, I use `pf` for preview files.

You can reference FZF's env variable to reduce duplication too:

    alias pf="fzf ${FZF_CTRL_T_OPTS}"
Ctrl-O for ranger or one of its rewrites is a great idea too.
Why not just "fd -e fi.md -X batcat"?
Why not `find -name '*.fi.md' -exec less {} \;`
Can less provide syntax highlighting?
It can with lesspipe but don't you think that's a bit of an overkill for a simple markdown document?
Sort of. Setting the LESSOPEN environment variable will filter less input through that, which could do syntax highlighting (if you use less -r).

The default (/usr/bin/lesspipe.sh, shipped with less) isn't very clever. It can uncompress files in some common formats and open images, but isn't very smart and doesn't handle markdown or code of any kind as far as I can tell.

find is pretty slow compared to fd. It also spends a lot of time searching through directories like .git or node_modules which you typically want to exclude.
The bottleneck for speed will be the human examining the documents so there really isn't any difference in the overall time spent. Even without the required human input it doesn't make much difference for such a small amount of files. Most of the time there isn't a much reason to use `fd` or `rg` over more standard tools. Often you get most of the benefit from a single `cd`. When making a script for general consumption and there are possibly larger collective time savings from excluding subdirectories it would make more sense to use `-prune` rather than a niche tool with default rules that might change in the future.
Good first idea, and I just tried it - but sadly, this opens every Markdown document at once, as a giant pile of documents I would have to scroll down through.

That's not what I'm after. I want to survey the whole page with my eyes as fast as possible for unusual colors / oddly short files / etc, then press `q` to have the screen totally clear and move on to the next one.

Why write this up but not explain it? This command is a combination of several commands used in Unix-like operating systems, connected together using pipes. Let's break it down:

fd '.fi.md$':

fd is a program similar to the traditional find command but with a more user-friendly syntax and faster performance. '.fi.md$' is a regular expression. It matches files whose names end with .fi.md. The dollar sign $ in regular expressions signifies the end of a line or string, so this ensures that the command only finds files that exactly end with .fi.md. |:

This is a pipe. It takes the output of the command on its left (the list of files found by fd) and uses it as the input for the command on its right. xargs -I _ -- batcat --paging=always _:

xargs is a command used to build and execute command lines from standard input. -I _ tells xargs to replace occurrences of _ in the initial arguments with names read from standard input (the list of files provided by fd). -- is used to signify the end of command options, after which only positional arguments are accepted. batcat --paging=always _: Here, batcat is likely an alias or a symlink to bat, a command that provides syntax highlighting and Git integration for a variety of file types, and it's an improved version of the cat command. --paging=always ensures that bat always uses a pager (like less) to display the file content, regardless of the size of the file. _ is replaced by each file name from the output of fd. Putting it all together:

The command finds all files ending in .fi.md in the current directory and subdirectories. For each of these files, it then calls batcat (or bat) with the --paging=always option, effectively displaying their contents with syntax highlighting and paging, allowing you to scroll through the content if it's longer than the screen size.

I find that extensive flagging of this comment represents the degradation of users on HN. Yes, this comment may sound a little dismissive when you take the most derogatory interpretation, so what? It provides very useful context and was joy to read.
It is botspam and deserves to be flagged. Go ask chatgpt for explanation yourself instead of polluting forums with generated responses.
Interesting, so now instead of telling everyone to use Google, we tell everyone to use ChatGPT and we dismiss possible human written comments as those could have been written by ChatGPT? This user usual comments don't look like botspam.
Probably because there is barely anything to explain. It's a babby's first oneliner.

Everything after the first sentence in this comment seems to be LLM generated.

Sure, but not every reader is intimately familiar with Linux command line tools. I'm pretty certain that it is human written as ChatGPT gave much more detailed clarification (actually I got the idea to try it after reading this comment, I don't use ChatGPT very extensibly). I am fairly familiar with the Linux tooling but I can understand that oneliners like these can be quite intimidating.
The detail you get is dependent on your prompt and the model you use. The LLM used might not be chatgpt. The level of detail isn't the only thing you should consider. The writing style itself is unmistakably that of an LLM. Also explaining such basic concepts such as pipes is very suspect. Any human browsing this site would assume that everyone is already familiar with them. The nature of the post is such that it mostly appeals to shell enthusiasts anyways. The style shift between the first sentence and the rest of the comment is also quite obvious. The user's other comments do seem genuinely human however.

>oneliners like these

It is literally one pipe. You can't really get simpler than this.

> You can't really get simpler than this.

ls

But thanks for taking the time to explain.

(comment deleted)
Ehm... to replicate the same {most,less,more} for viewing and zsh */* patterns to the very same, Emacs+org-mode do far better... I fail to see the point (and the popular MD-mania...).