You are not logged in.

#1 2016-05-28 06:46:08

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

[W3M] tips & trics

As far as I know, there is no active thread dealing with w3m or any other text based browser. So I intend to create a common thread to discuss/share tips & trics among users of w3m.
    To set the ball rolling, let me write down few trics I am using.
    1) to play videos (youtube) using MPV, I have set mpv as my 3rd external browser in options (after qutebrowser and chromium).
So, whenever I want to play a video, I use "3M" to open link with my 3rd external browser. (M is command bound to external browser).
    2) I have created few short scripts,
w3d -->

#!/bin/bash


X="$1+$2+$3+$4"
w3m https://duckduckgo.com/?q="$X"

so I can search using "w3d <search term/s>

w3w --> similarly to search wikipedia
w3b --> aliased to "w3m -B" to display bookmarks

Offline

#2 2016-05-28 07:22:32

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [W3M] tips & trics

For your search, just use w3m as your browser in surfraw... smile


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2016-05-28 09:31:33

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [W3M] tips & trics

jasonwryan wrote:

For your search, just use w3m as your browser in surfraw... smile

Nice tip! I didn't knew that such thing exists! After adding w3m in surfraw config & adding /usr/lib/surfraw in default path, it is just matter of typing "aur telegram" or "archwiki mutt".

Offline

#4 2016-05-28 14:16:34

nbd
Member
Registered: 2014-08-04
Posts: 389

Re: [W3M] tips & trics

I recently at last confured mutt to read html email with the help of w3m:

https://fiasko-nw.net/~thomas/projects/ … ew.html.en


bing different

Offline

#5 2016-05-28 15:14:07

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [W3M] tips & trics

nbd wrote:

I recently at last confured mutt to read html email with the help of w3m:

https://fiasko-nw.net/~thomas/projects/ … ew.html.en

What is htmail-view? couldn't find it.

Offline

#6 2016-05-28 15:17:10

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,452
Website

Re: [W3M] tips & trics

Also why 4 parameters in the search?  And why an intermediate variable.  What you have would be equivalent to

w3m https://duckduckgo.com/?q="$1+$2+$3+$4"

But why require 4 and exactly 4 search terms?  Just use whatever is provided:

x=$@
w3m "https://duckduckgo.com/?q=${x// /+}"

I think there is a way to directly replace on the $@ array, but it's elluding me at the moment.

The following could work, it saves a line, but opens a subshell and calls another binary:

w3m https://duckduckgo.com/?q=$(printf "%s+" $@ | head -c -1)

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#7 2016-05-28 15:35:14

nbd
Member
Registered: 2014-08-04
Posts: 389

Re: [W3M] tips & trics

Docbroke wrote:
nbd wrote:

I recently at last confured mutt to read html email with the help of w3m:

https://fiasko-nw.net/~thomas/projects/ … ew.html.en

What is htmail-view? couldn't find it.

I cited the link that I found and used for configuring mutt to use w3m. Didn't hear about htmail-view either.


bing different

Offline

#8 2016-05-28 15:40:35

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [W3M] tips & trics

@Trilby, Cause I am linux beginner with limited knowledge, but I keep learning. Thanks for better solution.
4 search term, cause I think I won't need more than 4

Offline

#9 2016-06-03 13:43:54

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [W3M] tips & trics

I just found dmenu based search script "boosta" on github and did some modification for use with w3m, so here it is

script for searching with duckduckgo

