Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Make Googler your web browser

prathampowar2001 edited this page Jul 5, 2020 · 3 revisions

Make Gooogler your web browser

If you want to ditch your browser for browsing websites and do almost everything from the command line. Then this is for you. By almost I mean everything except online shopping , online banking etc.

Make a file called reader(Or name it something else) and make sure it is in your path. It would be a bash script and so this may not work on windows. The file should be such

First add a shebang at the top of the file

#!/bin/bash

Then get the url from the argument list , in bash you do this by

url=$1

And make sure there is no space before and after the equal to sign or else bash throws an error

Then it is just a few if statements away. For each if block you define a command to follow.In this setup I will show you how to open , a youtube video, wih mpv ,with the url as an a rgument,for any stackoverflow post I open socli( a command line stack overflow viewer that's open source) and anything else with w3m and less.You can make unlimited if statements like it. To be on the safe side and prevent the corresponding cli app mess with googler I spawn my terminal(alacritty) with the corresponding app, in the background which means that I can interact with googler almost immediatly.While the corresponding app opens in the background in another terminal.

By the way if statements are in this form

if [[ $url == *"youtube.com/watch"* ]];then
mpv $url 1>/dev/null 2>/dev/null &
elif next_condition;then
else
next app
fi

Here 1> and 2> means stdout and stdin which means mpv cannot spit output into googler and mess your terminal.And the ampersand actually runs that command in the background in bash.

Combine them with the abundance of cli apps for the web from reddit clients to facebook and instagram in the terminal.You can make a list of if statements that opens the corresponding url in the corresponding app.But sometimes We need to edit the url to extract the important bits. Like in the case of stack overflow and its corresponding app socli. To overcome this we have to edit the url using sed and awk and other bash tools

For example StackOverflow

    query=` echo $url | awk -F/ '{ print $6 }' | tr "-" " "`
    alacritty -e socli $query &

But if a random url is detected then you can use w3m with less to read it in the terminal

alacritty -e sh -c "w3m -dump $url | less "

This converts googler into a versatile browser.For list of cli apps just google awesome-cli-apps .You can find many others like devtocli ,medium-cli, etc I cannot include each of them in this article.But keep expanding and keep making googler into smooth web experience.

Taking all above examples The final script is

#!/bin/sh
#Getting the arguments
url=$1
#checking for url's

if [[ $url == *"youtube.com/watch"* ]]; then
      mpv $url 1>/dev/null 2>/dev/null &
elif [[ $url == *"stackoverflow.com/questions/"* ]]; then
      query=`echo $url | awk -F/ '{ print $6 }' | tr "-" " "`
      alacritty -e socli $query &
else
      alacritty -e sh -c "w3m -dump $url | less" &
fi