Natenoms Wiki

Weil Teilen Spaß macht :)

User Tools

Site Tools


Sidebar

Translations of this page:

Navigation



Lizenz dieses Wikis
Über dieses Wiki
Feed des Wikis
Impressum


Was gerade in meinem Blog geschieht:

en:linux:shell-funktionen:woerterbuch-abfrage

Online dictionary on the shell

With this function one can query a dictionary (dict.cc in this case) from within a shell.

Parameters

With the parameter '-l' '(lower case “L”)' one can change source and destination language; for German to Esperanto use -l deeo:

dic -l deeo baum
Baum {m}
    arbo

Withouth -l the translation from German to English is used.

Add to .bashrc

Add the following lines to your ~/.bashrc file

function dic() 
function dic() 
{ 
    DIC_HIST="$HOME/.local/share/dic_history"

    if [ "$1" = "-l" ]; then
        local _lang=$2;
        shift 2;
    else
        local _lang=deen;
    fi; 

    if [ "$1" = "-h" ]; then
        cat "${DIC_HIST}"
        return 
    fi  

    if [ "${_lang}" == "deen" ];
    then
        _lang=""
    else        
        _lang="${_lang}."
    fi      

    w3m -dump "http://${_lang}pocket.dict.cc?s=\"$*\"" | sed -r -e '/^([ ]{5,}.*)$/d' -e '1,2d' -e '/^$/d' -e '/^\[/d'
    echo "$@" >> "${DIC_HIST}"
}

Examples

dic blumentopf
Blumentopf {m} 
  flowerpot
  plant pot
dic in die Irre führen
in die Irre führen
  to mislead

Used dictionary

Integrate in OpenBox

Create a script

Create an executable script named dic.sh with the following content:

#!/bin/bash
>>>ADD HERE THE SHELL FUNCTION (see above)<<<

dic $(xsel) | less

The package xsel is needed.

Create shortcuts

Now create a new shortcut in the file ~/.config/openbox/rc.xml (or ~/.config/openbox/lxde-rc.xml for use in LXDE):

    <keybind key="W-t">
      <action name="Execute">
        <command>xterm -geometry 60x40 -e /path/to/dic.sh</command>
      </action>
    </keybind>

Now reload your configuration and have fun with it :)

Result

Select a word somewhere, press Win + t and see:<br />

en/linux/shell-funktionen/woerterbuch-abfrage.txt · Last modified: 2017/02/20 12:00 by Natenom