WhiteSur-gtk-theme/tweaks.sh

372 lines
18 KiB
Bash
Raw Permalink Normal View History

2021-05-23 20:04:01 +07:00
#! /usr/bin/env bash
2021-04-08 07:09:27 +07:00
# WARNING: Please make this shell not working-directory dependant, for example
2021-06-03 06:43:49 +07:00
# instead of using 'ls blabla', use 'ls "${REPO_DIR}/blabla"'
2021-04-08 07:09:27 +07:00
#
# WARNING: Don't use "cd" in this shell, use it in a subshell instead,
# for example ( cd blabla && do_blabla ) or $( cd .. && do_blabla )
2021-06-11 18:59:07 +07:00
#
# SUGGESTION: Please don't put any dependency installation here
2021-04-08 07:09:27 +07:00
###############################################################################
# VARIABLES & HELP #
###############################################################################
readonly REPO_DIR="$(dirname "$(readlink -m "${0}")")"
2024-10-30 19:59:27 +08:00
source "${REPO_DIR}/libs/lib-install.sh"
2021-04-08 07:09:27 +07:00
2021-08-21 22:39:24 +08:00
# Customization, default values
colors=("${COLOR_VARIANTS[@]}")
opacities=("${OPACITY_VARIANTS[@]}")
2024-09-18 12:18:23 +08:00
# Firefox values
adaptive=''
theme_name="$THEME_NAME"
firefoxtheme="$THEME_NAME"
left_button="3"
right_button="3"
2021-04-08 07:09:27 +07:00
usage() {
# Please specify their default value manually, some of them are come from _variables.scss
# You also have to check and update them regurally
helpify_title
2024-10-13 16:39:26 +08:00
helpify "-o, --opacity" "[$(IFS='|'; echo "${OPACITY_VARIANTS[*]}")]" " Set '${THEME_NAME}' GDM/Flatpak theme opacity variants" "Default is 'normal'"
helpify "-c, --color" "[$(IFS='|'; echo "${COMMAND_COLOR_VARIANTS[*]}")]" " Set '${THEME_NAME}' GDM/Flatpak theme color variants" "Default is 'light'"
helpify "-t, --theme" "[$(IFS='|'; echo "${THEME_VARIANTS[*]}")]" " Set '${THEME_NAME}' GDM/Flatpak theme accent color" "Default is BigSur-like theme"
2024-10-16 15:12:23 +08:00
helpify "-s, --scheme" "[$(IFS='|'; echo "${SCHEME_VARIANTS[*]}")]" " Set '${THEME_NAME}' GDM/Flatpak theme colorscheme style" "Default is 'standard'"
2024-08-31 16:58:31 +08:00
2024-10-13 16:39:26 +08:00
helpify "" "" "Tweaks for GDM theme" "options"
sec_title "-g, --gdm" "" " Without options default GDM theme will install..." ""
sec_helpify "1. -i, -icon" "[$(IFS='|'; echo "${ICON_VARIANTS[*]}")]" " Set GDM panel 'Activities' icon" "Default is 'standard'"
sec_helpify "2. -b, -background" "[default|blank|IMAGE_PATH]" " Set GDM background image" "Default is BigSur-like wallpaper"
sec_helpify "3. -p, -panelopacity" "[$(IFS='|'; echo "${PANEL_OPACITY_VARIANTS[*]}")]" " Set GDM panel transparency" "Default is 15%"
sec_helpify "4. -h, -panelheight" "[$(IFS='|'; echo "${PANEL_SIZE_VARIANTS[*]}")]" " Set GDM panel height size" "Default is 32px"
2024-10-16 15:12:23 +08:00
sec_helpify "5. -sf, -smallerfont" "" " Set GDM font size to smaller (10pt)" "Default is 11pt"
2024-10-13 16:39:26 +08:00
sec_helpify "6. -nd, -nodarken" "" " Don't darken '${THEME_NAME}' GDM theme background image" ""
sec_helpify "7. -nb, -noblur" "" " Don't blur '${THEME_NAME}' GDM theme background image" ""
helpify "" "" "Tweaks for firefox" "options"
2024-09-30 21:59:46 +01:00
sec_title "-f, --firefox" " [(monterey|flat)|alt|(darker|adaptive)]" " Without options default WhiteSur theme will install..." " Options:"
2024-09-18 12:18:23 +08:00
sec_helpify "1. monterey" " [3+3|3+4|3+5|4+3|4+4|4+5|5+3|5+4|5+5]" " Topbar buttons number: 'a+b'" " a: left side buttons number, b: right side buttons number"
sec_helpify "2. flat" " Monterey alt version" "" " Flat round tabs..."
2024-09-30 17:51:00 -07:00
sec_helpify "3. alt" " Alt windows button version" "" " Alt windows button style like gtk theme"
2024-09-30 21:59:46 +01:00
sec_helpify "4. darker" " Darker Firefox theme version" "" " Darker Firefox theme version"
2024-12-02 21:54:38 +08:00
sec_helpify "5. nord" " Nord Firefox colorscheme version" "" " Nord Firefox colorscheme version"
sec_helpify "6. adaptive" " Adaptive color version" " You need install adaptive-tab-bar-colour plugin first" " https://addons.mozilla.org/firefox/addon/adaptive-tab-bar-colour/"
2024-08-31 22:32:50 +08:00
2024-09-30 21:59:46 +01:00
helpify "-e, --edit-firefox" "[(monterey|flat)|alt|(darker|adaptive)]" " Edit '${THEME_NAME}' theme for Firefox settings and also connect the theme to the current Firefox profiles" ""
2024-08-31 16:58:31 +08:00
2024-10-13 16:39:26 +08:00
helpify "" "" "Others" "options"
sec_title "-F, --flatpak" "Support options: [-o, -c, -t...]" " Connect '${THEME_NAME}' theme to Flatpak" "Without options will only install default themes"
sec_helpify "1. -o, --opacity" "[$(IFS='|'; echo "${OPACITY_VARIANTS[*]}")]" " Set '${THEME_NAME}' flatpak theme opacity variants" "Default is 'normal'"
sec_helpify "2. -c, --color" "[$(IFS='|'; echo "${COLOR_VARIANTS[*]}")]" " Set '${THEME_NAME}' flatpak theme color variants" "Default is 'light'"
sec_helpify "3. -t, --theme" "[$(IFS='|'; echo "${THEME_VARIANTS[*]}")]" " Set '${THEME_NAME}' flatpak theme accent color" "Default is BigSur-like theme"
2024-10-13 20:36:04 +08:00
sec_helpify "4. -s, --scheme" "[$(IFS='|'; echo "${SCHEME_VARIANTS[*]}")]" " Set '${THEME_NAME}' flatpak theme colorscheme style" "Default is 'standard'"
2024-08-31 16:58:31 +08:00
#helpify "-s, --snap" "" " Connect '${THEME_NAME}' theme the currently installed snap apps" ""
2024-10-13 16:39:26 +08:00
2024-08-31 16:58:31 +08:00
helpify "-d, --dash-to-dock" "" " Fixed Dash to Dock theme issue" ""
helpify "-r, --remove, --revert" "" " Revert to the original themes, do the opposite things of install and connect" ""
helpify "--silent-mode" "" " Meant for developers: ignore any confirm prompt and params become more strict" ""
helpify "-h, --help" "" " Show this help" ""
2021-04-08 07:09:27 +07:00
}
2024-09-03 11:49:14 +08:00
gdm_info() {
if [[ "${gdm}" == "false" ]]; then
prompt -e "Oops... there's nothing to tweak. this option '${1}' only works for GDM theme! ..."
prompt -i "HINT: Run ./tweaks.sh -h for help!... \n"
fi
}
2021-04-08 07:09:27 +07:00
###############################################################################
# MAIN #
###############################################################################
#-----------------------------PARSE ARGUMENTS---------------------------------#
2021-06-13 21:47:00 +07:00
echo
2021-04-08 07:09:27 +07:00
while [[ $# -gt 0 ]]; do
# Don't show any dialog here. Let this loop checks for errors or shows help
# We can only show dialogs when there's no error and no -r parameter
#
# * shift for parameters that have no value
# * shift 2 for parameter that have a value
#
# Please don't exit any error here if possible. Let it show all error warnings
# at once
case "${1}" in
2021-06-02 23:04:59 +07:00
# Parameters that don't require value
2021-04-08 07:09:27 +07:00
-r|--remove|--revert)
uninstall='true'; shift ;;
2021-06-15 20:15:34 +07:00
--silent-mode)
full_sudo "${1}"; silent_mode='true'; shift ;;
2021-04-08 07:09:27 +07:00
-h|--help)
need_help="true"; shift ;;
2021-07-04 23:14:42 +08:00
-f|--firefox|-e|--edit-firefox)
2021-04-08 07:09:27 +07:00
case "${1}" in
-f|--firefox)
firefox="true" ;;
-e|--edit-firefox)
edit_firefox="true" ;;
esac
2021-07-04 23:14:42 +08:00
for variant in "${@}"; do
case "${variant}" in
default)
2024-08-31 16:58:31 +08:00
firefoxtheme="WhiteSur"
2024-08-31 22:32:50 +08:00
shift ;;
2021-07-04 23:14:42 +08:00
monterey)
2024-08-31 16:58:31 +08:00
firefoxtheme="Monterey"
theme_name="Monterey"
2024-08-31 22:32:50 +08:00
shift
for button in "${@}"; do
case "${button}" in
3+3)
left_button="3"
right_button="3"
shift ;;
3+4)
left_button="3"
right_button="4"
shift ;;
3+5)
left_button="3"
right_button="5"
shift ;;
4+3)
left_button="4"
right_button="3"
shift ;;
4+4)
left_button="4"
right_button="4"
shift ;;
4+5)
left_button="4"
right_button="5"
2024-10-13 16:39:26 +08:00
shift ;;
2024-08-31 22:32:50 +08:00
5+3)
left_button="5"
right_button="3"
shift ;;
5+4)
left_button="5"
right_button="4"
2024-10-13 16:39:26 +08:00
shift ;;
2024-08-31 22:32:50 +08:00
5+5)
left_button="5"
right_button="5"
shift ;;
esac
done
prompt -s "Left side topbar button number: $left_button, right side topbar button number: $right_button.\n" ;;
2024-09-18 12:18:23 +08:00
flat)
firefoxtheme="Flat"
2024-08-31 16:58:31 +08:00
theme_name="Monterey"
2024-08-31 22:32:50 +08:00
shift ;;
2024-09-18 12:18:23 +08:00
alt)
window="alt"
2024-09-24 19:55:23 +01:00
prompt -i "Alt windows button version...\n"
2024-09-18 12:18:23 +08:00
shift ;;
darker)
darker="-darker"
prompt -i "Darker Firefox theme version...\n"
shift ;;
2024-12-02 21:54:38 +08:00
nord)
colorscheme="-nord"
prompt -i "Nord Firefox colorscheme version...\n"
shift ;;
2024-08-31 16:58:31 +08:00
adaptive)
2024-09-18 12:18:23 +08:00
adaptive="-adaptive"
2024-08-31 20:34:02 +08:00
prompt -i "Firefox adaptive color version...\n"
prompt -w "You need install adaptive-tab-bar-colour plugin first: https://addons.mozilla.org/firefox/addon/adaptive-tab-bar-colour/\n"
2024-08-31 22:32:50 +08:00
shift ;;
2021-07-04 23:14:42 +08:00
esac
done
if ! has_command firefox && ! has_command firefox-bin && ! has_flatpak_app org.mozilla.firefox && ! has_snap_app firefox && ! has_command firefox-developer-edition; then
2021-04-08 07:09:27 +07:00
prompt -e "'${1}' ERROR: There's no Firefox installed in your system"
has_any_error="true"
elif [[ ! -d "${FIREFOX_DIR_HOME}" && ! -d "${FIREFOX_FLATPAK_DIR_HOME}" && ! -d "${FIREFOX_SNAP_DIR_HOME}" ]]; then
2021-04-08 07:09:27 +07:00
prompt -e "'${1}' ERROR: Firefox is installed but not yet initialized."
prompt -w "'${1}': Don't forget to close it after you run/initialize it"
has_any_error="true"
elif pidof "firefox" &> /dev/null || pidof "firefox-bin" &> /dev/null; then
2021-04-08 07:09:27 +07:00
prompt -e "'${1}' ERROR: Firefox is running, please close it"
has_any_error="true"
fi; shift ;;
2024-10-13 16:39:26 +08:00
-g|--gdm)
gdm="true"; full_sudo "${1}"
showapps_normal="true" # use normal showapps icon
background="default"
2024-10-15 16:30:39 +08:00
shift
2024-10-13 16:39:26 +08:00
for variant in "${@}"; do
case "${variant}" in
-i|-icon)
activities_icon="true";
check_param "${1}" "${1}" "${2}" "must" "must" "must" && shift 2 || shift ;;
-b|-background)
check_param "${1}" "${1}" "${2}" "must" "must" "must" "false" && shift 2 || shift ;;
-p|-panelopacity)
check_param "${1}" "${1}" "${2}" "optional" "optional" "optional" && shift 2 || shift ;;
-h|-panelheight)
check_param "${1}" "${1}" "${2}" "optional" "optional" "optional" && shift 2 || shift ;;
2024-10-16 15:12:23 +08:00
-nd|-nodarken)
2024-10-13 16:39:26 +08:00
gdm_info ${1}
no_darken="true"; shift ;;
2024-10-16 15:12:23 +08:00
-nb|-noblur)
2024-10-13 16:39:26 +08:00
gdm_info ${1}
no_blur="true"; shift ;;
2024-10-16 15:12:23 +08:00
-sf|-smallerfont)
smaller_font="true"; shift ;;
2024-10-13 16:39:26 +08:00
esac
done
if ! has_command gdm && ! has_command gdm3 && [[ ! -e /usr/sbin/gdm3 ]]; then
prompt -e "'${1}' ERROR: There's no GDM installed in your system"
has_any_error="true"
2024-10-15 16:30:39 +08:00
fi ;;
2021-04-08 07:09:27 +07:00
-F|--flatpak)
2021-08-21 22:39:24 +08:00
flatpak="true"; signal_exit
2021-04-08 07:09:27 +07:00
if ! has_command flatpak; then
2021-04-08 07:09:27 +07:00
prompt -e "'${1}' ERROR: There's no Flatpak installed in your system"
has_any_error="true"
fi; shift ;;
2022-12-07 22:06:48 +08:00
# -s|--snap)
# snap="true";
2021-04-08 07:09:27 +07:00
2022-12-07 22:06:48 +08:00
# if ! has_command snap; then
# prompt -e "'${1}' ERROR: There's no Snap installed in your system"
# has_any_error="true"
# fi; shift ;;
2021-04-08 07:09:27 +07:00
-d|--dash-to-dock)
2021-08-27 13:24:32 +08:00
if [[ ! -d "${DASH_TO_DOCK_DIR_HOME}" && ! -d "${DASH_TO_DOCK_DIR_ROOT}" ]]; then
prompt -e "'${1}' ERROR: There's no Dash to Dock installed in your system"
2021-05-14 18:31:26 +08:00
has_any_error="true"
else
dash_to_dock="true"
2021-04-08 07:09:27 +07:00
fi; shift ;;
-o|--opacity)
2024-08-27 12:30:03 +08:00
check_param "${1}" "${1}" "${2}" "not-at-all" "must" "must" && shift 2 || shift ;;
2021-04-08 07:09:27 +07:00
-c|--color)
2024-08-27 12:30:03 +08:00
check_param "${1}" "${1}" "${2}" "not-at-all" "must" "must" && shift 2 || shift ;;
2021-04-08 07:09:27 +07:00
-t|--theme)
2024-08-27 12:30:03 +08:00
check_param "${1}" "${1}" "${2}" "not-at-all" "must" "must" && shift 2 || shift ;;
2024-10-16 15:12:23 +08:00
-s|--scheme)
check_param "${1}" "${1}" "${2}" "not-at-all" "must" "must" && shift 2 || shift ;;
2021-04-08 07:09:27 +07:00
*)
prompt -e "ERROR: Unrecognized tweak option '${1}'."
has_any_error="true"; shift ;;
esac
done
finalize_argument_parsing
#---------------------------START INSTALL THEMES-------------------------------#
if [[ "${uninstall}" == 'true' ]]; then
2021-11-04 09:55:52 +08:00
prompt -w "REMOVAL: Non file-related parameters will be ignored. \n"
2021-04-08 07:09:27 +07:00
2023-06-11 12:45:02 +08:00
if [[ "${gdm}" == 'true' ]]; then
if [[ "${firefox}" == 'true' || "${edit_firefox}" == 'true' || "${flatpak}" == 'true' || "${snap}" == 'true' || "${dash_to_dock}" == 'true' ]]; then
prompt -e "Do not run this option with '--gdm' \n"
else
prompt -i "Removing '${name}' GDM theme... \n"
revert_gdm_theme
prompt -s "Done! '${name}' GDM theme has been removed. \n"
fi
fi
# if [[ "${snap}" == 'true' && "${gdm}" != 'true' ]]; then
2022-12-07 22:06:48 +08:00
# prompt -i "Disconnecting '${name}' theme from your installed snap apps... \n"
# disconnect_snap
2023-06-11 12:45:02 +08:00
# prompt -s "Done! '${name}' theme has been disconnected from your snap apps.\n"
2022-12-07 22:06:48 +08:00
# fi
2021-08-23 16:00:41 +08:00
2023-06-11 12:45:02 +08:00
if [[ "${flatpak}" == 'true' && "${gdm}" != 'true' ]]; then
2021-08-23 16:00:41 +08:00
prompt -i "Disconnecting '${name}' theme from your Flatpak... \n"
disconnect_flatpak
2023-06-11 12:45:02 +08:00
prompt -s "Done! '${name}' theme has been disconnected from your Flatpak. \n"
2021-08-23 16:00:41 +08:00
fi
2023-06-11 12:45:02 +08:00
if [[ "${dash_to_dock}" == 'true' && "${gdm}" != 'true' ]]; then
2023-10-13 06:36:42 +08:00
prompt -i "Revert Dash to Dock theme... \n"
2021-04-08 07:09:27 +07:00
revert_dash_to_dock_theme
2023-10-13 06:36:42 +08:00
prompt -s "Done! Dash to Dock theme has reverted to default. \n"
2021-04-08 07:09:27 +07:00
fi
2023-06-11 12:45:02 +08:00
if [[ "${firefox}" == 'true' && "${gdm}" != 'true' ]]; then
2024-08-31 16:58:31 +08:00
prompt -i "Removing '${firefoxtheme}' Firefox theme... \n"
2021-04-08 07:09:27 +07:00
remove_firefox_theme
2024-08-31 16:58:31 +08:00
prompt -s "Done! '${firefoxtheme}' Firefox theme has been removed. \n"
2021-04-08 07:09:27 +07:00
fi
2021-08-23 16:00:41 +08:00
else
show_needed_dialogs; customize_theme
2021-04-08 07:09:27 +07:00
2023-06-11 12:45:02 +08:00
if [[ "${gdm}" == 'true' ]]; then
if [[ "${firefox}" == 'true' || "${edit_firefox}" == 'true' || "${flatpak}" == 'true' || "${snap}" == 'true' || "${dash_to_dock}" == 'true' ]]; then
prompt -e "Do not run this option with '--gdm' \n"
else
prompt -i "Installing '${name}' GDM theme... \n"
install_gdm_theme
prompt -s "Done! '${name}' GDM theme has been installed. \n"
fi
2021-04-08 07:09:27 +07:00
fi
2023-06-11 12:45:02 +08:00
# if [[ "${snap}" == 'true' && "${gdm}" != 'true' ]]; then
# prompt -i "Connecting '${name}' theme to your installed snap apps... \n"
# connect_snap
# prompt -s "Done! '${name}' theme has been connected to your snap apps. \n"
# fi
if [[ "${flatpak}" == 'true' && "${gdm}" != 'true' ]]; then
2021-08-27 13:24:32 +08:00
prompt -i "Connecting '${name}' themes to your Flatpak... \n"
2024-10-15 14:35:29 +08:00
prompt -w "Without options it will only install default themes\n"
2024-08-27 12:30:03 +08:00
customize_theme; avoid_variant_duplicates; connect_flatpak
2023-06-11 12:45:02 +08:00
prompt -s "Done! '${name}' theme has been connected to your Flatpak. \n"
2021-04-08 07:09:27 +07:00
fi
2023-06-11 12:45:02 +08:00
if [[ "${dash_to_dock}" == 'true' && "${gdm}" != 'true' ]]; then
2023-10-13 06:36:42 +08:00
prompt -i "Fix Dash to Dock theme issue... \n"
fix_dash_to_dock
prompt -s "Done! '${name}' Dash to Dock theme has been fixed. \n"
2021-11-04 10:17:20 +08:00
prompt -w "DASH TO DOCK: You may need to logout to take effect. \n"
2021-04-08 07:09:27 +07:00
fi
if [[ "${firefox}" == 'true' || "${edit_firefox}" == 'true' ]]; then
if [[ "${darker}" == '-darker' && "${adaptive}" == '-adaptive' ]]; then
prompt -w "FIREFOX: You can't use 'adaptive' and 'darker' at the same time. \n"
prompt -i "FIREFOX: Setting to adaptive only... \n"
darker=''
fi
2023-06-11 12:45:02 +08:00
if [[ "${firefox}" == 'true' && "${gdm}" != 'true' ]]; then
2024-08-31 16:58:31 +08:00
prompt -i "Installing '${firefoxtheme}' Firefox theme... \n"
2021-04-08 07:09:27 +07:00
install_firefox_theme
2024-08-31 16:58:31 +08:00
prompt -s "Done! '${firefoxtheme}' Firefox theme has been installed. \n"
2021-04-08 07:09:27 +07:00
fi
2023-06-11 12:45:02 +08:00
if [[ "${edit_firefox}" == 'true' && "${gdm}" != 'true' ]]; then
2024-08-31 16:58:31 +08:00
prompt -i "Editing '${firefoxtheme}' Firefox theme preferences... \n"
2021-04-08 07:09:27 +07:00
edit_firefox_theme_prefs
2024-08-31 16:58:31 +08:00
prompt -s "Done! '${firefoxtheme}' Firefox theme preferences has been edited. \n"
2021-04-08 07:09:27 +07:00
fi
2024-09-03 11:49:14 +08:00
if [[ "${gdm}" == "false" ]]; then
2024-08-31 22:32:50 +08:00
prompt -w "FIREFOX: Please go to [Firefox menu] > [Customize...], and customize your Firefox to make it work. Move your 'new tab' button to the titlebar instead of tab-switcher. \n"
2023-11-06 16:12:46 -06:00
prompt -i "FIREFOX: Anyway, you can also edit 'userChrome.css' and 'customChrome.css' later in your Firefox profile directory. \n"
2023-06-11 12:45:02 +08:00
fi
2021-04-08 07:09:27 +07:00
fi
fi
2022-12-07 22:06:48 +08:00
if [[ "${firefox}" == "false" && "${edit_firefox}" == "false" && "${flatpak}" == "false" && "${gdm}" == "false" && "${dash_to_dock}" == "false" && "${libadwaita}" == "false" ]]; then
2021-06-13 21:47:00 +07:00
prompt -e "Oops... there's nothing to tweak..."
prompt -i "HINT: Don't forget to define which component to tweak, e.g. '--gdm'"
2023-06-11 12:45:02 +08:00
prompt -i "HINT: Run ./tweaks.sh -h for help!... \n"
2021-04-08 07:09:27 +07:00
fi