BACK TO THE HOMEPAGE

Aug 27, 2021 4 min read

Enhancing Cloudshell on Google Cloud

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
# Amend ctrl + b to ctrl + a
unbind C-b
set -g prefix C-a

# Set the delay
set -s escape-time 1

# Use | to split the window vertically
bind | split-window -h -c "#{pane_current_path}"
# Use - to split the window horizontally
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %

# Move between panes using Vim keys
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U:
bind l select-pane -R

# Sync windows - turn on/off
bind-key a set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"

# Split the window into two
split-window -v -p 10 -t cloudshell
  1. Source the configuration i.e. tell tmux we changed the configuration
tmux 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
" RR: User settings
syntax on                                          " Syntax highlight
set noerrorbells                                   " No bells
set tabstop=2 softtabstop=2                        " Default tab use space
set shiftwidth=2                                   " Default shift
set expandtab                                      " Default tab expansion
set smartindent
set nu rnu
set nowrap                                         " Dont wrap lines
set smartcase                                      " Case insensitive
set noswapfile
set nobackup
set undodir=~/.vim/undodir                         " Create this directory on device!!!
set undofile
set incsearch                                      " Incremental search
set encoding=utf-8
set spelllang=en_gb
set spell
set splitright                                     " vsplit right
set splitbelow                                     " split below

set colorcolumn=80                                 " Add a column bar
highlight ColorColumn ctermbg=0 guibg=lightgrey

colorscheme evening
set background=dark

" ctrl-[hjkl] to select the active split!
nmap <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>

let g:netrw_browse_split=2
let g:netrw_banner=0
let g:netrw_winsize=20
let g:ctrlp_use_caching=0

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