Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash-completion: complete 'clean|groups|repolist' using help (v2) #161

Conversation

ignatenkobrain
Copy link
Contributor

Reported-by: Parag Nemade pnemade@redhat.com
Reference: #159 (comment)

@ignatenkobrain ignatenkobrain changed the title bash-completion: complete 'clean|groups|repolist' using help bash-completion: complete 'clean|groups|repolist' using help (v2) Sep 10, 2014
@pnemade
Copy link
Contributor

pnemade commented Sep 10, 2014

cool this worked fine for me now. 👍

@ignatenkobrain
Copy link
Contributor Author

Now we use only bash built-in functions. it's more faster than sed/perl

@ignatenkobrain
Copy link
Contributor Author

Function to parse written on some programming languages

bash built-in

_dnf_help_command()
{
    local cmd=$( dnf help $1 | grep -E "^$1" | tr "|" " " )
    cmd=${cmd#*[} && cmd=${cmd%%]*}
    eval "$2='$cmd'"
}

perl

_dnf_help_command()
{
    eval "$2='$( dnf help $1 | perl -ne "next unless /^$1/; s|.*?\[(.*?)\].*|\1|g; s/\|/ /g; print; exit" )'"
}

sed

_dnf_help_command()
{
    eval "$2='$( dnf help $1 | grep -E "^$1" | sed -e "s/|/ /g" -e "s/^$1 \[//g" -e "s/\].*$//g" )'"
}

python

_dnf_help_command()
{
    eval "$2='$( dnf help $1 | python -c "import sys,re; [[sys.stdout.write(m.replace("|", " ")) for m in re.findall('${1} \[(.*?)\]', line)] for line in sys.stdin]" )'"
}

@akozumpl
Copy link
Contributor

Thanks!

@akozumpl akozumpl closed this Sep 16, 2014
@ignatenkobrain ignatenkobrain deleted the bash_completion branch June 21, 2016 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants