emoji: add fzf mode
This commit is contained in:
parent
b34e1121c1
commit
cc6b56e7a7
24
emoji.sh
24
emoji.sh
|
@ -19,6 +19,7 @@ usage() {
|
||||||
echo " -l LIMIT limit number of output lines"
|
echo " -l LIMIT limit number of output lines"
|
||||||
echo " -u unique result (equals -n and -l 1), no new line"
|
echo " -u unique result (equals -n and -l 1), no new line"
|
||||||
echo " -c show code point"
|
echo " -c show code point"
|
||||||
|
echo " -z use fzf mode"
|
||||||
echo " -d download UCD zip to create list file (requires curl)"
|
echo " -d download UCD zip to create list file (requires curl)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +40,8 @@ HIDE_NAME=
|
||||||
LIMIT=
|
LIMIT=
|
||||||
NO_NEW_LINE=
|
NO_NEW_LINE=
|
||||||
SHOW_CP=
|
SHOW_CP=
|
||||||
while getopts "hdnl:uc" OPTION; do
|
FZF_MODE=
|
||||||
|
while getopts "hdnl:ucz" OPTION; do
|
||||||
case $OPTION in
|
case $OPTION in
|
||||||
h) usage; exit 0 ;;
|
h) usage; exit 0 ;;
|
||||||
d) download_ucdxml; exit $? ;;
|
d) download_ucdxml; exit $? ;;
|
||||||
|
@ -47,6 +49,7 @@ while getopts "hdnl:uc" OPTION; do
|
||||||
l) LIMIT=$OPTARG ;;
|
l) LIMIT=$OPTARG ;;
|
||||||
u) HIDE_NAME=true; LIMIT=1; NO_NEW_LINE=true ;;
|
u) HIDE_NAME=true; LIMIT=1; NO_NEW_LINE=true ;;
|
||||||
c) SHOW_CP=true ;;
|
c) SHOW_CP=true ;;
|
||||||
|
z) FZF_MODE=true ;;
|
||||||
*) usage; exit 1 ;;
|
*) usage; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -58,8 +61,9 @@ if [ ! -f "$LIST" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
line_id=0
|
find_emojis() {
|
||||||
zcat "$LIST" | "$GREP" -i "$FILTER" | while read -r line; do
|
line_id=0
|
||||||
|
zcat "$LIST" | "$GREP" -i "$FILTER" | while read -r line; do
|
||||||
[ -n "$LIMIT" ] && (( line_id >= LIMIT )) && break
|
[ -n "$LIMIT" ] && (( line_id >= LIMIT )) && break
|
||||||
readarray -d ";" -t elements <<< "$line"
|
readarray -d ";" -t elements <<< "$line"
|
||||||
codepoint="${elements[0]}"
|
codepoint="${elements[0]}"
|
||||||
|
@ -74,4 +78,16 @@ zcat "$LIST" | "$GREP" -i "$FILTER" | while read -r line; do
|
||||||
[ "$NO_NEW_LINE" = true ] && echo_opt="-n" || echo_opt=""
|
[ "$NO_NEW_LINE" = true ] && echo_opt="-n" || echo_opt=""
|
||||||
echo "$echo_opt" "$result"
|
echo "$echo_opt" "$result"
|
||||||
line_id=$(( line_id + 1 ))
|
line_id=$(( line_id + 1 ))
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$FZF_MODE" = true ]; then
|
||||||
|
result="$(find_emojis | fzf)"
|
||||||
|
echo "$result"
|
||||||
|
if command -v xclip > /dev/null; then
|
||||||
|
echo -n "$(awk '{print $1}' <<< "$result")" | xclip
|
||||||
|
echo "(copied to X clipboard)"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
find_emojis
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in a new issue