-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpacman-comment
executable file
·41 lines (35 loc) · 1.05 KB
/
pacman-comment
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
#!/usr/bin/env sh
# vim: ft=sh ts=4 sw=4 sts=4 et :
PKGS_LOGPATH="/var/log"
PKGS_LOGFILE="/var/log/pacman-pkg-comments.log"
prepare() {
# Check for root privileges
if [ "$(id -u)" -ne 0 ]; then
echo "error: you cannot perform this operation unless you are root." >&2
exit 1
fi
# Check if log directory exists
if [ ! -d "$PKGS_LOGPATH" ]; then
printf "\033[1;33mwarning:\033[0m comment file does not exist\n" >&2
exit 1
fi
}
add_comments() {
# Find available editor
for vim_cmd in nvim vim vi; do
if command -v "$vim_cmd" >/dev/null 2>&1; then
vim_cmd=$(command -v "$vim_cmd")
break
fi
done
if [ -n "$vim_cmd" ]; then
# Redirect I/O to terminal for interactive use
$vim_cmd -c "set expandtab softtabstop=4 tabstop=4 shiftwidth=4" \
"$PKGS_LOGFILE" </dev/tty >/dev/tty
else
printf "\033[1;33mwarning:\033[0m vi not available -- add comments to %s manually\n" \
"$PKGS_LOGFILE" >&2
fi
}
prepare
add_comments