mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-11-25 01:43:04 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
934576b89b | ||
|
|
b5cb2fe952 |
No files matched your search
+4
-3
@@ -237,9 +237,10 @@ function _omz_diag_dump_one_big_text() {
|
||||
fi
|
||||
builtin echo
|
||||
builtin echo "Zsh compdump files:"
|
||||
local dumpfile dumpfiles
|
||||
command ls -lad $zdotdir/.zcompdump*
|
||||
dumpfiles=( $zdotdir/.zcompdump*(N) )
|
||||
local dumpfile
|
||||
local -U dumpfiles
|
||||
dumpfiles=( $zdotdir/.zcompdump*(N) ${ZSH_COMPDUMP:h}/.zcompdump*(N) )
|
||||
(( $#dumpfiles )) && command ls -lad $dumpfiles
|
||||
if [[ $verbose -ge 2 ]]; then
|
||||
for dumpfile in $dumpfiles; do
|
||||
_omz_diag_dump_echo_file_w_header $dumpfile
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ fi
|
||||
|
||||
# Save the location of the current completion dump file.
|
||||
if [[ -z "$ZSH_COMPDUMP" ]]; then
|
||||
ZSH_COMPDUMP="${ZDOTDIR:-$HOME}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
|
||||
ZSH_COMPDUMP="${ZSH_CACHE_DIR}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
|
||||
fi
|
||||
|
||||
# Resolve the commit $ZSH is checked out at into $REPLY by reading the git
|
||||
|
||||
+11
-14
@@ -247,20 +247,17 @@ function aws_profiles() {
|
||||
aws --no-cli-pager configure list-profiles 2> /dev/null
|
||||
return
|
||||
fi
|
||||
local file line words
|
||||
for file in "$config" "$creds"; do
|
||||
# Only read the section headers, so the credentials never enter the shell
|
||||
for line in "${(@f)$(command grep '^[[:space:]]*\[' -- "$file" 2> /dev/null)}"; do
|
||||
line=${line#*\[} # drop up to the first [
|
||||
line=${line%\]*} # drop from the last ] (comments, CR)
|
||||
words=(${=line})
|
||||
if (( $#words == 1 )); then
|
||||
# [default], or any [foo] in the credentials file
|
||||
[[ $file == $creds || $words[1] == default ]] && print -r -- $words[1]
|
||||
elif (( $#words == 2 )) && [[ $words[1] == profile ]]; then
|
||||
print -r -- $words[2]
|
||||
fi
|
||||
done
|
||||
local line words
|
||||
# Only read the section headers, so the credentials never enter the shell
|
||||
for line in "${(@f)$(command grep -h '^[[:space:]]*\[' -- "$config" "$creds" 2> /dev/null)}"; do
|
||||
line=${line#*\[} # drop up to the first [
|
||||
line=${line%\]*} # drop from the last ] (comments, CR)
|
||||
words=(${=line})
|
||||
if (( $#words == 1 )); then
|
||||
print -r -- $words[1] # [default], or [foo] in the credentials file
|
||||
elif (( $#words == 2 )) && [[ $words[1] == profile ]]; then
|
||||
print -r -- $words[2]
|
||||
fi
|
||||
done | command sort -u
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,37 @@ plugins=(... hcloud)
|
||||
| hcst | `hcloud server-type list` | List all server types |
|
||||
| hcit | `hcloud image list --type system` | List all system images |
|
||||
|
||||
## Prompt function
|
||||
|
||||
This plugin provides `hcloud_prompt_info` which can be added to your prompt to display the current Hetzner Cloud context.
|
||||
|
||||
- If `HCLOUD_TOKEN` environment variable is set, it displays `HCLOUD_TOKEN` (indicating direct token usage)
|
||||
- Otherwise, it displays the active context name
|
||||
|
||||
### Usage
|
||||
|
||||
Add `$(hcloud_prompt_info)` to your `PROMPT` or `RPROMPT` in your `.zshrc`:
|
||||
|
||||
```zsh
|
||||
RPROMPT='$(hcloud_prompt_info)'
|
||||
```
|
||||
|
||||
### Theme variables
|
||||
|
||||
| Variable | Default | Description |
|
||||
| :----------------------------- | :-------------- | :----------------------------------------------- |
|
||||
| `ZSH_THEME_HCLOUD_PREFIX` | `<hcloud:` | Prefix before the context name |
|
||||
| `ZSH_THEME_HCLOUD_SUFFIX` | `>` | Suffix after the context name |
|
||||
| `ZSH_THEME_HCLOUD_TOKEN_TEXT` | `HCLOUD_TOKEN` | Text shown when `HCLOUD_TOKEN` env var is set |
|
||||
|
||||
### Example with custom styling
|
||||
|
||||
```zsh
|
||||
ZSH_THEME_HCLOUD_PREFIX="%{$fg[blue]%}hcloud:("
|
||||
ZSH_THEME_HCLOUD_SUFFIX=")%{$reset_color%}"
|
||||
RPROMPT='$(hcloud_prompt_info)'
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
This plugin requires the [Hetzner Cloud CLI](https://github.com/hetznercloud/cli) to be installed.
|
||||
|
||||
@@ -131,3 +131,20 @@ alias hcdc='hcloud datacenter list'
|
||||
alias hcloc='hcloud location list'
|
||||
alias hcst='hcloud server-type list'
|
||||
alias hcit='hcloud image list --type system'
|
||||
|
||||
# Prompt function to display current hcloud context
|
||||
# Usage: add $(hcloud_prompt_info) to your PROMPT or RPROMPT
|
||||
function hcloud_prompt_info() {
|
||||
# Check if HCLOUD_TOKEN is set (overrides context)
|
||||
if [[ -n "$HCLOUD_TOKEN" ]]; then
|
||||
echo "${ZSH_THEME_HCLOUD_PREFIX=<hcloud:}${ZSH_THEME_HCLOUD_TOKEN_TEXT=HCLOUD_TOKEN}${ZSH_THEME_HCLOUD_SUFFIX=>}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Get active context
|
||||
local context
|
||||
context=$(hcloud context active 2>/dev/null)
|
||||
[[ -n "$context" ]] || return
|
||||
|
||||
echo "${ZSH_THEME_HCLOUD_PREFIX=<hcloud:}${context}${ZSH_THEME_HCLOUD_SUFFIX=>}"
|
||||
}
|
||||
Reference in new issue
Block a user