chubin / cheat.sh

the only cheat sheet you need
https://cheat.sh/
MIT License
38.42k stars 1.79k forks source link

Personal Cheatsheets #97

Open dufferzafar opened 6 years ago

dufferzafar commented 6 years ago

Is there a way to create personal / private cheatsheets? for tools that are internal to our team etc.

With other tools like Chris' cheat we could do this by simply adding a file in one of the config directories.

How can this be done using the cht.sh bash CLI tool?

chubin commented 6 years ago

The first and main question is can you install the cheat.sh server somewhere in your local environment or not?

If yes, then it is not a problem at all. With our "cascading cheat sheets" mode (it will be described in README.md soon), you can create a hierarchy of cheat sheets servers, where each server delivers local cheat sheets + if a requested cheat sheet is not found, the query is forwarded to the upstream server (and so on).

cheat.sh
    ^
    |
cheat.my
    ^
    |
clients

For the user it looks fully transparent, it uses the same clients as always. The only difference is that the clients should be configured the correct server (is some clients are used; of course, if you use nothing but curl, you change nothing but the name of the server in the query):

curl cheat.my/secret

In this query, you ask the cheat.my server for the secret cheat sheet.

dufferzafar commented 6 years ago

Um, I can install whatever I want on my personal machine. But not too sure about the work machine I use. It has all sorts of weird permission restrictions.

Is there any other alternative?

I used to use my own cheat tool before, and it just needed a list of paths where cheats were kept. So I would give it the path to cheatsheets from chrisallenlane/cheat and my own secret cheats.

Could something like this directory list be added to the cht.sh CLI?

  1. First check if file /path/to/secret/command exist
  2. Else, do curl cht.sh/command
chubin commented 6 years ago

@dufferzafar It is an interesting idea, but this solution would be inconsistent, because the cheat sheets would be available only on the local machine and only for this client. Is it ok for you?

dufferzafar commented 6 years ago

I could use other tools I know to sync my sheets.

Like I would use a private git repository?

Or Even Dropbox.

I think you should leave this to the people, and not worry about it.

On Wed 15 Aug, 2018, 10:14 PM Igor Chubin, notifications@github.com wrote:

@dufferzafar https://github.com/dufferzafar It is an interesting idea, but this solution would be inconsistent, because the cheat sheets would be available only on the local machine and only for this client. Is it ok for you?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chubin/cheat.sh/issues/97#issuecomment-413258257, or mute the thread https://github.com/notifications/unsubscribe-auth/ABYeKD1whbVBq0dtDZIpGO9WBhEAwSq_ks5uRE_0gaJpZM4V5Q4o .

chubin commented 6 years ago

Yes, you are absolutely right, but for that we have to fully implement the cascading cheat sheets feature. It is almost done, and I think you could use it soon

miloskroulik commented 4 years ago

Any news regarding this?

chubin commented 4 years ago

@miloskroulik Please take a look at this, starting here:

https://github.com/chubin/cheat.sh/issues/98#issuecomment-493783491

You can install cheat.sh in the standalone mode, and configure it to use your own cheat sheets sources. Is it the feature you are looking for?

ochaloup commented 4 years ago

@chubin I'm trying to understand how to configure my own cheat sheets source but unfortunately I haven't found how to do it.

I installed the cht.sh in standalone mode and the installation says that

You can add your own cheat sheets repository (config is in `etc/config.yaml`),
or create new cheat sheet adapters (in `lib/adapters`).

The etc/config.yaml contains just information about redis cache

server:
    address: "0.0.0.0"
cache:
    type:   redis

I can't find any information about this configuration file and what can be configured.

I'm trying to do this for my own dev machine. The best I would like not to start a "server", but just define a directory where the text resides - ie. https://github.com/chubin/cheat.sh/issues/97#issuecomment-413264518.

I found if I add a file under some directory of upstream folder - e.g. upstream/cheatsheets/my-cheat-sheet then the file will be considered (using cht.ch command). But I don't think it's the expected usage and it's not optimal.

The other option could probably be (?) to add a ~/.cheat.sh/lib/ adapter - as a .py source (e.g. similar to https://github.com/chubin/cheat.sh/blob/master/lib/adapter/cheat_sheets.py) that would work with a repository and somehow register(?) it to cht.ch?

Would you be so kind and help me what is the best practice? Is there some doc about these topics? Thanks a lot

ochaloup commented 4 years ago

Oh, I probably found it. Is it the feature which is under development, right? https://github.com/chubin/cheat.sh/issues/230

chubin commented 4 years ago

@ochaloup actually, you did it right. The easiest way to do it would be exactly as you did: you can just replace the repository URL here:

https://github.com/chubin/cheat.sh/blob/master/lib/adapter/cheat_sheets.py#L47

What structure has your internal cheat sheets repository? The same as https://github.com/chubin/cheat.sheets ?

ochaloup commented 4 years ago

@chubin thanks a lot for answering

On testing this I ended with trying to create an adapter working with the file system and now I have several more questions :-) https://github.com/ochaloup/cheat.sh/commit/dbab0842f079feaca967f984fc9b2783c2a5407d

