1
0
Fork 0
mirror of synced 2024-10-31 15:28:57 -04:00

Compare commits

..

131 commits

Author SHA1 Message Date
Eric Nielsen
99a4dc396a
Respect NO_COLOR environment variable
See https://no-color.org/
2024-10-28 18:15:03 -05:00
Eric Nielsen
0392926d61
Nothing to do on check action for mkdir tool 2024-10-25 11:15:11 -05:00
Eric Nielsen
e8e26c1b13
Also output zimfw config and zimfw script paths
in info action, following symlinks if any.
2024-10-10 09:17:22 -05:00
Eric Nielsen
84c59ede0e
v1.15.1 2024-10-09 19:28:54 -05:00
Eric Nielsen
331f1c5548
Preserve original module if reinstall fails
instead of deleting it first. Also minor fix in mkdir tool which was not
properly skipping the reinstall action.
2024-10-09 19:24:01 -05:00
Eric Nielsen
f4bc83da7e
v1.15.0 2024-10-08 18:42:34 -05:00
Eric Nielsen
4bb6172900
Add --if-ostype option to zmodule 2024-10-08 18:25:12 -05:00
Eric Nielsen
caa0c850ae
Add disclaimer comment to beginning of .zimrc
Also remove unneeded check from zmodule, since now it can only be called
from _zimfw_source_zimrc.
2024-10-07 09:29:08 -05:00
Eric Nielsen
92c3eede1f
Add reinstall action
that removes and then installs again the modules that failed any of the
"pre" checks. This runs the "pre" checks (as "prereinstall") and, if the
checks failed (return code is not 0), then proceeds with the reinstall
for each module.

Also minor change of the use of the word "upgrade", reserving it to mean
upgrading zimfw.

Fixes #542
2024-10-07 08:52:41 -05:00
Eric Nielsen
869a8f5f17
Ask before uninstallng each unused module
instead of asking just once for all. Keep printing number of unused
modules, even if zero.
2024-09-16 18:30:09 -05:00
Eric Nielsen
3fe3ba2b48
Check degit URL in pre action
as we also check the git URL in the pre action there.
Don't use _zimfw_source_zimrc with a flag when no _znames is needed
(flag 1) or _zfpaths, _zfunctions, _zcmds are needed (flag 2).
2024-09-16 18:06:12 -05:00
Eric Nielsen
ded640ed80
Hide git-related information in list for mkdir tool
as that information has no effect for that tool.
2024-08-26 19:46:25 -05:00
Eric Nielsen
880ed131a1
Pre check module before running tool
Check if module is correctly installed before running any other action
on the module.

See #542
2024-08-20 08:07:10 -05:00
Eric Nielsen
7f3491b1bb
Don't autoload zimfw if no config file exists
instead of if no ${ZIM_HOME} exists. If current user has no config file,
then most likely they're sourcing the init.zsh generated by another user
in the same machine.
2024-08-16 23:46:32 -05:00
Eric Nielsen
6166fce1a1
v1.14.0 2024-06-25 12:32:13 -05:00
Eric Nielsen
3b7908dca1
Try to upgrade zimfw.zsh if it's a symlink
Initially the idea was to not allow this so upgrades are disabled when
the script is installed using a package manager, but this is an
unnecessary complexity. Making it less smart and more predictable.
2024-06-25 09:08:10 -05:00
Eric Nielsen
0785d87ea4
Improve error messages and check ZIM_HOME
for write permission. Also, if ZIM_HOME is not defined, don't "autoload"
the zimfw function, since this is going to be a scenario where the user
only has something like `source /path/to/zim/init.zsh` in their .zshrc.
2024-06-21 15:43:48 -05:00
Eric Nielsen
eb37844857
Disable background version check if no write access
to zimfw.zsh or if it's a symlink or not a regular file. It does not
make sense to show a message to user saying "Run zimfw upgrade to
upgrade" if the action will then fail.
2024-06-18 17:40:12 -05:00
Eric Nielsen
3e812ed311
Don't upgrade zimfw.zsh if not in a writable path
or if it's a symlink or not a regular file. This makes more sense now
that zimfw.zsh can exist outside ZIM_HOME, that the same file can be
used my multiple users in the same machine, and that it is going to be
possible to install it with a package manager once it's stable to do so.
2024-06-18 17:13:53 -05:00
Eric Nielsen
897afc9cf9
Reapply "Use ${HOME} in generated static init.zsh script"
This reverts commit 9a47fde0c8.
2024-06-17 07:29:19 -05:00
Eric Nielsen
76164d6217
Allow zimfw.zsh to exist outside ZIM_HOME
and change initialization so ZIM_HOME is required before sourcing the
script.
2024-06-14 20:17:07 -05:00
Eric Nielsen
9a47fde0c8
Revert "Use ${HOME} in generated static init.zsh script"
This reverts commit 06f8bc71a3.

This breaks allowing a machine to have just one init.zsh script that can
be sourced by different users.
2024-06-10 07:52:45 -05:00
Eric Nielsen
06f8bc71a3
Use ${HOME} in generated static init.zsh script
Fixes #509
2024-06-09 11:32:08 -05:00
Eric Nielsen
9dc4056c4e
chmod a+r init.zsh so all users can read it
This better allows a global instalation of Zim that can be sourced by
other users in the same machine.

See #486
2024-06-03 08:51:20 -05:00
Eric Nielsen
96f60da366
Improve zimfw's degit error message
Hopefully make it clearer when either the git or the degit tool is being
used.

