Skip to content

Commit 785ed9f

Browse files
authored
Properly close spawned kitty window (#2471)
* properly close spawned kitty window * python2 support * changelog
1 parent cdfd64f commit 785ed9f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ The table below shows which release corresponds to each branch, and what date th
7272

7373
## 4.15.0 (`dev`)
7474

75+
- [#2471][2471] Properly close spawned kitty window
7576
- [#2358][2358] Cache output of `asm()`
7677
- [#2457][2457] Catch exception of non-ELF files in checksec.
7778
- [#2444][2444] Add `ELF.close()` to release resources
7879

80+
[2471]: https://github.com/Gallopsled/pwntools/pull/2471
7981
[2358]: https://github.com/Gallopsled/pwntools/pull/2358
8082
[2457]: https://github.com/Gallopsled/pwntools/pull/2457
8183
[2444]: https://github.com/Gallopsled/pwntools/pull/2444

pwnlib/util/misc.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,13 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
443443
log.debug("Launching a new terminal: %r" % argv)
444444

445445
stdin = stdout = stderr = open(os.devnull, 'r+b')
446-
if terminal == 'tmux':
446+
if terminal == 'tmux' or terminal == 'kitty':
447447
stdout = subprocess.PIPE
448448

449449
p = subprocess.Popen(argv, stdin=stdin, stdout=stdout, stderr=stderr, preexec_fn=preexec_fn)
450450

451+
kittyid = None
452+
451453
if terminal == 'tmux':
452454
out, _ = p.communicate()
453455
try:
@@ -460,6 +462,16 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
460462
with subprocess.Popen((qdbus, konsole_dbus_service, '/Sessions/{}'.format(last_konsole_session),
461463
'org.kde.konsole.Session.processId'), stdout=subprocess.PIPE) as proc:
462464
pid = int(proc.communicate()[0].decode())
465+
elif terminal == 'kitty':
466+
pid = p.pid
467+
468+
out, _ = p.communicate()
469+
try:
470+
kittyid = int(out)
471+
except ValueError:
472+
kittyid = None
473+
if kittyid is None:
474+
log.error("Could not parse kitty window ID from output (%r)", out)
463475
else:
464476
pid = p.pid
465477

@@ -468,6 +480,8 @@ def kill():
468480
try:
469481
if terminal == 'qdbus':
470482
os.kill(pid, signal.SIGHUP)
483+
elif terminal == 'kitty':
484+
subprocess.Popen(["kitten", "@", "close-window", "--match", "id:{}".format(kittyid)])
471485
else:
472486
os.kill(pid, signal.SIGTERM)
473487
except OSError:

0 commit comments

Comments
 (0)