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

Makefile rule to create a sourceable version so that internals can be re-used. #10

Closed
chr15m opened this issue Dec 1, 2019 · 5 comments
Labels
enhancement New feature or request has-pr This issue has a candidate PR. question Further information is requested

Comments

@chr15m
Copy link
Owner

chr15m commented Dec 1, 2019

No description provided.

@chr15m chr15m added the enhancement New feature or request label Dec 1, 2019
@chr15m chr15m mentioned this issue Dec 1, 2019
@chr15m chr15m added the help wanted Extra attention is needed label Dec 1, 2019
@denisidoro
Copy link

Another possibility is to wrap the code outside a function into a function and call it if a certain predicate is satisfied. This way we can have the same file for both purposes:

# all the helpers
...

# code which is now in the "root"
main() { ... }

if ! ${FLK_SOURCEABLE:-false}; then
   main "$@"
fi

@chr15m
Copy link
Owner Author

chr15m commented Dec 1, 2019

If someone submits a PR for this I will merge it.

@chr15m
Copy link
Owner Author

chr15m commented Dec 2, 2019

https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced

[[ $_ != $0 ]] && echo "Script is being sourced" || echo "Script is a subshell"

@chr15m
Copy link
Owner Author

chr15m commented Dec 3, 2019

Hey @denisidoro I've pushed a new version of flk which is able to be sourced without running the REPL or load-script so you can re-use it's functions in another script. Can you test this out and let me know if it's what you need?

@chr15m chr15m added has-pr This issue has a candidate PR. question Further information is requested and removed help wanted Extra attention is needed labels Dec 3, 2019
@denisidoro
Copy link

I can't test it right now but It seems to cover my needs. Thanks!

@chr15m chr15m closed this as completed Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request has-pr This issue has a candidate PR. question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants