Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic gcp-ps1 #7936

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions plugins/gcp-ps1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# gcp prompt for zsh

Prompt which displays current configuration

## Current state

Tested only on ubuntu.
May or may not work on FreeBSD or osX. Feel free to fix any issue!

## Requirements

[gcloud](https://cloud.google.com/sdk/docs/downloads-interactive)


## Enabling

In order to use gcp-ps1 with Oh My Zsh, you'll need to enable them in the
.zshrc file. You'll find the zshrc file in your $HOME directory.

```shell
vim $HOME/.zshrc
```

Add gcp-ps1 to the list of enabled plugins and enable it on the prompt:

```shell
plugins=(
git
gcp-ps1
)

PROMPT=$PROMPT'$(gcp_ps1) '
```

49 changes: 49 additions & 0 deletions plugins/gcp-ps1/gcp-ps1.plugin.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/zsh

# GCP prompt helper for zsh
# ported to oh-my-zsh
# Displays current configuration
#
# Author: Marcin Niemira
#
# 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.

# Debug
[[ -n $DEBUG ]] && set -x

setopt PROMPT_SUBST
autoload -U add-zsh-hook
add-zsh-hook precmd _gcp_ps1_update_cache


GCP_PS1_COLOR_SYMBOL="%{$fg[blue]%}"
GCP_PS1_COLOR_NS="%{$fg[cyan]%}"

_gcp_ps1_symbol() {
echo "☁️ "
}

_gcp_ps1_update_cache() {
CONTEXT=$(cat "$HOME/.config/gcloud/active_config")
}

gcp_ps1 () {
local reset_color="%{$reset_color%}"

GCP_PS1="${reset_color}("
GCP_PS1+="$(_gcp_ps1_symbol)"
GCP_PS1+="${GCP_PS1_COLOR_SYMBOL}$CONTEXT${reset_color}"
GCP_PS1+=")${reset_color}"

echo "${GCP_PS1}"
}