yamaton / h2o-curated-data

Semi-hand curated command-line option data for many CLI programs, geared toward bioinformatics tools. Shell completion scripts are also available.
14 stars 0 forks source link
bash bioinformatics cli dataset fish shell vscode-extension zsh

CLI curated data for shell completion

This repository contains command-line specs for Shell Completion for VS Code. This repository also contains tab completion scripts for bash/zsh/fish shells.

Shell completion scripts for bioinformatics tools are located in the separate repositories:

Loading the data in VS Code

Shell completion for bash/zsh/fish

They would be useful especially for bioinformaticians.

bash

Copy files (general) to ~/.bash_completion.d/, and add the following to ~/.bashrc.

for bcfile in ~/.bash_completion.d/* ; do
    . "$bcfile"
done

zsh

Save files (bio, general) to ~/.zfunc, then add the following line to ~/.zshrc.

fpath=( ~/.zfunc "${fpath[@]}" )

fish

Save files (bio, general) to ~/.config/fish/completions/.

How I prepare the data

I use h2o (closed source code) to extract CLI specs, and then apply yq to convert from JSON to YAML.

Here is how I extracted the CLI info from medaka, for example.

# Just see how it works
$ h2o --command medaka

# ...OK. H2o seems to fail parsing some.
# So save the help document as text file for manual editing...
$ medaka --help > medaka.txt

# Edit medaka.txt s.t. command options, subcommands, and descriptions are placed nicely.
# ...
# ...
# After finishing the edit, extract the data as YAML file.
$ h2o --file medaka.txt --format json | yq eval -P > bio/yaml/medaka.yaml

# Add TLDR to the YAML, then convert it to JSON and bash/zsh/fish scripts
# group=bio sets the environment variable and run make
# The makefile calls multiple scripts including
#    - Add TLDR to YAML
#    - Convert YAML to JSON
#    - Create bash/zsh/fish scripts
#    - Take the entire JSON as an array, create a gzipped JSON file
$ group=bio make

Data structure

Here is a sample file.

name: tar
description: an archiving utility
options:
  - names:
      - -x
      - --extract
      - --get
    argument: ""
    description: extract files from an archive
  - names:
      - -v
      - --verbose
    argument: ""
    description: verbosely list files processed
version: tar (GNU tar) 1.34

As you can see, an entry has following key-values: