[Bash-completion-devel] mysql, sitecopy, cups
Raphaël
raphael.droz at gmail.com
Mon Jun 13 12:45:15 UTC 2011
Almost all issues have been addressed in the attached patches.
(but, if possible, I would like to stay away from the test suite for
now)
Raph
-------------- next part --------------
>From 0d21bec84e7b4efea0932be48382caf59411c8cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= <raphael.droz+floss at gmail.com>
Date: Mon, 13 Jun 2011 13:26:59 +0200
Subject: [PATCH 1/7] use _parse_help and handle $prev for sitecopy(1).
---
completions/sitecopy | 33 +++++++++++++++++++++++++++------
1 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/completions/sitecopy b/completions/sitecopy
index a6bb4b4..9d5cd5a 100644
--- a/completions/sitecopy
+++ b/completions/sitecopy
@@ -1,5 +1,6 @@
# sitecopy(1) completion
# Copyright 2003 Eelco Lempsink <eelcolempsink at gmx.net>
+# 2011 Rapha?l Droz <raphael.droz+floss at gmail.com>
# License: GNU GPL v2 or later
have sitecopy || return
@@ -9,18 +10,38 @@ _sitecopy()
local cur prev words cword
_init_completion || return
+ case $prev in
+ --debug|-d)
+ COMPREPLY=( $( compgen -W "socket files rcfile ftp http httpbody rsh sftp xml xmlparse cleartext" \
+ -- "$cur" ) )
+ compopt -o nospace
+ return 0
+ ;;
+ --logfile|-g|--rcfile|-r)
+ _filedir
+ return 0
+ ;;
+ --storepath|-p)
+ _filedir -d
+ return 0
+ ;;
+ esac
+
case $cur in
--*)
- COMPREPLY=( $( compgen -W "$(sitecopy -h | command grep -e '--\w' |\
- awk '{sub (/=(FILE|PATH)/, "", $2); print $2}')" -- "$cur" ) )
+ COMPREPLY=( $( compgen -W "$(_parse_help $1)" -- "$cur" ) )
+ [[ $COMPREPLY == *= ]] && compopt -o nospace
;;
- -*)
- COMPREPLY=( $( compgen -W "$(sitecopy -h | command grep -e '-\w' | \
- awk '{sub (",", "", $1); print $1}')" -- "$cur" ) )
+
+ # only complete long options
+ -)
+ compopt -o nospace
+ COMPREPLY=( -- )
;;
+
*)
if [ -r ~/.sitecopyrc ]; then
- COMPREPLY=( $( compgen -W "$(sitecopy -v | \
+ COMPREPLY=( $( compgen -W "$($1 -v | \
command sed -n '/^Site:/s/Site: //p')" -- "$cur" ) )
fi
;;
--
1.7.3.4
-------------- next part --------------
>From a3f02ad7739b288be0f5aa62915e45779a26d910 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= <raphael.droz+floss at gmail.com>
Date: Mon, 13 Jun 2011 13:28:35 +0200
Subject: [PATCH 2/7] removed superfluous compopt for cups.
---
completions/cups | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/completions/cups b/completions/cups
index 21ddd76..499a2b0 100644
--- a/completions/cups
+++ b/completions/cups
@@ -18,7 +18,6 @@ _lpr()
local cur prev words cword
_init_completion || return
- compopt +o nospace
case $prev in
-P)
COMPREPLY=( $( compgen -W "$( lpstat -a | cut -d' ' -f1 )" -- "$cur" ) )
--
1.7.3.4
-------------- next part --------------
>From 3ab99ffd85b764ce8adcc206a5336e5327523d17 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= <raphael.droz+floss at gmail.com>
Date: Mon, 13 Jun 2011 13:31:33 +0200
Subject: [PATCH 3/7] better compopt setting for lpr(1) -o option.
---
completions/cups | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/completions/cups b/completions/cups
index 499a2b0..c08544b 100644
--- a/completions/cups
+++ b/completions/cups
@@ -28,8 +28,8 @@ _lpr()
return 0
;;
-o)
- compopt -o nospace
COMPREPLY=( $( compgen -W "media= landscape orientation-requested= sides= fitplot number-up= scaling= cpi= lpi= page-bottom= page-top= page-left= page-right=" -- "$cur" ) )
+ [[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
;;
esac
--
1.7.3.4
-------------- next part --------------
>From ffd7e89a1639780fc33bb0333bfe9fc8557a71a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= <raphael.droz+floss at gmail.com>
Date: Mon, 13 Jun 2011 13:48:18 +0200
Subject: [PATCH 4/7] better use of _parse_help and compopt for mysql(1).
---
completions/mysql | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/completions/mysql b/completions/mysql
index 39eb0c6..aabffd9 100644
--- a/completions/mysql
+++ b/completions/mysql
@@ -1,14 +1,11 @@
# mysql(1) completion
have mysql || return
+
_mysql()
{
- local cur prev split=false
-
- COMPREPLY=()
- _get_comp_words_by_ref cur prev
-
- _split_longopt && split=true
+ local cur prev words cword split=false
+ _init_completion -n = || return
case $prev in
-u|--user)
@@ -16,7 +13,7 @@ _mysql()
return 0
;;
-D|--database)
- COMPREPLY=( $( compgen -W "$(mysqlshow|sed -ne '2d' -e 's/^|.\([^|]\+\)|.*/\1/p')" -- "$cur" ) )
+ COMPREPLY=( $( compgen -W "$(mysqlshow 2>/dev/null|sed -ne '2d' -e 's/^|.\([^|]*\)|.*/\1/p')" -- "$cur" ) )
return 0
;;
@@ -50,7 +47,8 @@ _mysql()
--ssl-ca|--ssl-cert|--ssl-cipher|--ssl-key|\
--connect_timeout|max_allowed_packet|--prompt|\
--net_buffer_length|--select_limit|--max_join_size|\
- --server-arg|--debug|--delimiter|--execute|-e|--pager)
+ --server-arg|--debug|--delimiter|--execute|-e|--pager|\
+ --password|-p)
# Argument required but no completions available
return 0
;;
@@ -60,9 +58,11 @@ _mysql()
;;
esac
- $split && return 0
+ local help=$(_parse_help "$1"|sed -e '/--password/s/$/=/')
+ help+=" --skip-comment --skip-ssl"
- COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
+ COMPREPLY=( $( compgen -W "$help" -- "$cur" ) )
+ [[ $COMPREPLY == *= ]] && compopt -o nospace
} &&
complete -F _mysql mysql
--
1.7.3.4
-------------- next part --------------
>From be1ab4b4e3fac0c801c02bd2bf52ea15f2d832ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= <raphael.droz+floss at gmail.com>
Date: Mon, 13 Jun 2011 13:51:39 +0200
Subject: [PATCH 5/7] added mysql to Makefile.am
---
completions/Makefile.am | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/completions/Makefile.am b/completions/Makefile.am
index 60fa8ea..324599c 100644
--- a/completions/Makefile.am
+++ b/completions/Makefile.am
@@ -105,6 +105,7 @@ bashcomp_DATA = abook \
mtx \
munin-node \
mutt \
+ mysql \
mysqladmin \
ncftp \
net-tools \
--
1.7.3.4
-------------- next part --------------
>From 1461b0c47a001fd6b61b9c1bba56208812339a31 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= <raphael.droz+floss at gmail.com>
Date: Mon, 13 Jun 2011 14:33:18 +0200
Subject: [PATCH 6/7] handle properly long-options in sitecopy(1).
---
completions/sitecopy | 17 ++++++++---------
1 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/completions/sitecopy b/completions/sitecopy
index 9d5cd5a..df3212d 100644
--- a/completions/sitecopy
+++ b/completions/sitecopy
@@ -7,8 +7,8 @@ have sitecopy || return
_sitecopy()
{
- local cur prev words cword
- _init_completion || return
+ local cur prev words cword split
+ _init_completion -s || return
case $prev in
--debug|-d)
@@ -31,22 +31,21 @@ _sitecopy()
--*)
COMPREPLY=( $( compgen -W "$(_parse_help $1)" -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
+ return 0
;;
# only complete long options
-)
compopt -o nospace
COMPREPLY=( -- )
- ;;
-
- *)
- if [ -r ~/.sitecopyrc ]; then
- COMPREPLY=( $( compgen -W "$($1 -v | \
- command sed -n '/^Site:/s/Site: //p')" -- "$cur" ) )
- fi
+ return 0
;;
esac
+ if [ -r ~/.sitecopyrc ]; then
+ COMPREPLY=( $( compgen -W "$($1 -v | \
+ command sed -n '/^Site:/s/Site: //p')" -- "$cur" ) )
+ fi
return 0
} &&
complete -F _sitecopy -o default sitecopy
--
1.7.3.4
-------------- next part --------------
>From 98cf27384c2785e6b895e7896ae0e7e29e78c69e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= <raphael.droz+floss at gmail.com>
Date: Mon, 13 Jun 2011 14:34:25 +0200
Subject: [PATCH 7/7] handle properly long options in mysql(1).
---
completions/mysql | 30 +++++++++++++++++++++++-------
1 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/completions/mysql b/completions/mysql
index aabffd9..b4fb576 100644
--- a/completions/mysql
+++ b/completions/mysql
@@ -4,8 +4,8 @@ have mysql || return
_mysql()
{
- local cur prev words cword split=false
- _init_completion -n = || return
+ local cur prev words cword split
+ _init_completion -s || return
case $prev in
-u|--user)
@@ -45,7 +45,7 @@ _mysql()
;;
--default-character-set|-P|--port|--set-variable|\
--ssl-ca|--ssl-cert|--ssl-cipher|--ssl-key|\
- --connect_timeout|max_allowed_packet|--prompt|\
+ --connect_timeout|--max_allowed_packet|--prompt|\
--net_buffer_length|--select_limit|--max_join_size|\
--server-arg|--debug|--delimiter|--execute|-e|--pager|\
--password|-p)
@@ -58,11 +58,27 @@ _mysql()
;;
esac
- local help=$(_parse_help "$1"|sed -e '/--password/s/$/=/')
- help+=" --skip-comment --skip-ssl"
+ case $cur in
+ --*)
+ # TODO: fix _parse_help
+ local help=$(_parse_help "$1"|sed -e '/--password/s/$/=/' -e 's/[.)]*$//')
+ help+=" --skip-comment --skip-ssl"
- COMPREPLY=( $( compgen -W "$help" -- "$cur" ) )
- [[ $COMPREPLY == *= ]] && compopt -o nospace
+ COMPREPLY=( $( compgen -W "$help" -- "$cur" ) )
+ [[ $COMPREPLY == *= ]] && compopt -o nospace
+ return 0
+ ;;
+
+ # only complete long options
+ -)
+ compopt -o nospace
+ COMPREPLY=( -- )
+ return 0
+ ;;
+ esac
+
+ COMPREPLY=( $( compgen -W "$(mysqlshow 2>/dev/null|sed -ne '2d' -e 's/^|.\([^|]*\)|.*/\1/p')" \
+ -- "$cur" ) )
} &&
complete -F _mysql mysql
--
1.7.3.4
More information about the Bash-completion-devel
mailing list