mirror of
https://github.com/sunknudsen/privacy-guides.git
synced 2025-02-23 17:43:56 +00:00
Improved background apps guide
This commit is contained in:
parent
5c29479b15
commit
c802c5e0da
@ -82,16 +82,32 @@ cat << "EOF" >> ~/.zshrc
|
|||||||
|
|
||||||
# Kill apps that match string
|
# Kill apps that match string
|
||||||
function kill-apps() {
|
function kill-apps() {
|
||||||
|
IFS=$'\n'
|
||||||
|
red=$'\e[1;31m'
|
||||||
|
nc=$'\e[0m'
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
printf "%s\n" "Usage: kill-apps string"
|
printf "%s\n" "Usage: kill-apps string"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
printf "%s\n" "Finding apps that match \"$1\"..."
|
printf "%s\n" "Finding apps that match \"$1\"..."
|
||||||
pgrep -afil "$1"
|
sleep 1
|
||||||
printf "%s" "Kill found apps (y or n)? "
|
processes=($(pgrep -afil "$1"))
|
||||||
read -r answer
|
if [ ${#processes[@]} -eq 0 ]; then
|
||||||
if [ "$answer" = "y" ]; then
|
printf "%s\n" "No apps found"
|
||||||
pgrep -afi "$1" | xargs sudo kill 2>&1 && printf "%s\n" "Done"
|
return 0
|
||||||
|
else
|
||||||
|
printf "%s\n" "${processes[@]}"
|
||||||
|
printf "${red}%s${nc}" "Kill found apps (y or n)? "
|
||||||
|
read -r answer
|
||||||
|
if [ "$answer" = "y" ]; then
|
||||||
|
printf "%s\n" "Killing found apps..."
|
||||||
|
sleep 1
|
||||||
|
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
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user