Skip to content

Commit

Permalink
contrib: add sample Bashly completions implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rzmk authored Apr 8, 2024
1 parent 978a28a commit afa4817
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 0 deletions.
21 changes: 21 additions & 0 deletions contrib/bashly/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# qsv completions with Bashly

> These completions may be outdated by the time you're using them (see the version value in `src/bashly.yml` for the expected version to use it for). Update `src/bashly.yml` to ensure they're in sync with qsv's latest commands.
This is a foundation for CLI completions for [qsv](https://github.com/jqnatividad/qsv) using [Bashly](https://bashly.dannyb.co/).

## How to enable completions

Run `source completions.bash` on the `completions.bash` file in your terminal then try out the completions!

See Bashly's [Bash Completion docs](https://bashly.dannyb.co/advanced/bash-completion/) for more info.

## Development Setup

1. Install [Ruby](https://rubygems.org/pages/download).
2. Install bashly by running `gem install bashly` in your terminal.
3. Clone/download this directory to your system and `cd` into it.
4. If you're modifying the completions in `src/bashly.yml`, then you'll want to delete `completions.bash` before the next step (e.g., `rm completions.bash`).
5. Modify the `src/bashly.yml` as you see fit, save, then run `bashly add completions_script` which will generate a new `completions.bash` file.
6. Run the completions in your terminal with `source completions.bash`.
7. Try out the completions!
55 changes: 55 additions & 0 deletions contrib/bashly/completions.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# qsv completion -*- shell-script -*-

# This bash completions script was generated by
# completely (https://github.com/dannyben/completely)
# Modifying it manually is not recommended

_qsv_completions_filter() {
local words="$1"
local cur=${COMP_WORDS[COMP_CWORD]}
local result=()

if [[ "${cur:0:1}" == "-" ]]; then
echo "$words"

else
for word in $words; do
[[ "${word:0:1}" != "-" ]] && result+=("$word")
done

echo "${result[*]}"

fi
}

_qsv_completions() {
local cur=${COMP_WORDS[COMP_CWORD]}
local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
local compline="${compwords[*]}"

case "$compline" in
'frequency'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_qsv_completions_filter "--asc --delimiter --help --ignore-case --jobs --limit --memcheck --no-headers --no-nulls --output --select -h")" -- "$cur" )
;;

'count'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_qsv_completions_filter "--flexible --help --human-readable --low-memory --no-headers --no-polars --width -h")" -- "$cur" )
;;

'stats'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_qsv_completions_filter "--cardinality --dates-whitelist --delimiter --everything --force --help --infer-boolean --infer-dates --jobs --mad --median --memcheck --mode --no-headers --nulls --output --prefer-dmy --quartiles --round --select --stats-binout --typesonly -h")" -- "$cur" )
;;

'sqlp'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_qsv_completions_filter "--compress-level --compression --date-format --datetime-format --delimiter --float-precision --format --help --ignore-errors --infer-len --low-memory --memcheck --no-headers --no-optimizations --output --quiet --rnull-values --statistics --time-format --truncate-ragged-lines --try-parsedates --wnull-value -h")" -- "$cur" )
;;

*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_qsv_completions_filter "--help --version -h -v count frequency sqlp stats")" -- "$cur" )
;;

esac
} &&
complete -F _qsv_completions qsv

# ex: filetype=sh
131 changes: 131 additions & 0 deletions contrib/bashly/src/bashly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: qsv
# name: qsv.exe # Windows
version: 0.125.0

commands:
- name: count
completions:
- <file>
args:
- name: input
required: true
default: "-"
flags:
- long: --human-readable
- long: --width
- long: --no-polars
- long: --low-memory
- long: --flexible
- long: --no-headers

- name: frequency
completions:
- <file>
args:
- name: input
required: true
default: "-"
flags:
- long: --select
arg: arg
- long: --limit
arg: arg
- long: --asc
- long: --no-nulls
- long: --ignore-case
- long: --jobs
args: arg
- &output
long: --output
arg: <file>
- &no-headers
long: --no-headers
- &delimiter
long: --delimiter
arg: <arg>
- &memcheck
long: --memcheck

- name: stats
completions:
- <file>
args:
- name: input
required: true
default: "-"
flags:
- long: --select
arg: arg
- long: --everything
- long: --typesonly
- long: --infer-boolean
- long: --mode
- long: --cardinality
- long: --median
- long: --mad
- long: --quartiles
- long: --round
arg: decimal_places
- long: --nulls
- long: --infer-dates
- long: --dates-whitelist
arg: list
- long: --prefer-dmy
- long: --force
- long: --jobs
arg: arg
- long: --stats-binout
- *output
- *no-headers
- *delimiter
- *memcheck

- name: sqlp
completions:
- <file>
args:
- name: input
required: true
repeatable: true
default: "-"
- name: sql
required: true
flags:
- long: --human-readable
- long: --width
- long: --no-polars
- long: --low-memory
- long: --flexible
- long: --no-headers
flags:
- long: --format
arg: <arg>
- long: --try-parsedates
- long: --infer-len
arg: <arg>
- long: --low-memory
- long: --no-optimizations
- long: --truncate-ragged-lines
- long: --ignore-errors
- long: --rnull-values
arg: <arg>
- long: --datetime-format
arg: <fmt>
- long: --date-format
arg: <fmt>
- long: --time-format
arg: <fmt>
- long: --float-precision
arg: <arg>
- long: --wnull-value
arg: <arg>
- long: --compression
arg: <arg>
- long: --compress-level
arg: <arg>
- long: --statistics
- *output
- *no-headers
- *delimiter
- *memcheck
- long: --quiet

0 comments on commit afa4817

Please sign in to comment.