-
Notifications
You must be signed in to change notification settings - Fork 0
/
pacmen
executable file
·224 lines (174 loc) · 6.12 KB
/
pacmen
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
# -------------------------------
# Chose the aur helper you use
# -------------------------------
# AUR=yay
# AUR=paru
# -------------------------------
# Variable AUR set:
if [[ -n $AUR ]]; then
AUR=$AUR
# Variable AUR not set:
else
if [[ -f $(which paru) ]]; then
AUR=paru
elif [[ -f $(which yay) ]]; then
AUR=yay
else
echo "Warning! No AUR helper detected!"
fi
fi
# Initial prompt
if ! [[ -n "$1" ]]; then
echo -e "=== Pacmen ==="
echo -e "[A]UR package install (using paru)"
echo -e "[C]lean unused packages and files"
echo -e "[I]nstall a package"
echo -e "[R]emove a package"
echo -e "[S]earch a package (official then aur)"
echo -e "[T]ree view of dependencies of a package"
echo -e "[U]pdate whole system"
echo -e "[V]iew installed packages\n"
read -p "Choose: " x
fi
# HELP
if [[ "$1" = "-h" || "$1" = "--help" || "$1" = "h" || "$1" = "help" ]]; then
echo "Pacmen is an interactive and user friendly frontend pacman."
echo -e "\nUsage:"
echo -e "-> pacmen\n Interactive version"
echo -e "-> pacmen aur\n To install packages from the AUR"
echo -e "-> pacmen clean\n To clean from installed packages"
echo -e "-> pacmen install\n To Install packages"
echo -e "-> pacmen remove\n To Remove packages"
echo -e "-> pacmen search\n To search for packages"
echo -e "-> pacmen tree\n See package dependencies"
echo -e "-> pacmen update\n To Update system"
echo -e "-> pacmen view\n To view installed packages"
echo -e "\nExamples:"
echo -e "-> pacmen install firefox\n will search for firefox and install it"
echo -e "-> pacmen i firefox\n will also search for firefox and install it"
echo -e "-> pacmen remove firefox\n will remove firefox"
exit
# AUR: for installing from the AUR
elif [[ "$x" = "a" || "$x" = "A" || "$1" = "a" || "$1" = "A" || "$1" = "aur" ]]; then
if ! [[ -n "$2" ]]; then
read -p "AUR Package search: " pak
else
pak=$2
fi
# $AUR -Ss $pak | less
echo "Select package to install:"
pakinstall=$($AUR -Ss $pak | awk -F/ '{print $2}' | awk '{print $1}' | sed -r '/^\s*$/d' | fzf --height=35% --border=sharp)
if [[ -z $pakinstall ]]; then
echo "Exiting..."
exit
fi
echo "-> $AUR -S $pakinstall"
$AUR -S $pakinstall
# CLEAN: cleaning packages cache
elif [[ "$x" = "c" || "$x" = "C" || "$1" = "c" || "$1" = "C" || "$1" = "clean" ]]; then
echo "Remove unused dependencies"
echo "-> pacman -Qtdq | sudo pacman -Rns -"
pacman -Qtdq | sudo pacman -Rns -
echo "-> paccache -r"
paccache -r
echo "-> $AUR --sync --clean"
$AUR --sync --clean
# INSTALL: for installing pakages
elif [[ "$x" = "i" || "$x" = "I" || "$1" = "i" || "$1" = "I" || "$1" = "install" ]]; then
# for 2nd argument already given with search (like pacmen s vim)
if ! [[ -n "$2" ]]; then
read -p "Package search: " pak
else
pak=$2
fi
echo "Select package to install:"
pakinstall=$(pacman -Ss $pak | awk -F/ '{print $2}' | awk '{print $1}' | sed -r '/^\s*$/d' | fzf --height=35% --border=sharp)
echo "-> sudo pacman -S $pakinstall"
if [[ -z $pakinstall ]]; then
echo "Exiting..."
exit
fi
sudo pacman -S $pakinstall
# REM: for removing a package
elif [[ "$x" = "r" || "$x" = "R" || "$1" = "r" || "$1" = "R" || "$1" = "remove" || "$1" = "rem" ]]; then
if ! [[ -n "$2" ]]; then
echo "Select package to remove:"
rem=$(pacman -Qs | awk -F/ '{print $2}' | awk '{print $1}' | sed -r '/^\s*$/d' | fzf --height=35% --border=sharp)
else
rem=$(pacman -Qs $2 | awk -F/ '{print $2}' | awk '{print $1}' | sed -r '/^\s*$/d' | fzf --height=35% --border=sharp)
fi
if [[ -z $rem ]]; then
echo "Exiting..."
exit
fi
echo "-> sudo pacman -Rs $rem"
sudo pacman -Rs $rem
# SEARCH: for searching pakages to install
elif [[ "$x" = "s" || "$x" = "S" || "$1" = "s" || "$1" = "S" || "$1" = "search" ]]; then
# for 2nd argument already given with install (like pacmen i vim)
if ! [[ -n "$2" ]]; then
read -p "Package search: " pak
else
pak=$2
fi
echo "-> pacman -Ss $pak | less"
pacman -Ss $pak | less
read -p "Search the AUR? [Y/n] " choice
if [[ "$choice" = "n" || "$choice" = "N" ]]; then
echo "Skipping AUR..."
else
echo "-> $AUR -Ss $pak | less"
$AUR -Ss $pak | less
fi
read -p "Install from Local/Aur/No? [L/A/N] " choice
if [[ $choice = "L" || $choice = "l" ]]; then
pacmen i $pak
elif [[ $choice = "A" || $choice = "a" ]]; then
pacmen a $pak
else
exit
fi
exit
# TREE: Tree view of dependencies using pactree
elif [[ "$x" = "t" || "$x" = "T" || "$1" = "t" || "$1" = "T" || "$1" = "tree" ]]; then
if [[ -z "$2" ]]; then
pak=$(pacman -Qs | awk -F/ '{print $2}' | awk '{print $1}' | sed -r '/^\s*$/d' | fzf --height=35% --border=sharp)
else
pak=$(pacman -Qs $2 | awk -F/ '{print $2}' | awk '{print $1}' | sed -r '/^\s*$/d' | fzf --height=35% --border=sharp)
fi
pactree $pak | less
exit
# UPDATE: updating the whole system
elif [[ "$x" = "U" || "$x" = "u" || "$1" = "u" || "$1" = "U" || "$1" = "update" ]]; then
echo "-> sudo pacman -Syyu"
sudo pacman -Syyu
read -p "Update AUR Packages? [Y/n] " choice
if [[ "$choice" = "n" || "$choice" = "N" ]]; then
echo "Exiting..."
exit
elif [[ "$AUR" = "yay" ]]; then
echo "-> yay --refresh"
yay --refresh
elif [[ "$AUR" = "paru" ]]; then
echo "-> paru -Sua"
paru -Sua
fi
# VIEW: view packages
elif [[ "$x" = "v" || "$x" = "V" || "$1" = "v" || "$1" = "V" || "$1" = "view" ]]; then
if [[ -z "$2" ]]; then
echo "-> pacman -Qs | less"
pacman -Qs | less
else
echo "-> pacman -Qs $2 | less"
pacman -Qs $2 | less
fi
exit
# wrong choice
else
echo "Unknown inputs."
exit
fi
echo "=============================="
echo "Press ENTER or Ctrl-C to exit."
read -p "=============================="