Skip to content

Shell Profile

B. van Berkum edited this page Jan 27, 2019 · 1 revision

User-Env Profile

After bootstrap each profile loads in a context where it can add make-like variables:

= ?= := +=

The sole purpose is to reduce verbosity in shell profile scripts, and to add missing assurances and conveniences.

Another more symbolic incentive is that after expansion back to shell variables becomes a static profile, which can be snapshot and used for example in build systems to validate caches while nothing (of interest) has changed.

The profile.d dir(s) provide all user-env desired in the form of modules with global shell code and possibly functions for callbacks.

Some specific scheme to deal with various types of profiles will need to be devised. But once all are loaded, and some hooks possibly executed, the final set of env vars can be compiled. And some of them exported as well.

Subshells meanwhile re-use the exported env, but reiterate the process. And add dependency on context, ie. PWD.

Candidates for profile.d:

  • per-project files, symlinked or otherwise synced or produced by a certain package. Can control when they want to add to 'static' user-env, or when projects executes with BASH_ENV=~/.profile for one of its own processes. Or with the help of some package wrapping as part of its private env.

  • per-account; user credentials and var. tokens will require other schemes for organization. These variables are unwanted in the general user env.

    And only specifically for user or even server processes. But a convenient way to bootstrap a system. Again, for security purposes, loading and dumping secrets from a short-lived specific session would be better.

Env collection heuristic:

  • Add var declarations to env_d_mk='' by libs
  • Add hooks to ... env_d='' by libs
  • Look for env.d and include every one with $env_d_match_env $i

Then expand/compile check, combining env_d_mk var and mk fragments from env.d

Once done execute hooks. The profile is finished except for remaining interactive bits. If applicable.

env.d.mk format

Essentially triples, with decorators to indicate assignment modes. This allows to alleviate some long standing irks about shell profile scripts.

  =   recursive
  :=  non-recursive ( POSIX has ::= somehwere? )

  ?   apply only if var not already set

  +   append value if value exists or set
  ++  insert value if value exists or set
  %   append value with ':' if value exists
  %.  append value with '.' if value exists, etc.
  %%.  etc.

  !   apply value from this shell command (make shorthand for := $(shell ...))
  @   apply only if value is existing path
  *   apply var if value expands to existing paths
  #   invert modifier after

 #@+  append if file does not exist
#*++  insert glob spec if not exists
  @?  set if var is not set, and file exists

Etc. etc. Obviously some seq. are ilegal. But using simple sequences allows to keep checks in wanted sequence.

The equal sign is superfluous as white space will be enforced around the triples.

Category: Profile
Interwiki for User-Scripts (About)
Repo Wiki
core/master wiki
- forks/bvb-dev wiki

Clone this wiki locally