Comments (5)
hmmm.... I realized that maybe I can use --nth
to prevent call function/scripts to show {1}
in list, and {2}
in previous, and it indeed works :
$ env |
sed -r 's/^([a-zA-Z0-9_-]+)=(.*)$/\1 \2/' |
fzf --delimiter=' ' \
--preview='source ~/.marslo/bin/bash-color.sh; echo -e "$(c Ys)>> {1}$(c)\n$(c Wi).. {2}$(c)"' \
--with-nth=1
getenv-preview.mov
but I'm still curious how to call function instead of scripts, for more complex process to preview
from fzf.
suddenly realized that, I'm struggling for so long is because of "
and '
are different behavior in --preview
!
I was using "
( double quotes ) in the very beginning, and it's not working, so I decided to using function instead of cmd. Accidental I was using '
( single quote ) and it worked !!
here are details:
- double quotes
$ env | sed -rn 's/^([a-zA-Z0-9]+)=.*$/\1/p' | fzf --preview-window 'up,30%,wrap,rounded' \ --preview "_i={}; echo ${_i}"
- single quote
$ env | sed -rn 's/^([a-zA-Z0-9]+)=.*$/\1/p' | fzf --preview-window 'up,30%,wrap,rounded' \ --preview '_i={}; echo ${_i}'
details:
fzf-preview-single-double-quotes.mov
my environment:
$ sw_vers
ProductName: macOS
ProductVersion: 14.2.1
BuildVersion: 23C71
$ bash --version
GNU bash, version 5.2.26(1)-release (x86_64-apple-darwin23.2.0)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ fzf --version
0.45.0 (brew)
from fzf.
I'd like to know whether if any elegant way can handle call a function in --preview instead of call a shell script file
Functions are not visible to child processes unless they are exported with export -f
.
#!/usr/bin/env bash
foo() {
echo foo
}
export -f foo
fzf --preview 'foo'
Note
Please note, if your login shell isn't bash
(for example, on macOS the default is zsh
), the
function still won't work unless you change the SHELL
environment variable to bash
.
SHELL="$(which bash)" fzf --preview 'foo'
fzf starts child processes using $SHELL -c COMMAND
Alternatives:
- make it a string and call the variable
foo=$'echo foo'
: | fzf --preview "$foo"
- place the function in a file and source it
foo() {
echo foo
}
: | fzf --preview 'source /path/to/file/with/function; foo'
from fzf.
I'd like to know whether if any elegant way can handle call a function in --preview instead of call a shell script file
Functions are not visible to child processes unless they are exported with
export -f
.#!/usr/bin/env bash foo() { echo foo } export -f foo fzf --preview 'foo'
export -f foo
work like a charm !
Alternatives:
- make it a string and call the variable
foo=$'echo foo' : | fzf --preview "$foo"
- place the function in a file and source it
foo() { echo foo } : | fzf --preview 'source /path/to/file/with/function'; foo'
for alternatives solution, how to handle fzf
get from pip ( |
) ?
i.e.:
$ foo() { echo ${!1}; }
# fzf from `env | sed`:
$ env | sed -rn 's/^([a-zA-Z0-9]+)=.*$/\1/p' | fzf --preview-window 'up,30%,wrap,rounded' --preview "foo {} "
I've tried:
: | env | sed ... | fzf # < not working
env | sed ... | : | fzf # < not working
from fzf.
I've tried:
: | env | sed ... | fzf # < not working env | sed ... | : | fzf # < not working
I'm not entirely clear on the problem. The colon :
1 signifies nothing and can be omitted. It's
only useful if you want to initiate fzf
with an empty list.
foo=$'input={};echo "${!input}"'
command env | sed -rn 's/^([a-zA-Z0-9]+)=.*$/\1/p' | SHELL=bash fzf --preview "$foo"
Footnotes
from fzf.
Related Issues (20)
- Can't bind C-z to a readline function without getting 'readline: maximum macro execution nesting level exceeded' with fzf-cd - Alt-C HOT 5
- preserve whitespace flag s not working? HOT 1
- How to find file from zoxide result ? HOT 1
- Broken zsh shell integration on 0.51+ HOT 1
- last commit broke fzf.vim integration HOT 1
- code **<TAB> doesn't execute fzf HOT 4
- execute(echo {}) does not work with tmux integration on v0.53.0 HOT 2
- Divide by zero with --tiebreak=end for long-line inputs HOT 1
- Windows: Mouse-clicking doesn't work properly in bash HOT 1
- Merge fish history before showing history widget HOT 3
- Vi-mode for input field navigation and editing. Maybe by introducing readline support? HOT 1
- Ability to control search order (or have `--nth` respect it) HOT 2
- Cannot exclude symbolic links from search HOT 9
- `--walker-skip symlink-to-dir` not skipped
- Missing directory slashes when completion chosen HOT 2
- make CTRL-T work with directories outside the current one HOT 3
- Dynamically changing colors HOT 1
- Dynamically changing preview label position HOT 4
- Panic when killing script since 83b6033 'main.go'
- Option to disable terminal beep when exiting search HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fzf.