Skip to content

Instantly share code, notes, and snippets.

@jpl444
Forked from giabao/README.md
Created December 21, 2024 04:31
Show Gist options
  • Select an option

  • Save jpl444/467e6001a9671ae520a8f988ea232bae to your computer and use it in GitHub Desktop.

Select an option

Save jpl444/467e6001a9671ae520a8f988ea232bae to your computer and use it in GitHub Desktop.
bitwarden deduplicate import
  1. (optional) Import Data from chrome, firefox, keepass,..
  2. Export Vault to bitwarden.json file
  3. Get Ammonite
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/com-lihaoyi/Ammonite/releases/download/2.4.0/2.13-2.4.0) > /usr/local/bin/amm && chmod +x /usr/local/bin/amm' && amm
  1. Download the dedup.scala file below then run it in ammonite
amm dedup.scala bitwarden.json

This will create file bitwarden_out.json

  1. Purge Vault
  2. Re-Import Data from bitwarden_out.json
  3. Done
import upickle._
@main def dedup(filename: String): Unit = {
val path = os.pwd / filename
val json = ujson.read(os.read(path))
val items = json("items").arr
/* debug only
val itemsWithMatch = items.filter(
_("login").obj.get("uris") match {
case None => false
case Some(uris) => uris.arr.exists(! _("match").isNull)
}
)
println(itemsWithMatch.length)
val itemsWithOrganizationId = items.filter(! _("organizationId").isNull)
println(itemsWithOrganizationId.length)
*/
// only interested in those fields
def interested(d: ujson.Value) = {
val l = d("login").obj
( d("organizationId"),
d("notes"),
l("username"),
l("password"),
l("totp"),
for {
uris <- l.get("uris").toList
uri <- uris.arr
} yield (uri("match"), uri("uri"))
)
}
val out = items.distinctBy(interested)
json("items") = out
val outName = path.baseName + "_out." + path.ext
os.write.over(os.pwd / outName, ujson.write(json))
println(s"Removed ${items.length - out.length} from ${items.length}, remains ${out.length} entries.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment