commit e5d2adf4fefc8896f8f7340cd42140ba84c8f132
parent 55fadd5af9ae61a98890dd31b1068e046af7fd98
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Fri, 24 May 2019 14:01:22 +0200
Suggest defining text in clipboard in --gui mode
Diffstat:
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/.local/bin/define b/.local/bin/define
@@ -1,7 +1,7 @@
-#!/usr/bin/env bash
+#!/bin/sh
set -e
-function show_help {
+show_help() {
echo "usage: ${0##*/} [OPTIONS] TERM[S]"
echo "shows definitions for each TERM from dict.org"
echo
@@ -11,16 +11,16 @@ function show_help {
echo " -h, --help show this message"
}
-function define {
+define() {
curl --silent dict://dict.org/d:"$1"
}
-function remove_comm_msgs {
+remove_comm_msgs() {
grep -vE '[0-9][0-9] ' | \
sed 's/^\.//'
}
-function die {
+die() {
printf '%s\n' "$1" >&2
exit 1
}
@@ -53,20 +53,20 @@ while :; do
done
if [ "$gui" = 1 ]; then
- word=$(echo "" | dmenu_themed -i -p "Dictionary lookup:") || exit 1
+ word=$(xclip -o | dmenu_themed -i -p "Dictionary lookup:") || exit 1
notify-send "define: $word" "$(define "$word" | remove_comm_msgs)"
exit 0
else
- [[ $# -lt 1 ]] && (show_help && exit 1)
+ [ $# -lt 1 ] && (show_help && exit 1)
fi
definition=""
for word in "$@"; do
definition="${definition}\n$(define "$word" | remove_comm_msgs)"
done
-if [[ $(printf "%s" "$definition" | wc -l) -gt $(tput lines) ]] && \
- [[ "$pager" = 1 ]]; then
- echo -en "$definition" | tail -n +2 | less
+if [ "$(printf "%s" "$definition" | wc -l)" -gt "$(tput lines)" ] && \
+ [ "$pager" = 1 ]; then
+ printf "%s" "$definition" | tail -n +2 | less
else
- echo -en "$definition" | tail -n +2
+ printf "%s" "$definition" | tail -n +2
fi