1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-25 21:40:08 +00:00

before installing a font, check if it already exists; try to remove if so

This commit is contained in:
romkatv 2020-02-26 14:48:15 +01:00
parent 3077929e18
commit 5567ab3850

View file

@ -374,9 +374,10 @@ function install_font() {
function ask_font() { function ask_font() {
can_install_font || return 0 can_install_font || return 0
{
while true; do while true; do
clear clear
print_greeting (( greeting_printed )) || print_greeting
flowing -c "%BInstall %b%2FMeslo Nerd Font%f%B?%b" flowing -c "%BInstall %b%2FMeslo Nerd Font%f%B?%b"
print -P "" print -P ""
print -P "" print -P ""
@ -391,12 +392,57 @@ function ask_font() {
read -k key${(%):-"?%BChoice [ynq]: %b"} || quit -c read -k key${(%):-"?%BChoice [ynq]: %b"} || quit -c
case $key in case $key in
q) quit;; q) quit;;
y) install_font; break;; y) ask_remove_font || return; install_font; break;;
n) break;; n) break;;
esac esac
done done
} always {
greeting_printed=1 greeting_printed=1
} }
}
function ask_remove_font() {
local font
local -a fonts
local -i protected
for font in {,/System,~}/Library/Fonts/**/*[Mm]eslo*.(ttf|otf)(N:A); do
[[ -f $font && -r $font ]] || continue
[[ $font == ~/Library/Fonts/'MesloLGS NF '(Regular|Bold|Italic|Bold\ Italic).ttf ]] && continue
[[ "$(<$font)" == *"MesloLGS NF"$'\0'* ]] || continue
fonts+=$font
[[ -w ${font:h} ]] || protected=1
done
(( $#fonts )) || return 0
while true; do
clear
flowing -c "A variant of %2FMeslo Nerd Font%f" is already installed.
print -P ""
for font in $fonts; do
print -P " %B${font//\%/%%}%b"
done
print -P ""
if (( protected )); then
flowing Please %Bdelete%b these files and run '%2Fp10k%f %Bconfigure%b.'
print
exit 0
fi
flowing -c "%BDelete these files?%b"
print -P ""
print -P "%B(y) Yes (recommended).%b"
print -P ""
print -P "(r) Restart from the beginning."
print -P "(q) Quit and do nothing."
print -P ""
local key=
read -k key${(%):-"?%BChoice [yrq]: %b"} || quit -c
case $key in
q) quit;;
r) return 1;;
y) zf_rm -f -- $fonts || quit -c; break;;
esac
done
}
function ask_diamond() { function ask_diamond() {
while true; do while true; do