]> Sergey Matveev's repositories - zk.zsh.git/commitdiff
mapfile instead of cat-like call is faster
authorSergey Matveev <stargrave@stargrave.org>
Tue, 15 Mar 2022 09:18:08 +0000 (12:18 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 15 Mar 2022 09:18:08 +0000 (12:18 +0300)
zk.zsh

diff --git a/zk.zsh b/zk.zsh
index 94653b1965db5edfa3a39cc8060f7fc6e7a84085..fe3f62e9018e63d2b855a22c314592990418a4f6 100755 (executable)
--- a/zk.zsh
+++ b/zk.zsh
@@ -19,7 +19,6 @@ EOF
 
 [[ $# -eq 2 ]] || usage
 
-# Collect all pages
 setopt GLOB_STAR_SHORT
 zmodload -F zsh/stat b:zstat
 typeset -A pages
@@ -30,13 +29,13 @@ for p (**(.)) {
 typeset -a cats
 for p (**(/)) cats=($p $cats)
 
-# Determine the links between them
+zmodload zsh/mapfile
 typeset -A links
 typeset -A backs
 typeset -aU words
 for p (${(k)pages}) {
     words=()
-    for w (`< $p`) {
+    for w (${=mapfile[$p]}) {
         [[ $w =~ "\[(.*)\]" ]] || continue
         w=${match[1]}
         [[ ${pages[$w]} ]] || {
@@ -74,7 +73,7 @@ getrel() {
 genHTML() {
     local page=$1
     local data p
-    [[ $# -eq 1 ]] && data=`< $page` || data=$2
+    [[ $# -eq 1 ]] && data=${mapfile[$page]} || data=$2
     data=${data//&/&amp;}
     data=${data//</&lt;}
     data=${data//>/&gt;}
@@ -99,7 +98,7 @@ $data
 }
 
 zmodload -F zsh/datetime b:strftime
-now=$(strftime "%F %T")
+strftime -s now "%F %T"
 
 genIndex() {
     local p