-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpkg_search
executable file
·81 lines (70 loc) · 2.25 KB
/
pkg_search
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
#!/bin/sh
main() {
set_screen_variables
parse_arguments "$@"
check_dependencies
selection=$(pkglocate '*' | cut -d ':' -f1 | uniq | fzf -e --query "$keyword")
if [ "--info" = "$info" ] || [ "-i" == "$info" ]; then
[ ! -z "$selection" ] && pkg_info -q "$selection"
else
[ ! -z "$selection" ] && echo "$selection"
fi
}
check_dependencies() {
if ! command -v pkglocate > /dev/null; then
echo -n "${bold}${yellow}Warning:${no_color} "
echo "missing ${bold}${italic}pkglocatedb${no_color} dependency"
echo "${bold}Run:${no_color} ${under_score}doas pkg_add pkglocatedb${no_color}"
exit 1
fi
if ! command -v fzf > /dev/null ; then
echo -n "${bold}${yellow}Warning:${no_color} "
echo "missing ${bold}${italic}fzf${no_color} dependency"
echo "${bold}Run:${no_color} ${under_score}doas pkg_add fzf${no_color}"
exit 1
fi
}
parse_arguments() {
if [ "--help" = "$1" ] || [ "-h" = "$1" ]; then
print_help
exit 0
fi
if [ "$#" -eq 0 ]; then
keyword=""
info=""
elif [ "$#" -eq 1 ]; then
if [ "--info" == "$1" ] || [ "-i" == "$1" ]; then
info="$1"
keyword=""
else
keyword="$1"
info=""
fi
elif [ "$#" -ge 2 ]; then
keyword="$2"
info="$1"
fi
}
print_help() {
echo "${bold}${green}pkg_search${no_color} - interactive search for OpenBSD packages"
echo ""
echo "${tab}${italic}-i${no_color} or ${italic}--info${no_color} get information about the selected package "
echo "${tab}${italic}-h${no_color} or ${italic}--help${no_color} print this help"
echo ""
echo "${two_space}${bold}NOTE:${no_color} make sure to have following packages installed:"
echo "${two_space}${tab}${bold}* pkglocatedb${no_color} -- ${under_score}doas pkg_add pkglocatedb${no_color}"
echo "${two_space}${tab}${bold}* fzf${no_color} -- ${under_score}doas pkg_add fzf${no_color}"
echo ""
}
set_screen_variables() {
no_color="\033[0m"
red="\033[38;5;160m"
yellow="\033[38;5;226m"
green="\033[38;5;119m"
bold="\033[1m"
under_score="\033[4m"
italic="\033[3m"
two_space=" "
tab=" "
}
main "$@"