fix: handle newlines

This commit is contained in:
Viktor Varland 2026-02-05 15:49:49 +01:00
parent 1dc3e8842f
commit 2394cfdd86
No known key found for this signature in database
GPG key ID: 991E991EBEC46432
2 changed files with 4 additions and 1 deletions

View file

@ -18,7 +18,9 @@ histcmd_dir="$HOME/dev/vlv/shell-history"
_add_history() {
if test "$(id -u)" -ne 0; then
echo "$(date --utc --iso-8601=seconds) $(hostname) $(pwd) $(fc -ln -1)" >> $histdb_dir/zsh-history-$(date "+%Y-%m-%d").log;
local cmd=$(fc -ln -1)
cmd=${cmd//$'\n'/\\n}
echo "$(date --utc --iso-8601=seconds) $(hostname) $(pwd) $cmd" >> $histdb_dir/zsh-history-$(date "+%Y-%m-%d").log;
fi
}
add-zsh-hook precmd _add_history

View file

@ -24,6 +24,7 @@ if [[ -d "$histdb" ]]; then
)"
entry_cmd="$(<<<$entry awk -F' ' '{ print substr($0, index($0, $4)) }')"
entry_cmd="${entry_cmd//\\n/$'\n'}" # unescape newlines
if [[ "$entry" ]]; then
eval $copy_cmd <<< "$entry_cmd" >/dev/null