diff --git a/README.md b/README.md index bfdbda7..1556459 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,13 @@ Krunner pass Integrates [krunner](https://userbase.kde.org/Plasma/Krunner) with [pass](https://www.passwordstore.org). +## Use with [pass-otp](https://github.com/tadfisher/pass-otp) + +To use with pass-otp, use the identifier "totp::" as a prefix in the filename or file path of the otp password file. + +Alternatively, set $PASSWORD_STORE_OTP_IDENTIFIER to overwrite the identifier string. This must be set in `.xprofile` +or similar file, before the initalization of krunner. + Build and Installation ====================== diff --git a/pass.cpp b/pass.cpp index b1fb357..6d5d70c 100644 --- a/pass.cpp +++ b/pass.cpp @@ -61,6 +61,12 @@ void Pass::init() { } } + this->passOtpIdentifier = "totp::"; + auto passOtpIdentifier = getenv("PASSWORD_STORE_OTP_IDENTIFIER"); + if (passOtpIdentifier != nullptr) { + this->passOtpIdentifier = passOtpIdentifier; + } + initPasswords(); connect(&watcher, SIGNAL(directoryChanged(QString)), this, SLOT(reinitPasswords(QString))); @@ -125,7 +131,12 @@ void Pass::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &m { Q_UNUSED(context); - auto ret = QProcess::execute(QString("pass -c ") + match.text()); + auto regexp = QRegularExpression("^" + QRegularExpression::escape(this->passOtpIdentifier) + ".*"); + auto isOtp = match.text().split('/').filter(regexp).size() > 0; + + auto ret = isOtp ? + QProcess::execute(QString("pass otp -c ") + match.text()) : + QProcess::execute(QString("pass -c ") + match.text()); if (ret == 0) { QString msg = i18n("Password %1 copied to clipboard for %2 seconds", match.text(), timeout); KNotification::event("password-unlocked", "Pass", msg, diff --git a/pass.h b/pass.h index ea641eb..34d58b5 100644 --- a/pass.h +++ b/pass.h @@ -44,6 +44,7 @@ protected: private: QDir baseDir; + QString passOtpIdentifier; int timeout; QReadWriteLock lock; QList passwords;