feat: lazysecrets list's text lines start with the kind
This commit is contained in:
2 files changed
+13
-8
No files matched your search
@@ -26,9 +26,11 @@ import (
|
|||||||
// listCmd prints every source, vault and secret lazysecrets can find, one
|
// listCmd prints every source, vault and secret lazysecrets can find, one
|
||||||
// per line, for fzf, editor pickers and scripts:
|
// per line, for fzf, editor pickers and scripts:
|
||||||
//
|
//
|
||||||
// lazysecrets list | fzf --ansi --with-nth='..-2' --accept-nth=-1
|
// lazysecrets list | fzf --ansi --with-nth='2..-2' --accept-nth=-1
|
||||||
//
|
//
|
||||||
// Each line is the name, then the link: the name coloured from the theme,
|
// Each line is the kind, the name and the link, tab-separated (the kind
|
||||||
|
// a word, the link without spaces, so even fields split on spaces keep
|
||||||
|
// them first and last): the name coloured from the theme,
|
||||||
// with the provider's icon (as in the TUI: --icons, LAZYSECRETS_ICONS,
|
// with the provider's icon (as in the TUI: --icons, LAZYSECRETS_ICONS,
|
||||||
// ui.icons); the link never is.
|
// ui.icons); the link never is.
|
||||||
//
|
//
|
||||||
@@ -40,7 +42,7 @@ func listCmd(providers []provider.Provider, cachePath string, timeout func(provi
|
|||||||
fs := flag.NewFlagSet("list", flag.ContinueOnError)
|
fs := flag.NewFlagSet("list", flag.ContinueOnError)
|
||||||
cached := fs.Bool("cached", false, "only what's cached, and repos: load nothing from Azure or Databricks")
|
cached := fs.Bool("cached", false, "only what's cached, and repos: load nothing from Azure or Databricks")
|
||||||
maxAge := fs.Duration("max-age", 2*time.Minute, "load cached lists older than this again")
|
maxAge := fs.Duration("max-age", 2*time.Minute, "load cached lists older than this again")
|
||||||
format := fs.String("format", "text", "text: name and link, tab-separated; json: an object per line")
|
format := fs.String("format", "text", "text: kind, name and link, tab-separated; json: an object per line")
|
||||||
color := fs.String("color", "always", "colour the names (text): always or never; fzf needs --ansi")
|
color := fs.String("color", "always", "colour the names (text): always or never; fzf needs --ansi")
|
||||||
iconsOn := fs.Bool("icons", withIcons, "put the provider's Nerd Font icon before names (text)")
|
iconsOn := fs.Bool("icons", withIcons, "put the provider's Nerd Font icon before names (text)")
|
||||||
kinds := fs.String("kind", "", "only these kinds, comma-separated: "+strings.Join(listing.Kinds, ", ")+" (vault: also scopes and repo files)")
|
kinds := fs.String("kind", "", "only these kinds, comma-separated: "+strings.Join(listing.Kinds, ", ")+" (vault: also scopes and repo files)")
|
||||||
@@ -73,7 +75,7 @@ func listCmd(providers []provider.Provider, cachePath string, timeout func(provi
|
|||||||
case "text":
|
case "text":
|
||||||
write = func(e listing.Entry) error {
|
write = func(e listing.Entry) error {
|
||||||
// A tab or line break in a name would break the line up.
|
// A tab or line break in a name would break the line up.
|
||||||
_, err := fmt.Fprintf(out, "%s\t%s\n", oneLine.Replace(nameOf(e, theme, iconSet, *color == "always")), e.Link)
|
_, err := fmt.Fprintf(out, "%s\t%s\t%s\n", e.Kind, oneLine.Replace(nameOf(e, theme, iconSet, *color == "always")), e.Link)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case "json":
|
case "json":
|
||||||
|
|||||||
+7
-4
@@ -139,18 +139,21 @@ a newline only on a terminal.
|
|||||||
### Listing, for fzf and pickers
|
### Listing, for fzf and pickers
|
||||||
|
|
||||||
`lazysecrets list` prints every source, vault and secret, one per line:
|
`lazysecrets list` prints every source, vault and secret, one per line:
|
||||||
its name (`platform-prod / kv-app-prod / db-password`), then its link,
|
its kind (`source`, `vault`, `secret`, `key` or `certificate`), its name
|
||||||
|
(`platform-prod / kv-app-prod / db-password`) and its link,
|
||||||
tab-separated. It's what Go to searches, so fzf, or an editor's picker,
|
tab-separated. It's what Go to searches, so fzf, or an editor's picker,
|
||||||
can search it instead, showing the names and acting on the links:
|
can search it instead, showing the names and acting on the links:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
lazysecrets list | fzf --ansi --with-nth='..-2' --accept-nth=-1 \
|
lazysecrets list | fzf --ansi --with-nth='2..-2' --accept-nth=-1 \
|
||||||
--bind 'ctrl-o:become(lazysecrets open {-1})' \
|
--bind 'ctrl-o:become(lazysecrets open {-1})' \
|
||||||
--bind 'ctrl-y:execute-silent(lazysecrets get {-1} | pbcopy)'
|
--bind 'ctrl-y:execute-silent(lazysecrets get {-1} | pbcopy)'
|
||||||
```
|
```
|
||||||
|
|
||||||
`--with-nth='..-2'` shows and searches the names, leaving out the link,
|
`--with-nth='2..-2'` shows and searches the names, leaving out the kind,
|
||||||
the last field; `{-1}` and `--accept-nth=-1` are the link. `enter` prints
|
the first field, and the link, the last; `{-1}` and `--accept-nth=-1` are
|
||||||
|
the link. The kind is one word and the link has no spaces, so this works
|
||||||
|
without `--delimiter`. To filter by kind yourself: `awk -F'\t' '$1 == "secret"'`. `enter` prints
|
||||||
it (`lazysecrets get $(…)`), `ctrl-o` opens it in lazysecrets and `ctrl-y`
|
it (`lazysecrets get $(…)`), `ctrl-o` opens it in lazysecrets and `ctrl-y`
|
||||||
copies the value (`pbcopy` on macOS; `wl-copy` or `xclip` on Linux). A
|
copies the value (`pbcopy` on macOS; `wl-copy` or `xclip` on Linux). A
|
||||||
value copied this way isn't cleared from the clipboard after
|
value copied this way isn't cleared from the clipboard after
|
||||||
|
|||||||
Reference in new issue
Block a user