From 2394cfdd863ffe390f36192a8b4487dd3c15a904 Mon Sep 17 00:00:00 2001 From: Viktor Varland Date: Thu, 5 Feb 2026 15:49:49 +0100 Subject: [PATCH] fix: handle newlines --- README.md | 4 +++- search.sh | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e4079db..12742b6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/search.sh b/search.sh index f479c17..ba0b520 100755 --- a/search.sh +++ b/search.sh @@ -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