Cheat sheet -----几乎所有编程语言的速查表

偶然发现一个比较好用的工具,可以用它作为学习任何一门编程语言reminder。

cheat.sh

这就是要介绍的主角了。不需要安装,只要联网且有http服务就可以岁时查询任何编程语言的一些语法和关键字。

cheat.sh的四种格式:
    curl cheat.sh/tar
    curl cht.sh/curl
    curl https://cheat.sh/rsync
    curl https://cht.sh/tr

这里写图片描述

用法:curl+cht.sh/编程语言名称/需要查询的关键字或者问题
举个例子:
    curl cht.sh/go/Pointers     ##查询go语言中指针
    [root@79 Desktop]# curl cht.sh/go/Pointers
p := Vertex{1, 2}  // p is a Vertex
q := &p            // q is a pointer to a Vertex
r := &Vertex{1, 2} // r is also a pointer to a Vertex

// The type of a pointer to a Vertex is *Vertex
// new creates a pointer to a new struct instance

    curl cht.sh/scala/Functions    ##scala语言中函数用法
    curl cht.sh/python/lambda      ##python中lamba函数
[root@79 Desktop]# curl cht.sh/python
# Python is a high-level programming language
# and python is a Python interpreter.

#   Python language cheat sheets at /python/
#   list of pages:      /python/:list     ##python中可查询的列表
#   learn python:       /python/:learn    ##python基本语法
#   search in pages:    /python/~keyword  ##关键字
如果想要查询具体怎么操作,就需要添加问题:
Example:
    curl cht.sh/go/reverse+a+list      ##怎样反转数组
    curl cht.sh/python/random+list+elements   #怎样在列表中随机选取元素

import random
foo = ['a', 'b', 'c', 'd', 'e']
print(random.choice(foo))

    curl cht.sh/js/parse+json
    curl cht.sh/lua/merge+tables      ##在lua中合并列表
    curl cht.sh/clojure/variadic+function  
如果查询内容不满意,可以看一些extended explanation.
    curl cht.sh/python/random+string
    curl cht.sh/python/random+string/1
    curl cht.sh/python/random+string/2

当然,为了更详细地解释查询内容,cheet sheets 中既有示例的代码,也有一些text comments。如果不喜欢的话,在命令后添加’?Q’就行。

    $ curl cht.sh/lua/table+keys?Q
    local keyset={}
    local n=0

    for k,v in pairs(tab) do
      n=n+1
      keyset[n]=k
    end

而且一般变量都会被高亮,’?T’可以去除高亮。

    curl cht.sh/lua/merge+tables?QT

cht.sh

cheat.sh 服务有自己专有的使用命令,就是cht.sh。

用这个命令有什么好处呢?
  • Special shell mode with a persistent queries context and readline support.
  • Queries history.
  • Clipboard integration.
  • Tab completion support for shells (bash, fish, zsh).
  • Stealth mode. (匿名模式)

首先安装一下:

    curl https://cht.sh/:cht.sh > /bin/cht.sh
    chmod +x /bin/cht.sh

安装以后,就不需要再使用curl了,极大简化了查询的命令。

    $ cht.sh go reverse a list
    $ cht.sh python random list elements
    $ cht.sh js parse json
如果还要更方便的话,可以进入shell模式,便捷查询。
    $ cht.sh --shell
    cht.sh> go reverse a list
切换到go语言查询
    $ cht.sh --shell
    cht.sh> cd go
    cht.sh/go> reverse a list
或者:
    $ cht.sh --shell go
    cht.sh/go> reverse a list
    ...
    cht.sh/go> join a list
    ...

SHELL中自动补齐

Bash Tab completion

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

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

安装是出现了一个小问题还没解决

[root@79 Desktop]# cht.sh --shell
DEPENDENCY: please install "xsel" for "copy"
DEPENDENCY: install "rlwrap" to use cht.sh in the shell mode

猜你喜欢

转载自blog.csdn.net/qq_36747237/article/details/81111906