跳转到主要内容

网络上的GNU cat,支持自动完成

项目描述

https://raw.githubusercontent.com/mpenkov/koshka/master/matroskin.jpeg

使用方法

自动完成S3存储桶名称

$ kot s3://my{tab}
//mybucket      //mybucket1     //mybucket2

自动完成S3前缀

$ kot s3://mybucket/myf{tab}
//mybucket/myfile0.txt      //mybucket/myfile0.json

自动完成S3版本(关于版本更多详情见下文)

$ kot s3://myversionedbucket/key{tab}
2021-03-23T03:46:03  2021-06-25T01:35:06

自动完成S3输出前缀

$ kot README.rst -o //mybucket/myf{tab}
//mybucket/myfile0.txt      //mybucket/myfile0.json

自动完成使用JSON的RESTful API端点

$ kot https://example.com/api
{
    "customers": "http://example.com/api/customers",
    "locations": "http://example.com/api/locations",
    "products": "http://example.com/api/products"
}
$ kot https://example.com/api/{tab}
//example.com/api/customers
//example.com/api/locations
//example.com/api/products

透明地编辑远程文件(再次,使用自动完成)

$ kote //mybucket/myfile0.txt{enter}
{$EDITOR opens a copy of the file locally}
{Once $EDITOR exits, the local file overwrites the remote destination}

别名

$ kot data/README.md{tab}
https://mydataserver.developers.mycompany.com/README.md

使用此功能访问频繁的较长的URL。有关别名设置,请参阅下文配置部分。

为什么?

项目最初专注于S3,但后来也扩展到了HTTP/S。

现有的awscli工具不支持自动完成。如果你不知道确切的密钥,你需要首先使用额外的命令来查找它

$ aws s3 ls s3://bucket/
2018-07-12 20:22:15        575 key.yaml
$ aws s3 cp s3://bucket/key.yaml -
...

如果密钥很长,你仍然需要全部输入

$ aws s3 ls s3://thesimpsons/apu
2018-07-12 20:22:15     123456 apu_nahasapeemapetilon.png
$ aws s3 cp s3://thesimpsons/apu_nahasapeemapetilon.png -
...

另一个问题是处理非标准端点,如localstack。你需要为每个命令指定端点URL,例如

$ aws --endpoint-url https://127.0.0.1:4566 s3 cp s3://local/hello.txt -
hello world!

如果你很懒,并且经常通过CLI访问S3,那么上述问题都是痛点。 kot通过自动完成和可选的配置文件解决了这些问题

$ kot s3://bucket/{tab}
//key.yaml
$ kot s3://thesimpsons/apu{tab}
//apu_nahasapeemapetilon.png
$ kot s3://local/hello{tab}
//hello.txt
{enter}
hello world!

安装

从PyPI安装最新版本

pip install koshka

为了在bash下使自动完成工作

pip install argcomplete
eval "$(kot --register)"
eval "$(kote --register)"

有关其他平台的信息,请参阅argcomplete文档

配置(可选)

你可以通过配置文件告诉kot使用哪个AWS配置文件和/或端点URL进行请求。将配置文件放在$HOME/kot.cfg中。示例

[s3://mybucket]
endpoint_url = https://127.0.0.1:4566

[s3://myotherbucket]
profile_name = myprofile

[https://mydataserver.developers.mycompany.com]
alias = data

章节名称被解释为正则表达式。因此,在上面的例子中,kot将使用https://127.0.0.1:4566作为端点URL来处理所有以s3://mybucket开头的请求。同样,它将使用myprofile AWS配置文件来处理所有以s3://myotherbucket开头的请求。

S3对象版本

如果存储桶支持版本控制,kot将列出每个版本的日期戳,而不是AWS分配的任意版本ID。例如,您可能会看到以下URL:

s3://bucket/key?LastModified=2021-03-23T03:46:03

在底层,kot会将日期戳转换为版本ID,然后再尝试访问内容。这是因为kot是为人类用户设计的,与boto3和类似的工具不同。通过查看日期戳,用户可以更好地决定访问哪个版本。存在一个边缘情况,即两个版本之间的时间差小于一秒,这意味着它们的戳将相同,但这很少发生,并且kot不会尝试处理它。

为了在命令行界面中将版本作为URL的一部分表示,kot使用URL的查询字符串部分,因为这对用户来说很直观,我想不出更好的替代方案。不幸的是,S3 URL没有查询字符串组件,实际上可以包含查询字符串分隔符(?)。幸运的是,这是一个很少发生的边缘情况,并且kot不会尝试处理它。

项目详情


下载文件

下载适用于您平台的应用程序。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源分布

koshka-0.9.tar.gz (11.2 kB 查看哈希值)

上传时间

构建分布

koshka-0.9-py3-none-any.whl (11.5 kB 查看哈希值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面