[Bash-completion-devel] mplayer list-options language agnostic

gibboris at gmail.com gibboris at gmail.com
Tue Dec 8 00:44:32 UTC 2009


Hi,
the mplayer/mencoder is english only.
because of a
sed -ne '1,/^[[:space:]]*Name/d'

I felt the need to change this [patch attached]
and switched to a white-list regexp approach.
(It paradoxally added 2 missing options containing
a star in the doc)

I don't understand why a sort wasn't part of the compgen call.
Is there any implicit rule here ?

About the _mplayer_options_list, it's harder since
the help arguments doesn't output something easily parsable in
a common way.
'Available' can't be used, rest the ^.*:$ pattern,
(in french is the header lines match ^.* :$ while in english ^.*[^ ]:$  )

The ${2#-} should be given an explanation in a comment (which filter
it applied to)

"-vop has been removed, use -vf instead."

Raph
-------------- next part --------------
diff --git a/contrib/mplayer b/contrib/mplayer
index 7a43f84..41c822f 100644
--- a/contrib/mplayer
+++ b/contrib/mplayer
@@ -4,8 +4,9 @@ have mplayer && {
 _mplayer_options_list()
 {
     cur=${cur%\\}
+    #sed -ne 's/^ *\([a-z0-9]*\) *[0-9].*/\1/p'
     COMPREPLY=( $( compgen -W "$( $1 $2 help 2>/dev/null | \
-        sed -e '1,/^Available/d' | awk '{print $1}' | \
+        sed -e '1,/:$/d' | awk '{print $1}' | \
         sed -e 's/:$//' -e 's/^'${2#-}'$//' -e 's/<.*//' )" -- "$cur" ) )
 }
 
@@ -19,7 +20,7 @@ _mplayer()
     prev=${COMP_WORDS[COMP_CWORD-1]}
 
     case "$prev" in
-        -[av][cfo]|-[av]fm|-vop|-fstype|-demuxer|-o[av]c|-of|-profile)
+        -[av][cfo]|-[av]fm|-fstype|-demuxer|-o[av]c|-of|-profile)
             _mplayer_options_list $cmd $prev
             return 0
             ;;
@@ -231,10 +232,9 @@ _mplayer()
 
     case "$cur" in
         -*)
-            COMPREPLY=( $( compgen -W '$( $cmd -list-options 2>/dev/null | \
-                sed -ne '1,/^[[:space:]]*Name/d' \
-                    -e "s/^[[:space:]]*/-/" -e "s/[[:space:]:].*//" \
-                    -e "/^-\(Total\|.*\*\)\?$/!p" )' -- "$cur" ) )
+            COMPREPLY=( $( compgen -W '$( $cmd -list-options 2>/dev/null |\
+                                          sed -n "s/^[[:space:]]*\([a-z0-9_-]\+\).*/-\1/p" |\
+                                          sort -u)' -- "$cur" ) )
             ;;
         *)
             _filedir '@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|ASF|vob|VOB|bin|BIN|dat|DAT|vcd|VCD|ps|PS|pes|PES|fl[iv]|FL[IV]|viv|VIV|rm?(j)|RM?(J)|ra?(m)|RA?(M)|yuv|YUV|mov|MOV|qt|QT|mp[234]|MP[234]|m4[av]|M4[AV]|og[gmavx]|OG[GMAVX]|w?(a)v|W?(A)V|dump|DUMP|mk[av]|MK[AV]|m4a|M4A|aac|AAC|m[24]v|M[24]V|dv|DV|rmvb|RMVB|mid|MID|ts|TS|3g[p2]|mpc|MPC|flac|FLAC|vro|VRO|divx|DIVX|aif?(f)|AIF?(F)|m2ts|M2TS|vdr|VDR|xvid|XVID|ape|APE)'


More information about the Bash-completion-devel mailing list