From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 8afad4ff for ; Fri, 1 Feb 2019 19:09:00 +0000 (UTC) Received: (qmail 5712 invoked by alias); 1 Feb 2019 19:08:46 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44033 Received: (qmail 28847 invoked by uid 1010); 1 Feb 2019 19:08:46 -0000 X-Qmail-Scanner-Diagnostics: from mail-it1-f196.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.100.2/25112. spamassassin: 3.4.2. Clear:RC:0(209.85.166.196):SA:0(-1.9/5.0):. Processed in 3.3894 secs); 01 Feb 2019 19:08:46 -0000 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=sTTXNRuuewCbMbYx2v+ShA9k1NUJBS7jJuRkKmgGqZs=; b=RbfsXvRsFjZuKOQeRDq93Zd9AOG6S96IagViaVqZi+XPVZerc6CytDw3aH+//vt9lG mezFAV5pTSDSRnLLbRHmrCYXFOMKTAF7krBv6AEp7u/3UvU9hn0yiDVCBxlRgkhDMmIr cUyK74kFGUC/9WjR48bgVvpndUsTvQaR/ionJRQgpDr1APm9UWWRCLCsblyktzHlt82T Y9L8tjxJQsYSbIS4VL3jYQk7i4c2SX9PhUUMN7AM4gOhMG0Hwi4EfOymaIeGD9TF3Akg 3vSYKT5XN/QplH2Dhmei2YwbNun3+uTYPpXBY5Rr9khRCJn4hVnheE4EJFNW2plxm3MA dT0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=sTTXNRuuewCbMbYx2v+ShA9k1NUJBS7jJuRkKmgGqZs=; b=pkb3HmVlOq6wqsXtHvqJCMTMxay+jVasZcDYBfVgZumBZToTcgCu9teA5tPhI7lmNR ipmUWo28m0jW4xcGTllUGDhpI5vVBOR/Muliolxg8ckNQX3ThnVEV5y0B9Gk/6wNijNW jlQSPV/2HeLyIsTBhsuyAuTt6v+/J2vY9ryKsmAa+E8AiDHME3PwVvop1rtjpVuLacug C7GZfcPeYYtXrpODmqNA6degbqtPDARTiFWjuJdpjossaNrUz8ZZ6FwpYA1kyYwX7zoV 4Er2Gl8v9RsPnfdCxJlO12rw8i29xQBmjov1oDZLBrvdgyAhXc/cJ7aGPnhwFEDpEL2d gQYg== X-Gm-Message-State: AJcUukeoAMqhjinXWBkLcZXEQAPvy2edo/rR/IJBQgqIKokA+c7dgn5X 9KHVHYwXfD1oMTXB3GLvFlUZHnNv+Ug= X-Google-Smtp-Source: ALg8bN7lrhTp9Y39NV2n/3nWXRPaCxjBYj0xRxB8UiS7HOHHW34wX0hZW3zzgWjkCJJcnk0WYMvRww== X-Received: by 2002:a02:a589:: with SMTP id b9mr24575746jam.113.1549048119570; Fri, 01 Feb 2019 11:08:39 -0800 (PST) From: dana Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.0 \(3445.100.39\)) Subject: [PATCH] Completion: Add _dos2unix Message-Id: <7299F2D6-B525-4EA7-A7EA-335996E53365@dana.is> Date: Fri, 1 Feb 2019 13:08:38 -0600 To: Zsh workers X-Mailer: Apple Mail (2.3445.100.39) New function for (i think) the most popular dos2unix/unix2dos = implementations dana diff --git a/Completion/Unix/Command/_dos2unix = b/Completion/Unix/Command/_dos2unix new file mode 100644 index 000000000..c7820a8ec --- /dev/null +++ b/Completion/Unix/Command/_dos2unix @@ -0,0 +1,129 @@ +#compdef dos2unix unix2dos mac2unix unix2mac + +local variant ret=3D1 +local -a context expl line state state_descr cp_opts xl_opts args +local -A opt_args + +# Code-page options for ISO translation (use group `cp`) +cp_opts=3D( + '(-7 -ascii)-437[use DOS code page 437 (US) for ISO translation]' + '(-7 -ascii)-850[use DOS code page 850 (Western European) for ISO = translation]' + '(-7 -ascii)-860[use DOS code page 860 (Portuguese) for ISO = translation]' + '(-7 -ascii)-863[use DOS code page 863 (French Canadian) for ISO = translation]' + '(-7 -ascii)-865[use DOS code page 865 (Nordic) for ISO translation]' + + '(-7 -ascii)-1252[use Windows code page 1252 (Western European) for = ISO translation]' +) +# Translation/conversion options (use group `xl`) +xl_opts=3D( + '(cp)-7[also replace 8-bit characters by 7-bit spaces]' + '(cp)-ascii[convert only line breaks (CRLF<->LF)]' + '-iso[also convert between DOS and ISO character sets]' + + {-c,--convmode}'[specify conversion mode]:conversion mode:(( + 7bit\:"also replace 8-bit characters by 7-bit spaces" + ascii\:"convert only line breaks (CRLF<->LF)" + iso\:"also convert between DOS and ISO character sets" + mac\:"convert only line breaks (CR<->LF)" + ))' + {-ub,--assume-utf16be}'[assume input file format is UTF-16BE]' + {-ul,--assume-utf16le}'[assume input file format is UTF-16LE]' +) + +# `dos2unix` here is the dos2unix package provided by many Linux = distributions, +# Homebrew, &al. `unix2dos` is the unix2dos package provided by = FreeBSD, &al. +# Some implementations (Solaris) don't bother with any kind of argument +# validation, so we pass in /dev/null to make sure they never hang +_pick_variant -r variant \ + dos2unix=3D'(#i)waterlan' \ + unix2dos=3D'-p' \ + $OSTYPE \ + --version /dev/null{,} + +case $variant in + dos2unix) + # -D and -gb are omitted, since they only make sense on Windows + args=3D( + '(: * -)'{-h,--help}'[display help information]' + '(: * -)'{-L,--license}'[display license information]' + '(: * -)'{-V,--version}'[display version information]' + '(-l --newline)'{-l,--newline}'[write two line breaks to output = for each converted line break]' + '(-u --keep-utf16)'{-u,--keep-utf16}'[write output in same UTF-16 = encoding as input]' + '*:: :->file' + + '(qv)' # Verbosity options + {-q,--quiet}'[reduce output verbosity]' + {-v,--verbose}'[increase output verbosity]' + + '(cp)' # Code-page options + $cp_opts + + '(xl)' # Translation/conversion options + $xl_opts + + bm # BOM options + '(-b -r --keep-bom --remove-bom)'{-b,--keep-bom}'[write existing = BOM to output]' + '(-m -r --add-bom --remove-bom)'{-m,--add-bom}'[write new BOM to = output]' + '(bm)'{-r,--remove-bom}"[don't write BOM to output]" + + '(ch)' # chown options + '--allow-chown[allow file-ownership changes in old-file mode]' + "--no-allow-chown[don't allow file-ownership changes in old-file = mode]" + + '(fs)' # Force/safe options + {-f,--force}'[force conversion of binary files]' + {-s,--safe}'[skip binary files]' + + '(in)' # Info options + {-i-,--info=3D-}'[display (specified) file information]:: = :->info' + + '(ln)' # Symlink options + {-F,--follow-symlink}'[follow symbolic links]' + {-R,--replace-symlink}'[replace symbolic links]' + {-S,--skip-symlink}'[skip symbolic links]' + + '(no)' # File-mode options + {-n,--newfile}'[convert each input file to specified output = file]' + {-o,--oldfile}'[convert input files in place]' + ) + # No stacking! + _arguments -S -A '-*' : $args && ret=3D0 + + case $state in + file) + if (( CURRENT % 2 =3D=3D 0 )) && [[ -n = ${opt_args[(I)*-(-n|--newfile)]} ]]; then + _description files expl 'output file' + else + _description files expl 'input file' + fi + _files "${(@)expl}" && ret=3D0 + ;; + info) + _values -s '' 'information flag [dumbt]' \ + '0[end each output line with NUL instead of newline]' \ + 'b[show BOM type]' \ + 'c[show only files that would be converted]' \ + 'd[show number of DOS line breaks (CRLF)]' \ + 'h[show header]' \ + 'm[show number of Mac line breaks (CR)]' \ + 'p[show file names without paths]' \ + 't[show whether file is text or binary]' \ + 'u[show number of UNIX line breaks (LF)]' \ + && ret=3D0 + ;; + esac + + return ret + ;; + unix2dos) + _arguments -s -S -A '-*' : \ + '-p[preserve access and modification times]' \ + '*:input file:_files' + return + ;; + solaris*) + _arguments -A '-*' : \ + '1:input file:_files' \ + '2:output file:_files' \ + + '(cp)' \ + ${(@M)cp_opts:#(|\([^\)]#\))-(437|850|860|863|865)(|\[*)} \ + + '(xl)' \ + ${(@M)xl_opts:#(|\([^\)]#\))-(7|ascii|iso)(|\[*)} + return + ;; + *) + _default + return + ;; +esac