diff --git a/misc/userscripts/README.md b/misc/userscripts/README.md index d389a39bb..023248227 100644 --- a/misc/userscripts/README.md +++ b/misc/userscripts/README.md @@ -75,8 +75,6 @@ The following userscripts can be found on their own repositories. and retrieve they when you want. - [doi](https://github.com/cadadr/configuration/blob/default/dotfiles/qutebrowser/userscripts/doi): Opens DOIs on Sci-Hub. -- [qute-1password](https://github.com/fmartingr/qute-1password): - Qutebrowser userscript to fill 1password credentials - [1password](https://github.com/tomoakley/dotfiles/blob/master/qutebrowser/userscripts/1password): Integration with 1password on macOS. - [localhost](https://github.com/SidharthArya/.qutebrowser/blob/master/userscripts/localhost): @@ -97,7 +95,7 @@ The following userscripts can be found on their own repositories. substitution) - [pseudo per domain stylesheets](https://github.com/bschnitz/qute): Userscript for generating url restricted greasemonkey scripts to apply user styles. -- [qute-containers](https://github.com/s-praveen-kumar/qute-containers): +- [qute-containers](https://github.com/s-praveen-kumar/qute-containers): A simple interface to manage browser containers by manipulating the basedir parameter. - [qutebrowser-metascript](https://codeberg.org/mister_monster/qutebrowser-metascript): @@ -108,7 +106,7 @@ The following userscripts can be found on their own repositories. automatically mutates input URLs based on configurable rules - [qute-translate-popup](https://github.com/JohnBardoe/qute-translate-popup): selected text translation, with a qute popup! - + [Zotero]: https://www.zotero.org/ [Pocket]: https://getpocket.com/ [Instapaper]: https://www.instapaper.com/ diff --git a/misc/userscripts/qute-1pass b/misc/userscripts/qute-1pass index 19e5414a5..37ab9f877 100755 --- a/misc/userscripts/qute-1pass +++ b/misc/userscripts/qute-1pass @@ -70,48 +70,57 @@ echo "message-info 'Looking for password for $URL...'" >> "$QUTE_FIFO" if [ -f "$TOKEN_CACHE" ]; then TOKEN=$(cat "$TOKEN_CACHE") - if ! op signin --session="$TOKEN" --output=raw > /dev/null; then - TOKEN=$(rofi -dmenu -password -p "1password: "| op signin --output=raw) || TOKEN="" + if ! op signin --session="$TOKEN" --raw > /dev/null; then + TOKEN=$(rofi -dmenu -password -p "1password: " | op signin --raw) || TOKEN="" echo "$TOKEN" > "$TOKEN_CACHE" fi else - TOKEN=$(rofi -dmenu -password -p "1password: "| op signin --output=raw) || TOKEN="" + TOKEN=$(rofi -dmenu -password -p "1password: " | op signin --raw) || TOKEN="" install -m 600 /dev/null "$TOKEN_CACHE" echo "$TOKEN" > "$TOKEN_CACHE" fi if [ -n "$TOKEN" ]; then - UUID=$(op list items --cache --session="$TOKEN" | jq --arg url "$URL" -r '[.[] | {uuid, url: [.overview.URLs[]?.u, .overview.url][]?} | select(.uuid != null) | select(.url != null) | select(.url|test(".*\($url).*"))][.0].uuid') || UUID="" + # find entry matching the exact host of our domain + UUID=$(op item list --format=json --session="$TOKEN" | \ + jq --arg url "$URL" -r ' + [ .[] + | select((.urls[]?.href // .url? // "") + | split("/")[2] == $url) + | .id + ] + | first + ') || UUID="" - if [ -z "$UUID" ] || [ "$UUID" == "null" ];then - echo "message-error 'No entry found for $URL'" >> "$QUTE_FIFO" - TITLE=$(op list items --cache --session="$TOKEN" | jq -r '.[].overview.title' | rofi -dmenu -i) || TITLE="" + if [ -z "$UUID" ] || [ "$UUID" == "null" ]; then + TITLE=$(op item list --format=json --session="$TOKEN" | jq -r '.[].title' | rofi -dmenu -i) || TITLE="" if [ -n "$TITLE" ]; then - UUID=$(op list items --cache --session="$TOKEN" | jq --arg title "$TITLE" -r '[.[] | {uuid, title:.overview.title}|select(.title|test("\($title)"))][.0].uuid') || UUID="" - else - UUID="" + # fallback: pick entry whose title contains the chosen string + UUID=$(op item list --format=json --session="$TOKEN" | \ + jq --arg title "$TITLE" -r '[.[] | select(.title | contains($title))][0].id') || UUID="" fi fi - if [ -n "$UUID" ];then - ITEM=$(op get item --cache --session="$TOKEN" "$UUID") + if [ -n "$UUID" ]; then + ITEM=$(op item get --format=json --session="$TOKEN" "$UUID") - PASSWORD=$(echo "$ITEM" | jq -r '.details.fields | .[] | select(.designation=="password") | .value') + # extract password field (fallback to any concealed field if purpose missing) + PASSWORD=$(echo "$ITEM" | jq -r '(.fields[] | select(.purpose=="PASSWORD") | .value) // (.fields[] | select(.type=="CONCEALED") | .value)' | head -n1) if [ -n "$PASSWORD" ]; then - TITLE=$(echo "$ITEM" | jq -r '.overview.title') - USERNAME=$(echo "$ITEM" | jq -r '.details.fields | .[] | select(.designation=="username") | .value') + TITLE=$(echo "$ITEM" | jq -r '.title') + USERNAME=$(echo "$ITEM" | jq -r '.fields[] | select(.purpose=="USERNAME") | .value') printjs() { js | sed 's,//.*$,,' | tr '\n' ' ' } echo "jseval -q $(printjs)" >> "$QUTE_FIFO" - TOTP=$(echo "$ITEM" | op get totp --cache --session="$TOKEN" "$UUID") || TOTP="" + TOTP=$(op item get --otp --session="$TOKEN" "$UUID") || TOTP="" if [ -n "$TOTP" ]; then echo "$TOTP" | xclip -in -selection clipboard - echo "message-info 'Pasted one time password for $TITLE to clipboard'" >> "$QUTE_FIFO" + echo "message-info 'Pasted one time password for $TITLE to clipboard'" >> "$QUTE_FIFO" fi else echo "message-error 'No password found for $URL'" >> "$QUTE_FIFO" @@ -122,3 +131,4 @@ if [ -n "$TOKEN" ]; then else echo "message-error 'Wrong master password'" >> "$QUTE_FIFO" fi +