zdharma-continuum / zinit

🌻 Flexible and fast ZSH plugin manager
MIT License
3.09k stars 128 forks source link

feat: Run commands via a CI-like INI file #422

Closed psprint closed 1 year ago

psprint commented 1 year ago

Description

A new feature: running of commands stored in INI file. The INI file of a command allows to set:

  1. Command run directory (CWD)
  2. Output and input redirections
  3. $fpath and $path
  4. Shell used to execute it
  5. Type (one of: binary, script (for sourcing), autoload function and eval code)

Example command (included in the PR):

[vars]
tmp=/tmp/$(mktemp)

[main]
type=binary
shell=
runnable=$EDITOR
run-path=%zi
disabled=no
quiet=io

[args]
arg-1=zinit.zsh
arg-2=zinit-install.zsh
arg-3=zinit-autoload.zsh
arg-4=zinit-side.zsh
arg-5=zinit-additional.zsh
arg-7=README.md
arg-8=functions/*~*~

[io]
in=/dev/tty
out=/dev/tty
err=/dev/tty

Motivation and Context

I've created a bigger project zseriveces/command-CI-server however it didn't start with momentum, so I thought that extending zinit might be a good idea – it has some sense to provide limited run support to just run the commands. It's nice, for example, that editing zinit sources after zi cmd zi that executes the example INI file (zinit.git/cmds/zi.ini) is possible.

The commands are searched in ~/.config/zinit/cmds and in $ZINIT[BIN_DIR]/cmds by default. Other commands will be found in $ZICMD_COMMAND_PATH variable (:-separated paths).

Related Issue(s)

Usage examples

zi cmd zi

How Has This Been Tested?

Types of changes

Checklist:

pschmitt commented 1 year ago

Sorry but I don't see why this should ever be part of zinit.

This is feature creep and only caters the need of a single person. Correct if I'm wrong but I just don't believe there's anyone else beside you that will use this.

psprint commented 1 year ago

I in general agree with you @pschmitt Yes it's a narrow feature. However I by intuition think that it can be part of zinit, because zinit is used to provide commands via shims. The INI commands can be seen as a manual shims. User could build a command that has its IO redirections tightly set and CWD and others. So for example instead of writing script or creating alias for fzf that greps files in a directory one could create an INI file with CWD set to the directory with some fancy input redirection like <(ls -1 $PWD) for example.

alichtman commented 1 year ago

Sure, but scripts are portable and this is not.

vladdoster commented 1 year ago

Not to beat a dead horse, but it would bitrot in zinit.

Could this not be an annex?