Skip to content

Instantly share code, notes, and snippets.

@tatesuke
Last active February 21, 2020 04:16
Show Gist options
  • Save tatesuke/c02922d24ae69047303683aa18b983e6 to your computer and use it in GitHub Desktop.
Save tatesuke/c02922d24ae69047303683aa18b983e6 to your computer and use it in GitHub Desktop.
ScoopでインストールしたSakuraエディタを右クリックメニューに加えるレジストリ登録ファイルを生成する。
# coding=utf-8
import logging
import sys
import subprocess
import os
import textwrap
logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger(__name__)
def main():
sakuraPath = createSakuraPath()
installText = textwrap.dedent('''
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\*\shell\OpenWithSakura]
@="Open with &Sakura"
"Icon"="{sakuraPath}"
[HKEY_CURRENT_USER\Software\Classes\*\shell\OpenWithSakura\command]
@="\\"{sakuraPath}\\" \\"%1\\""
''').format(sakuraPath=sakuraPath.replace("\\", "\\\\")).strip()
with open("install.reg", "w", encoding="shift-jis") as f:
f.write(installText)
uninstallText = textwrap.dedent('''
Windows Registry Editor Version 5.00
[-HKEY_CURRENT_USER\Software\Classes\*\shell\OpenWithSakura]
[-HKEY_CURRENT_USER\Software\Classes\*\shell\OpenWithSakura\command]
''').strip()
with open("uninstall.reg", "w", encoding="shift-jis") as f:
f.write(uninstallText)
def createSakuraPath():
# サクラエディタのパス取得
try:
which = subprocess.check_output(["scoop", "which", "sakura"], shell=True)
which = which.decode("utf-8").strip()
except subprocess.CalledProcessError as e:
if e.returncode == 1:
LOGGER.error("Error. `scoop` command not found. Prease install `scoop`.")
elif e.returncode == 3:
LOGGER.error("Error. `sakura` not found. Prease install `sakura-editor`.")
sys.exit(1)
# ~置換
homeDrive = os.environ.get("HOMEDRIVE")
homePath = os.environ.get("HOMEPATH")
sakuraPath = "{}{}".format(homeDrive, which.replace("~", homePath))
LOGGER.debug(sakuraPath)
return sakuraPath
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment