Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Released: TBA.
[Diff](https://github.com/kvz/bash3boilerplate/compare/v2.4.2...master).

- [x] Add feature to edit/update comments in ini file (#132, @rfuehrer)
- [x] New magic variable `__origin` when called via symlink (@efelon)

## v2.4.2

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ We are looking for endorsements! Are you also using b3bp? [Let us know](https://
- [Lukas Stockner](mailto:[email protected])
- [Gert Goet](https://github.com/eval)
- [@rfuehrer](https://github.com/rfuehrer)
- [@efelon](https://github.com/efelon)


## License
Expand Down
2 changes: 2 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fi
__dir="$(cd "$(dirname "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")"
__base="$(basename "${__file}" .sh)"
__origin="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")")" && pwd)"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one problem with this is that readlink isn't ubiquitously available like this https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @kvz for pointing that out, and unwillingly throwing me into a rabbit hole with it 😉.
It seems with this restriction a one-liner solution cannot be achived. Could you imagine introducing a function like __readlink_f for this functionality?

I challenged myself to write an equivalent using cd, pwd -P and readlink, which should be available on all platforms. I got a lot right, but I'm struggling with relative symlinks. The function will not be very big, but ~100 lines it will be I guess.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been down that rabbit hole before, and i think it is a case where we should admit defeat unfortunately 😔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it out the 🐇🕳️ again. I'm not sure how deep I went, but I would love to here what you think, if you find the time: rdlink.md (rename it back to sh)

I ran a lot of tests but only debian based newer OSs and only bash 3.2.57 and bash 5.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very impressive! I'm happy to link to it in the README or even inline with the main template as a comment, but i don't think we can inline as much code with the template for this use case, i do apologize about that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i don't think we can inline as much code with the template for this use case, i do apologize about that

Please don't apologize. I totally get that.

What do you think about adding it to the src directory? Let me add a reference in the script to where it actually lives and I could make another PR. But I'm still a little hesitant because I don't really know if it performs under OSX or busybox.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we should first test it on osx and such. but if you don't mind, you could open the pr, we keep it pending for a bit while we spot issues on different systems, and then decide?

# shellcheck disable=SC2034,SC2015
__invocation="$(printf %q "${__file}")$( (($#)) && printf ' %q' "$@" || true)"

Expand Down Expand Up @@ -412,6 +413,7 @@ info "__i_am_main_script: ${__i_am_main_script}"
info "__file: ${__file}"
info "__dir: ${__dir}"
info "__base: ${__base}"
info "__origin: ${__origin}"
info "OSTYPE: ${OSTYPE}"

info "arg_f: ${arg_f}"
Expand Down