Show HN:空回车扩展器——使用此工具减少终端输入
Show HN: Empty Enter Expander – Type less in the terminal with this tool

原始链接: https://github.com/waszabi/empty-enter-expander

Empty Enter Expander 通过允许用户仅需在空命令后按 Enter 键,即可用少量按键触发存储在指定“模块目录”中的命令,从而简化了 zsh 中的命令执行。模块目录包含以小写字母命名的文件和文件夹,用作命令快捷方式。 例如,一个冗长的 Git 命令可以存储在 `~/Tools/expander-example-module/g Git/l Log` 中,内容为 `echo 'git log --pretty=format:"%h %an : %s %d" --graph'`。 配置涉及在 `~/.zprofile` 中设置 `EMPTY_ENTER_EXPANDER_MODULE_PATH` 并加载 `zsh-function.zsh` 脚本。激活扩展程序需要将该函数添加到 zle 小部件中。 重新加载 shell 配置后,在空命令行按 Enter 键会调用扩展程序,显示可用命令列表。输入 'g' 再输入 'l' 将执行 'git log' 命令,并将其插入提示符中以便立即使用。此系统提供了一种快速且有条理的方法来访问常用命令。

Hacker News 的一篇帖子讨论了“Empty Enter Expander”,这是一个 zsh 工具,可以帮助用户通过减少输入来回忆和执行命令。作者 waszabi 创建它是为了解决记住别名,特别是那些不常用的别名的困难。该工具通过在空命令行上按 Enter 键触发,根据文件夹结构显示命令列表,并在提示符处将用户定义的快捷方式扩展为完整的命令。 评论中重点介绍了其他方法,例如制表符补全、fish shell 的缩写、tmux/fzf 别名搜索以及修剪不常用的别名。一些用户表示他们对他们当前拥有的别名很满意。其他建议包括在 fish shell 中使用缩写和使用 `navi` 来实现类似的功能。讨论还涉及到像 `kubectl` 这样的命令构建器,以及自定义键绑定以触发此类工具。一些用户注意到多次按下 Enter 键来清除屏幕的习惯。
相关文章
  • 更好的Shell历史搜索 2025-03-26
  • (评论) 2024-08-04
  • (评论) 2025-04-24
  • (评论) 2024-07-10
  • 轻松设置新的Macbook 2025-04-25

  • 原文

    Empty Enter Expander inserts a command into the prompt with a few keystrokes.

    It is currently written for the zsh. The bash version is not published yet.

    Commands are stored in a module directory that contains files and folders with lowercase letters at the beginning of their names, which act as shortcuts.

    The tool is activated by pressing Enter on an empty command.

    After that, the following keys are pressed to activate the commands::

    • 1, 1, 1, Enter to change the directory to the project's folder
    • g, s, Enter to view the git status
    • g, l, Enter to view the git log

    Demo of Empty Enter Expander

    Expander uses a directory where the commands are stored. It is called a module directory.

    The module directory might be located in ~/Tools/expander-example-module.

    Let's say you have a lengthy Git command. Prepare a script that will output it. Place the prepared script in the module directory within the subdirectory g Git and name the file l Log.

    # Contents of the example script
    # Save as "~/Tools/expander-example-module/g Git/l Log"
    echo 'git log --pretty=format:"%h %an : %s %d" --graph'

    Note the use of lowercase letters at the beginning. These will serve as key shortcuts.

    You can now store your own commands in a structure that you prefer.

    Clone this project and configure the module directory along with the other settings.

    # Contents of the tool's configuration
    # Place it in the "~/.zprofile" file
    setopt HIST_IGNORE_SPACE
    export EMPTY_ENTER_EXPANDER_MODULE_PATH="/Users/user/Tools/expander-module-one"
    source ~/Tools/empty-enter-expander/zsh-function.zsh 2>/dev/null || :
    zle -N empty-enter-expander
    bindkey "^M" empty-enter-expander

    Open a new shell to apply the configuration.

    Hit Enter on an empty command to activate the expander. It will open a listing of stored commands, so you do not have to remember them. Then press the g and l keys to insert the example command into the prompt.

    联系我们 contact @ memedata.com