@@ -50,11 +50,8 @@ is_true() { [[ -n "$1" ]] && "${1:l}" == (1|y(es|)|t(rue|)|o(n|)) ]]; }
5050
5151# Trim string.
5252str_trim () {
53- local s=" $1 "
54- # Trim leading and trailing spaces.
55- s=" ${s# " ${s%% [![:space:]]* } " } "
56- s=" ${s% " ${s##* [![:space:]]} " } "
57- printf ' %s' " $s "
53+ # Trim leading and trailing spaces using parameter expansion.
54+ printf ' %s' " ${${1## [[:space:]]## } %% [[:space:]]## } "
5855}
5956
6057epoch () {
@@ -91,7 +88,7 @@ cache_dir() {
9188 local result
9289 if [[ " ${ANTIDOTE_OSTYPE} " == darwin* ]]; then
9390 result=" $HOME /Library/Caches"
94- elif [[ " ${ANTIDOTE_OSTYPE} " == cygwin* || " ${ANTIDOTE_OSTYPE} " == msys* ]]; then
91+ elif [[ " ${ANTIDOTE_OSTYPE} " == ( cygwin| msys) * ]]; then
9592 result=" ${LOCALAPPDATA:- $LocalAppData } "
9693 if (( $+ commands[cygpath] )) ; then
9794 result=" $( cygpath " $result " ) "
@@ -109,22 +106,23 @@ cache_dir() {
109106 say " $result "
110107}
111108
112- # Collect <redirected or piped| input.
109+ # Collect <redirected or piped> input.
113110collect_args () {
114- local arg line
115111 local -a results=()
116112
117- for arg in " $@ " ; do
118- arg= " ${arg // \\ n / $NL } "
119- while IFS= read -r line || [[ -n " $line " ]] ; do
120- results+=( " $line " )
121- done < <( printf ' %s ' " $arg " )
122- done
113+ # Process arguments (split on newlines)
114+ if (( $# > 0 )) ; then
115+ results=( " ${(f @ ) ${(j : \n : ) @ } } " )
116+ fi
117+
118+ # Read from stdin if not a terminal
123119 if [[ ! -t 0 ]]; then
120+ local line
124121 while IFS= read -r line || [[ -n " $line " ]]; do
125122 results+=(" $line " )
126123 done
127124 fi
125+
128126 typeset -ga reply=(" ${results[@]} " )
129127 [[ " $ANTIDOTE_DEBUG " != true ]] || say " ${reply[@]} "
130128}
@@ -177,10 +175,8 @@ gitcmd() {
177175
178176# Use shell's lexer for word splitting rules
179177wordsplit () {
180- local str=" $* "
181- str=" ${str// \$ / \\\$ } "
182- eval " set -- $str "
183- typeset -ga reply=(" $@ " )
178+ # Use the (z) flag for shell word splitting
179+ typeset -ga reply=(" ${(z)* } " )
184180 [[ " $ANTIDOTE_DEBUG " != true ]] || say " ${reply[@]} "
185181}
186182
@@ -434,7 +430,7 @@ git_branch() { gitcmd -C "$1" rev-parse --abbrev-ref HEAD; }
434430git_sha () { gitcmd -C " $1 " rev-parse HEAD; }
435431git_repodate () { gitcmd -C " $1 " log -1 --format=%cd --date=short; }
436432git_clone () {
437- local -a $ o_branch =()
433+ local -a o_branch=()
438434 [[ -z " $3 " ]] || o_branch=(--branch " $3 " )
439435 gitcmd clone --quiet --recurse-submodules --shallow-submodules $o_branch " $1 " " $2 "
440436}
0 commit comments