-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add a plugin.zsh file to be ZSH-framework friendly #15
base: main
Are you sure you want to change the base?
Conversation
Added sourcing the helper functions |
Sorry for the delay in getting back to you on this. I am not a zsh user so I'll need instructions on how to test this, how users are expected to use it, and what dependencies it has (i.e., does this require oh-my-zsh or something else to work?). Also, is this meant to supplant the built-in mechanism of modifying .zshrc? |
Basically, this is a supplement to manually modifying If a user is using any of the ZSH frameworks (not just oh-my-zsh), having a plugin file makes it easy to have the framework handle loading the integration. Many of the frameworks will even handle automatically running Basically if someone's using a framework, a plugin file will make it easier to use the integration, and if they aren't, it won't harm anything. I didn't see install instructions in the top level README or I would have added framework usage instructions there. |
Sorry for the delay in getting back to you. I really need detailed instructions on how to test this. |
ZSH frameworks can load plugins that follow the ZSH plugin standard during startup - for example, if the end user uses zgenom, they'd add The plugin file I added adds the repo's utilities directory to the user's |
@unixorn the Don't know if only @gnachman you can run it in a container to try it out. Here's a Dockerfile that you can use: FROM zshusers/zsh:5.9
RUN useradd -ms /usr/bin/zsh zshuser
RUN install_packages curl ca-certificates git
RUN echo 'source "$HOME"/.zshrc' >> /etc/profile.d/zsh
USER zshuser
WORKDIR /home/zshuser
ENV HOME=/home/zshuser
ENV ZDOTDIR=/home/zshuser
ENV ZIM_HOME=/home/zshuser/zimfw
RUN curl -fsSL --create-dirs -o ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
RUN echo '[[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]] \
&& source ${ZIM_HOME}/zimfw.zsh init -q; \
source ${ZIM_HOME}/init.zsh' >> .zshrc
RUN echo 'zmodule unixorn/iTerm2-shell-integration --branch add-plugin-file' >> .zimrc
ENTRYPOINT [ "/usr/bin/zsh", "-l" ] |
iterm2-shell-integration.plugin.zsh
Outdated
# Add utilities to our path | ||
PLUGIN_BIN="$(dirname $0)/utilities" | ||
export PATH=${PATH}:${PLUGIN_BIN} | ||
|
||
# And source the helper functions, too. | ||
source "${0:h}/shell_integration/zsh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're using the base-dir expansion ${0:h}
for sourcing, it'd be more consistent to use that as well when assigning PATH
. Also could potentially be a tiny bit slower to call dirname
as it's a sub-shell call. But I could be wrong here.
Here's my suggestion:
path+=("${0:h}/utilities")
You don't need to export, and this way you append to the tied array version of $PATH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just because I've too much time at hand, I wanted to check how many millis one could scrape off with the parameter expansion over the dirname
call. Turns out quite a few, though negligable in it's direct effect:
$ hyperfine --runs 500 'echo $(dirname $PWD)' 'echo "${PWD:h}"'
Benchmark 1: echo $(dirname $PWD)
Time (mean ± σ): 5.3 ms ± 2.0 ms [User: 0.5 ms, System: 1.9 ms]
Range (min … max): 1.2 ms … 26.0 ms 500 runs
Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
Benchmark 2: echo "${PWD:h}"
Time (mean ± σ): 0.6 ms ± 0.9 ms [User: 0.0 ms, System: 0.1 ms]
Range (min … max): 0.0 ms … 6.5 ms 500 runs
Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
Summary
echo "${PWD:h}" ran
8.98 ± 14.07 times faster than echo $(dirname $PWD)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your way is better, @nunico, I've switched to using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and renamed the plugin file
5a5e525
to
3a463d2
Compare
Sorry for taking so long to get to this. I'd like to merge it but I don't understand how it's supposed to be used. Where does this file go when installed? I'm not a zsh user so please assume I don't know anything about their plugin ecosystem. |
Basically, most ZSH frameworks can be configured to clone a repository. If there's a file named The iTerm2-shell-integration.plugin.zsh file I've added adds the repo's utilities directory to the user's The better frameworks will even periodically do a |
Basically, adding this file makes it a lot more convenient for ZSH framework users to use the integration and to keep the version they're using current. |
What do I do to try it out? |
If you source the file, it should update your At the end of the day, what ZSH frameworks do is make it easy to clone repositories, keep their copy up to date, and source their |
@unixorn I think what is needed here in the instructions is actual executable code that the user has to use to get the plugin working not just describing in English what to do. |
Added an install section to |
plugin.zsh files will be automatically detected and loaded by ZSH frameworks. Add one that adds the utilities folder to the user's `$PATH`. Signed-off-by: Joe Block <jpb@unixorn.net>
Signed-off-by: Joe Block <jpb@unixorn.net>
Add a section to README.md that details installing it with the three most commonly used ZSH frameworks. Signed-off-by: Joe Block <jpb@unixorn.net>
Anything else I need to do to get this merged? |
@unixorn Can you explain to me (a non-zsh user) how to test this? |
Testing
That's pretty much it. The reason to have a Keeping that functionality in the |
*.plugin.zsh
files will be automatically detected and loaded by ZSH frameworks.Add one that adds the utilities folder to the user's
$PATH
.