#!/bin/bash

 LAUNCHER='rofi -dmenu -p Search_Duckduckgo:'
 BROWSER='sakura -e w3d'

 url=`cat /dev/null | $LAUNCHER | awk -F '|' '{printf("%s ", $NF)}' | tr -d '\r\n'`

 if [ ${#url} -gt 0 ]
 then
 $BROWSER $url
 fi

requires another script w3d

cat bin/w3d
#!/bin/bash

x=$@
w3m "https://duckduckgo.com/?q=${x// /+}"

Script can be modified for use with any other broswer. sakura can be replaced with any other terminal of choice, and "rofi -dmenu" with "dmenu"

Another script for using bookmarks with dmenu/rofi

#!/bin/bash

 LAUNCHER='rofi -dmenu -location 1 -lines 10 -width 100 -p Bookmarks:'
 BROWSER='sakura -e w3m'
 BOOKMARKS="$HOME/.w3m/bookmarks"

 url=`cat $BOOKMARKS | $LAUNCHER | awk -F '|' '{printf("%s ", $NF)}' | tr -d '\r\n'`

 if [ ${#url} -gt 0 ]
 then
 $BROWSER $url
 fi

this script requires bookmarks file(text), with one url per line.

Offline

#10 2016-06-04 01:55:02

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [W3M] tips & trics

did some more editing and now this is "ooh nice", with below given script I can use/search native bookmarks and history files of w3m through dmenu/rofi, just like with uzbl.

#!/bin/bash

 grep -o 'http[^"]*' .w3m/bookmark.html > /tmp/bookmarks
 cat .w3m/history >> /tmp/bookmarks
 

 LAUNCHER='rofi -dmenu -location 1 -lines 10 -width 100 -p Bookmarks:'
 BROWSER='sakura -e w3m'
 BOOKMARKS="/tmp/bookmarks"
 
 url=`cat $BOOKMARKS | $LAUNCHER | awk -F '|' '{printf("%s ", $NF)}' | tr -d '\r\n'`

 if [ ${#url} -gt 0 ]
 then
 $BROWSER $url
 fi

Last edited by Docbroke (2016-06-04 01:56:03)

Offline

#11 2016-06-09 03:02:16

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [W3M] tips & trics

here is updated script, it opens bookmars & history, opens urls, & if search term is not present in bookmarks/history or it is not a url it will be searched using duckduckgo

#!/bin/bash

    grep -o 'http[^"]*' .w3m/bookmark.html > /tmp/bookmarks
    grep -o 'http[^"]*' .w3m/history >> /tmp/bookmarks

    cat /tmp/bookmarks | rofi -dmenu -location 6 -lines 10 -width 100 -p W3M: > /tmp/x

    check=$(cat /tmp/x | wc -l)
    (( check == 0)) && exit

    grep -o http /tmp/x && sakura -e w3m $(cat /tmp/x) && exit
    grep -o "www\." /tmp/x && sakura -e w3m $(cat /tmp/x) && exit
    grep -o "\.com" /tmp/x && sakura -e w3m $(cat /tmp/x) && exit
    grep -o "\.in" /tmp/x && sakura -e w3m $(cat /tmp/x) && exit
    grep -o "\.org" /tmp/x && sakura -e w3m $(cat /tmp/x) && exit

    sakura -e w3d $(cat /tmp/x)

   
    only thing that I am not able to solve yet is if search term is present in bookmarks there is no way to search it using duckduckgo.
    so if I want to search "duck" I cannot as duckduckgo is there in bookmarks

Offline

#12 2016-06-09 03:05:51

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [W3M] tips & trics

here is updated script, it opens bookmars & history, opens urls, & if search term is not present in bookmarks/history or it is not a url it will be searched using duckduckgo
script w3d is posted above

#!/bin/bash

    grep -o 'http[^"]*' .w3m/bookmark.html > /tmp/bookmarks
    grep -o 'http[^"]*' .w3m/history >> /tmp/bookmarks

    cat /tmp/bookmarks | rofi -dmenu -location 6 -lines 10 -width 100 -p W3M: > /tmp/x

    check=$(wc -l < /tmp/x)
    (( check == 0)) && exit
    
    grep -o http /tmp/x && sakura -e w3m $(< /tmp/x) && exit
    grep -o "www\." /tmp/x && sakura -e w3m $(< /tmp/x) && exit
    grep -o "\.com" /tmp/x && sakura -e w3m $(< /tmp/x) && exit
    grep -o "\.in" /tmp/x && sakura -e w3m $(< /tmp/x) && exit
    grep -o "\.org" /tmp/x && sakura -e w3m $(< /tmp/x) && exit
    
    sakura -e w3d $(< /tmp/x)

   
    only thing that I am not able to solve yet is if search term is present in bookmarks there is no way to search it using duckduckgo.
    so if I want to search "duck" I cannot as duckduckgo is there in bookmarks
   
    EDIT: just spared all the cats, as suggested by jwr, now feline-lovers can rest in piece!

Last edited by Docbroke (2016-06-09 04:03:09)

Offline

#13 2016-06-09 03:14:24

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [W3M] tips & trics

That cat only has one more life!

$( </tmp/x)

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#14 2016-06-09 04:04:45

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [W3M] tips & trics

yeah, edited && saved the feline!

Offline

#15 2016-06-11 05:05:07

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [W3M] tips & trics

further update, now using surfraw for searching various sites, (not added all surfraw scripts as I don't need them all)
example to search life of pie on imdb use "imdb life of pie" as your search term in dmenu

#!/bin/bash

    ## requires surfraw, w3m, sakura, dmenu/rofi aliased to dmenu
    ## add below to your .bashrc, (required to search with surfraw)
    ## PATH=/usr/lib/surfraw:${PATH}

    grep -o 'http[^"]*' .w3m/bookmark.html > /tmp/bookmarks
    grep -o 'http[^"]*' .w3m/history >> /tmp/bookmarks

    cat /tmp/bookmarks | dmenu -location 6 -lines 10 -width 100 -p 'W3M:' > /tmp/x

    check=$(wc -l < /tmp/x)
    (( check == 0)) && exit

    awk '{ print $1 }' /tmp/x > /tmp/y
    awk '{ print $2, $3, $4, $5, $6, $7, $8 }' /tmp/x > /tmp/z

    grep -o http /tmp/x && sakura -e w3m $(< /tmp/x) && exit
    grep -o "www\." /tmp/x && sakura -e w3m $(< /tmp/x) && exit
    grep -o "\.com" /tmp/x && sakura -e w3m $(< /tmp/x) && exit
    grep -o "\.in" /tmp/x && sakura -e w3m $(< /tmp/x) && exit
    grep -o "\.org" /tmp/x && sakura -e w3m $(< /tmp/x) && exit
    grep -o "\.edu" /tmp/x && sakura -e w3m $(< /tmp/x) && exit
....
    grep -o wiki /tmp/y && sakura -e wikipedia $(< /tmp/z) && exit
    grep -o imdb /tmp/y && sakura -e imdb $(< /tmp/z) && exit
    grep -o aur /tmp/y && sakura -e aur $(< /tmp/z) && exit
    grep -o aw /tmp/y && sakura -e archwiki $(< /tmp/z) && exit
    grep -o pkg /tmp/y && sakura -e archpkg $(< /tmp/z) && exit
    grep -o google /tmp/y && sakura -e google $(< /tmp/z) && exit
    grep -o dict /tmp/y && sakura -e webster $(< /tmp/z) && exit
    grep -o dictu /tmp/y && sakura -e urban $(< /tmp/z) && exit
    grep -o torrent /tmp/y && sakura -e piratebay $(< /tmp/z) && exit
    grep -o pubmed /tmp/y && sakura -e pubmed $(< /tmp/z) && exit

    sakura -e S $(< /tmp/x)

    Below is a version for GUI browsers, just name your brower in browser=" " line, current default is chromium


   

#!/bin/bash

    ## requires surfraw, add below to your .bashrc
    ## PATH=/usr/lib/surfraw:${PATH}

    BROWSER=chromium

    grep -o 'http[^"]*' .w3m/bookmark.html > /tmp/bookmarks
    grep -o 'http[^"]*' .w3m/history >> /tmp/bookmarks
    cat /tmp/bookmarks | rofi -dmenu -location 6 -lines 10 -width 100 -p $BROWSER: > /tmp/x

    check=$(wc -l < /tmp/x)
    (( check == 0)) && exit

    awk '{ print $1 }' /tmp/x > /tmp/y
    awk '{ print $2, $3, $4, $5, $6, $7, $8 }' /tmp/x > /tmp/z

    grep -o http /tmp/x && $BROWSER  $(cat /tmp/x) && exit
    grep -o "www\." /tmp/x && $BROWSER $(cat /tmp/x) && exit
    grep -o "\.com" /tmp/x && $BROWSER $(cat /tmp/x) && exit
    grep -o "\.in" /tmp/x && $BROWSER $(cat /tmp/x) && exit
    grep -o "\.org" /tmp/x && $BROWSER $(cat /tmp/x) && exit

    grep -o wiki /tmp/y && wikipedia -browser=$BROWSER  $(< /tmp/z) && exit
    grep -o imdb /tmp/y && imdb -browser=$BROWSER $(< /tmp/z) && exit
    grep -o aur /tmp/y && aur -browser=$BROWSER $(< /tmp/z) && exit
    grep -o aw /tmp/y && archwiki -browser=$BROWSER $(< /tmp/z) && exit
    grep -o pkg /tmp/y && archpkg -browser=$BROWSER $(< /tmp/z) && exit
    grep -o google /tmp/y && google -browser=$BROWSER $(< /tmp/z) && exit
    grep -o dict /tmp/y && webster -browser=$BROWSER $(< /tmp/z) && exit
    grep -o dictu /tmp/y && urban -browser=$BROWSER $(< /tmp/z) && exit
    grep -o torrent /tmp/y && piratebay -browser=$BROWSER $(< /tmp/z) && exit
    grep -o pubmed /tmp/y && pubmed -browser=$BROWSER $(< /tmp/z) && exit

    S -browser=$BROWSER $(cat /tmp/x)

Last edited by Docbroke (2016-06-11 05:39:17)

Offline

#16 2016-11-19 04:37:55

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [W3M] tips & trics

another trick to yank page url from w3m

within w3m open options page with "O"
go to external browser, and set "echo %s | xclip -i" as a external browser, if it is first external browser the script will be called when you press "M" within w3m page and will yank the url to clipboard (requires xclip obviously), if it is for example 2nd external browser you have to use "2M' as keyboard shortcut. To yank url under the cursor use "alt-M" or "2-alt-M" depending on number of the external browser you are using.

In similar way one can open magnet links with torrent client or videos with mpv/youtube-dl from withing w3m.

Offline

Board footer

Powered by FluxBB