[PATCH] contrib: check completionhints file for possible completions

Matt Mackall mpm at selenic.com
Wed Sep 16 14:52:29 CDT 2015


On Tue, 2015-09-15 at 13:30 -0700, Gulshan Singh wrote:
> # HG changeset patch
> # User Gulshan Singh <gulshan at fb.com>
> # Date 1441845115 25200
> #      Wed Sep 09 17:31:55 2015 -0700
> # Node ID 4e3b6c50e59e493d6ef557476f962770787ba3c3
> # Parent  ab1c6e4efda47281b14a4f5a46cc0d4a114fff7d
> contrib: check completionhints file for possible completions
> 
> Check a file called completionhints in the .hg directory for possible completions.
> Each line of this file can be a possible completion. This is useful so we can store
> things like recently viewed hashes in this file and use them for completion, and
> at some point allow us to do bookmark autocompletion without executing hg.

Very interesting.

> diff --git a/contrib/bash_completion b/contrib/bash_completion
> --- a/contrib/bash_completion
> +++ b/contrib/bash_completion
> @@ -54,11 +54,36 @@
>  
>  shopt -s extglob
>  
> +_find_root()
> +{
> +    d=$PWD
> +    while : ; do
> +        if [[ -d "$d/.hg" ]]; then
> +            echo $d
> +            return
> +        fi
> +        [[ "$d" = / ]] && break
> +        d=$(cd -P "$d/.." && echo "$PWD")
> +    done
> +}

This wants to be a patch of its own.

>  _hg_cmd()
>  {
>      HGPLAIN=1 "$hg" "$@" 2>/dev/null
>  }
>  
> +_hg_completionhints()
> +{
> +    local root=$(_find_root)
> +    if [[ -n "$root" ]]; then
> +        local hint_file="$root/.hg/completionhints"
> +        if [ -e "$hint_file" ]; then
> +            local hints=$(cat "$hint_file")
> +            COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$hints' -- "$cur"))
> +        fi
> +    fi
> +}

We probably want to add a parameter to this function to say what type of
hints we want and then tweak the hint filename.

> +
>  _hg_commands()
>  {
>      local commands
> @@ -113,6 +138,7 @@
>      local labels="$(_hg_cmd debugnamecomplete "$cur")"
>      local IFS=$'\n'
>      COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$labels' -- "$cur"))
> +    _hg_completionhints
>  }

How do things get into the hints file? How do we clean the file when it
gets stale?

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list