Skip to content

$FILTER falls back to the selected item name, so plugins can't detect if a filter is active#4126

Description

@TobiasKrok




Is your feature request related to a problem? Please describe.
The $FILTER environment variable will return the current filter the user has applied, but when no filter is applied it will default to returning to the current hovered item. A plugin is not able to know if something was searched for, which makes plugin logic like this not really possible:

plugins:
  my-plugin:
    shortCut: Shift-E
    description: My plugin
    scopes:
      - all
    background: true
    command: bash
    args:
      - -c
      - |
         if [[ -n "$FILTER" ]]; then 
             kubectl get $RESOURCE_NAME --context $CONTEXT | sed -n "1p; /^$FILTER/p" #....
         fi;

Describe the solution you'd like
A way for plugins to know whether a filter is actually active. To avoid breaking backwards compatibility, two options could be:

  1. A new env var like $FILTER_APPLIED=true/false
  2. A new env var like $RAW_FILTER that contains command buffer text (empty when no filter is active)

Another option is of course to leave $FILTER empty but I'm not sure about the implications of this change. I think that if you need to know the current resource name, its best to use $NAME anyways.

This would let plugins pass the filter to grep/kubectl for more customized searches.

Describe alternatives you've considered
Comparing $FILTER to $NAME to detect the fallback case, it can work but its ambiguous as the plugin might draw the wrong conclusion.

Additional context
The fallback happens in internal/view/table

env["FILTER"] = t.CmdBuff().GetText()
if env["FILTER"] == "" {
    env["NAMESPACE"], env["FILTER"] = client.Namespaced(path)
}

And in internal/view/xray.go

	env["FILTER"] = x.CmdBuff().GetText()
	if env["FILTER"] == "" {
		ns, n := client.Namespaced(spec.Path())
		env["NAMESPACE"], env["FILTER"] = ns, n
	}

I'm happy to make a PR for this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions