Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Make navi variables to fzf's header option #899

Open
tapyu opened this issue May 30, 2024 · 3 comments
Open

[feature request] Make navi variables to fzf's header option #899

tapyu opened this issue May 30, 2024 · 3 comments
Labels
new feature New feature or request

Comments

@tapyu
Copy link
Contributor

tapyu commented May 30, 2024

Is your feature request related to a problem? Please describe.
Let us consider that I want to create a navi cheat sheet to print a line of a file using sed.

% sed

# Print a specific line from a file
sed -n <number>p <file>

$ file: find . -maxdepth 1 -type f | cut -c3-
$ number: export aux=$(wc -l <file> | cut -d ' ' -f 1) --- --header "This file contains $aux pages"

Describe the solution you'd like
My idea is that the aux variable becomes available to fzf so that it prints out a header like

This file contains 618 pages

Describe alternatives you've considered
I tried some syntax such as <file>, $file, etc. But it seems that fzf is insensitive to any variable declared by navi.

@tapyu tapyu added the new feature New feature or request label May 30, 2024
@chiva
Copy link

chiva commented Jul 6, 2024

You can try a workaround for the same result

% sed

# Print a specific line from a file
sed -n <number>p <file>

$ file: find . -maxdepth 1 -type f | cut -c3-
$ number: aux=$(wc -l <file> | cut -f 1) && echo "This file contains $aux pages" --- --header-lines 1

@tapyu
Copy link
Contributor Author

tapyu commented Jul 8, 2024

Small correction, it should be aux=$(wc -l <file> | cut -d ' ' -f 1), we need to define the delimiter.

Anyway, that is a good workaround, but it is a workaround. I would be great to make fzf option aware of both shell-defined variables (e.g., $aux) and navi-defined variables (e.g., <file>), so that one can write something like

% sed

# Print a specific line from a file
sed -n <number>p <file>

$ file: find . -maxdepth 1 -type f | cut -c3-
$ number: export aux=$(wc -l <file> | cut -d ' ' -f 1) --- --header "The file <file> contains $aux pages "

No workarounds, no tricks, no complications.

@tapyu
Copy link
Contributor Author

tapyu commented Jul 8, 2024

Consider another example

# add submodule
git submodule add <is_branch>

$ is_branch: echo "" --- --map "grep -Pq '.+' && echo 'branch=<is_branch>'" --header "are you adding submodule from a specific branch? Type the branch name if yes, or leave empty if no."

I want to create an optional example. If I write something, I must append --branch= to the written argument. Your workaround doesn't work here.

The solution would be

# add submodule
git submodule add <prefix><is_branch>

$ is_branch: echo "" --- --header "are you adding submodule from a specific branch? Type the branch name if yes, or leave empty if no."
$ prefix: [[ -n $(echo <is_branch>) ]] && echo '--branch=' || echo '' --- --fzf-overrides '-1'

Again, a functional but ugly workaround. It would be much better to be able to write former solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants