diff --git a/README.md b/README.md index 532e963..eb2ef18 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,9 @@ sessions expires automatically after 30 minutes of inactivity. ### Configuring login items in 1Password In order to show only relevant login items and to maintain compatibility with -[sudolikeaboss](https://github.com/ravenac95/sudolikeaboss), its required to set the value of the -`website` field for each login item with the value of `sudolikeaboss://local`. +[sudolikeaboss](https://github.com/ravenac95/sudolikeaboss), by default it is required to set the value of the +`website` field for each login item with the value of `sudolikeaboss://local`. To override this behavior and provide +customized filtering, see configuration options `@1password-enabled-url-filter` and `@1password-items-jq-filter` below. ## Configuration @@ -121,6 +122,54 @@ set -g @1password-copy-to-clipboard 'on' Default: `'off'` +#### Enabled URL Filter + +By default, the plugin maintains compatibility with [sudolikeaboss](https://github.com/ravenac95/sudolikeaboss) by +filtering urls using the string "sudolikeaboss://local", by setting the following, the list of items will no longer be +filtered. + +``` +set -g @1password-enabled-url-filter 'off' +``` + +Default: `'on'` + +#### Customize URL Filtering + +If complete customization of url filtering is required, a `jq` filter can be provided to filter and map +items. + +##### Filtering by tags + +``` +set -g @1password-items-jq-filter '.[] | [select(.overview.tags | map(select(. == "tag_name")) | length == 1)?] | map([ .overview.title, .uuid ] | join(",")) | .[]' +``` + +##### Filtering by custom url + +``` +set -g @1password-items-jq-filter '.[] | [select(.overview.URLs | map(select(.u == "myspecial-url-filter")) | length == 1)?] | map([ .overview.title, .uuid ] | join(",")) | .[]' +``` + +Default: `''` + +Items come in the following format from which the filter operates: + +``` +[ + { + "uuid": "some-long-uuid", + "overview": { + "URLs": [ + { "u": "sudolikeaboss://local" } + ], + "title": "Some item", + "tags": ["tag_name"] + } + } +] +``` + ## Prior art Also see: diff --git a/scripts/main.sh b/scripts/main.sh index 751aca6..700ae7a 100755 --- a/scripts/main.sh +++ b/scripts/main.sh @@ -15,6 +15,8 @@ declare -r TMP_TOKEN_FILE="$HOME/.op_tmux_token_tmp" declare -r OPT_SUBDOMAIN="$(get_tmux_option "@1password-subdomain" "my")" declare -r OPT_VAULT="$(get_tmux_option "@1password-vault" "")" declare -r OPT_COPY_TO_CLIPBOARD="$(get_tmux_option "@1password-copy-to-clipboard" "off")" +declare -r OPT_ENABLED_URL_FILTER="$(get_tmux_option "@1password-enabled-url-filter" "on")" +declare -r OPT_ITEMS_JQ_FILTER="$(get_tmux_option "@1password-items-jq-filter" "")" declare spinner_pid="" @@ -58,13 +60,25 @@ get_op_items() { # } # ] - local -r JQ_FILTER=" - .[] - | [select(.overview.URLs | map(select(.u == \"sudolikeaboss://local\")) | length == 1)?] - | map([ .overview.title, .uuid ] - | join(\",\")) - | .[] - " + if [ -n "$OPT_ITEMS_JQ_FILTER" ]; then + local -r JQ_FILTER="$OPT_ITEMS_JQ_FILTER" + elif [ "$OPT_ENABLED_URL_FILTER" == "on" ]; then + local -r JQ_FILTER=" + .[] + | [select(.overview.URLs | map(select(.u == \"sudolikeaboss://local\")) | length == 1)?] + | map([ .overview.title, .uuid ] + | join(\",\")) + | .[] + " + else + local -r JQ_FILTER=" + .[] + | [select(.overview.URLs | map(select(.u)) | length == 1)?] + | map([ .overview.title, .uuid ] + | join(\",\")) + | .[] + " + fi op list items --vault="$OPT_VAULT" --session="$(op_get_session)" 2> /dev/null \ | jq "$JQ_FILTER" --raw-output