Skip to main content

Tools Alias CLI

一个用于管理和运行自定义工具别名的命令行工具,支持环境变量配置。

特性

  • 📋 工具管理:定义自定义工具,包含名称、命令和帮助信息
  • 🌍 环境变量:从配置文件加载环境变量,并支持用户路径展开
  • 📝 字符串模板:在工具命令中使用 ${VARIABLE} 语法引用环境变量
  • 🎯 动态子命令:工具可作为直接子命令使用
  • 📖 帮助系统:内置 help 命令,支持工具特定的帮助信息
  • 📦 易于安装:通过 pip 或 uv 安装
  • 📂 配置目录定制:通过 TOOLS_ALIAS_DIR 环境变量自定义配置目录位置

安装

使用 uv

uv pip install tools-alias-cli

使用 pip

pip install tools-alias-cli

配置

配置文件

默认情况下,工具会在 ~/.tools-alias/config.toml 查找配置文件。

配置目录定制

你可以通过环境变量 TOOLS_ALIAS_DIR 来指定配置文件所在的目录:

# Linux/Mac
TOOLS_ALIAS_DIR="~/my-tools-alias" tools-alias-cli list

# Windows
set TOOLS_ALIAS_DIR="C:\\my-tools-alias" && tools-alias-cli list

如果未设置该环境变量,工具会自动将 TOOLS_ALIAS_DIR 设置为默认目录 ~/.tools-alias 的绝对路径。

配置格式

配置文件使用 TOML 格式,结构如下:

# 环境变量(可选)
[ENV]
HOME_PATH = "~/my-tools"
CONFIG_PATH = "~/.config/tools-alias"
USER = "myuser"

# 工具定义(必填)
[[tool]]
name = "show-home"
command = "echo ${HOME_PATH}"
short_help = "显示用户主目录"
help = "显示展开后的主目录路径"

[[tool]]
name = "list-files"
command = "ls -la"
short_help = "列出当前目录文件"

[[tool]]
name = "grep-pattern"
command = "grep $args *.py"
short_help = "在 Python 文件中搜索模式"

配置选项

环境变量 ([ENV])

  • 定义可用于所有工具命令的环境变量
  • 值可以包含用户路径展开(~ 会被替换为用户主目录)
  • 配置文件中的环境变量会覆盖系统环境变量

工具定义 ([[tool]])

  • name:工具的唯一标识符(必填)
  • command:要执行的命令(必填)
  • short_help:帮助输出中显示的简短描述(可选)
  • help:详细帮助文本(可选)
  • help_command:使用 help 命令时执行的帮助命令(可选)

使用方法

基本命令

# 列出所有可用工具
tools-alias-cli list

# 显示特定工具的帮助信息
tools-alias-cli help show-home

# 显示所有工具的帮助信息
tools-alias-cli help

# 使用 run 命令执行工具
tools-alias-cli run show-home

# 直接作为子命令执行工具
tools-alias-cli show-home

示例

示例 1:列出所有工具

$ tools-alias-cli list
工具别名列表:
  show-home -> echo C:\Users\user/my-tools ( 显示用户主目录 )
  list-files -> ls -la ( 列出当前目录文件 )
  grep-pattern -> grep $args *.py (  Python 文件中搜索模式 )

示例 2:显示所有工具的帮助信息

$ tools-alias-cli help
所有工具别名:
  show-home - 显示用户主目录
  list-files - 列出当前目录文件
  grep-pattern -  Python 文件中搜索模式

示例 3:执行工具

$ tools-alias-cli show-home
执行命令: echo C:\Users\user/my-tools 
C:\Users\user/my-tools

示例 4:带参数执行工具

$ tools-alias-cli grep-pattern "import"
执行命令: grep import *.py 
__init__.py:import argparse
__init__.py:import os
__init__.py:import sys
__init__.py:from string import Template
__init__.py:from typing import Dict, List, Optional
# 处理 Python 3.10 兼容性
__init__.py:if sys.version_info >= (3, 11):
__init__.py:    import tomllib
__init__.py:else:
__init__.py:    import tomli as tomllib

环境变量展开

工具支持两种类型的环境变量处理:

  1. 用户路径展开:环境变量中的 ~ 会被替换为用户的主目录
  2. 字符串模板:命令中的 ${VARIABLE} 会被替换为对应的环境变量值

开发

要求

  • Python 3.10+
  • uv(用于开发)

设置开发环境

# 安装依赖
uv install

# 以开发模式安装
uv install -e .

# 运行测试
uv run python -m pytest

# 运行类型检查
uv run mypy src/

# 构建包
uv build

许可证

Apache License 2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tools_alias_cli-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tools_alias_cli-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file tools_alias_cli-0.1.0.tar.gz.

File metadata

  • Download URL: tools_alias_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for tools_alias_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 93631c95fa9914eef8703576be53851f04a4809ac6890bd0d7ef5e7ee37a7c05
MD5 c2caa2aad2fc6cc021e37c8a47980f7f
BLAKE2b-256 a8e779388c34796b2d7cbef9f59f243934f39460f0ae6632afd6dd093ccab8df

See more details on using hashes here.

File details

Details for the file tools_alias_cli-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tools_alias_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9392696450f1fb6f1a726c19b8f9b1d804122714068e8f132c93a3f0d09d9dd
MD5 75b22aa4abf531a8ca02a3cc5d154292
BLAKE2b-256 46ba9755088b7ffdcfcb4890c3805ec8654ed9487ef8627fa2f6e63258fe8559

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page