// attempt to locate the keychain directory automatically func findKeyChainDirs() []string { paths := []string{} // try using 'locate' locateCmd := exec.Command("locate", "-b", "--existing", ".agilekeychain") locateOutput, err := locateCmd.Output() if err == nil { locateLines := strings.Split(string(locateOutput), "\n") for _, path := range locateLines { err = onepass.CheckVault(path) if err == nil { paths = append(paths, path) } } } // try default paths defaultPaths := []string{ os.Getenv("HOME") + "/Dropbox/1Password/1Password.agilekeychain", } for _, defaultPath := range defaultPaths { ok := rangeutil.Contains(0, len(paths), func(i int) bool { return paths[i] == defaultPath }) if !ok { err = onepass.CheckVault(defaultPath) if err == nil { paths = append(paths, defaultPath) } } } return paths }
func removeTag(vault *onepass.Vault, pattern string, tag string) { items, err := lookupItems(vault, pattern) if err != nil { fatalErr(err, "Unable to lookup items") } for _, item := range items { hasTag := rangeutil.Contains(0, len(item.OpenContents.Tags), func(i int) bool { return item.OpenContents.Tags[i] == tag }) if hasTag { logItemAction("Untagging item", item) newTags := []string{} for _, existingTag := range item.OpenContents.Tags { if existingTag != tag { newTags = append(newTags, existingTag) } } item.OpenContents.Tags = newTags err = item.Save() if err != nil { fatalErr(err, fmt.Sprintf("Unable to save item '%s'", item.Title)) } } } }
func listTag(vault *onepass.Vault, tag string) { items, err := vault.ListItems() if err != nil { fatalErr(err, "Unable to list vault items") } itemsWithTag := []onepass.Item{} for _, item := range items { hasTag := rangeutil.Contains(0, len(item.OpenContents.Tags), func(i int) bool { return item.OpenContents.Tags[i] == tag }) if hasTag { itemsWithTag = append(itemsWithTag, item) } } listItems(vault, itemsWithTag) }
func addTag(vault *onepass.Vault, pattern string, tag string) { items, err := lookupItems(vault, pattern) if err != nil { fatalErr(err, "Unable to lookup items") } for _, item := range items { hasTag := rangeutil.Contains(0, len(item.OpenContents.Tags), func(i int) bool { return item.OpenContents.Tags[i] == tag }) if !hasTag { logItemAction("Tagging item", item) item.OpenContents.Tags = append(item.OpenContents.Tags, tag) err = item.Save() if err != nil { fatalErr(err, fmt.Sprintf("Unable to save item '%s'", item.Title)) } } } }