mirror of
https://github.com/joshuadavidthomas/dotfiles.git
synced 2025-07-07 20:55:01 +00:00
43 lines
829 B
Text
43 lines
829 B
Text
function reload() {
|
|
source ~/.zshenv
|
|
source ~/.zshrc
|
|
}
|
|
|
|
function killport() {
|
|
local port
|
|
local force=false
|
|
local pid
|
|
|
|
for arg in "$@"; do
|
|
if [[ $arg == '--force' ]]; then
|
|
force=true
|
|
elif [[ $arg =~ ^[0-9]+$ ]]; then
|
|
port=$arg
|
|
fi
|
|
done
|
|
|
|
if [[ -z $port ]]; then
|
|
echo "Error: No port number specified."
|
|
return 1
|
|
fi
|
|
|
|
pid=$(sudo netstat -tulpn | grep ":$port" | awk '{print $7}' | cut -d'/' -f1)
|
|
|
|
if [[ -z $pid ]]; then
|
|
echo "No process found on port $port."
|
|
return 1
|
|
fi
|
|
|
|
if ! $force; then
|
|
echo -n "Are you sure you want to kill the process on port $port? (y/n) "
|
|
read -r REPLY
|
|
echo
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
echo "Operation cancelled."
|
|
return 1
|
|
fi
|
|
fi
|
|
|
|
echo "Killing process on port $port with PID $pid"
|
|
sudo kill "$pid"
|
|
}
|