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

Why does --revert option use a variable instead of printing to stdout #5

Open
curusarn opened this issue Dec 12, 2019 · 1 comment
Open

Comments

@curusarn
Copy link
Owner

curusarn commented Dec 12, 2019

Why not return the revert command using standard output instead of using _bindfunc_revert variable.

Then you could use it just like ssh-agent:

revert_cmd=$(bindfunc arg1 arg2)
@curusarn
Copy link
Owner Author

curusarn commented Dec 12, 2019

When you need to capture the output of a function/command in bash you have pretty limited options.

The simplest way is: variable=$(function arg1 arg2)

The problem is that this way the function runs in a subshell. That usually doesn't matter. However, unlike other functions and commands bindfunc changes the current shell session (by adding the bindings) and when we run it in a subshell these changes stay in the subshell and don't affect the current shell.

There are some ways to capture the output of a function without running it in a subshell but none of them is simple.

To make the use of bindfunc simple and comfortable we use _bindfunc_revert as a special variable that holds the returned revert command.

If you have a better idea feel free to comment.

@curusarn curusarn changed the title Why does --revert option use a variable (_bindfunc_revert) instead of printing to stdout Why does --revert option use a variable instead of printing to stdout Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant