feat: add free port (fp) function

This commit is contained in:
max_richter 2021-01-21 12:40:08 +00:00
parent dd5d566080
commit 4d24e9b47e
2 changed files with 31 additions and 1 deletions

View File

@ -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;

View 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
}