Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 45 additions & 27 deletions tel/.tel/bin/tel-app
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ show_help(){
"__________________________"\
"OPTIONS"\
" -h display this help message"\
" -u update app cache"
" -u update app cache"\
" -r uninstall an app"
}

update_cache(){
Expand All @@ -25,42 +26,25 @@ update_cache(){
-a com.termux.app.reload_style com.termux > /dev/null
}

main(){
cachefile="$HOME/.apps"
app_namefile="$HOME/.app_names"
case "$1" in
# Update the app list
# Incase a new app has been installed
-u)
update_cache
exit 0
;;
# Display the help message
-h)
show_help
exit 0
;;
esac
if [ ! -f $cachefile ] || [ ! -f $app_namefile ] ; then
update_cache
fi
find_app(){
# fuzzy search in $app_namefile to get the app code and app
# name in this format
# app_code | app_name
app_data=$(fzf -e --cycle --prompt=" Launch app: " --query="$*" --color=16 --select-1 -0 < "$app_namefile")
app_data=$(fzf -e --cycle --prompt=" Select app: " --query="$*" --color=16 --select-1 -0 < "$app_namefile")
case "$?" in
# No app found
"1" )
printf "\e[38;5;2m Launcher\e[m: \e[38;5;1mApp not found%s\n\e[m"
printf "\e[38;5;2m Finder\e[m: \e[38;5;1mApp not found%s\n\e[m"
exit 1
;;
# If Ctrl+C is used
"130")
return 1
printf "\e[38;5;2m Exiting...\e[m%s\n"
exit 1
;;
esac
# get the app code
app_code=$( echo "$app_data" | cut -d "|" -f1)
app_code=$( echo "$app_data" | cut -d "|" -f1)
# get the app name
app_name=$( echo "$app_data" | cut -d "|" -f2)

Expand All @@ -69,10 +53,44 @@ esac

# get the activity name
activity=$( grep "$app_code" "$cachefile" | cut -d "|" -f2 )

return 0
}

main(){
cachefile="$HOME/.apps"
app_namefile="$HOME/.app_names"
case "$1" in
# Update the app list
# Incase a new app has been installed
-u)
update_cache
exit 0
;;
# Display the help message
-h)
show_help
exit 0
;;
# Uninstall an app using the built-in android packageinstaller
-r)
find_app $2
package=$(echo "$activity" | cut -d "/" -f1)
printf "\e[38;5;9m Uninstalling\e[m %s\n"\
"$app_name - $package"
am start -n com.android.packageinstaller/.UninstallerActivity -d $package --user 0 > /dev/null 2>&1
exit 0
;;
esac

if [ ! -f $cachefile ] || [ ! -f $app_namefile ] ; then
update_cache
fi

# Launch the app
find_app $1
printf "\e[38;5;2m Launching\e[m %s\n"\
"$app_name - $activity"

# Laucnh the app
am start -n "$activity" --user 0 > /dev/null 2>&1
}
main "$@"
main "$@"