[PATCH] contrib: check completionhints file for possible completions

Gulshan Singh gulshan at fb.com
Tue Sep 15 20:30:08 UTC 2015


# 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.

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
+}
+
 _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
+}
+
 _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
 }
 
 # this is "kind of" ugly...


More information about the Mercurial-devel mailing list