Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get shell command completion (autocomplete) for gcloud?

I tried both 1. the official Google installation for Ubuntu, and 2. the one-liner sudo snap install google-cloud-sdk --classic, and neither didn't give me command autocompletion with tab. Has anyone found a version of installation that gives you autocomplete? I had it on my last laptop, so I know it's possible

ie. usage: gcloud compute instances li (here you hit tab) and it autocompletes to gcloud compute instances list

Thanks!

like image 439
Nathan Avatar asked Sep 07 '26 18:09

Nathan


2 Answers

The documentation says to source it in your profile. First, you will need to locate your gcloud installation. For me, it was in /snap. Then, locate the completions file (should be directly under the `` dir). For me, it was: /snap/google-cloud-cli/current/completion.bash.inc Last, update your profile. I am on bash so I did

cd
nano .profile

scroll to the end and add: source /snap/google-cloud-cli/current/completion.bash.inc

like image 66
Eytan Avatar answered Sep 10 '26 08:09

Eytan


I successfully installed gcloud's Command Line Interface with autocomplete here on February 24, 2021 at 7:00 P.M. EST (Eastern Standard Time). My operating system is Ubuntu 20.04

Shell commands copied from the aforementioned source:

sudo apt-get update
# You should probably do other commands after this like
#   sudo apt-get upgrade, sudo apt-get dist-upgrade, 
#   but I didn't need them

# can cd wherever here:
cd
wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-307.0.0-linux-x86_64.tar.gz
tar –xvzf google-cloud-sdk-307.0.0-linux-x86_64.tar.gz
cd google-cloud-sdk
./install.sh

# Answer a few "y/N" questions, mostly to your preference.

#   NOTE: Be sure to answer "Y" to the question "modify profile to update your $PATH and enable shell command completion?" !!  (This was the crux of the OP's question)

This is an image description!  (Obviously this image shows a bash session with the question about autocompletion)

# Clean up:
cd ..
rm -f google-cloud-sdk-307.0.0-linux-x86_64.tar.gz
like image 27
Nathan Avatar answered Sep 10 '26 09:09

Nathan