Skip to content

Instantly share code, notes, and snippets.

@Arnav-arw
Last active April 9, 2022 10:12
Show Gist options
  • Save Arnav-arw/aeb9119a84cb44f903b8fe339f64c8bf to your computer and use it in GitHub Desktop.
Save Arnav-arw/aeb9119a84cb44f903b8fe339f64c8bf to your computer and use it in GitHub Desktop.
cat << "EOF" >> ~/.zshrc
function kill-app() {
IFS=$'\n'
red=$(tput setaf 1)
normal=$(tput sgr0)
if [ -z "$1" ] || [ "$1" = "--help" ]; then
printf "%s\n" "Usage: kill-apps string"
return 0
fi
printf "%s\n" "Finding apps that match "$1"..."
sleep 1
processes=($(pgrep -afil "$1"))
if [ ${#processes[@]} -eq 0 ]; then
printf "%s\n" "No apps found"
return 0
else
for process in "${processes[@]}"; do
echo $process | awk '{print $1}' | xargs sudo kill 2>&1 | grep -v "No such process"
done
printf "%s\n" "Done"
return 0
fi
}
EOF
source ~/.zshrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment