* Small patch for FFmpeg completion function
@ 2011-04-26 21:48 Haakon Riiser
2011-04-28 14:46 ` Haakon Riiser
0 siblings, 1 reply; 4+ messages in thread
From: Haakon Riiser @ 2011-04-26 21:48 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 157 bytes --]
This is a patch for Completion/Unix/Command/_ffmpeg (CVS rev 1.2)
It adds the "copy" keyword as an extra completion to -acodec and
-vcodec.
--
Haakon
[-- Attachment #2: ffmpeg-codec-copy.patch --]
[-- Type: text/x-patch, Size: 1652 bytes --]
--- _ffmpeg 26 Apr 2011 21:36:04 -0000 1.9
+++ _ffmpeg 26 Apr 2011 21:36:17 -0000 1.10
@@ -11,27 +11,27 @@
}
_ffmpeg_presets() {
local presets
presets=(~/.ffmpeg/*.ffpreset(:t:r) "$FFMPEG_DATADIR"/*.ffpreset(:t:r))
_ffmpeg_compadd 'select preset' presets ''
}
_ffmpeg_acodecs() {
local acodecs
- acodecs=(${${(M)${(f)"$(ffmpeg -codecs 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]]A[S[:space:]][D[:space:]][T[:space:]][[:space:]][^[:space:]]##*}//(#b)????????([^[:space:]]##)*/$match[1]})
+ acodecs=(copy ${${(M)${(f)"$(ffmpeg -codecs 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]]A[S[:space:]][D[:space:]][T[:space:]][[:space:]][^[:space:]]##*}//(#b)????????([^[:space:]]##)*/$match[1]})
_ffmpeg_compadd 'force audio codec (''copy'' to copy stream)' acodecs ''
}
_ffmpeg_vcodecs() {
local vcodecs
- vcodecs=(${${(M)${(f)"$(ffmpeg -codecs 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]]V[S[:space:]][D[:space:]][T[:space:]][[:space:]][^[:space:]]##*}//(#b)????????([^[:space:]]##)*/$match[1]})
+ vcodecs=(copy ${${(M)${(f)"$(ffmpeg -codecs 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]]V[S[:space:]][D[:space:]][T[:space:]][[:space:]][^[:space:]]##*}//(#b)????????([^[:space:]]##)*/$match[1]})
_ffmpeg_compadd 'force video codec (''copy'' to copy stream)' vcodecs ''
}
_ffmpeg_formats() {
local formats
formats=(${(ou)${=${(s:,:)${${(M)${(f)"$(ffmpeg -formats 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]][[:space:]][^[:space:]]##*}//(#b)????([^[:space:]]##)*/$match[1]}}}})
_ffmpeg_compadd 'force format' formats ''
}
_ffmpeg_list_pix_fmts() {
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Small patch for FFmpeg completion function
2011-04-26 21:48 Small patch for FFmpeg completion function Haakon Riiser
@ 2011-04-28 14:46 ` Haakon Riiser
2011-04-30 20:59 ` Peter Stephenson
0 siblings, 1 reply; 4+ messages in thread
From: Haakon Riiser @ 2011-04-28 14:46 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 775 bytes --]
On Tue, 26 Apr 2011 23:48:21 +0200, Haakon Riiser
<haakon.riiser@fys.uio.no> wrote:
> This is a patch for Completion/Unix/Command/_ffmpeg (CVS rev 1.2)
> It adds the "copy" keyword as an extra completion to -acodec and
> -vcodec.
Decided to clean it up further. Obviously it is better to avoid having
Perl as a dependency, so the attached version does everything using zsh
scripting. It also uses _call_program and $words[1] instead of "ffmpeg"
directly.
No differences other than that: The completion function should produce
the same results as the previous one that used Perl. Because of the
large diff, the entire completion function is attached. It is based on
the last version I sent (which again is based on the last version in
CVS).
--
Haakon
[-- Attachment #2: _ffmpeg --]
[-- Type: application/octet-stream, Size: 6489 bytes --]
#compdef ffmpeg
local context state line
typeset -A opt_args
local -a _ffmpeg_argspecs
local BOLD=$'\e[1m'
local NORM=$'\e[m'
(( $+functions[_ffmpeg_compadd] )) || _ffmpeg_compadd() {
compadd -X "${BOLD}$1${NORM}" -q -S "$3" -a $2
}
(( $+functions[_ffmpeg_presets] )) || _ffmpeg_presets() {
local presets
presets=(~/.ffmpeg/*.ffpreset(:t:r) "$FFMPEG_DATADIR"/*.ffpreset(:t:r))
_ffmpeg_compadd 'select preset' presets ''
}
(( $+functions[_ffmpeg_acodecs] )) || _ffmpeg_acodecs() {
local acodecs
acodecs=(copy ${${(M)${(f)"$(_call_program audio-codecs $words[1] -codecs 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]]A[S[:space:]][D[:space:]][T[:space:]][[:space:]][^[:space:]]##*}//(#b)????????([^[:space:]]##)*/$match[1]})
_ffmpeg_compadd 'force audio codec (''copy'' to copy stream)' acodecs ''
}
(( $+functions[_ffmpeg_vcodecs] )) || _ffmpeg_vcodecs() {
local vcodecs
vcodecs=(copy ${${(M)${(f)"$(_call_program video-codecs $words[1] -codecs 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]]V[S[:space:]][D[:space:]][T[:space:]][[:space:]][^[:space:]]##*}//(#b)????????([^[:space:]]##)*/$match[1]})
_ffmpeg_compadd 'force video codec (''copy'' to copy stream)' vcodecs ''
}
(( $+functions[_ffmpeg_formats] )) || _ffmpeg_formats() {
local formats
formats=(${(ou)${=${(s:,:)${${(M)${(f)"$(_call_program formats $words[1] -formats 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]][[:space:]][^[:space:]]##*}//(#b)????([^[:space:]]##)*/$match[1]}}}})
_ffmpeg_compadd 'force format' formats ''
}
(( $+functions[_ffmpeg_list_pix_fmts] )) || _ffmpeg_list_pix_fmts() {
print -l ${${(M)${(f)"$(_call_program pix-fmts $words[1] -pix_fmts 2>/dev/null)"}:#[I.]*}//(#b)??????([^[:space:]]##)*/$match[1]}
}
(( $+functions[_ffmpeg_pix_fmts] )) || _ffmpeg_pix_fmts() {
local pix_fmts
pix_fmts=($(_ffmpeg_list_pix_fmts))
_ffmpeg_compadd 'set pixel format' pix_fmts ''
}
(( $+functions[_ffmpeg_bsfs] )) || _ffmpeg_bsfs() {
local bsfs
bsfs=(${${(f)"$(_call_program bsfs $words[1] -bsfs 2>/dev/null)"}:#*:})
_ffmpeg_compadd 'set bitstream filter' bsfs ''
}
{
local lastopt
local lastopt_description
local lastopt_takesargs
local -a lastopt_values
_call_program options $words[1] -h 2>/dev/null | while IFS=$'\n' read -r; do
if [[ $REPLY == -* ]]; then
if [[ -n $lastopt ]]; then
if (( lastopt_takesargs )); then
lastopt+=":$lastopt_description:"
if (( $#lastopt_values )); then
lastopt+="(${lastopt_values[*]})"
fi
fi
_ffmpeg_argspecs+=$lastopt
fi
lastopt=${REPLY%%[[:space:]]*}
lastopt_description=${REPLY##-[^[:space:]]##[[:space:]]##}
if [[ $lastopt_description == '<'* ]]; then
lastopt_description=${lastopt_description##<[^[:space:]]##>[[:space:]]##[^[:space:]]##[[:space:]]#}
if [[ -z $lastopt_description ]]; then
lastopt_description=$lastopt
fi
lastopt_description=${lastopt_description//:/\\:}
elif [[ $lastopt_description == [^[:space:]]##[[:space:]][[:space:]]* ]]; then
local example=${lastopt_description%% *}
example=${example//:/\\:}
lastopt_description=${lastopt_description##[^[:space:]]##[[:space:]]##}
lastopt_description=${lastopt_description//:/\\:}
if [[ $example == filename ]]; then
lastopt_takesargs=0
lastopt+=":$lastopt_description:_files"
elif [[ $lastopt == -[asv]pre ]]; then
lastopt_takesargs=0
lastopt+=": :_ffmpeg_presets"
elif [[ $lastopt == -acodec ]]; then
lastopt_takesargs=0
lastopt+=": :_ffmpeg_acodecs"
elif [[ $lastopt == -vcodec ]]; then
lastopt_takesargs=0
lastopt+=": :_ffmpeg_vcodecs"
elif [[ $lastopt == -f ]]; then
lastopt_takesargs=0
lastopt+=": :_ffmpeg_formats"
elif [[ $lastopt == -pix_fmt ]]; then
lastopt_takesargs=0
lastopt+=": :_ffmpeg_pix_fmts"
elif [[ $example == bitstream_filter ]]; then
lastopt_takesargs=0
lastopt+=": :_ffmpeg_bsfs"
else
lastopt_takesargs=1
lastopt_description+=" ($example)"
fi
else
lastopt_takesargs=0
if [[ $lastopt == -vfilters ]]; then
lastopt+=": :->vfilters"
fi
fi
lastopt_values=()
elif [[ $REPLY == ' '* ]]; then
REPLY=${REPLY##[[:space:]]##}
REPLY=${REPLY%%[[:space:]]##*}
lastopt_takesargs=1
lastopt_values+=$REPLY
fi
done
if [[ -n $lastopt ]]; then
if (( lastopt_takesargs )); then
lastopt+=":$lastopt_description:"
if (( $#lastopt_values )); then
lastopt+="(${lastopt_values[*]})"
fi
fi
_ffmpeg_argspecs+=$lastopt
fi
}
_arguments -S \
"${_ffmpeg_argspecs[@]}" \
'*:output file:_files' \
&& return 0
[[ "$state" == "vfilters" ]] &&
_values -s , -S = 'video filters' \
'aspect:set aspect ratio (rational number X\:Y or decimal number):' \
'crop:crop input video (x\:y\:width\:height):' \
'format: :->format' \
'noformat: :->noformat' \
'null' \
'pad:add pads to the input image (width\:height\:x\:y\:color_string):' \
'pixelaspect:set pixel aspect ratio (rational number X\:Y or decimal number):' \
'scale:scale input video (width\:height):' \
'slicify:output slice height ("random" or a number of pixels):' \
'unsharp:luma_x\:luma_y\:luma_amount\:chroma_x\:chroma_y\:chroma_amount:' \
'vflip' \
'buffer' \
'nullsrc' \
'nullsink' \
&& return 0
[[ "$state" == "format" ]] &&
_values -s : -S = 'convert input video to one of the specified pixel formats' $(_ffmpeg_list_pix_fmts) && return 0
[[ "$state" == "noformat" ]] &&
_values -s : -S = 'disable specified pixel formats by force' $(_ffmpeg_list_pix_fmts) && return 0
return 1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Small patch for FFmpeg completion function
2011-04-28 14:46 ` Haakon Riiser
@ 2011-04-30 20:59 ` Peter Stephenson
2011-04-30 23:03 ` Haakon Riiser
0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2011-04-30 20:59 UTC (permalink / raw)
To: zsh-workers
On Thu, 28 Apr 2011 16:46:19 +0200
Haakon Riiser <haakon.riiser@fys.uio.no> wrote:
> On Tue, 26 Apr 2011 23:48:21 +0200, Haakon Riiser
> <haakon.riiser@fys.uio.no> wrote:
> > This is a patch for Completion/Unix/Command/_ffmpeg (CVS rev 1.2)
> > It adds the "copy" keyword as an extra completion to -acodec and
> > -vcodec.
>
> Decided to clean it up further. Obviously it is better to avoid having
> Perl as a dependency, so the attached version does everything using zsh
> scripting. It also uses _call_program and $words[1] instead of "ffmpeg"
> directly.
Thanks, committed this without doing more than a cursory scan of it ---
no doubt someone will say if they're having problems.
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Small patch for FFmpeg completion function
2011-04-30 20:59 ` Peter Stephenson
@ 2011-04-30 23:03 ` Haakon Riiser
0 siblings, 0 replies; 4+ messages in thread
From: Haakon Riiser @ 2011-04-30 23:03 UTC (permalink / raw)
To: Peter Stephenson; +Cc: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 2249 bytes --]
On Sat, 30 Apr 2011 21:59:44 +0100, Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
> On Thu, 28 Apr 2011 16:46:19 +0200
> Haakon Riiser <haakon.riiser@fys.uio.no> wrote:
>> Decided to clean it up further. Obviously it is better to avoid
>> having
>> Perl as a dependency, so the attached version does everything using
>> zsh
>> scripting. It also uses _call_program and $words[1] instead of
>> "ffmpeg"
>> directly.
>
> Thanks, committed this without doing more than a cursory scan of it
> ---
> no doubt someone will say if they're having problems.
Thank you for committing the patch so soon. Unfortunately, I found a
couple of more things to improve. :)
First of all, there was a bug in the pixel format completion - it
included an invalid match. This bug was not introduced by my previous
patch, it has been there for a long time.
The second thing I changed was not a bug, but probably something that
was poor form. Previously, I did this:
local BOLD=$'\e[1m'
local NORM=$'\e[m'
compadd -X "${BOLD}description{NORM}" -q -S '' -a array
Here, "array" contains a list of keywords to be completed (e.g., a list
of codec names), and "description" contains a description headline to be
displayed at the top, above the list of keywords. The $BOLD and $NORM
escape codes were used to make it visually identical to description
headers in other functions (e.g., _files). This method worked, but I
never liked hard-coding ANSI escape codes directly. Now, this is
replaced by:
_wanted ffmpeg-XXX expl 'description' compadd -a array
Seems to work just as well, and I don't need the ANSI escapes.
Hopefully, this is the correct way to insert matches directly. If you
notice something else that is poor form, let me know and I will fix it.
PS: I have also recently written a completion function for nmcli (the
command-line interface to NetworkManager, which is used in a lot of
Linux distros). It was a bit tricky to get right, because a deep nesting
of subcommands and non-standard command line parsing. I think I got it
right, but I haven't posted it here yet. Thought I'd get the _ffmpeg
improvements out of the way first, so that I don't make the same
mistakes in _nmcli.
--
Haakon
[-- Attachment #2: fixed_pix_fmt_completion.patch --]
[-- Type: text/x-patch, Size: 3485 bytes --]
Index: _ffmpeg
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_ffmpeg,v
retrieving revision 1.3
diff -u -1 -0 -r1.3 _ffmpeg
--- _ffmpeg 30 Apr 2011 20:58:49 -0000 1.3
+++ _ffmpeg 30 Apr 2011 22:46:59 -0000
@@ -1,64 +1,56 @@
#compdef ffmpeg
-local context state line
+local context state line expl
typeset -A opt_args
-local -a _ffmpeg_argspecs
-
-local BOLD=$'\e[1m'
-local NORM=$'\e[m'
-
-(( $+functions[_ffmpeg_compadd] )) || _ffmpeg_compadd() {
- compadd -X "${BOLD}$1${NORM}" -q -S "$3" -a $2
-}
-
(( $+functions[_ffmpeg_presets] )) || _ffmpeg_presets() {
local presets
presets=(~/.ffmpeg/*.ffpreset(:t:r) "$FFMPEG_DATADIR"/*.ffpreset(:t:r))
- _ffmpeg_compadd 'select preset' presets ''
+ _wanted ffmpeg-presets expl 'select preset' compadd -a presets
}
(( $+functions[_ffmpeg_acodecs] )) || _ffmpeg_acodecs() {
local acodecs
acodecs=(copy ${${(M)${(f)"$(_call_program audio-codecs $words[1] -codecs 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]]A[S[:space:]][D[:space:]][T[:space:]][[:space:]][^[:space:]]##*}//(#b)????????([^[:space:]]##)*/$match[1]})
- _ffmpeg_compadd 'force audio codec (''copy'' to copy stream)' acodecs ''
+ _wanted ffmpeg-audio-codecs expl 'force audio codec (''copy'' to copy stream)' compadd -a acodecs
}
(( $+functions[_ffmpeg_vcodecs] )) || _ffmpeg_vcodecs() {
local vcodecs
vcodecs=(copy ${${(M)${(f)"$(_call_program video-codecs $words[1] -codecs 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]]V[S[:space:]][D[:space:]][T[:space:]][[:space:]][^[:space:]]##*}//(#b)????????([^[:space:]]##)*/$match[1]})
- _ffmpeg_compadd 'force video codec (''copy'' to copy stream)' vcodecs ''
+ _wanted ffmpeg-video-codecs expl 'force video codec (''copy'' to copy stream)' compadd -a vcodecs
}
(( $+functions[_ffmpeg_formats] )) || _ffmpeg_formats() {
local formats
formats=(${(ou)${=${(s:,:)${${(M)${(f)"$(_call_program formats $words[1] -formats 2>/dev/null)"}:#[[:space:]][D[:space:]][E[:space:]][[:space:]][^[:space:]]##*}//(#b)????([^[:space:]]##)*/$match[1]}}}})
- _ffmpeg_compadd 'force format' formats ''
+ _wanted ffmpeg-formats expl 'force format' compadd -a formats
}
(( $+functions[_ffmpeg_list_pix_fmts] )) || _ffmpeg_list_pix_fmts() {
- print -l ${${(M)${(f)"$(_call_program pix-fmts $words[1] -pix_fmts 2>/dev/null)"}:#[I.]*}//(#b)??????([^[:space:]]##)*/$match[1]}
+ echo - ${${${(M)${(f)"$(_call_program formats $words[1] -pix_fmts 2>/dev/null)"}:#[I.][O.][H.][P.][B.] [^=[:space:]]*}#* }%% *}
}
(( $+functions[_ffmpeg_pix_fmts] )) || _ffmpeg_pix_fmts() {
local pix_fmts
pix_fmts=($(_ffmpeg_list_pix_fmts))
- _ffmpeg_compadd 'set pixel format' pix_fmts ''
+ _wanted ffmpeg-pix-fmts expl 'set pixel format' compadd -a pix_fmts
}
(( $+functions[_ffmpeg_bsfs] )) || _ffmpeg_bsfs() {
local bsfs
bsfs=(${${(f)"$(_call_program bsfs $words[1] -bsfs 2>/dev/null)"}:#*:})
- _ffmpeg_compadd 'set bitstream filter' bsfs ''
+ _wanted ffmpeg-bsfs expl 'set bitstream filter' compadd -a bsfs
}
+local -a _ffmpeg_argspecs
{
local lastopt
local lastopt_description
local lastopt_takesargs
local -a lastopt_values
_call_program options $words[1] -h 2>/dev/null | while IFS=$'\n' read -r; do
if [[ $REPLY == -* ]]; then
if [[ -n $lastopt ]]; then
if (( lastopt_takesargs )); then
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-04-30 23:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-26 21:48 Small patch for FFmpeg completion function Haakon Riiser
2011-04-28 14:46 ` Haakon Riiser
2011-04-30 20:59 ` Peter Stephenson
2011-04-30 23:03 ` Haakon Riiser
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).