feat: add free port (fp) function
This commit is contained in:
parent
dd5d566080
commit
4d24e9b47e
@ -2,4 +2,5 @@ source $(dirname "$0")/functions/co.zsh;
|
|||||||
source $(dirname "$0")/functions/fx.zsh;
|
source $(dirname "$0")/functions/fx.zsh;
|
||||||
source $(dirname "$0")/functions/start.zsh;
|
source $(dirname "$0")/functions/start.zsh;
|
||||||
source $(dirname "$0")/functions/wp.zsh;
|
source $(dirname "$0")/functions/wp.zsh;
|
||||||
source $(dirname "$0")/functions/y.zsh;
|
source $(dirname "$0")/functions/y.zsh;
|
||||||
|
source $(dirname "$0")/functions/fp.zsh;
|
29
configs/zsh/functions/fp.zsh
Normal file
29
configs/zsh/functions/fp.zsh
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#Helps stop processes which use ports
|
||||||
|
|
||||||
|
function fp(){
|
||||||
|
|
||||||
|
PORT=$1;
|
||||||
|
|
||||||
|
if [ "$(which lsof)" = "lsof not found" ]; then
|
||||||
|
echo "lsof not installed"
|
||||||
|
else
|
||||||
|
PIDS="$(lsof -t -i:$PORT)"
|
||||||
|
|
||||||
|
AMOUNT=$(wc -w<<<$PIDS);
|
||||||
|
|
||||||
|
if [ $AMOUNT = 0 ]; then
|
||||||
|
|
||||||
|
echo "No processes use port $PORT";
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
echo "Killing $AMOUNT process(es) using port $PORT";
|
||||||
|
|
||||||
|
echo "$PIDS" | while IFS= read -r pid ; do
|
||||||
|
kill -9 $pid;
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user