9 ms·
FYI, 'curl -sL -H "Accept: text/roff" https://jamesg.blog/2024/02/28/programming-projects/ https://jamesg.blog/2024/02/28/programming-projects/ | man -l /dev/st
by yrro 3y ago
FYI, 'curl -sL -H "Accept: text/roff" https://jamesg.blog/2024/02/28/programming-projects/ https://jamesg.blog/2024/02/28/programming-projects/ | man -l /dev/stdin' works for me - no need to safe the roff file locally.
- zerojames 3y agoUnfortunately, that command doesn't work on macOS (`/usr/bin/man: illegal option -- l`). I tried to get a one-liner with piping working on my Mac but I always ran into errors. The -l flag doesn't exist in the macOS man implementation (I consulted the man page; meta!).
- jolmg 3y agoThe `-l` can be skipped (probably because there are `/`s in man's argument): curl -sL -H "Accept: text/roff" https://jamesg.blog/2024/02/28/programming-projects/ | man /dev/stdin
- BossingAround 3y ago(which still doesn't work on mac)
- divbzero 3y agoThis still doesn’t work for me on macOS, perhaps a difference in how /dev/stdin is implemented? Fortunately, macOS has ZSH as the default shell so the following does work: man =(curl -sL -H "Accept: text/roff" https://jamesg.blog/2024/02/28/programming-projects/)
- penguinjanitor 3y agoMaybe 'man <(curl -sL -H "Accept: text/roff" https://jamesg.blog/2024/02/28/programming-projects/ https://jamesg.blog/2024/02/28/programming-projects/)' works then?
- BossingAround 3y agoNope
- divbzero 3y agoThis doesn’t work because it’s equivalent to piping stdout from curl into stdin for man.
- penguinjanitor 3y agoIt's not, that would be `man <<< "$(curl ...)" `. `man <(curl ...)` is a slightly different version of the process substitution[1] from your comment - `man =(curl ...)`. [1] https://zsh.sourceforge.io/Doc/Release/Expansion.html#Process-Substitution https://zsh.sourceforge.io/Doc/Release/Expansion.html#Proces...
- divbzero 3y agoYou’re right, it isn’t quite the same as piping. man <(curl ...) ends up working on Linux but for whatever reason still yields an error on macOS: No manual entry for /dev/fd/11
- jasomill 3y agocurl -sL -H "Accept: text/roff" https://jamesg.blog/2024/02/28/programming-projects/ | mandoc -a works on macOS (and should also work on (Free|Net|Open)BSD, which ship similar man toolchains).
- globular-toast 3y agoIt's actually process substitution: https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html https://www.gnu.org/software/bash/manual/html_node/Process-S... It's essentially running the process in another shell and sending its output to a tempfile. The name of that file is then substituted in the original command. So, in theory, equivalent to `inner > /tmp/file; outer /tmp/file`. This works with programs that don't read from stdin, or need two or more inputs, for example.
- salviati 3y agoYou can save a few chars with a process sostitution instead of a pipe if you're using bash: man -l <(curl -sL -H "Accept: text/roff" https://jamesg.blog/2024/02/28/programming-projects/)
- teaearlgraycold 3y agoAnd the world rejoiced as the bytes were saved.
- hk__2 3y agoIf you’re into that you can save four more chars by using `-sLH Accept:text/roff`
- godelski 3y agoI'm pretty sure the OP is intentionally not doing this because piping commands/things-from-the-internet into "bash" (or anything else) is generally considered bad practice. For me, I'm all for this. Anyone that is aware of the security implications is extremely likely aware of how to make the conversion like you've provided. In that case, no reason to tell people, because they already know. But it's not a great thing to tell noobies to do because they will get burned. So don't tell them. As they advance they'll naturally learn about this feature. And hopefully they have learned the implications by the time they learn how to do this. (not me): https://www.seancassidy.me/dont-pipe-to-your-shell.html https://www.seancassidy.me/dont-pipe-to-your-shell.html
- globular-toast 3y agoPiping to your shell and piping to `man` are not the same thing. The really dangerous thing is copy/pasting from a browser to your terminal. Always do Ctrl-X Ctrl-E to open an editor, paste it in there, then inspect it before saving/closing the editor to run the command.
- crtasm 3y agoNever knew that shortcut, useful!
- godelski 3y agoI only recently learned of it myself despite being on nix for over a decade and reading many advanced bash shortcut blogs. IDK why it isn't well known. For zsh users see here: https://nuclearsquid.com/writings/edit-long-commands/ https://nuclearsquid.com/writings/edit-long-commands/ Note: this can be tricky depending on where it goes in your zshrc. If you use a plugin manager (like Sheldon) then this should be above that. I ended up with this and it works well on OSX and linux autoload -U edit-command-line # Emacs style (<C-x><C-e>) zle -N edit-command-line # make sure `set -o vi` is above this line bindkey '^xe' edit-command-line bindkey '^x^e' edit-command-line # (VIM) Use visual mode bindkey -M vicmd v edit-command-line
- 3y ago