Lookup dictionary definitions with the dict protocol

Heya,

I just wanted to share this small snippet for looking up definitions of words from dict.org. It uses the dict protocol and requires curl.

define-command -override lookup_word -docstring "Lookup word under selection" -params 0..1 %{
	evaluate-commands %sh{
		if [ -n "$1" ]; then
			WORD="$1"
		else
			WORD="$kak_selection"
		fi # Fetch the definition and remove noise
		definition=$(
			curl "dict://dict.org/d:$WORD" 2>/dev/null \
			| tr -d '\r' \
			| grep -v '^[0-9]' \
			| sed '/^\.$/d'
		)
		printf "info -title Definition %%{%s%%}" "$definition"
	}
}

# example binding
map -docstring "Lookup word under selection" global user d ":lookup_word<ret>"

5 Likes

Glad to see some plugins that address the needs of prose writers :slight_smile:

1 Like

This is slick!