1. Home
  2. Linux
  3. How to use google bard from the linux terminal

How to use Google Bard from the Linux terminal

Google Bard is a handy tool. But did you know that you can interact with it from the Linux terminal, and even pass system commands to it? Learn how you can use Google Bard from the Linux terminal.

How to install Bard Shell requirements on Linux

To use Google Bard in your Linux terminal, you must install a few things. First, you’ll need to install the Google Bard API. You need this API to interact with Google Bard. To install the Bard API, start by opening up a terminal window.

Once the terminal window is open and ready to use, it’s time to install the Google Bard API with the pip install command.

Ubuntu

sudo apt install python3-venv python3-pip  

Debian

sudo apt install python3-venv python3-pip  

Arch Linux

pacman -S python-virtualenv python-pip  

Fedora

sudo dnf install python3-virtualenv python3-pip  

OpenSUSE

sudo zypper install python3-virtualenv python3-pip  

After you’ve installed the Python virtual environment, you need to create your environment for Bard. You can do this with the python -m command below.

python -m venv bard-environment

If you are on Debian or Ubuntu, you’ll need to run this command instead:

python3 -m venv bard-environment

You can now activate your new environment with the following commands.

chmod +x $HOME/bard-environment/bin/activate

source $HOME/bard-environment/bin/activate

Once the Bard environment is active, you’ll see (bard-environment) in the terminal prompt. From here, use the pip install command to set up the Bard API.

pip install bardapi

You will also need to install Toml. Toml handles authentication with Bard, and it is required for the program to function. You can install Toml with the pip install command.

pip install toml

With Toml and the Bard API installed in your Bard environment, everything will be ready to install.

Bard Environment alias

If you would like to make it easier to activate your Bard environment, you can add an alias to ~/.bashrc. First, open up the file for editing in Nano.

nano -w ~/.bashrc

Once the file is open for editing, add the following line to the very bottom.

alias bard-environment='source $HOME/bard-environment/bin/activate'

Save the file with Ctrl + O, and exit with Ctrl + X. You’ll then need to load in the new configuration using the source command.

source ~/.bashrc

Once the file is sourced, you can run the command bard-environment at any time to activate the Bard environment.

How to install Bard-Shell on Linux

To install Bard Shell, start by using the git clone command to download the latest version of Bard-Shell from the developer’s GitHub. Ensure you have the git package installed on your system. If not, you can install it with the commands below.

Ubuntu and Debian

sudo apt install git  

Arch Linux

sudo pacman -S git  

Fedora

sudo dnf install git  

OpenSUSE

 sudo zypper install git

Once the Git package is installed on your system, you can download Bard-Shell.

git clone https://github.com/kshitijaucharmal/Bard-Shell.git

With it installed, open up a web browser, and go log into Bard Once you’ve logged in, press F12 on the keyboard to open up the web developer console (this button works on both Firefox and Chrome.)

After opening up the web developer console, do the following:

Firefox

In the Firefox web developer console, find the “Storage” tab, and click on the drop-down arrow next to “Cookies.” Look through the cookies for _Secure-1PSID. This cookie is your login token for Bard. Copy the value to your clipboard.

Chrome (and Chrome-based browsers)

In Chrome (or browsers based on Chrome), log into Bard and press the F12 key to open up the web developer console. Once in the console, look for “Application,” and select “Cookies.” Look through the cookies for _Secure-1PSID. This cookie will log you into Bard. Copy it to your clipboard.

Now that you have your cookie value, do the following commands in a terminal window.

mkdir -p ~/.config/bardshell

touch  ~/.config/bardshell/bard.toml

Open up the bard.toml file with the Nano text editor.

nano -w ~/.config/bardshell/bard.toml

Paste the following code into the bard.toml file. Be sure to replace “PASTE COOKIE VALUE HERE” with the value you got from _Secure-1PSID.

[default]
modes = "content,code,links"
instructions = "Instructions:\nTake my system Information into consideration if given before giving outputs. If the command output is not empty, use it as the input to perform operations. Do what the Prompt says with the input.\n\n"

[user]
token = "PASTE COOKIE VALUE HERE"

Save your edits in the bard.toml file by pressing Ctrl + O and exit with Ctrl + X. Bard-Shell should now be installed and configured correctly. However, note that this cookie changes often, so you will likely need to re-configure it when an error occurs.

How to use Bard-Shell on Linux

To use Bard-Shell, start by launching a terminal. Once it is open, activate your Bard Environment (if it is not active) with bard-environment. Then, run the Bard-Shell help page.

python ~/Bard-Shell/bard-shell.py -h

Those on Debian/Ubuntu will need to run this instead:

python3 ~/Bard-Shell/bard-shell.py -h

The -h page will show all available Bard-Shell operations. To run a simple prompt to bard do the following:

python ~/Bard-Shell/bard-shell.py -p "YOUR PROMPT HERE"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.