Sort fonts and a script to run foot (for sway) using it.
This commit is contained in:
parent
23f4721ece
commit
5dedfd1262
2 changed files with 113 additions and 0 deletions
99
fontsbyuse.py
Executable file
99
fontsbyuse.py
Executable file
|
|
@ -0,0 +1,99 @@
|
|||
#!/usr/bin/env python3
|
||||
# coding:utf-8
|
||||
"""
|
||||
Author: Sir Garbagetruck --<truck>
|
||||
Purpose: Sort fonts by use
|
||||
Created: 2020/07/24
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
def newfontlist():
|
||||
"""generate a new fontlist with all zero uses of current fonts"""
|
||||
|
||||
fonts = subprocess.Popen(
|
||||
["fc-list", ":spacing=mono"], stdout=subprocess.PIPE)
|
||||
fontscut = subprocess.Popen(
|
||||
["cut", "-d:", "-f2"], stdin=fonts.stdout, stdout=subprocess.PIPE)
|
||||
fontsort = subprocess.Popen(
|
||||
["sort"], stdin=fontscut.stdout, stdout=subprocess.PIPE)
|
||||
fontuniq = subprocess.Popen(
|
||||
["uniq"], stdin=fontsort.stdout, stdout=subprocess.PIPE)
|
||||
fonts.stdout.close()
|
||||
fontscut.stdout.close()
|
||||
fontsort.stdout.close()
|
||||
fontlist = fontuniq.communicate()[0].decode().split('\n')
|
||||
|
||||
newlist = []
|
||||
for i in fontlist:
|
||||
newlist.append([0, i.lstrip()])
|
||||
return newlist
|
||||
|
||||
|
||||
def jsonpretty(thing):
|
||||
"""prettify a thing as json to stdout"""
|
||||
return json.dumps(thing, check_circular=True, indent=4, sort_keys=True)
|
||||
|
||||
|
||||
def writelist(fontlist, outfile):
|
||||
with open(outfile, 'w+') as fh:
|
||||
fh.write(jsonpretty(fontlist))
|
||||
|
||||
|
||||
def readfile(filename):
|
||||
thefile = os.path.expanduser(filename)
|
||||
with open(thefile) as fh:
|
||||
fontlist = json.loads(fh.read())
|
||||
return fontlist
|
||||
|
||||
|
||||
def increment_font(fontlist, fontname):
|
||||
"""increment the named font by one use"""
|
||||
newlist = []
|
||||
for i in fontlist:
|
||||
if i[1] == fontname:
|
||||
newlist.append([i[0] + 1, i[1]])
|
||||
else:
|
||||
newlist.append(i)
|
||||
return newlist
|
||||
|
||||
|
||||
def main(args):
|
||||
"""open json, or create new, and spit out the sorted list."""
|
||||
if args.output is not None:
|
||||
outfile = os.path.expanduser(args.output)
|
||||
else:
|
||||
outfile = os.path.expanduser(args.filename)
|
||||
if args.renew is not None:
|
||||
print("this is not written yet")
|
||||
exit(1)
|
||||
if args.increment is not None:
|
||||
fontlist = readfile(args.filename)
|
||||
fontlist = increment_font(fontlist, args.increment)
|
||||
writelist(fontlist, outfile)
|
||||
exit(0)
|
||||
if args.new:
|
||||
fontlist = newfontlist()
|
||||
writelist(fontlist, outfile)
|
||||
else:
|
||||
fontlist = readfile(args.filename)
|
||||
sortedlist = sorted(fontlist, key=lambda font: font[0], reverse=True)
|
||||
for i in sortedlist:
|
||||
print(i[1])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument('-f', '--filename',
|
||||
help='json "use" file to load',
|
||||
default='~/.config/fonts.json')
|
||||
ap.add_argument('--new', help='create new (all zero) json file',
|
||||
action='store_true', default=False)
|
||||
ap.add_argument('--renew', help='load old json and add any new fonts')
|
||||
ap.add_argument('-o', '--output', help='write to this output json file')
|
||||
ap.add_argument('-i', '--increment', help="increment named font by 1")
|
||||
main(ap.parse_args())
|
||||
14
sortedmonofontpick.sh
Executable file
14
sortedmonofontpick.sh
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/zsh
|
||||
MENU=mybemenu
|
||||
#PICKST=$(ls ~/bin/st* | ${MENU} )
|
||||
#PICKFOOT=
|
||||
#F=$(fc-list :spacing=mono| cut -d: -f2 | sort | uniq | rofi -dmenu -i)
|
||||
F=$(python ~/bin/fontsbyuse.py | ${MENU})
|
||||
if [[ ${F} ]]; then
|
||||
S=$(seq 24 -4 8 |sed -e '1 s/^/20\n/' | ${MENU})
|
||||
C=$(ls ~/.config/foot/ | grep -v \~ | sort --sort=random | ${MENU})
|
||||
#dmenu -l 8 -fn 'Px437_ATI_SmallW_6x8 NF:style=Book:pixelsize=16:antialias=true'`
|
||||
python ~/bin/fontsbyuse.py -i "${F}"
|
||||
foot -c ~/.config/foot/${C} -f "${F}-${S},Symbola-${S},Noto Color Emoji-${S}"
|
||||
fi
|
||||
#echo foot -c ~/.config/foot/${C} -f \"${F}-${S},Symbola-${S},Noto Color Emoji-${S}\"
|
||||
Loading…
Add table
Add a link
Reference in a new issue