DEV Community

HaxNet
HaxNet

Posted on • Updated on

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.