4

Is there a way to configure w3m so that with 'U', i.e. after entering text into the URL field, the browser will automatically prepend "google.com/search?q=" to it?

Or can some other command be used or defined to obtain the same effect? I tried calling a shell script via "#" but it just passes output into buffer.

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54

3 Answers3

3

I added this to my ~/.profile

goo() {
    IFS=+ w3m https://google.com/search?hl=en\&q="$*"\&btnI= https://google.com/search?hl=en\&q="$*"
}

This allows a quick look at "I'm Feeling Lucky" result on a command line like this: goo linux kernel. If first match is a miss, hitting B presents the normal list of results. The convenience comes at expense of latency though, as both URLs load before anything is displayed.

  • i didn't notice that the original question was about searching from within w3m – Pavel Tumanov Aug 17 '18 at 23:44
  • Great function. For zsh compatability I use ```goo() { query=$(echo "$*" | xargs | sed -E 's/\s+/\+/g') w3m "https://google.com/search?hl=en\&q=$query" }``` – dimid Apr 10 '23 at 17:22
1

You need only configure google.cgi plugin:

cp /path-to-w3m-sources/Bonus/google.cgi /usr/lib/w3m/cgi-bin chmod +x /usr/lib/w3m/cgi-bin/google.cgi

Create protocol g:

echo 'g: file:/usr/lib/w3m/cgi-bin/google.cgi?%s'' >> ~/.w3m/urimethodmap

Edit google.cgi, find this line:

$url .= "search?q=$_&hl=ja&lr=lang_ja&ie=EUC-JP";

Adjust for english:

$url .= "search?q=$_&hl=en&ie=UTF-8";

Now you can search in URL prompt of w3m like g:my+google+query

1

You can map a macro hotkey to do a 'smart search' for different search engines. Once you hit the hotkey it will open a new tab then take you directly to the text field to type in your keyword:

$EDITOR ~/.w3m/keymap

keymap  sd      COMMAND "TAB_GOTO https://duckduckgo.com/lite/; NEXT_LINK; GOTO_LINK; SUBMIT"
keymap  sg      COMMAND "TAB_GOTO https://google.com; GOTO_LINE 6; NEXT_LINK; GOTO_LINK; SUBMIT"
keymap  sy      COMMAND "TAB_GOTO https://yewtu.be; NEXT_LINK; GOTO_LINK"
keymap  so      COMMAND "TAB_GOTO https://search.yahoo.com; GOTO_LINE 19; NEXT_LINK; GOTO_LINK"

Usage example: hit sg type in hello world then hit enter

gotbletu
  • 146
  • 1
  • 5