Migrate from .stow-rename to --dotfiles

This commit is contained in:
Danielle McLean 2023-10-23 15:15:37 +11:00
parent 2cd7ee3bf7
commit f309f3a7a6
Signed by: 00dani
GPG key ID: 52C059C3B22A753E
20 changed files with 0 additions and 2 deletions

104
dot-local/bin/automasq Executable file
View file

@ -0,0 +1,104 @@
#!/usr/bin/env python3
"""OSX-based script to watch for changes to network state and write out a
second resolv.conf file containing the DHCP provided nameservers, intended
for use with a local resolver such as dnsmasq. This is to workaround the
changes in Snow Leopard from Leopard with regards to DNS resolution.
ie: the inability to have both manually configured nameservers and
DHCP provided ones as well as the issues with split-DNS.
usage: python automasq.py /path/to/second/resolv.conf
original source: https://gist.github.com/edwardgeorge/270506
"""
import optparse
import sys
from SystemConfiguration import *
GLOBAL_KEY = 'State:/Network/Global/IPv4'
class Watcher(object):
def __init__(self, filename, defaults_filename=None,
append_defaults=False):
self.filename = filename
self.defaults = defaults_filename
self.append = append_defaults
store = self.store = SCDynamicStoreCreate(None, "automasq",
self.dynamicStoreChanged, None)
SCDynamicStoreSetNotificationKeys(store, None, [GLOBAL_KEY])
source = self.source = SCDynamicStoreCreateRunLoopSource(None,
store, 0)
self.write_file(self.get_primary_dns(store))
loop = self.loop = CFRunLoopGetCurrent()
CFRunLoopAddSource(loop, source, kCFRunLoopCommonModes)
CFRunLoopRun()
def write_file(self, servers=[]):
with open(self.filename, 'w+') as f:
for server in servers:
f.write('nameserver %s\n' % server)
if (self.append or not servers) and self.defaults is not None:
with open(self.defaults) as d:
f.write(d.read())
def process_dns_for_service(self, store, service):
key = 'State:/Network/Service/%s/DNS' % service
val = SCDynamicStoreCopyValue(store, key)
data = list(dict(val)['ServerAddresses'])
return data
def get_primary_dns(self, store=None):
store = store or self.store
val = SCDynamicStoreCopyValue(store, GLOBAL_KEY)
if val:
data = dict(val)
svcid = data['PrimaryService']
return self.process_dns_for_service(store, svcid)
else:
return []
def dynamicStoreChanged(self, store, changedKeys, info):
servers = []
for key in list(changedKeys):
#if key == GLOBAL_KEY:
servers = self.get_primary_dns(store)
self.write_file(servers)
def dummy_timer(*args):
pass
def main(filename, options):
# this gives us a callback into python every 1s for signal handling
CFRunLoopAddTimer(CFRunLoopGetCurrent(),
CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), 1.0, 0, 0,
dummy_timer, None),
kCFRunLoopCommonModes)
try:
watcher = Watcher(filename, defaults_filename=options.default,
append_defaults=options.append_defaults)
except KeyboardInterrupt as e:
# exiting
pass
if __name__ == '__main__':
usage = "usage: %prog [options] output-file"
parser = optparse.OptionParser(usage)
parser.add_option('-d', '--default-conf', dest='default',
help='default conf if no resolvers provided', metavar='RESOLVCONF')
parser.add_option('-a', '--append', dest='append_defaults',
action='store_true',
help='always append defaults to generated resolv.conf')
opts, args = parser.parse_args()
if len(args) != 1:
parser.error("specify a single output-file")
if opts.append_defaults and not opts.default:
parser.error("default conf must be specified to be able to append")
main(args[0], opts)

32
dot-local/bin/cmus-mediakeys Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
import osxmmkeys
import subprocess
import time
commands = {
'play_pause': '-u',
'next_track': '-n',
'prev_track': '-r'
}
class CmusKeys():
def __init__(self):
def cmusRemote(command, flag):
def f():
print(command)
subprocess.call(['cmus-remote', flag])
return False
return f
self.tap = osxmmkeys.Tap()
for command, flag in commands.items():
self.tap.on(command, cmusRemote(command, flag))
def run(self):
self.tap.start()
try:
while True: time.sleep(1)
except (KeyboardInterrupt, SystemExit):
self.tap.stop()
if __name__ == '__main__': CmusKeys().run()

View file

@ -0,0 +1,4 @@
#!/bin/bash
while mpc idle; do
open -g swiftbar://refreshplugin?name=mpd-control
done

6
dot-local/bin/osx-env-sync Executable file
View file

@ -0,0 +1,6 @@
#!/bin/zsh
for name in ${(k)parameters}; do
[[ ${parameters[$name]} == scalar-*export* ]] || continue
print $name=${(P)name}
launchctl setenv $name "${(P)name}"
done

25
dot-local/bin/qtb Executable file
View file

@ -0,0 +1,25 @@
#!/bin/zsh
# The arguments should be a command to run in qutebrowser. If no arguments are
# provided, then :open -w is run by default.
cmd=($@)
(( $# < 1 )) && cmd=(:open -w)
# There should only be one qutebrowser socket, but just in case we only take
# the first result we find.
sockets=( ${TMPDIR}qutebrowser/ipc*(N) )
SOCKET=$sockets[1]
if [[ -w $SOCKET ]]; then
# We have a legit socket. Let's send the commands to qutebrowser. Yay!
jo target_arg=null protocol_version=1 cwd=$PWD "args[]=$cmd" | socat - UNIX-CONNECT:$SOCKET
else
# No socket. Let's start qutebrowser!
open -a qutebrowser.app
# If we were given commands to run, we still wanna run them once qutebrowser
# starts, so wait a little while and then re-exec this script.
if (( $# )); then
sleep 5
exec qtb "$@"
fi
fi

7
dot-local/bin/sign-with-own-ca Executable file
View file

@ -0,0 +1,7 @@
#!/bin/zsh
if ! [[ -r $1 ]]; then
print "Usage: $0 path/to/request.csr" >&2
exit 1
fi
ca=/etc/ssl/$HOST/root
sudo openssl x509 -req -CA $ca.crt -CAkey $ca.key -CAcreateserial -sha256 -days 30 -extensions v3_req -extfile /usr/local/etc/openssl/openssl.cnf -in $1 -out ${1:r}.crt