From 190500bf1de6a89416e2a74470d3b5cceab102ba Mon Sep 17 00:00:00 2001 From: Aloxaf Date: Fri, 12 Nov 2021 14:26:25 +0800 Subject: [PATCH] fix: remove NUL in string when pass it to awk a better fix for #218 --- lib/ftb-tmux-popup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ftb-tmux-popup b/lib/ftb-tmux-popup index 1139ff2..7e74d3c 100755 --- a/lib/ftb-tmux-popup +++ b/lib/ftb-tmux-popup @@ -40,7 +40,7 @@ zstyle -a ":fzf-tab:$_ftb_curcontext" popup-pad popup_pad || popup_pad=(0 0) # get the size of content, note we should remove all ANSI color code comp_lines=$(( ${#${(f)mapfile[$tmp_dir/completions.$$]}} + $popup_pad[2] )) -if (( comp_lines <= 500 || ! $+commands[gawk] )); then +if (( comp_lines <= 500 )); then comp_length=0 for line in ${(f)mapfile[$tmp_dir/completions.$$]}; do length=${(m)#${(S)line//$'\x1b['[0-9]#*m}} @@ -48,7 +48,7 @@ if (( comp_lines <= 500 || ! $+commands[gawk] )); then done else # FIXME: can't get the correct width of CJK characters. - comp_length=$(command sed 's/\x1b\[[0-9;]*m//g' $tmp_dir/completions.$$ | command gawk 'length > max_length { max_length = length; } END { print max_length }') + comp_length=$(command sed 's/\x1b\[[0-9;]*m//g;s/\x00//g' $tmp_dir/completions.$$ | command awk 'length > max_length { max_length = length; } END { print max_length }') fi comp_length=$(( comp_length + $popup_pad[1] ))