33

给大家推荐两个小工具

 5 years ago
source link: https://mp.weixin.qq.com/s?__biz=MzU3NDQxNTQ1Mw%3D%3D&%3Bmid=2247483911&%3Bidx=1&%3Bsn=db3553e1689a135b6c2cf58237167017&%3Bchksm=fd33f535ca447c23307e590d5ee9b6cd7bbe5f98deec4b44e697f5f0b22dac921d3c47f
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

第一个 cheat.sh

NNnueiQ.jpg!web

这个工具是干什么用的呢?在之前的一篇文章里我们提到:做软链接的时候,如果不知道参数顺序会随手看一下 man ln。但是看了手册之后并没有带来多大的帮助。cheat.sh就是来解决这个问题的。虽然cheat.sh也是提供手册服务,但是他的手册是提供了命令常用的例子。所以cheat.sh提供的文档更加实用,帮助也更直接。

fyEfqeF.png!web

有两种方式来使用cheat.sh。第一种,就是通过他的网址 http://cheat.sh进入网站 (点击原文链接),然后在左上角的下拉菜单里面选择你需要查看的命令;第二种方法就是安装它的sh脚本,这样子的话就可以在命令行里面就能完成查询的工作。安装也非常的方便, 用下面的命令安装之后,就能通过 `cht.sh` 脚本来使用cheat.sh的文档服了。 比如 `cht.sh curl`

curl https://cht.sh/:cht.sh | sudo tee /usr/local/bin/

sudo chmod +x /usr/local/bin/cht.sh

其实,cheat.sh不仅能够查询一些常用的命令行的程序的文档,还能查一些计算机语言常用功能的代码实现。比如想用go实现一个HTTP server,用 cht.sh go http, 就能获得实现代码。

$cht.sh go http
package main
import (
    "fmt"
    "net/http"
)
// define a type for the response
type Hello struct{}
// let that type implement the ServeHTTP method (defined in interface http.Handler)
func (h Hello) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello!")
}
func main() {
    var h Hello
    http.ListenAndServe("localhost:4000", h)
}
// Here's the method signature of http.ServeHTTP:
// type Handler interface {
//     ServeHTTP(w http.ResponseWriter, r *http.Request)
// }

由于cheat.sh,对程序员非常友好,内容也是基于社区,所以社区里面也出现了各种cheat.sh的插件,如果大家感兴趣的话也可以安装一个,这样的话就直接可以在编辑器/ide里面,根据语言环境查询你需要的功能,然后查询结果的代码就会直接贴到代码中了。

NNnueiQ.jpg!web

给大家推荐的第2个工具就叫做typesync。typesync这个工具是针对TypeScript语言的。当我们在使用TypeScript的时候,会先安装一个依赖的包,然后再去安装对应的d.ts定义包。有些包是自己本身带 d.ts 文件的,有些是独立出来放在@types这个npm domain下。所以就需要自己去查一下,某个包是要额外安装 d.ts 还是自带的?那么用了`typesync`这个工具之后呢,它会自动扫描项目的package.json并查找对应的定义包,如果缺失会自动把他添加到package.json文件里面。

$typesync
»  TypeSync v0.5.1
✔  4 new typings added.
:package: demo-project — package.json (4 new typings added)
├─ @types/chai
├─ @types/superagent
├─ @types/lodash
└─ @types/mocha

当然如果你用了`--dry` 选项,它只是把@types依赖列出来,不会去修改package.json。所以有了这个工具之后呢,你只要专心的把你需要的包一次性安装好,然后执行下 typesync, 最后把新的@types依赖安装下就好了。

好了,今天介绍的这两个工具他们都能帮你节省一点时间。希望通过这些微小改进可以提高一点工作效率,工作效率提高了你自然就不需要996了。

mYjEjav.jpg!web


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK