Files
dotfiles/plugins/common/proc_utils.zsh
2024-12-22 02:19:26 +02:00

57 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env zsh
# reload entire shell
reload-zsh() {
source $HOME/.zshrc
}
# find out which process is listening on a specific port
listening() {
if [[ $# -eq 0 ]]; then
lsof -iTCP -sTCP:LISTEN -n -P
elif [[ $# -eq 1 ]]; then
lsof -iTCP -sTCP:LISTEN -n -P | grep -i --color $1
else
echo "Usage: listening [pattern]"
fi
}
# kill process listening on a specific port
kill-listening() {
if [[ $# -eq 0 ]]; then
echo "Usage: kill-listening <port>"
return 1
fi
listening $1 | awk '{print $2}' | xargs kill
}
# run a command and report the time it took
bench() {
if [[ $# -eq 0 ]]; then
echo_red "Usage: bench [-v] <command>"
return 1
fi
verbose=0
while [[ $# -gt 1 ]]; do
case $1 in
-v)
verbose=1
;;
esac
shift
done
command=$1
shift
echo "Benchmarking $command..."
bin="/usr/bin/time"
flags=''
if [[ $verbose -eq 1 ]]; then
flags='-h -l'
fi
# TODO implement
# xargs $bin $flags $command $@
/usr/bin/time -h -l $command $@
}