From 1ec8e6689effa0169e435c846957c3248f4f5e85 Mon Sep 17 00:00:00 2001 From: Abubakar Yagoub Date: Sat, 3 Dec 2022 04:27:16 +0800 Subject: [PATCH] zsh: treat zsh history file as text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit .z-history file is saved as data leading to grep displaying a message about the file being a binary after each command, the `-a` flag makes grep treat binary files as text eliminating the message. before: ```bash ~ ❯ read start_ts <<< "$( grep "^:" "${HISTFILE}" | tail -n1 | cut -d: -f2 )" grep: /home/blacksuan19/.zsh_history: binary file matches ``` After: ```bash ~ ❯ read start_ts <<< "$( grep -a "^:" "${HISTFILE}" | tail -n1 | cut -d: -f2 )" ``` --- zsh.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh.sh b/zsh.sh index af7b6f5..7c6f396 100644 --- a/zsh.sh +++ b/zsh.sh @@ -46,7 +46,7 @@ function __ash_last_command() { [[ "${ASH:-0}" == "0" ]] && __ash_info __ash_last_command && return local cmd cmd_no start_ts end_ts=$( date +%s ) - read start_ts <<< "$( grep "^:" "${HISTFILE}" | tail -n1 | cut -d: -f2 )" + read start_ts <<< "$( grep -a "^:" "${HISTFILE}" | tail -n1 | cut -d: -f2 )" read -r cmd_no cmd <<< "$( builtin history -1 )" echo -E ${cmd_no:-0} ${start_ts:-0} ${end_ts:-0} "${cmd:-UNKNOWN}" }