See #535
2024-05-30 09:38:44 -05:00
Eric Nielsen
cdd9258d5c
Don't expose the zmodule function outside zimfw
Don't want to maintain extra code to allow zmodule to run outside zimfw.
This has no added benefit and might confuse users. If you were calling
zmodule in the shell just to get the help message, hopefully you can
look that up in the documentation instead.
2024-05-30 09:21:16 -05:00
Eric Nielsen
4fcc85b2db
Update README.md with ZIM_CONFIG_FILE instructions
Also add git-info and duration-info modules to the basic templates for a
better user experience.
2024-05-26 12:44:49 -05:00
Eric Nielsen
4200e6cdb3
v1.13.1 2024-04-28 14:07:41 -05:00
Eric Nielsen
c86223f473
Don't use tar --strip
as it's not compatible with BSD distributions.
Fixes #534
2024-04-28 14:06:24 -05:00
Eric Nielsen
39d2087ad4
v1.13.0 2024-02-16 21:06:36 -05:00
Eric Nielsen
2e9256a567
Add new mkdir tool to generate empty modules
This will allow creating modules that contain only externally generated
files. For example, this is how I currently use it to generate modules
for code that is supposed to be eval'ed:

    zmodule-eval() {
      local -r zcommand=${${=1}[1]} ztarget=${1//[^[:alnum:]]/-}.zsh
      zmodule custom-${zcommand} --use mkdir --if-command ${zcommand} \
          --cmd "if [[ ! {}/${ztarget} -nt \${commands[${zcommand}]} ]]; then ${1} >! {}/${ztarget}; zcompile -UR {}/${ztarget}; fi" \
          --source ${ztarget}
    }
    zmodule-eval 'starship init zsh'
    unfunction zmodule-eval
2024-02-16 20:41:29 -05:00
Eric Nielsen
8bec2f7549
Add --if-command option to zmodule 2024-01-22 21:36:17 -05:00
Eric Nielsen
5f649d3031
v1.12.1 2023-09-16 13:26:53 -05:00
Eric Nielsen
26151d2f54
Remove prompt expansion from print statements
and replace the foreground color and bold expansions by ANSI escape
codes. This should make the print calls now safe and no expansion at all
should happen as we're using `-R` -- unless the `-e` flag is given.
Fixes #521. Closes #522
2023-09-16 13:21:14 -05:00
Eric Nielsen
d33d632ec1
Use --sort=-v:refname in _zimfw_check_version
to sort tags, instead of using Zsh's `(On)`. The tags will come sorted
already.
2023-09-15 19:55:43 -05:00
Eric Nielsen
e0d067977c
v1.12.0 2023-07-17 18:55:26 -05:00
Eric Nielsen
49386cad6d
Make forced check-version asynchronous (again)
as it was before a34b8dab64.
Don't make zimfw hang in the foreground waiting for git to connect to
GitHub, mainly because the waiting can take too long in case of
connection issues or no network. Also set git timeout to 30 seconds so
background check also does hang for too long, just it case.

Fixes #514
2023-06-16 20:24:33 -05:00
Eric Nielsen
0566b9b8a3
Use _zimfw_print 2023-06-15 09:33:14 -05:00
alesandar
f9648e07a9
Handle module root directories without write permission
Closes #513. Fixes #512
2023-06-15 09:26:37 -05:00
Eric Nielsen
db96076cf0
fixup! Don't use a new shell to run tool anymore 2023-04-01 08:31:09 -05:00
Eric Nielsen
f93e43e8a5
Tools run in a subshell 2023-03-31 20:34:26 -05:00
Eric Nielsen
67de6ec25b
Don't resolve symlinks when building init.zsh
So init.zsh is consistent after symlinks change to point to something
else. See zimfw/completion#15
2023-03-30 08:38:12 -05:00
Eric Nielsen
ee93f7944f
Don't use a new shell to run tool anymore
This was needed when we were using xargs, but we're already using zargs
instead for quite some time. Pro is that now common functions are reused
instead of repeated. Con (or change) is that due to that reuse, and in
favor of simplification, the warning for a module with git submodules in
degit is in a separate line from a separate print call now.

Also fix regressions from recent commits:
- Need to call _zimfw_source_zimrc twice with 1 and 2 flags instead of
  with flag 3, since flag 2 must be used after module is installed or
  updated.
- Need to call _zimfw_print_okay from the function that handles on-pull,
  since we want to include the on-pull output in verbose mode. This
  function was called just `handle` before, now it's called
  _zimfw_pull_print_okay.

Still need to figure out how to return a final error code from
_zimfw_run_tool_action.
2023-03-28 07:56:37 -05:00
Eric Nielsen
312b08c20a
Fix missing -C in command git 2023-03-26 16:51:24 -05:00
Eric Nielsen
903e0e5249
Add check and rename version-check to check-version
actions. Return 4 if there's a zimfw update from check-version. Don't
return a specific error code if there are module updates from check, as
it uses zargs to check all and each check runs in a separate shell. Need
to figure out how to propagate all that to a final error code.

See #503
2023-03-26 09:34:07 -05:00
Eric Nielsen
b7b33f3786
Also output LANG LC_* parameters in info action 2023-03-24 09:46:44 -05:00
Eric Nielsen
a34b8dab64
Add version-check action
And don't run the dumping of the .latest_version file in
_zimfw_version_check in the background (with `&!`) anymore.

See #503
2023-03-24 08:44:52 -05:00
Eric Nielsen
222c971542
v1.11.3 2023-02-25 19:44:58 -05:00
Eric Nielsen
6a24459de9
Deprecate check-dumpfile action
The completion module alone will handle checking the dumpfile.
See https://github.com/zimfw/completion/pull/12
2023-02-25 19:03:37 -05:00
Eric Nielsen
fff151be09
v1.11.2 2023-02-16 07:59:49 -05:00
Eric Nielsen
f71bff5418
Quote path names in init.zsh
to properly handle path names with spaces.
Fixes #497
2023-02-16 07:51:30 -05:00
Eric Nielsen
d10d7c627c
Revert "Further improve check-dumpfile action accuracy"
This reverts commit e47eaae2e4.
2023-02-16 07:51:30 -05:00
Eric Nielsen
e47eaae2e4
Further improve check-dumpfile action accuracy
Previous change fixed the old dumpfile vs. new dumpfile check, but
removed an existing (but flawled) old Zim fpath vs. new Zim fpath check.
We should be doing both checks the right way now.
2023-02-06 19:19:15 -05:00
Eric Nielsen
05164357b8
v1.11.1 2023-02-04 09:47:19 -05:00
Eric Nielsen
7778e9749a
Update LICENSE 2023-02-04 09:46:11 -05:00
Eric Nielsen
a434fda508
More accurate check-dumpfile action
by using the `_zim_dumpfile_fpath` variable set by the completion module
[here](33737e8c15/init.zsh (L11))
right before `compinit` is run.
2023-02-03 18:56:16 -05:00
Eric Nielsen
281cde57f7
v1.11.0 2022-12-18 16:09:04 -05:00
Eric Nielsen
e54958b91c
Allow customizing .zimrc file path
with the ZIM_CONFIG_FILE environment variable.
Fixes #479.
2022-10-23 19:34:14 -05:00
Eric Nielsen
3959a7f4e0
Add --if option to zmodule
Fixes #355
2022-10-06 19:52:57 -05:00
Eric Nielsen
8a9d63c522
Fix quoting string in glob
so it does not get expanded as a glob itself, if it contains special
characters.
2022-09-28 19:42:05 -05:00
Eric Nielsen
3351dc6dac
Update CHANGELOG.md 2022-09-27 17:50:52 -05:00
Eric Nielsen
238da94b54
v1.10.0 2022-09-27 17:45:16 -05:00
Eric Nielsen
05b8e0cdf2
Add --root option to zmodule
which makes it straighforward to use repositories that contain multiple
modules, like sorin-ionescu/prezto or ohmyzsh/ohmyzsh.
2022-09-26 20:33:49 -05:00
Eric Nielsen
887bfd6a03
Update info action output and update README.md
Show the value of some relevant environment variables instead of calling
uname, which might show private information like the host name.

Other minor fixes regarding output.
2022-08-02 12:49:09 -05:00
Eric Nielsen
b5703f9e17
Update CHANGELOG.md 2022-05-24 16:29:36 -05:00
Eric Nielsen
a620953556
v1.9.1 2022-05-24 16:25:32 -05:00
Eric Nielsen
5bcfb8cc9f
Override repository options along zmodule calls
for the same module name. Other minor fixes:
* Show skipping already installed modules with install action and `-v`.
* Consider external module dirs when calling compile action directly, by
  making sure _zimfw_source_zimrc is called first.
* Ignore return value from `zargs` with `-P`, as it's oddly returning
  123 since Zsh 5.9. Maybe related to these changes:
  67f932e7c5
2022-05-17 18:43:59 -05:00
Eric Nielsen
d6b4aa6ff4
v1.9.0 2022-05-09 18:36:03 -05:00
Eric Nielsen
741bb78a04
Add --on-pull option to zmodule
Fixes #456
2022-05-07 16:31:08 -05:00
Eric Nielsen
e0fe8ef9c9
Update README.md with one more .zimrc example
and hopefully make it clear that the completion module is optional, and
just for users that prefer our predefined configuration instead of their
own set up calling compinit directly.
2022-03-18 22:43:01 -05:00
Eric Nielsen
98fd5fa4da
Update README.md 2022-03-06 17:28:23 -05:00
Eric Nielsen
8b8938f414
Update CHANGELOG.md 2022-03-04 09:17:30 -05:00
RayZ0rr
97133502fd
Update README.md with badges, ToC, sample rc files
Closes #453

Co-authored-by: Eric Nielsen <eric@amalgamar.com.br>
2022-03-03 21:19:40 -05:00
Eric Nielsen
4fe7c66e07
v1.8.0 2022-01-25 17:19:34 -05:00
Eric Nielsen
72fe20c5bd
Update LICENSE 2022-01-25 17:14:27 -05:00
Eric Nielsen
27dcd4832e
Add --no-submodules option to zmodule
Fixes #409
2022-01-25 09:32:50 -05:00
Eric Nielsen
016e498bd6
Also work when _zim_fpath is not set
when doing `zimfw check-dumpfile`, otherwise it won't work until init.zsh
is rebuilt, because it's a newly introduced variable.
2022-01-24 18:58:28 -05:00
Eric Nielsen
ac2843d8c8
Simplify check-dumpfile to do the same as compinit
first because simpler is usually better, and second because we cannot
always guarantee that the .latest_comp file, which was holding the list
of all completion functions, is consistently in sync with the dumpfile
that is generated afterwards.
2022-01-18 20:51:11 -05:00
Eric Nielsen
35e1d2ea48
Add check-dumpfile action
that removes the dumpfile if it's outdated, so it will get dumped again
when the shell starts next time. We're not using comdump because wrapped
ZLE widgets cannot or should not be identified by compdump when they
have a different name than the original one.
See https://github.com/zsh-users/zsh-syntax-highlighting/issues/851
2022-01-18 20:34:36 -05:00
Eric Nielsen
bd765df785
Update README.md 2022-01-11 23:03:46 -05:00
Eric Nielsen
afd35f6590
v1.7.0 2022-01-11 22:51:06 -05:00
Eric Nielsen
92bfa96993
Further clean up and simplify code
@startup_files_glob is not used anymore.
2022-01-11 11:29:47 -05:00
Eric Nielsen
2491856a7b
Clean up and simplify code
No need to set zscriptglob in _zimfw_build_login_init anymore.
Use _zimfw_print in _zimfw_compile.
And other minor simplifications.
2022-01-10 20:41:50 -05:00
Eric Nielsen
cfc955c9fd
Deprecate compile in background via login_init.zsh
Changes are:
  * Don't compile in the background anymore, only via the `zimfw` tool
    after actions where scripts can change (build, install, update)
  * Move compilation of the completion dumpfile to the completion module:
    9386a76eac/init.zsh (L10-L11)
  * Don't compile users startup scripts anymore (.zshenv, .zshrc, etc.)
  * Make output of `zimfw init` friendlier for the terminal startup
    screen when called without `-q`.

See https://github.com/romkatv/zsh-bench/pull/11#issuecomment-994979683
and https://github.com/romkatv/zsh-bench#cutting-corners

Regarding not compiling users startup scripts anymore, I'm choosing to
only compile the modules' scripts at least for the reason that compile
won't happen so ofter anymore -- it will only happen when the user calls
the `zimfw` build, install or update actions. So it makes more sense to
only compile the files that `zimfw` has control over changes...

Closes #450
2022-01-10 09:29:32 -05:00
Eric Nielsen
90de91ab4f
v1.6.2 2021-11-21 14:41:25 -05:00
Eric Nielsen
a5fb148ccf
Force local zsh emulation options
so the code is not broken by unexpected option changes, like

    setopt RC_EXPAND_PARAM

which breaks

    print -R 'fpath=('${${_zfpaths#${~zpre}}:A}' ${fpath})'

in the _zimfw_build_init function, for example.

See #444.
2021-11-21 14:39:20 -05:00
Eric Nielsen
de685e8ef3
Minor text updates in warnings, errors, and usages 2021-11-15 19:37:40 -05:00
Eric Nielsen
e060934a9e
.git can be either a directory or a file
Git submodules usually have .git as file, actually. Zim modules should
not be git submodules, but we don't want Zim to be too smart here either.
See https://git-scm.com/docs/gitrepository-layout#_description
2021-11-11 13:46:28 -05:00
Eric Nielsen
cd71c8d228
Use git -C instead of changing to the module dir
when doing update using the git tool.
2021-11-10 22:50:17 -05:00
Eric Nielsen
6e7c6a269d
Update README.md formatting
to be closer to the one used in https://zimfw.sh/docs/commands/
2021-11-08 20:27:14 -05:00
Eric Nielsen
ab613bf398
Narrow zmodule help text again
to avoid the horizontal scroll in the https://github.com/zimfw/zimfw
GitHub homepage, as GitHub made the width of the pre block further
narrower. (It's 94 characters now, was 97 before)
2021-11-08 20:05:32 -05:00
Eric Nielsen
503f2daf4c
v1.6.1 2021-11-08 12:03:49 -05:00
Eric Nielsen
811616cc60
Add missing -l in git tool print_okay
This fixes a regression introduced in commit b1edcf34d0.

Also don't use any option after `-R` just to be safe. The zshbuiltins(1)
manual states:

> Only the -e and -n flags are recognized after -R; all other arguments
> and options are printed.
2021-11-08 11:38:56 -05:00
Enno
a292ca40ac
Update README.md
The new zshrc template will download the zimfw script if missing.
See 023e13f042/src/templates/zshrc (L100-L108)

Similar to https://github-wiki-see.page/m/junegunn/vim-plug/wiki/tips

Useful if the ZIM_HOME folder is not version tracked in a dotfiles repo.

Closes #440
2021-11-06 17:36:48 -05:00
Eric Nielsen
d7229bb6bc
v1.6.0 2021-11-06 17:04:47 -05:00
Eric Nielsen
4259e64d22
Update init action to also install new modules
so users don't get a "Not installed" error when they add a new module to
.zimrc and forget to run `zimfw install` after that.

See #440
2021-10-26 11:15:40 -05:00
Eric Nielsen
a86f69a2f1
Warn when module isn't installed with current tool
instead of showing it as an error. This change allow the message to be
omitted with `-q`.
2021-10-19 08:36:51 -05:00
Eric Nielsen
de7d2b131f
More verbose output in install and update actions
listing modules that are frozen or exernal.

Also be less colorful. And some other minor fixes: allow autoloading a
function name that starts with `-`, and add required quotes around
command subsitution (otherwise words are split).
2021-09-29 21:22:28 -05:00
Eric Nielsen
1d5c0c18d1
Initalization options are all auto or all manual
in `zmodule`, since there's no way to unset a default value to "nothing".
2021-09-26 19:47:44 -05:00
Eric Nielsen
b1edcf34d0
Use print -l to print multiple lines
and also remove extra quotes. Still only leave redundant quotes in

    zstyle -s 'context' style 'name'

as that's kind of a convention already.
2021-09-23 14:29:40 -05:00
Eric Nielsen
6ca4690edc
Further improve handling of external modules
Fix computing the list of unused modules by using the full `_zdirs`
instead of just the `_zmodules` names. The fixed code was even simpler
and cleaner, which makes it even more satisfying.  :- )

Show "not found" instead of "not installed" error when an external
module dir does not exist, since we don't install external modules.
2021-09-23 11:44:31 -05:00
Eric Nielsen
92e6d6b74b
Don't output warnings in quiet mode
For sake of simplicity, and also to distinguish warnings from errors.
So now we have:
  * errors: output to stderr, are **not** silenced with `-q`
  * warnings: output to stderr, are silenced with `-q`
  * info: output to stdout, are silenced with `-q`
  * solicited output (like help, info, or list): output to stdout, does
    not make sense to be silenced with `-q`

We also only have warning in 3 situations so far...  :- )
2021-09-21 16:47:04 -05:00
Eric Nielsen
9a67adfe3b
Update zimfw help text to be more detailed
and add more comments to the code to also hopefully make it clearer.
2021-09-21 08:27:56 -05:00
Eric Nielsen
7deda9c7f4
Show a more informative error when running zmodule
from the shell. This means getting

    zmodule: Must be called from ${ZDOTDIR:-${HOME}}/.zimrc

and the full zmodule usage, instead of getting

    zsh: command not found: zmodule

Fixes #430
2021-09-20 21:21:27 -05:00
Eric Nielsen
b3b282f0f6
Move .github and CODE_OF_CONDUCT.md to .github repo
See
https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/creating-a-default-community-health-file
2021-09-20 16:12:55 -05:00
Eric Nielsen
e097e6bf71
Add list action, don't run tool on external module
Using the `list` action with `-v` shows all current details for the
existing modules.
Don't try to install or update external modules, since they have an
absolute path instead of a valid URL.
2021-09-19 13:37:13 -05:00
Eric Nielsen
3e1a89ae4b
Update issue templates
The config.yml does not support markdown yet.  :- (
2021-09-02 08:49:14 -05:00
Eric Nielsen
aaaa754115
Update issue templates 2021-09-02 08:48:12 -05:00
Eric Nielsen
476bb6b320
Fix warning when WARN_CREATE_GLOBAL is set
and ZIM_HOME is not. It can be reproduced with:

    unset ZIM_HOME
    setopt WARN_CREATE_GLOBAL
    zimfw info

and the warning is:

    zimfw.zsh:33: scalar parameter ZIM_HOME created globally in function zimfw
2021-08-31 18:42:30 -05:00
Eric Nielsen
c021507ac7
Update issue templates
Closes #437
2021-08-29 11:26:41 -05:00
Eric Nielsen
df70a1ca99
Fix update with git tool when module dir is under
an unresolved symlink.
2021-08-26 18:15:39 -05:00
Eric Nielsen
3bbddf2a23
Update zmodule help message 2021-08-25 16:12:48 -05:00
Eric Nielsen
da9270d651
Update ISSUE_TEMPLATE.md 2021-08-25 16:01:34 -05:00
Eric Nielsen
8f3de99700
Update ISSUE_TEMPLATE.md 2021-08-25 15:53:14 -05:00
Eric Nielsen
e89793c87e
Update CHANGELOG.md README.md
with new changes from version 1.5.0.
2021-08-10 10:55:04 -05:00
Eric Nielsen
c51898fef0
v1.5.0 2021-08-10 09:56:25 -05:00
Eric Nielsen
35cd6f5f23
Be careful with multiple variables in the same line
as one cannot depend on the other.
2021-08-09 22:28:13 -05:00
Eric Nielsen
f6b623f515
Do git clone with core.autocrlf=false
to override any `core.autocrlf=true` the user could have set globally.
Fixes #404
2021-08-09 20:32:32 -05:00
Eric Nielsen
6700933262
Update README.md with speed graph
generated via GitHub Action in
https://github.com/zimfw/zsh-framework-benchmark/actions
2021-08-08 20:44:37 -05:00
Eric Nielsen
7d43589843
Add zstyle to set default zmodule tool
and also simplify code by setting multiple variables at once. This
should make the resulting script a tiny bit smaller, while not
compromising on legibility.
2021-07-11 15:58:15 -05:00
Eric Nielsen
2c8f8e348e
Update help and error messages
and bring back the help message for -z|--frozen that was deleted
accidentally.
2021-07-01 18:08:25 -05:00
Eric Nielsen
9a0f336ac1
Collapse manual installation in README.md
so the text is more concise and friendlier for unexperienced users.
2021-07-01 18:01:29 -05:00
Eric Nielsen
5db2b66052
Allow uninstalling modules with custom names
that have a slash, as that yields subdirectories. For example:

    zmodule duration-info -n zimfw/duration-info
    zmodule git-info -n zimfw/git-info
    zmodule asciiship -n zimfw/asciiship
2021-06-17 20:05:01 -05:00
Eric Nielsen
7d533fcecd
Add diff to degit
so we show at least some change log. Not the same as a git log, and I
hope this is good info for users.
2021-04-23 19:15:20 -05:00
Eric Nielsen
89d6f7b7f3
Rename .zim_degit_info to .zdegit
Nicer and way simpler!
2021-04-21 19:37:47 -05:00
Eric Nielsen
2869851379
Fix degit update
Had to remove ${DIR} before renaming ${dir_new} to ${DIR}.

Also also add ${REV} to the info file, in case we need it in the future,
when extracting Zim's degit as a standalone tool for example.
2021-04-08 16:28:47 -05:00
Eric Nielsen
cffd456556
Add new degit tool \o/
and rename previous to git.

Tools allow for different install and update scripts. The git tool does
what the previous implementation did (installs and updates using the git
client). The new tool installs and updates with the GitHub API, not
using the git client, but using curl/wget and tar instead.

Closes #373
2021-04-07 17:54:47 -05:00
Eric Nielsen
b4b9829360
v1.4.3 2021-03-19 18:44:53 -05:00
Eric Nielsen
163d36b61b
Use Zsh scripting instead of sed, sort and tail
`foo | sed 's?^.*/v??' | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -n1` is
the same as `${${(On)${(f)"$(foo)"}##*v}[1]}`. We don't want to depend
on external tools that might not be available in all platforms.
2021-03-19 18:14:31 -05:00
Eric Nielsen
65783e61ed
Use 2 as exit code for usage errors
See https://tldp.org/LDP/abs/html/exitcodes.html
2021-03-19 17:13:21 -05:00
Eric Nielsen
f7c0bbeb36
Prefer the prezto module format
to avoid conflicts when we have Zim modules made to also be compatible
with ohmyzsh, like https://github.com/zimfw/pvenv
We don't want to be affected by the noise a `${module_name}.plugin.zsh`
file creates, as we always want to source `init.zsh` when a module also
has a `functions` subdir. Hope this better protects us from the "wild
west out there".
2021-03-16 17:04:40 -05:00
42 changed files with 2420 additions and 927 deletions

View file

@ -1,25 +0,0 @@
Please check the existing issues to make sure you're not duplicating a report.
For bug reports, please provide the following information:
In a terminal, run `zimfw info` and paste the output below:
```
#Paste the output here
```
- gist of .zimrc:
- gist of .zshrc:
Description
-----------
Steps to reproduce
------------------
Images or other information
---------------------------

View file

@ -1 +0,0 @@
Please follow Zim's [code style guidelines](https://github.com/zimfw/zimfw/wiki/Code-Style-Guide).

View file

@ -7,7 +7,270 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
_No unreleased changes._
### Added
- Also output zimfw config and zimfw.zsh script paths in `info` action,
following symlinks if any.
- Don't output colors if `NO_COLOR` environment variable is set to a non-empty
value.
## [1.15.1] - 2024-10-10
### Fixed
- Preserve original module if reinstall fails instead of removing it first.
## [1.15.0] - 2024-10-08
### Added
- `reinstall` action, that removes and then installs again the modules that
failed any of the checks: (See [#542](https://github.com/zimfw/zimfw/issues/542))
- module was installed with the defined tool,
- module URL matches the defined one.
- `--if-ostype` option to `zmodule`. This option is equivalent to
`--if "[[ \${OSTYPE} == ${1} ]]"`.
### Changed
- Ask before uninstalling each unused module, instead of asking just once for
all.
- Add disclaimer comment at beginning of .zimrc file.
## [1.14.0] - 2024-06-25
### Changed
- Don't expand `${HOME}` in the init.zsh script. (See
[#509](https://github.com/zimfw/zimfw/issues/509))
- Don't allow calling `zmodule` from the command line. Let it fail with "command
not found" instead, as it's intended to be used only in the .zimrc script.
- `ZIM_HOME` must be defined before sourcing zimfw.zsh. All documentation was
already doing so, hence not considering this as a breaking change.
- Allow zimfw.zsh to exist anywhere else, not only inside `ZIM_HOME`. This
enables installing the zimfw.zsh script independently with a package manager.
- Don't try to upgrade if sourced zimfw.zsh is not in a writable path.
- Don't try actions that write to `ZIM_HOME` if user has no write permissions
there.
### Fixed
- Update error messages to hopefully make it clearer when either the git or the
degit tool is being used.
- Set read permissions to generated init.zsh script, so it can be read from
other users.
## [1.13.1] - 2024-04-28
### Fixed
- The `--strip` option in tar command is not BSD compatible.
## [1.13.0] - 2024-02-17
### Added
- `--if-command` option to `zmodule`. This option is equivalent to
`--if "(( \${+commands[${1}]} ))"`.
- `mkdir` tool option in `zmodule` that creates an empty directory. This allows
creating modules that contain only externally generated files.
## [1.12.1] - 2023-09-16
### Fixed
- Expansion of prompt sequences in print statements causing text between
backticks to be executed by the shell.
## [1.12.0] - 2023-07-17
### Added
- `check-version` action, that immediately checks if a new version of `zimfw` is
available and returns code 4 if there is one.
- `check` action, that checks if there are updates available for current modules.
- Output of `LANG` and `LC_*` parameters in `info` action.
### Changed
- Don't resolve symlinks when building init.zsh.
### Fixed
- Show warning when there's no write permission to compile Zsh scripts.
## [1.11.3] - 2023-02-26
### Deprecated
- `check-dumpfile` action. The [completion] module alone now handles
checking the dumpfile. (See
[zimfw/completion#12](https://github.com/zimfw/completion/pull/12))
## [1.11.2] - 2023-02-16
### Fixed
- Quote path names in init.zsh to properly handle path names with spaces.
## [1.11.1] - 2023-02-04
### Fixed
- Use `_zim_dumpfile_fpath` defined by the completion module
[here](https://github.com/zimfw/completion/blob/33737e8c15fa8dba9af47bef8408b1af2599c21b/init.zsh#L11),
right before `compinit` is run, to more accurately do `zimfw check-dumpfile`.
## [1.11.0] - 2022-12-18
### Added
- `--if` option to `zmodule` that will only initialize the module root if the
specified test returns a zero exit status. The test is evaluated at every new
terminal startup.
- Ability to customize the .zimrc file name and path with the `ZIM_CONFIG_FILE`
environment variable.
## [1.10.0] - 2022-09-27
### Added
- `--root` option to `zmodule`. Combined with the ability to call `zmodule`
multiple times for the same module, this allows initializing from multiple
roots in repositories like prezto or ohmyzsh. Also, `--on-pull` and `--disable`
now work on a per-module-root basis.
### Changed
- Show `OSTYPE`, `TERM`, `TERM_PROGRAM` and `TERM_PROGRAM_VERSION` environment
variables instead of calling the `uname -a` command to show system info in the
`zimfw info` action.
## [1.9.1] - 2022-05-24
### Fixed
- Override repository options along multiple `zmodule` calls with the same
module name.
- Show already installed modules skipped with install action and `-v`.
- Consider external module directory paths when calling compile action directly.
- Ignore return value from `zargs` with `-P`.
(See https://www.zsh.org/mla/workers/2022/msg00611.html)
## [1.9.0] - 2022-05-09
### Added
- `--on-pull` option to `zmodule`, which allows setting a command that is always
triggered after the module is installed or updated.
## [1.8.0] - 2022-01-25
### Added
- `check-dumpfile` action. It runs in the build, install and update actions, and
checks if a new completion configuration needs to be dumped. It's intended to
be used with `compinit -C`, so no checks are done during the shell startup.
(See [zimfw/completion#8](https://github.com/zimfw/completion/pull/8))
- `--no-submodules` option to `zmodule`, which disables installing or updating
git submodules.
## [1.7.0] - 2022-01-12
### Changed
- The output of `zimfw init` to be friendlier to the terminal startup screen
when called without `-q`.
- Only compile scripts via the `zimfw` tool after actions where scripts can
change (build, install, update, upgrade).
- Move compilation of the completion dumpfile to the completion module,
[here](https://github.com/zimfw/completion/blob/9386a76eac3f55b1c04d57d26238f725b4b3ba25/init.zsh#L10-L11).
- Don't compile user Zsh startup scripts anymore
(See [#450](https://github.com/zimfw/zimfw/pull/450)). This means you can:
- either manually delete the compiled files, as they won't be updated by zimfw
anymore (recommended):
```
for zfile in ${ZDOTDIR:-${HOME}}/.z(shenv|profile|shrc|login|logout); do
rm -f ${zfile}.zwc(|.old)(N)
done
```
- or add the following to your .zlogin so Zsh startup scripts continue to be
compiled:
```diff
+for zfile in ${ZDOTDIR:-${HOME}}/.z(shenv|profile|shrc|login|logout); do
+ if [[ ! ${zfile}.zwc -nt ${zfile} ]] zcompile -R ${zfile}
+done
+unset zfile
```
### Deprecated
- The login_init.zsh script, which is now empty. This means you can safely
remove the following line from your .zlogin:
```diff
-source ${ZIM_HOME}/login_init.zsh -q &!
```
## [1.6.2] - 2021-11-21
### Fixed
- Force local zsh emulation options, so the code is not broken by unexpected
option changes by the user.
## [1.6.1] - 2021-11-08
### Fixed
- Missing line break before showing git log when using the git tool to update.
## [1.6.0] - 2021-11-06
### Added
- `list` action. Using it with `-v` also shows the current details for all
modules.
### Changed
- Be quieter and don't output warnings when `-q` is provided.
- Be more verbose when `-v` is provided: show skipped external and frozen
modules with the install and update actions.
- Show warning instead of error when module was not installed with the tool
currently in use.
- Manually setting any `zmodule` initialization option will disable all the
default values from the other initialization options, so only user-provided
values are used in this case. I.e. it's either all automatic, or all manual.
- Also install new modules when starting a new shell (via `zimfw init`, that
is sourced in .zshrc).
### Fixed
- Error in `zimfw update` with the `git` tool when module directory is under a
symlinked directory.
- Warning when `WARN_CREATE_GLOBAL` is set and `ZIM_HOME` is not.
- "zsh: command not found: zmodule" when trying to run `zmodule` from the shell.
Show a more informative error instead.
- Don't try to install or update external modules.
## [1.5.0] - 2021-08-10
### Added
- Option to use the new `degit` tool in `zmodule`, that is able to install and
update modules from GitHub without requiring `git`. Modules are installed
faster and take less disk space when using this tool. It can be set as the
default with `zstyle ':zim:zmodule' use 'degit'`.
### Fixed
- Force `core.autocrlf=false` when doing `git clone`.
(See [#404](https://github.com/zimfw/zimfw/issues/404))
- Allow uninstalling modules with custom names that have a slash.
## [1.4.3] - 2021-03-19
### Fixed
- Prefer the prezto module format when using defaults to initialize a module.
This is the format we use in our Zim framework modules. It's not well
documented anywhere officially, but in short words a prezto module can have:
* a `functions` subdirectory that is added to the fpath by the framework,
* files inside the `functions` subdirectory that are autoloaded by the
framework (except for those with names matching `_*` or `prompt_*_setup`),
* an `init.zsh` file that is sourced by the framework.
## [1.4.2] - 2021-02-19
@ -106,7 +369,7 @@ _No unreleased changes._
This is a major change, where modules are not git submodules in the Zim repo
anymore, but customized and installed separately as individual repositories.
External modules can more easily be installed, updated and uninstalled. This
makes Zim the first project for Zsh that is both a set of community-maintained
makes Zim a project for Zsh that is both a set of community-maintained
modules with a default installation (like on-my-zsh and prezto) and a plugin
manager (like antigen and zplug).
@ -125,7 +388,7 @@ Take your time to review the updated [README.md] and the changes listed below.
- The Zim "core" is reduced to a single file, namely zimfw.zsh, that is
self-updated without requiring git. With this, `ZIM_HOME` is not (the root of)
a git repo anymore.
- Zsh and modules are configured in .zshrc instead of .zimrc.
- Zsh and modules are initialized in .zshrc instead of .zimrc.
- .zimrc is not sourced during Zsh startup anymore, and only contains the module
definitions.
- Zim's init.zsh and login_init.zsh scripts are generated by the `zimfw` CLI
@ -156,6 +419,7 @@ Take your time to review the updated [README.md] and the changes listed below.
- `ZIM_HOME` is set in .zshenv instead of .zshrc. The issue was that the
variable was not available in .zlogin in non-interactive login shells.
[completion]: https://github.com/zimfw/completion
[README.md]: https://github.com/zimfw/zimfw/blob/master/README.md
[environment]: https://github.com/zimfw/environment
[input]: https://github.com/zimfw/input
@ -163,7 +427,28 @@ Take your time to review the updated [README.md] and the changes listed below.
[termtitle]: https://github.com/zimfw/termtitle
[s1ck94]: https://github.com/zimfw/s1ck94
[Unreleased]: https://github.com/zimfw/zimfw/compare/v1.4.2...HEAD
[Unreleased]: https://github.com/zimfw/zimfw/compare/v1.15.1...HEAD
[1.15.1]: https://github.com/zimfw/zimfw/compare/v1.15.0...v1.15.1
[1.15.0]: https://github.com/zimfw/zimfw/compare/v1.14.0...v1.15.0
[1.14.0]: https://github.com/zimfw/zimfw/compare/v1.13.1...v1.14.0
[1.13.1]: https://github.com/zimfw/zimfw/compare/v1.13.0...v1.13.1
[1.13.0]: https://github.com/zimfw/zimfw/compare/v1.12.1...v1.13.0
[1.12.1]: https://github.com/zimfw/zimfw/compare/v1.12.0...v1.12.1
[1.12.0]: https://github.com/zimfw/zimfw/compare/v1.11.3...v1.12.0
[1.11.3]: https://github.com/zimfw/zimfw/compare/v1.11.2...v1.11.3
[1.11.2]: https://github.com/zimfw/zimfw/compare/v1.11.1...v1.11.2
[1.11.1]: https://github.com/zimfw/zimfw/compare/v1.11.0...v1.11.1
[1.11.0]: https://github.com/zimfw/zimfw/compare/v1.10.0...v1.11.0
[1.10.0]: https://github.com/zimfw/zimfw/compare/v1.9.1...v1.10.0
[1.9.1]: https://github.com/zimfw/zimfw/compare/v1.9.0...v1.9.1
[1.9.0]: https://github.com/zimfw/zimfw/compare/v1.8.0...v1.9.0
[1.8.0]: https://github.com/zimfw/zimfw/compare/v1.7.0...v1.8.0
[1.7.0]: https://github.com/zimfw/zimfw/compare/v1.6.2...v1.7.0
[1.6.2]: https://github.com/zimfw/zimfw/compare/v1.6.1...v1.6.2
[1.6.1]: https://github.com/zimfw/zimfw/compare/v1.6.0...v1.6.1
[1.6.0]: https://github.com/zimfw/zimfw/compare/v1.5.0...v1.6.0
[1.5.0]: https://github.com/zimfw/zimfw/compare/v1.4.3...v1.5.0
[1.4.3]: https://github.com/zimfw/zimfw/compare/v1.4.2...v1.4.3
[1.4.2]: https://github.com/zimfw/zimfw/compare/v1.4.1...v1.4.2
[1.4.1]: https://github.com/zimfw/zimfw/compare/v1.4.0...v1.4.1
[1.4.0]: https://github.com/zimfw/zimfw/compare/v1.3.2...v1.4.0

View file

@ -1,84 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at `eric@amalgamar.com.br` and `m@tthamilton.com`. All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of actions.
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the project community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.

View file

@ -1,7 +1,7 @@
MIT License
Copyright (c) 2015-2016 Matt Hamilton and contributors
Copyright (c) 2016-2021 Eric Nielsen, Matt Hamilton and contributors
Copyright (c) 2016-2024 Eric Nielsen, Matt Hamilton and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

414
README.md
View file

@ -1,141 +1,385 @@
<p align="center">
<a href="https://github.com/zimfw/zimfw/releases"><img src="https://img.shields.io/github/v/release/zimfw/zimfw"></a>
<a href="https://github.com/zimfw/zimfw/issues"><img src="https://img.shields.io/github/issues/zimfw/zimfw.svg"></a>
<a href="https://github.com/zimfw/zimfw/network/members"><img src="https://img.shields.io/github/forks/zimfw/zimfw.svg"></a>
<a href="https://github.com/zimfw/zimfw/stargazers"><img src="https://img.shields.io/github/stars/zimfw/zimfw.svg"></a>
<a href="https://github.com/zimfw/zimfw/releases"><img src="https://img.shields.io/github/downloads/zimfw/zimfw/total.svg"></a>
<a href="https://github.com/zimfw/zimfw/discussions"><img src="https://img.shields.io/badge/forum-online-green.svg"></a>
<a href="https://github.com/zimfw/zimfw/blob/master/LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/zimfw/zimfw"></a>
</p>
<div align="center">
<a href="https://github.com/zimfw/zimfw">
<img width="600" src="https://zimfw.github.io/images/zimfw-banner@2.jpg">
</a>
</div>
Zsh IMproved FrameWork
======================
What is Zim?
------------
Zim is a Zsh configuration framework with [blazing speed] and modular extensions.
Zim is a Zsh configuration framework that bundles a [plugin manager](#usage),
useful [modules] and a wide variety of [themes], without compromising on [speed].
Zim is very easy to customize, and comes with a rich set of modules and features without compromising on speed or functionality!
Check how Zim compares to other frameworks and plugin managers:
What does Zim offer?
<a href="https://github.com/zimfw/zimfw/wiki/Speed">
<img src="https://zimfw.github.io/images/results.svg">
</a>
Table of Contents
-----------------
If you're here, it means you want to see the cool shit Zim can do. Check out the [available modules]!
Below is a brief showcase of Zim's features.
### Speed
For a speed comparison between Zim and other frameworks, see [this wiki entry][blazing speed].
### Themes
To preview some of the available themes, check the [themes page].
### Fish-shell history navigation
![history-substring-search]
### Syntax highlighting
![syntax-highlighting]
### And much more!
Zim has many modules! Enable as many or as few as you'd like.
* [Installation](#installation)
* [Automatic installation](#automatic-installation)
* [Manual installation](#manual-installation)
* [Set up `~/.zshrc`](#set-up-zshrc)
* [Create `~/.zimrc`](#create-zimrc)
* [Usage](#usage)
* [`zmodule`](#zmodule)
* [`zimfw`](#zimfw)
* [Settings](#settings)
* [Uninstalling](#uninstalling)
Installation
------------
Installing Zim is easy:
Installing Zim is easy. You can choose either the automatic or manual method below:
* With curl:
### Automatic installation
This will install a predefined set of modules and a theme for you.
* With `curl`:
```zsh
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```
* With wget:
* With `wget`:
```zsh
wget -nv -O - https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```
Open a new terminal and you're done! Enjoy your Zsh IMproved! Take some time to
read about the [available modules] and tweak your `~/.zshrc` file.
If you have a different shell framework installed (like oh-my-zsh or prezto),
*uninstall those first to prevent conflicts*.
Restart your terminal and you're done. Enjoy your Zsh IMproved! Take some time
to tweak your [`~/.zshrc`](#set-up-zshrc) file and to also check the available
[modules] and [themes] you can add to your [`~/.zimrc`](#create-zimrc).
### Manual installation
1. Set Zsh as the default shell:
1. Set Zsh as the default shell, if you haven't done so already:
```zsh
chsh -s $(which zsh)
````
2. Add the lines in the following templates to the respective dot files:
* [~/.zshenv](https://github.com/zimfw/install/blob/master/src/templates/zshenv)
* [~/.zshrc](https://github.com/zimfw/install/blob/master/src/templates/zshrc)
* [~/.zlogin](https://github.com/zimfw/install/blob/master/src/templates/zlogin)
* [~/.zimrc](https://github.com/zimfw/install/blob/master/src/templates/zimrc)
2. [Set up your `~/.zshrc` file](#set-up-zshrc)
3. Copy https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh to
`~/.zim/zimfw.zsh`.
3. [Create your `~/.zimrc` file](#create-zimrc)
4. Install the modules defined in `~/.zimrc` and build the initialization scripts:
4. Restart your terminal and you're done. Enjoy your Zsh IMproved!
zsh ~/.zim/zimfw.zsh install
#### Set up `~/.zshrc`
Add the lines below to your `~/.zshrc` file, in the following order:
1. To use our `degit` tool by default to install modules:
```zsh
zstyle ':zim:zmodule' use 'degit'
````
This is optional and only required if you don't have `git` installed (yes,
zimfw works even without `git`!)
2. To set where the zimfw plugin manager configuration file will be located:
```zsh
ZIM_CONFIG_FILE=~/.config/zsh/zimrc
```
This is optional. The value of `ZIM_CONFIG_FILE` can be any path your user
has at least read access to. By default, the file must be at `~/.zimrc`, if
the `ZDOTDIR` environment variable is not defined. Otherwise, it must be at
`${ZDOTDIR}/.zimrc`.
3. To set the directory where the zimfw plugin manager will keep necessary files:
```zsh
ZIM_HOME=~/.zim
```
The value of `ZIM_HOME` can be any directory your user has write access to.
You can even set it to a cache directory like `${XDG_CACHE_HOME}/zim` or
`~/.cache/zim`.
4. To automatically download the zimfw plugin manager if missing:
```zsh
# Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
curl -fsSL --create-dirs -o ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
fi
```
Or if you use `wget` instead of `curl`:
```zsh
# Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
mkdir -p ${ZIM_HOME} && wget -nv -O ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
fi
```
This is optional. Alternatively, you can download the `zimfw.zsh` script
anywhere your user has write access to: just replace the occurrences of
`${ZIM_HOME}/zimfw.zsh` by the preferred path, like `/usr/local/bin/zimfw.zsh`
for example. If you choose to not include this step, you should manually
download the `zimfw.zsh` script once and keep it at the preferred path.
5. To automatically install missing modules and update the static initialization
script if missing or outdated:
```zsh
# Install missing modules and update ${ZIM_HOME}/init.zsh if missing or outdated.
if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} ]]; then
source ${ZIM_HOME}/zimfw.zsh init -q
fi
```
This step is optional, but highly recommended. If you choose to not include
it, you must remember to manually run `zimfw install` every time you update
your [`~/.zimrc`](#create-zimrc) file. If you have chosen to keep the
`zimfw.zsh` in a different path as mentioned in the previous step, replace
`${ZIM_HOME}/zimfw.zsh` by the chosen path.
6. To source the static script, that will initialize your modules:
```zsh
# Initialize modules.
source ${ZIM_HOME}/init.zsh
```
#### Create `~/.zimrc`
This file configures the zimfw plugin manager. It's referred to as `~/.zimrc`
in the documentation for the sake of simplicity, but the actual location of the
file is defined by the following rules:
1. You can define the full path and name of the file with a `ZIM_CONFIG_FILE`
environment variable. For example:
```zsh
ZIM_CONFIG_FILE=~/.config/zsh/zimrc
```
2. Or, if you defined a `ZDOTDIR` environment variable, then the file must be at
`${ZDOTDIR}/.zimrc`
3. Otherwise, it must be at at `~/.zimrc`, which is it's default location.
As for the contents of the file, you can start with just:
```zsh
zmodule zsh-users/zsh-syntax-highlighting
zmodule zsh-users/zsh-autosuggestions
```
If you also want one of our prompt [themes]:
```zsh
zmodule git-info
zmodule duration-info
zmodule asciiship
zmodule zsh-users/zsh-syntax-highlighting
zmodule zsh-users/zsh-autosuggestions
```
If you want to use our [completion] module too, instead of using `compinit` directly:
```zsh
zmodule git-info
zmodule duration-info
zmodule asciiship
zmodule zsh-users/zsh-completions --fpath src
zmodule completion
zmodule zsh-users/zsh-syntax-highlighting
zmodule zsh-users/zsh-autosuggestions
```
The [completion] module calls `compinit` for you. You should remove any
`compinit` calls from your `~/.zshrc` when you use this module. The modules will
be initialized in the order they are defined, and [completion] must be
initialized *after* all modules that add completion definitions, so it must come
after [zsh-users/zsh-completions].
Check the [`zmodule` usage](#zmodule) below for more examples on how to use it to
define the modules you want to use.
Usage
-----
The zimfw plugin manager installs your modules at `${ZIM_HOME}/modules` and
builds a static script at `${ZIM_HOME}/init.zsh` that will initialize them. Your
modules are defined in your `~/.zimrc` file.
The `~/.zimrc` file must contain `zmodule` calls to define the modules to be
initialized. The modules will be initialized in the same order they're defined.
The `~/.zimrc` file is not sourced during Zsh startup and it's only used to
configure the zimfw plugin manager.
Check [examples of `~/.zimrc` files](#create-zimrc) above.
### zmodule
<pre>
Usage: <strong>zmodule</strong> &lt;url&gt; [<strong>-n</strong>|<strong>--name</strong> &lt;module_name&gt;] [options]
Below are some usage examples:
Add <strong>zmodule</strong> calls to your <strong>~/.zimrc</strong> file to define the modules to be initialized. The modules are
initialized in the same order they are defined.
* A module from the [@zimfw] organization: `zmodule archive`
* A module from another GitHub organization: `zmodule StackExchange/blackbox`
* A module with a custom URL: `zmodule https://gitlab.com/Spriithy/basher.git`
* A module at an absolute path, that is already installed:
`zmodule /usr/local/share/zsh-autosuggestions`
* A module with a custom fpath: `zmodule zsh-users/zsh-completions --fpath src`
* A module with a custom initialization file and with git submodules disabled:
`zmodule spaceship-prompt/spaceship-prompt --source spaceship.zsh --no-submodules` or
`zmodule spaceship-prompt/spaceship-prompt --name spaceship --no-submodules`
* A module with two custom initialization files:
`zmodule sindresorhus/pure --source async.zsh --source pure.zsh`. Separate
zmodule calls can also be used. In this equivalent example, the second call
automatically discovers the second file to be sourced:
```
zmodule sindresorhus/pure --source async.zsh
zmodule sindresorhus/pure
```
* A module with a custom initialization command:
`zmodule skywind3000/z.lua --cmd 'eval "$(lua {}/z.lua --init zsh enhanced once)"'`
* A module with an on-pull command. It can be used to create a cached initialization script:
`zmodule skywind3000/z.lua --on-pull 'lua z.lua --init zsh enhanced once >! init.zsh'`
* A module with a big git repository: `zmodule romkatv/powerlevel10k --use degit`
* A module with a custom root subdirectory: `zmodule ohmyzsh/ohmyzsh --root plugins/vim-interaction`
* A module with multiple roots:
```
zmodule sorin-ionescu/prezto --root modules/command-not-found
zmodule sorin-ionescu/prezto --root modules/gnu-utility
```
or
```
zmodule ohmyzsh/ohmyzsh --root plugins/perl
zmodule ohmyzsh/ohmyzsh --root plugins/vim-interaction
```
<details id="zmodule-usage">
<summary>Want help with the complete <code>zmodule</code> usage?</summary>
<pre>Usage: <b>zmodule</b> &lt;url&gt; [<b>-n</b>|<b>--name</b> &lt;module_name&gt;] [<b>-r</b>|<b>--root</b> &lt;path&gt;] [options]
Add <b>zmodule</b> calls to your <b>~/.zimrc</b> file to define the modules to be initialized. The initiali-
zation will be done in the same order it&apos;s defined.
&lt;url&gt; Module absolute path or repository URL. The following URL formats
are equivalent: <strong>name</strong>, <strong>zimfw/name</strong>, <strong>https://github.com/zimfw/name.git</strong>.
<strong>-n</strong>|<strong>--name</strong> &lt;module_name&gt; Set a custom module name. Default: the last component in the &lt;url&gt;.
are equivalent: <b>foo</b>, <b>zimfw/foo</b>, <b>https://github.com/zimfw/foo.git</b>.
If an absolute path is given, the module is considered externally
installed and won&apos;t be installed or updated by zimfw.
<b>-n</b>|<b>--name</b> &lt;module_name&gt; Set a custom module name. Default: the last component in &lt;url&gt;.
Slashes can be used inside the name to organize the module into
subdirectories. The module will be installed at
<b>${ZIM_HOME}/</b>&lt;module_name&gt;.
<b>-r</b>|<b>--root</b> &lt;path&gt; Relative path to the module root.
Repository options:
<strong>-b</strong>|<strong>--branch</strong> &lt;branch_name&gt; Use specified branch when installing and updating the module.
Overrides the tag option. Default: the repository's default branch.
<strong>-t</strong>|<strong>--tag</strong> &lt;tag_name&gt; Use specified tag when installing and updating the module.
Overrides the branch option.
<strong>-z</strong>|<strong>--frozen</strong> Don't install or update the module.
Per-module options:
<b>-b</b>|<b>--branch</b> &lt;branch_name&gt; Use specified branch when installing and updating the module.
Overrides the tag option. Default: the repository default branch.
<b>-t</b>|<b>--tag</b> &lt;tag_name&gt; Use specified tag when installing and updating the module. Over-
rides the branch option.
<b>-u</b>|<b>--use</b> &lt;tool_name&gt; Install and update the module using the defined tool. Default is
either defined by <b>zstyle &apos;:zim:zmodule&apos; use &apos;</b>&lt;tool_name&gt;<b>&apos;</b>, or <b>git</b>
if none is provided. The tools available are:
<b>git</b> uses the git command. Local changes are preserved on updates.
<b>degit</b> uses curl or wget, and currently only works with GitHub
URLs. Modules install faster and take less disk space. Local
changes are lost on updates. Git submodules are not supported.
<b>mkdir</b> creates an empty directory. The &lt;url&gt; is only used to set
the module name. Use the <b>-c</b>|<b>--cmd</b> or <b>--on-pull</b> options to execute
the desired command to generate the module files.
<b>--no-submodules</b> Don&apos;t install or update git submodules.
<b>-z</b>|<b>--frozen</b> Don&apos;t install or update the module.
Initialization options:
<strong>-f</strong>|<strong>--fpath</strong> &lt;path&gt; Add specified path to fpath. The path is relative to the module
root directory. Default: <strong>functions</strong>, if the subdirectory exists.
<strong>-a</strong>|<strong>--autoload</strong> &lt;func_name&gt; Autoload specified function. Default: all valid names inside the
module's specified fpath paths.
<strong>-s</strong>|<strong>--source</strong> &lt;file_path&gt; Source specified file. The file path is relative to the module root
directory. Default: the file with largest size matching
<strong>{init.zsh,module_name.{zsh,plugin.zsh,zsh-theme,sh}}</strong>, if any exist.
<strong>-c</strong>|<strong>--cmd</strong> &lt;command&gt; Execute specified command. Occurrences of the <strong>{}</strong> placeholder in the
command are substituted by the module root directory path.
<strong>-s 'script.zsh'</strong> and <strong>-c 'source {}/script.zsh'</strong> are equivalent.
<strong>-d</strong>|<strong>--disabled</strong> Don't initialize or uninstall the module.
The per-module options above are carried over multiple zmodule calls for the same module.
Modules are uniquely identified by their name.
Per-module-root options:
<b>--if</b> &lt;test&gt; Will only initialize module root if specified test returns a zero
exit status. The test is evaluated at every new terminal startup.
<b>--if-command</b> &lt;cmd_name&gt; Will only initialize module root if specified external command is
available. This is evaluated at every new terminal startup.
Equivalent to <b>--if &apos;(( ${+commands[</b>&lt;cmd_name&gt;<b>]} ))&apos;</b>.
<b>--if-ostype</b> &lt;ostype&gt; Will only initialize module root if <b>OSTYPE</b> is equal to the given
expression. This is evaluated at every new terminal startup.
Equivalent to <b>--if &apos;[[ ${OSTYPE} == </b>&lt;ostype&gt;<b> ]]&apos;</b>.
<b>--on-pull</b> &lt;command&gt; Execute command after installing or updating the module. The com-
mand is executed in the module root directory.
<b>-d</b>|<b>--disabled</b> Don&apos;t initialize the module root or uninstall the module.
The per-module-root options above are carried over multiple zmodule calls for the same mod-
ule root.
Per-call initialization options:
<b>-f</b>|<b>--fpath</b> &lt;path&gt; Will add specified path to fpath. The path is relative to the
module root directory. Default: <b>functions</b>, if the subdirectory
exists and is non-empty.
<b>-a</b>|<b>--autoload</b> &lt;func_name&gt; Will autoload specified function. Default: all valid names inside
the <b>functions</b> subdirectory, if any.
<b>-s</b>|<b>--source</b> &lt;file_path&gt; Will source specified file. The path is relative to the module
root directory. Default: <b>init.zsh</b>, if a non-empty <b>functions</b> sub-
directory exists, else the largest of the files matching the glob
<b>(init.zsh|</b>&lt;name&gt;<b>.(zsh|plugin.zsh|zsh-theme|sh))</b>, if any.
&lt;name&gt; in the glob is resolved to the last component of the mod-
ule name, or the last component of the path to the module root.
<b>-c</b>|<b>--cmd</b> &lt;command&gt; Will execute specified command. Occurrences of the <b>{}</b> placeholder
in the command are substituted by the module root directory path.
I.e., <b>-s &apos;foo.zsh&apos;</b> and <b>-c &apos;source {}/foo.zsh&apos;</b> are equivalent.
Setting any per-call initialization option above will disable the default values from the
other per-call initialization options, so only your provided values will be used. I.e. these
values are either all automatic, or all manual in each zmodule call. To use default values
and also provided values, use separate zmodule calls.
</pre>
</details>
### zimfw
Added new modules to `~/.zimrc`? Run `zimfw install`.
The Zim plugin manager:
Removed modules from `~/.zimrc`? Run `zimfw uninstall`.
Want to update your modules to their latest revisions? Run `zimfw update`.
Want to upgrade `zimfw` to its latest version? Run `zimfw upgrade`.
For more information about the `zimfw` tool, run `zimfw help`.
* Added new modules to `~/.zimrc`? Run `zimfw install`.
* Removed modules from `~/.zimrc`? Run `zimfw uninstall`.
* Want to update your modules to their latest revisions? Run `zimfw update`.
* Want to upgrade zimfw to its latest version? Run `zimfw upgrade`.
* For more information about the zimfw plugin manager, run `zimfw help`.
Settings
--------
Set the path of the directory used by zimfw with the `ZIM_HOME` environment
variable:
By default, `zimfw` will check if it has a new version available every 30 days.
This can be disabled with:
ZIM_HOME=~/.zim
By default, the zimfw plugin manager configuration file must be at `~/.zimrc`,
if the `ZDOTDIR` environment variable is not defined. Otherwise, it must be at
`${ZDOTDIR}/.zimrc`. You can customize its full path and name with the
`ZIM_CONFIG_FILE` environment variable:
ZIM_CONFIG_FILE=~/.config/zsh/zimrc
Modules are installed using `git` by default. If you don't have `git`
installed, or if you want to take advantage of our degit tool for faster and
lighter module installations, you can set degit as the default tool with:
zstyle ':zim:zmodule' use 'degit'
By default, zimfw will check if it has a new version available every 30 days. If
the `zimfw.zsh` file cannot be upgraded, either because your user does not have
write access to it, or because it was sourced from a symlink, then this will be
disabled. This can be manually disabled with:
zstyle ':zim' disable-version-check yes
To disable color output from zimfw, prefix the zimfw call with `NO_COLOR=1`,
like:
NO_COLOR=1 zimfw install
or add the following to your `.zshrc`, which should also disable color output
for other tools. See https://no-color.org/
export NO_COLOR=1
Uninstalling
------------
The best way to remove Zim is to manually delete `~/.zim`, `~/.zimrc`, and
remove the initialization lines from your `~/.zshenv`, `~/.zshrc` and `~/.zlogin`.
[history-substring-search]: https://zimfw.github.io/images/zim_history-substring-search.gif
[syntax-highlighting]: https://zimfw.github.io/images/zim_syntax-highlighting.gif
[blazing speed]: https://github.com/zimfw/zimfw/wiki/Speed
[available modules]: https://zimfw.sh/docs/modules/
[themes page]: https://zimfw.sh/docs/themes/
[modules]: https://zimfw.sh/docs/modules/
[themes]: https://zimfw.sh/docs/themes/
[speed]: https://github.com/zimfw/zimfw/wiki/Speed
[@zimfw]: https://github.com/zimfw
[completion]: https://github.com/zimfw/completion
[zsh-users/zsh-completions]: https://github.com/zsh-users/zsh-completions

View file

@ -0,0 +1,243 @@
zmodule() {
local -r zusage="Usage: ${_zbold}${0}${_znormal} <url> [${_zbold}-n${_znormal}|${_zbold}--name${_znormal} <module_name>] [${_zbold}-r${_znormal}|${_zbold}--root${_znormal} <path>] [options]
Add ${_zbold}zmodule${_znormal} calls to your ${_zbold}${_zconfig}${_znormal} file to define the modules to be initialized.
The initialization will be done in the same order it's defined.
<url> Module absolute path or repository URL. The following URL formats
are equivalent: ${_zbold}foo${_znormal}, ${_zbold}zimfw/foo${_znormal}, ${_zbold}https://github.com/zimfw/foo.git${_znormal}.
If an absolute path is given, the module is considered externally
installed and won't be installed or updated by zimfw.
${_zbold}-n${_znormal}|${_zbold}--name${_znormal} <module_name> Set a custom module name. Default: the last component in <url>.
Slashes can be used inside the name to organize the module into
subdirectories. The module will be installed at
${_zbold}${ZIM_HOME}/${_znormal}<module_name>.
${_zbold}-r${_znormal}|${_zbold}--root${_znormal} <path> Relative path to the module root.
Per-module options:
${_zbold}-b${_znormal}|${_zbold}--branch${_znormal} <branch_name> Use specified branch when installing and updating the module.
Overrides the tag option. Default: the repository default branch.
${_zbold}-t${_znormal}|${_zbold}--tag${_znormal} <tag_name> Use specified tag when installing and updating the module. Over-
rides the branch option.
${_zbold}-u${_znormal}|${_zbold}--use${_znormal} <tool_name> Install and update the module using the defined tool. Default is
either defined by ${_zbold}zstyle ':zim:zmodule' use '${_znormal}<tool_name>${_zbold}'${_znormal}, or ${_zbold}git${_znormal}
if none is provided. The tools available are:
${_zbold}git${_znormal} uses the git command. Local changes are preserved on updates.
${_zbold}degit${_znormal} uses curl or wget, and currently only works with GitHub
URLs. Modules install faster and take less disk space. Local
changes are lost on updates. Git submodules are not supported.
${_zbold}mkdir${_znormal} creates an empty directory. The <url> is only used to set
the module name. Use the ${_zbold}-c${_znormal}|${_zbold}--cmd${_znormal} or ${_zbold}--on-pull${_znormal} options to execute
the desired command to generate the module files.
${_zbold}--no-submodules${_znormal} Don't install or update git submodules.
${_zbold}-z${_znormal}|${_zbold}--frozen${_znormal} Don't install or update the module.
The per-module options above are carried over multiple zmodule calls for the same module.
Modules are uniquely identified by their name.
Per-module-root options:
${_zbold}--if${_znormal} <test> Will only initialize module root if specified test returns a zero
exit status. The test is evaluated at every new terminal startup.
${_zbold}--if-command${_znormal} <cmd_name> Will only initialize module root if specified external command is
available. This is evaluated at every new terminal startup.
Equivalent to ${_zbold}--if '(( \${+commands[${_znormal}<cmd_name>${_zbold}]} ))'${_znormal}.
${_zbold}--if-ostype${_znormal} <ostype> Will only initialize module root if ${_zbold}OSTYPE${_znormal} is equal to the given
expression. This is evaluated at every new terminal startup.
Equivalent to ${_zbold}--if '[[ \${OSTYPE} == ${_znormal}<ostype>${_zbold} ]]'${_znormal}.
${_zbold}--on-pull${_znormal} <command> Execute command after installing or updating the module. The com-
mand is executed in the module root directory.
${_zbold}-d${_znormal}|${_zbold}--disabled${_znormal} Don't initialize the module root or uninstall the module.
The per-module-root options above are carried over multiple zmodule calls for the same mod-
ule root.
Per-call initialization options:
${_zbold}-f${_znormal}|${_zbold}--fpath${_znormal} <path> Will add specified path to fpath. The path is relative to the
module root directory. Default: ${_zbold}functions${_znormal}, if the subdirectory
exists and is non-empty.
${_zbold}-a${_znormal}|${_zbold}--autoload${_znormal} <func_name> Will autoload specified function. Default: all valid names inside
the ${_zbold}functions${_znormal} subdirectory, if any.
${_zbold}-s${_znormal}|${_zbold}--source${_znormal} <file_path> Will source specified file. The path is relative to the module
root directory. Default: ${_zbold}init.zsh${_znormal}, if a non-empty ${_zbold}functions${_znormal} sub-
directory exists, else the largest of the files matching the glob
${_zbold}(init.zsh|${_znormal}<name>${_zbold}.(zsh|plugin.zsh|zsh-theme|sh))${_znormal}, if any.
<name> in the glob is resolved to the last component of the mod-
ule name, or the last component of the path to the module root.
${_zbold}-c${_znormal}|${_zbold}--cmd${_znormal} <command> Will execute specified command. Occurrences of the ${_zbold}{}${_znormal} placeholder
in the command are substituted by the module root directory path.
I.e., ${_zbold}-s 'foo.zsh'${_znormal} and ${_zbold}-c 'source {}/foo.zsh'${_znormal} are equivalent.
Setting any per-call initialization option above will disable the default values from the
other per-call initialization options, so only your provided values will be used. I.e. these
values are either all automatic, or all manual in each zmodule call. To use default values
and also provided values, use separate zmodule calls."
if (( ! # )); then
print -u2 -lR "${_zerror}${funcfiletrace[1]}: Missing zmodule url${_znormal}" '' ${zusage}
_zfailed=1
return 2
fi
local zurl=${1} zname=${1:t} zroot zarg
local -a zfpaths zfunctions zcmds
if [[ ${zurl} =~ ^[^:/]+: ]]; then
zname=${zname%.git}
elif [[ ${zurl} != /* ]]; then
# Count number of slashes
case ${#zurl//[^\/]/} in
0) zurl=https://github.com/zimfw/${zurl}.git ;;
1) zurl=https://github.com/${zurl}.git ;;
esac
fi
shift
while [[ ${1} == (-n|--name|-r|--root) ]]; do
if (( # < 2 )); then
print -u2 -lR "${_zerror}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalred} Missing argument for zmodule option ${_zbold}${1}${_znormal}" '' ${zusage}
_zfailed=1
return 2
fi
case ${1} in
-n|--name)
shift
zname=${${1%%/##}##/##}
;;
-r|--root)
shift
zroot=${${1%%/##}##/##}
;;
esac
shift
done
if [[ ${zurl} == /* ]]; then
_zdirs[${zname}]=${zurl%%/##}
zurl=
else
_zdirs[${zname}]=${ZIM_HOME}/modules/${zname}
fi
if [[ ${+_zurls[${zname}]} -ne 0 && ${_zurls[${zname}]} != ${zurl} ]]; then
print -u2 -lR "${_zerror}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalred} Module already defined with a different URL. Expected ${_zbold}${_zurls[${zname}]}${_znormal}" '' ${zusage}
_zfailed=1
return 2
fi
_zurls[${zname}]=${zurl}
local -r zroot_dir=${_zdirs[${zname}]}${zroot:+/${zroot}}
_zroot_dirs+=(${zroot_dir})
# Set default values
if (( ! ${+_ztools[${zname}]} )); then
zstyle -s ':zim:zmodule' use "_ztools[${zname}]" || _ztools[${zname}]=git
fi
if (( ! ${+_ztypes[${zname}]} )) _ztypes[${zname}]=branch
if (( ! ${+_zsubmodules[${zname}]} )) _zsubmodules[${zname}]=1
# Set values from options
while (( # > 0 )); do
case ${1} in
-b|--branch|-t|--tag|-u|--use|--on-pull|--if|--if-command|--if-ostype|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd)
if (( # < 2 )); then
print -u2 -lR "${_zerror}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalred} Missing argument for zmodule option ${_zbold}${1}${_znormal}" '' ${zusage}
_zfailed=1
return 2
fi
;;
esac
case ${1} in
-b|--branch|-t|--tag|-u|--use|--no-submodules)
if [[ -z ${zurl} ]] _zimfw_print -u2 -R "${_zwarn}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalyellow} The zmodule option ${_zbold}${1}${_znormalyellow} has no effect for external modules${_znormal}"
;;
esac
case ${1} in
-b|--branch)
shift
_ztypes[${zname}]=branch
_zrevs[${zname}]=${1}
;;
-t|--tag)
shift
_ztypes[${zname}]=tag
_zrevs[${zname}]=${1}
;;
-u|--use)
shift
_ztools[${zname}]=${1}
;;
--no-submodules) _zsubmodules[${zname}]=0 ;;
-z|--frozen) _zfrozens[${zname}]=1 ;;
--on-pull)
shift
zarg=${1}
if [[ -n ${zroot} ]] zarg="(builtin cd -q ${zroot}; ${zarg})"
_zonpulls[${zname}]="${_zonpulls[${zname}]+${_zonpulls[${zname}]}; }${zarg}"
;;
--if)
shift
_zifs[${zroot_dir}]=${1}
;;
--if-command)
shift
_zifs[${zroot_dir}]="(( \${+commands[${1}]} ))"
;;
--if-ostype)
shift
_zifs[${zroot_dir}]="[[ \${OSTYPE} == ${1} ]]"
;;
-f|--fpath)
shift
zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg}
zfpaths+=(${zarg})
;;
-a|--autoload)
shift
zfunctions+=(${1})
;;
-s|--source)
shift
zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg}
zcmds+=('source '${(qqq)zarg:a})
;;
-c|--cmd)
shift
zcmds+=(${1//{}/${(qqq)zroot_dir:a}})
;;
-d|--disabled) _zdisabled_root_dirs+=(${zroot_dir}) ;;
*)
print -u2 -lR "${_zerror}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalred} Unknown zmodule option ${_zbold}${1}${_znormal}" '' ${zusage}
_zfailed=1
return 2
;;
esac
shift
done
if (( _zflags & 1 )); then
_znames+=(${zname})
fi
if (( _zflags & 2 )); then
if [[ ! -e ${zroot_dir} ]]; then
print -u2 -R "${_zerror}${funcfiletrace[1]}:${_zbold}${zname}: ${zroot_dir}${_znormalred} not found${_znormal}"
_zfailed=1
return 1
fi
if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
zfpaths=(${zroot_dir}/functions(NF))
# _* functions are autoloaded by compinit
# prompt_*_setup functions are autoloaded by promptinit
zfunctions=(${^zfpaths}/^(*~|*.zwc(|.old)|_*|prompt_*_setup)(N-.:t))
local -ra prezto_scripts=(${zroot_dir}/init.zsh(N))
if (( ${#zfpaths} && ${#prezto_scripts} )); then
# this follows the prezto module format, no need to check for other scripts
zcmds=('source '${(qqq)^prezto_scripts:a})
else
# get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first)
local -ra zscripts=(${zroot_dir}/(init.zsh|(${zname:t}|${zroot_dir:t}).(zsh|plugin.zsh|zsh-theme|sh))(NOL[1]))
zcmds=('source '${(qqq)^zscripts:a})
fi
fi
if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
_zimfw_print -u2 -lR "${_zwarn}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalyellow} Nothing found to be initialized. Customize the module name, root or initialization with ${_zbold}zmodule${_znormalyellow} options.${_znormal}" '' ${zusage}
fi
# Prefix is added to all _zfpaths, _zfunctions and _zcmds to distinguish the originating root dir
local -r zpre=${zroot_dir}$'\0'
_zfpaths+=(${zpre}${^zfpaths})
_zfunctions+=(${zpre}${^zfunctions})
zcmds=(${zcmds//${HOME}/\${HOME}})
_zcmds+=(${zpre}${^zcmds})
fi
}

View file

@ -1,7 +1,12 @@
autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then
print -u2 -PR "%F{red}${0}: Error starting Zim. You're using Zsh version %B${ZSH_VERSION}%b and versions < %B<%= min_zsh_version %>%b are not supported. Upgrade your Zsh.%f"
print -u2 -R "${_zred}${0}: Error starting zimfw. You're using Zsh version ${_zbold}${ZSH_VERSION}${_znormalred} and versions < ${_zbold}<%= min_zsh_version %>${_znormalred} are not supported. Update your Zsh.${_znormal}"
return 1
fi
autoload -Uz zargs
# Define Zim location
: ${ZIM_HOME=${0:A:h}}
if (( ! ${+ZIM_HOME} )); then
print -u2 -R "${_zred}${0}: ${_zbold}ZIM_HOME${_znormalred} not defined${_znormal}"
return 1
fi
# Define zimfw location
typeset -g __ZIMFW_FILE=${0}

View file

@ -2,12 +2,11 @@ _zimfw_mv() {
local -a cklines
if cklines=(${(f)"$(command cksum ${1} ${2} 2>/dev/null)"}) && \
[[ ${${(z)cklines[1]}[1,2]} == ${${(z)cklines[2]}[1,2]} ]]; then
_zimfw_print -PR "<%= okay %>%B${2}:%b Already up to date"
_zimfw_print -R "${_zokay}${_zbold}${2}:${_znormal} Already up to date"
else
if [[ -e ${2} ]]; then
command mv -f ${2}{,.old} || return 1
fi
command mv -f ${1} ${2} && \
_zimfw_print -PR "<%= okay %>%B${2}:%b Updated. Restart your terminal for changes to take effect."
command mv -f ${1} ${2} && command chmod a+r ${2} && _zimfw_print -R "${_zokay}${_zbold}${2}:${_znormal} Updated.${_zrestartmsg}"
fi
}

View file

@ -1,13 +1,46 @@
_zimfw_build_init() {
local -r ztarget=${ZIM_HOME}/init.zsh
# Force update of init.zsh if it's older than .zimrc
if [[ ${ztarget} -ot <%= home %>/.zimrc ]]; then
if [[ ${ztarget} -ot ${_zconfig} ]]; then
command mv -f ${ztarget}{,.old} || return 1
fi
_zimfw_mv =(
print -R "zimfw() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }"
if (( ${#_zfpaths} )) print -R 'fpath=('${_zfpaths:A}' ${fpath})'
if (( ${#_zfunctions} )) print -R 'autoload -Uz '${_zfunctions}
print -R ${(F)_zcmds}
print -R '# FILE AUTOMATICALLY GENERATED FROM '${_zconfig}
print '# EDIT THE SOURCE FILE AND THEN RUN zimfw build. DO NOT DIRECTLY EDIT THIS FILE!'
print
print -R 'if [[ -e ${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} ]] zimfw() { source '${${(qqq)__ZIMFW_FILE}/${HOME}/\${HOME}}' "${@}" }'
local zroot_dir zpre
local -a zif_functions zif_cmds zroot_functions zroot_cmds
local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds})
# Keep fpath constant regardless of "if" root dirs, to avoid confusing compinit.
# Move all from zfunctions and zcmds with "if" root dirs prefixes.
for zroot_dir in ${_zroot_dirs}; do
if (( ${+_zifs[${zroot_dir}]} )); then
zpre=${zroot_dir}$'\0'
zif_functions+=(${(M)zfunctions:#${zpre}*})
zif_cmds+=(${(M)zcmds:#${zpre}*})
zfunctions=(${zfunctions:#${zpre}*})
zcmds=(${zcmds:#${zpre}*})
fi
done
zpre=$'*\0'
if (( ${#_zfpaths} )) print -R 'fpath=('${${(qqq)${_zfpaths#${~zpre}}:a}/${HOME}/\${HOME}}' ${fpath})'
if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}}
for zroot_dir in ${_zroot_dirs}; do
zpre=${zroot_dir}$'\0'
if (( ${+_zifs[${zroot_dir}]} )); then
zroot_functions=(${${(M)zif_functions:#${zpre}*}#${zpre}})
zroot_cmds=(${${(M)zif_cmds:#${zpre}*}#${zpre}})
if (( ${#zroot_functions} || ${#zroot_cmds} )); then
print -R 'if '${_zifs[${zroot_dir}]}'; then'
if (( ${#zroot_functions} )) print -R ' autoload -Uz -- '${zroot_functions}
if (( ${#zroot_cmds} )) print -R ${(F):- ${^zroot_cmds}}
print fi
fi
else
zroot_cmds=(${${(M)zcmds:#${zpre}*}#${zpre}})
if (( ${#zroot_cmds} )) print -R ${(F)zroot_cmds}
fi
done
) ${ztarget}
}

View file

@ -1,13 +1,10 @@
_zimfw_build_login_init() {
# Array with unique dirs. ${ZIM_HOME} or any subdirectory should only occur once.
local -Ur zscriptdirs=(${ZIM_HOME} ${${_zdirs##${ZIM_HOME}/*}:A})
local -r zscriptglob=("${^zscriptdirs[@]}/(^*test*/)#*.zsh(|-theme)(N-.)")
local -r ztarget=${ZIM_HOME}/login_init.zsh
# Force update of login_init.zsh if it's older than .zimrc
if [[ ${ztarget} -ot <%= home %>/.zimrc ]]; then
if [[ ${ztarget} -ot ${_zconfig} ]]; then
command mv -f ${ztarget}{,.old} || return 1
fi
_zimfw_mv =(
print -Rn "<%= render_escaped("src/templates/login_init.zsh.erb") %>"
print '# Do nothing. This file is deprecated.'
) ${ztarget}
}

View file

@ -1,3 +1,3 @@
_zimfw_build() {
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print -P '<%= done %>Done with build.'
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print 'Done with build.'
}

View file

@ -1,155 +0,0 @@
zmodule() {
local -r zusage="Usage: %B${0}%b <url> [%B-n%b|%B--name%b <module_name>] [options]
Add %Bzmodule%b calls to your %B${ZDOTDIR:-${HOME}}/.zimrc%b file to define the modules to be initialized.
The modules are initialized in the same order they are defined.
<url> Module absolute path or repository URL. The following URL formats
are equivalent: %Bname%b, %Bzimfw/name%b, %Bhttps://github.com/zimfw/name.git%b.
%B-n%b|%B--name%b <module_name> Set a custom module name. Default: the last component in the <url>.
Repository options:
%B-b%b|%B--branch%b <branch_name> Use specified branch when installing and updating the module.
Overrides the tag option. Default: the repository's default branch.
%B-t%b|%B--tag%b <tag_name> Use specified tag when installing and updating the module.
Overrides the branch option.
%B-z%b|%B--frozen%b Don't install or update the module.
Initialization options:
%B-f%b|%B--fpath%b <path> Add specified path to fpath. The path is relative to the module
root directory. Default: %Bfunctions%b, if the subdirectory exists.
%B-a%b|%B--autoload%b <func_name> Autoload specified function. Default: all valid names inside the
module's specified fpath paths.
%B-s%b|%B--source%b <file_path> Source specified file. The file path is relative to the module root
directory. Default: the file with largest size matching
%B{init.zsh,module_name.{zsh,plugin.zsh,zsh-theme,sh}}%b, if any exist.
%B-c%b|%B--cmd%b <command> Execute specified command. Occurrences of the %B{}%b placeholder in the
command are substituted by the module root directory path.
%B-s 'script.zsh'%b and %B-c 'source {}/script.zsh'%b are equivalent.
%B-d%b|%B--disabled%b Don't initialize or uninstall the module.
"
if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then
print -u2 -PR "%F{red}${0}: Must be called from %B<%= home %>/.zimrc%b%f"$'\n\n'${zusage}
return 1
fi
if (( ! # )); then
print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}: Missing zmodule url%f"$'\n\n'${zusage}
_zfailed=1
return 1
fi
setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB
local zmodule=${1:t} zurl=${1}
local ztype zrev
local -i zdisabled=0 zfrozen=0
local -a zfpaths zfunctions zcmds
local zarg zdir
if [[ ${zurl} =~ ^[^:/]+: ]]; then
zmodule=${zmodule%.git}
elif [[ ${zurl} != /* ]]; then
# Count number of slashes
case ${#zurl//[^\/]/} in
0) zurl="https://github.com/zimfw/${zurl}.git" ;;
1) zurl="https://github.com/${zurl}.git" ;;
esac
fi
shift
if [[ ${1} == (-n|--name) ]]; then
if (( # < 2 )); then
print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f"$'\n\n'${zusage}
_zfailed=1
return 1
fi
shift
zmodule=${1}
shift
fi
if [[ ${zurl} == /* ]]; then
zdir=${zurl}
else
zdir=${ZIM_HOME}/modules/${zmodule}
fi
while (( # > 0 )); do
case ${1} in
-b|--branch|-t|--tag|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd)
if (( # < 2 )); then
print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f"$'\n\n'${zusage}
_zfailed=1
return 1
fi
;;
esac
case ${1} in
-b|--branch)
shift
ztype=branch
zrev=${1}
;;
-t|--tag)
shift
ztype=tag
zrev=${1}
;;
-z|--frozen) zfrozen=1 ;;
-f|--fpath)
shift
zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zdir}/${zarg}
zfpaths+=(${zarg})
;;
-a|--autoload)
shift
zfunctions+=(${1})
;;
-s|--source)
shift
zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zdir}/${zarg}
zcmds+=("source ${zarg:A}")
;;
-c|--cmd)
shift
zcmds+=(${1//{}/${zdir:A}})
;;
-d|--disabled) zdisabled=1 ;;
*)
print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Unknown zmodule option ${1}%f"$'\n\n'${zusage}
_zfailed=1
return 1
;;
esac
shift
done
if (( _zprepare_zargs )); then
if (( ! zfrozen )); then
_zmodules_zargs+=(${zmodule} ${zdir} ${zurl} "${ztype}" "${zrev}" ${_zprintlevel})
fi
else
if (( zdisabled )); then
_zdisableds+=(${zmodule})
else
if [[ ! -d ${zdir} ]]; then
print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Not installed. Run %Bzimfw install%b to install.%f"
_zfailed=1
return 1
fi
if (( ! ${#zfpaths} )) zfpaths+=(${zdir}/functions(NF))
if (( ! ${#zfunctions} )); then
# _* functions are autoloaded by compinit
# prompt_*_setup functions are autoloaded by promptinit
zfunctions+=(${^zfpaths}/^(*~|*.zwc(|.old)|_*|prompt_*_setup)(N-.:t))
fi
if (( ! ${#zcmds} )); then
local -r zscript=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1]))
zcmds+=("source ${^zscript[@]:A}")
fi
if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
print -u2 -PR "%F{yellow}<%= warn %>${funcfiletrace[1]}:%B${zmodule}:%b Nothing found to be initialized. Customize the module name or initialization with %Bzmodule%b options.%f"$'\n\n'${zusage}
fi
_zmodules+=(${zmodule})
_zdirs+=(${zdir})
_zfpaths+=(${zfpaths})
_zfunctions+=(${zfunctions})
_zcmds+=(${zcmds})
fi
fi
}

View file

@ -1,13 +1,25 @@
_zimfw_source_zimrc() {
local -r ztarget=<%= home %>/.zimrc
local -ri _zprepare_zargs=${1}
<%= render_all("src/functions/*.erb") %>
{
local -r _zflags=${1}
local -i _zfailed=0
if ! source ${ztarget} || (( _zfailed )); then
print -u2 -PR "%F{red}<%= failed %>Failed to source %B${ztarget}%b%f"
if ! source ${_zconfig} || (( _zfailed )); then
print -u2 -R "${_zred}Failed to source ${_zbold}${_zconfig}${_znormal}"
return 1
fi
if (( _zprepare_zargs && ! ${#_zmodules_zargs} )); then
print -u2 -PR "%F{red}<%= failed %>No modules defined in %B${ztarget}%b%f"
if (( _zflags & 1 && ${#_znames} == 0 )); then
print -u2 -R "${_zred}No modules defined in ${_zbold}${_zconfig}${_znormal}"
return 1
fi
# Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes
local zroot_dir zpre
for zroot_dir in ${_zdisabled_root_dirs}; do
zpre=${zroot_dir}$'\0'
_zfpaths=(${_zfpaths:#${zpre}*})
_zfunctions=(${_zfunctions:#${zpre}*})
_zcmds=(${_zcmds:#${zpre}*})
done
} always {
unfunction zmodule
}
}

View file

@ -0,0 +1,18 @@
_zimfw_list_unuseds() {
local -i i=1
local zinstalled=(${ZIM_HOME}/modules/*(N/))
local -r zdirs=(${(v)_zdirs})
# Search into subdirectories
while (( i <= ${#zinstalled} )); do
if (( ${zdirs[(I)${zinstalled[i]}/*]} )); then
zinstalled+=(${zinstalled[i]}/*(N/))
zinstalled[i]=()
else
(( i++ ))
fi
done
# Unused = all installed dirs not in zdirs
_zunused_dirs=(${zinstalled:|zdirs})
local zunused
for zunused (${_zunused_dirs}) _zimfw_print -R "${_zbold}${zunused:t}:${_znormal} ${zunused}${1}"
}

View file

@ -1,18 +0,0 @@
_zimfw_version_check() {
if (( _zprintlevel > 0 )); then
setopt LOCAL_OPTIONS EXTENDED_GLOB
local -r ztarget=${ZIM_HOME}/.latest_version
# If .latest_version does not exist or was not modified in the last 30 days
if [[ -w ${ztarget:h} && ! -f ${ztarget}(#qNm-30) ]]; then
command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*' | \
command sed 's?^.*/v??' | command sort -n -t. -k1,1 -k2,2 -k3,3 | \
command tail -n1 >! ${ztarget} &!
fi
if [[ -f ${ztarget} ]]; then
local -r zlatest_version=$(<${ztarget})
if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
print -u2 -PR "%F{yellow}Latest zimfw version is %B${zlatest_version}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f"$'\n'
fi
fi
fi
}

View file

@ -0,0 +1,3 @@
_zimfw_check_dumpfile() {
_zimfw_print -u2 "${_zwarn}Deprecated action. This is now handled by the completion module alone.${_znormal}"
}

View file

@ -0,0 +1,23 @@
_zimfw_check_version() {
if (( ${1} )); then
if (( ${2} )); then
# background check
if [[ -w ${_zversion_target:h} ]]; then
print -R ${${${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs --sort=-v:refname \
https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${_zversion_target} &!
fi
else
# foreground check
local tags
tags=$(command git ls-remote --tags --refs --sort=-v:refname https://github.com/zimfw/zimfw.git 'v*') || return 1
>! ${_zversion_target} <<<${${${(f)tags}##*v}[1]} || return 1
fi
fi
if [[ -f ${_zversion_target} ]]; then
local -r zlatest_version=$(<${_zversion_target})
if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
_zimfw_print -u2 -R "${_zyellow}Latest zimfw version is ${_zbold}${zlatest_version}${_znormalyellow}. You're using version ${_zbold}${_zversion}${_znormalyellow}. Run ${_zbold}zimfw upgrade${_znormalyellow} to upgrade.${_znormal}"
return 4
fi
fi
}

View file

@ -1,9 +1,8 @@
_zimfw_clean_compiled() {
# Array with unique dirs. ${ZIM_HOME} or any subdirectory should only occur once.
local -Ur zscriptdirs=(${ZIM_HOME} ${${_zdirs##${ZIM_HOME}/*}:A})
local -Ur zscriptdirs=(${ZIM_HOME:A} ${${(v)_zdirs##${ZIM_HOME:A}/*}:A})
local zopt
if (( _zprintlevel > 0 )) zopt='-v'
command rm -f ${zopt} ${^zscriptdirs}/**/*.zwc(|.old)(N) || return 1
command rm -f ${zopt} <%= home %>/<%= startup_files_glob %>.zwc(|.old)(N) || return 1
_zimfw_print -P '<%= done %>Done with clean-compiled. Run %Bzimfw compile%b to re-compile.'
if (( _zprintlevel > 0 )) zopt=-v
command rm -f ${zopt} ${^zscriptdirs}/**/*.zwc(|.old)(N) && \
_zimfw_print "Done with clean-compiled. Restart your terminal or run ${_zbold}zimfw compile${_znormal} to re-compile."
}

View file

@ -1,7 +1,7 @@
_zimfw_clean_dumpfile() {
local zdumpfile zopt
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump
if (( _zprintlevel > 0 )) zopt='-v'
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old))(N) || return 1
_zimfw_print -P '<%= done %>Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
if (( _zprintlevel > 0 )) zopt=-v
command rm -f ${zopt} ${zdumpfile}(|.dat|.zwc(|.old))(N) && \
_zimfw_print -R "Done with clean-dumpfile.${_zrestartmsg}"
}

View file

@ -1,5 +1,16 @@
_zimfw_compile() {
local zopt
if (( _zprintlevel <= 0 )) zopt='-q'
source ${ZIM_HOME}/login_init.zsh ${zopt}
# Compile zimfw scripts
local zroot_dir zfile
for zroot_dir in ${_zroot_dirs:|_zdisabled_root_dirs}; do
if [[ ! -w ${zroot_dir} ]]; then
_zimfw_print -R "${_zwarn}${_zbold}${zroot_dir}:${_znormalyellow} No write permission, unable to compile.${_znormal}"
continue
fi
for zfile in ${zroot_dir}/(^*test*/)#*.zsh(|-theme)(N-.); do
if [[ ! ${zfile}.zwc -nt ${zfile} ]]; then
zcompile -UR ${zfile} && _zimfw_print -R "${_zokay}${_zbold}${zfile}.zwc:${_znormal} Compiled"
fi
done
done
_zimfw_print 'Done with compile.'
}

View file

@ -1,6 +1,10 @@
_zimfw_info() {
_zimfw_info_print_symlink 'zimfw config' ${_zconfig}
_zimfw_info_print_symlink ZIM_HOME ${ZIM_HOME}
_zimfw_info_print_symlink 'zimfw script' ${__ZIMFW_FILE}
print -R 'zimfw version: '${_zversion}' (built at <%= Time.now.utc %>, previous commit is <%= `git rev-parse --short HEAD | tr -d '\r\n'` %>)'
print -R 'ZIM_HOME: '${ZIM_HOME}
print -R 'Zsh version: '${ZSH_VERSION}
print -R 'System info: '$(command uname -a)
local zparam
for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZSH_VERSION; do
print -R ${(r.22....:.)zparam}${(P)zparam}
done
}

View file

@ -0,0 +1,5 @@
_zimfw_info_print_symlink() {
print -Rn ${(r.22....:.)1}${2}
if [[ -L ${2} ]] print -Rn ' -> '${2:A}
print
}

View file

@ -1,15 +1,17 @@
_zimfw_uninstall() {
local zopt
if (( _zprintlevel > 0 )) zopt='-v'
local zuninstalls=(${ZIM_HOME}/modules/*(N/:t))
# Uninstall all installed modules not in _zmodules and _zdisableds
zuninstalls=(${${zuninstalls:|_zmodules}:|_zdisableds})
if (( ${#zuninstalls} )); then
_zimfw_print -PR %B${(F)zuninstalls}%b
if (( _zprintlevel <= 0 )) || read -q "?Uninstall ${#zuninstalls} module(s) listed above [y/N]? "; then
_zimfw_print
command rm -rf ${zopt} ${ZIM_HOME}/modules/${^zuninstalls} || return 1
if (( _zprintlevel <= 0 )); then
command rm -rf ${_zunused_dirs} || return 1
else
local zunused_dir
print "Found ${_zbold}${#_zunused_dirs}${_znormal} unused module(s)."
for zunused_dir in ${_zunused_dirs}; do
if read -q "?Uninstall ${zunused_dir} [y/N]? "; then
print
command rm -rfv ${zunused_dir} || return 1
else
print
fi
done
print 'Done with uninstall.'
fi
_zimfw_print -P '<%= done %>Done with uninstall.'
}

View file

@ -1,14 +1,19 @@
_zimfw_upgrade() {
local -r ztarget=${ZIM_HOME}/zimfw.zsh
local -r zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
local -r ztarget=${__ZIMFW_FILE:A} zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
if [[ ! -w ${ztarget:h} ]]; then
print -u2 -R "${_zred}No write permission to ${_zbold}${ztarget:h}${_znormalred}. Will not try to upgrade.${_znormal}"
return 1
fi
{
if (( ${+commands[curl]} )); then
command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1
else
local zopt
if (( _zprintlevel <= 1 )) zopt='-q'
if (( _zprintlevel <= 1 )) zopt=-q
if ! command wget -nv ${zopt} -O ${ztarget}.new.gz ${zurl}; then
if (( _zprintlevel <= 1 )) print -u2 -PR "%F{red}<%= error %>Error downloading %B${zurl}%b. Use %B-v%b option to see details.%f"
if (( _zprintlevel <= 1 )); then
print -u2 -R "${_zred}Failed to download ${_zbold}${zurl}${_znormalred}. Use ${_zbold}-v${_znormalred} option to see details.${_znormal}"
fi
return 1
fi
fi
@ -16,7 +21,7 @@ _zimfw_upgrade() {
# .latest_version can be outdated and will yield a false warning if zimfw is
# upgraded before .latest_version is refreshed. Bad thing about having a cache.
_zimfw_mv ${ztarget}{.new,} && command rm -f ${ZIM_HOME}/.latest_version && \
_zimfw_print -P '<%= done %>Done with upgrade.'
_zimfw_print 'Done with upgrade.'
} always {
command rm -f ${ztarget}.new{,.gz}
}

View file

@ -0,0 +1,44 @@
_zimfw_run_list() {
local -r zname=${1}
local -r zdir=${_zdirs[${zname}]}
print -nR "${_zbold}${zname}:${_znormal} ${zdir}"
if [[ -z ${_zurls[${zname}]} ]] print -n ' (external)'
if (( ${_zfrozens[${zname}]} )) print -n ' (frozen)'
if (( ${_zdisabled_root_dirs[(I)${zdir}]} )) print -n ' (disabled)'
print
if (( _zprintlevel > 1 )); then
if [[ ${_zfrozens[${zname}]} -eq 0 && -n ${_zurls[${zname}]} ]]; then
if [[ ${_ztools[${zname}]} == mkdir ]]; then
print ' From: mkdir'
else
print -nR " From: ${_zurls[${zname}]}, "
if [[ -z ${_zrevs[${zname}]} ]]; then
print -n 'default branch'
else
print -nR "${_ztypes[${zname}]} ${_zrevs[${zname}]}"
fi
print -nR ", using ${_ztools[${zname}]}"
if (( ! _zsubmodules[${zname}] )) print -n ', no git submodules'
print
fi
if [[ -n ${_zonpulls[${zname}]} ]] print -R " On-pull: ${_zonpulls[${zname}]}"
fi
# Match the current module dir prefix from _zroot_dirs
local -r zroot_dirs=(${(M)_zroot_dirs:#${zdir}/*})
if (( ${#zroot_dirs} )); then
print ' Additional root:'
local zroot_dir
for zroot_dir in ${zroot_dirs}; do
print -nR " ${zroot_dir}"
if (( ${_zdisabled_root_dirs[(I)${zroot_dir}]} )) print -n ' (disabled)'
print
done
fi
# Match and remove the prefix from _zfpaths, _zfunctions and _zcmds
local -r zpre="${(q)zdir}(|/*)"$'\0'
local -r zfpaths=(${${(M)_zfpaths:#${~zpre}*}#${~zpre}}) zfunctions=(${${(M)_zfunctions:#${~zpre}*}#${~zpre}}) zcmds=(${${(M)_zcmds:#${~zpre}*}#${~zpre}})
if (( ${#zfpaths} )) print -R ' fpath: '${zfpaths}
if (( ${#zfunctions} )) print -R ' autoload: '${zfunctions}
if (( ${#zcmds} )) print -R ' cmd: '${(j:; :)zcmds}
fi
}

View file

@ -0,0 +1,6 @@
_zimfw_create_dir() {
if ! ERR=$(command mkdir -p ${1} 2>&1); then
_zimfw_print_error "Error creating ${1}" ${ERR}
return 1
fi
}

View file

@ -0,0 +1,3 @@
_zimfw_print_error() {
print -u2 -lR $'<%= clear_line %>'"${_zerror}${_zbold}${_zname}:${_znormalred} ${1}${_znormal}" ${2:+${(F):- ${(f)^2}}}
}

View file

@ -0,0 +1,3 @@
_zimfw_print_okay() {
if (( _zprintlevel > ${2:-0} )) print -lR $'<%= clear_line %>'"${_zokay}${_zbold}${_zname}:${_znormal} ${1}" ${3:+${(F):- ${(f)^3}}}
}

View file

@ -0,0 +1,3 @@
_zimfw_print_warn() {
_zimfw_print -u2 -R $'<%= clear_line %>'"${_zwarn}${_zbold}${_zname}:${_znormalyellow} ${1}${_znormal}"
}

View file

@ -0,0 +1,13 @@
_zimfw_pull_print_okay() {
# Useb by tools, which run in a subshell
if [[ -n ${ONPULL} ]]; then
if ! ERR=$(builtin cd -q ${DIR} 2>&1 && builtin eval ${ONPULL} 2>&1); then
_zimfw_print_error 'Error during on-pull' ${ERR}
return 1
elif [[ ${_zprintlevel} -gt 1 && -n ${ERR} ]]; then
# Overrides ${3} to include the on-pull output, to be used by _zimfw_print_okay below.
builtin set ${1} ${2:-0} ${3:+${3}$'\n'}'On-pull output:'$'\n'${ERR}
fi
fi
_zimfw_print_okay "${@}"
}

View file

@ -0,0 +1,151 @@
_zimfw_download_tarball() {
if [[ ${URL} =~ <%= url_regex %> ]]; then
readonly HOST=${match[3]}
readonly REPO=${match[4]%.git}
fi
if [[ ${HOST} != github.com || -z ${REPO} ]]; then
_zimfw_print_error "${URL} is not a valid URL. Will not try to ${ACTION}. The zimfw degit tool only supports GitHub URLs. Use zmodule option ${_zbold}--use git${_znormalred} to use git instead."
return 1
fi
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
{
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
# Previous REV is in line 2, reserved for future use.
readonly INFO_HEADER=${INFO[3]}
readonly TARBALL_URL=https://api.github.com/repos/${REPO}/tarball/${REV}
if [[ ${ACTION} == check ]]; then
if [[ -z ${INFO_HEADER} ]] return 0
if (( ${+commands[curl]} )); then
command curl -IfsL -H ${INFO_HEADER} ${TARBALL_URL} >${HEADERS_TARGET}
else
command wget --spider -qS --header=${INFO_HEADER} ${TARBALL_URL} 2>${HEADERS_TARGET}
fi
else
if (( ${+commands[curl]} )); then
if ! ERR=$(command curl -fsSL ${INFO_HEADER:+-H} ${INFO_HEADER} -o ${TARBALL_TARGET} -D ${HEADERS_TARGET} ${TARBALL_URL} 2>&1); then
_zimfw_print_error "Error downloading ${TARBALL_URL} with curl" ${ERR}
return 1
fi
else
# wget returns 8 when 304 Not Modified, so we cannot use wget's error codes
command wget -qS ${INFO_HEADER:+--header=${INFO_HEADER}} -O ${TARBALL_TARGET} ${TARBALL_URL} 2>${HEADERS_TARGET}
fi
fi
while IFS= read -r HEADER; do
HEADER=${${HEADER## ##}%%$'\r'##}
if [[ ${HEADER} == HTTP/* ]]; then
HTTP_CODE=${${(s: :)HEADER}[2]}
elif [[ ${${(L)HEADER%%:*}%% ##} == etag ]]; then
ETAG=${${HEADER#*:}## ##}
fi
done < ${HEADERS_TARGET}
if (( HTTP_CODE == 304 )); then
# Not Modified
command rm -f ${TARBALL_TARGET} 2>/dev/null
return 0
elif (( HTTP_CODE != 200 )); then
_zimfw_print_error "Error downloading ${TARBALL_URL}, HTTP code ${HTTP_CODE}"
return 1
fi
if [[ -z ${ETAG} ]]; then
_zimfw_print_error "Error downloading ${TARBALL_URL}, no ETag header found in response"
return 1
fi
if [[ ${ACTION} == check ]]; then
command touch ${TARBALL_TARGET} # Update available
else
if ! print -lR "${URL}" "${REV}" "If-None-Match: ${ETAG}" >! ${INFO_TARGET} 2>/dev/null; then
_zimfw_print_error "Error creating or updating ${INFO_TARGET}"
return 1
fi
fi
} always {
command rm -f ${HEADERS_TARGET} 2>/dev/null
}
}
_zimfw_untar_tarball() {
if ! ERR=$(command tar -C ${1} -xzf ${TARBALL_TARGET} 2>&1); then
_zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR}
return 1
fi
local zsubdir
for zsubdir in ${1}/*(/); do
if ! ERR=$(command mv -f ${zsubdir}/*(DN) ${1} 2>&1 && command rmdir ${zsubdir} 2>&1); then
_zimfw_print_error "Error moving ${zsubdir}" ${ERR}
return 1
fi
done
}
_zimfw_tool_degit() {
# This runs in a subshell
readonly -i SUBMODULES=${6}
readonly ACTION=${1} DIR=${2} URL=${3} REV=${5} ONPULL=${7} TEMP=.zdegit_${sysparams[pid]}_${RANDOM}
readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit
case ${ACTION} in
pre|prereinstall)
local premsg
if [[ ${ACTION} == pre ]] premsg=" Use zmodule option ${_zbold}-z${_znormalred}|${_zbold}--frozen${_znormalred} to disable this error or run ${_zbold}zimfw reinstall${_znormalred} to reinstall."
if [[ -e ${DIR} ]]; then
if [[ ! -r ${INFO_TARGET} ]]; then
_zimfw_print_error $'Module was not installed using zimfw\'s degit.'${premsg}
return 1
fi
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
if [[ ${URL} != ${INFO[1]} ]]; then
_zimfw_print_error 'The zimfw degit URL does not match. Expected '${URL}.${premsg}
return 1
fi
fi
return 0
;;
install)
{
_zimfw_create_dir ${DIR} && _zimfw_download_tarball && _zimfw_untar_tarball ${DIR} && _zimfw_pull_print_okay Installed || return 1
} always {
# return 1 does not change ${TRY_BLOCK_ERROR}, only changes ${?}
(( TRY_BLOCK_ERROR = ? ))
command rm -f ${TARBALL_TARGET} 2>/dev/null
if (( TRY_BLOCK_ERROR )) command rm -rf ${DIR} 2>/dev/null
}
;;
check|update)
readonly DIR_NEW=${DIR}${TEMP}
{
_zimfw_download_tarball || return 1
if [[ ${ACTION} == check ]]; then
if [[ -e ${TARBALL_TARGET} ]]; then
_zimfw_print_okay 'Update available'
return 4
fi
_zimfw_print_okay 'Already up to date' 1
return 0
else
if [[ -e ${TARBALL_TARGET} ]]; then
_zimfw_create_dir ${DIR_NEW} && _zimfw_untar_tarball ${DIR_NEW} || return 1
if (( ${+commands[diff]} )); then
LOG=$(command diff -x '.zdegit*' -x '*.zwc' -x '*.zwc.old' -qr ${DIR} ${DIR_NEW} 2>/dev/null)
LOG=${${LOG//${DIR_NEW}/new}//${DIR}/old}
fi
if ! ERR=$({ command cp -f ${INFO_TARGET} ${DIR_NEW} && \
command rm -rf ${DIR} && command mv -f ${DIR_NEW} ${DIR} } 2>&1); then
_zimfw_print_error "Error updating ${DIR}" ${ERR}
return 1
fi
_zimfw_pull_print_okay Updated 0 ${LOG} || return 1
else
_zimfw_pull_print_okay 'Already up to date' || return 1
fi
fi
} always {
command rm -f ${TARBALL_TARGET} 2>/dev/null
command rm -rf ${DIR_NEW} 2>/dev/null
}
;;
esac
# Check after successful install or update
if [[ ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then
_zimfw_print_warn "Module contains git submodules, which are not supported by zimfw's degit. Use zmodule option ${_zbold}--no-submodules${_znormalyellow} to disable this warning."
fi
}

View file

@ -0,0 +1,103 @@
_zimfw_tool_git() {
# This runs in a subshell
readonly -i SUBMODULES=${6}
readonly ACTION=${1} DIR=${2} URL=${3} TYPE=${4} ONPULL=${7}
REV=${5}
case ${ACTION} in
pre|prereinstall)
local premsg
if [[ ${ACTION} == pre ]] premsg=" Use zmodule option ${_zbold}-z${_znormalred}|${_zbold}--frozen${_znormalred} to disable this error or run ${_zbold}zimfw reinstall${_znormalred} to reinstall."
if [[ -e ${DIR} ]]; then
if [[ ! -r ${DIR}/.git ]]; then
_zimfw_print_error 'Module was not installed using git.'${premsg}
return 1
fi
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
_zimfw_print_error 'The git URL does not match. Expected '${URL}.${premsg}
return 1
fi
fi
;;
install)
if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then
_zimfw_pull_print_okay Installed
else
_zimfw_print_error 'Error during git clone' ${ERR}
return 1
fi
;;
check|update)
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then
_zimfw_print_error 'Error during git fetch' ${ERR}
return 1
fi
if [[ ${TYPE} == branch ]]; then
if [[ -z ${REV} ]]; then
# Get HEAD remote branch
if ! ERR=$(command git -C ${DIR} remote set-head origin -a 2>&1); then
_zimfw_print_error 'Error during git remote set-head' ${ERR}
return 1
fi
if REV=$(command git -C ${DIR} symbolic-ref --short refs/remotes/origin/HEAD 2>&1); then
REV=${REV#origin/}
else
_zimfw_print_error 'Error during git symbolic-ref' ${REV}
return 1
fi
fi
TO_REV=${REV}@{u}
if [[ ${ACTION} == check ]]; then
readonly -i BEHIND=$(command git -C ${DIR} rev-list --count ${REV}..${TO_REV} -- 2>/dev/null)
if (( BEHIND )); then
_zimfw_print_okay "Update available [behind ${BEHIND}]"
return 4
else
_zimfw_print_okay 'Already up to date' 1
return 0
fi
fi
else
if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then
if [[ ${ACTION} == check ]]; then
_zimfw_print_okay 'Already up to date' 1
return 0
else
_zimfw_pull_print_okay 'Already up to date'
return ${?}
fi
fi
if [[ ${ACTION} == check ]]; then
_zimfw_print_okay 'Update available'
return 4
fi
TO_REV=${REV}
fi
if [[ -z ${NO_COLOR} ]]; then
LOG=$(command git -C ${DIR} log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${TO_REV} -- 2>/dev/null)
else
LOG=$(command git -C ${DIR} log --graph --format='%h %s (%cr)' ..${TO_REV} -- 2>/dev/null)
fi
if ! ERR=$(command git -C ${DIR} checkout -q ${REV} -- 2>&1); then
_zimfw_print_error 'Error during git checkout' ${ERR}
return 1
fi
if [[ ${TYPE} == branch ]]; then
if ! OUT=$(command git -C ${DIR} merge --ff-only --no-progress -n 2>&1); then
_zimfw_print_error 'Error during git merge' ${OUT}
return 1
fi
# keep just first line of OUT
OUT=${OUT%%($'\n'|$'\r')*}
else
OUT="Updating to ${TYPE} ${REV}"
fi
if (( SUBMODULES )); then
if ! ERR=$(command git -C ${DIR} submodule update --init --recursive -q -- 2>&1); then
_zimfw_print_error 'Error during git submodule update' ${ERR}
return 1
fi
fi
_zimfw_pull_print_okay ${OUT} 0 ${LOG}
;;
esac
}

View file

@ -0,0 +1,15 @@
_zimfw_tool_mkdir() {
# This runs in a subshell
readonly -i SUBMODULES=${6}
readonly ACTION=${1} DIR=${2} TYPE=${4} REV=${5} ONPULL=${7}
if [[ ${ACTION} == (pre|prereinstall|check) ]] return 0
if [[ -n ${REV} ]]; then
_zimfw_print_warn "The zmodule option ${_zbold}-${TYPE[1]}${_znormalyellow}|${_zbold}--${TYPE}${_znormalyellow} has no effect when using the mkdir tool"
fi
if (( ! SUBMODULES )); then
_zimfw_print_warn "The zmodule option ${_zbold}--no-submodules${_znormalyellow} has no effect when using the mkdir tool"
fi
if [[ ! -d ${DIR} || -n ${ONPULL} ]]; then
_zimfw_create_dir ${DIR} && _zimfw_pull_print_okay Created || return 1
fi
}

View file

@ -0,0 +1,68 @@
_zimfw_run_tool() {
local zaction=${1}
local -r _zname=${2}
if [[ -z ${_zurls[${_zname}]} ]]; then
_zimfw_print_okay 'Skipping external module' 1
return 0
fi
if (( _zfrozens[${_zname}] )); then
_zimfw_print_okay 'Skipping frozen module' 1
return 0
fi
local -r ztool=${_ztools[${_zname}]}
if [[ ${ztool} != (degit|git|mkdir) ]]; then
_zimfw_print_error "Unknown tool ${ztool}"
return 1
fi
set "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
if [[ ${zaction} == reinstall ]]; then
_zimfw_tool_${ztool} prereinstall "${@}" && return 0
if (( _zprintlevel > 0 )); then
if read -q "?Reinstall ${_zname} [y/N]? "; then
print
else
print
return 0
fi
fi
local -r zdir_new=.${_zdirs[${_zname}]}_${sysparams[pid]}_${RANDOM}
_zimfw_print -nR 'Reinstalling '${_zname}'<%= ellipsis %>'
{
_zimfw_tool_${ztool} install ${zdir_new} "${@:2}" || return 1
if ! ERR=$({ command rm -rf ${_zdirs[${_zname}]} && command mv -f ${zdir_new} ${_zdirs[${_zname}]} } 2>&1); then
_zimfw_print_error "Error updating ${_zdirs[${_zname}]}" ${ERR}
return 1
fi
} always {
command rm -rf ${zdir_new} 2>/dev/null
}
return 0
else
_zimfw_tool_${ztool} pre "${@}" || return 1
fi
case ${zaction} in
install)
if [[ -e ${_zdirs[${_zname}]} ]]; then
_zimfw_print_okay 'Skipping already installed module' 1
return 0
fi
_zimfw_print -nR $'<%= clear_line %>Installing '${_zname}'<%= ellipsis %>'
;;
check|update)
if [[ ! -d ${_zdirs[${_zname}]} ]]; then
_zimfw_print_error "Not installed. Run ${_zbold}zimfw install${_znormalred} to install."
return 1
fi
if [[ ${zaction} == check ]]; then
if (( _zprintlevel > 1 )) print -nR $'<%= clear_line %>Checking '${_zname}'<%= ellipsis %>'
else
_zimfw_print -nR $'<%= clear_line %>Updating '${_zname}'<%= ellipsis %>'
fi
;;
*)
_zimfw_print_error "Unknown action ${zaction}"
return 1
;;
esac
_zimfw_tool_${ztool} ${zaction} "${@}"
}

View file

@ -0,0 +1,7 @@
_zimfw_run_tool_action() {
local -i zmaxprocs=0
if [[ ${1} == reinstall ]] zmaxprocs=1
_zimfw_source_zimrc 1 || return 1
zargs -n 2 -P ${zmaxprocs} -- "${_znames[@]}" -- _zimfw_run_tool ${1}
return 0
}

View file

@ -1,86 +1,122 @@
zimfw() {
local -r _zversion='<%= version %>'
local -r zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
builtin emulate -L zsh -o EXTENDED_GLOB
if [[ -z ${NO_COLOR} ]]; then
local -r _znormal=$'\E[0m' _zbold=$'\E[1m' _zred=$'\E[31m' _znormalred=$'\E[0;31m' _zgreen=$'\E[32m' _zyellow=$'\E[33m' _znormalyellow=$'\E[0;33m'
else
local -r _znormal= _zbold= _zred= _znormalred= _zgreen= _zyellow= _znormalyellow=
fi
local -r _zerror="${_zred}<%= error %>" _zokay="${_zgreen}<%= okay %>${_znormal}" _zwarn="${_zyellow}<%= warn %>"
local -r _zconfig=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} _zversion='<%= version %>'
local -r zusage="Usage: ${_zbold}${0}${_znormal} <action> [${_zbold}-q${_znormal}|${_zbold}-v${_znormal}]
Actions:
%Bbuild%b Build %Binit.zsh%b and %Blogin_init.zsh%b
%Bclean%b Clean all (see below)
%Bclean-compiled%b Clean Zsh compiled files
%Bclean-dumpfile%b Clean completion dump file
%Bcompile%b Compile Zsh files
%Bhelp%b Print this help
%Binfo%b Print Zim and system info
%Binstall%b Install new modules
%Buninstall%b Delete unused modules
%Bupdate%b Update current modules
%Bupgrade%b Upgrade %Bzimfw.zsh%b
%Bversion%b Print Zim version
${_zbold}build${_znormal} Build ${_zbold}${ZIM_HOME}/init.zsh${_znormal} and ${_zbold}${ZIM_HOME}/login_init.zsh${_znormal}.
Also does ${_zbold}compile${_znormal}. Use ${_zbold}-v${_znormal} to also see its output.
${_zbold}clean${_znormal} Clean all. Does both ${_zbold}clean-compiled${_znormal} and ${_zbold}clean-dumpfile${_znormal}.
${_zbold}clean-compiled${_znormal} Clean Zsh compiled files.
${_zbold}clean-dumpfile${_znormal} Clean completion dumpfile.
${_zbold}compile${_znormal} Compile Zsh files.
${_zbold}help${_znormal} Print this help.
${_zbold}info${_znormal} Print zimfw and system info.
${_zbold}list${_znormal} List all modules currently defined in ${_zbold}${_zconfig}${_znormal}.
Use ${_zbold}-v${_znormal} to also see the modules details.
${_zbold}init${_znormal} Same as ${_zbold}install${_znormal}, but with output tailored to be used at terminal startup.
${_zbold}install${_znormal} Install new modules. Also does ${_zbold}build${_znormal}, ${_zbold}compile${_znormal}. Use ${_zbold}-v${_znormal} to also see their
output, any on-pull output and skipped modules.
${_zbold}reinstall${_znormal} Reinstall modules that failed check. Prompts for confirmation. Use ${_zbold}-q${_znormal} for
quiet reinstall. Also does ${_zbold}build${_znormal}, ${_zbold}compile${_znormal}. Use ${_zbold}-v${_znormal} to also see their output,
any on-pull output and skipped modules.
${_zbold}uninstall${_znormal} Delete unused modules. Prompts for confirmation. Use ${_zbold}-q${_znormal} for quiet uninstall.
${_zbold}check${_znormal} Check if updates for current modules are available. Use ${_zbold}-v${_znormal} to also see
skipped and up to date modules.
${_zbold}update${_znormal} Update current modules. Also does ${_zbold}build${_znormal}, ${_zbold}compile${_znormal}. Use ${_zbold}-v${_znormal} to also see their
output, any on-pull output and skipped modules.
${_zbold}check-version${_znormal} Check if a new version of zimfw is available.
${_zbold}upgrade${_znormal} Upgrade zimfw. Also does ${_zbold}compile${_znormal}. Use ${_zbold}-v${_znormal} to also see its output.
${_zbold}version${_znormal} Print zimfw version.
Options:
%B-q%b Quiet (yes to prompts, and only outputs errors)
%B-v%b Verbose
"
local ztool
local -a _zdisableds _zmodules _zdirs _zfpaths _zfunctions _zcmds _zmodules_zargs
${_zbold}-q${_znormal} Quiet (yes to prompts and only outputs errors)
${_zbold}-v${_znormal} Verbose (outputs more details)"
local -Ua _znames _zroot_dirs _zdisabled_root_dirs
local -A _zfrozens _ztools _zdirs _zurls _ztypes _zrevs _zsubmodules _zonpulls _zifs
local -a _zfpaths _zfunctions _zcmds _zunused_dirs
local -i _zprintlevel=1
if (( # > 2 )); then
print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage}
return 1
print -u2 -lR "${_zred}${0}: Too many options${_znormal}" '' ${zusage}
return 2
elif (( # > 1 )); then
case ${2} in
-q) _zprintlevel=0 ;;
-v) _zprintlevel=2 ;;
*)
print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n\n'${zusage}
print -u2 -lR "${_zred}${0}: Unknown option ${2}${_znormal}" '' ${zusage}
return 2
;;
esac
fi
local -r _zversion_target=${ZIM_HOME}/.latest_version
if ! zstyle -t ':zim' disable-version-check && \
[[ ${1} != check-version && -w ${ZIM_HOME} && -w ${__ZIMFW_FILE:A:h} ]]
then
# If .latest_version does not exist or was not modified in the last 30 days
[[ -f ${_zversion_target}(#qNm-30) ]]; local -r zversion_check_force=${?}
_zimfw_check_version ${zversion_check_force} 1
fi
if [[ ! -w ${ZIM_HOME} && ${1} == (build|check|init|install|update|reinstall|check-version) ]]; then
print -u2 -R "${_zred}${0}: No write permission to ${_zbold}${ZIM_HOME}${_znormalred}. Will not try to ${1}.${_znormal}"
return 1
;;
esac
fi
if ! zstyle -t ':zim' disable-version-check; then
_zimfw_version_check
fi
case ${1} in
install)
ztool="<%= render_escaped("src/tools/install.zsh.erb") %>"
;;
update)
ztool="<%= render_escaped("src/tools/update.zsh.erb") %>"
;;
esac
local _zrestartmsg=' Restart your terminal for changes to take effect.'
case ${1} in
build)
_zimfw_source_zimrc && _zimfw_build || return 1
_zimfw_source_zimrc 2 && _zimfw_build || return 1
(( _zprintlevel-- ))
_zimfw_compile
;;
init) _zimfw_source_zimrc && _zimfw_build ;;
clean) _zimfw_source_zimrc && _zimfw_clean_compiled && _zimfw_clean_dumpfile ;;
clean-compiled) _zimfw_source_zimrc && _zimfw_clean_compiled ;;
check-dumpfile) _zimfw_check_dumpfile ;;
clean) _zimfw_source_zimrc 0 && _zimfw_clean_compiled && _zimfw_clean_dumpfile ;;
clean-compiled) _zimfw_source_zimrc 0 && _zimfw_clean_compiled ;;
clean-dumpfile) _zimfw_clean_dumpfile ;;
compile) _zimfw_source_zimrc && _zimfw_build_login_init && _zimfw_compile ;;
help) print -PR ${zusage} ;;
compile) _zimfw_source_zimrc 0 && _zimfw_compile ;;
help) print -R ${zusage} ;;
info) _zimfw_info ;;
install|update)
_zimfw_source_zimrc 1 || return 1
autoload -Uz zargs && \
zargs -n 9 -P 10 -- "${_zmodules_zargs[@]}" -- zsh -c ${ztool} ${1} && \
_zimfw_print -PR "<%= done %>Done with ${1}. Restart your terminal for any changes to take effect." || return 1
(( _zprintlevel-- ))
_zimfw_source_zimrc && _zimfw_build && _zimfw_compile
list)
_zimfw_source_zimrc 3 && zargs -n 1 -- "${_znames[@]}" -- _zimfw_run_list && \
_zimfw_list_unuseds ' (unused)'
;;
uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;;
check)
_zrestartmsg=
_zimfw_run_tool_action ${1} || return 1
(( _zprintlevel-- ))
_zimfw_print -R "Done with ${1}." # Only printed in verbose mode
;;
init)
_zrestartmsg=
_zimfw_run_tool_action install || return 1
(( _zprintlevel-- ))
_zimfw_print 'Done with install.' # Only printed in verbose mode
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
;;
install|update|reinstall)
_zimfw_run_tool_action ${1} || return 1
_zimfw_print -R "Done with ${1}.${_zrestartmsg}"
(( _zprintlevel-- ))
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
;;
uninstall) _zimfw_source_zimrc 0 && _zimfw_list_unuseds && _zimfw_uninstall ;;
check-version) _zimfw_check_version 1 ;;
upgrade)
_zimfw_upgrade || return 1
(( _zprintlevel-- ))
_zimfw_compile
_zimfw_source_zimrc 0 && _zimfw_compile
;;
version) print -PR ${_zversion} ;;
version) print -R ${_zversion} ;;
*)
print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n\n'${zusage}
return 1
print -u2 -lR "${_zred}${0}: Unknown action ${1}${_znormal}" '' ${zusage}
return 2
;;
esac
}

View file

@ -1,23 +0,0 @@
() {
setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB
autoload -Uz zrecompile
local zdumpfile zfile
# Compile the completion cache; significant speedup
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump
if [[ -f ${zdumpfile} ]]; then
zrecompile -p ${1} ${zdumpfile} || return 1
fi
# Compile Zsh startup files
for zfile in <%= home %>/<%= startup_files_glob %>(N-.); do
zrecompile -p ${1} ${zfile} || return 1
done
# Compile Zim scripts
for zfile in #{zscriptglob}; do
zrecompile -p ${1} ${zfile} || return 1
done
if [[ ${1} != -q ]] print -P '<%= done %>Done with compile.'
} "${@}"

View file

@ -1,18 +0,0 @@
# This runs in a new shell
readonly MODULE=${1}
readonly DIR=${2}
readonly URL=${3}
readonly BRANCH=${5:+-b ${5}}
readonly -i PRINTLEVEL=${6}
readonly CLEAR_LINE=$'\E[2K\r'
if [[ -e ${DIR} ]]; then
# Already exists
return 0
fi
if (( PRINTLEVEL > 0 )) print -Rn ${CLEAR_LINE}"Installing ${MODULE}<%= ellipsis %>"
if ERR=$(command git clone ${=BRANCH} -q --recursive ${URL} ${DIR} 2>&1); then
if (( PRINTLEVEL > 0 )) print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Installed"
else
print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git clone%f"$'\n'${(F):- ${(f)^ERR}}
return 1
fi

View file

@ -1,66 +0,0 @@
# This runs in a new shell
readonly MODULE=${1}
readonly DIR=${2}
readonly URL=${3}
readonly TYPE=${4:=branch}
REV=${5}
readonly -i PRINTLEVEL=${6}
readonly CLEAR_LINE=$'\E[2K\r'
if (( PRINTLEVEL > 0 )) print -Rn ${CLEAR_LINE}"Updating ${MODULE}<%= ellipsis %>"
if ! builtin cd -q ${DIR} 2>/dev/null; then
print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Not installed. Run %Bzimfw install%b to install.%f"
return 1
fi
if [[ ${PWD} != $(command git rev-parse --show-toplevel 2>/dev/null) ]]; then
# Not in repo root. Will not try to update.
return 0
fi
if [[ ${URL} != $(command git config --get remote.origin.url) ]]; then
print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b URL does not match. Expected ${URL}. Will not try to update.%f"
return 1
fi
if ! ERR=$(command git fetch -pq origin 2>&1); then
print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git fetch%f"$'\n'${(F):- ${(f)^ERR}}
return 1
fi
if [[ ${TYPE} == tag ]]; then
if [[ ${REV} == $(command git describe --tags --exact-match 2>/dev/null) ]]; then
if (( PRINTLEVEL > 0 )) print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Already up to date"
return 0
fi
elif [[ -z ${REV} ]]; then
# Get HEAD remote branch
if ! ERR=$(command git remote set-head origin -a 2>&1); then
print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git remote set-head%f"$'\n'${(F):- ${(f)^ERR}}
return 1
fi
REV=${$(command git symbolic-ref --short refs/remotes/origin/HEAD)#origin/} || return 1
fi
if [[ ${TYPE} == branch ]]; then
LOG_REV=${REV}@{u}
else
LOG_REV=${REV}
fi
LOG=$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${LOG_REV} -- 2>/dev/null)
if ! ERR=$(command git checkout -q ${REV} -- 2>&1); then
print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git checkout%f"$'\n'${(F):- ${(f)^ERR}}
return 1
fi
if [[ ${TYPE} == branch ]]; then
if ! OUT=$(command git merge --ff-only --no-progress -n 2>&1); then
print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git merge%f"$'\n'${(F):- ${(f)^OUT}}
return 1
fi
# keep just first line of OUT
OUT=${OUT%%($'\n'|$'\r')*}
else
OUT="Updating to ${TYPE} ${REV}"
fi
if ! ERR=$(command git submodule update --init --recursive -q 2>&1); then
print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git submodule update%f"$'\n'${(F):- ${(f)^ERR}}
return 1
fi
if (( PRINTLEVEL > 0 )); then
if [[ -n ${LOG} ]] OUT=${OUT}$'\n'${(F):- ${(f)^LOG}}
print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b ${OUT}"
fi

View file

@ -1,18 +1,21 @@
<%
class Zim
attr_reader :home, :min_zsh_version, :startup_files_glob, :version, :ellipsis, :okay, :warn, :error, :done, :failed
attr_reader :version, :home, :min_zsh_version, :url_regex,
:bold, :normal, :red, :normalred, :yellow, :normalyellow, :clear_line, :ellipsis, :okay, :warn, :error
def initialize
@version = "1.16.0-SNAPSHOT"
@home = "${ZDOTDIR:-${HOME}}"
@min_zsh_version = "5.2"
@startup_files_glob = ".z(shenv|profile|shrc|login|logout)"
@version = "1.4.2"
# Matches {ssh,http,https,git}://{user@,}host/org/repo and {user@,}host:org/repo
# but not file:///path/to/repo or /path/to/repo
# ${match[3]} contains host, and ${match[4]} contains org/repo
@url_regex = "^([^:@/]+://)?([^@]+@)?([^:/]+)[:/]([^/]+/[^/]+)/?$"
@clear_line = "\\E[2K\\r"
@ellipsis = " ..."
@okay = "%F{green})%f "
@okay = ") "
@warn = "! "
@error = "x "
@done = ""
@failed = ""
end
def render(filename)
@ -23,10 +26,6 @@ class Zim
Dir[pattern].sort.map { |filename| render(filename) }.join("\n")
end
def render_escaped(filename)
render(filename).gsub(/(?=\$[^']|"|`)/, "\\\\").gsub(/#\{/, "$\{")
end
def render_commented(filename)
render(filename).gsub(/^(?=.)/, "# ").gsub(/^$/, "#")
end

1160
zimfw.zsh

File diff suppressed because it is too large Load diff