Skip to content

Instantly share code, notes, and snippets.

@adhamali450
Last active March 11, 2022 01:38
Show Gist options
  • Save adhamali450/a304681fe0f406eb1e20ebe1b7183f6f to your computer and use it in GitHub Desktop.
Save adhamali450/a304681fe0f406eb1e20ebe1b7183f6f to your computer and use it in GitHub Desktop.
Python script mimics (install all fonts) feature on Windows for Linux
import os
import re
from shutil import copyfile
import getpass
# Supported font formats. Feel free to customize them!
fontFormats = ('otf', 'ttf', 'eot', 'woff', 'woff2')
# Source directory where the fonts are
choice = 0
while not choice in (1,2):
os.system("clear")
choice = int(input("""[1]: Install from current directory
[2]: Specify another directory
fonts-installer: """))
sourceDir = ""
if choice == 1:
sourceDir = os.getcwd()
else:
sourceDir = input("/> ")
# Fonts are installed ONLY for the user who ran the script.
# You can change this for the fonts to be installed globally
distDir = "/home/%s/.local/share/fonts" % getpass.getuser()
dirFiles = tuple(os.listdir(sourceDir)) # All files in the directory
fontFiles = [] # Only files with a font extension
# Getting all font files in directory
for file in dirFiles:
for format in fontFormats:
font = re.search("." + format, file)
if font:
fontFiles.append(file)
# Copying each font file to distDir
for fontFile in fontFiles:
print(fontFile)
copyfile("%s/%s" % (sourceDir, fontFile),
"%s/%s" % (distDir, fontFile))
print("\n%s font/s has been installed in: %s" % (len(fontFiles), distDir))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment