mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-12 19:53:24 +02:00
Allow copying the same file to multiple locations
This commit is contained in:
@@ -5,13 +5,15 @@
|
||||
import glob
|
||||
import os
|
||||
import shlex
|
||||
import uuid
|
||||
from typing import (
|
||||
Iterable, Iterator, List, NamedTuple, Optional, Sequence, Tuple
|
||||
Dict, Iterable, Iterator, List, NamedTuple, Optional, Sequence, Tuple
|
||||
)
|
||||
|
||||
from kitty.cli import parse_args
|
||||
from kitty.cli_stub import CopyCLIOptions
|
||||
from kitty.types import run_once
|
||||
|
||||
from ..transfer.utils import expand_home, home_path
|
||||
|
||||
|
||||
@@ -81,11 +83,12 @@ def get_arcname(loc: str, dest: Optional[str], home: str) -> str:
|
||||
|
||||
|
||||
class CopyInstruction(NamedTuple):
|
||||
local_path: str
|
||||
arcname: str
|
||||
exclude_patterns: Tuple[str, ...]
|
||||
|
||||
|
||||
def parse_copy_instructions(val: str) -> Iterable[Tuple[str, CopyInstruction]]:
|
||||
def parse_copy_instructions(val: str, current_val: Dict[str, str]) -> Iterable[Tuple[str, CopyInstruction]]:
|
||||
opts, args = parse_copy_args(shlex.split(val))
|
||||
locations: List[str] = []
|
||||
for a in args:
|
||||
@@ -97,4 +100,4 @@ def parse_copy_instructions(val: str) -> Iterable[Tuple[str, CopyInstruction]]:
|
||||
home = home_path()
|
||||
for loc in locations:
|
||||
arcname = get_arcname(loc, opts.dest, home)
|
||||
yield loc, CopyInstruction(arcname, tuple(opts.exclude))
|
||||
yield str(uuid.uuid4()), CopyInstruction(loc, arcname, tuple(opts.exclude))
|
||||
|
||||
@@ -98,8 +98,8 @@ def make_tarfile(ssh_opts: SSHOptions, base_env: Dict[str, str]) -> bytes:
|
||||
buf = io.BytesIO()
|
||||
with tarfile.open(mode='w:bz2', fileobj=buf, encoding='utf-8') as tf:
|
||||
rd = ssh_opts.remote_dir.rstrip('/')
|
||||
for location, ci in ssh_opts.copy.items():
|
||||
tf.add(location, arcname=ci.arcname, filter=filter_from_globs(*ci.exclude_patterns))
|
||||
for ci in ssh_opts.copy.values():
|
||||
tf.add(ci.local_path, arcname=ci.arcname, filter=filter_from_globs(*ci.exclude_patterns))
|
||||
add_data_as_file(tf, 'data.sh', env_script)
|
||||
if ksi:
|
||||
arcname = 'home/' + rd + '/shell-integration'
|
||||
|
||||
@@ -32,7 +32,7 @@ def env(val: str, current_val: Dict[str, str]) -> Iterable[Tuple[str, str]]:
|
||||
|
||||
|
||||
def copy(val: str, current_val: Dict[str, str]) -> Iterable[Tuple[str, CopyInstruction]]:
|
||||
yield from parse_copy_instructions(val)
|
||||
yield from parse_copy_instructions(val, current_val)
|
||||
|
||||
|
||||
def init_results_dict(ans: Dict[str, Any]) -> Dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user