Fzf: Accessing shell functions inside preview window

Created on 21 Jul 2018  路  2Comments  路  Source: junegunn/fzf

  • Category

    • [ x] fzf binary

    • [ ] fzf-tmux script

    • [ ] Key bindings

    • [ ] Completion

    • [ ] Vim

    • [ ] Neovim

    • [ ] Etc.

  • OS

    • [x ] Linux

    • [ ] Mac OS X

    • [ ] Windows

    • [ ] Windows Subsystem for Linux

    • [ ] Etc.

  • Shell

    • [ x] bash

    • [ ] zsh

    • [ ] fish

Admittedly the usecase is minimal... but "--preview 'declare -f {}'" gives undesired results if it is passed a bash function that is not in the bashrc (even if the bashrc sources the other file). It seems to be because fzf runs these in a non-login shell. This would be convenient for editing bash functions by allowing you to search for all your bash functions and then display the bash code in the preview window.

question

Most helpful comment

Bash functions are not visible to child processes if you don't explicitly export them.

> foo() { echo foo; }
> declare -f foo
foo ()
{
    echo foo
}
> bash -c 'declare -f foo'
> export -f foo
> bash -c 'declare -f foo'
foo ()
{
    echo foo
}

All 2 comments

Bash functions are not visible to child processes if you don't explicitly export them.

> foo() { echo foo; }
> declare -f foo
foo ()
{
    echo foo
}
> bash -c 'declare -f foo'
> export -f foo
> bash -c 'declare -f foo'
foo ()
{
    echo foo
}

Or you can load your configuration files in preview command

fzf --preview 'source ~/.bashrc; declare -f {}'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

skamsie picture skamsie  路  3Comments

erusev picture erusev  路  3Comments

aleclarson picture aleclarson  路  3Comments

alistaircolling picture alistaircolling  路  3Comments

olethanh picture olethanh  路  3Comments