4 ms·
fd, xargs, bat = quick document review
- 29athrowaway 3y agoMaybe rg or fzf and bat
- nickjj 3y agoThat'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-to-preview-files https://nickjanetakis.com/blog/customize-fzf-ctrl-t-binding-...
- hiAndrewQuinn 3y agoThis was super helpful actually, I somehow totally missed Ctrl-T being a thing and this makes it even nicer.
- nickjj 3y agoNo 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}"
- 29athrowaway 3y agoCtrl-O for ranger or one of its rewrites is a great idea too.
- 149765 3y agoWhy not just "fd -e fi.md -X batcat"?
- katehikes88 3y agoWhy not `find -name '*.fi.md' -exec less {} \;`
- genman 3y agoCan less provide syntax highlighting?
- katehikes88 3y agoIt can with lesspipe but don't you think that's a bit of an overkill for a simple markdown document?
- rwmj 3y agoSort 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.
- throwaway143829 3y agofind 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.
- katehikes88 3y agoThe 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.
- awsanswers 3y agoWhy 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.
- genman 3y agoI 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.
- katehikes88 3y agoIt is botspam and deserves to be flagged. Go ask chatgpt for explanation yourself instead of polluting forums with generated responses.
- deleted 3y ago[deleted]
- kkfx 3y agoEhm... 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...).