mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-16 21:45:03 +02:00
Look for config file in stabdard location on startup
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
import re
|
import re
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
from PyQt5.QtGui import QFont, QFontInfo
|
||||||
|
|
||||||
key_pat = re.compile(r'([a-zA-Z][a-zA-Z0-9_-]*)\s+(.+)$')
|
key_pat = re.compile(r'([a-zA-Z][a-zA-Z0-9_-]*)\s+(.+)$')
|
||||||
|
|
||||||
defaults = {}
|
defaults = {}
|
||||||
@@ -15,6 +17,8 @@ foreground #dddddd
|
|||||||
foreground_bold #ffffff
|
foreground_bold #ffffff
|
||||||
cursor #dddddd
|
cursor #dddddd
|
||||||
background #000000
|
background #000000
|
||||||
|
font_family monospace
|
||||||
|
font_size system
|
||||||
|
|
||||||
# black
|
# black
|
||||||
color0 #000000
|
color0 #000000
|
||||||
@@ -63,7 +67,11 @@ def load_config(path):
|
|||||||
if not path:
|
if not path:
|
||||||
return defaults
|
return defaults
|
||||||
ans = defaults._asdict()
|
ans = defaults._asdict()
|
||||||
with open(path) as f:
|
try:
|
||||||
|
f = open(path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return defaults
|
||||||
|
with f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line or line.startswith('#'):
|
if not line or line.startswith('#'):
|
||||||
@@ -74,3 +82,8 @@ def load_config(path):
|
|||||||
if key in ans:
|
if key in ans:
|
||||||
ans[key] = val
|
ans[key] = val
|
||||||
return Options(**ans)
|
return Options(**ans)
|
||||||
|
|
||||||
|
|
||||||
|
def validate_font(opts):
|
||||||
|
if not QFontInfo(QFont(opts.font_family)).fixedPitch():
|
||||||
|
raise ValueError('The font specified in the configuration "{}" is not a monospace font'.format(opts.font_family))
|
||||||
|
|||||||
@@ -2,6 +2,28 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import os
|
||||||
|
from PyQt5.QtCore import QStandardPaths
|
||||||
|
|
||||||
appname = 'kitty'
|
appname = 'kitty'
|
||||||
version = (0, 1, 0)
|
version = (0, 1, 0)
|
||||||
str_version = '.'.join(map(str, version))
|
str_version = '.'.join(map(str, version))
|
||||||
|
|
||||||
|
|
||||||
|
def _get_config_dir():
|
||||||
|
# This must be called before calling setApplicationName
|
||||||
|
if 'KITTY_CONFIG_DIRECTORY' in os.environ:
|
||||||
|
return os.path.abspath(os.path.expanduser(os.environ['VISE_CONFIG_DIRECTORY']))
|
||||||
|
|
||||||
|
candidate = QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
|
||||||
|
if not candidate:
|
||||||
|
raise RuntimeError(
|
||||||
|
'Failed to find path for application config directory')
|
||||||
|
ans = os.path.join(candidate, appname)
|
||||||
|
try:
|
||||||
|
os.makedirs(ans)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
return ans
|
||||||
|
config_dir = _get_config_dir()
|
||||||
|
del _get_config_dir
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from PyQt5.QtCore import Qt, QSocketNotifier
|
|||||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
|
||||||
|
|
||||||
from .config import load_config, validate_font
|
from .config import load_config, validate_font
|
||||||
from .constants import appname, str_version
|
from .constants import appname, str_version, config_dir
|
||||||
from .term import TerminalWidget
|
from .term import TerminalWidget
|
||||||
|
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ def option_parser():
|
|||||||
a = parser.add_argument
|
a = parser.add_argument
|
||||||
a('--name', default=appname, help=_('Set the name part of the WM_CLASS property'))
|
a('--name', default=appname, help=_('Set the name part of the WM_CLASS property'))
|
||||||
a('--class', default=appname, dest='cls', help=_('Set the class part of the WM_CLASS property'))
|
a('--class', default=appname, dest='cls', help=_('Set the class part of the WM_CLASS property'))
|
||||||
a('--config', default=None, help=_('Specify a path to the config file to use'))
|
a('--config', default=os.path.join(config_dir, 'kitty.conf'), help=_('Specify a path to the config file to use'))
|
||||||
a('--cmd', '-c', default=None, help=_('Run python code in the kitty context'))
|
a('--cmd', '-c', default=None, help=_('Run python code in the kitty context'))
|
||||||
a('-d', '--directory', default='.', help=_('Change to the specified directory when launching'))
|
a('-d', '--directory', default='.', help=_('Change to the specified directory when launching'))
|
||||||
a('--version', action='version', version='{} {} by Kovid Goyal'.format(appname, '.'.join(str_version)))
|
a('--version', action='version', version='{} {} by Kovid Goyal'.format(appname, '.'.join(str_version)))
|
||||||
|
|||||||
Reference in New Issue
Block a user