Skip to content

Instantly share code, notes, and snippets.

@arrase
Last active December 5, 2023 16:38
Show Gist options
  • Save arrase/7edafc36472ee079dd89c49f74891b5d to your computer and use it in GitHub Desktop.
Save arrase/7edafc36472ee079dd89c49f74891b5d to your computer and use it in GitHub Desktop.
Simple gcloud prompt for zsh
#!/usr/bin/env bash
# Copyright 2023 Juan Ezquerro LLanes
#
# 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
#
# http://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.
# Debug
[[ -n $DEBUG ]] && set -x
_gcloud_ps1_init() {
setopt PROMPT_SUBST
zmodload -F zsh/stat b:zstat
zmodload zsh/datetime
}
# Set gcloud-ps1 shell defaults
_gcloud_ps1_init
# Build our prompt
gcloud_ps1() {
GCLOUD_PS1="$(gcloud config get project 2>/dev/null)"
echo "${GCLOUD_PS1}"
}
@arrase
Copy link
Author

arrase commented Dec 5, 2023

source $HOME/.gcloud-ps1.sh
PROMPT='$(gcloud_ps1) '$PROMPT

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