-
Notifications
You must be signed in to change notification settings - Fork 0
/
tel-app
executable file
·118 lines (111 loc) · 3.24 KB
/
tel-app
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
#!/usr/bin/env bash
### TEL app launcher ###
version=0.3
removing_app=false
print_ERR_and_die(){
# Error printing function
printf "\e[33;5;1m[!]%s\n\e[m"\
"$*" 1>&2
exit 1
}
show_help(){
printf "%s\n"\
"tel-app [OPTIONS] [PATTERN]"\
"__________________________"\
"OPTIONS"\
" -h | --help display this help message"\
" -i | --info show settings page for chosen app"\
" -r | --remove remove/uninstall chosen app"\
" -u | --update-cache update app cache"
}
update_cache(){
printf "\e[33;5;2m Launcher\e[m: \e[33;5;1mUpdating app cache...%s\n\e[m"
am broadcast --user 0 \
--es com.termux.app.reload_style apps-cache \
-a com.termux.app.reload_style com.termux > /dev/null
}
main(){
cachefile="$HOME/.apps"
app_namefile="$HOME/.app_names"
show_info_page="false"
case "$1" in
-v | --version)
printf "\e[33;5;2m Launcher\e[m: \e[33;5;1mversion $version"
exit 0
;;
-i | --info)
shift
show_info_page="true"
;;
# Update the app list
# Incase a new app has been installed
-u | --update-cache)
update_cache
exit 0
;;
-r | --remove)
shift
removing_app=true
;;
# Display the help message
-h | --help)
show_help
exit 0
;;
esac
if [ ! -f $cachefile ] || [ ! -f $app_namefile ] ; then
update_cache
fi
# fuzzy search in $app_namefile to get the app code and app
# name in this format
# app_code | app_name
app_data=$(fzf -e --prompt=" Choose app: " --query="$*" --color=16 --select-1 -0 < "$app_namefile")
case "$?" in
# No app found
"1" )
printf "\e[33;5;2m Launcher\e[m: \e[33;5;1mApp not found%s\n\e[m"
exit 1
;;
# If Ctrl+C is used
"130")
return 1
;;
esac
# get the app code
app_code=$( echo "$app_data" | cut -d "|" -f1)
# get the app name
app_name=$( echo "$app_data" | cut -d "|" -f2)
# No app name recieved
[[ -z "$app_code" ]] && exit 1
# get the activity name
activity=$( grep "$app_code" "$cachefile" | cut -d "|" -f2 )
if [ "$removing_app" == "true" ] ; then
printf "\e[33;5;2m Launcher\e[m: \e[33;5;1mUninstall app '$app_name'? y/N\n\e[m"
read response
if [ "$response" == y ] ; then
activity=$(echo "$activity" | cut -d "/" -f1)
uninstalled=$(su -c pm uninstall $activity > /dev/null)
if [ "$?" == 0 ] ; then
printf "\e[33;5;2m Launcher\e[m: \e[33;5;1m'$app_name' was uninstalled\e[m\e\n"
update_cache
else
printf "\e[33;5;2m Launcher:\e[m error removing $app_name"
exit 1
fi
else
exit 0
fi
exit 0
elif [ "$show_info_page" == "true" ] ; then
printf "\e[33;5;2m Launching\e[m %s\n"\
"$app_name - app info page"
activity=$(echo "$activity" | cut -d "/" -f1)
am start -a android.settings.APPLICATION_DETAILS_SETTINGS "package:$activity" > /dev/null 2>&1
else
printf "\e[33;5;2m Launching\e[m %s\n"\
"$app_name - $activity"
# Launch the app
am start -n "$activity" --user 0 > /dev/null 2>&1
fi
}
main "$@"