From 24afcffe52de7e19a1ef9a108b4881b34491604a Mon Sep 17 00:00:00 2001 From: Jim Richter Date: Wed, 14 Jul 2021 19:14:02 +0200 Subject: [PATCH] fix: cleanup fp command --- configs/zsh/functions/fp.zsh | 45 +++++++++++++++--------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/configs/zsh/functions/fp.zsh b/configs/zsh/functions/fp.zsh index 3840f45..8de37bf 100644 --- a/configs/zsh/functions/fp.zsh +++ b/configs/zsh/functions/fp.zsh @@ -2,33 +2,26 @@ function fp(){ - for p in "$@" - do - - PORT=$var; - - 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 + if [ "$(which lsof)" = "lsof not found" ]; then + echo "lsof not installed" + else + for PORT in "$@" + do + if [ "$PORT" != "" ]; then + #echo "checking ($PORT)" + 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 - fi - - done + done + fi }