From a8826f0d02be9ffa3d767f7168d7e55d98b4fb7c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 25 Feb 2022 10:30:15 +0530 Subject: [PATCH] When dropping URLs/files onto kitty at a shell prompt insert them appropriately quoted and space separated --- docs/changelog.rst | 3 +++ kitty/boss.py | 7 ++++++- kitty/window.py | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index a9dfa1ced..3cd1b9e4d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -97,6 +97,9 @@ Detailed list of changes - Fix :ac:`show_last_command_output` not working when the output is stored partially in the scrollback pager history buffer (:iss:`4435`) +- When dropping URLs/files onto kitty at a shell prompt insert them appropriately quoted and space + separated (:iss:`4734`) + - Improve CWD detection when there are multiple foreground processes in the TTY process group - A new option :opt:`narrow_symbols` to turn off opportunistic wide rendering of private use codepoints diff --git a/kitty/boss.py b/kitty/boss.py index da7f9abe7..54c054f65 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1221,7 +1221,12 @@ class Boss: if w is not None: text = data.decode('utf-8', 'replace') if mime == 'text/uri-list': - text = '\n'.join(parse_uri_list(text)) + urls = parse_uri_list(text) + if w.at_prompt: + import shlex + text = ' '.join(map(shlex.quote, urls)) + else: + text = '\n'.join(urls) w.paste(text) @ac('win', 'Focus the nth OS window') diff --git a/kitty/window.py b/kitty/window.py index ce7b94e35..7cc4fa27a 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -520,9 +520,13 @@ class Window: def current_colors(self) -> Dict[str, Optional[int]]: return self.screen.color_profile.as_dict() + @property + def at_prompt(self) -> bool: + return self.screen.cursor_at_prompt() + @property def has_running_program(self) -> bool: - return not self.screen.cursor_at_prompt() + return not self.at_prompt def matches(self, field: str, pat: MatchPatternType) -> bool: if not pat: