Skip to content

Commit

Permalink
Wofi and Bemenu support. Closes #71 and #105
Browse files Browse the repository at this point in the history
  • Loading branch information
firecat53 committed Apr 9, 2022
1 parent d319ea5 commit 4ff4c8f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2021 Scott Hansen <firecat four one five three at gmail dot com>
Copyright (c) 2022 Scott Hansen <firecat four one five three at gmail dot com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# Networkmanager-dmenu

Manage NetworkManager connections with dmenu, [Rofi][1] or [Bemenu][2] instead of nm-applet

**WARNING** _Two breaking changes 2021-12-08_

1. _ALL_ menu configuration moved to `dmenu_command`, including `-i`. Note
options changed in config.ini.example
2. Minimum Python version now 3.7
Manage NetworkManager connections with dmenu, [Rofi][1], [Bemenu][2] or
[Wofi][7] instead of nm-applet

## Features

Expand All @@ -32,7 +27,7 @@ Manage NetworkManager connections with dmenu, [Rofi][1] or [Bemenu][2] instead o

1. Python 3.7+
2. NetworkManager
3. Dmenu, Rofi or bemenu
3. Dmenu (X), Rofi (X or XWayland), Wofi (Wayland) or Bemenu (X or Wayland)
4. Python gobject (PyGObject, python-gobject, etc.)
5. (Debian/Ubuntu based distros) libnm-util-dev and gir1.2-nm-1.0 (you have to
explicitly install the latter on Debian Sid)
Expand All @@ -53,8 +48,8 @@ Manage NetworkManager connections with dmenu, [Rofi][1] or [Bemenu][2] instead o
- If using dmenu for passphrase entry (pinentry not set), dmenu options in the
`[dmenu_passphrase]` section of config.ini will set the normal foreground and
background colors to be the same to obscure the passphrase. The [Suckless
password patch][6] `-P` option is supported if that patch is installed. Rofi and
bemenu will use their respective flags for passphrase entry.
password patch][6] `-P` option is supported if that patch is installed. Rofi,
Wofi and Bemenu will use their respective flags for passphrase entry.
- Set default terminal (xterm, urxvtc, etc.) command in config.ini if desired.
- Saved connections can be listed if desired. Set `list_saved = True` under
`[dmenu]` in config.ini. If set to `False`, saved connections are still
Expand Down Expand Up @@ -106,3 +101,4 @@ Manage NetworkManager connections with dmenu, [Rofi][1] or [Bemenu][2] instead o
[4]: https://github.com/Woomy4680-exe/Woomy-overlay "Woomy Overlay"
[5]: https://wiki.archlinux.org/index.php/NetworkManager#Set_up_PolicyKit_permissions "PolicyKit permissions"
[6]: https://tools.suckless.org/dmenu/patches/password/ "Suckless password patch"
[7]: https://hg.sr.ht/~scoopta/wofi "Wofi"
38 changes: 27 additions & 11 deletions networkmanager_dmenu
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ def cli_args():
return args


def dmenu_pass(command, color):
"""Check if dmenu passphrase patch is applied and return the correct command
line arg list
Args: command - string
color - obscure color string
Returns: list or None
"""
if command != 'dmenu':
return None
try:
# Check for dmenu password patch
dm_patch = b'P' in subprocess.run(["dmenu", "-h"],
capture_output=True,
check=False).stderr
except FileNotFoundError:
dm_patch = False
return ["-P"] if dm_patch else ["-nb", color, "-nf", color]


def dmenu_cmd(num_lines, prompt="Networks", active_lines=None):
"""Parse config.ini for menu options
Expand All @@ -73,9 +94,11 @@ def dmenu_cmd(num_lines, prompt="Networks", active_lines=None):
["dmenu", "-l", "<num_lines>", "-p", "<prompt>", "-i"]
"""
# Create command string
commands = {"dmenu": ["-p", str(prompt)],
"rofi": ["-dmenu", "-p", str(prompt), "-l", str(num_lines)],
"bemenu": ["-p", str(prompt)]}
"bemenu": ["-p", str(prompt)],
"wofi": ["-p", str(prompt)]}
command = shlex.split(CONF.get('dmenu', 'dmenu_command', fallback="dmenu"))
command.extend(cli_args())
command.extend(commands.get(command[0], []))
Expand All @@ -87,17 +110,10 @@ def dmenu_cmd(num_lines, prompt="Networks", active_lines=None):
obscure = CONF.getboolean('dmenu_passphrase', 'obscure', fallback=False)
if prompt == "Passphrase" and obscure is True:
obscure_color = CONF.get('dmenu_passphrase', 'obscure_color', fallback='#222222')
try:
# Check for dmenu password patch
dm_patch = b'P' in subprocess.run(["dmenu", "-h"],
capture_output=True,
check=False).stderr
except FileNotFoundError:
dm_patch = False
dmenu = ["-P"] if dm_patch else ["-nb", obscure_color, "-nf", obscure_color]
pass_prompts = {"dmenu": dmenu,
pass_prompts = {"dmenu": dmenu_pass(command[0], obscure_color),
"rofi": ['-password'],
"bemenu": ['x']}
"bemenu": ['-x'],
"wofi": ['-P']}
command.extend(pass_prompts.get(command[0], []))
return command

Expand Down

0 comments on commit 4ff4c8f

Please sign in to comment.