On playing with the code I stuck with not understanding of the config setup. The code was placed at the lib directory but the adapter searched no page. Then I found there is a list adapters.active and routing.main(...?) https://github.com/chubin/cheat.sh/blob/ee0f4c494b82e6b66226c611d8e14b99c3177ff9/lib/config.py#L76 Is there some way to update the config.yaml to get those list updated (ie. appended) with one more adapter?

Btw. what is the place where the config.yaml can be placed? I run on Fedora 32 and the config is under ~/.cheat.sh/etc/config.yaml. I don't understand if changes of the code under the directory will make working commands like cheat.sh --shell; update (I was thinking there could be some git pull in the background and conflicts may occur. But in fact even there are some changes at the cheat.sh master/origin no code update seems not happen. I'm thinking if because of the conflicts. On the other hand there are no errors shown) Maybe the under ~/.cht.sh/config.yaml?

ochaloup commented 3 years ago

hi @chubin , I don't want to bother you with long questions. Just if you find time to explain details how to work correctly with adapters (ie. my doubts above) or/and what is the plan about easy ways to add personal cheatsheets it would be great. Thank you.

chubin commented 3 years ago

@ochaloup Hi! Please excuse me for the long response time, I hope it will be better in future.

You are doing everything absolutely right! I like your file based implementation, and this approach will work.

I don't know though why you don't want to use an existing, Git-based adapter, because even for private notes, git is a useful thing to have. You could just create a git repository (even a private one) for your notes, and just use it.

Location of the config file is etc/config.yaml as you correctly guessed, and you can configure the routing table directly in it.

Have you added your adapter to adapters.active + to the route table (routing.main)?

ochaloup commented 3 years ago

@chubin thanks for the response and I do apologize for my late response as well. I was playing with my own repository back in the time and but I haven't got to finish it with your guidelines.

On the lib/config.py - I added my adapter to adapters.active and routing.main. The cheet.sh is capable to list the cheetsheets but there is not working the TAB autocomplete functionality in bash. I will be missing some setup here. Would you have tip for me? :-)

I agree that git-based adapter could be working fine just I'm not used to work with git as a storage for my notes. Thus I decided to adjust your great tool for my purposes. I understand that it's not your use case but for me it's fine to not be forced to use the github. By interest, would you consider adding a functionality of non git-based adapters in future or rather not?

If you don't mind my asking - or I can post to some other place if this is not appropriate for such kind of question - how does work the command cht.sh update? Should there be update of repositories or the cheat.sh scripts from github? It seems it does nothing for me.

dufferzafar commented 3 years ago

So, I needed a personal cheatsheet again and came back to this.

@chubin you'd mentioned:

we have to fully implement the cascading cheat sheets feature

was this done?

chubin commented 3 years ago

@ochaloup

The cheet.sh is capable to list the cheetsheets but there is not working the TAB autocomplete functionality in bash. I will be missing some setup here. Would you have tip for me? :-)

If you see that the new cheat sheets are available when you curl your server directly, but you don't see them with the cht.sh client, can you please make sure that it access your server, and not the main cheat.sh server?

By interest, would you consider adding a functionality of non git-based adapters in future or rather not?

Yes, absolutely. What type of the adapter do you need?

how does work the command cht.sh update

It updates the cht.sh client itself, if it needs to be updated.

@dufferzafar Yes this was implemented. It is not yet fully documented, but it is implemented and it works

ochaloup commented 3 years ago

@chubin thanks for the answers

ad autocomplete functionality) ok, then it's the point. I haven't started local server (at least I think so) and I didn't know that the autocompletion is queried via a remote call. I assume the reason is that the main cheat.sh server is queried for me.

ad non git-based adapters) I would like to have a chance to use just the file based repo - ie. point to a directory where cheat sheets are placed (no new adapters to be created or configured, just one configuration line pointing to a directory). That was the point of my question - if this is possible in future?

ad cht.sh update) ok, I see. I figured out that I was thinking that the repositories should be updated but that's what should be done with ~/.cheat.sh/ve/bin/python3 ~/.cheat.sh/lib/fetch.py update-all. I will need to investigate on cht.sh --standalone-install to see how this will work for me (I'm still using what was available 2 months ago where offline_usage branch was not working).

chubin commented 3 years ago

file based adapter; if this is possible in future?

Yes, absolutely

2 months ago where offline_usage branch was not working

I believe the branch was merged more than two months ago; maybe there were some minor fixes two months ago, but nothing big. I would suggest you to try to go through this documentation, and check if it works for you or not

https://github.com/chubin/cheat.sh/blob/master/doc/standalone.md

ochaloup commented 3 years ago

@chubin oh, I see the offlne branch is merged, right? I was confused as the image at [https://github.com/chubin/cheat.sh/blob/master/doc/standalone.md]standalone.md) (ie. https://user-images.githubusercontent.com/3875145/57986904-ef3f1b80-7a7a-11e9-9531-ef37ec74b03a.png) mentions the tracking branch offline_usage. I will work with master then.