[Feature] imgcat `url`
Jeff-Tian opened this issue · 4 comments
cat image by url is great
Hi Jeff. Thanks for the issue! As imgcat
wishes to follow the UNIX philosophy of creating small, composable utilities that do one task well, I do not think integrating a URL fetcher into imgcat
is an appropriate use of maintenance resources. Because of this composability, you can already display images by URL with imgcat
by combining it with curl
:
imgcat <(curl -s https://imgs.xkcd.com/comics/tar.png)
Here's a small shell wrapper that gives you this functionality:
# Add this to your shell startup file, e.g., ~/zshrc, ~/.bash_profile, or ~/.bashrc:
function imgcat-url() {
imgcat <(curl -sf "$1")
}
I encourage you to expand and experiment with the above example.
Then you get the desired functionality:
imgcat-url https://imgs.xkcd.com/comics/tar.png
I hope this helps. Thanks again for getting in touch!
Hi @eddieantonio , sorry to ask a dumb question, I tried put the imgcat-url
to a imgcaturl.sh
file, and tried execute sh imgcaturl.sh
, it gives error:
line 2: syntax error near unexpected token `('
line 2: ` imgcat <(curl -sf "$1")'
Do you know where is wrong?
Hi @Jeff-Tian. It turns out the syntax I gave you only works in a #!/bin/bash
script; it will not work in a #!/bin/sh
script, which is the default. As such, please add the line
#!/bin/bash
...as the topmost line in the file. This is called the shebang line, and it tells your system which interpreter to use (it should be using bash
!)
Hi @eddieantonio thanks for your reply! Now I know it's a bash
syntax, great.
I found I can use the following syntax that works with sh
too:
curl -sf https://imgs.xkcd.com/comics/tar.png | imgcat