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

Add shell-completion for available function names #22

Open
sharkdp opened this issue Apr 1, 2018 · 3 comments
Open

Add shell-completion for available function names #22

sharkdp opened this issue Apr 1, 2018 · 3 comments

Comments

@sharkdp
Copy link
Owner

sharkdp commented Apr 1, 2018

ls | map <TAB>
@rpdeo
Copy link

rpdeo commented Apr 3, 2018

here is a sample completion function for bash

#!/bin/bash
# bash completion for shell-functools

ft_functions="$(ft-functions | sed -E 's/�\[[0-9]+m//g' | cut -f1 -d' ')"

function _complete_ft() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="-h --help -c --column"

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    else
        COMPREPLY=( $(compgen -W "${ft_functions}" -- ${cur}) )
        return 0
    fi
}
complete -F _complete_ft map
complete -F _complete_ft filter
complete -F _complete_ft foldl

Install to /etc/bash_completions.d/shell-functools.sh
See here for an intro: https://debian-administration.org/article/317/An_introduction_to_bash_completion_part_2

Interesting project..., cheers!

rpdeo added a commit to rpdeo/shell-functools that referenced this issue Apr 3, 2018
* see sharkdp#22 on sharkdp/shell-functools
@sharkdp
Copy link
Owner Author

sharkdp commented Apr 3, 2018

@rpdeo Cool, thanks!

We should probably add an option to ft-functions that only outputs the function names without any ANSI codes and type annotations (actually, it would be super-cool to additionally show the type annotations in the tab-completion without pasting it on the command line, in a similar way how command line options are shown with the help text).

@rpdeo
Copy link

rpdeo commented Apr 4, 2018

You are welcome!

I have not looked at the python code yet to fully understand the Command class, but am pretty sure it can be extended well with python modules like prompt_toolkit, cliff and click. If I come up with something along those lines that might be worth merging, will let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants