休斯顿是一种简单的基于GPT的命令行工具,可通过提供简单的自然语言指令来生成外壳命令或脚本。
在Linux,Mac和Windows上工作。您可以将其用于Bash,Powershell,ZSH,Python或任何其他外壳或脚本语言。
cargo install --git https://github.com/npgrosser/Houston.git
与休斯顿互动的默认命令是hu (休斯顿的缩写)。您可以为休斯顿提供自然语言的指导。
例如:
hu run ubuntu container with interactive bashhu find all pdf files in my home directoryhu delete unused docker images and networkshu tell me a dad joke要使用休斯顿,必须将OpenAI_API_KEY环境变量设置为OpenAI API密钥。您可以在https://platform.openai.com上获得一个。如果愿意,还可以在配置文件中指定密钥,请参阅“配置”部分以获取更多信息。
休斯顿对您的系统一无所知。因此,为了给休斯顿完成任务的最佳机会,您可以提供上下文信息。这可能包括有关文件树的详细信息,特定文件的内容,已安装的软件包,您的bash历史记录等。
为此,有一些功能可以帮助您完成此操作。
上下文文件是一个具有“ .ctxt”扩展名的文件,其中包含自然语言的信息列表。
您还可以使用命令变量添加动态生成的信息。
您在〜/Houston/default.ctxt文件中定义的信息始终提供给休斯敦。这是您将使用的上下文文件让休斯顿了解您的个人偏好和要求。例如,您喜欢哪个软件包经理,您最喜欢的语言是什么,您喜欢他打电话给您,等等。
上下文文件的内容应写入项目符号列表。
例子:
- If I want you to install something, use brew if the package is avaiable there
- If the script gets more complex, use comments to explain what you are doing
- When printing to the console, use capital letters. I like it when you shout at me
命名的上下文文件是您可以按照指示启用的上下文文件。它们对于提供特定特定任务的上下文信息很有用。像默认的上下文文件一样,它们位于〜/Houston目录中。您可以使用-c标志启用它们。
hu <instruction> -c <context-file-name>
例子:
〜/houston/pretty-ofput.ctxt
- when printing to the terminal, use colored output and fancy ASCII art
用法:
hu print hello world -c pretty-output
根据指令,您可以启用多个上下文文件。
hu <instruction> -c <context-file-name-1> -c <context-file-name-2>
例子:
hu tell me a joke -c pretty-output -c dark-humor
上下文文件可以是纯文本文件,但它们也可以包含命令变量。您可以使用${cmd}语法来利用它们。这些命令变量在每个说明上评估,并替换为命令的输出。
这是使用命令变量的上下文文件的示例:
- The current working directory is ${pwd}.
- The current user is ${whoami}.
- The current time is ${date}.
处理此模板时,结果输出看起来与此相似:
- The current working directory is /home/user/my-name/houston.
- The current user is my-name.
- The current time is 2020-10-10 12:00:00.
编写自己的上下文文件时,请记住所有数据将发送到OpenAI。因此,您应仅使用未透露敏感信息的命令。
通过-c标志使用命名上下文时,您也可以通过参数。例如:
hu tell me a joke -c lang:german
参数传递给模板,您可以像使用任何普通的Shell脚本一样访问它。例子:
〜/休斯顿/lang.ctxt:
- When printing to the terminal, always use the ${echo $1} language.
请记住,我们需要在此处使用echo命令,因为命令变量被命令的输出替换
如果要通过多个参数,则只需要确保围绕上下文规范添加引号即可。
hu tell me a joke -c "langs:german english french"
请注意,上面的示例假定Bash用作评估命令变量的外壳。
使用其他外壳时,您可能需要使用其他语法来访问参数。
例如,在PowerShell中,您将使用$ args变量。另外,您无需使用Echo命令。
- When printing to the terminal, always use the ${$args[0]} language.
这里还有一些命名上下文文件的示例,可以让您了解如何使用它们。
将当前GIT状态作为上下文信息添加的上下文文件。
- The current git status is:
```
${git status}
```
上下文文件,将当前的Docker状态添加为上下文信息。
- The current docker status is:
```
${docker ps -a}
```
- The current docker images are:
```
${docker images}
```
上下文文件,将bash历史记录中的最后一个n(默认10)命令作为上下文信息。
- The last ${1:-10} commands I ran were:
```
${tail -n ${1:-10} ~/.bash_history | cut -d ';' -f 2-}
```
上下文文件,将当前环境变量作为上下文信息。
- The current environment variables are:
```
${env}
```
上下文文件,将当前文件树添加为上下文信息。
- The current file tree is:
```
${tree -L ${1:-3}}
```
如果您想查看实际传递给API的内容,则可以使用-v (冗长)标志。
hu <instruction> -v
如果您想查看如何评估上下文文件,这将特别有用。
有关可用的配置选项,请参见示例config.yml 。首次运行hu时,将自动创建配置。它要么在$XDG_CONFIG_HOME/houston/config.yml或~/.config/houston/config.yml中。