Welcome to the next pikoTutorial !
Linux terminal is a basic tool for many software engineers and the place where we often spend a lot of our time during the work day. Even if you’re not doing anything in the terminal right now, it is for sure opened for the entire time on your second screen or at the bottom of your IDE.
This is the reason why it’s a good idea to incorporate as many of the every day actions as possible directly into the terminal. We’ve already covered how to embed hex/dec conversions, so now it’s time to see how search the internet faster, without manually going to the internet browser.
How to open any website from the terminal?
If you use Google Chrome, the syntax for opening any website is very simple:
google-chrome "www.somepage.com"How to search in Google from the terminal?
The easiest way to search Google from the terminal is to add a bash function to you .bashrc file:
google() {
local query="$*"
if [ -z "$query" ]; then
google-chrome "https://www.google.com"
else
query=$(echo "$query" | jq -sRr @uri)
google-chrome "https://www.google.com/search?q=$query"
fi
}It defines a function google which:
- if called without any additional arguments, it just opens “www.google.com”
- if called with any argument, it builds a Google query and opens web browser displaying Google search results for that query
For example, if I call:
google c++ futureI get my browser immediately opened with all the Google results for “c++ future” search term. Line query=$(echo "$query" | jq -sRr @uri) is crucial because it allows you to use non-alphanumerical characters (like “+”) in your queries:
jqis a lightweight JSON processor which we’re using here to URL-encode the input string-sflag treats the input as a single string instead of individual lines-Rflag tellsjqto treat the input as raw text instead JSON data-rflag makesjqoutput raw text instead of JSON-encoded@uriencodes the string as a URL, so special characters are replaced with percent ASCII-encoded equivalents
What else is worth having in the .bashrc file?
Search StackOverflow from the terminal
so() {
local query="$*"
if [ -z "$query" ]; then
google-chrome "https://stackoverflow.com"
else
query=$(echo "$query" | jq -sRr @uri)
google-chrome "https://stackoverflow.com/search?q=$query"
fi
}If you get some unfamiliar error prompt, it’s often useful to just call:
so c++ use of deleted functionSearch YouTube from the terminal
yt() {
local query="$*"
if [ -z "$query" ]; then
google-chrome "https://www.youtube.com"
else
query=$(echo "$query" | jq -sRr @uri)
google-chrome "https://www.youtube.com/results?search_query=$query"
fi
}YouTube is priceless when it comes to every GUI-based tool, so by having yt function at hand, you can always call things like:
yt vs code configure snippetsHard code aliases for frequently used pages
If you have any pages that you use on a daily bases, just hard code the in form of the aliases. For example, when I’m in the terminal, I often need to check some error code value of the UDS protocol (Unified Diagnostics Services). There’s a section on the UDS Wikipedia page for that, so I just have an alias uds in my .bashrc file for this purpose:
alias uds='google-chrome https://en.wikipedia.org/wiki/Unified_Diagnostic_Services#Negative_response_codes'Adding # after the Wikipedia page name in the URL allows you to link directly to a page section, instead of the beginning of the page.
Read also:
- GTest and short-circuit evaluation in C++
- AI is powerful. Snippets are instant.
- From AUTOSAR to S-Core: the first C++ pub/sub implementation
- How to write Arduino Uno code with Python?
- Combining Bazel with Docker
- Running commands with timeout on Linux
- Running Python unit tests with CMake
- Thirdparty dependencies with FetchContent
- Bug of the week #11
- Combining CMake with Docker
- How to search the internet from Linux terminal?
- Folding expressions in C++
- How to derive from an enum in Python?
- Bug of the week #10
- Trying ROS2: client/server within a single container
- Make C++ a better place #4: Go as an alternative
- How to convert hex to dec in Linux terminal?
- Setting up a Python project with CMake
- Separating builds for different configs with Bazel
- Trying ROS2: pub/sub within a single container
- Bug of the week #9
- UDP multicasting with Python
- Destruction order vs thread safety in C++
- Let’s review some code: C++ #2
- Make C++ a better place #3: D as an alternative
- Registering callback using std::function in C++
- Bug of the week #8
- TCP client/server with Python
- Simple menus in Bash scripts with select
- Calling member function on a nullptr in C++
- Bug of the week #7
- Python lru_cache explained
- How to dockerize a Python application?
- Make C++ a better place #2: CppFront as an alternative
- Parameters combinations in GoogleTest
- Data transfer with curl
- Python reduce explained
- Bug of the week #6
- Custom literals in C++
- Linux and hash command
- 5 Python good practices which make life easier
- Let’s review some code: Python #1
- Make C++ a better place #1: What does better mean
- Enums vs enum class in C++
- Bug of the week #5
- UDP client/server with Python
- Hard links in Linux
- Functions calling order in unit tests in C++
- Bug of the week #4
- Yield in Python – state machines, coroutines and more
- Copy files from another branch with Git
- Make C++ a better place #0: Introduction
- 5 misconceptions about std::move in C++
- How to use xargs on Linux?
- How to test method call order with unittest in Python?
- Bug of the week #3
- Build & run C++ unit tests with CMake
- Arrange text with sort on Linux
- Key derivation function with Python
- Let’s review some code #1: C++









