2015-11-12 22:08:47 +08:00
# Completion for builtin string
# This follows a strict command-then-options approach, so we can just test the number of tokens
complete -f -c string
2019-06-16 13:30:31 +08:00
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and not contains -- (commandline -opc)[2] escape collect" -s q -l quiet -d "Do not print output"
2019-01-22 09:08:49 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "lower"
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "upper"
2015-11-12 22:08:47 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "length"
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "sub"
2019-09-24 13:43:38 +08:00
complete -x -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] sub" -s s -l start -xa "(seq 1 10)"
complete -x -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] sub" -s l -l length -xa "(seq 1 10)"
2015-11-12 22:08:47 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "split"
2019-01-22 09:08:49 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "split0"
complete -x -c string -n 'test (count (commandline -opc)) -ge 2; and string match -qr split0\?\$ -- (commandline -opc)[2]' -s m -l max -a "(seq 1 10)" -d "Specify maximum number of splits"
complete -f -c string -n 'test (count (commandline -opc)) -ge 2; and string match -qr split0\?\$ -- (commandline -opc)[2]' -s r -l right -d "Split right-to-left"
2019-02-07 19:45:17 +08:00
complete -f -c string -n 'test (count (commandline -opc)) -ge 2; and string match -qr split0\?\$ -- (commandline -opc)[2]' -s n -l no-empty -d "Empty results excluded"
2019-06-16 13:30:31 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "collect"
2019-06-17 07:40:14 +08:00
complete -f -c string -n 'test (count (commandline -opc)) -ge 2; and string match -qr collect\$ -- (commandline -opc)[2]' -s N -l no-trim-newlines -d "Don't trim trailing newlines"
2019-02-07 19:45:17 +08:00
2015-11-12 22:08:47 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "join"
2019-01-22 09:08:49 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "join0"
2015-11-12 22:08:47 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "trim"
2019-02-07 19:45:17 +08:00
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] trim" -s l -l left -d "Trim only leading chars"
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] trim" -s r -l right -d "Trim only trailing chars"
2019-09-24 13:43:38 +08:00
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] trim" -s c -l chars -d "Specify the chars to trim (default: whitespace)" -x
2015-11-12 22:08:47 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "escape"
2019-01-22 09:08:49 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "unescape"
2019-02-07 19:45:17 +08:00
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] escape; or contains -- (commandline -opc)[2] unescape" -s n -l no-quoted -d "Escape with \\ instead of quotes"
2019-09-24 13:43:38 +08:00
complete -x -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] escape; or contains -- (commandline -opc)[2] unescape" -l style -d "Specify escaping style" -xa "
2018-11-13 01:56:11 +08:00
( printf '%s\t%s\n' script 'For use in scripts' \
var 'For use as a variable name' \
2019-01-22 09:08:49 +08:00
regex 'For string match -r, string replace -r' \
2018-11-13 01:56:11 +08:00
url 'For use as a URL' ) "
2015-11-12 22:08:47 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "match"
2019-02-07 19:45:17 +08:00
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] match" -s n -l index -d "Report index, length of match"
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] match" -s v -l invert -d "Report only non-matches"
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] match" -s e -l entire -d "Show entire matching lines"
2015-11-12 22:08:47 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "replace"
2019-02-07 19:45:17 +08:00
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] replace" -s f -l filter -d "Report only actual replacements"
2015-11-12 22:08:47 +08:00
# All replace options are also valid for match
2019-02-07 19:45:17 +08:00
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] match replace" -s a -l all -d "Report every match"
2016-06-14 14:10:05 +08:00
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] match replace" -s i -l ignore-case -d "Case insensitive"
2015-11-12 22:08:47 +08:00
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] match replace" -s r -l regex -d "Use regex instead of globs"
2019-02-07 19:45:17 +08:00
2017-03-07 22:39:21 +08:00
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a "repeat"
2019-09-24 13:43:38 +08:00
complete -x -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] repeat" -s n -l count -xa "(seq 1 10)" -d "Repetition count"
complete -x -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] repeat" -s m -l max -xa "(seq 1 10)" -d "Maximum number of printed chars"
2017-03-07 22:39:21 +08:00
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] repeat" -s N -l no-newline -d "Remove newline"