1
1
local api = vim .api
2
+ local actions = require (" kubectl.actions.actions" )
2
3
local commands = require (" kubectl.actions.commands" )
3
4
local container_view = require (" kubectl.views.containers" )
4
5
local deployment_view = require (" kubectl.views.deployments" )
@@ -17,6 +18,7 @@ api.nvim_buf_set_keymap(0, "n", "g?", "", {
17
18
hints = hints .. tables .generateHintLine (" <d>" , " Describe selected pod \n " )
18
19
hints = hints .. tables .generateHintLine (" <t>" , " Show resources used \n " )
19
20
hints = hints .. tables .generateHintLine (" <enter>" , " Opens container view \n " )
21
+ hints = hints .. tables .generateHintLine (" <shift-f>" , " Port forward \n " )
20
22
hints = hints .. tables .generateHintLine (" <C-k>" , " Kill pod \n " )
21
23
view .Hints (hints )
22
24
end ,
@@ -104,6 +106,46 @@ api.nvim_buf_set_keymap(0, "n", "<C-k>", "", {
104
106
end ,
105
107
})
106
108
109
+ api .nvim_buf_set_keymap (0 , " n" , " <S-f>" , " " , {
110
+ noremap = true ,
111
+ silent = true ,
112
+ callback = function ()
113
+ local namespace , pod_name = tables .getCurrentSelection (unpack (col_indices ))
114
+ if pod_name and namespace then
115
+ local current_port_query = " get pod " .. pod_name .. ' -o jsonpath="{.spec.containers[*].ports[*].containerPort}"'
116
+
117
+ local current_port_result = commands .execute_shell_command (" kubectl" , current_port_query )
118
+
119
+ vim .ui .input ({ prompt = " Port forward " .. current_port_result }, function (input )
120
+ if input ~= nil then
121
+ actions .confirmation_buffer (
122
+ " Are you sure that you want to port forward to " .. input .. " ?" ,
123
+ nil ,
124
+ function (confirm )
125
+ if confirm then
126
+ local port_forward_query = " port-forward pods/"
127
+ .. pod_name
128
+ .. " "
129
+ .. input
130
+ .. " :"
131
+ .. current_port_result
132
+
133
+ commands .shell_command_async (" kubectl" , port_forward_query , function (response )
134
+ vim .schedule (function ()
135
+ vim .notify (response )
136
+ end )
137
+ end )
138
+ end
139
+ end
140
+ )
141
+ end
142
+ end )
143
+ else
144
+ api .nvim_err_writeln (" Failed to select pod." )
145
+ end
146
+ end ,
147
+ })
148
+
107
149
if not loop .is_running () then
108
150
loop .start_loop (pod_view .Pods )
109
151
end
0 commit comments