-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpacman-wrapper.sh
154 lines (144 loc) · 2.93 KB
/
pacman-wrapper.sh
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
#!/bin/bash
# Copyright (c) 2017 Josh Glendenning(https://github.com/isobit/pac)
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# pac
# A simple bash wrapper for pacman.
# Author: Josh Glendenning
# Usage: pac [options] <command> <args>...
function pac() {
function log_info {
echo "$(tput setaf 4)$1$(tput sgr0)" >&2
}
function log_warn {
echo "$(tput setaf 3)$1$(tput sgr0)" >&2
}
function log_error {
echo "$(tput setaf 1)ERROR:$(tput sgr0) $1" >&2
}
function display_help {
cat <<EOS
Usage: pac [options] <command> <args>...
pac install(i) <package>
pac install-tarball <file>
pac search <package>
pac info <package>
pac remove(uni) <package>
pac update [args]...
pac upgrade(up) [args]...
pac list-installed(ls) List locally installed packages
pac locate <file> Query the package which provides <file>
Options:
-h | --help Show this screen.
-v | --verbose Display the command to be passed through.
--yaourt Use yaourt instead of pacman.
--pacman Force pacman if use_yaourt is enabled
EOS
}
CMD='pacman'
# Try to detect if yaourt is installed
if hash yaourt 2>/dev/null; then
use_yaourt=true
fi
# Match any [options]
while :; do
case "$1" in
-h | --help)
display_help # Call your function
# no shifting needed here, we're done.
return
;;
-v | --verbose)
verbose=true
shift
;;
--yaourt)
use_yaourt=true
shift
;;
--pacman)
use_yaourt=false
shift
;;
--dry-run)
dry_run=true
shift
;;
--) # End of all options
shift
break
;;
-*)
log_error "Unknown option: $1"
break
;;
*) # No more options
break
;;
esac
done
# Use yaourt if use_yaourt is enabled
if [ "$use_yaourt" = true ]; then
CMD='yaourt'
fi
# Update the $CMD if user_sudo is enabled
# (and yaourt is not enabled)
# if [ "$use_sudo" = true ]; then
# CMD="sudo $CMD"
# fi
# Match <command> and pass though to pacman
case "$1" in
'i' | 'install' | 'add')
shift
CMD_ARGS="-S $*"
;;
'install-tarball')
shift
CMD_ARGS="-U $*"
;;
's' | 'search')
shift
CMD_ARGS="-Ss $*"
;;
'info')
shift
CMD_ARGS="-Si $*"
;;
'update')
shift
CMD_ARGS="-Sy $*"
;;
'up' | 'upgrade')
shift
CMD_ARGS="-Syu $*"
;;
'uni' | 'rm' | 'remove')
shift
CMD_ARGS="-Rs $*"
;;
'ls' | 'list-installed')
shift
CMD_ARGS="-Q $*"
;;
'locate')
shift
CMD_ARGS="-Qo $*"
;;
*)
log_error "Unknown command: $1"
return 1
;;
esac
# echo the whole command if verbose is enabled
if [ "$verbose" = true ]; then
log_info "=> $(tput sgr0)$CMD $CMD_ARGS"
fi
# Call the command
if [ "$dry_run" = true ]; then
echo "$CMD $CMD_ARGS"
else
eval "$CMD $CMD_ARGS"
# echo "$CMD $CMD_ARGS"
fi
}