Skip to content

Commit

Permalink
Update flattool
Browse files Browse the repository at this point in the history
Updated version number.
Fixed various typos.
Surrounded variables in { } when next to text to avoid potential problems.
Removed any use of local.
Clarified bash in the shebang instead of sh.
  • Loading branch information
heliguy4599 authored Jun 16, 2023
1 parent f604325 commit c814708
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions flattool
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only

# Global variables
versionNumber="0.1.1"
versionNumber="0.1.2"
appID=''

# Functions to save time programming this
Expand All @@ -17,13 +17,13 @@ printerr() {
printf "\033[1;31merror:\033[0m $1\n\n"

if [ $# -eq 2 ]; then
printf "$2\n"
printf "${2}\n"
fi
}

# Get explicit concent function
userConcent() {
local prompt=$1
prompt=$1
printf -- "$prompt [y|N]: "
read -r answer
case "$answer" in
Expand All @@ -40,14 +40,14 @@ userConcent() {

# Information printing function
printinfo() {
printf -- " Version\t$versionNumber\n"
printf -- " Location\t$0\n\n"
printf -- " Version\t${versionNumber}\n"
printf -- " Location\t${0}\n\n"
}

# Function to easily check that the command called has the right amount of arguments
checkArgLength() {
local minLnegth=$1
local maxLength=$2
minLnegth=$1
maxLength=$2
if [ $minLnegth -lt 0 ] || ( [ $minLnegth -gt $maxLength ] && [ $maxLength -ge 0 ] ); then
printerr "Internal program error: checkArgLength called with improper min or max values\n$0"
exit 1
Expand All @@ -66,6 +66,7 @@ checkArgLength() {
fi
}
# ====================================================================================

printMasterHelp() {
println "Usage: flattool <command>"
printinfo
Expand All @@ -87,22 +88,22 @@ print_subcommand_help() {
install)
println " install - usage: flattool install <app-query> <app-query> <app-query> ..."
println " can also be ran with '-i'"
println " about: Installs one or more flatpak apps with seperate processes to avoid cancelling the queue if a name cannot be matched\n"
println " about: Installs one or more flatpak apps with separate processes to avoid cancelling the queue if a name cannot be matched\n"
;;
uninstall)
println " uninstall - usage: flattool uninstall <app-query> <app-query> <app-query> ..."
println " can also be ran with '-u', 'remove', 'rm'"
println " about: Uninstalls one or more flatpak apps with seperate processes to avoid cancelling the queue if a name cannot be matched\n"
println " about: Uninstalls one or more flatpak apps with separate processes to avoid cancelling the queue if a name cannot be matched\n"
;;
purge)
println " purge - usage: flattool puge <app-query>"
println " purge - usage: flattool purge <app-query>"
println " can also be ran with '-p'"
println " about: Uninstalls a flatpak app and trashes its user data folder\n"
;;
search)
println " search - usage: flattool search <app-query>"
println " can also be ran with '-s'"
println " about:Searches installed flatpaks and returns lines from 'flatpak list' that match the query\n"
println " about: Searches installed flatpaks and returns lines from 'flatpak list' that match the query\n"
;;
id)
println " id - usage: flattool id <app-query>"
Expand Down Expand Up @@ -171,17 +172,17 @@ esac
# Main functions for the app
# ====================================================================================
identifyByQuery() {
local app=$(flatpak list | awk -v app="${1,,}" -F '\t' 'tolower($0) ~ app { print $2 }' | head -n 1)
app=$(flatpak list | awk -v app="${1,,}" -F '\t' 'tolower($0) ~ app { print $2 }' | head -n 1)
if [ -z $app ]; then
printerr "No Application ID found from query: '\033[1m$1\033[0m'"
printerr "No Application ID found from query: '\033[1m${1}\033[0m'"

exit 1
fi
appID=$app
}

searchApp() {
local output=$(flatpak list | grep -i "$1")
output=$(flatpak list | grep -i "$1")
if [ -z "$output" ]; then
println "No installed application found from query: '\033[1m$1\033[0m'"
exit 1
Expand Down Expand Up @@ -209,7 +210,7 @@ removeApp() {

purgeApp() {
identifyByQuery $1
userConcent "Are you sure you want to uninstall \033[1m$appID\033[0m and move its user data to the trash?"
userConcent "Are you sure you want to uninstall \033[1m${appID}\033[0m and move its user data to the trash?"
flatpak uninstall $appID
gio trash $HOME/.var/app/$appID
}
Expand Down Expand Up @@ -355,6 +356,6 @@ case "$subcommand" in
printinfo
;;
*)
printerr "'$subcommand' is not a flattool command" "See 'flattool --help'"
printerr "'${subcommand}' is not a flattool command" "See 'flattool --help'"
;;
esac

0 comments on commit c814708

Please sign in to comment.