1 个稳定版本

23.4.0 2023 年 4 月 26 日

#1059开发工具

MIT 许可证

18KB
272

gitig

通过命令行生成 .gitignore 文件

PyPI Crates.io

gitig 将输出写入 stdout。将结果重定向到合适的位置,例如

gi python > .gitignore

安装

使用 cargo

gitig 在 Rust 中有一个实现(以及一个 Python 实现)并且可以通过 cargo 安装

cargo install gitig-rs

使用 pipx

gitig 旨在作为 最终用户命令行应用程序 使用(即不作为软件包的依赖项)。最简单的方法是使用 pipx

pipx install gitig

使用 pip

gitig 也可以通过传统的 pip(或 poetry 等)安装

pip install gitig

用法

$ gi -h
usage: gi [-h] [-v] [--completion {bash,fish}] [--no-pager]
          [template [template ...]]

positional arguments:
  template              Template(s) to include in the generated .gitignore
                        file. If no templates are specified, display a list of
                        all available templates.

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  --completion {bash,fish}
                        Generate a completion file for the selected shell.
  --no-pager            Write template list to stdout. By default, this
                        program attempts to paginate the list of available
                        templates for easier reading.

示例

  • 列出所有可用的 gitignore 模板(如果可用,使用分页器)

    gi
    
  • 为 Python 和 Jupyter 生成 gitignore 文件

    gi python jupyternotebooks
    

为 Bash 或 Fish 启用 Tab 补全

gitig 支持为 Bash 和 Fish 生成补全脚本。以下是生成各种 shell 补全脚本的命令

对于 Bash,你可能需要 source (.) 生成的 Tab 补全脚本才能生效。

要启用启动时的 Tab 补全,可以将生成的补全脚本添加到你的 .bashrc.bash_profile 中。

Bash

gi --completion bash > /etc/bash_completion.d/gi.bash-completion

Bash (Homebrew)

gi --completion bash > $(brew --prefix)/etc/bash_completion.d/gi.bash-completion

Fish

gi --completion fish > ~/.config/fish/completions/gi.fish

Fish (Homebrew)

gi --completion fish > (brew --prefix)/share/fish/vendor_completions.d/gi.fish

API

CLI

gi # query gitignore.io and list available options
gi python jupyternotebooks # write a .gitingore file for python and jupyter to stdout
gi --completion bash # write generated bash autocompletion script to stdout
gi --completion fish # write generated fish autocompletion script to stdout
gi --version # write gitig version info to stdout

自动补全

gi <TAB><TAB>
1c                         1c-bitrix                  actionscript
ada                        adobe                      advancedinstaller          adventuregamestudio
agda                       al                         alteraquartusii            altium
...
$ gi python j<TAB><TAB>
jabref  jboss6          jekyll         jetbrains+iml  joe     jupyternotebooks
java    jboss-4-2-3-ga  jenv           jgiven         joomla  justcode
jboss   jboss-6-x       jetbrains      jigsaw         jspm
jboss4  jdeveloper      jetbrains+all  jmeter         julia

Rust API

gitig::list_templates();  // same as `gi`
gitig::create(vec!['python', 'jupyter']);  // same as `gi python jupyter`
gitig::bash_completion();  // same as `gi --completion bash`
gitig::fish_completion();  // same as `gi --completion fish`
gitig::VERSION;

Python API

import gitig

gitig.list_templates()  # same as `gi`
gitig.create(['python', 'jupyter'])  # same as `gi python jupyter`
gitig.bash_completion()  # same as `gi --completion bash`
gitig.fish_completion()  # same as `gi --completion fish`
gitig.__version__

贡献

Rust

  1. Fork 仓库
  2. 运行 cargo build
  3. 运行 pre-commit install
  4. 添加你的更改(添加/更新测试总是很好的)
  5. 提交你的更改并推送到你的 fork
  6. 打开 PR

Python

  1. 拥有或安装最新版本的 poetry(版本 >= 1.1)
  2. Fork 仓库
  3. 设置虚拟环境(您喜欢的方式)
  4. 运行 poetry install
  5. 运行 pre-commit install
  6. 添加你的更改(添加/更新测试总是很好的)
  7. 提交你的更改并推送到你的 fork
  8. 打开 PR

依赖项

~4–19MB
~242K SLoC