mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-23 06:10:08 +00:00
add basic gcp-ps1
This commit is contained in:
parent
c105c04b6b
commit
4b9c2cfcd6
2 changed files with 83 additions and 0 deletions
34
plugins/gcp-ps1/README.md
Normal file
34
plugins/gcp-ps1/README.md
Normal 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) '
|
||||
```
|
||||
|
49
plugins/gcp-ps1/gcp-ps1.plugin.zsh
Normal file
49
plugins/gcp-ps1/gcp-ps1.plugin.zsh
Normal 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}"
|
||||
}
|
Loading…
Reference in a new issue