Skip to content

Commit

Permalink
add support to read item name from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
dcreemer committed Aug 2, 2021
1 parent 06dd8e5 commit 9394950
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
13 changes: 10 additions & 3 deletions 1pass
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
set -e
set -o pipefail

VERSION="1.4"
VERSION="1.5"

if [ "$XDG_CONFIG_HOME" != "" ] && [ ! -d "${HOME}/.1pass" ]; then
op_dir="${XDG_CONFIG_HOME}/1pass"
Expand Down Expand Up @@ -146,7 +146,7 @@ list_fields=0
usage()
{
cat <<USAGE
usage: 1pass [-fhprv] [<Item> [<username|password|totp>]]
usage: 1pass [-fhprv] [<Item>|- [<username|password|totp>]]
-f Forget GPG key from gpg-agent, and remove local session
-h Help
Expand All @@ -159,7 +159,8 @@ usage: 1pass [-fhprv] [<Item> [<username|password|totp>]]
With no arguments, prints a list of all Logins and Passwords in all 1Password vaults.
With a single argument, fetches the Item (Login, Password, or TOTP) matching the
given name, and copies the resulting password to the clipboard.
given name, and copies the resulting password to the clipboard. If "-" is supplied
for <Item>, the item is read from stdin.
With two arguments, fetches the specified field (e.g.) "username" from the named
item, and copies the results to the clipboard.
Expand Down Expand Up @@ -494,6 +495,12 @@ _get_by()
local func=$1
local title=$2
local field=$3
if [ "$title" == "-" ]; then
# read title from stdin. turn off error propogation to handle EOF as well as NL
set +e
read title
set -e
fi
if [ ! -r "$index" ] || [ $refresh -eq 1 ]; then
fetch_index
fi
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ as described below, you can obtain an account password in a shell simply by typi
$ 1pass Github
```

and your Gitbub password will be copied to the clipboard.
and your Github password will be copied to the clipboard.

The official 1Password CLI application (```op```) can be difficult to use interactively, and unlike
the macOS or Windows 1Password native applications, requires an internet connection to fetch data
Expand All @@ -36,9 +36,6 @@ JSON output is easy for a program to use, but is not trivially consumed by human

Together these features enable easy use of 1Password-stored credentials.

[![asciicast](https://asciinema.org/a/eiE9JmHW0um7Ee0FVj488GYo6.png)](https://asciinema.org/a/eiE9JmHW0um7Ee0FVj488GYo6)


## Installation

First make sure that the `op` [1Password
Expand Down Expand Up @@ -200,6 +197,14 @@ $ 1pass -p MyBankAccount username
me@example.com
```

Sometimes it's easier to pass the title to search for via stdin, rather than as a command line
argument. Use the `-` character to force 1pass to read from stdin for the value.

```sh
$ echo "MyBankAccount" | 1pass -p - username
me@example.com
```

**1pass** can lookup other fields besides username or password. They field name is the "label" for
the field in the 1Password GUI.

Expand Down

0 comments on commit 9394950

Please sign in to comment.