Skip to content

Commit 5d37ce1

Browse files
committed
feat(completions): add Bash and fish
These completions only apply to the command `remarshal`, not `foo2bar` short commands.
1 parent 662d11d commit 5d37ce1

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

completions/install.fish

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /usr/bin/env fish
2+
3+
cd "$(path dirname "$(status filename)")"
4+
5+
set --local src remarshal.fish
6+
set --local dst $__fish_config_dir/completions/
7+
8+
printf 'copying "%s" to "%s"\n' $src $dst
9+
10+
cp $src $dst

completions/remarshal.bash

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
_remarshal() {
2+
local cur prev opts formats input_formats output_formats
3+
4+
COMPREPLY=()
5+
cur=${COMP_WORDS[COMP_CWORD]}
6+
prev=${COMP_WORDS[COMP_CWORD - 1]}
7+
8+
formats='cbor json msgpack toml yaml'
9+
input_formats=$formats
10+
output_formats="$formats python"
11+
12+
opts='--help --version --from --if --input-format --input --indent --stringify --max-values --output --sort-keys --to --of --output-format --unwrap --verbose --width --wrap --yaml-style'
13+
14+
case "${prev}" in
15+
--from | --if | --input-format | -f)
16+
COMPREPLY=($(compgen -W "${input_formats}" -- ${cur}))
17+
return 0
18+
;;
19+
--to | --of | --output-format | -t)
20+
COMPREPLY=($(compgen -W "${output_formats}" -- ${cur}))
21+
return 0
22+
;;
23+
--yaml-style)
24+
COMPREPLY=($(compgen -W '\" '"\\' '|' '>'" -- ${cur}))
25+
return 0
26+
;;
27+
--input | -i | --output | -o)
28+
COMPREPLY=($(compgen -f -- ${cur}))
29+
return 0
30+
;;
31+
*)
32+
if [[ ${cur} == -* ]]; then
33+
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
34+
else
35+
COMPREPLY=($(compgen -f -- ${cur}))
36+
fi
37+
;;
38+
esac
39+
}
40+
41+
complete -F _remarshal remarshal

completions/remarshal.fish

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
complete -c remarshal -s h -l help -d "Show help message and exit"
2+
complete -c remarshal -s v -l version -d "Show program's version number and exit"
3+
4+
complete -c remarshal -s f -l from -l if -l input-format -x -a "cbor json msgpack toml yaml" -d "Input format"
5+
6+
complete -c remarshal -s i -l input -r -d "Input file"
7+
complete -c remarshal -s o -l output -r -d "Output file"
8+
9+
complete -c remarshal -s t -l to -l of -l output-format -x -a "cbor json msgpack python toml yaml" -d "Output format"
10+
11+
complete -c remarshal -l indent -x -d "JSON and YAML indentation"
12+
complete -c remarshal -s k -l stringify -d "Turn special values into strings"
13+
complete -c remarshal -l max-values -x -d "Maximum number of values in input data"
14+
complete -c remarshal -s s -l sort-keys -d "Sort JSON, Python, and TOML keys"
15+
complete -c remarshal -l width -x -d "Python and YAML line width"
16+
complete -c remarshal -l yaml-style -x -a '"\'" "\\"" "|" ">"' -d "YAML formatting style"
17+
18+
complete -c remarshal -l unwrap -x -d "Only output data under given key"
19+
complete -c remarshal -l verbose -d "Print debug information on error"
20+
complete -c remarshal -l wrap -x -d "Wrap data in a map with given key"

0 commit comments

Comments
 (0)