mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-22 14:07:55 +00:00
parallel: Basic --completion implemented for bash.
This commit is contained in:
parent
add978635c
commit
37528da98b
43
src/parallel
43
src/parallel
|
@ -1558,10 +1558,16 @@ sub shell_completion() {
|
||||||
if($opt::completion eq "zsh") {
|
if($opt::completion eq "zsh") {
|
||||||
# if(shell == zsh);
|
# if(shell == zsh);
|
||||||
zsh_competion();
|
zsh_competion();
|
||||||
|
} elsif($opt::completion eq "bash") {
|
||||||
|
# if(shell == bash);
|
||||||
|
bash_competion();
|
||||||
} elsif($opt::completion eq "auto") {
|
} elsif($opt::completion eq "auto") {
|
||||||
if($Global::shell =~ m:/zsh$|^zsh$:) {
|
if($Global::shell =~ m:/zsh$|^zsh$:) {
|
||||||
# if(shell == zsh);
|
# if(shell == zsh);
|
||||||
zsh_competion();
|
zsh_competion();
|
||||||
|
} elsif($Global::shell =~ m:/bash$|^bash$:) {
|
||||||
|
# if(shell == bash);
|
||||||
|
bash_competion();
|
||||||
} else {
|
} else {
|
||||||
::error("--completion is not implemented for '$Global::shell'.");
|
::error("--completion is not implemented for '$Global::shell'.");
|
||||||
wait_and_exit(255);
|
wait_and_exit(255);
|
||||||
|
@ -1572,6 +1578,39 @@ sub shell_completion() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub bash_competion() {
|
||||||
|
# Print:
|
||||||
|
# complete -F _comp_parallel parallel;
|
||||||
|
# _comp_parallel() {
|
||||||
|
# COMPREPLY=($(compgen -W "--options" --
|
||||||
|
# "${COMP_WORDS[$COMP_CWORD]}"));
|
||||||
|
# };
|
||||||
|
my @bash_completion =
|
||||||
|
("complete -F _comp_parallel parallel;",
|
||||||
|
'_comp_parallel() { COMPREPLY=($(compgen -W "');
|
||||||
|
my @och = options_completion_hash();
|
||||||
|
while(@och) {
|
||||||
|
$_ = shift @och;
|
||||||
|
# Split input like:
|
||||||
|
# "joblog|jl=s[Logfile for executed jobs]:logfile:_files"
|
||||||
|
if(/^(.*?)(\[.*?])?(:[^:]*)?(:.*)?$/) {
|
||||||
|
my $opt = $1;
|
||||||
|
my $desc = $2;
|
||||||
|
my $argdesc = $3;
|
||||||
|
my $func = $4;
|
||||||
|
# opt=s => opt
|
||||||
|
$opt =~ s/[:=].$//;
|
||||||
|
push @bash_completion,
|
||||||
|
(map { (length $_ == 1) ? "-$_ " : "--$_ " }
|
||||||
|
split /\|/, $opt);
|
||||||
|
|
||||||
|
}
|
||||||
|
shift @och;
|
||||||
|
}
|
||||||
|
push @bash_completion,'" -- "${COMP_WORDS[$COMP_CWORD]}")); };'."\n";
|
||||||
|
print @bash_completion;
|
||||||
|
}
|
||||||
|
|
||||||
sub zsh_competion() {
|
sub zsh_competion() {
|
||||||
my @zsh_completion =
|
my @zsh_completion =
|
||||||
("compdef _comp_parallel parallel; ",
|
("compdef _comp_parallel parallel; ",
|
||||||
|
@ -1584,7 +1623,7 @@ sub zsh_competion() {
|
||||||
$_ = shift @och;
|
$_ = shift @och;
|
||||||
# Split input like:
|
# Split input like:
|
||||||
# "joblog|jl=s[Logfile for executed jobs]:logfile:_files"
|
# "joblog|jl=s[Logfile for executed jobs]:logfile:_files"
|
||||||
if(/^(.*?)(\[.*?])(:[^:]*)?(:.*)?$/) {
|
if(/^(.*?)(\[.*?])?(:[^:]*)?(:.*)?$/) {
|
||||||
my $opt = $1;
|
my $opt = $1;
|
||||||
my $desc = $2;
|
my $desc = $2;
|
||||||
my $argdesc = $3;
|
my $argdesc = $3;
|
||||||
|
@ -2542,7 +2581,7 @@ sub check_invalid_option_combinations() {
|
||||||
|
|
||||||
sub init_globals() {
|
sub init_globals() {
|
||||||
# Defaults:
|
# Defaults:
|
||||||
$Global::version = 20220331;
|
$Global::version = 20220401;
|
||||||
$Global::progname = 'parallel';
|
$Global::progname = 'parallel';
|
||||||
$::name = "GNU Parallel";
|
$::name = "GNU Parallel";
|
||||||
$Global::infinity = 2**31;
|
$Global::infinity = 2**31;
|
||||||
|
|
|
@ -778,13 +778,14 @@ See also: B<--csv> B<{>I<n>B<}> B<--trim> B<--link>
|
||||||
|
|
||||||
Generate shell completion code for interactive shells.
|
Generate shell completion code for interactive shells.
|
||||||
|
|
||||||
Supported shells: zsh.
|
Supported shells: bash zsh.
|
||||||
|
|
||||||
Use I<auto> as I<shell> to automatically detect running shell.
|
Use I<auto> as I<shell> to automatically detect running shell.
|
||||||
|
|
||||||
Activate the completion code with:
|
Activate the completion code with:
|
||||||
|
|
||||||
zsh% eval "`parallel --completion auto`"
|
zsh% eval "`parallel --completion auto`"
|
||||||
|
bash$ eval "`parallel --completion auto`"
|
||||||
|
|
||||||
|
|
||||||
=item B<--compress>
|
=item B<--compress>
|
||||||
|
|
|
@ -16,6 +16,15 @@ export -f stdsort
|
||||||
# Test amount of parallelization
|
# Test amount of parallelization
|
||||||
# parallel --shuf --jl /tmp/myjl -j1 'export JOBS={1};'bash tests-to-run/parallel-local-0.3s.sh ::: {1..16} ::: {1..5}
|
# parallel --shuf --jl /tmp/myjl -j1 'export JOBS={1};'bash tests-to-run/parallel-local-0.3s.sh ::: {1..16} ::: {1..5}
|
||||||
|
|
||||||
|
par_completion() {
|
||||||
|
echo '### --completion'
|
||||||
|
# This will change, if you change options
|
||||||
|
parallel --completion bash | md5sum
|
||||||
|
bash -c 'parallel --completion auto;true' | md5sum
|
||||||
|
parallel --completion zsh | md5sum
|
||||||
|
zsh -c 'parallel --completion auto;true' | md5sum
|
||||||
|
}
|
||||||
|
|
||||||
par_ctagstring() {
|
par_ctagstring() {
|
||||||
echo '### --ctag --ctagstring should be different from --tag --tagstring'
|
echo '### --ctag --ctagstring should be different from --tag --tagstring'
|
||||||
parallel --tag echo ::: 1 ::: a| wc -c
|
parallel --tag echo ::: 1 ::: a| wc -c
|
||||||
|
|
|
@ -62,6 +62,11 @@ par_colsep_0 OK
|
||||||
par_colsep_0 OK
|
par_colsep_0 OK
|
||||||
par_colsep_default bug #37956: --colsep does not default to '\t' as specified in the man page.
|
par_colsep_default bug #37956: --colsep does not default to '\t' as specified in the man page.
|
||||||
par_colsep_default one 1
|
par_colsep_default one 1
|
||||||
|
par_completion ### --completion
|
||||||
|
par_completion 857e87c031164f28c4ec91e610c8cff7 -
|
||||||
|
par_completion 857e87c031164f28c4ec91e610c8cff7 -
|
||||||
|
par_completion 09b6d6d121bc9542589aca39741e5390 -
|
||||||
|
par_completion 09b6d6d121bc9542589aca39741e5390 -
|
||||||
par_compress_stdout_stderr ### Test compress - stdout
|
par_compress_stdout_stderr ### Test compress - stdout
|
||||||
par_compress_stdout_stderr OK
|
par_compress_stdout_stderr OK
|
||||||
par_compress_stdout_stderr ### Test compress - stderr
|
par_compress_stdout_stderr ### Test compress - stderr
|
||||||
|
|
Loading…
Reference in a new issue