1
1
mirror of https://github.com/chubin/cheat.sh.git synced 2024-11-22 01:40:48 +03:00

Merge branch 'master' into chubin.devkeys

This commit is contained in:
Igor Chubin 2021-04-25 12:19:31 +00:00
commit 60cc9faf39
8 changed files with 119 additions and 81 deletions

View File

@ -1,4 +1,5 @@
![cheat.sh logo](http://cheat.sh/files/big-logo-v2-fixed.png)
Unified access to the best community driven cheat sheets repositories of the world.
@ -15,7 +16,7 @@ What features should it have?
* **Tutoring** — It should help you to learn the subject.
* **Inconspicuous** — It should be possible to use it completely unnoticed.
Such a thing exists.
Such a thing exists! It's easy to [install](#installation) and there's even [auto-complete](#tab-completion).
## Features
@ -43,7 +44,10 @@ Such a thing exists.
* [Installation](#installation)
* [Client usage](#client-usage)
* [Tab-completion](#tab-completion)
- [Bash Tab completion](#bash-tab-completion)
- [ZSH Tab completion](#zsh-tab-completion)
* [Stealth mode](#stealth-mode)
* [Windows command line client](#windows-command-line-client)
* [Self-Hosting](#self-hosting)
* [Docker](#docker)
* [Editors integration](#editors-integration)
@ -187,6 +191,8 @@ Try your own queries. Follow these rules:
Read more about the programming languages queries below.
----
## Command line client, cht.sh
The cheat.sh service has its own command line client (`cht.sh`) that
@ -202,17 +208,18 @@ has several useful features compared to querying the service directly with `curl
To install the client:
```
mkdir -p ~/bin/
curl https://cht.sh/:cht.sh > ~/bin/cht.sh
chmod +x ~/bin/cht.sh
```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"
```
or to install it globally (for all users):
```
curl https://cht.sh/:cht.sh | sudo tee /usr/local/bin/cht.sh
chmod +x /usr/local/bin/cht.sh
```bash
curl https://cht.sh/:cht.sh | sudo tee /usr/local/bin/cht.sh
chmod +x /usr/local/bin/cht.sh
```
Note: The package "rlwrap" is a required dependency to run in shell mode. Install this using `sudo apt install rlwrap`
@ -300,13 +307,13 @@ Use it to specify query options that you would use with each query.
For example, to switch syntax highlighting off create the file with the following
content:
```
```bash
CHTSH_QUERY_OPTIONS="T"
```
Or if you want to use a special syntax highlighting theme:
```
```bash
CHTSH_QUERY_OPTIONS="style=native"
```
@ -314,7 +321,7 @@ CHTSH_QUERY_OPTIONS="style=native"
Other cht.sh configuration parameters:
```
```bash
CHTSH_CURL_OPTIONS="-A curl" # curl options used for cht.sh queries
CHTSH_URL=https://cht.sh # URL of the cheat.sh server
```
@ -326,21 +333,23 @@ CHTSH_URL=https://cht.sh # URL of the cheat.sh server
To activate tab completion support for `cht.sh`, add the `:bash_completion` script to your `~/.bashrc`:
```
$ curl https://cheat.sh/:bash_completion > ~/.bash.d/cht.sh
$ . ~/.bash.d/cht.sh
$ # and add . ~/.bash.d/cht.sh to ~/.bashrc
```bash
curl https://cheat.sh/:bash_completion > ~/.bash.d/cht.sh
. ~/.bash.d/cht.sh
# and add . ~/.bash.d/cht.sh to ~/.bashrc
```
#### ZSH Tab completion
To activate tab completion support for `cht.sh`, add the `:zsh` script to the *fpath* in your `~/.zshrc`:
```zsh
curl https://cheat.sh/:zsh > ~/.zsh.d/_cht
echo 'fpath=(~/.zsh.d/ $fpath)' >> ~/.zshrc
# Open a new shell to load the plugin
```
$ curl https://cheat.sh/:zsh > ~/.zsh.d/_cht
$ echo 'fpath=(~/.zsh.d/ $fpath)' >> ~/.zshrc
$ # Open a new shell to load the plugin
```
----
### Stealth mode
@ -442,6 +451,8 @@ You can also use [`scoop`](https://github.com/lukesampson/scoop) command-line in
scoop install cht
```
----
## Self-Hosting
### Docker
@ -529,7 +540,7 @@ In this example, several Vim plugins are used:
* [scrooloose/syntastic](https://github.com/vim-syntastic/syntastic) — Syntax checking plugin
* [cheat.sh-vim](https://github.com/dbeniamine/cheat.sh-vim) — Vim support
Syntastic shows warnings and errors (found by code analysis tools: `jshint`, `merlin`, `pylint`, `shellcheckt etc.),
Syntastic shows warnings and errors (found by code analysis tools: `jshint`, `merlin`, `pylint`, `shellcheck` etc.),
and `cheat.sh-vim` shows you explanations for the errors and warnings
and answers on programming languages queries written in the editor.
@ -813,15 +824,17 @@ and information sources, maintained by thousands of users, developers and author
all over the world
(in the *Users* column number of contributors/number of stars is shown):
|Cheat sheets |Repository | Users | Creation Date |
|-----------------------|------------------------------------------------------|------------|---------------|
|UNIX/Linux, programming|[cheat.sheets](https://github.com/chubin/cheat.sheets)| 38/223 | May 1, 2017 |
|UNIX/Linux commands |[tldr-pages/tldr](https://github.com/tldr-pages/tldr) | 760/23158 | Dec 8, 2013 |
|UNIX/Linux commands |[chrisallenlane/cheat](https://github.com/chrisallenlane/cheat)|131/5240|Jul 28, 2013|
|Programming languages |[adambard/learnxinyminutes-docs](https://github.com/adambard/learnxinyminutes-docs)|1246/6748|Jun 23, 2013|
|Go |[a8m/go-lang-cheat-sheet](https://github.com/a8m/go-lang-cheat-sheet)|31/4039|Feb 9, 2014|
|Perl |[pkrumnis/perl1line.txt](https://github.com/pkrumins/perl1line.txt)|5/190|Nov 4, 2011|
|Programming languages |[StackOverflow](https://stackoverflow.com)|9M |Sep 15, 2008|
|Cheat sheets |Repository |C/U* |Stars |Creation Date|
|-----------------------|------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|-------------|
|UNIX/Linux, programming|[cheat.sheets](https://github.com/chubin/cheat.sheets) |![](https://img.shields.io/github/contributors-anon/chubin/cheat.sheets?label=%F0%9F%91%A5&labelColor=white) |![](https://img.shields.io/github/stars/chubin/cheat.sheets?label=%E2%AD%90&labelColor=white) |May 1, 2017 |
|UNIX/Linux commands |[tldr-pages/tldr](https://github.com/tldr-pages/tldr) |![](https://img.shields.io/github/contributors-anon/tldr-pages/tldr?label=%F0%9F%91%A5&labelColor=white) |![](https://img.shields.io/github/stars/tldr-pages/tldr?label=%E2%AD%90&labelColor=white) |Dec 8, 2013 |
|UNIX/Linux commands |[chrisallenlane/cheat](https://github.com/chrisallenlane/cheat) |![](https://img.shields.io/github/contributors-anon/chrisallenlane/cheat?label=%F0%9F%91%A5&labelColor=white) |![](https://img.shields.io/github/stars/chrisallenlane/cheat?label=%E2%AD%90&labelColor=white) |Jul 28, 2013 |
|Programming languages |[adambard/learnxinyminutes-docs](https://github.com/adambard/learnxinyminutes-docs) |![](https://img.shields.io/github/contributors-anon/adambard/learnxinyminutes-docs?label=%F0%9F%91%A5&labelColor=white)|![](https://img.shields.io/github/stars/adambard/learnxinyminutes-docs?label=%E2%AD%90&labelColor=white)|Jun 23, 2013 |
|Go |[a8m/go-lang-cheat-sheet](https://github.com/a8m/go-lang-cheat-sheet) |![](https://img.shields.io/github/contributors-anon/a8m/go-lang-cheat-sheet?label=%F0%9F%91%A5&labelColor=white) |![](https://img.shields.io/github/stars/a8m/go-lang-cheat-sheet?label=%E2%AD%90&labelColor=white) |Feb 9, 2014 |
|Perl |[pkrumnis/perl1line.txt](https://github.com/pkrumins/perl1line.txt) |![](https://img.shields.io/github/contributors-anon/pkrumins/perl1line.txt?label=%F0%9F%91%A5&labelColor=white) |![](https://img.shields.io/github/stars/pkrumins/perl1line.txt?label=%E2%AD%90&labelColor=white) |Nov 4, 2011 |
|Programming languages |[StackOverflow](https://stackoverflow.com) |[14M](https://stackexchange.com/leagues/1/alltime/stackoverflow) |N/A |Sep 15, 2008 |
<sup>(*) C/U — contributors for GitHub repositories, Users for Stackoverflow</sup>
Pie diagram reflecting cheat sheets sources distribution (by number of cheat sheets on cheat.sh originating from a repository):

View File

@ -134,7 +134,7 @@ class GitRepositoryAdapter(RepositoryAdapter): #pylint: disable=abstract-meth
"""
local_repository_dir = cls.local_repository_location()
state_filename = os.path.join(local_repository_dir, '.cached_revision')
open(state_filename, 'w').write(state)
open(state_filename, 'wb').write(state)
@classmethod
def get_state(cls):

View File

@ -136,6 +136,7 @@ def _update_adapter(adptr):
updates = []
if cmd:
errorcode, output = _run_cmd(cmd)
output = output.decode("utf-8")
if errorcode:
_log("\nERROR:\n---\n" + output + "\n---\nCould not get list of pages to be updated: %s" % adptr)
return False

View File

@ -96,7 +96,7 @@ def _render_html(query, result, editable, repository_button, topics_list, reques
curl_line = "<span class='pre'>$ curl cheat.sh/</span>"
if query == ':firstpage':
query = ""
form_html = ('<form action="/" method="GET"/>'
form_html = ('<form action="/" method="GET">'
'%s%s'
'<input'
' type="text" value="%s" name="topic"'

View File

@ -24,8 +24,8 @@
# count words in text counter
# group elements list
__CHTSH_VERSION=0.0.1
__CHTSH_DATETIME="2020-08-05 09:30:30 +0200"
__CHTSH_VERSION=0.0.4
__CHTSH_DATETIME="2021-04-25 12:30:30 +0200"
# cht.sh configuration loading
#
@ -199,8 +199,8 @@ EOF
fi
_say_what_i_do Creating virtual environment
"$python" "$(command -v virtualenv)" "${virtualenv_python3_option[@]}" ve \
|| fatal Could not create virtual environment with "python2 $(command -v virtualenv) ve"
virtualenv "${virtualenv_python3_option[@]}" ve \
|| fatal "Could not create virtual environment with 'virtualenv ve'"
export CHEATSH_PATH_WORKDIR=$PWD
@ -514,7 +514,11 @@ else
fi
if [ "$is_macos" != yes ]; then
command -v xsel >/dev/null || echo 'DEPENDENCY: please install "xsel" for "copy"' >&2
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
command -v rlwrap >/dev/null || { echo 'DEPENDENCY: install "rlwrap" to use cht.sh in the shell mode' >&2; exit 1; }
@ -562,7 +566,11 @@ cmd_copy() {
else
curl -s "${CHTSH_URL}"/"$(get_query_options "$query"?T)" > "$TMP1"
if [ "$is_macos" != yes ]; then
xsel -bi < "$TMP1"
if [ "$XDG_SESSION_TYPE" = wayland ]; then
wl-copy < "$TMP1"
else
xsel -bi < "$TMP1"
fi
else
pbcopy < "$TMP1"
fi
@ -578,7 +586,11 @@ cmd_ccopy() {
else
curl -s "${CHTSH_URL}"/"$(get_query_options "$query"?TQ)" > "$TMP1"
if [ "$is_macos" != yes ]; then
xsel -bi < "$TMP1"
if [ "$XDG_SESSION_TYPE" = wayland ]; then
wl-copy < "$TMP1"
else
xsel -bi < "$TMP1"
fi
else
pbcopy < "$TMP1"
fi
@ -674,7 +686,11 @@ cmd_stealth() {
if [ "$is_macos" = yes ]; then
past=$(pbpaste)
else
past=$(xsel -o)
if [ "$XDG_SESSION_TYPE" = wayland ]; then
past=$(wl-paste -p)
else
past=$(xsel -o)
fi
fi
printf "\033[0;31mstealth:\033[0m you are in the stealth mode; select any text in any window for a query\n"
printf "\033[0;31mstealth:\033[0m selections longer than $STEALTH_MAX_SELECTION_LENGTH words are ignored\n"
@ -686,13 +702,17 @@ cmd_stealth() {
if [ "$is_macos" = yes ]; then
current=$(pbpaste)
else
current=$(xsel -o)
if [ "$XDG_SESSION_TYPE" = wayland ]; then
current=$(wl-paste -p)
else
current=$(xsel -o)
fi
fi
if [ "$past" != "$current" ]; then
past=$current
current_text="$(echo $current | tr -c '[a-zA-Z0-9]' ' ')"
if [ "$(echo "$current_text" | wc -w)" -gt "$STEALTH_MAX_SELECTION_LENGTH" ]; then
echo "\033[0;31mstealth:\033[0m selection length is longer than $STEALTH_MAX_SELECTION_LENGTH words; ignoring"
printf "\033[0;31mstealth:\033[0m selection length is longer than $STEALTH_MAX_SELECTION_LENGTH words; ignoring\n"
continue
else
printf "\n\033[0;31mstealth: \033[7m $current_text\033[0m\n"

View File

@ -1,7 +1,7 @@
Usage:
$ curl cheat.sh/TOPIC show cheat sheet on the TOPIC
$ curl cheat.sh/TOPIC/SUB show cheat sheet on the SUB topic in TOPIC
$ curl cheat.sh/TOPIC show cheat sheet on the TOPIC
$ curl cheat.sh/TOPIC/SUB show cheat sheet on the SUB topic in TOPIC
$ curl cheat.sh/~KEYWORD search cheat sheets for KEYWORD
Options:
@ -19,7 +19,7 @@ Options:
Options can be combined together in this way:
curl 'cheat.sh/for?qT&style=bw'
(when using & in shell, don't forget to specify the quotes or escape & with \)
Special pages:
@ -54,7 +54,7 @@ Editor integration:
Search:
/~snapshot look for "snapshot" in the first level cheat sheets
/~snapshot look for "snapshot" in the first level cheat sheets
/~ssh~passphrase several keywords can be combined together using ~
/scala/~closure look for "closure" in scala cheat sheets
/~snapshot/r look for "snapshot" in all cheat sheets recursively
@ -71,17 +71,9 @@ List of search options:
Programming languages topics:
each programming language topic has the following subptopics:
Each programming language topic has the following subtopics:
hello hello world + how to start the program
:learn big cheat sheet for learning language from scratch
:list list of topics
:list list of topics
:random fetches a random cheat sheet belonging to the topic
Support programming languages:
go
scala
rust
python
php

View File

@ -1,7 +1,7 @@
Usage:
$ curl cheat.sh/TOPIC show cheat sheet on the TOPIC
$ curl cheat.sh/TOPIC/SUB show cheat sheet on the SUB topic in TOPIC
$ curl cheat.sh/TOPIC show cheat sheet on the TOPIC
$ curl cheat.sh/TOPIC/SUB show cheat sheet on the SUB topic in TOPIC
$ curl cheat.sh/~KEYWORD search cheat sheets for KEYWORD
Options:
@ -19,7 +19,7 @@ Options:
Options can be combined together in this way:
curl 'cheat.sh/for?qT&style=bw'
(when using & in shell, don't forget to specify the quotes or escape & with \)
Special pages:
@ -54,7 +54,7 @@ Editor integration:
Search:
/~snapshot look for "snapshot" in the first level cheat sheets
/~snapshot look for "snapshot" in the first level cheat sheets
/~ssh~passphrase several keywords can be combined together using ~
/scala/~closure look for "closure" in scala cheat sheets
/~snapshot/r look for "snapshot" in all cheat sheets recursively
@ -71,17 +71,9 @@ List of search options:
Programming languages topics:
each programming language topic has the following subptopics:
Each programming language topic has the following subtopics:
hello hello world + how to start the program
:learn big cheat sheet for learning language from scratch
:list list of topics
:list list of topics
:random fetches a random cheat sheet belonging to the topic
Support programming languages:
go
scala
rust
python
php

View File

@ -24,8 +24,8 @@
# count words in text counter
# group elements list
__CHTSH_VERSION=0.0.1
__CHTSH_DATETIME="2020-08-05 09:30:30 +0200"
__CHTSH_VERSION=0.0.4
__CHTSH_DATETIME="2021-04-25 12:30:30 +0200"
# cht.sh configuration loading
#
@ -199,8 +199,8 @@ EOF
fi
_say_what_i_do Creating virtual environment
"$python" "$(command -v virtualenv)" "${virtualenv_python3_option[@]}" ve \
|| fatal Could not create virtual environment with "python2 $(command -v virtualenv) ve"
virtualenv "${virtualenv_python3_option[@]}" ve \
|| fatal "Could not create virtual environment with 'virtualenv ve'"
export CHEATSH_PATH_WORKDIR=$PWD
@ -514,7 +514,11 @@ else
fi
if [ "$is_macos" != yes ]; then
command -v xsel >/dev/null || echo 'DEPENDENCY: please install "xsel" for "copy"' >&2
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
command -v rlwrap >/dev/null || { echo 'DEPENDENCY: install "rlwrap" to use cht.sh in the shell mode' >&2; exit 1; }
@ -562,7 +566,11 @@ cmd_copy() {
else
curl -s "${CHTSH_URL}"/"$(get_query_options "$query"?T)" > "$TMP1"
if [ "$is_macos" != yes ]; then
xsel -bi < "$TMP1"
if [ "$XDG_SESSION_TYPE" = wayland ]; then
wl-copy < "$TMP1"
else
xsel -bi < "$TMP1"
fi
else
pbcopy < "$TMP1"
fi
@ -578,7 +586,11 @@ cmd_ccopy() {
else
curl -s "${CHTSH_URL}"/"$(get_query_options "$query"?TQ)" > "$TMP1"
if [ "$is_macos" != yes ]; then
xsel -bi < "$TMP1"
if [ "$XDG_SESSION_TYPE" = wayland ]; then
wl-copy < "$TMP1"
else
xsel -bi < "$TMP1"
fi
else
pbcopy < "$TMP1"
fi
@ -674,7 +686,11 @@ cmd_stealth() {
if [ "$is_macos" = yes ]; then
past=$(pbpaste)
else
past=$(xsel -o)
if [ "$XDG_SESSION_TYPE" = wayland ]; then
past=$(wl-paste -p)
else
past=$(xsel -o)
fi
fi
printf "\033[0;31mstealth:\033[0m you are in the stealth mode; select any text in any window for a query\n"
printf "\033[0;31mstealth:\033[0m selections longer than $STEALTH_MAX_SELECTION_LENGTH words are ignored\n"
@ -686,13 +702,17 @@ cmd_stealth() {
if [ "$is_macos" = yes ]; then
current=$(pbpaste)
else
current=$(xsel -o)
if [ "$XDG_SESSION_TYPE" = wayland ]; then
current=$(wl-paste -p)
else
current=$(xsel -o)
fi
fi
if [ "$past" != "$current" ]; then
past=$current
current_text="$(echo $current | tr -c '[a-zA-Z0-9]' ' ')"
if [ "$(echo "$current_text" | wc -w)" -gt "$STEALTH_MAX_SELECTION_LENGTH" ]; then
echo "\033[0;31mstealth:\033[0m selection length is longer than $STEALTH_MAX_SELECTION_LENGTH words; ignoring"
printf "\033[0;31mstealth:\033[0m selection length is longer than $STEALTH_MAX_SELECTION_LENGTH words; ignoring\n"
continue
else
printf "\n\033[0;31mstealth: \033[7m $current_text\033[0m\n"