@guanghechen/kit-profile
v0.5.14
Published
Render shell environment variables from profile config
Readme
@guanghechen/kit-profile
从 profile 配置渲染 shell 环境变量脚本。
命令会先将脚本写入系统剪切板,再输出脚本文本;不会直接修改父 shell 环境。
使用方式
通过 kit 聚合命令:
kit profile --shell fish --profile agent:prod | source
kit profile --fish --profile agent:prod | source
eval "$(kit profile --shell bash --profile agent:prod)"
eval "$(kit profile --bash --profile agent:prod)"
kit profile --shell pwsh --profile agent:prod | Invoke-Expression
kit profile --pwsh --profile agent:prod | Invoke-Expression通过独立命令:
kit-profile --shell fish --profile agent:prod | source
kit-profile --fish --profile agent:prod | source参数
--profile <name[:variant]>: 必填,profile 选择器。--shell <fish|bash|pwsh>: 可选,目标 shell。--fish: 可选,--shell fish的简写。--bash: 可选,--shell bash的简写。--pwsh: 可选,--shell pwsh的简写。--set <key:value...>: 可选,模板变量(variadic,可重复,后者覆盖前者)。--allow-env <key...>: 可选,显式放行默认拦截的危险 env key。
约束:
name不允许包含:、/、\,且不能为.或..。variant不允许为空,且不允许包含:。
说明:
- 不支持
--config参数。 --shell与--fish/--bash/--pwsh至少需要提供一个。--fish/--bash/--pwsh同时只能出现一个。- 若剪切板写入失败,命令直接报错并退出。
配置路径
根据 <name> 自动查找以下配置文件:
$XDG_CONFIG_HOME/kit/profile/<name>.profile.json(若设置)~/.config/kit/profile/<name>.profile.json(默认)
配置结构
{
"name": "agent",
"envs": {
"ANTHROPIC_BASE_URL": "http://localhost:${port}/api/claude"
},
"vars": {
"port": 4747
},
"variants": {
"prod": {
"envs": {
"NODE_ENV": "production"
},
"vars": {
"port": 4747
}
}
}
}模板优先级:--set > variant.vars > profile.vars。
显式指定 variant 时,最终 env:{ ...profile.envs, ...variant.envs }。
输出脚本中的 env 按 key 名字典序排序。
JSON Schema
- 本仓库路径:
packages/profile/schema/profile.schema.json - 发布后路径:
lib/schema/profile.schema.json - 线上
$id:https://guanghechen.github.io/kit/schemas/profile/profile.schema.json
生成命令:pnpm -C packages/profile run schema:config
安全策略
- 禁止危险对象键:
__proto__、constructor、prototype。 - 默认拦截危险 env key:
BASH_ENV、ENV、PROMPT_COMMAND。 - 如确有需要,可通过
--allow-env显式放行。
