LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices

Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

A very tiny quick dictionary look up script

Posted 10-12-2011 at 10:05 PM by the dsc
Updated 11-16-2011 at 04:35 PM by the dsc

For a long time I had fantasdic set to respond to a desktop environment keybinding, it would then appear with the result for a query that was made through the clipboard. I don't recall how much of it was its own functionality and how much was some sort of wrap-around scriptery. I'm so used to use computer dictionaries in that way (instead of directly going to them and typing) that to me it's almost useless without this keybinding functionality. And indeed it has been quite some time since it does not work quite well for some reason.

It works only for the first time the fantasdic is called, then in the second one (when it's already on the system tray), its window wouldn't show up, and there would be some X-related error in xsession-errors. I don't remember if I've ever made a bug report of some sort, I remember having mentioned it somewhere though. As a matter of fact, I'm not even sure it's still the case.

Nevertheless, I've made this tiny script to make up a little bit for the virtual "uselessness" of fantasdic:

Code:
#! /bin/bash
query=$(xclip -o)
dict -h localhost "$query" | sed 's#^\(.*From.*\)#<b> \1 </b>#' >/dev/shm/dict.tmp
kdialog --title "$query" --textbox /dev/shm/dict.tmp 400 550
With an openbox keybinding, it will pop up a kdialog text box with even a little text formatting (just bold "header" lines for each dictionary). You need only to select the text, doesn't need to "copy" it, just do whatever is the keybinding you set to run the script. It hasn't all the functionality that fantasdic had (like double clicking any word on the text/definition box and then going to the definition of that word), but I think it will be a decent replacement.

Besides kdialog and xclip (which gives the clipboard as input), I also have dict and dictd (the former is a client and the latter a server, if I'm not mistaken; I don't remember how much they're independent from each other), and dictionaries installed locally (hence "localhost"), but it could work with remote dictionaries as well, as long as someone fixes the dict query accordingly.
Posted in Uncategorized
Views 16564 Comments 5
« Prev     Main     Next »
Total Comments 5

Comments

  1. Old Comment
    Kdict for kde3 still works these days though, and it's somewhat better than this script. It has links to other definitions within the text and such things. Combined with the qtcurve theme engine, it can even have the same look of all the other applications, even though it would normally be ignored by "more" native theme settings of KDE4, and completely ignored by gnome/gtk.
    Posted 11-13-2011 at 02:19 PM by the dsc the dsc is offline
  2. Old Comment
    You need to to add an exclamation mark after the number sign and a space (if you want to maintain compatibility).
    Posted 11-14-2011 at 07:58 PM by lupusarcanus lupusarcanus is offline
  3. Old Comment
    Quote:
    You need to to add an exclamation mark after the number sign and a space
    I've never had to use a space in the shebang line of any script I've written…I think that's just a matter of style. :-\

    …but yes, you do need it to be a she-bang line, not just a she- line.
    Posted 11-14-2011 at 08:15 PM by MrCode MrCode is offline
  4. Old Comment
    Thanks, I hadn't noticed. Is the space supposed to be before the slash or after bash? I had never noticed a space there in any script I've ever seen.
    Posted 11-16-2011 at 04:38 PM by the dsc the dsc is offline
  5. Old Comment
    Quote:
    Is the space supposed to be before the slash or after bash? I had never noticed a space there in any script I've ever seen.
    I think what lupusarcanus is describing is a line like this:

    Code:
    #! /bin/bash
    …but IMO this works just as well:

    Code:
    #!/bin/bash
    The point is, you need a bang (exclamation point) in there to make it a valid interpreter selection line, otherwise it's simply interpreted as a comment, and the rest of the script is executed under the default shell*.

    (* - …which may be bash on most Linuxes, but if you're using bash-specific features, and you plan to run the script on systems where bash is not the default shell [but is installed], you'll want to explicitly tell the existing shell to switch to a different interpreter. )
    Posted 11-17-2011 at 05:40 AM by MrCode MrCode is offline
    Updated 11-17-2011 at 05:45 AM by MrCode
 

  



All times are GMT -5. The time now is 09:11 PM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration