cheat.sh (cht.sh)

repository·master·Indexed 13 days ago

https://github.com/chubin/cheat.sh

A community-driven cheat sheet service providing instant access to documentation for over 1000 UNIX/Linux commands and 56 programming languages via a simple HTTP interface. It includes a command-line client with shell mode, stealth mode, and integrations for editors like Vim, VS Code, Sublime Text, IntelliJ IDEA, Emacs, and QtCreator.

Tokens
10.2K
Snippets
44
Records
69
Agent score
99%

What's inside cheat.sh

  1. Access programming language cheat sheets

    master

    Cheat sheets for programming languages are organized using namespaces (subdirectories) named after the language. For any supported language, you can access specific specialized sheets using the following patterns:

    • {language}: The main cheat sheet for the language.
    • {language}/hello: Instructions on how to start with the language (installation, building, running, and a 'Hello World' example).
    • {language}/:list: A list of all available topics related to that language.
    • {language}/:learn: A 'learn-x-in-minutes' style sheet for quick onboarding.
    • {language}/1line: A collection of one-liners for that language (if supported).
    • {language}/weirdness: A collection of unusual or 'weird' language examples (if supported).

    Example for Lua:

    lua
    lua/hello
    lua/:list
    lua/:learn
  2. Best practices for cheat.sh queries

    master

    To get the most accurate results from cheat.sh, follow these query rules:

    1. Be specific: /python/append+file is more effective than /python/file.
    2. Use practical questions: Ask how to perform a specific task.
    3. Specify language: For programming questions, always include the language name in the path.
    4. Use + for spaces: Replace spaces with the + character.
    5. Avoid special characters: They are ignored by the service.
    6. Exclude terms: To exclude cheat sheets containing a specific word, use +- (e.g., python/multiply+matrices+-numpy).
  3. Use cheat.sh Stealth Mode

    master

    Stealth mode allows you to query cheat sheets by simply selecting text with your mouse. This is useful in environments like online interviews where you want to remain inconspicuous.

    To use it in the cht.sh shell:

    1. Run cht.sh --shell.
    2. Run stealth Q inside the shell.
    3. Select any text in your environment; the selection will be used as a query. Selections longer than 5 words are ignored.
    $ cht.sh --shell python
    cht.sh/python> stealth Q
    # Now, selecting text in your browser/editor triggers queries
  4. Explore programming language topics

    master

    Each programming language topic includes specific subtopics to help you learn or find specific information:

    • hello: Hello world and program startup instructions.
    • :learn: A comprehensive cheat sheet for learning the language from scratch.
    • :list: List all subtopics for that language.
    • :random: Fetches a random cheat sheet belonging to that specific language topic.
    # Example: Learning Python from scratch
    curl cheat.sh/python/:learn
  5. Self-host cheat.sh using Docker

    master

    You can run a local instance of the service using docker-compose. This setup includes a Redis instance for backing the service.

    Run the following command in the directory containing the docker-compose.yml file:

    docker-compose up

    The service will be available at http://localhost:8002.

    Note: This is an early implementation intended for internal, development, or personal use.

    docker-compose up
  6. Install Redis on Mac OS X

    master

    If your local installation requires Redis, you can install it via Homebrew on Mac OS X:

    $ brew install redis
    $ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
    $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
    $ redis-cli ping
    # Should return PONG
    brew install redis
    ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
    redis-cli ping
  7. Integrate cheat.sh with Sublime Text

    master

    Install the cheat.sh-sublime-plugin to replace text with cheat sheet answers.

    Usage:

    1. Write your query string in the editor.
    2. Select the query string.
    3. Press Cmd + ⇧ Shift + B to replace the selection with the generated answer.
  8. Install cheat.sh locally for offline use

    master

    To use cheat.sh offline or to use your own custom cheat sheets, you must perform a standalone installation. This installs the application and its data sources to ~/.cheat.sh by default.

    1. Download the cht.sh CLI client:
    curl https://cht.sh/:cht.sh > ~/bin/cht.sh
    chmod +x ~/bin/cht.sh
    1. Run the standalone installation command:
    cht.sh --standalone-install
    curl https://cht.sh/:cht.sh > ~/bin/cht.sh
    chmod +x ~/bin/cht.sh
    cht.sh --standalone-install
  9. Use the cht.sh interactive shell mode

    master

    The --shell mode allows for an interactive session with persistent context. You can change the language context using the cd command or switch to a different language for a single query using /.

    Key Shell Commands:

    • cd <LANG>: Change the language context.
    • c or y: Copy the last answer to the clipboard.
    • C or Y: Copy the last answer without comments to the clipboard.
    • help: Show internal client help.
    • stealth Q: Enter stealth mode (queries based on selected text).
    # Start interactive shell in a specific language
    $ cht.sh --shell go
    
    # Inside the shell
    cht.sh/go> reverse a list
    cht.sh/go> C
  10. Install and use the cht.sh shell client

    master

    The cht.sh client is a local shell script that provides a more convenient interface than raw curl commands.

    Installation:

    1. Download the script: curl https://cht.sh/:cht.sh > ~/bin/cht.sh
    2. Make it executable: chmod +x ~/bin/cht.sh
    3. Ensure ~/bin is in your $PATH.

    Usage:

    • Run a cheat sheet: cht.sh python
    • Use learning mode: cht.sh python :learn
    • Configure your shell: cht.sh --shell
    $ curl https://cht.sh/:cht.sh > ~/bin/cht.sh
    $ chmod +x ~/bin/cht.sh
    $ cht.sh python :learn
  11. Set up Bash tab completion for cht.sh

    master

    To enable tab completion for the cht.sh client in Bash, follow these steps:

    1. Create the bash directory: mkdir -p ~/.bash.d/
    2. Download the completion script: curl cheat.sh/:bash_completion > ~/.bash.d/cht.sh
    3. Load it in your current session: . ~/.bash.d/cht.sh
    4. Make it permanent by adding it to your .bashrc: echo '. ~/.bash.d/cht.sh' >> ~/.bashrc
    $ mkdir -p ~/.bash.d/
    $ curl cheat.sh/:bash_completion > ~/.bash.d/cht.sh
    $ . ~/.bash.d/cht.sh
    $ echo '. ~/.bash.d/cht.sh' >> ~/.bashrc