From 195001e359f52a43029dea116eededa7bfbe14d0 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Wed, 4 Nov 2020 23:31:25 +0800 Subject: [PATCH] [feature] rename dict to d --- bin/{dict => d} | 11 ++++++++--- fish/config/config.fish | 20 -------------------- 2 files changed, 8 insertions(+), 23 deletions(-) rename bin/{dict => d} (88%) diff --git a/bin/dict b/bin/d similarity index 88% rename from bin/dict rename to bin/d index f91197d..0262628 100755 --- a/bin/dict +++ b/bin/d @@ -1,5 +1,7 @@ #!/bin/sh +# shellcheck disable=2086 + set -e DIR="$(readlink -f "$(dirname "$0")")" DMENU_OPTS='-i -c -fn monospace:13 -nb #626262 -nf #bbbbbb -sb #5b97f7 -sf #eeeeee -l 20' @@ -34,7 +36,7 @@ display() { fi display elif echo "$INPUT" | grep -P '^ '; then - echo -n $INPUT | sed 's/^\s+//' | xsel -b + printf "%s" "$INPUT" | sed 's/^\s+//' | xsel -b else SENTENCE="$INPUT" request @@ -44,7 +46,10 @@ display() { SENTENCE="$*" -[ -z "$SENTENCE" ] && SENTENCE="$(xsel -o)" -request +if [ -n "$SENTENCE" ]; then + request +else + display +fi #pronounce "$@" diff --git a/fish/config/config.fish b/fish/config/config.fish index 9c1f803..c77ed8a 100644 --- a/fish/config/config.fish +++ b/fish/config/config.fish @@ -5,26 +5,6 @@ function dt date "+%Y%m%d-%H%M%S" end -# translation -function d - set meta ( - curl -SsLG "http://cn.bing.com/dict/search" --data-urlencode "q=$argv" | \ - string match -r '' - ) - set trans (string replace -ra '\W(?=(\w+\.|网络释义:))' \n $meta[2]) - string join \n $trans -end - -# pronounciation -function dp - set play afplay - if not which $play 2>/dev/null - set play ffplay -nodisp -autoexit - end - wget -O /tmp/sound.mp3 "http://dict.youdao.com/dictvoice?audio=$argv[1]&type=1" &>/dev/null - and eval $play /tmp/sound.mp3 1>/dev/null 2>/dev/null -end - function clean-taobao-link echo "$argv" | sed 's/^\(.*\)?\(.*&\)\?\(id=[^&]\+\).*$/\1?\3/g' | xsel -sb end