Refactor _f_last_updated

This commit is contained in:
Stig-Ørjan Smelror 2024-02-12 22:44:57 +01:00
parent 0dfa793dae
commit 80e1874926

23
qsgen2
View File

@ -422,27 +422,30 @@ function _last_updated() {
} }
function _f_last_updated() { function _f_last_updated() {
# This function updates #updated and #version tags in the provided string in files # Updates #updated and #version tags in the provided file using Zsh
if [[ ${globaldebug} == "true" ]]; then if [[ ${globaldebug} == "true" ]]; then
local debug=true local debug=true
else else
# If you want to debug this function only, set this to true
local debug=false local debug=false
fi fi
if (${debug}); then _msg debug "_f_last_updated: Setting date and version in footer of file ${1}"; fi local file_path="${1}"
if (${debug}); then _msg debug "_f_last_updated: ${upd_msg}"; fi
local upd_msg="Last updated ${today} by <a href=\"https://blog.kekepower.com/qsgen2.html\">${QSGEN} ${VERSION}</a>" local upd_msg="Last updated ${today} by <a href=\"https://blog.kekepower.com/qsgen2.html\">${QSGEN} ${VERSION}</a>"
local content="${1}" if ${debug}; then
_msg debug "_f_last_updated: Setting date and version in footer of file ${file_path}"
_msg debug "_f_last_updated: ${upd_msg}"
fi
# Perform the replacements # Read the file content into a variable
tee < ${content} | sed \ local content="$(<${file_path})"
-e "s|#updated|${upd_msg}|" \
> ${content}
# Perform the replacement
content="${content//#updated/${upd_msg}}"
# Write the updated content back to the file
print -r -- "$content" >| "${file_path}"
} }
function _file_to_lower() { function _file_to_lower() {