Skip to content

Add zyp un/zyp unneeded #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion zyp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ printf '%s\n' "
orphaned, or Lists installed packages which no longer have a repository associated with them.
'--list or -l' may be used to list only the package names.
'--remove or -r' may be used to remove all orphaned packages (USE WITH CAUTION).
unneeded, un Lists installed packages which may no longer be needed.
'--list' or '-l' may be used to list only the package names.
'--remove' or '-r' may be used to remove all unneeded packages (USE WITH CAUTION).
"
}

Expand Down Expand Up @@ -524,6 +527,26 @@ case "$1" in
;;
esac
;;
un|unneeded)
case "$2" in
# list orphaned packages separated by spaces
-l|--list) zypper --no-color --no-refresh -q pa --unneeded | tail -n +3 | cut -f3 -d'|' | tr -d ' ' | tr '\n' ' '; echo;;
# prompt to remove all orphaned packages
-r|--remove) sudo zypper --no-refresh rm -u $(zypper --no-color --no-refresh -q pa --unneeded | tail -n +3 | cut -f3 -d'|' | tr -d ' ' | tr '\n' ' ');;
# list orphaned packages in similar fashion to search output
*)
zypper --no-color --no-refresh -q pa --unneeded | tail -n +3 > "$HOME"/.cache/zyp/zypunneeded.txt
for package in $(cat "$HOME"/.cache/zyp/zypunneeded.txt | cut -f3 -d'|' | tr -d ' '); do
echo "$(tput setaf $COLOR_INFO)Name: $(cat "$HOME"/.cache/zyp/zypunneeded.txt | grep -w "$package" | cut -f3 -d'|' | tr -d ' ')$(tput sgr0)"
echo "Status: $(cat "$HOME"/.cache/zyp/zypunneeded.txt | grep -w "$package" | cut -f1 -d'|' | tr -d ' ')"
echo "Version: $(cat "$HOME"/.cache/zyp/zypunneeded.txt | grep -w "$package" | cut -f4 -d'|' | tr -d ' ')"
echo "Arch: $(cat "$HOME"/.cache/zyp/zypunneeded.txt | grep -w "$package" | cut -f5 -d'|' | tr -d ' ')"
echo "Repo: $(cat "$HOME"/.cache/zyp/zypunneeded.txt | grep -w "$package" | cut -f2 -d'|' | tr -d ' ')"
done
rm -f "$HOME"/.cache/zyp/zypunneeded.txt
;;
esac
;;
# --no-refresh to save time
pa|packages) zypper --no-refresh "$@";;
# use rpm to get changelog for installed packages
Expand Down Expand Up @@ -571,4 +594,3 @@ case "$1" in
esac
;;
esac