Hi,

I made some changes to make the patch without use of perl :)
What do you think?

>>> Jean Delvare <[email protected]> 01/23/13 11:02 AM >>>
Le dimanche 20 janvier 2013 à 21:46 +0100, Martin Quinson a écrit :
> Hello Daniel,
> 
> well, I dunno. My feeling is that firering a perl process each time we
> press on tab is somehow wrong. But I now realize that quilt already
> depends on perl on several locations. That looks wrong to me but if
> the others don't mind, I guess that your patch can get in as it is.

I do agree with Martin's initial rant about using perl here. This is
simply wrong. I couldn't find any other bash completion script relying
on perl. Doing so would be wrong from a performance perspective.

Even from a dependency perspective it is wrong. While quilt does indeed
use perl for several helper scripts, none of these is mandatory. You can
do a lot with quilt without ever running guards, dependency-graph,
edmail or remove-trailing-ws.

So, please, no perl for bash completion. Please do the best you can with
sed, grep, awk and friends.

Thanks,
-- 
Jean Delvare
Suse L3



diff --git a/bash_completion b/bash_completion
index 19736cb..f6824e9 100644
--- a/bash_completion
+++ b/bash_completion
@@ -86,6 +86,30 @@ _quilt_comfile()
         done
 }
 
+
+# Quote a string for use in a basic regular expression.
+quote_bre()
+{
+       echo "$1" | sed -e 's:\([][^$/.*\\]\):\\\1:g'
+}
+
+# Resolve paths to patches only inside QUILT_PATCHES directory
+# 
+# Problem with `quilt series` within completion is it's nature of output
+#  as it produces relative path to current working directory, instead of 
+#  relative path to QUILT_PATCHES directory.
+#
+# sed explanation: capture as many as possible of "../" and after that
+#  QUILT_PATCHES directory name (if not defined, use default "patches")
+#  and remove it all from each filename
+#
+
+_quilt_patchlist()
+{
+       local quoted=$(quote_bre ${QUILT_PATCHES:-patches})
+       quilt "$1" | sed "s:^\\(\\.\\./\\)*${quoted}/\\?::" 
+}
+
 _quilt_completion()
 {
     local cur prev cmds command_matches
@@ -123,7 +147,7 @@ _quilt_completion()
        add)
           case $prev in
             -P)
-               COMPREPLY=( $( compgen -W "$(quilt applied 2>/dev/null)" -- 
$cur ) )
+               COMPREPLY=( $( compgen -W "$(_quilt_patchlist applied 
2>/dev/null)" -- $cur ) )
                ;;
             *)
                _quilt_comfile
@@ -134,7 +158,7 @@ _quilt_completion()
        annotate)
           case $prev in
             -P)
-               COMPREPLY=( $( compgen -W "$(quilt applied 2>/dev/null)" -- 
$cur ) )
+               COMPREPLY=( $( compgen -W "$(_quilt_patchlist applied 
2>/dev/null)" -- $cur ) )
                ;;
             *)
                _quilt_comfile
@@ -143,10 +167,10 @@ _quilt_completion()
           esac
           ;;
        applied) 
-          COMPREPLY=( $( compgen -W "-h $(quilt applied 2>/dev/null)" -- $cur 
) )
+          COMPREPLY=( $( compgen -W "-h $(_quilt_patchlist applied 
2>/dev/null)" -- $cur ) )
           ;;
        delete) 
-          COMPREPLY=( $( compgen -W "-n -r -h --backup $(quilt series)" -- 
$cur ) )
+          COMPREPLY=( $( compgen -W "-n -r -h --backup $(_quilt_patchlist 
series)" -- $cur ) )
           ;;
        diff) 
           case $prev in
@@ -154,7 +178,7 @@ _quilt_completion()
                COMPREPLY=( $( compgen -W "0 1" -- $cur ) )
                ;;
             -P|--combine)
-               COMPREPLY=( $( compgen -W "$(quilt applied 2>/dev/null)" -- 
$cur ) )
+               COMPREPLY=( $( compgen -W "$(_quilt_patchlist applied 
2>/dev/null)" -- $cur ) )
                ;;
             --diff|-U|-C)
                ;;
@@ -171,10 +195,10 @@ _quilt_completion()
        files)
           case $prev in
             --combine)
-               COMPREPLY=( $( compgen -W "$(quilt applied 2>/dev/null)" -- 
$cur ) )
+               COMPREPLY=( $( compgen -W "$(_quilt_patchlist applied 
2>/dev/null)" -- $cur ) )
                ;;
             *)
