Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added command line options to change the rofi options depending on th… #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions bitwarden_pyro/bwpyro.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import re
import sys
import logging
import shlex
from collections import namedtuple

from bitwarden_pyro.util.logger import ProjectLogger
from bitwarden_pyro.util.arguments import parse_arguments
Expand Down Expand Up @@ -72,7 +74,7 @@ def __lock(self):
self._session.lock()
except SessionException:
self._logger.exception("Failed to lock session")
self._rofi = Rofi(None, None, None)
self._rofi = Rofi([], None, None)
self._rofi.show_error("Failed to lock and delete session")

def __unlock(self, force=False):
Expand Down Expand Up @@ -197,8 +199,14 @@ def __init_ui(self):
try:
self._config = ConfigLoader(self._args)
self._session = Session(
self._config.get_int('security.timeout'))
self._rofi = Rofi(self._args.rofi_args,
self._config.get_int('security.timeout'))

RofiArgs = namedtuple('RofiArgs',
'main_window_args password_window_args additional_args')
rofi_args = RofiArgs(shlex.split(self._args.main_window_rofi_args),
shlex.split(self._args.password_window_rofi_args),
self._args.rofi_args)
self._rofi = Rofi(rofi_args,
self._config.get_itemaction('keyboard.enter'),
self._config.get_boolean('interface.hide_mesg'))
self._clipboard = Clipboard(
Expand Down
17 changes: 16 additions & 1 deletion bitwarden_pyro/util/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,25 @@ def parse_arguments():
choices=['uris', 'logins', 'names', 'folders']
)

parser.add_argument(
"--main-window-rofi-args",
help="rofi arguments used for the main window",
type=str,
default=""
)

parser.add_argument(
"--password-window-rofi-args",
help="rofi arguments used for the password window",
type=str,
default=""
)

parser.add_argument(
'rofi_args',
help=argparse.SUPPRESS,
nargs=argparse.REMAINDER
nargs=argparse.REMAINDER,
default=[]
)

return parser.parse_args()
Expand Down
26 changes: 15 additions & 11 deletions bitwarden_pyro/view/rofi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ class Rofi:
def __init__(self, args, enter_event, hide_mesg):
self._logger = ProjectLogger().get_logger()
self._keybinds = {}
self._args = args[1:]
self._main_window_args = args.main_window_args + args.additional_args[1:]
self._password_window_args = args.password_window_args + args.additional_args[1:]
self._enter_event = enter_event
self._hide_mesg = hide_mesg
self._keybinds_code = 10

if len(args) > 0:
self._logger.debug("Setting rofi arguments: %s", self._args)
if len(self._main_window_args) > 0:
self._logger.debug("Setting rofi arguments for main window: %s", self._main_window_args)
if len(self._password_window_args) > 0:
self._logger.debug("Setting rofi arguments for password window: %s",
self._password_window_args)

def __extend_command(self, command):
if len(self._args) > 0:
command.extend(self._args)
def __extend_command(self, command, args):
if len(args) > 0:
command.extend(args)

if not self._hide_mesg:
mesg = []
Expand Down Expand Up @@ -68,8 +72,8 @@ def get_password(self):
"-password", "-lines", "0"
]

if len(self._args) > 0:
cmd.extend(self._args)
if len(self._password_window_args) > 0:
cmd.extend(self._password_window_args)

proc = sp.run(cmd, check=True, capture_output=True)
return proc.stdout.decode("utf-8").strip()
Expand All @@ -84,8 +88,8 @@ def show_error(self, message):
self._logger.info("Showing Rofi error")
cmd = ["rofi", "-e", f"ERROR! {message}"]

if len(self._args) > 0:
cmd.extend(self._args)
if len(self._main_window_args) > 0:
cmd.extend(self._main_window_args)

sp.run(cmd, capture_output=True, check=True)
except CalledProcessError:
Expand All @@ -99,7 +103,7 @@ def show_items(self, items, prompt='Bitwarden'):
echo_cmd = ["echo", items]
rofi_cmd = self.__extend_command([
"rofi", "-dmenu", "-p", prompt, "-i", "-no-custom"
])
], self._main_window_args)

echo_proc = sp.Popen(echo_cmd, stdout=sp.PIPE)
rofi_proc = sp.run(
Expand Down