Last active
November 15, 2023 07:34
-
-
Save zombiezen/d24fbe7d59d56f61b762ec1435699df2 to your computer and use it in GitHub Desktop.
zsh on Google Cloud Shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
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
I'd been wanting to put zsh on my cloud shell but hadn't taken the time to do it. I appreciate the gist, it saved me time!