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=( address@hidden:-} $( 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=( address@hidden:-} $( 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) ;;