Skip to content

Instantly share code, notes, and snippets.

@androidcn
Created June 21, 2023 02:11
Show Gist options
  • Save androidcn/98340963102cca1f9e7a84bfce0cb4c4 to your computer and use it in GitHub Desktop.
Save androidcn/98340963102cca1f9e7a84bfce0cb4c4 to your computer and use it in GitHub Desktop.
1Password_Duplicate去重(去除-标题+用户名+密码相同的项目)
#!/usr/local/bin/bash
declare -A itemMap
for id in $(op item list --categories Login --format=json | jq -r '.[] | select(.id != null) | .id'); do
item=$(op item get $id --format=json)
if [[ $item != null ]]; then
fields=$(echo $item | jq -r '.fields')
title=$(echo $item | jq -r '.title')
if [[ $fields != null ]]; then
username=$(echo $fields | jq -r '.[] | select(.label=="username").value')
#title=$(echo $fields | jq -r '.[] | select(.label=="title").value')
password=$(echo $fields | jq -r '.[] | select(.label=="password").value')
fi
#if [[ $titles != null ]]; then
# title=$(echo $titles | jq -r '.[] | select(.label=="title").value')
#fi
#echo "检测: id: $id, username: $username, Title: $title, Password:$password"
urls=$(echo $item | jq -r '.urls')
href=$(echo $urls | jq -r '.[0].href')
website=$(echo $href | awk -F[/:] '{print $4}')
if [[ -n $title && -n $username && -n $password ]]; then
key="$title-$username-$password"
if [[ ${itemMap[$key]} ]]; then
echo "Duplicate found:"
echo "Item 1: id: ${itemMap[$key]}, username: $username, website: $website"
echo "Item 2: id: $id, username: $username, website: $website"
op item delete $id --archive
echo "$id deleted"
else
itemMap[$key]=$id
#echo "$id popinList"
fi
fi
fi
echo "$id Passed"
done
echo "ALl DONE!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment