DEV Community

HaxNet
HaxNet

Posted on • Edited on

5 2

quick internet search in terminal

Do you ever need to do a quick search but don't want to open a browser just to find something and you already on a terminal?

The solution is quite easy actually. Just download lynx browser which is a CLI browser in your terminal.

in your shell (I use zsh) and I just put this code in there

urlencode(){
  declare str="$*"
  declare encoded=""
  declare i c x
  for ((i=0; i<${#str}; i++ )); do
    c=${str:$i:1}
    case "$c" in
      [-_.~a-zA-Z0-9] ) x="$c" ;;
      * ) printf -v x '%%%02x' "'$c";;
    esac
    encoded+="$x"
  done
  echo "$encoded"
}

duck(){
  declare url=$(urlencode "$*")
  lynx "https://duckduckgo.com/lite?q=$url"
}

alias "?"=duck
Enter fullscreen mode Exit fullscreen mode

now when I go in my terminal I just type

? keywords
Enter fullscreen mode Exit fullscreen mode

Enjoy!

Top comments (1)

Collapse
 
vonheikemen profile image
Heiker

might want to make the title a little more specific. Like "a quick internet search inside the terminal".

For the people at home who don't use bash or zsh, in this stackoverflow question you can find more alternatives to the urlencode function.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay