Search And Browse Stack Overflow Website From Commandline
Stack Overflow is one of the well-known and prominent online community website for Programmers to learn and share their knowledge with millions of users around the world. Also, It is my preferred website when it comes to search, discover programming related stuffs, and questions. If you are like me, I have good news for you. Now, you can search and browse Stack Overflow website without leaving your Terminal. A guy named Gautam krishna has created a commandline utility called “SoCLI” to search and browse Stack Overflow site from your Terminal. It will be quite useful when you want to browse Stack Overflow website from a System that has no GUI mode. Using SoCLI, you can post to Stack overflow, upvote and comment an answer. SoCLI is a cross-platform utility, so It will work on GNU/Linux, Microsoft Windows, and Mac OS X.
Concerning about the features of CLI, we can list the following:
- Search and browse Stack Overflow interactively
- Search a specific most voted question with its answer manually
- Search using specific question with single or multiple tags
- Open a page in the default web browser
- Creating new questions via the web browser
- Coloured interface
- Question stats view
In this brief tutorial, I will walk you through how to browse Stack Overflow using SoCLI tool from Commandline, Follow me!
SoCLI – Search and browse Stack Overflow Website From Commandline
SoCLI is a Stack Overflow commandline client written in Python programming language. In order to install it, you need to install python and pip package manager. Pip is the package manager to install applications written using Python.
First, let us install pip.
On Arch Linux and its derivatives:
sudo pacman -S python-pip
On Debian, Ubuntu, Linux Mint:
sudo apt-get install python-pip
On RHEL, Fedora, CentOS:
sudo yum install python-pip
sudo dnf install python-pip
sudo zypper install python-pip
Once pip installed, run the following command to install SoCLI. The following command is same for all Linux distributions!
sudo pip install socli
The directory '/home/sk/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/home/sk/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Collecting socli Downloading socli-2.9.tar.gz Collecting BeautifulSoup4 (from socli) Downloading beautifulsoup4-4.5.3-py2-none-any.whl (85kB) 100% |████████████████████████████████| 92kB 283kB/s Collecting requests (from socli) Downloading requests-2.12.4-py2.py3-none-any.whl (576kB) 100% |████████████████████████████████| 583kB 260kB/s Installing collected packages: BeautifulSoup4, requests, socli Running setup.py install for socli ... done Successfully installed BeautifulSoup4-4.5.3 requests-2.12.4 socli-2.9
To update/upgrade existing socli version, run:
sudo pip install --upgrade socli
SoCLI usage is fairly simple and straight forward. The typical syntax of SoCLI is:
socli [ Arguments] < Search Query >
Let us see some examples.
To search a query “nginx reverse proxy”, the command would be:
socli nginx reverse proxy
This command search the given query “nginx reverse proxy” through Stack Overflow and display the first most voted question with its most voted answer. Cool, isn’t it?
I want to do interactive search, how can do it? That’s very simple. Use “-iq” parameter before your search term (Of course, without quotes).
socli -iq ajax in framework7
This command will search the questions for the query “ajax in framework7” and also allow you to choose any one of the question interactively.
Just enter the question number to select a question in the given result. I chose the 6th answer by entering 6 in “Type the option no to continue or any other key to exit” prompt. And it displayed the chosen question with its most voted answer instantly.
Likewise, You can type “n” for the next answer, “b” for previous answer or hit any other key to exit from SoCLI.
Specify a particular Question by number
SoCLI also allows us to display a specific question by its number. Say for example, I want to display the second question of the given query. So, I entered:
socli -r 2 -q cmake
This command will display the second most voted question that has the query “cmake” with its most voted answer.
Topic based search using tags
Stack Overflow allows us to search a particular topic using tags. So, we can do the same using SoCLI client.
Say for example, to search for a query “python” using tag “linux”, run the following command:
socli -t linux -q python
You can also include multiple tags using comma as shown below.
socli -t linux,android -q python
Submit a new question
Can’t find an answer to your question in Stack Overflow? No worries! Run the following command to create a new question.
This command will open a new question page of Stack Overflow in your web browser. Please note that you must have installed a web browser to use this feature.
To know more details about SoCLI, refer the help section by running the following ocmmand:
You know now how to search and browse through questions and answers in Stack Overflow community website via commandline. SoCLI just worked fine as it is advertised in its GitHub page. If you’re a programmer and looking for a client tool for Stack Overflow, you need to give SoCLI a try.
Have you tried this already? Great! Let us know about your experience with SoCLI in the comment section below.
That’s all for now. I will be back soon with another interesting article. If you find this guide useful, please share it on your social networks and support OSTechNix.