Getting started with 1Password for your growing team, or refining your setup? Our Secured Success quickstart guide is for you.
Forum Discussion
jpr5
2 years agoNew Contributor
"Use as global default on my system" never works -- only ever from home dir
On macOS, no matter where I run "op plugin init aws" from, no matter how often I pick "Use as global default on my system", subsequent invocations of aws only work from my homedir (and subdirs from t...
pan93412
2 years agoNew Contributor
There are several issues related to this matter:
- https://github.com/1Password/shell-plugins/issues/416
- https://github.com/1Password/shell-plugins/issues/407
- https://github.com/1Password/shell-plugins/issues/429
The 1Password team has not responded to these issues, which is frustrating. This issue is particularly annoying because I sometimes clone files to /tmp
, where the .op
configuration directory created by “Use automatically when in this directory or subdirectories” in op plugin init gh
cannot be persisted.
After profiling the op
CLI, I found that searchDefaultsFilelnCurrentDirRecursively
attempts to traverse the parent directories and open files to locate the .op/plugins/<plugin>.json
file before falling back to the global configuration. However, this process can be slow due to the complexity of the parent directory structure.
As the description of this function, "Use automatically when in this directory or subdirectories," clearly indicates, there is no need to traverse the entire directory tree of the parent, I propose simplifying the searchDefaultsFilelnCurrentDirRecursively
function, which would take O(n)
time, where n
is the depth of the current directory relative to the root. I do not know the signature of the original function, so this function may need to be rewritten to match the exact behavior. Unit tests should be added to this code, but I have tested it with some hanging cases in my directory. I hope this helps!
```go
package main
import (
"errors"
"os"
"path/filepath"
"strings"
)
func searchDefaultsFilelnCurrentDirRecursively(dir string, program string) ([]byte, error) {
dirToCheck := filepath.Clean(dir)
configFile := filepath.Join(".op", "plugins", program+".json")
for len(dirToCheck) > 0 {
configFilePath := filepath.Join(dirToCheck, configFile)
content, err := os.ReadFile(configFilePath)
if err == nil {
return content, nil
}
dirToCheck = dirToCheck[:strings.LastIndexByte(dirToCheck, byte(os.PathSeparator))]
}
content, err := os.ReadFile(filepath.Join("/", configFile))
if err == nil {
return content, nil
}
return nil, errors.New("no defaults found")
}
```