From c919fa7f691fc18af1a9beb60b8426ebc2fc7eac Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 21 Jun 2018 14:57:39 +0200 Subject: 43078: add completion for the sed expression --- Completion/Unix/Command/_sed | 217 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 206 insertions(+), 11 deletions(-) (limited to 'Completion/Unix') diff --git a/Completion/Unix/Command/_sed b/Completion/Unix/Command/_sed index 80218051b..f03278364 100644 --- a/Completion/Unix/Command/_sed +++ b/Completion/Unix/Command/_sed @@ -1,16 +1,60 @@ #compdef sed gsed psed s2p -local inplace extended -local -a args aopts=( -A '-*' ) +local variant inplace extended ign sep separator +local -i nest=0 +local -a args aopts sedexpr cmds_none cmds_slash cmds_end substflags expl bsnl nl labels excl dedup +local -a step range negate mods +aopts=( -A '-*' ) +bsnl=( $'\\\n' ) +nl=$'\n' +compquote nl +cmds_none=( + '{:start group' + 'q:quit after printing pattern space' + 'h:copy pattern space to hold space' + '\::place label' + '#:comment' + '=:print current line number' + 'a:append text' + 'i:insert text' + 'r:append contents of file' + 'b:branch' + 't:branch if s command has been successful' + 'c:replace line with text' + 'l:list current line in visually unambiguous form' + 'w:write pattern space to file' +) +cmds_slash=( + 's:substitute regex' + 'y:transliterate characters' +) +cmds_end=( + 'd:delete pattern space' + 'D:delete up to the first newline in the pattern space' + 'g:copy hold space to pattern space' + 'G:append hold space to pattern space' + 'H:append pattern space to hold space' + 'n:read the next line of input into pattern space' + 'N:append the next line of input to the pattern space' + 'p:print the current pattern space' + 'P:print upto the first newline of the current pattern space' + 'x:exchange hold and pattern spaces' + '}:end group' +) +substflags=( + 'g:replace all matches to the regular expression' + 'p:print new pattern space if substitution made' + 'w:write result to named file if substitution made' +) args=( '(-n --quiet --silent)'{-n,--quiet,--silent}'[suppress automatic printing of pattern space]' - '(1)*'{-e+,--expression=}'[specify sed commands to run]:sed script' - '(1)*'{-f+,--file=}'[add contents of file to commands to run]: :_files' - '(-e)1: :_guard "^-*" sed script' + '(1)*'{-e+,--expression=}'[specify sed commands to run]:sed script:_sed_expressions' + '(1)*'{-f+,--file=}'[add contents of file to commands to run]:file:_files' + '(-e)1:sed script:_sed_expressions' '*:input file:_files' ) -inplace='[edit files in-place, running scripts separately for each file]::suffix for backup' +inplace='[edit files in-place, running scripts separately for each file]:: :_guard "^(*[@/; ]*|?(#c6,)|-*)" "suffix for backup"' extended='[use extended regular expressions]' if [[ $service = (psed|s2p) ]]; then @@ -18,11 +62,12 @@ if [[ $service = (psed|s2p) ]]; then "${(@)args:#(|\(*\))(|\*)--*}" '-a[delay opening files listed with w function]' ) -elif _pick_variant gnu=GNU unix --version; then +elif _pick_variant -r variant gnu=GNU unix --version; then aopts=( ) + (( $#words > 2 )) && ign='!' args+=( '--follow-symlinks[follow symlinks when processing in place]' - '(-i --in-place)'{-i+,--in-place=}$inplace + '(-i --in-place -s --separate)'{-i-,--in-place=-}$inplace '(-c --copy)'{-c,--copy}'[copy instead of rename when shuffling files in in-place mode]' '(-l --line-length)'{-l+,--line-length=}'[specify line-wrap length for the l command]' '(-r)--posix[disable GNU extensions]' @@ -31,9 +76,28 @@ elif _pick_variant gnu=GNU unix --version; then '--sandbox[block commands that can affect the system (r/w/W/e)]' '(-u --unbuffered)'{-u,--unbuffered}'[disable data buffering]' '(-z --null-data)'{-z,--null-data}'[separate lines by NUL characters]' - '(- 1 :)--help[print program usage]' - '(- 1 :)--version[print program version]' + "${ign}(- 1 :)--help[print program usage]" + "${ign}(- 1 :)-