Skip to content

shadowy-pycoder/goso

Repository files navigation

goso - Stack Overflow CLI Tool written in Go

GitHub Actions Workflow Status License: MIT Go Reference GitHub go.mod Go version Go Report Card GitHub Release GitHub Downloads (all assets, all releases)

Features

  • Syntax highlighting
  • Fast search
  • Easy to use
  • Support for Linux, Windows, macOS

Demo

goso - Animated gif demo

Installation

You can download the binary for your platform from Releases page.

Alternatively, you can install it using go install command (requires Go 1.23 or later):

CGO_ENABLED=0 go install -ldflags "-s -w" -trimpath github.com/shadowy-pycoder/goso/cmd/goso@latest

This will install the goso binary to your $GOPATH/bin directory.

If none of the above works for you, you can use the Makefile to build the binary from source.

git clone https://github.com/shadowy-pycoder/goso.git
cd goso
make build

Search Engine Setup

Google Search JSON API

This approach employs Custom Search JSON API from Google to obtain most relevant results from Stack Overflow. So, to make it work, you need to get an API key from Google and also a Search Engine ID. That gives you 100 requests per day, which I believe is enough for most use cases.

Setup your Search Engine ID like this:

Screenshot from 2024-11-12 13-17-26

Add variables to your environment:

echo "export GOSO_API_KEY=<YOUR_API_KEY>" >> $HOME/.profile
echo "export GOSO_SE=<YOUR_SEARCH_ENGINE_ID>" >> $HOME/.profile
source $HOME/.profile

OpenSerp API

goso also supports OpenSERP (Search Engine Results Page) from Karust. This is a completely FREE alternative to the Google Search JSON API, though it works a little bit slower, but gives basically the same results.

So, to make it work, you need to run OperSERP server locally. You can do it like this:

With Docker:

docker run -p 127.0.0.1:7000:7000 -it karust/openserp serve -a 0.0.0.0 -p 7000

Or as a CLI command:

openserp serve 

You can learn more on how to install OpenSERP here.

Once you have it running, add variables to your environment:

echo "export GOSO_OS_HOST=127.0.0.1" >> $HOME/.profile
echo "export GOSO_OS_PORT=7000" >> $HOME/.profile
source $HOME/.profile

These variables will have priority over the GOSO_API_KEY and GOSO_SE.

Usage

goso -h
                                                                  
 .d88b.   .d88b.  .d8888b   .d88b.  
d88P"88b d88""88b 88K      d88""88b 
888  888 888  888 "Y8888b. 888  888 
Y88b 888 Y88..88P      X88 Y88..88P 
 "Y88888  "Y88P"   88888P'  "Y88P"  
     888                            
Y8b d88P  Stack Overlow CLI Tool by shadowy-pycoder                         
 "Y88P"   GitHub: https://github.com/shadowy-pycoder/goso                        
                                                                                                                                                                                              
Usage: goso [OPTIONS] QUERY
Options:
  -h    Show this help message and exit.
  -a int
        The number of answers for each result [min=1, max=10] (default 3)
  -l string
        The name of Chroma lexer. See https://github.com/alecthomas/chroma/tree/master/lexers/embedded (default "bash")
  -q int
        The number of questions [min=1, max=10] (default 10)
  -s string
        The name of Chroma style. See https://xyproto.github.io/splash/docs/ (default "onedark")
  -v    print version

It is possible to adjust default values for the number of questions and answers, lexer and style.

echo "export GOSO_LEXER=python" >> $HOME/.profile
echo "export GOSO_STYLE=onedark" >> $HOME/.profile
echo "export GOSO_ANSWERS=5" >> $HOME/.profile
echo "export GOSO_QUESTIONS=5" >> $HOME/.profile
source $HOME/.profile

Example

goso  -l go -s onedark -q 1 -a 1 Sort maps in Golang

Output:

Screenshot from 2024-11-14 10-16-52

You can also use less command for instance to page through the results:

#!/bin/bash
goso "$@" | less -F -R -X

Contributing

Are you a developer?

  • Fork the repository
  • Create your feature branch: git switch -c my-new-feature
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request