Skip to content

Commit

Permalink
Added actions to copy image path and command line
Browse files Browse the repository at this point in the history
  • Loading branch information
ueffel committed Apr 19, 2020
1 parent f6fca55 commit ef07c19
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode
*.bak
*.keypirinha-package
36 changes: 35 additions & 1 deletion kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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()))
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit ef07c19

Please sign in to comment.