Skip to content

Commit

Permalink
Fix #348
Browse files Browse the repository at this point in the history
This is because grep may not be able to correctly distinguish tab characters.
In order to solve this, added a ltsv parser written by awk.

- Fix #326 (see also second commit in P-R #344), fix #348
- Add `__zplug::utils::awk::ltsv function`
  • Loading branch information
babarot committed Jan 6, 2017
1 parent 951e74d commit 8deef6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/job/process.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ __zplug::job::process::get_status_code() {
fi

cat "$_zplug_log[$target]" \
| grep "^repo:$repo\t" \
| awk '{print $2}' \
| cut -d: -f2
| __zplug::utils::awk::ltsv \
'key("repo")=="'"$repo"'"{print key("status")}'

return $status
}

Expand Down
21 changes: 21 additions & 0 deletions base/utils/awk.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,24 @@ __zplug::utils::awk::available()
return 1
fi
}

__zplug::utils::awk::ltsv()
{
local \
user_awk_script="$1" \
ltsv_awk_script

ltsv_awk_script=$(cat <<-'EOS'
function key(name) {
for (i = 1; i <= NF; i++) {
match($i, ":");
xs[substr($i, 0, RSTART)] = substr($i, RSTART+1);
};
return xs[name":"];
}
EOS
)

awk -F'\t' \
"${ltsv_awk_script} ${user_awk_script}"
}

0 comments on commit 8deef6e

Please sign in to comment.