Skip to content

renatgalimov/op.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

op.el —1Password integration for Emacs

Run Unit Tests

image

op.el

1Password integration for Emacs.

  • Call op from Emacs without repeated authentication prompts
  • Read secrets anywhere via op-read
  • Use 1Password as an auth-source backend

Why

Using the 1Password CLI (op) inside Emacs is annoying:

  • It may re-request authentication on every call
  • There's no simple way to fetch secrets inline
  • Emacs packages still expect .authinfo or pass

This package fixes all of that.

Installation

Requires Emacs 29.1+ and the 1Password CLI (op).

use-package (with vc)

(use-package op
  :vc (:url "https://github.com/renatgalimov/op.el" :branch "main"))

use-package (with vc) + auth-source

(use-package op-auth-source
  :vc (:url "https://github.com/renatgalimov/op.el" :branch "main")
  :config
  (op-auth-source-enable))

Manual

Clone the repository and add it to your load-path:

(add-to-list 'load-path "/path/to/op.el")
(require 'op)

auth-source Integration

The op-auth-source package provides an auth-source backend so that Emacs packages like smtpmail, Gnus, ERC, and others can fetch credentials from 1Password automatically.

Setup

(require 'op-auth-source)
(op-auth-source-enable)

This adds 1password to your auth-sources list. Emacs will then consult 1Password when any package calls auth-source-search.

1Password Setup

Tag the items you want Emacs to access with emacs-auth-source in 1Password. The backend only searches items with this tag.

Items are matched by their fields. The backend maps each search criterion to one or more field labels:

Criterion Matched field labels
:host host, server, hostname
:user user, username, email
:port port, port number

Any other criterion key is matched against a field whose label equals the key name (e.g., :security matches a field labeled security).

A search must include at least one non-nil criterion; an empty search returns no results.

How It Works

When a package searches for credentials (e.g., :host "smtp.gmail.com" :user "alice@gmail.com" :port 587), the backend:

  1. Runs op item list --tags emacs-auth-source --format json to find tagged items
  2. Fetches full item details via op item get
  3. Matches each criterion against the item's fields by label
  4. Returns the password via op item get <id> --fields label=password

Disabling

(op-auth-source-disable)

Contributing

Write unit tests with Buttercup and name each spec using the pattern X when Y should Z.

Install the development dependencies with Cask and run the suite via ./scripts/run-tests.sh before submitting a pull request.

About

1password integration for Emacs

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages