From d9a0a899c2e20b72129f13c02eafeacc40de2e07 Mon Sep 17 00:00:00 2001 From: Andrew Kaiser Date: Wed, 12 Sep 2018 16:30:28 -0400 Subject: [PATCH] ensure error command is executed, detail readme --- README.md | 41 +++++++++++++++++++++++++++++------------ bin/cli.js | 22 ++++++++++++++-------- package.json | 6 +++++- 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 62786d0..1789299 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,12 @@ # bitwarden-dmenu -[bitwarden](https://bitwarden.com/) client using dmenu +[![node](https://img.shields.io/node/v/bitwarden-dmenu.svg)](http://npmjs.com/package/bitwarden-dmenu) +[![GitHub](https://img.shields.io/github/license/andykais/bitwarden-dmenu.svg)](https://github.com/andykais/bitwarden-dmenu/blob/master/LICENSE) -## Depends on -- [dmenu](https://tools.suckless.org/dmenu/) -- [bitwarden-cli](https://help.bitwarden.com/article/cli/) -## Installation -```bash -# login with bitwarden-cli once before using bitwarden-dmenu -bw login -# install the cli -npm i -g bitwarden-dmenu -``` + +dmenu for [bitwarden](https://bitwarden.com/) which can copy usernames, passwords, and various fields to your +clipboard. ## Usage ``` @@ -26,6 +20,29 @@ Options: without providing a password again. Defaults to 0s. --sync-vault-after Number of seconds allowable between last bitwarden sync and current time. Defaults to 0s. - --on-error Arbitrary command to run if the program fails. Defaults to none. + --on-error Arbitrary command to run if the program fails. The thrown error + is piped to the given command. Defaults to none. +``` +By default, this program runs at its most secure. No session is stored for any time period, the vault is updated +every time it is used, and the clipboard is cleared every 15 seconds. In reality, you may want something a +little more lenient. Here is the command I use in my personal i3wm config. +```bash +bitwarden-dmenu --clear-clipboard 30 --session-timeout 100 --sync-vault-after 3600 --on-error 'xargs notify-send --urgency=low' ``` + +## Installation +```bash +# login with bitwarden-cli once before using bitwarden-dmenu +bw login +# install the cli +npm i -g bitwarden-dmenu +``` + +## Depends on +- [dmenu](https://tools.suckless.org/dmenu/) +- [bitwarden-cli](https://help.bitwarden.com/article/cli/) + +## Credits + +Inspired by the no longer maintained [keepass-dmenu](https://github.com/gustavnikolaj/keepass-dmenu) diff --git a/bin/cli.js b/bin/cli.js index d32bb76..f57acf7 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -22,7 +22,8 @@ Options: without providing a password again. Defaults to ${sessionTimeoutDefault}s. --sync-vault-after Number of seconds allowable between last bitwarden sync and current time. Defaults to ${syncVaultAfterDefault}s. - --on-error Arbitrary command to run if the program fails. Defaults to none. + --on-error Arbitrary command to run if the program fails. The thrown error + is piped to the given command. Defaults to none. ` ) process.exit() @@ -46,18 +47,23 @@ menu({ saveSession, sessionFile, oldestAllowedVaultSync }) }) ) .catch(e => { - console.log(e) + console.error(e) // if something goes wrong, immediately clear the clipboard & lock bitwarden, // then run error command scheduleCleanup({ lockBitwardenAfter: 0, clearClipboardAfter: 0, sessionFile - }).then(() => { - if (onErrorCommand) { - const errorCommand = exec(onErrorCommand) - errorCommand.stdin.write(`'${e.toString()}'`) - errorCommand.stdin.end() - } }) + .catch(e => { + // simply log a secondary error + console.error(e) + }) + .then(() => { + if (onErrorCommand) { + const errorCommand = exec(onErrorCommand) + errorCommand.stdin.write(`'${e.toString()}'`) + errorCommand.stdin.end() + } + }) }) diff --git a/package.json b/package.json index a1fd472..87320a7 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,16 @@ { "name": "bitwarden-dmenu", - "version": "1.0.0", + "version": "1.0.1", "description": "", "keywords": [ "bitwarden", "cli", "dmenu" ], + "repository": { + "type": "git", + "url": "https://github.com/andykais/bitwarden-dmenu.git" + }, "license": "MIT", "author": "Andrew Kaiser", "main": "index.js",