# @fvictorio/tabtab 中文文档

规范地址：https://npmcn.com/package/%40fvictorio/tabtab/

版本：0\.0\.3
npm 元数据更新时间：2022-04-05T13:11:34.031Z
中文译文更新时间：2026-11-15T19:28:23.119Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40fvictorio/tabtab
原文对照：https://npmcn.com/package/%40fvictorio/tabtab/?lang=original
项目主页：https://github.com/pnpm/tabtab#readme
源码仓库：https://github.com/pnpm/tabtab

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：783 kB，34 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=10
- 运行依赖：5 个
- 首次发布：2020-12-09T18:17:11.896Z
- 最新版本发布：2020-12-11T20:20:39.074Z
- 近 30 天下载量：4155（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 0 个）

## 中文简介

选项卡补全助手,用于节点 cli 程序。 受到npm完成的启发.

## 安装

```sh
npm install @fvictorio/tabtab
```

也可以使用：`pnpm add @fvictorio/tabtab`、`yarn add @fvictorio/tabtab`、`bun add @fvictorio/tabtab`

## README

# @pnpm/tabtab (英语)

[![Build Status](https://travis-ci.com/pnpm/tabtab.svg?branch=master)](https://travis-ci.com/pnpm/tabtab)

执行自定义命令行的节点软件包 `<tab><tab>` 任何项目的补全 系统指挥,用于巴什,兹什,和鱼壳.

使用与 npm 相同的技术实现(其完成率相当) 真棒)依靠贝壳脚本桥来完成实际完成从 节点之地.

![tabtab](https://user-images.githubusercontent.com/113832/46506243-deb39b00-c833-11e8-8f5f-7136987e7341.gif)

**警告/ 中断更改**

-   不支持窗口
-   缓存已删除
-   现在只支持节点 `> 7.10.1`,用于支持节点的上一个版本 6 确定使用标签 `2.2.x`

## 目录

-   [3.0.0版本的目标](https://npmcn.com/package/%40fvictorio/tabtab/#readme-goal-of-this-300-version)
    
-   [安装](https://npmcn.com/package/%40fvictorio/tabtab/#readme-installation)
    
-   [使用量](https://npmcn.com/package/%40fvictorio/tabtab/#readme-usage)
    
    -   [1\. 安装完成](https://npmcn.com/package/%40fvictorio/tabtab/#readme-1-install-completion)
    -   [2\. 日志完成情况](https://npmcn.com/package/%40fvictorio/tabtab/#readme-2-log-completion)
    -   [3\. 剖析坑](https://npmcn.com/package/%40fvictorio/tabtab/#readme-3-parsing-env)
-   [完成机制](https://npmcn.com/package/%40fvictorio/tabtab/#readme-completion-mechanism)
    
    -   [完成安装](https://npmcn.com/package/%40fvictorio/tabtab/#readme-completion-install)
    -   [完成未安装](https://npmcn.com/package/%40fvictorio/tabtab/#readme-completion-uninstall)
-   [调试](https://npmcn.com/package/%40fvictorio/tabtab/#readme-debugging)
    
-   [API 文档](https://npmcn.com/package/%40fvictorio/tabtab/#readme-api-documentation)
    
-   [更改日志](https://npmcn.com/package/%40fvictorio/tabtab/#readme-changelog)
    
-   [贷项](https://npmcn.com/package/%40fvictorio/tabtab/#readme-credits)
    

## 3.0.0版本的目标

简化一切,大修,从零开始重写.

功能性强,抽象性较弱,文献记录更清晰,测试覆盖面好, 支持节点 10 没有bayl.

上至相依性,更能调试,更能测试.

应该继续支持出击,zsh和鱼 但出击是重点 阿尔法版本.

没有二进制文件了,只是一个库(仍在与我自己辩论)

此重写的目标有两重:

-   与 [哟](https://github.com/yeoman/yo) (约曼)
-   拥有一个强大而快的图书馆 [线条补全](https://github.com/mklabs/yarn-completions)

## 安装

```
pnpm add @pnpm/tabtab
```

## 使用量

写入完成是一个两步的过程:安装和日志. 标签 仅此而已.

以下是一个使用 [最小数](https://www.npmjs.com/package/minimist) 以分析参数.

```js
#! /usr/bin/env node

const tabtab = require('@pnpm/tabtab');
const opts = require('minimist')(process.argv.slice(2), {
  string: ['foo', 'bar'],
  boolean: ['help', 'version', 'loglevel']
});

const args = opts._;
const completion = env => {
  if (!env.complete) return;

  // Write your completions there

  if (env.prev === 'foo') {
    return tabtab.log(['is', 'this', 'the', 'real', 'life']);
  }

  if (env.prev === 'bar') {
    return tabtab.log(['is', 'this', 'just', 'fantasy']);
  }

  if (env.prev === '--loglevel') {
    return tabtab.log(['error', 'warn', 'info', 'notice', 'verbose']);
  }

  return tabtab.log([
    '--help',
    '--version',
    '--loglevel',
    'foo',
    'bar',
    'install-completion',
    'completion',
    'someCommand:someCommand is some kind of command with a description',
    {
      name: 'someOtherCommand:hey',
      description: 'You must add a description for items with ":" in them'
    },
    'anotherOne'
  ]);
};

const run = async () => {
  const cmd = args[0];

  // Write your CLI there

  // Here we install for the program `tabtab-test` (this file), with
  // completer being the same program. Sometimes, you want to complete
  // another program that's where the `completer` option might come handy.
  if (cmd === 'install-completion') {
    await tabtab
      .install({
        name: 'tabtab-test',
        completer: 'tabtab-test'
      })
      .catch(err => console.error('INSTALL ERROR', err));

    return;
  }

  if (cmd === 'uninstall-completion') {
    // Here we uninstall for the program `tabtab-test` (this file).
    await tabtab
      .uninstall({
        name: 'tabtab-test'
      })
      .catch(err => console.error('UNINSTALL ERROR', err));

    return;
  }

  // The completion command is added automatically by tabtab when the program
  // is completed.
  if (cmd === 'completion') {
    const env = tabtab.parseEnv(process.env);
    return completion(env);
  }
};

run();
```

请参看 [实例/tabtab测试-完成](https://npmcn.com/package/%40fvictorio/tabtab/examples/tabtab-test-complete) 一个软件包 实例。 以下的用法文件就是以此为基础的.

### 1\. 安装完成

要完成给定的程序或软件包,您必须启用 在您或用户的系统中完成。 这是通过呼叫 `tabtab.install()` 通常位于 `program install-completion` 命令或类似的东西.

```js
// Here we install for the program `tabtab-test`, with completer being the same
// program. Sometimes, you want to complete another program that's where the
// `completer` option might come handy.
tabtab.install({
  name: 'tabtab-test',
  completer: 'tabtab-test'
})
  .then(() => console.log('Completion installed'))
  .catch(err => console.error(err))
```

方法还原一个承诺,所以 `await / async` 使用是可能的。 它需要一个 `options` 参数,使用:

-   `name`: 要完成的程序
-   `completer`:完成的程序(可以是同一程序).

`tabtab.install()` 将询问用户使用哪个 SHELL, 并选择路径 写给。 这将增加一条新行到其中之一 `~/.bashrc`, (中文(简体) ), `~/.zshrc` 或者说 `~/.config/fish/config.fish` 文件到源 tatab 补全脚本.

只有一行会被添加,即使它被多次调用.

### 2\. 日志完成情况

一旦完成启用并激活,您就可以为 程序(在此示例中) `tabtab-test`) (中文(简体) ). 简而言之,增加的完成是: 和日志输出一样简单 `stdout`,具有一些特殊性(即: Bash, 和描述), 但这是由 `tabtab.log()`。 。 。 .

```js
tabtab.log([
  '--help',
  '--version',
  'command'
  'command-two'
]);
```

这是添加完成数的最简单方式. 您也可以使用对象, 而不是简单的字符串,与 `{ name, description }` 属性 为每个完成项添加描述, 用于支持它们的弹壳 (如Zsh或鱼. 或者用更简单的 `name:description` 形式.

```js
tabtab.log([
  { name: 'command', description: 'Description for command' },
  'command-two:Description for command-two'
]);
```

这个 `{ name, description }` 方法在您完成时更为可取 带有 `:` 在他们身上.

请注意,你可以打电话 `tabtab.log()` 多次,如果你喜欢这样做,它 仅按顺序记录到控制台.

#### 文件系统完成

如果您有一个参数可以期望某个文件的路径, 您可以允许 贝壳使用其本地自动补全。 这样可以省去写作的功用 自定义文件系统自动完成逻辑 。 况且 本地的自动完成能力更好 处理诸如 dircolors 或隐藏文件之类的事项.

要启动文件系统补全, 使用 `tabtab.logFiles()` 没有 参数.

```js
if (previousFlag === '--file') {
  tabtab.logFiles();
}
```

### 3\. 剖析坑

如果你想增加更多的智能完成, 你需要检查和 查看已完成行中最后一个或上一个单词,以便您能够 添加特定命令或旗帜的选项(例如日志级别) `--loglevel` (例如,见a/cn.9/wg.iii/wp.iii/wp.1号文件).

Tabtab 添加了一些环境变量供您检查和使用, 这是 打电话 `tabtab.parseEnv()` 方法.

```js
const env = tabtab.parseEnv(process.env);
// env:
//
// - complete    A Boolean indicating whether we act in "plumbing mode" or not
// - words       The Number of words in the completed line
// - point       A Number indicating cursor position
// - line        The String input line
// - partial     The String part of line preceding cursor position
// - last        The last String word of the line
// - lastPartial The last word String of partial
// - prev        The String word preceding last
```

通常,你会想检查 `env.last` 或者说 `env.prev`。 。 。 .

```js
if (env.prev === '--loglevel') {
  tabtab.log(['error', 'warn', 'info', 'notice', 'verbose']);
}
```

## 完成机制

随便浏览 [脚本](https://npmcn.com/package/%40fvictorio/tabtab/scripts) 检查各种目录 创建补全时使用的模板文件 `tabtab.install()`。 。 。 .

以下是由 Tabtab 创建的 Bash 补全片段 .

```bash
###-begin-tabtab-test-completion-###
if type complete &>/dev/null; then
  _tabtab-test_completion () {
    local words cword
    if type _get_comp_words_by_ref &>/dev/null; then
      _get_comp_words_by_ref -n = -n @ -n : -w words -i cword
    else
      cword="$COMP_CWORD"
      words=("${COMP_WORDS[@]}")
    fi

    local si="$IFS"
    IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
                           COMP_LINE="$COMP_LINE" \
                           COMP_POINT="$COMP_POINT" \
                           tabtab-test completion -- "${words[@]}" \
                           2>/dev/null)) || return $?
    IFS="$si"
    if type __ltrim_colon_completions &>/dev/null; then
      __ltrim_colon_completions "${words[cword]}"
    fi
  }
  complete -o default -F _tabtab-test_completion tabtab-test
fi
###-end-tabtab-test-completion-###
```

这个系统相当简单(虽然很难把它钉住,但是谢谢你 npm). 一个新的 创建 Bash 函数,每当 `tabtab-test` 是标签 已完成。 此函数然后引用完整器 `tabtab-test completion` 与 `COMP_CWORD`, (中文(简体) ), `COMP_LINE` 财务报告和审定财务报表 `COMP_POINT` 环境变量(即 解析 `tabtab.parseEnv()`) (中文(简体) ).

同样的机制可以适用于Zsh和Fish.

### 完成安装

如本报告所述 [`Usage > Install Completion`](https://npmcn.com/package/%40fvictorio/tabtab/#readme-1-install-completion) 区域,安装一个补全涉及在源中增加一条新行 `~/.bashrc`, (中文(简体) ), `~/.zshrc` 或者说 `~/.config/fish/config.fish` 文档.

在那个 `3.0.0` 版本,它已被改进为只添加一行 在系统上安装的每个完成包各一个.

这样,就增加了一条单行线,以便完成各种项目 程序不会对 Shell 配置文件进行挤压.

示例 `~/.bashrc`

```bash
# tabtab source for packages
# uninstall by removing these lines
[ -f ~/.config/tabtab/__tabtab.bash ] && . ~/.config/tabtab/__tabtab.bash || true
```

会装入文件的 `__tabtab.bash`中创建 `~/.config/tabtab` 目录, 它将保存每个标签包定义 a 的所有源行 已完成.

```bash
# tabtab source for foo package
# uninstall by removing these lines
[ -f ~/.config/tabtab/foo.bash ] && . ~/.config/tabtab/foo.bash || true

# tabtab source for tabtab-test package
# uninstall by removing these lines
[ -f ~/.config/tabtab/tabtab-test.bash ] && . ~/.config/tabtab/tabtab-test.bash || true
```

### 完成未安装

您可以跟踪您 SHELL 配置文件中添加的文件并禁用一个 删除上述行后完成.

或者通过删除您 SHELL 配置文件中的行来简单禁用标签 .

或者,你可以用来 `tabtab.uninstall()` 为了你.

```js
if (cmd === 'uninstall-completion') {
  // Here we uninstall for the program `tabtab-test`
  await tabtab
    .uninstall({
      name: 'tabtab-test'
    })
    .catch(err => console.error('UNINSTALL ERROR', err));

  return;
}
```

## 调试

tabtab 内部记录了很多东西,使用 [调试](https://www.npmjs.com/package/debug) 软件包.

当测试完成时,可以看到这些日志,但写给 `stdout` 或者说 `stderr` 完成某件事会很麻烦的.

你可以用这个 `TABTAB_DEBUG` 要指定要登录的文件的环境变量 换句话说.

```
export TABTAB_DEBUG="/tmp/tabtab.log"
tail -f /tmp/tabtab.log

# in another shell
tabtab-test <tab>
```

见 [标签](https://npmcn.com/package/%40fvictorio/tabtab/lib/utils/tabtabDebug.js) 详细文件.

## API 文档

请参考 [api 密码](https://npmcn.com/package/%40fvictorio/tabtab/api) 要查看生成的文档的目录( 使用) [日记2md](https://github.com/jsdoc2md/jsdoc-to-markdown)(中文(简体) )

## 更改日志

请参考 [变化](https://npmcn.com/package/%40fvictorio/tabtab/CHANGELOG.md) 以查看此工程的所有可能更改.

## 贷项

npm的完成功能相当惊人 击打和zsh 提供命令标签补全,允许您完成名称 命令在您的路径。 通常这些函数意味着击打 脚本,对于npm来说,部分是真实的.

有一个特别的 `npm completion` 命令你也许想四处看看, 如果还没有.

```
npm completion
```

运行此程序应丢弃 [这个 脚本](https://raw.github.com/isaacs/npm/caafb7323708e113d100e3e8145b949ed7a16c22/lib/utils/completion.sh) 到操纵台。 此脚本同时使用 bash/zsh 并绘制正确的地图 npm 可执行的补全函数。 这些职能需要照顾 分析 `comp_*` 点击标签完成时可用的变量 命令,将其设置为环境变量并运行 `npm completion` 命令后继 `-- words` 字词匹配值的 命令正在完成.

这意味着使用这种技术 npm 能够执行 bash/zsh 使用节点和javascript完成。 实际上,npm的综合性 完成是相当惊人的.

这个软件包/模块完全基于 npm 的代码和 @isaacs 工作时.

* * *

> [光标](https://npmcn.com/package/%40fvictorio/tabtab/LICENSE)  \* > [mklabs.github.io (英语)](https://mklabs.github.io/)  \* > [@mklabs (英语)](https://github.com/mklabs)

## 常见问题

### @fvictorio/tabtab 是什么？

选项卡补全助手,用于节点 cli 程序。 受到npm完成的启发\.

### 如何安装 @fvictorio/tabtab？

在项目目录运行 npm install @fvictorio/tabtab，或使用 pnpm add / yarn add / bun add。

### @fvictorio/tabtab 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/fvictorio\_\_tabtab 是否存在。

### @fvictorio/tabtab 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @fvictorio/tabtab 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=10。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @fvictorio/tabtab 可以商用吗？

@fvictorio/tabtab 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @fvictorio/tabtab 的下载量有多少？

根据 npm 官方下载统计，@fvictorio/tabtab 在 2026/10/16 – 2026/11/14 这 30 天内被下载 4,155 次，日均约 139 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @fvictorio/tabtab 还在维护吗？

最新版本 0\.0\.3 发布于 2020/12/12（5 年前）；至今共发布 3 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/12/10。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

