### Python Environment Setup Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Configures Python version (2 or 3) and installs requirements into a virtual environment. ```shell mkdir -p "log/" LOG="$PWD/log/install.log" set -o pipefail PYTHON2=NO if [[ $PYTHON2 = YES ]]; then python="python2" pip="pip" virtualenv_python3_option=() else python="python3" pip="pip3" virtualenv_python3_option=(-p python3) fi _say_what_i_do Creating virtual environment virtualenv "${virtualenv_python3_option[@]}" ve \ || fatal "Could not create virtual environment with 'virtualenv ve'" export CHEATSH_PATH_WORKDIR=$PWD if [[ $PYTHON2 = YES ]]; then sed -i s/rapidfuzz/fuzzywuzzy/ requirements.txt echo "python-Levenshtein" >> requirements.txt fi _say_what_i_do Installing python requirements into the virtual environment ve/bin/"$pip" install -r requirements.txt > "$LOG" \ || { echo "ERROR:" echo "---" } ``` -------------------------------- ### Setup Bash Tab Completion Source: https://github.com/chubin/cheat.sh/blob/master/README.md Installs the bash completion script for `cht.sh` by downloading it and sourcing it in your `~/.bashrc`. Ensure `~/.bash.d/` exists or adjust the path. ```bash curl https://cheat.sh/:bash_completion > ~/.bash.d/cht.sh . ~/.bash.d/cht.sh # and add . ~/.bash.d/cht.sh to ~/.bashrc ``` -------------------------------- ### Install Redis on Mac OS X Source: https://github.com/chubin/cheat.sh/blob/master/doc/standalone.md Install Redis using Homebrew on macOS and configure it to load on startup. Verify the installation by pinging the Redis server. ```bash $brew install redis $ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents $launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist $redis-cli ping ``` -------------------------------- ### GET /:cht.sh — Download the cht.sh CLI client Source: https://context7.com/chubin/cheat.sh/llms.txt Provides the `cht.sh` bash client script, which can be directly piped for installation. ```APIDOC ## GET /:cht.sh — Download the cht.sh CLI client ### Description Returns the `cht.sh` bash client script, suitable for piping directly into installation. ### Method GET ### Endpoint `/:cht.sh` ### Request Example ```bash # Install cht.sh client curl https://cht.sh/:cht.sh > ~/bin/cht.sh chmod +x ~/bin/cht.sh # Or install globally curl -s https://cht.sh/:cht.sh | sudo tee /usr/local/bin/cht.sh && sudo chmod +x /usr/local/bin/cht.sh ``` ### Response #### Success Response (200) - **script** (string) - The bash script for the `cht.sh` CLI client. ``` -------------------------------- ### Setup Zsh Tab Completion Source: https://github.com/chubin/cheat.sh/blob/master/README.md Installs the zsh completion script for `cht.sh` by downloading it and adding its directory to the fpath in your `~/.zshrc`. Ensure `~/.zsh.d/` exists or adjust the path. ```zsh curl https://cheat.sh/:zsh > ~/.zsh.d/_cht echo 'fpath=(~/.zsh.d/ $fpath)' >> ~/.zshrc # Open a new shell to load the plugin ``` -------------------------------- ### Install cht.exe with Scoop Source: https://github.com/chubin/cheat.sh/blob/master/README.md Use the scoop command-line installer for Windows to install the cht.exe client. ```batch scoop install cht ``` -------------------------------- ### Perform Standalone Installation Source: https://github.com/chubin/cheat.sh/blob/master/doc/standalone.md Execute the standalone installation command using the locally installed cht.sh client. This fetches cheat sheets and installs them locally, typically in `~/.cheat.sh`. ```bash cht.sh --standalone-install ``` -------------------------------- ### Vim Configuration for cheat.sh Source: https://github.com/chubin/cheat.sh/blob/master/README.md Example Vim configuration using Vundle to install syntastic and cheat.sh-vim plugins. This setup allows for syntax checking and explanations of errors/warnings directly within Vim. ```vim " some configuration above ... let mapleader=" " call vundle#begin() Bundle 'gmarik/vundle' Bundle 'scrooloose/syntastic' Bundle 'dbeniamine/cheat.sh-vim' call vundle#end() let g:syntastic_javascript_checkers = [ 'jshint' ] let g:syntastic_ocaml_checkers = ['merlin'] let g:syntastic_python_checkers = ['pylint'] let g:syntastic_shell_checkers = ['shellcheck'] " some configuration below ... ``` -------------------------------- ### Standalone Installation Help Text Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Displays help information for installing cheat.sh in standalone mode, including disk space requirements and dependencies. ```shell cat < ~/bin/cht.sh chmod +x ~/bin/cht.sh ``` ```bash # Or install globally curl -s https://cht.sh/:cht.sh | sudo tee /usr/local/bin/cht.sh && sudo chmod +x /usr/local/bin/cht.sh ``` -------------------------------- ### Quick Manual Installation of cheat.sh-vim Source: https://github.com/chubin/cheat.sh/blob/master/share/vim.txt Manually install the cheat.sh-vim plugin by cloning the repository and copying files. ```bash git clone https://github.com/dbeniamine/cheat.sh-vim.git cd cheat.sh-vim/ cp -r ./* ~/.vim ``` -------------------------------- ### Install cheat.sh CLI Client Source: https://github.com/chubin/cheat.sh/blob/master/doc/standalone.md Download and make the cht.sh client executable for local use. This is a prerequisite for standalone installation. ```bash curl https://cht.sh/:cht.sh > ~/bin/cht.sh chmod +x ~/bin/cht.sh ``` -------------------------------- ### Basic Client Usage Examples Source: https://github.com/chubin/cheat.sh/blob/master/README.md Demonstrates how to query cheat.sh using the client with natural language queries. Spaces are used instead of '+'. ```bash $ cht.sh go reverse a list ``` ```bash $ cht.sh python random list elements ``` ```bash $ cht.sh js parse json ``` -------------------------------- ### Lua Cheat Sheet Example Source: https://github.com/chubin/cheat.sh/blob/master/README.md Example of a Lua cheat sheet for retrieving table keys, including comments formatted as Lua comments. ```lua $ curl cht.sh/lua/table+keys -- lua: retrieve list of keys in a table local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end --|| [ Note that you cannot guarantee any order in keyset. If you want the [ keys in sorted order, then sort keyset with table.sort(keyset). [ [ [lhf] [so/q/12674345] [cc by-sa 3.0] ]] ``` -------------------------------- ### Install cheat.sh Client Locally Source: https://github.com/chubin/cheat.sh/blob/master/README.md Installs the cheat.sh client script to a specified directory in your PATH. Ensure the directory exists and is in your PATH. ```bash PATH_DIR="$HOME/bin" # or another directory on your $PATH mkdir -p "$PATH_DIR" curl https://cht.sh/:cht.sh > "$PATH_DIR/cht.sh" chmod +x "$PATH_DIR/cht.sh" ``` -------------------------------- ### Install cheat.sh Client Globally Source: https://github.com/chubin/cheat.sh/blob/master/README.md Installs the cheat.sh client script globally for all users. Requires sudo privileges. ```bash curl -s https://cht.sh/:cht.sh | sudo tee /usr/local/bin/cht.sh && sudo chmod +x /usr/local/bin/cht.sh ``` -------------------------------- ### Directory Existence and Space Check Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Verifies if the target installation directory exists and if there is sufficient disk space (700MB). ```shell if [ -e "$installdir" ]; then echo "ERROR: Installation directory [$installdir] exists already" echo "Please remove it first before continuing" return 1 fi if ! mkdir -p "$installdir"; then echo "ERROR: Could not create the installation directory \"$installdir\"" echo "ERROR: Please check the permissions and start the script again" return 1 fi local space_needed=700 local space_available; space_available=$(($(df -k "$installdir" | awk '{print $4}' | tail -1)/1024)) if [ "$space_available" -lt "$space_needed" ]; then echo "ERROR: Installation directory has no enough space (needed: ${space_needed}M, available: ${space_available}M" echo "ERROR: Please clean up and start the script again" rmdir "$installdir" return 1 fi ``` -------------------------------- ### Vizardry Installation for cheat.sh-vim Source: https://github.com/chubin/cheat.sh/blob/master/share/vim.txt Use this command with Vizardry to install the cheat.sh-vim plugin. ```vimscript Invoke -u dbeniamine cheat.sh-vim ``` -------------------------------- ### General Usage Examples Source: https://github.com/chubin/cheat.sh/blob/master/share/static/malformed-response.html These examples demonstrate how to use curl to interact with cheat.sh for various purposes, including accessing cheat sheets and potentially other services. ```bash curl https://t.co/9A97GQdoKB ``` ```bash curl https://t.co/F2XAJAIzDJ ``` ```bash curl https://t.co/XAKEDhzWjL ``` -------------------------------- ### Start Shell Mode with Initial Language Context Source: https://github.com/chubin/cheat.sh/blob/master/README.md Starts the cheat.sh shell with a pre-defined language context. Useful if most of your queries are for a specific language. ```bash $ cht.sh --shell go cht.sh/go> reverse a list ``` -------------------------------- ### Dependency Check for Standalone Install Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Checks if 'python', 'git', and 'virtualenv' are installed and available in the PATH. ```shell local dependencies=(python git virtualenv) for dep in "${dependencies[@]}"; do command -v "$dep" >/dev/null || \ { echo "DEPENDENCY: \"$dep\" is needed to install cheat.sh in the standalone mode" >&2; _exit_code=1; } done [ "$_exit_code" -ne 0 ] && return "$_exit_code" ``` -------------------------------- ### Learn a Specific Language Source: https://github.com/chubin/cheat.sh/blob/master/share/static/malformed-response.html This command provides a quick way to learn the basics or get an overview of a specific programming language. ```bash curl cht.sh/LANGUAGE/:learn ``` -------------------------------- ### cht.sh CLI Client Installation and Usage Source: https://context7.com/chubin/cheat.sh/llms.txt Install the cht.sh CLI client using curl. Supports one-shot queries, interactive shell mode, language-scoped shells, and clipboard integration. ```bash # Install curl https://cht.sh/:cht.sh > ~/bin/cht.sh && chmod +x ~/bin/cht.sh # One-shot query cht.sh tar cht.sh go reverse a list cht.sh python random list elements # Interactive shell mode cht.sh --shell # Interactive shell scoped to a language cht.sh --shell python # cht.sh/python> sort list # cht.sh/python> zip two lists # cht.sh/python> /go reverse a list (switch language with /) # cht.sh/python> cd go (change context) # Copy last answer to clipboard # cht.sh/python> c (with comments) # cht.sh/python> C (without comments) # Stealth mode: auto-query X clipboard selections cht.sh --shell python # cht.sh/python> stealth Q # Configuration file: ~/.cht.sh/cht.sh.conf # CHTSH_QUERY_OPTIONS="T" # always strip ANSI # CHTSH_QUERY_OPTIONS="style=native" # default color style # CHTSH_URL=https://cht.sh # server URL ``` -------------------------------- ### Learn Programming Language Basics Source: https://github.com/chubin/cheat.sh/blob/master/README.md Access the ':learn' page for a programming language to get a basic introduction, often mapped from the 'Learn X in Y' project. ```bash curl cht.sh/go/:learn ``` -------------------------------- ### Install Zsh Completion for cheat.sh Source: https://context7.com/chubin/cheat.sh/llms.txt Download the zsh completion script and configure your Zsh environment to use it for cheat.sh. ```zsh curl https://cheat.sh/:zsh > ~/.zsh.d/_cht echo 'fpath=(~/.zsh.d/ $fpath)' >> ~/.zshrc ``` -------------------------------- ### Start cheat.sh Server Mode Source: https://github.com/chubin/cheat.sh/blob/master/doc/standalone.md Run the cheat.sh server locally using its Python script. Gunicorn can also be used for starting the server. ```bash $HOME/.cheat.sh/ve/bin/python $HOME/.cheat.sh/bin/srv.py ``` -------------------------------- ### Get Help for Special Queries Source: https://github.com/chubin/cheat.sh/blob/master/share/intro.txt Access the full list of special queries and modes of operation by requesting the ':help' cheat sheet. ```bash curl cht.sh/:help ``` -------------------------------- ### Start cht.sh in General Shell Mode Source: https://github.com/chubin/cheat.sh/blob/master/share/intro.txt Initiate the cht.sh client in shell mode without a predefined context. You will need to specify the language for each query. ```bash cht.sh --shell ``` -------------------------------- ### Learn a New Programming Language Source: https://github.com/chubin/cheat.sh/blob/master/share/intro.txt Use the ':learn' special query to get introductory information for a new programming language, often sourced from 'Learn X in Y'. ```bash curl cht.sh/elixir/:learn | less -R ``` ```bash cht.sh/elixir> :learn ``` -------------------------------- ### GET /:styles / /:styles-demo — List syntax highlighting styles Source: https://context7.com/chubin/cheat.sh/llms.txt Lists all available Pygments color styles or displays a demo of each style. A specific style can also be applied to a query. ```APIDOC ## GET /:styles / /:styles-demo — List syntax highlighting styles ### Description Lists all available Pygments color styles or shows a demo of each. A specific style can also be applied to a query. ### Method GET ### Endpoint `/:styles` or `/:styles-demo` ### Parameters #### Query Parameters - **style** (string) - Optional - Use a specific Pygments color style for the output (when used with a topic query). ### Request Example ```bash # List all style names curl cht.sh/:styles # Show colored demo curl cht.sh/:styles-demo # Use a specific style in a query curl "cht.sh/python/sort?style=monokai" curl "cht.sh/go/channels?style=native" ``` ### Response #### Success Response (200) - **styles** (string) - For `/:styles`, a list of style names, one per line. - **demo** (string) - For `/:styles-demo`, a colored demo of each style. ``` -------------------------------- ### Install bash Tab Completion for cht.sh Source: https://github.com/chubin/cheat.sh/blob/master/share/intro.txt Follow these steps to install the bash tab completion script for cht.sh. This enables autocompletion when typing queries in your bash shell. ```bash mkdir -p ~/.bash.d/ curl https://cht.sh/:bash_completion > ~/.bash.d/cht.sh echo 'source ~/.bash.d/cht.sh' >> ~/.bashrc source ~/.bash.d/cht.sh ``` -------------------------------- ### Access Programming Language Cheat Sheets Source: https://github.com/chubin/cheat.sh/blob/master/share/intro.txt Fetch cheat sheets for specific programming languages by using a language-specific path. Use 'go/func' for Go language functions as an example. ```bash curl cht.sh/go/func ``` -------------------------------- ### Vundle Installation for cheat.sh-vim Source: https://github.com/chubin/cheat.sh/blob/master/share/vim.txt Add this line to your Vundle configuration to include the cheat.sh-vim plugin. ```vimscript Plugin 'dbeniamine/cheat.sh-vim' ``` -------------------------------- ### Pathogen Installation for cheat.sh-vim Source: https://github.com/chubin/cheat.sh/blob/master/share/vim.txt Clone the cheat.sh-vim repository into your Vim bundle directory using Pathogen. ```bash git clone https://github.com/dbeniamine/cheat.sh-vim.git ~/.vim/bundle/cheat.sh-vim ``` -------------------------------- ### List All Available Cheat Sheets Source: https://github.com/chubin/cheat.sh/blob/master/share/static/malformed-response.html Use this command to get a list of all programming languages for which cheat sheets are available. ```bash curl cht.sh/:list ``` -------------------------------- ### Retrieve Random Cheat Sheet from Namespace Source: https://context7.com/chubin/cheat.sh/llms.txt Get a random cheat sheet topic, scoped to a specific namespace like 'go' or 'python'. ```bash curl cht.sh/go/:random ``` ```bash curl cht.sh/python/:random ``` -------------------------------- ### GET /:help — Service help page Source: https://context7.com/chubin/cheat.sh/llms.txt Retrieves the complete help page for the cheat.sh service, detailing all special pages and available query options. ```APIDOC ## GET /:help — Service help page ### Description Returns the complete help page describing all special pages and query options. ### Method GET ### Endpoint `/:help` ### Response #### Success Response (200) - **help_text** (string) - The full help text listing special pages, query options, and usage examples. ``` -------------------------------- ### Run Unit Tests with Pytest Source: https://github.com/chubin/cheat.sh/blob/master/tests/README.md Execute unit tests using the pytest framework. Ensure pytest is installed and accessible in your environment. ```bash python3 -m pytest -v ../lib/ ``` -------------------------------- ### Get General Help from cheat.sh Source: https://github.com/chubin/cheat.sh/blob/master/share/emacs.txt Retrieves general help information from cheat.sh by querying the ':help' topic. ```emacs-lisp (defun cheat-sh-help () "Get help on using cheat.sh." (interactive) (cheat-sh ":help")) ``` -------------------------------- ### Start cheat.sh in Shell Mode Source: https://github.com/chubin/cheat.sh/blob/master/README.md Launches the cheat.sh client in an interactive shell mode for easier querying. Type 'help' for available commands. ```bash $ cht.sh --shell ``` -------------------------------- ### Install Fish Shell Integration for cheat.sh Source: https://context7.com/chubin/cheat.sh/llms.txt Download the Fish shell integration script to enable cheat.sh functionality in your Fish shell. ```fish curl https://cheat.sh/:fish > ~/.config/fish/functions/cht.fish ``` -------------------------------- ### Schedule Cheat Sheet Updates Source: https://github.com/chubin/cheat.sh/blob/master/doc/standalone.md Set up a cron job to regularly update all cheat sheets. This example updates daily at 5:00 AM local time. ```bash 0 5 0 0 0 $HOME/.cheat.sh/ve/bin/python $HOME/.cheat.sh/lib/fetch.py update-all ``` -------------------------------- ### Install Bash Tab Completion for cheat.sh Source: https://context7.com/chubin/cheat.sh/llms.txt Download and source the bash completion script to enable tab completion for cheat.sh commands in your bash shell. ```bash curl https://cheat.sh/:bash_completion > ~/.bash.d/cht.sh source ~/.bash.d/cht.sh # add to ~/.bashrc ``` -------------------------------- ### cht.sh Stealth Mode Example Source: https://github.com/chubin/cheat.sh/blob/master/README.md Demonstrates the interactive usage of cht.sh in stealth mode, including the 'Q' option for code-only results. This mode is activated by running `cht.sh --shell python` and then entering 'stealth Q'. Selections are used as queries, with longer selections being ignored. ```bash You: Hi! | $ cht.sh --shell python She: Hi! | cht.sh/python> stealth Q She: Are you ready for a small interview? | stealth: you are in the stealth mode; select any text She: Just a couple of questions | stealth: selections longer than 5 words are ignored She: We will talk about python | stealth: query arguments: ?Q She: Let's start from something simple. | stealth: use ^C to leave this mode She: Do you know how to reverse a list in python? | You: Sure | You: (selecting "reverse a list") | stealth: reverse a list | reverse_lst = lst[::-1] You: lst[::-1]? | She: Good. | She: Do you know how to chain a list of lists? | You: (selecting "chain a list of lists") | stealth: chain a list of lists | import itertools | a = [["a","b"], ["c"]] | print list(itertools.chain.from_iterable(a)) You: May I use external modules? | She: What module do you want to use? | You: itertools | She: Yes, you may use it | You: Ok, then: | You: itertools.chain.from_iterable(a) | She: Good. Let's try something harder. | She: What about quicksort implementation? | You: (selecting "quicksort implementation") | stealth: quicksort implementation You: Let me think about it. | (some big and clumsy lowlevel implementation shown) You: Well...(starting typing it in) | def sort(array=[12,4,5,6,7,3,1,15]): | less = [] She: (seeing your ugly pascal style) | equal = [] She: Could you write it more concise? | greater = [] | if len(array) > 1: She: I mean, | pivot = array[0] She: do you really need all these ifs and fors? | for x in array: She: Could you maybe just use filter instead? | if x < pivot: less.append(x) | if x == pivot: equal.append(x) | if x > pivot: greater.append(x) | return sort(less)+equal+sort(greater) You: quicksort with filter? | else: She: Yes | return array You: (selecting "quicksort with filter") | You: Ok, I will try. | You: Something like this? | You: qsort(filter(lt, L[1:]))+[pivot] \ | + qsort(filter(ge, L[1:])) | | She: Yes! Perfect! Exactly what I wanted to see! | | ``` -------------------------------- ### GET /:bash_completion / /:zsh / /:fish — Shell integration scripts Source: https://context7.com/chubin/cheat.sh/llms.txt Returns shell-specific completion and integration scripts for bash, zsh, and fish. ```APIDOC ## GET /:bash_completion / /:zsh / /:fish — Shell integration scripts ### Description Returns shell-specific completion and integration scripts. ### Method GET ### Endpoint `/:bash_completion`, `/:zsh`, or `/:fish` ### Response #### Success Response (200) - **script** (string) - The shell integration script for the requested shell. ``` -------------------------------- ### Self-Host cheat.sh with Docker Compose Source: https://github.com/chubin/cheat.sh/blob/master/README.md Build and run a self-hosted cheat.sh instance using docker-compose.yml. This starts the app and a Redis instance, making the service available at http://localhost:8002. This is an early implementation suitable for development or personal use. ```bash docker-compose up ``` -------------------------------- ### Use cht.sh Client for Queries Source: https://github.com/chubin/cheat.sh/blob/master/share/intro.txt The cht.sh client allows using spaces instead of '+' to separate words in queries. Example: 'python zip lists'. ```bash cht.sh python zip lists ``` -------------------------------- ### Start cht.sh in Shell Mode with Context Source: https://github.com/chubin/cheat.sh/blob/master/share/intro.txt Run the cht.sh client in shell mode, specifying the programming language context (e.g., 'python') to avoid repeating it in subsequent queries. ```bash cht.sh --shell python ``` -------------------------------- ### Ask Programming Language Questions Source: https://github.com/chubin/cheat.sh/blob/master/share/intro.txt Get instant answers to programming language questions using direct curl queries or the cht.sh client. Use '+' for curl and spaces for the client. ```bash curl cht.sh/python/reverse+list ``` ```bash cht.sh/python> reverse list ``` ```bash cht.sh> python reverse list ``` -------------------------------- ### Get List of Topics from cheat.sh Source: https://github.com/chubin/cheat.sh/blob/master/share/emacs.txt Retrieves a list of available topics from cheat.sh. If THING is an empty string, it fetches the global list; otherwise, it fetches topics related to THING. ```emacs-lisp (defun cheat-sh-list (thing) "Get a list of topics available on cheat.sh. Either gets a topic list for subject THING, or simply gets a list of all available topics on cheat.sh if THING is supplied as an empty string.") ``` -------------------------------- ### Show Syntax Highlighting Style Demo Source: https://context7.com/chubin/cheat.sh/llms.txt Request a demo page that showcases the appearance of each available Pygments color style. ```bash curl cht.sh/:styles-demo ``` -------------------------------- ### Get Query Options for cheat.sh Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Appends any configured query options to a given query string. If query options are set, it formats them as a query parameter, handling cases where the query already contains parameters. ```bash get_query_options() { local query="$*" if [ -n "$CHTSH_QUERY_OPTIONS" ]; then case $query in *"?"*) query="$query&${CHTSH_QUERY_OPTIONS}";; *) query="$query?${CHTSH_QUERY_OPTIONS}";; esac fi printf "%s" "$query" } ``` -------------------------------- ### Cloning cheat.sh Repository Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Clones the cheat.sh repository from GitHub into the specified installation directory. ```shell _say_what_i_do Cloning cheat.sh locally local url=https://github.com/chubin/cheat.sh rmdir "$installdir" git clone "$url" "$installdir" || fatal Could not clone "$url" with git into "$installdir" cd "$installdir" || fatal "Cannot cd into $installdir" ``` -------------------------------- ### List Available Syntax Highlighting Styles Source: https://context7.com/chubin/cheat.sh/llms.txt Retrieve a list of all available Pygments color styles supported by the service. ```bash curl cht.sh/:styles ``` -------------------------------- ### Configure Query Options (Custom Syntax Highlighting Theme) Source: https://github.com/chubin/cheat.sh/blob/master/README.md Sets the CHTSH_QUERY_OPTIONS environment variable to 'style=native' to use a specific syntax highlighting theme. Refer to `curl cht.sh/:styles-demo` for available styles. ```bash CHTSH_QUERY_OPTIONS="style=native" ``` -------------------------------- ### Check for rlwrap dependency Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Ensures that 'rlwrap' is installed, which is required for using cht.sh in shell mode for better interactive experience. ```bash command -v rlwrap >/dev/null || { echo 'DEPENDENCY: install "rlwrap" to use cht.sh in the shell mode' >&2; exit 1; } ``` -------------------------------- ### Display Help Information Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Shows the help message for the cht.sh shell, listing available commands and their usage. ```bash cmd_help() { cat < python zip list cht.sh/python> zip list cht.sh/go> /python zip list EOF } ``` -------------------------------- ### List Topics in a Specific Namespace Source: https://context7.com/chubin/cheat.sh/llms.txt Fetch a list of topics that belong to a particular namespace, such as 'go' or 'python'. ```bash curl cht.sh/go/:list ``` ```bash curl cht.sh/python/:list ``` -------------------------------- ### Retrieve Cheat Sheet with Options (No Highlighting) Source: https://context7.com/chubin/cheat.sh/llms.txt Fetch a cheat sheet for a programming language subtopic, disabling syntax highlighting to receive plain text. ```bash curl cht.sh/js/parse+json?T ``` -------------------------------- ### HTTP GET Request Function Source: https://github.com/chubin/cheat.sh/blob/master/share/static/1.html Defines a synchronous XMLHttpRequest function to fetch data from a URL. Ensure the URL is valid and accessible. ```javascript function httpGet(theUrl) { var xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", theUrl, false ); // false for synchronous request xmlHttp.send( null ); return xmlHttp.responseText; }; ``` -------------------------------- ### Combine Cheat Sheet Options Source: https://context7.com/chubin/cheat.sh/llms.txt Fetch a cheat sheet for a programming language subtopic, combining multiple options like disabling comments and syntax highlighting. ```bash curl "cht.sh/lua/merge+tables?QT" ``` -------------------------------- ### Disable Initial Help Message Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Disables the initial 'use help' message that appears when starting the cht.sh shell by creating a .hushlogin file. ```bash cmd_hush() { mkdir -p "$CHTSH_HOME/" && touch "$CHTSH_HOME/.hushlogin" && echo "Initial 'use help' message was disabled" ``` -------------------------------- ### Generate Cheat Sheets On-the-Fly Source: https://github.com/chubin/cheat.sh/blob/master/README.md For queries without existing cheat sheets, the service generates answers dynamically from available resources like StackOverflow. ```bash curl cht.sh/go/reverse+a+list curl cht.sh/python/random+list+elements curl cht.sh/js/parse+json curl cht.sh/lua/merge+tables curl cht.sh/clojure/variadic+function ``` -------------------------------- ### Execute a Query Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Prepares and executes a query against the cht.sh service. ```bash cmd_query() { query=$(prepare_query "$section" "$input") do_query "$query" } ``` -------------------------------- ### Docker Deployment for cheat.sh Source: https://context7.com/chubin/cheat.sh/llms.txt Deploy cheat.sh using Docker. Recommended method is docker-compose up. Manual image building and running with custom configurations are also supported. ```bash # Build and run with docker-compose (recommended) docker-compose up # Service available at http://localhost:8002 # Build image manually docker build -t cheatsh . # Run with custom config docker run -p 8002:8002 \ -e CHEATSH_CACHE_TYPE=none \ -e CHEATSH_SERVER_PORT=8002 \ cheatsh # Debug mode docker-compose -f docker-compose.debug.yml up ``` -------------------------------- ### Retrieve Shell Integration Scripts Source: https://context7.com/chubin/cheat.sh/llms.txt Fetch shell-specific completion and integration scripts for bash, zsh, or fish. ```bash curl cht.sh/:bash_completion ``` ```bash curl cht.sh/:zsh ``` ```bash curl cht.sh/:fish ``` -------------------------------- ### GET /:random — Random cheat sheet Source: https://context7.com/chubin/cheat.sh/llms.txt Returns a randomly selected cheat sheet topic. The selection can optionally be scoped to a specific namespace. ```APIDOC ## GET /:random — Random cheat sheet ### Description Returns a randomly selected cheat sheet topic, optionally scoped to a namespace prefix. ### Method GET ### Endpoint `/:random` ### Parameters #### Path Parameters - **namespace** (string) - Optional - The namespace to scope the random topic selection to (e.g., `go/`, `python/`). ### Request Example ```bash # Random topic from anywhere curl cht.sh/:random # Random topic in the go/ namespace curl cht.sh/go/:random # Random topic in the python/ namespace curl cht.sh/python/:random ``` ### Response #### Success Response (200) - **cheat_sheet** (string) - The content of a randomly selected cheat sheet. ``` -------------------------------- ### Build Docker Image Source: https://github.com/chubin/cheat.sh/blob/master/doc/standalone.md Build the Docker image for cheat.sh using the Dockerfile located in the source root directory. ```bash docker build . ``` -------------------------------- ### List All Available Topics using get_topics_list Source: https://context7.com/chubin/cheat.sh/llms.txt Call get_topics_list to retrieve a sorted list of all available topic strings. Options are available to skip internal or directory-style topics. ```python # List all available topics topics = get_topics_list() # Returns: sorted list of all topic strings, e.g. ["awk", "bash", "go/channels", ...] # Skip internal and directory-style topics topics = get_topics_list(skip_dirs=True, skip_internal=True) ``` -------------------------------- ### Get UNIX/Linux Command Cheat Sheets with Curl Source: https://github.com/chubin/cheat.sh/blob/master/README.md Use curl to query cheat.sh with the command name. Supports both HTTP/HTTPS and short/long service names. ```bash curl cheat.sh/tar curl cht.sh/curl curl https://cheat.sh/rsync curl https://cht.sh/tr ``` -------------------------------- ### Configure Curl Options for cht.sh Source: https://github.com/chubin/cheat.sh/blob/master/README.md Sets the CHTSH_CURL_OPTIONS environment variable to customize curl options used for cht.sh queries. Example sets the User-Agent string. ```bash CHTSH_CURL_OPTIONS="-A curl" ``` -------------------------------- ### Prepare a Query String Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Formats a query string for the cheat.sh service. It combines a section and input, replacing spaces with '+' for URL encoding. It also appends any provided arguments as a query string. ```bash prepare_query() { local section="$1"; shift local input="$1"; shift local arguments="$1" local query if [ -z "$section" ] || [ x"${input}" != x"${input#/}" ]; then query=$(printf %s "$input" | sed 's@ @/@; s@ @+@g') else query=$(printf %s "$section/$input" | sed 's@ @+@g') fi [ -n "$arguments" ] && arguments="?$arguments" printf %s "$query$arguments" } ``` -------------------------------- ### Config / CONFIG Source: https://context7.com/chubin/cheat.sh/llms.txt Provides a configuration system that layers settings from defaults, YAML files, and environment variables. It resolves relative paths against the working directory. ```APIDOC ## `Config` / `CONFIG` — Configuration system ### Description `lib/config.py` exports a `Config` dict subclass that auto-resolves relative paths against `path.workdir`. Configuration is layered: defaults → project `etc/config.yaml` → workdir `etc/config.yaml` → environment variables prefixed with `CHEATSH_`. ### Accessing Configuration The `CONFIG` object is a dictionary-like interface to access configuration values. ### Example Usage ```python from config import CONFIG # Read configuration values print(CONFIG["server.port"]) print(CONFIG["cache.type"]) print(CONFIG["cache.redis.host"]) print(CONFIG["search.limit"]) print(CONFIG["upstream.url"]) print(CONFIG["path.repositories"]) print(CONFIG["adapters.active"]) ``` ### Configuration Layering and Overrides Configuration values can be overridden through environment variables or YAML files. **Environment Variables:** Prefix with `CHEATSH_`, and dots in keys become underscores. Example: `CHEATSH_SERVER_PORT=9000` `CHEATSH_CACHE_TYPE=none` `CHEATSH_UPSTREAM_URL=http://localhost:8002` `CHEATSH_PATH_WORKDIR=/opt/cheatsh` **YAML Files (`etc/config.yaml`):** Supports nested or dot-key notation. Example: ```yaml server: port: 9000 cache: type: none redis: host: redis-host port: 6379 upstream: url: "https://cheat.sh" timeout: 10 search: limit: 50 ``` ``` -------------------------------- ### GET /:list — List all available topics Source: https://context7.com/chubin/cheat.sh/llms.txt Retrieves a newline-delimited list of all cheat sheet topics known to the server. This list can be scoped to a specific namespace. ```APIDOC ## GET /:list — List all available topics ### Description Returns a newline-delimited list of all cheat sheet topics known to the server. Can be scoped to a namespace. ### Method GET ### Endpoint `/:list` ### Parameters #### Path Parameters - **namespace** (string) - Optional - The namespace to scope the topic list to (e.g., `go/`, `python/`). ### Request Example ```bash # All topics curl cht.sh/:list # Topics in the go/ namespace only curl cht.sh/go/:list # Topics in the python/ namespace curl cht.sh/python/:list ``` ### Response #### Success Response (200) - **topics** (string) - A newline-delimited list of available topics. ``` -------------------------------- ### Check for copy command dependencies Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Checks for the availability of clipboard copy tools ('wl-copy' for Wayland or 'xsel' for X11) on non-macOS systems. It prints a dependency message if the tool is not found. ```bash if [ "$is_macos" != yes ]; then if [ "$XDG_SESSION_TYPE" = wayland ]; then command -v wl-copy >/dev/null || echo 'DEPENDENCY: please install "wl-copy" for "copy"' >&2 else command -v xsel >/dev/null || echo 'DEPENDENCY: please install "xsel" for "copy"' >&2 fi fi ``` -------------------------------- ### Contribute Cheat Sheet with Git Source: https://github.com/chubin/cheat.sh/blob/master/share/post.txt Contribute a cheat sheet by cloning the repository, copying your cheat sheet, staging, committing, and pushing the changes. A pull request is then sent for review. ```bash # clone chubin/cheat.sheets git pull https://github.com/${you}/cheat.sheets && cd cheat.sheets cp ${cheatsheet} newcmd git add newcmd git commit -m 'added newcmd cheat sheet' newcmd git push # send pull request ``` -------------------------------- ### Retrieve ANSI-formatted Answer using cheat_wrapper Source: https://context7.com/chubin/cheat.sh/llms.txt Call the cheat_wrapper function with a query to get an ANSI-formatted code snippet. The function returns the answer and a boolean indicating if it was found. ```python # lib/cheat_wrapper.py from cheat_wrapper import cheat_wrapper # Retrieve ANSI-formatted answer for a shell query answer, found = cheat_wrapper("python/list comprehension") print(answer) # Output: ANSI-colored code snippet ``` -------------------------------- ### Select Alternative Answers Source: https://github.com/chubin/cheat.sh/blob/master/README.md If an answer is not satisfactory, append '/1', '/2', etc., to the query to retrieve alternative responses. ```bash curl cht.sh/python/random+string curl cht.sh/python/random+string/1 curl cht.sh/python/random+string/2 ``` -------------------------------- ### Basic Loop in ABAP Source: https://github.com/chubin/cheat.sh/blob/master/share/styles-demo.txt Demonstrates a simple for loop in ABAP. This syntax is used for iterating over a range of numbers. ```abap for i in 1 2 3 4 5 6 7 8 9 10 do echo $i done ``` -------------------------------- ### Get a Random Topic using get_answers Source: https://context7.com/chubin/cheat.sh/llms.txt Retrieve a random entry for a given topic by appending '/:random' to the topic name when calling get_answers. The topic will be replaced before dispatch. ```python # Random topic answers = get_answers("go/:random") # topic is replaced with a random go/ entry before dispatch ``` -------------------------------- ### Get Answers for a Specific Topic using get_answers Source: https://context7.com/chubin/cheat.sh/llms.txt Call the get_answers function with a topic string to retrieve a list of answer dictionaries. This function handles routing to the appropriate adapter. ```python from routing import get_answers, get_topics_list # Get answers for a topic (returns list of answer dicts) answers = get_answers("python/zip") # Returns: [{"topic": "python/zip", "topic_type": "cheat.sheets", # "format": "code", "answer": "...", "cache": True}] ``` -------------------------------- ### GitRepositoryAdapter for Git-Backed Cheat Sheets Source: https://context7.com/chubin/cheat.sh/llms.txt Implement GitRepositoryAdapter for Git-hosted cheat sheet sources. Subclasses must define repository URL, file prefix, and extension. Provides commands for fetching, updating, and cache invalidation. ```python from adapter.git_adapter import GitRepositoryAdapter # Example custom adapter subclass class MyCheatAdapter(GitRepositoryAdapter): _adapter_name = "mycheat" _output_format = "code" _cache_needed = True _repository_url = "https://github.com/example/my-cheat-sheets" _cheatsheet_files_prefix = "sheets/" _cheatsheet_files_extension = ".md" adapter = MyCheatAdapter() # Get clone command for initial setup print(adapter.fetch_command()) # ["git", "clone", "--depth=1", # "https://github.com/example/my-cheat-sheets", # "/home/user/.cheat.sh/upstream/my-cheat-sheets"] # Get pull command for updates print(adapter.update_command()) # ["git", "pull"] # Get revision hash command (for cache invalidation) print(adapter.current_state_command()) # ["git", "rev-parse", "--short", "HEAD", "--"] # Get list of changed files since last cached state print(adapter.get_updates_list_command()) # ["git", "diff", "--name-only", "", "HEAD", "--"] ``` -------------------------------- ### Retrieve Raw JSON Answer using cheat_wrapper Source: https://context7.com/chubin/cheat.sh/llms.txt Call cheat_wrapper with output_format='json' to get a JSON object containing all answer metadata, including the query, topic, and the answer content. ```python # Get raw JSON with all answer metadata json_answer, found = cheat_wrapper("go/goroutines", output_format="json") # json_answer contains: # { # "query": "go/goroutines", # "keyword": null, # "answers": [ # { # "topic": "go/goroutines", # "topic_type": "cheat.sheets", # "format": "code", # "answer": "...", # "cache": true # } # ] # } ``` -------------------------------- ### Retrieve Cheat Sheet with Options (No Comments) Source: https://context7.com/chubin/cheat.sh/llms.txt Fetch a cheat sheet for a programming language subtopic, disabling comments to show plain code only. ```bash curl cht.sh/python/lambda?Q ``` -------------------------------- ### Run Self-Tests for cheat.sh Source: https://github.com/chubin/cheat.sh/blob/master/share/cht.sh.txt Executes the self-tests for the cheat.sh installation. It sets specific environment variables to control the test behavior and logs the output. If tests fail, it provides instructions for manual re-running. ```bash CHEATSH_TEST_STANDALONE=YES \ CHEATSH_TEST_SKIP_ONLINE=NO \ CHEATSH_TEST_SHOW_DETAILS=NO \ PYTHON=../ve/bin/python bash run-tests.sh | tee -a "$LOG" ```