Skip to content

Commit

Permalink
Release 0.9.0
Browse files Browse the repository at this point in the history
New features:

- If `wtype` is available, it will be preferred over `xdotool` when
  `--type` is used
  • Loading branch information
emlun committed Jul 22, 2020
2 parents 0455492 + a26f857 commit 9586f7e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -8,7 +8,7 @@ SCRIPT_INSTALL_FULL_PATH=$(BINDIR)/$(SCRIPT_INSTALL_FILENAME)

default:
@echo "Nothing to do!"
@echo 'Use "make install" to install the program to $(DESTDIR)$(BINDIR)'
@echo 'Use "make install" to install the program to $(BINDIR)'

install:
install -D -m755 "$(SCRIPT_SRC_FILENAME)" "$(SCRIPT_INSTALL_FULL_PATH)"
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
@@ -1,4 +1,8 @@
- Version 0.8.0
- Version 0.9.0 - released 2020-07-22
- If `wtype` is available, it will be preferred over `xdotool` when `--type`
is used

- Version 0.8.0 - released 2019-04-10
- Will now prompt for YubiKey OATH password if needed
- New option `--pinentry` to set pinentry program to use to prompt for
password when needed
Expand Down
10 changes: 7 additions & 3 deletions README.md
Expand Up @@ -5,7 +5,8 @@ yubikey-oath-dmenu

This program lets you pick an OATH credential from your YubiKey using [dmenu][],
and copies the corresponding OTP to the clipboard using [xclip][].
Alternatively, it can "type" the OTP using [xdotool][].
Alternatively, it can "type" the OTP using [xdotool][] on X11 or [wtype][]
on Wayland.

Notable features:

Expand All @@ -27,7 +28,7 @@ in [i3wm][] like this:

# Grab OTPs from ykman oath
bindsym $mod+o exec yubikey-oath-dmenu --notify --clipboard clipboard
bindsym $mod+Shift+o exec yubikey-oath-dmenu --notify --type
bindsym $mod+Shift+o exec yubikey-oath-dmenu --notify --type -p "Credential to type:"


Dependencies
Expand All @@ -43,7 +44,8 @@ Optional dependencies:

- [libnotify][]: For the `--notify` option, which uses `notify-send`
- [pinentry][]: To prompt for the YubiKey OATH password when needed
- [xdotool][]: For the `--type` option
- [xdotool][]: For the `--type` option under X11
- [wtype][]: For the `--type` option under Wayland (`xdotool` might also work)


Installation
Expand Down Expand Up @@ -77,6 +79,7 @@ Installation
[libnotify]: https://developer.gnome.org/libnotify/
[pinentry]: https://www.gnupg.org/related_software/pinentry/index.html
[python]: https://www.python.org/
[wtype]: https://github.com/atx/wtype
[xclip]: https://linux.die.net/man/1/xclip
[xdotool]: http://www.semicomplete.com/projects/xdotool/
[ykman]: https://github.com/Yubico/yubikey-manager
Expand All @@ -89,4 +92,5 @@ Contributors
Big thanks to our contributors:

- [Andrei Gherzan](https://github.com/agherzan)
- [Mark Stosberg](https://github.com/markstos)
- [relatev](https://github.com/relatev)
21 changes: 16 additions & 5 deletions yubikey-oath-dmenu.py
Expand Up @@ -17,14 +17,16 @@

import click
import re
import shutil
import subprocess
import sys
import ykman.driver_ccid
import ykman.oath

from threading import Timer


VERSION = '0.8.0'
VERSION = '0.9.0'

notify_enabled = False

Expand Down Expand Up @@ -122,7 +124,7 @@ def verify_password(oath_controller, password):
@click.option('--pinentry', 'pinentry_program', metavar='BINARY', default='pinentry',
help='Use pinentry program BINARY to prompt for password when needed')
@click.option('--type', 'typeit', default=False, is_flag=True,
help='Type code using xdotool instead of copying to clipboard')
help='Type code instead of copying to clipboard')
@click.argument('dmenu_args', nargs=-1, type=click.UNPROCESSED)
@click.version_option(version=VERSION)
def cli(ctx, clipboard, dmenu_prompt, notify_enable, no_hidden, pinentry_program, typeit, dmenu_args):
Expand All @@ -135,6 +137,16 @@ def cli(ctx, clipboard, dmenu_prompt, notify_enable, no_hidden, pinentry_program
global notify_enabled
notify_enabled = notify_enable

typeit_cmd = None
if typeit:
if shutil.which('wtype'):
typeit_cmd = ['wtype']
elif shutil.which('xdotool'):
typeit_cmd = ['xdotool', 'type']
else:
click.echo('Error: wtype or xdotool binary not found', err=True)
sys.exit(1)

controllers = {i: ykman.oath.OathController(driver)
for i, driver in enumerate(
ykman.driver_ccid.open_devices())
Expand All @@ -146,7 +158,6 @@ def cli(ctx, clipboard, dmenu_prompt, notify_enable, no_hidden, pinentry_program
notify_err(msg)
ctx.fail(msg)


credentials = {
k: {cred.printable_key: cred
for cred in ctrl.list() if not (no_hidden and cred.printable_key.startswith("_hidden"))
Expand Down Expand Up @@ -191,8 +202,8 @@ def cli(ctx, clipboard, dmenu_prompt, notify_enable, no_hidden, pinentry_program
code = ctrl.calculate(credentials[ctrl_idx][selected_cred_id]).value
touch_timer.cancel()

if typeit:
subprocess.run(['xdotool', 'type', code])
if typeit_cmd:
subprocess.run(typeit_cmd + [code])
else:
xclip_proc = subprocess.Popen(
['xclip', '-selection', clipboard] if clipboard else ['xclip'],
Expand Down

0 comments on commit 9586f7e

Please sign in to comment.