CloudShell is one of my favourite tools on Google Cloud, its smouldering jambalaya of goodness. Essentially its a power packed terminal giving you immediate access to your favourite tools.
As great as it is, there are some elements that could be improved and this blog post provides some quick tips for making your environment a bit more user friendly.
- Progressive Web Application
- Tmux
- Vim
Progressive Web Application
Did you know Cloud Shell is a Progressive Web Application (PWA) and as such can be installed on your machine. Having your awesome CloudShell available at the click of a button is super helpful. The main reason I use the PWA version is due to the key binding working correctly.
If you use Tmux or Vim you might be especially familiar with the popup message shown below:
When using the Browser version of CloudShell, keys are intercepted leading to all manner of unintended consequences. Honestly it can be super annoying, but the good folks at Google Cloud have resolved that particular heartache through the CloudShell Progressive Web App.
Install the PWA to remove that annoying message and commence your keyboard driven adventure. Feel your productivity surge as you unleash the shackles of life and discover an unbounded universe.
To learn more about how to install the CloudShell PWA visit this support article: https://support.google.com/chrome/answer/9658361
Once installed you have access to the same CloudShell you love, but it now works and feels like an actual terminal. Even better, the session context can be easily switched. Commence a CloudShell browser session on your laptop, then switch machines to your desktop. Now on the desktop open your CloudShell and reconnect to seamlessly reattach to the same session. Pretty awesome right?
Setting the Project
One thing that will be essential is the ability to set the correct Google Cloud project. Memorise the commands below replacing [YOUR_PROJECT] with one you have access to:
- Open a CloudShell terminal
- Use gcloud to config the default project and authenticate
gcloud config set project [YOUR_PROJECT]
3. The shell will then authenticate you to Google Cloud and connect you to your project
If you use CloudShell, then you will likely use this and region/zone settings a lot.
CloudShell includes lots of fun things, so I highly recommend investigating what’s available. I will probably return to this topic at a later date.
TMUX
Did you know TMUX is available in CloudShell? It is blended in quite nicely with the environment to hide itself, but it is there. Default keybindings are available, but you may want to make some minor changes to the base configuration.
Tmux uses a leader key which is set to CTRL-b (i.e. press the control key and b key at the same time). A leader key is essentially the key pressed to tell the system you wish to perform an action. So for example, using the leader key and then pressing p, would move to the previous window. If you press the leader key and then press n, it would move to the next window. I assume you don’t have any additional windows at this point, so instead you should see a message flash up on screen.
Follow the Leader
From the above you may feel like CTRL-b is quite an awkward key combination. I personally use CTRL-a. To make this change in your environment, create a Tmux configuration file and update your settings.
- Cut and Paste the Tmux configuration file in CloudShell
cat <<EOF >~/.tmux.conf
# My CloudShell TMUX config
# Amend ctrl + b to ctrl + a
unbind C-b
set -g prefix C-a
EOF
2. You will now have a .tmux.conf file located at the root of your home folder
3. Use the command below to update your tmux configuration file
tmux source ~/.tmux.conf
Your Tmux configuration now uses the leader key of CTRL-a. If you fancy updating Tmux to include other stuff, you also now have a configuration file that you can add to. Don’t forget to source the file once you have made changes.
GitHub Source: tmux.sh
Unfollow the Leader
If you want to revert the changes back to using CTRL-b, update your configuration as shown below:
- Replace your Tmux configuration file in CloudShell with this
cat <<EOF >~/.tmux.conf
# My CloudShell TMUX config
# Amend ctrl + b to ctrl + a
# unbind C-b
# set -g prefix C-a
EOF
2. In the above add # before the unbind and set commands to make these lines comments.
3. Don’t forget to source the file once you have made changes!
tmux source ~/.tmux.conf
Your tmux config is now back to the original setting.
VIM
Personally I really like Vim and will use it wherever I can, including CloudShell. Similar to Tmux, you can add some basic configuration to make Vim more user friendly.
Again, there is a Vim configuration file that can be created to manage your application settings. I won’t be going into the use of Plugins at this stage. It is most likely you don’t need them? Within the configuration, there are three areas that can enhance your experience:
- General Configuration
- Text Editor Configuration
- Code Editor Configuration
General Configuration
In the category of general configuration, I would include things like setting the colour scheme, undo level and all the other niceties you might expect to be available out of the box. Adding these settings most likely make your use of Vim more pleasant.
Text Editor
Text editor settings are the ones that may cause you some discomfort if they are not available, the key one for me is spelling.
Code Editor
If you are a developer, then you are probably going to need a bit more in terms of text placement and syntax highlighting.
Add Vim Settings
So without further ado, here is a basic Vim configuration settings that can be used with CloudShell. For additional options do visit the Vim wiki site
- Create a folder to hold a undo file
mkdir -p ~/.vim/undodir
2. Create your Vim configuration file in CloudShell by pasting the following:
cat <<EOF >~/.vimrc
" CloudShell Vim Settings
" GENERAL SETTINGS:
set noerrorbells " No bells
set noswapfile " Turn off swap file
set nobackup " Turn off back file
set undodir=~/.vim/undodir " CREATE THIS FOLDER!!!
set undofile " Set undo in the folder
set encoding=utf-8 " Support unicode encoding
colorscheme industry " Color scheme
highlight ColorColumn ctermbg=0 guibg=lightgrey " Add Highlight config
" EDITOR SETTINGS:
set nowrap " Dont wrap lines
set spell " Enable spelling
set spelllang=en_gb " Set the Spelling lang
set colorcolumn=80 " Add a column bar
" CODE SETTINGS:
syntax on " Syntax highlight
set tabstop=2 softtabstop=2 " Default tab use space
set shiftwidth=2 " Default shift
set expandtab " Default tab expansion
set smartindent " Alternative to autoindent
set nu rnu " Set number + relative
set smartcase " Case insensitive
set incsearch " Incremental search
set splitright " vsplit right
set splitbelow " split below
EOF
The Vim configuration is now active. Now when you enter Vim, it should look more modern and have some helpful settings applied.
GitHub Source: vim.sh
Remove Vim Settings
If you decide the settings are not for you, you can delete the ~/.vimrc file or comment out the settings that don’t match your expectations.
- To comment out a configuration setting add a comment (i.e. “ ) in front of the command to be deactivated e.g.
" CloudShell Vim Settings
Summary
So that is a quick tour of the basics of configuring CloudShell to look a bit more appealing. You can of course do a lot more, but I am excited to see what configurations you come up with.
Let me know in the comments.