Last active
February 29, 2024 00:22
-
-
Save jfarcand/ca6c0c1ce8d487a0e9dc58487e7679a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kl() | |
local key="$1" | |
local namespace="${2:-production}" # Default to production if no namespace is provided | |
local pod_names | |
local selected_pods=() | |
# Find the pod names based on the key | |
pod_names=($(kubectl get pod -n "$namespace" | grep "$key" | awk '{print $1}')) | |
if [[ ${#pod_names[@]} -eq 0 ]]; then | |
echo "No pods found with key: $key in namespace: $namespace" | |
return 1 | |
fi | |
# Pass the count of pod_names to AppleScript | |
local pod_count=${#pod_names[@]} | |
osascript <<EOF | |
tell application "iTerm" | |
tell current window | |
tell current session | |
write text "kubectl logs -n '$namespace' -f '${pod_names[1]}' | zap-pretty" | |
if $pod_count > 1 then | |
split vertically with default profile | |
delay 1 | |
end if | |
end tell | |
if $pod_count > 1 then | |
tell last session of current tab | |
write text "kubectl logs -n '$namespace' -f '${pod_names[2]}' | zap-pretty" | |
end tell | |
end if | |
end tell | |
end tell | |
EOF | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment