-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contrib: add sample Bashly completions implementation
- Loading branch information
Showing
3 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |