.dotfiles/configs/zsh/functions/fp.zsh

35 lines
620 B
Bash
Raw Normal View History

2021-01-21 13:40:08 +01:00
#Helps stop processes which use ports
function fp(){
2021-06-22 13:05:12 +02:00
for p in "$@"
do
2021-01-21 13:40:08 +01:00
2021-06-22 13:05:12 +02:00
PORT=$var;
2021-01-21 13:40:08 +01:00
2021-06-22 13:05:12 +02:00
if [ "$(which lsof)" = "lsof not found" ]; then
echo "lsof not installed"
else
PIDS="$(lsof -t -i:$PORT)"
2021-01-21 13:40:08 +01:00
2021-06-22 13:05:12 +02:00
AMOUNT=$(wc -w<<<$PIDS);
2021-01-21 13:40:08 +01:00
2021-06-22 13:05:12 +02:00
if [ $AMOUNT = 0 ]; then
2021-01-21 13:40:08 +01:00
2021-06-22 13:05:12 +02:00
echo "No processes use port $PORT";
2021-01-21 13:40:08 +01:00
2021-06-22 13:05:12 +02:00
else
2021-01-21 13:40:08 +01:00
2021-06-22 13:05:12 +02:00
echo "Killing $AMOUNT process(es) using port $PORT";
2021-01-21 13:40:08 +01:00
2021-06-22 13:05:12 +02:00
echo "$PIDS" | while IFS= read -r pid ; do
kill -9 $pid;
done
fi
2021-01-21 13:40:08 +01:00
fi
2021-06-22 13:05:12 +02:00
done
}