-
Notifications
You must be signed in to change notification settings - Fork 31
/
pfpod
executable file
·40 lines (31 loc) · 1.05 KB
/
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
31
32
33
34
35
36
37
38
39
40
#!/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
_kube_fzf_handler "pfpod" "$@"
IFS=$'|' read -r namespace_query pod_query port open copy <<< "$args"
result=$(_kube_fzf_search_pod "$namespace_query" "$pod_query")
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
$copy && copy_to_clipboard $splitted_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") &
}
copy_to_clipboard() {
copier=$noop
command -v xclip >/dev/null 2>&1 && {
copier=xclip
}
command -v pbcopy >/dev/null 2>&1 && {
copier=pbcopy
}
echo "http://localhost:$1" | $copier
}
pfpod "$@"