Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Feature request: a command launcher


I came up with a feature that could be called "services". It's about defining a widely understood environment for a specified command. The point is that "environment" doesn't only mean: exported variables, but also: redirections, working directory, use of sudo, command arguments, etc. Present solutions like direnv/direnv handle only environment variables.

A definition of service could look like this:

# Definition of a service that builds Zsh located at
# ~/github/sfzsh3, with -O2 and pointers to libgdbm.
# This file is for configure script. File sfzsh3make
# is for running make, and is triggered automatically
# by this file

integer disabled=0
local command="./configure"

local arguments='--enable-unicode9'
integer spawn_type=0        # available: disown, fork, subshell, coproc, zpty, nohup;
                            # can combine to some extent, e.g. $(( fork | disown ))
integer run_method=command  # available: command, autofun, source

local stdin=""              # no redirection
local stdout="/dev/null"
local stderr=""

integer sudo=0
local run_first=""          # no service to run first
local run_last="sfzsh3make" # run sfzsh3make after this service

local workdir="$HOME/github/sfzsh3"
integer cd=1                # stay in $workdir after this service finishes

local -A env
    CFLAGS      "-g -Wall -O2"
    CPPFLAGS    "-I/usr/local/include"
    LDFLAGS     "-L/usr/local/lib"

Then, to compile Zsh, one would issue: zsrv build_sfzsh3. "zsrv" is hard to type, the name should be better.

Someone might ask: why not create a script that holds complete configure command and make invocation. So why e.g. OS X does the definition-way for its services, it could just create and collect scripts ;) I'll limit to just this: the definition is just a series of parameter assignments, it's like separating data from presentation (XML vs. HTML). All this is a subtle, but still a paradigm-shift.

I'm worried about how many use cases would this have. Above "Zsh building that doesn't need history-dig, cd and parsing 'is it -O0 or -O2, what did I run last time'" is a good use case. But are there more use cases, has someone ideas?

I came up with this idea for Zplugin, but decided to ask in feature-request style, because I really think that Zsh would gain from such feature. And I'm curious of possible code and alterations. But I also need feedback if this looks useful or not.

Sebastian Gniazdowski
psprint /at/ zdharma.org

Messages sorted by: Reverse Date, Date, Thread, Author