Skip to content

Instantly share code, notes, and snippets.

@zombiezen
Last active November 15, 2023 07:34
Show Gist options
  • Save zombiezen/d24fbe7d59d56f61b762ec1435699df2 to your computer and use it in GitHub Desktop.
Save zombiezen/d24fbe7d59d56f61b762ec1435699df2 to your computer and use it in GitHub Desktop.
zsh on Google Cloud Shell
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ -n "$BASH_VERSION" ]; then
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# Assume that you ran: ./configure --prefix=$HOME/zsh && make -j2 && make install
[ -f $HOME/zsh/bin/zsh ] && exec $HOME/zsh/bin/zsh
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [[ -e "/google/google-cloud-sdk/path.zsh.inc" ]]; then
source "/google/google-cloud-sdk/path.zsh.inc"
fi
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
setopt promptsubst
PROMPT='%n@${DEVSHELL_PROJECT_ID:-cloudshell}:%~ %(!.#.Z) '
if [[ -e "/google/google-cloud-sdk/completion.zsh.inc" ]]; then
source "/google/google-cloud-sdk/completion.zsh.inc"
fi
onexit () {
for FILE in /google/devshell/bash_exit.google.d/*; do
if [ -x "$FILE" ]; then
"$FILE"
fi
done
}
trap onexit EXIT
@skeenan947
Copy link

You can also build a custom image w/ zsh in it. Was super simple to do.
My cloudshell Dockerfile:

FROM gcr.io/cloudshell-images/cloudshell:latest
RUN  sudo apt-get -qq update 
RUN  sudo apt-get -qq install zsh virtualenvwrapper zsh-syntax-highlighting ttf-ancient-fonts fonts-powerline -y

Tried to change default shell but google runs bash anyways. Ended up using your method of checking for zsh and running it from .profile

@cvigo
Copy link

cvigo commented Sep 19, 2019

You can also build a custom image w/ zsh in it. Was super simple to do.
My cloudshell Dockerfile:

FROM gcr.io/cloudshell-images/cloudshell:latest
RUN  sudo apt-get -qq update 
RUN  sudo apt-get -qq install zsh virtualenvwrapper zsh-syntax-highlighting ttf-ancient-fonts fonts-powerline -y

Tried to change default shell but google runs bash anyways. Ended up using your method of checking for zsh and running it from .profile

It works now, just doing:

sudo su
usermod -s /bin/zsh [your_user]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment