展示 HN:Shellock,一个用于 fish shell 的实时 CLI 标志解释器。
Show HN: Shellock, a real-time CLI flag explainer for fish shell

原始链接: https://github.com/ibehnam/shellock

## Shellock:Fish Shell 的实时命令行标志解释器 Shellock 是一个用于 Fish shell 的工具,可以在您输入命令时*实时*显示标志描述,从而增强 CLI 的可用性。 简单安装后,解释将出现在您的提示符下方,帮助您记住命令选项。 它通过解析您的输入、搜索命令 `--help` 输出和手册页以获取描述,并缓存结果以提高速度来工作。 Shellock 支持各种手册页格式(GNU、BSD 等),并且可以直接从命令行用于解释命令、查找特定标志或解析命令结构。 主要功能包括:输入时自动解释、缓存以提高性能,以及通过 Python 脚本直接使用以执行特定任务。 它利用 ANSI 转义码进行显示,需要 Python 3.11+ 和标准的 Unix 工具。

## Shellock:实时 CLI 标志解释器 Shellock 是一款为 Fish shell 设计的新工具,旨在实时解释命令行标志。它在 Hacker News 上分享,目标是帮助用户记住 `ls` 和 `find` 等命令的参数。 初步用户反馈显示,安装过程略有困难,需要将 `shellock` 目录放置在 `~/Downloads` 文件夹中,并手动符号链接文件。 虽然对较简单的命令有用,但它在处理更复杂的命令(如 `gcc -Wall`)时遇到困难,错误地将每个字母识别为单独的标志。对于具有大型 man 页面的命令,性能也可能较慢。用户建议潜在的改进措施,例如白名单命令以触发提示,并探索 Zsh 的类似工具。尽管存在这些早期问题,许多人认为这个概念很有价值,并赞赏有人正在积极开发解决方案。
相关文章

原文

Real-time CLI flag explainer for fish shell. Shows flag descriptions as you type commands.

$ tree -L 2 -a -C
  -L  Max display depth of the directory tree.
  -a  All files are printed...
  -C  Turn colorization on always...
# Clone or download to ~/Downloads/shellock
cd ~/Downloads/shellock
fish install.fish

After installation, explanations appear automatically as you type:

  • Type any command with flags (e.g., ls -la)
  • Flag explanations appear below the prompt
  • Press Enter to execute (clears explanations)
  • Press Ctrl+C to cancel (clears explanations)
  • Press Ctrl+H for manual help on current command
  1. Command Parsing: Extracts command name and flags from your input
  2. Flag Lookup: Searches --help output and man pages for descriptions
  3. Caching: Caches results in ~/.cache/shellock/ for fast subsequent lookups
  4. Display: Renders explanations below your prompt using ANSI escape codes

You can also use shellock directly:

# Explain flags in a command
./shellock.py explain "git commit -am 'message'"

# Look up a specific flag
./shellock.py lookup git -m --subcommand commit

# Parse command structure (JSON output)
./shellock.py parse "rsync -avz src/ dest/"

# Clear cache
./shellock.py clear-cache

Shellock parses various man page formats:

  • GNU style: -x, --long-option with description on next line
  • BSD style: -x Description on same line
  • Multiple flags: -R, -r, --recursive
  • Single-dash long flags: -name pattern (find, java style)
  • Tree style: -L level with description below
  • Some commands with unusual man page formats may not parse correctly
  • Commands that open interactive help (like git commit --help opening a pager) require man page fallback
  • Combined short flags like -rf are split into individual flags
~/Downloads/shellock/
├── shellock.py          # Main Python script
├── shellock.fish        # Fish shell functions
├── shellock_bindings.fish # Key bindings (symlinked to config)
├── install.fish         # Installer script
└── README.md            # This file
  • Python 3.11+
  • fish shell
  • Standard Unix tools (man, col)

MIT

联系我们 contact @ memedata.com