Please describe your feature request.
It is about 3 months heavily I am using yq to parse, modify, check yaml files
I have to check many yaml files locally or on some servers (after ssh-ing into them)
Since I code in bash and create their tab-completion as well, I could create a tab-completion script and fulfill me needs.
My need was checking each object's value rather than cat those files and scroll the terminal
But yq has no option to select a file (e.g docker-compose -f file-name.yaml) explicitly
So I wish yq had these two features or at least the first one
- An option to select a file , a yaml file to parse
- Support tab-completion script to have this traversal feature ( I can contribute)
Describe the solution you'd like
Solution are
- Add -f or any other available letter in order the explicitly select a file (I solved this using an other script)
- Refactor your tab-completion (it is ready)
As an input
kind: database
type: source
project: project-name
salt: my-salt
encrypt:
object:
- .company.people.data
- .company.employee.data
file:
- .company.people
- .company.employee
decrypt:
object:
- .company.people.data
- .company.employee.data
file:
- .company.people
- .company.employee
And we run a command:
it could output
.decrypt.file.0 .decrypt.object.1 .encrypt.object.0 .project
.decrypt.file.1 .encrypt.file.0 .encrypt.object.1 .salt
.decrypt.object.0 .encrypt.file.1 .kind .type
My solution for -f option
#!/bin/bash
yq $2 $1 ${@:3}
My solution for object traversal
cmd_name='yqi'; # $1
current_arg=''; # $2
previous_arg=''; # $3
yqi_path=$(which yqi);
yqi_short_opt=($(perl -lne 'print $& if /-[a-zA-Z0-9]\b/' <($yqi_path --help) | sort | uniq))
yqi_long_opt=($(perl -lne 'print $& if /--[a-zA-Z0-9-]+\b/' <($yqi_path --help 2>&1) | sort | uniq));
_comp_yqi () {
current_arg=${COMP_WORDS[$COMP_CWORD]};
previous_arg=${COMP_WORDS[$COMP_CWORD-1]};
case ${previous_arg} in
yqi )
files=($(echo *.yml *.json *.xml));
COMPREPLY=(${files[@]});
;;
esac
case ${current_arg} in
.* )
keys=($(yq -o props ${COMP_WORDS[1]} | perl -lpe 's/^/./; s/ =.*$//g'));
COMPREPLY=( $(egrep -o "${current_arg//./\\.}[^ ]+" <<< ${keys[@]}) );
;;
[a-zA-Z0-9]* )
COMPREPLY=( $(egrep -o "${current_arg//./\\.}[^ ]+" <<< ${files[@]}) );
;;
esac
}
complete -o bashdefault -o default -o nospace -F _comp_yqi yqi
This tab-completion script is pretty short , but smart enough to give us list of keys to check their value.
Actually by any TAB hit - it parses the yaml file using yq -o props and generates a new list .
how to test and use
- save the script as
yqi and give the right permission
source the second script to activate Tab-Completion for first script yqi
here is a sceenshot of it

Please describe your feature request.
It is about 3 months heavily I am using yq to parse, modify, check yaml files
I have to check many yaml files locally or on some servers (after ssh-ing into them)
Since I code in bash and create their tab-completion as well, I could create a tab-completion script and fulfill me needs.
My need was checking each object's value rather than
catthose files and scroll the terminalBut yq has no option to select a file (e.g docker-compose -f file-name.yaml) explicitly
So I wish yq had these two features or at least the first one
Describe the solution you'd like
Solution are
As an input
And we run a command:
it could output
My solution for -f option
My solution for object traversal
This tab-completion script is pretty short , but smart enough to give us list of keys to check their value.
Actually by any TAB hit - it parses the yaml file using
yq -o propsand generates a new list .how to test and use
yqiand give the right permissionsourcethe second script to activate Tab-Completion for first scriptyqihere is a sceenshot of it
