wfxr / forgit

:zzz: A utility tool powered by fzf for using git interactively.
MIT License
4.32k stars 136 forks source link

Backwards compatibility check reports functions and not only vars #256

Closed gbtec-markusmeier closed 1 year ago

gbtec-markusmeier commented 1 year ago

Check list

Environment info

Problem / Steps to reproduce

Problem

Forgit detects variables and functions in bash instead of only variables. See: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

Reproduction

Write a function that sets a FORGIT environment variable and then source forgit:

load_forgit() {
    export FORGIT_PAGER=less
    source "${HOME}/bin/forgit/forgit.plugin.sh"
}

load_forgit

Result

[Warn] Config options have to be exported in future versions of forgit.
[Warn] Please update your config accordingly:
[Warn]   export FORGIT_COPY_CMD
[Warn]   export FORGIT_DIFF_FZF_OPTS
[Warn]   export FORGIT_LOG_FZF_OPTS
[Warn]   export FORGIT_PAGER
[Warn]   export FORGIT_STASH_FZF_OPTS
[Warn]   export export FORGIT_PAGER
bash: export: `export FORGIT_PAGER': not a valid identifier

Expectation

The test in https://github.com/wfxr/forgit/blob/master/forgit.plugin.zsh#L24 should correctly report only variables, not strings in functions.

Deeper analysis

Bash's set returns (amongst others) the above defined function:

load_forgit ()
{
    export FORGIT_PAGER=less;
    source "${HOME}/bin/forgit/forgit.plugin.sh"
}

When grepping the result, line export FORGIT_PAGER=less; is processed.

Solution

Detect only variables in bash without functions:

https://unix.stackexchange.com/questions/176001/how-can-i-list-all-shell-variables

Note that set -o posix ; set is only available in bash, not in zsh, so we would need to distinguish that in https://github.com/wfxr/forgit/blob/master/forgit.plugin.zsh#L24