Move expandvars to utils
This commit is contained in:
parent
e74797037c
commit
a0d6445dda
@ -9,8 +9,8 @@ import sys
|
||||
from contextlib import contextmanager, suppress
|
||||
from functools import partial
|
||||
from typing import (
|
||||
Any, Callable, Dict, Generator, Iterable, List, Match, NamedTuple,
|
||||
Optional, Sequence, Set, Tuple, Type, Union
|
||||
Any, Callable, Dict, Generator, Iterable, List, NamedTuple, Optional,
|
||||
Sequence, Set, Tuple, Type, Union
|
||||
)
|
||||
|
||||
from . import fast_data_types as defines
|
||||
@ -24,7 +24,7 @@ from .constants import cache_dir, defconf, is_macos
|
||||
from .key_names import get_key_name_lookup, key_name_aliases
|
||||
from .options_stub import Options as OptionsStub
|
||||
from .typing import EdgeLiteral, TypedDict
|
||||
from .utils import log_error
|
||||
from .utils import expandvars, log_error
|
||||
|
||||
KeySpec = Tuple[int, bool, int]
|
||||
KeyMap = Dict[KeySpec, 'KeyAction']
|
||||
@ -585,20 +585,6 @@ def handle_deprecated_macos_show_window_title_in_menubar_alias(key: str, val: st
|
||||
ans['macos_show_window_title_in'] = macos_show_window_title_in
|
||||
|
||||
|
||||
def expandvars(val: str, env: Dict[str, str] = {}) -> str:
|
||||
|
||||
def sub(m: Match) -> str:
|
||||
key = m.group(1)
|
||||
result = env.get(key)
|
||||
if result is None:
|
||||
result = os.environ.get(key)
|
||||
if result is None:
|
||||
result = m.group()
|
||||
return result
|
||||
|
||||
return re.sub(r'\$\{(\S+?)\}', sub, val)
|
||||
|
||||
|
||||
@special_handler
|
||||
def handle_env(key: str, val: str, ans: Dict[str, Any]) -> None:
|
||||
key, val = val.partition('=')[::2]
|
||||
|
||||
@ -7,7 +7,7 @@ import os
|
||||
import shutil
|
||||
import sys
|
||||
from contextlib import contextmanager, suppress
|
||||
from typing import Generator, List, Mapping, Optional, Tuple, Sequence
|
||||
from typing import Generator, List, Mapping, Optional, Sequence, Tuple
|
||||
|
||||
from .borders import load_borders_program
|
||||
from .boss import Boss
|
||||
@ -15,7 +15,7 @@ from .child import set_default_env
|
||||
from .cli import create_opts, parse_args
|
||||
from .cli_stub import CLIOptions
|
||||
from .conf.utils import BadLine
|
||||
from .config import cached_values_for, initial_window_size_func, expandvars
|
||||
from .config import cached_values_for, initial_window_size_func
|
||||
from .constants import (
|
||||
appname, beam_cursor_data_file, config_dir, glfw_path, is_macos,
|
||||
is_wayland, kitty_exe, logo_data_file, running_in_kitty
|
||||
@ -29,7 +29,7 @@ from .fonts.box_drawing import set_scale
|
||||
from .fonts.render import set_font_family
|
||||
from .options_stub import Options as OptionsStub
|
||||
from .utils import (
|
||||
detach, log_error, read_shell_environment, single_instance,
|
||||
detach, expandvars, log_error, read_shell_environment, single_instance,
|
||||
startup_notification_handler, unix_socket_paths
|
||||
)
|
||||
from .window import load_shader_programs
|
||||
|
||||
@ -14,8 +14,8 @@ from contextlib import suppress
|
||||
from functools import lru_cache
|
||||
from time import monotonic
|
||||
from typing import (
|
||||
Any, Callable, Dict, Generator, Iterable, List, NamedTuple, Optional,
|
||||
Tuple, Union, cast
|
||||
Any, Callable, Dict, Generator, Iterable, List, Match, NamedTuple,
|
||||
Optional, Tuple, Union, cast
|
||||
)
|
||||
|
||||
from .constants import (
|
||||
@ -28,6 +28,20 @@ from .typing import AddressFamily, PopenType, Socket, StartupCtx
|
||||
BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def expandvars(val: str, env: Dict[str, str] = {}) -> str:
|
||||
|
||||
def sub(m: Match) -> str:
|
||||
key = m.group(1)
|
||||
result = env.get(key)
|
||||
if result is None:
|
||||
result = os.environ.get(key)
|
||||
if result is None:
|
||||
result = m.group()
|
||||
return result
|
||||
|
||||
return re.sub(r'\$\{(\S+?)\}', sub, val)
|
||||
|
||||
|
||||
def load_shaders(name: str) -> Tuple[str, str]:
|
||||
from .fast_data_types import GLSL_VERSION
|
||||
with open(os.path.join(BASE, '{}_vertex.glsl'.format(name))) as f:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user