forked from bench87/kube-fzf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfpod
executable file
·30 lines (21 loc) · 949 Bytes
/
pfpod
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
#!/usr/bin/env bash
set -e
set -o pipefail
[[ -z "${KUBE_FZF_PATH}" ]] && source kube-fzf.sh || source $KUBE_FZF_PATH
pfpod() {
local namespace_query pod_query port result namespace pod_name open copy context
_kube_fzf_handler "pfpod" "$@"
context_selector=$(echo $args | awk -F '|' '{ print $5 }')
IFS=$'|' read -r namespace_query pod_query port open context_selector _unused _unused <<< "$args"
result=$(_kube_fzf_search "$namespace_query" "$pod_query" "$context_selector" "pod")
IFS=$'|' read -r namespace pod_name <<< "$result"
local fzf_args=$(_kube_fzf_fzf_args "" "--select-1")
_kube_fzf_echo "kubectl port-forward --namespace='$namespace' $pod_name $port"
IFS=':' read -ra splitted_port <<< $port
$open && open_in_browser $splitted_port
kubectl port-forward --namespace=$namespace $pod_name $port
}
open_in_browser() {
(sleep 3 && echo "Opening localhost:$1" && open "http://localhost:$1") &
}
pfpod "$@"