4

I would like to create an alias with the function to perform a DuckDuckGo search with W3M via the Command Line Interface (CLI).

I have already created the alias and the DuckDuckGo search engine is called. However, I would also like to enter a search keyword after the alias in the CLI and I do not know how to do that. Example:

alias duckit="w3m https://lite.duckduckgo.com/lite/"

When I enter the command duckit in the CLI, this alias calls the DuckDuckGo search engine and opens the web page. But I want the alias to also enter the search keyword in DuckDuckGo and show me the results.

So I tried adding ?q= at the end of the alias above:

alias duckit="w3m https://lite.duckduckgo.com/lite/?q="

However, running it as follows does not work:

duckit test

What do I need to do?

muru
  • 193,181
  • 53
  • 473
  • 722
Teso
  • 184
  • 1
  • 1
  • 12

2 Answers2

7

You cannot use an alias if you need to pass parameters to it, you need to use a function instead. Add this to your ~/.bashrc file:

duckit(){
    w3m https://lite.duckduckgo.com/lite/?q="$@"
}

Now open a new terminal and try duckit test.

terdon
  • 98,183
  • 15
  • 197
  • 293
  • Thank you! - Search terms with blank space must be entered in quotes. Example: **duckit "install w3m ubuntu"** – Teso May 13 '21 at 16:50
  • 2
    @Teso yes. Alternatively, you could use this instead: `duckit(){ w3m https://lite.duckduckgo.com/lite/?q="$*"; }`. But in any case, it is almost always better to pass your arguments quoted. – terdon May 13 '21 at 17:34
  • Ohh yaaa! I like this better… – Teso May 13 '21 at 21:45
0

Installation guide

  1. Install the W3M Web-Browser:

    sudo apt-get install w3m
    
  2. Or with image support (shows images on web pages):

    sudo apt-get install w3m w3m-img
    
  3. Copy the following command into the CLI and press Enter:

    echo 'duckit(){ w3m https://lite.duckduckgo.com/lite/?q="$*"; }' >> ~/.bashrc
    

4.Open a new CLI and run a search

duckitl test my w3m on ddg

W3M




DuckIt - Update Version 0.4

DuckDuckGo offers a pure HTML version of its search engine.
Since the W3M does not support JavaScript anyway, it is better to use the DDG-HTML page. This has one advantage, the HTML page contains no scripts and therefore less code. Less code means smaller HTML-file and therefore less data transfer, which makes the page load faster.

echo 'duckit(){ w3m https://lite.duckduckgo.com/html/?q="$*"; }' >> ~/.bashrc

If you already have DuckIt-W3m installed, just change the string in the ~/.bashrc file with your favorite text editor (e.g. nano ~/.bashrc) from lite to html.

https://lite.duckduckgo.com/html/




DuckIt - Update Version 0.5

Some people like the Lynx web browser better, so I have two new aliases for you.

The alias has changed.
The DDG-Lynx alias is: duckitl

sudo apt-get install lynx
echo 'duckitx(){ lynx https://lite.duckduckgo.com/html/?q="$*"; }' >> ~/.bashrc

Open a new CLI and run a search:

duckitx test my lynx on ddg

Probably the fastest search on Planet.

Teso
  • 184
  • 1
  • 1
  • 12