-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender-dashboard.plugin.zsh
More file actions
103 lines (89 loc) · 3.16 KB
/
render-dashboard.plugin.zsh
File metadata and controls
103 lines (89 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env zsh
# Render Dashboard ZSH Plugin
#
# Installation:
# 1. Copy to: ~/.oh-my-zsh/custom/plugins/render-dashboard/render-dashboard.plugin.zsh
# 2. Add 'render-dashboard' to plugins in ~/.zshrc
# 3. Reload: source ~/.zshrc
# Cache file location
_RDASH_CACHE_FILE="${HOME}/.cache/render-dashboard/completions"
# Generate completions from config.yaml
_rdash_generate_completions() {
# Look for config in standard locations
local config_file=""
if [[ -f "${HOME}/.config/render-dashboard/config.yaml" ]]; then
config_file="${HOME}/.config/render-dashboard/config.yaml"
elif [[ -f "./config.yaml" ]]; then
config_file="./config.yaml"
else
return 1
fi
# Extract service aliases from config
local aliases=()
while IFS= read -r line; do
# Match lines like: - "chat"
if [[ $line =~ ^[[:space:]]*-[[:space:]]*[\"\'](.*)[\"\']\s*$ ]]; then
aliases+=("${match[1]}")
fi
done < <(awk '/aliases:/{flag=1;next}/^[[:space:]]*-[[:space:]]*id:/{flag=0}flag' "$config_file")
# Actions that can be performed on services
local actions=(logs events deploys settings status)
# Create cache directory
mkdir -p "$(dirname "$_RDASH_CACHE_FILE")"
# Write completions to cache
{
for alias in $aliases; do
for action in $actions; do
echo "rdash ${alias} ${action}"
done
done
} > "$_RDASH_CACHE_FILE"
}
# Completion function
_rdash_completion() {
local -a commands
local state
# Generate cache if missing or config is newer
local config_file=""
if [[ -f "${HOME}/.config/render-dashboard/config.yaml" ]]; then
config_file="${HOME}/.config/render-dashboard/config.yaml"
elif [[ -f "./config.yaml" ]]; then
config_file="./config.yaml"
fi
if [[ -n "$config_file" ]] && { [[ ! -f "$_RDASH_CACHE_FILE" ]] || [[ "$config_file" -nt "$_RDASH_CACHE_FILE" ]]; }; then
_rdash_generate_completions
fi
# Define completion spec
_arguments -C \
'1:service:->services' \
'2:action:->actions' \
&& return 0
case $state in
services)
# Extract unique service aliases from cache
if [[ -f "$_RDASH_CACHE_FILE" ]]; then
local -a services
services=($(awk '{print $2}' "$_RDASH_CACHE_FILE" | sort -u))
_describe 'service' services
fi
;;
actions)
local -a actions
actions=(
'logs:Open service logs in browser'
'events:Open service events in browser'
'deploys:Open service deploys in browser'
'settings:Open service settings in browser'
'status:Show current service status in terminal'
)
_describe 'action' actions
;;
esac
}
# Register completion
compdef _rdash_completion rdash
# Generate initial completions on plugin load
_rdash_generate_completions 2>/dev/null
# Helpful aliases (optional - can be commented out if not wanted)
# Uncomment these if you want quick aliases
# alias rd='rdash' # If you want to use 'rd' as shorthand