[Bps-public-commit] Path-Dispatcher branch, master, updated. e0bc61977f0364ce4191597bba6a65805388c5af

Shawn Moore sartak at bestpractical.com
Fri Jun 18 14:13:16 EDT 2010


The branch, master has been updated
       via  e0bc61977f0364ce4191597bba6a65805388c5af (commit)
      from  72e497e41161e9783689b2b6f071cb377bee0b69 (commit)

Summary of changes:
 lib/Path/Dispatcher/Cookbook.pod |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

- Log -----------------------------------------------------------------
commit e0bc61977f0364ce4191597bba6a65805388c5af
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Fri Jun 18 14:14:17 2010 -0400

    Documentation for shell tab completion

diff --git a/lib/Path/Dispatcher/Cookbook.pod b/lib/Path/Dispatcher/Cookbook.pod
index 60982d0..20d9b9f 100644
--- a/lib/Path/Dispatcher/Cookbook.pod
+++ b/lib/Path/Dispatcher/Cookbook.pod
@@ -55,5 +55,37 @@ You can use a C<chain> rule approximate chaining behavior:
 
     MyDispatcher->run("show score"); # "Displaying score:\n ..."
 
+=head2 How can I configure tab completion for shells?
+
+First add a dispatcher rule for generating completions based on the path. Here
+we name it _gencomp, so that if the user types "app _gencomp hel" it will print
+out the various completions of "hel".
+
+    on qr/^_gencomp\s*(.*)/ => sub {
+        my $self = shift;
+        my $path = $1;
+        $path = "" if !defined($path);
+        print "$_\n" for dispatcher->complete($path);
+    };
+
+Then tell your shell about how to use _gencomp. For zsh it might look
+like this (replace "app" with your binary name):
+
+    /usr/share/zsh/site-functions/_app:
+        #compdef app
+        typeset -a app_completions
+        app_completions=($($words[1] _gencomp $words[2,-1]))
+        compadd $app_completions
+
+For bash it might look like this:
+
+    /etc/bash_completion.d/app.bash:
+        function _app_()
+        {
+            COMPREPLY=($($1 _gencomp ${COMP_WORDS[COMP_CWORD]}))
+        }
+
+        complete -F _app_ app
+
 =cut
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list