dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 2fc8c29ffeba6496b93f8e905531aa060b45bda1
parent 25469d2f0c9d0823bf22957e67644cf7d8a8b558
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed,  1 May 2019 15:42:28 +0200

Add gui option to define, improve output text formatting

Diffstat:
Mbin/define | 22+++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/bin/define b/bin/define @@ -6,8 +6,9 @@ function show_help { echo "shows definitions for each TERM from dict.org" echo echo "Options:" - echo " -h, --help show this message" + echo " -g, --gui use dmenu for input and notify-send for output" echo " -np, --no-pager do not use a pager for long output" + echo " -h, --help show this message" } function define { @@ -24,7 +25,7 @@ function die { exit 1 } -[[ $# -lt 1 ]] && (show_help && exit 1) +gui=0 pager=1 while :; do case "$1" in @@ -32,6 +33,9 @@ while :; do show_help exit 0 ;; + -g|--gui) + gui=1 + ;; -np|--no-pager) pager=0 ;; @@ -48,13 +52,21 @@ while :; do shift done +if [ "$gui" = 1 ]; then + word=$(echo "" | dmenu_themed -i -p "Dict lookup:") || exit 1 + notify-send "define" "$(define "$word" | remove_comm_msgs)" + exit 0 +else + [[ $# -lt 1 ]] && (show_help && exit 1) +fi + definition="" for word in "$@"; do definition="${definition}\n$(define "$word" | remove_comm_msgs)" done -if [[ $(printf "$definition" | wc -l) -gt $(tput lines) ]] && \ +if [[ $(printf "%s" "$definition" | wc -l) -gt $(tput lines) ]] && \ [[ "$pager" = 1 ]]; then - printf "$definition" | less + echo -en "$definition" | tail -n +2 | less else - printf "$definition" + echo -en "$definition" | tail -n +2 fi