shell-functools icon indicating copy to clipboard operation
shell-functools copied to clipboard

Add shell-completion for available function names

Open sharkdp opened this issue 6 years ago • 3 comments

ls | map <TAB>

sharkdp avatar Apr 01 '18 20:04 sharkdp

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 avatar Apr 03 '18 13:04 rpdeo

@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).

sharkdp avatar Apr 03 '18 19:04 sharkdp

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.

rpdeo avatar Apr 04 '18 04:04 rpdeo