Skip to content

Instantly share code, notes, and snippets.

@dakyskye
Created April 12, 2022 17:15
Show Gist options
  • Save dakyskye/65a5505aae5afb08db5880b7c045cacd to your computer and use it in GitHub Desktop.
Save dakyskye/65a5505aae5afb08db5880b7c045cacd to your computer and use it in GitHub Desktop.
rename nvim_ostheme.py to nvim_ostheme, put it in /usr/local/bin and update your .zshrc aliases
alias vim="/usr/local/bin/nvim_ostheme; nvim"
alias nvim="/usr/local/bin/nvim_ostheme; nvim"
#!/usr/bin/python3
import subprocess
import os
import re
if __name__ == '__main__':
cmd = 'defaults read -g AppleInterfaceStyle'
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
theme = 'dark' if bool(proc.communicate()[0]) else 'light'
with open(f"{os.environ['HOME']}/.config/nvim/plugins.vim", "r+") as f:
content = f.read()
content = re.sub('set background=(light|dark)', f'set background={theme}', content)
f.seek(0)
f.truncate()
i = f.write(content)
if i != len(content):
print("it seems we didn't manage to fully write the vim config...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment