Files
I38/scripts/i38-help-personal.sh

66 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# This file is part of I38.
# I38 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
# I38 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with I38. If not, see <https://www.gnu.org/licenses/>.
configPath="$(readlink -f "$0")"
configPath="${configPath%/*/*}"
customizationsPath="${configPath}/customizations"
if [[ -f "${configPath}/config" ]]; then
mod="$(grep "set \$mod " "${configPath}/config" | cut -d ' ' -f3)"
mod="${mod//Mod1/Alt}"
mod="${mod//Mod4/Super}"
else
exit 1
fi
if [[ ! -f "$customizationsPath" ]] || ! grep -q '^mode "personal"' "$customizationsPath"; then
message="Personal mode bindings were not found. Check ${customizationsPath}."
echo -e "$message" | yad --text-info --show-cursor --title "I38 - Personal Mode Help" --button "Close:0" --listen
exit 0
fi
personalModeKey="$(grep -m1 -E '^bindsym[[:space:]]+.*mode "personal"' "$customizationsPath" | \
sed -e 's/^bindsym[[:space:]]*//' -e 's/[[:space:]]*mode "personal".*$//')"
if [[ -n "$personalModeKey" ]]; then
personalModeKey="${personalModeKey//\$mod/$mod}"
personalModeKey="${personalModeKey//Mod1/Alt}"
personalModeKey="${personalModeKey//Mod4/Super}"
fi
mapfile helpText < <(sed -n '/^mode "personal"/,/^}$/p' "$customizationsPath" | \
sed -e '/^mode "personal"/d' \
-e '/^}$/d' \
-e 's/bindsym/Key:/g' \
-e 's/Mod1/Alt/g' \
-e 's/, mode "default"//g' \
-e 's/--no-startup-id //g' \
-e "s/\$mod/$mod/g")
for i in "${!helpText[@]}" ; do
helpText[i]="${helpText[i]//${configPath}\/scripts\//}"
helpText[i]="${helpText[i]/.sh/}"
helpText[i]="${helpText[i]/.py/}"
done
header="Personal Mode Keybindings\n\n"
if [[ -n "$personalModeKey" ]]; then
header+="Press ${personalModeKey} to enter personal mode, then use these shortcuts:\n\n"
else
header+="Use these shortcuts while in personal mode:\n\n"
fi
helpText=("$header" "${helpText[@]}" "End of personal mode help. Press Control+Home to jump to the beginning.")
echo -e "${helpText[@]}" | yad --text-info --show-cursor --title "I38 - Personal Mode Help" --button "Close:0" --listen
exit 0