From 1f7cd8cfa76eacacee683fcc413b16745da0edb7 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 5 Jan 2023 16:34:06 +0100 Subject: [PATCH] dic: fix edge case --- .config/shell/functions | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.config/shell/functions b/.config/shell/functions index 9f56e9d..3c99402 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -394,8 +394,9 @@ hex() { hexyl "$@" | "${PAGER:-less}"; } export DICT="$XDG_DATA_HOME/dictcc" dic() { - result=$(cat $DICT/dict.txt | sed '/#/d;/&/d;/^$/d' | fzf --tiebreak=chunk,length --bind='alt-bspace:clear-query' --print-query --query="$1") && - dic "$(echo "$result" | tail -1 | sed 's/\t/\n/g' | head -2 | grep --invert-match --ignore-case "$(echo "$result" | head -1)" || echo "$result" | head -1 | sed 's/ \W.*//')" + result=$(cat $DICT/dict.txt | sed '/#/d;/&/d;/^$/d' | FZF_DEFAULT_OPTS=${FZF_DEFAULT_OPTS#--exit-0} fzf --tiebreak=chunk,length --bind='alt-bspace:clear-query' --print-query --query="$1") && + dic "$(echo "$result" | tail -1 | sed 's/\t/\n/g' | head -2 | grep --invert-match --ignore-case "$(echo "$result" | head -1)" --max-count 1 || echo "$result" | head -1 | sed 's/ \W.*//')" + # Could be slightly improved using fzf -f to reproduce selection } #fzf --tiebreak=length --bind='alt-bspace:clear-query' alias dict="rlwrap rdictcc --directory $DICT"