cheat.sh icon indicating copy to clipboard operation
cheat.sh copied to clipboard

How to get original url form cht.sh cli?

Open rabbitear opened this issue 6 years ago • 8 comments

Hello, I always find myself wanting to add more to many of the sheets, specially the unix commands. In the readme it says one way to do that is find the url and use the browser. I'm using the cli cht.sh, wondering how to find the url of the specific sheet I'm looking at?

Thanks.

rabbitear avatar Jul 25 '18 02:07 rabbitear

I don't currently believe there is a way to do this via the command line "curl" of cht.sh however, if you open the same cheat sheet in the browser, it'll have an "edit" link in the top right side.

You can see that if you visit https://cht.sh/bash for instance. However, not all cheat sheets have that link, because, IIRC, they can come from other sources. (ie: https://cht.sh/vim ) - in that case, all the way at the bottom there is a link to the github repo that contained the sheet, as well.

I reckon the difference is because @chubin knows which ones are hosted under his github acct, so he can directly add an edit link to them.

sullivant avatar Jul 26 '19 17:07 sullivant

That's a very good question. Actually, we should have the url anyway, at least for the license purposes (as we have it for stackoverflow answers). What would be even cooler, and we will implement it, that it would be possible to edit cheat sheets directly with cht.sh -e:

$ cht.sh -e tar

chubin avatar Aug 06 '19 12:08 chubin

It's definitely a feature that be nice on editors plugin

dbeniamine avatar Aug 07 '19 08:08 dbeniamine

Implement ?src option that will show where the cheat sheet comes from?

$ curl cht.sh/btrfs\?src
https://github.com/chubin/cheat.sheets/edit/master/sheets/btrfs

abitrolly avatar Jul 31 '20 01:07 abitrolly

I think, it should be either a short option (like S) or a long option (like show_src=true); otherwise it will be misinterpreted as a group of three short options (s, r, and c)

chubin avatar Oct 12 '20 16:10 chubin

I now get a little marking at the bottom of the cheatsheet; e.g. [so/q/3418231]. Unfortunately, that is not a url, so I can't just do gx on it from within vim. Can we make that an actual url?

TamaMcGlinn avatar Feb 02 '21 08:02 TamaMcGlinn

@TamaMcGlinn yes, we will make it. I think the best way would be to add a special action, like action=url for that, so it will be possible to get the URL with

curl cht.sh/QUESTION?action=url

or a similar query

chubin avatar Apr 25 '21 07:04 chubin

I'm currently using sed to transform StackOverflow references into working links.

Example script:

curl -s https://cht.sh/sed+capture+group | sed -r 's_so/q/([0-9]+)_https://stackoverflow.com/questions/\1_g'

tplk avatar Sep 22 '21 13:09 tplk