Add generic font install function for pretty-code
This commit is contained in:
parent
8ee2e327a0
commit
41140787a1
2 changed files with 43 additions and 26 deletions
|
@ -1,6 +1,5 @@
|
||||||
;;; ui/pretty-code/autoload/iosevka.el -*- lexical-binding: t; -*-
|
;;; ui/pretty-code/autoload/iosevka.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defvar +pretty-code--iosevka-font-names
|
(defvar +pretty-code--iosevka-font-names
|
||||||
'(
|
'(
|
||||||
"iosevka-custom-lightoblique.ttf"
|
"iosevka-custom-lightoblique.ttf"
|
||||||
|
@ -26,29 +25,12 @@
|
||||||
"iosevka-custom-regular.ttf"))
|
"iosevka-custom-regular.ttf"))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +pretty-code/install-iosevka-font (&optional pfx)
|
(defun +pretty-code/install-iosevka-font (&optional prefix)
|
||||||
"Helper function to download and install Iosevka font based on OS.
|
"Download and install Iosevka font based on OS.
|
||||||
When PFX is non-nil, ignore the prompt and just install"
|
When prefix is non-nil, ignore the prompt and just install."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(when (or pfx (yes-or-no-p "This will download and install the Iosevka fonts, are you sure you want to do this?"))
|
(+pretty-code--install-font
|
||||||
(let* ((url-format "https://github.com/jsravn/iosevka-emacs/raw/master/%s")
|
prefix
|
||||||
(font-dest (cl-case window-system
|
"Iosevka"
|
||||||
(x (concat (or (getenv "XDG_DATA_HOME") ;; Default Linux install directories
|
"https://github.com/jsravn/iosevka-emacs/raw/master/%s"
|
||||||
(concat (getenv "HOME") "/.local/share"))
|
+pretty-code--iosevka-font-names))
|
||||||
"/fonts/"))
|
|
||||||
(mac (concat (getenv "HOME") "/Library/Fonts/" ))
|
|
||||||
(ns (concat (getenv "HOME") "/Library/Fonts/" )))) ;; Default MacOS install directory
|
|
||||||
(known-dest? (stringp font-dest))
|
|
||||||
(font-dest (or font-dest (read-directory-name "Font installation directory: " "~/"))))
|
|
||||||
|
|
||||||
(unless (file-directory-p font-dest) (mkdir font-dest t))
|
|
||||||
|
|
||||||
(dolist (font +pretty-code--iosevka-font-names)
|
|
||||||
(url-copy-file (format url-format font) (expand-file-name font font-dest) t))
|
|
||||||
|
|
||||||
(when known-dest?
|
|
||||||
(message "Font downloaded, updating font cache... <fc-cache -f -v> ")
|
|
||||||
(shell-command-to-string (format "fc-cache -f -v")))
|
|
||||||
(message "Successfully %s `Iosevka' fonts to `%s'!"
|
|
||||||
(if known-dest? "installed" "downloaded")
|
|
||||||
font-dest))))
|
|
||||||
|
|
|
@ -95,3 +95,38 @@ Otherwise it builds `prettify-code-symbols-alist' according to
|
||||||
(load! "+hasklig"))
|
(load! "+hasklig"))
|
||||||
((featurep! +pragmata-pro)
|
((featurep! +pragmata-pro)
|
||||||
(load! "+pragmata-pro")))
|
(load! "+pragmata-pro")))
|
||||||
|
|
||||||
|
(defun +pretty-code--install-font (prefix name url-format fonts-alist)
|
||||||
|
"Install fonts to the local system.
|
||||||
|
|
||||||
|
If PREFIX is nil, will prompt whether or not to download. NAME is informational only.
|
||||||
|
URL-FORMAT is a format string that should be a url and have a single %s, which is expanded
|
||||||
|
for each font in FONTS-ALIST. FONTS-ALIST should be the filename of each font. It is used
|
||||||
|
as the source and destination filename.
|
||||||
|
"
|
||||||
|
(when (or prefix (yes-or-no-p
|
||||||
|
(format "This will download and install the %s fonts, are you sure you want to do this?" name)))
|
||||||
|
(let* ((font-dest (cl-case window-system
|
||||||
|
;; Linux
|
||||||
|
(x (concat (or (getenv "XDG_DATA_HOME")
|
||||||
|
(concat (getenv "HOME") "/.local/share"))
|
||||||
|
"/fonts/"))
|
||||||
|
;; MacOS
|
||||||
|
(mac (concat (getenv "HOME") "/Library/Fonts/" ))
|
||||||
|
(ns (concat (getenv "HOME") "/Library/Fonts/" ))))
|
||||||
|
(known-dest? (stringp font-dest))
|
||||||
|
(font-dest (or font-dest (read-directory-name "Font installation directory: " "~/"))))
|
||||||
|
|
||||||
|
(unless (file-directory-p font-dest) (mkdir font-dest t))
|
||||||
|
|
||||||
|
(dolist (font fonts-alist)
|
||||||
|
(url-copy-file (format url-format font) (expand-file-name font font-dest) t))
|
||||||
|
|
||||||
|
(when known-dest?
|
||||||
|
(message "Font downloaded, updating font cache... <fc-cache -f -v> ")
|
||||||
|
(shell-command-to-string (format "fc-cache -f -v")))
|
||||||
|
(message "Successfully %s `%s' fonts to `%s'!"
|
||||||
|
(if known-dest? "installed" "downloaded")
|
||||||
|
name
|
||||||
|
font-dest)))
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue