printf for portability

This commit is contained in:
the-sane 2021-01-16 08:51:22 -05:00 committed by GitHub
parent 37762b9075
commit 7f9ad04753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,7 +41,7 @@
# Check for dependencies # Check for dependencies
if [ ! -x "$(command -v mktemp)" ] || [ ! -x "$(command -v basename)" ]; then if [ ! -x "$(command -v mktemp)" ] || [ ! -x "$(command -v basename)" ]; then
echo -e "lug-helper.sh: One or more required packages were not found on this system.\nPlease check that the following packages are installed:\n- mktemp (part of gnu coreutils)\n- basename (part of gnu coreutils)" 1>&2 printf "lug-helper.sh: One or more required packages were not found on this system.\nPlease check that the following packages are installed:\n- mktemp (part of gnu coreutils)\n- basename (part of gnu coreutils)\n" 1>&2
exit 1 exit 1
fi fi
@ -103,7 +103,7 @@ menu_option_height="25"
debug_echo() { debug_echo() {
# This function expects two string arguments # This function expects two string arguments
if [ "$#" -lt 2 ]; then if [ "$#" -lt 2 ]; then
echo -e "\nScript error: The debug_echo function expects two arguments. Aborting." printf "\nScript error: The debug_echo function expects two arguments. Aborting.\n"
read -n 1 -s -p "Press any key..." read -n 1 -s -p "Press any key..."
exit 0 exit 0
fi fi
@ -111,16 +111,16 @@ debug_echo() {
# Echo the provided string and, optionally, exit the script # Echo the provided string and, optionally, exit the script
case "$1" in case "$1" in
"continue") "continue")
echo -e "\n$2\n" printf "\n$2\n"
;; ;;
"exit") "exit")
# Write an error to stderr and exit # Write an error to stderr and exit
echo -e "lug-helper.sh: $2" 1>&2 printf "lug-helper.sh: $2\n" 1>&2
read -n 1 -s -p "Press any key..." read -n 1 -s -p "Press any key..."
exit 1 exit 1
;; ;;
*) *)
echo -e "lug-helper.sh: Unknown argument provided to debug_echo function. Aborting." 1>&2 printf "lug-helper.sh: Unknown argument provided to debug_echo function. Aborting.\n" 1>&2
read -n 1 -s -p "Press any key..." read -n 1 -s -p "Press any key..."
exit 0 exit 0
;; ;;
@ -172,14 +172,14 @@ message() {
# info message # info message
# call format: message info "text to display" # call format: message info "text to display"
clear clear
echo -e "\n$2\n" printf "\n$2\n\n"
read -n 1 -s -p "Press any key..." read -n 1 -s -p "Press any key..."
;; ;;
"warning") "warning")
# warning message # warning message
# call format: message warning "text to display" # call format: message warning "text to display"
clear clear
echo -e "\n$2\n" printf "\n$2\n\n"
read -n 1 -s -p "Press any key..." read -n 1 -s -p "Press any key..."
return 0 return 0
;; ;;
@ -187,7 +187,7 @@ message() {
# question # question
# call format: if message question "question to ask?"; then... # call format: if message question "question to ask?"; then...
clear clear
echo -e "$2" printf "$2\n"
while read -p "[y/n]: " yn; do while read -p "[y/n]: " yn; do
case "$yn" in case "$yn" in
[Yy]*) [Yy]*)
@ -197,7 +197,7 @@ message() {
return 1 return 1
;; ;;
*) *)
echo "Please type 'y' or 'n'" printf "Please type 'y' or 'n'\n"
;; ;;
esac esac
done done
@ -286,7 +286,7 @@ menu() {
else else
# Use a text menu if Zenity is not available # Use a text menu if Zenity is not available
clear clear
echo -e "\n$menu_text_terminal\n" printf "\n$menu_text_terminal\n\n"
PS3="Enter selection number: " PS3="Enter selection number: "
select choice in "${menu_options[@]}" select choice in "${menu_options[@]}"
@ -296,7 +296,7 @@ menu() {
for (( i=0; i<"${#menu_options[@]}"; i++ )); do for (( i=0; i<"${#menu_options[@]}"; i++ )); do
if [ "$choice" = "${menu_options[i]}" ]; then if [ "$choice" = "${menu_options[i]}" ]; then
# Execute the corresponding action # Execute the corresponding action
echo -e "\n" printf "\n\n"
${menu_actions[i]} ${menu_actions[i]}
matched="true" matched="true"
break break
@ -309,7 +309,7 @@ menu() {
break break
else else
# If no match was found, the user entered an invalid option # If no match was found, the user entered an invalid option
echo -e "\nInvalid selection." printf "\nInvalid selection.\n"
continue continue
fi fi
done done
@ -420,11 +420,11 @@ getdirs() {
clear clear
# Get the wine prefix directory # Get the wine prefix directory
if [ -z "$wine_prefix" ]; then if [ -z "$wine_prefix" ]; then
echo -e "Enter the full path to your Star Citizen WINE prefix directory (case sensitive)" printf "Enter the full path to your Star Citizen WINE prefix directory (case sensitive)\n"
echo -e "ie. /home/USER/.wine/" printf "ie. /home/USER/.wine/\n"
while read -rp ": " wine_prefix; do while read -rp ": " wine_prefix; do
if [ ! -d "$wine_prefix" ]; then if [ ! -d "$wine_prefix" ]; then
echo -e "That directory is invalid or does not exist. Please try again.\n" printf "That directory is invalid or does not exist. Please try again.\n\n"
else else
break break
fi fi
@ -437,13 +437,13 @@ getdirs() {
message question "Is this your Star Citizen game directory?\n\n$wine_prefix/drive_c/Program Files/Roberts Space Industries/StarCitizen"; then message question "Is this your Star Citizen game directory?\n\n$wine_prefix/drive_c/Program Files/Roberts Space Industries/StarCitizen"; then
game_path="$wine_prefix/drive_c/Program Files/Roberts Space Industries/StarCitizen" game_path="$wine_prefix/drive_c/Program Files/Roberts Space Industries/StarCitizen"
else else
echo -e "\nEnter the full path to your Star Citizen installation directory\n(case sensitive)" printf "\nEnter the full path to your Star Citizen installation directory (case sensitive)\n"
echo -e "ie. /home/USER/.wine/drive_c/Program Files/Roberts Space Industries/StarCitizen/" printf "ie. /home/USER/.wine/drive_c/Program Files/Roberts Space Industries/StarCitizen/\n"
while read -rp ": " game_path; do while read -rp ": " game_path; do
if [ ! -d "$game_path" ]; then if [ ! -d "$game_path" ]; then
echo -e "That directory is invalid or does not exist. Please try again.\n" printf "That directory is invalid or does not exist. Please try again.\n\n"
elif [ "$(basename "$game_path")" != "StarCitizen" ]; then elif [ "$(basename "$game_path")" != "StarCitizen" ]; then
echo -e "You must enter the full path to the directory named 'StarCitizen'\n" printf "You must enter the full path to the directory named 'StarCitizen'\n\n"
else else
break break
fi fi
@ -453,13 +453,13 @@ getdirs() {
# Get the backup directory # Get the backup directory
if [ -z "$backup_path" ]; then if [ -z "$backup_path" ]; then
echo -e "\nEnter the full path to a backup directory for your keybinds (case sensitive)" printf "\nEnter the full path to a backup directory for your keybinds (case sensitive)\n"
echo -e "ie. /home/USER/backups/" printf "ie. /home/USER/backups/\n"
while read -rp ": " backup_path; do while read -rp ": " backup_path; do
if [ ! -d "$backup_path" ]; then if [ ! -d "$backup_path" ]; then
echo -e "That directory is invalid or does not exist. Please try again.\n" printf "That directory is invalid or does not exist. Please try again.\n\n"
elif [[ $backup_path == $game_path* ]]; then elif [[ $backup_path == $game_path* ]]; then
echo -e "Please select a backup location outside your Star Citizen directory.\nie. /home/USER/backups/\n" printf "Please select a backup location outside your Star Citizen directory.\nie. /home/USER/backups/\n\n"
else else
break break
fi fi