Enhancing Cloudshell on Google Cloud

Share on:

Cloud Shell is super useful and features a lot of tools. However out of the box the general setup doesnt match my local machine. If you want to use tmux or vim in your environment, this blog post is for you.
The following is a quick summary of changes made to update Cloud Shell to be a bit more like my own machine.

Software Stack

My default software stack is based on the following applications

Section Software Description
1 oh-my-bash Command line tooling for visual feedback
2 tmux Terminal multiplexer for adminstration and developer productivity
3 vim Fast and extensible editor for a range of languages

If you are not familar with Vim, the general command navigation key configuration is as follows:

Key Meaning Description
h left Move the cursor left
j down Move the cursor downwards
k up Move the cursor upwards
l right Move the cursor right

You may have noticed Vim configurations exist in a number of other applications. So learning some of the key bindings can increase general productivity.

oh-my-bash

In case you have never heard of oh-my-bash (or fish/oh-my-zsh) they provide an enhanced command line experience. If you like visual feedback on the state of your machine, then I highly recommend spending sometime looking at these options.

I have already covered the installation process for Cloud Shell in an earlier blog post

Using oh-my-bash with Cloud Shell

Once installed, you know have a more interesting command line.

tmux

Tmux is a terminal multiplexer, which is a fancy way of saying it give you the ability to run multi terminals. It is already installed in Cloud Shell and just requires a few pieces of configuration to get going.

The configuration to be applied will focus on three things:

  • Amend the default command key to CTRL-a
  • Amend window pane split command to use | and -
  • Amend pane movement commands to Vim navigation key bindings
  1. In Cloud Shell create a new file called ~/.tmux.conf
  2. Add the following content to the file
 1# Amend ctrl + b to ctrl + a
 2unbind C-b
 3set -g prefix C-a
 4
 5# Set the delay
 6set -s escape-time 1
 7
 8# Use | to split the window vertically
 9bind | split-window -h -c "#{pane_current_path}"
10# Use - to split the window horizontally
11bind - split-window -v -c "#{pane_current_path}"
12unbind '"'
13unbind %
14
15# Move between panes using Vim keys
16bind h select-pane -L
17bind j select-pane -D
18bind k select-pane -U:
19bind l select-pane -R
20
21# Sync windows - turn on/off
22bind-key a set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"
23
24# Split the window into two
25split-window -v -p 10 -t cloudshell
  1. Source the configuration i.e. tell tmux we changed the configuration
1tmux source-file ~/.tmux.conf

Tmux is now setup to use CTRL+a to initiate a command.

Note: CTRL+a means press the CTRL key and a at the same time.
To initiate a command use CTRL+a (then let go of these keys) and then press the command i.e. | or -

For a more general tmux guide reference an earlier blog post: Setting up tmux

vim

Vim is an editor that is available on most linux distributions. The configuration below gives some helpful initial options.

  • Configuration settings e.g. make search case insensitve, turn syntax highlighting on
  • Set column width to 80
  • Amend the color scheme to use evening setting
  • Amend the default key bind for working with split windows

Avoid Browser command clashes i.e. CTRL+w by changing the default key bind

  1. In Cloud Shell create a new file called ~/.vimrc
  2. Add the following content to the file
 1" RR: User settings
 2syntax on                                          " Syntax highlight
 3set noerrorbells                                   " No bells
 4set tabstop=2 softtabstop=2                        " Default tab use space
 5set shiftwidth=2                                   " Default shift
 6set expandtab                                      " Default tab expansion
 7set smartindent
 8set nu rnu
 9set nowrap                                         " Dont wrap lines
10set smartcase                                      " Case insensitive
11set noswapfile
12set nobackup
13set undodir=~/.vim/undodir                         " Create this directory on device!!!
14set undofile
15set incsearch                                      " Incremental search
16set encoding=utf-8
17set spelllang=en_gb
18set spell
19set splitright                                     " vsplit right
20set splitbelow                                     " split below
21
22set colorcolumn=80                                 " Add a column bar
23highlight ColorColumn ctermbg=0 guibg=lightgrey
24
25colorscheme evening
26set background=dark
27
28" ctrl-[hjkl] to select the active split!
29nmap <silent> <c-k> :wincmd k<CR>
30nmap <silent> <c-j> :wincmd j<CR>
31nmap <silent> <c-h> :wincmd h<CR>
32nmap <silent> <c-l> :wincmd l<CR>
33
34let g:netrw_browse_split=2
35let g:netrw_banner=0
36let g:netrw_winsize=20
37let g:ctrlp_use_caching=0

For a more general vim guide reference an earlier blog post: Setting up vim