-
Notifications
You must be signed in to change notification settings - Fork 0
/
egetter
executable file
·58 lines (53 loc) · 1.53 KB
/
egetter
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
#!/usr/bin/env sh
cmd_path=$(command -v egetter)
if [ -n "$cmd_path" ]; then
dir_path="$(dirname $(readlink -f $cmd_path))"
md_path="$dir_path/awesome_tools.md"
else
echo "egetter is not in path"
md_path="./awesome_tools.md"
fi
_force=""
while [ "$#" -gt 0 ]; do
case "$1" in
-i | --install)
_force="True"
shift 1
;;
--fzf)
_fzf="True"
shift 1
;;
--eget)
shift 1
_eget_args="${@}"
break
;;
-*)
shift 1
;;
*)
inp="$1"
shift 1
;;
esac
done
if [ -z "$inp" ] && [ -z "$_fzf" ]; then
echo "Either use --fzf or pass a cli tool of interest"
exit 1
fi
if [ -n "$_fzf" ]; then
name="$(cat ${md_path} | fzf --reverse | cut -d '|' -f 3)"
name_len="$(printf %s $name | wc -c | tr -d ' ')"
[ "$name_len" -lt 1 ] && { exit 1; }
ins_com="eget $name ${_eget_args}"
printf "\n%s\n\n%s\n%s\n\n%s\n" "Will be downloaded to ${EGET_BIN:-.} or to the directory passed with the flag --to" \
"-----This is a dry run------" "${ins_com}" "rerun with -i to install it"
[ -n "$_force" ] && { eval "$ins_com"; }
else
_var="eget $(grep "$inp" "${md_path}" | tr ' ' '@' | cut -d '|' -f 3 | tr -d '@')"
_var="${_var} ${_eget_args}"
printf "\n%s\n\n%s\n%s\n\n%s\n" "Will be downloaded to ${EGET_BIN:-.} or to the directory passed with the flag --to" \
"-----This is a dry run------" "${_var}" "rerun with -i to install it"
[ -n "$_force" ] && { eval "$_var"; }
fi