File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,31 @@ function killf
21
21
end
22
22
end
23
23
24
+ # Select a port to kill, by pid, port, or command line
25
+ function kill_port
26
+
27
+ # Function to get the command line for a given PID
28
+ function get_command -a pid
29
+ ps -p $pid | awk ' NR>1 {for (i=4; i<=NF; i++) {printf "%s ", $i }; print ""}'
30
+ end
31
+
32
+ # Find listening processes, get commands, and format output
33
+ lsof -iTCP -sTCP :LISTEN -P | awk ' {print $2, $9}' | uniq | tail -n +2 | \
34
+ while read -l pid port
35
+ set -l command (get_command $pid )
36
+ set -l port (string pad -w 8 (string replace ' localhost' ' ' $port ))
37
+ set -l pid (string pad --right -w 6 $pid )
38
+ echo -e " $pid $port $command " | column
39
+ end | \
40
+
41
+ # Pipe the output to fzf for selection. Grab pid and show pstree
42
+ fzf --exact --tac --preview ' pstree -p (echo {} | awk "{print $2}")' --preview-window =down,30% --header " Select a process to kill (PID Command Port):" | \
43
+
44
+ # Kill the selected process
45
+ awk ' {print $1}' | xargs -r kill -9
46
+ end
47
+
48
+
24
49
function clone --description " clone something, cd into it. install it."
25
50
git clone --depth =1 $argv [1]
26
51
cd (basename $argv [1] | sed ' s/.git$//' )
You can’t perform that action at this time.
0 commit comments