From ef07c193934214111a1b341b3176354d4224091e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Br=C3=BCheim?= Date: Sun, 19 Apr 2020 15:30:06 +0200 Subject: [PATCH] Added actions to copy image path and command line --- .gitignore | 1 + kill.py | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b89f609..72ee587 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea +.vscode *.bak *.keypirinha-package diff --git a/kill.py b/kill.py index d7cdc52..ba14b7d 100644 --- a/kill.py +++ b/kill.py @@ -40,6 +40,8 @@ class Kill(kp.Plugin): ADMIN_SUFFIX = "_admin" ACTION_KILL_BY_ID_ADMIN = ACTION_KILL_BY_ID + ADMIN_SUFFIX ACTION_KILL_BY_NAME_ADMIN = ACTION_KILL_BY_NAME + ADMIN_SUFFIX + ACTION_COPY_CMD_LINE = "copy_cmd_line" + ACTION_COPY_IMAGE_PATH = "copy_image_path" DEFAULT_ITEM_LABEL = "Kill:" def __init__(self): @@ -126,6 +128,13 @@ def on_start(self): ) self._actions.append(kill_by_id_admin) + copy_image_path = self.create_action( + name=self.ACTION_COPY_IMAGE_PATH, + label="Copy the path of the executeable to clipboard", + short_desc="Copies the absolute path of the executable of this process to the clipboard" + ) + self._actions.append(copy_image_path) + self.set_actions(kp.ItemCategory.KEYWORD, self._actions) kill_and_restart_by_id = self.create_action( @@ -134,8 +143,16 @@ def on_start(self): short_desc="Kills single process by its process id" + " and tries to restart it" ) - self._actions.append(kill_and_restart_by_id) + + copy_image_path = self.create_action( + name=self.ACTION_COPY_CMD_LINE, + label="Copy the command line of the process to clipboard", + short_desc="Copys the command line that started this process to the clipboard" + + " and tries to restart it" + ) + self._actions.append(copy_image_path) + self.set_actions(RESTARTABLE, self._actions) self._default_icon = self.load_icon("res://{}/kill.ico".format(self.package_full_name())) @@ -497,6 +514,23 @@ def on_execute(self, item, action): if act.name() == self._default_action: action = act + if action.name() == self.ACTION_COPY_CMD_LINE: + databag = eval(item.data_bag()) + self.dbg(databag) + if "CommandLine" in databag: + kpu.set_clipboard(databag["CommandLine"]) + else: + self.err("CommandLine could not be obtained") + return + elif action.name() == self.ACTION_COPY_IMAGE_PATH: + databag = eval(item.data_bag()) + self.dbg(databag) + if "ExecutablePath" in databag: + kpu.set_clipboard(databag["ExecutablePath"]) + else: + self.err("ExecutablePath could not be obtained") + return + loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) if action.name().endswith(self.ADMIN_SUFFIX):