0
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-09-19 04:01:21 +02:00

add basic gcp-ps1

This commit is contained in:
Marcin Niemira 2019-06-18 21:43:20 +10:00
parent c105c04b6b
commit 4b9c2cfcd6
No known key found for this signature in database
GPG key ID: 5395D4A81A3FA475
2 changed files with 83 additions and 0 deletions

34
plugins/gcp-ps1/README.md Normal file
View file

@ -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) '
```

View file

@ -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}"
}