-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove-unneeded-packages
executable file
·45 lines (38 loc) · 1.31 KB
/
remove-unneeded-packages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env fish
# remove-unneeded-packages - Ask to remove all system packages installed as dependencies that are no longer needed.
set -- script "$(path basename (status filename))"
argparse -n $script 'h/help' 'l/list' -- $argv
if set -q _flag_h
echo "$script - ask to remove all system packages installed as dependencies that are no longer needed."
echo "Usage: $script [arguments]"
echo
echo " -h/--help - Print help and exit."
echo " -l/--list - List unneeded packages and exit."
exit
end
set distro "$(grep '^ID=' /etc/os-release | string sub --start 4)"
function unneeded-packages -d "Get a list of unneeded packages."
if contains "$distro" 'arch' 'archarm'
sudo pacman -Qdt | string match --all --regex --groups-only '^(\\S+)\\s+\\S+'
else
warn -t $script -l 'error' "Don't know how to get a list of unneeded packages for distro \"$distro\"."
exit 1
end
end
if set -q _flag_l
unneeded-packages
exit
end
if contains "$distro" 'arch' 'archarm'
set packages (unneeded-packages)
if test (count $packages) = 0
echo "$script: No unneeded packages." >&2
exit
end
sudo pacman -Rs $packages
else if contains "$distro" 'debian'
sudo apt autoremove
else
echo "$script: Error: Unsupported distro: \"$distro\"" >&2
exit 1
end