-               COMPREPLY=( $( compgen -W "-a -l -v -h --combine $(quilt 
applied 2>/dev/null)" -- $cur ) )
+               COMPREPLY=( $( compgen -W "-a -l -v -h --combine 
$(_quilt_patchlist applied 2>/dev/null)" -- $cur ) )
                ;;
           esac
           ;;
@@ -198,7 +222,7 @@ _quilt_completion()
                COMPREPLY=( $( compgen -W "files" -- $cur ) )
                ;;
             *)
-               COMPREPLY=( $( compgen -W "-T -h --all --reduce --lines 
--edge-labels $(quilt applied 2>/dev/null)" -- $cur ) )
+               COMPREPLY=( $( compgen -W "-T -h --all --reduce --lines 
--edge-labels $(_quilt_patchlist applied 2>/dev/null)" -- $cur ) )
                ;;
           esac
           ;;
@@ -207,7 +231,7 @@ _quilt_completion()
           COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -W "-h" -- $cur ) )
           ;;
        header)
-          COMPREPLY=( $( compgen -W "-a -e -h -r --backup --strip-diffstat 
--strip-trailing-whitespace $(quilt series)" -- $cur ) )
+          COMPREPLY=( $( compgen -W "-a -e -h -r --backup --strip-diffstat 
--strip-trailing-whitespace $(_quilt_patchlist series)" -- $cur ) )
           ;;
        import)
           case $prev in
@@ -229,17 +253,17 @@ _quilt_completion()
           COMPREPLY=( $( compgen -W "-m --prefix --mbox --send --sender --from 
--subject --to --cc --bcc" -- $cur ) )
           ;;
        next|previous)
-          COMPREPLY=( $( compgen -W "$(quilt series)" -- $cur ) )
+          COMPREPLY=( $( compgen -W "$(_quilt_patchlist series)" -- $cur ) )
           ;;
        patches)
           _quilt_comfile 
           COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -W "-v -h" -- $cur ) )
           ;;
        pop)
-          COMPREPLY=( $( compgen -W "-a -f -R -q -v -h $(quilt applied 
2>/dev/null)" -- $cur ) )
+          COMPREPLY=( $( compgen -W "-a -f -R -q -v -h $(_quilt_patchlist 
applied 2>/dev/null)" -- $cur ) )
           ;;
        push)
-          COMPREPLY=( $( compgen -W "-a -f -q -v -h --leave-rejects 
--interactive --color $(quilt unapplied 2>/dev/null)" -- $cur ) )
+          COMPREPLY=( $( compgen -W "-a -f -q -v -h --leave-rejects 
--interactive --color $(_quilt_patchlist unapplied 2>/dev/null)" -- $cur ) )
           ;;
        refresh)
           case $prev in
@@ -249,14 +273,14 @@ _quilt_completion()
             -U|-C)
                ;;
             *)
-               COMPREPLY=( $( compgen -W "-p -u -U -c -C -f -h $(quilt applied 
2>/dev/null) --no-timestamps --no-index --diffstat --sort --backup 
--strip-trailing-whitespace" -- $cur ) )
+               COMPREPLY=( $( compgen -W "-p -u -U -c -C -f -h 
$(_quilt_patchlist applied 2>/dev/null) --no-timestamps --no-index --diffstat 
--sort --backup --strip-trailing-whitespace" -- $cur ) )
                ;;
           esac
           ;;
        remove|revert)
           case $prev in
             -P)
-               COMPREPLY=( $( compgen -W "$(quilt applied 2>/dev/null)" -- 
$cur ) )
+               COMPREPLY=( $( compgen -W "$(_quilt_patchlist applied 
2>/dev/null)" -- $cur ) )
                ;;
             *)
                _quilt_comfile 
@@ -267,7 +291,7 @@ _quilt_completion()
        rename)
           case $prev in
             -P)
-               COMPREPLY=( $( compgen -W "$(quilt series)" -- $cur ) )
+               COMPREPLY=( $( compgen -W "$(_quilt_patchlist series)" -- $cur 
) )
                ;;
             *)
                COMPREPLY=( $( compgen -W "-P -h" -- $cur ) )
@@ -292,7 +316,7 @@ _quilt_completion()
           COMPREPLY=( $( compgen -W "-d -h" -- $cur ) )
           ;;
        unapplied)
-          COMPREPLY=( $( compgen -W "-h $(quilt series)" -- $cur ) )
+          COMPREPLY=( $( compgen -W "-h $(_quilt_patchlist series)" -- $cur ) )
           ;;
        fork|new|top|upgrade)
           ;;
_______________________________________________
Quilt-dev mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/quilt-dev

Reply via email to