Skip to content
forked from smemsh/libsh

lib: bash source file inclusion system and small function library

Notifications You must be signed in to change notification settings

tabulon-ext/libsh-1

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libsh

DEVELOPMENT STOPPED

Python is a better use of time rather than something like libsh. Once it reaches a level of complexity there is little point in using bash anymore.

So, development is stopped no more changes will be made to this repository EOM


"lib shell"

Shell function include subsystem, with sample function library

Description

Selectively import individual functions or groups of related functions into the shell environment, without having to track dependencies, source file location, or source order.

Krufty collection of shell functions provided (collected by author for his own projects). None of them are necessary, or very interesting; only the single include file is needed to start your own library.

Interface

require:import single function from the library (single file)
include:import group of related functions (entire directory)

Usage

  1. source the include file from your script
  2. place all library functions in subdirs of this file's location
    • use one file per function, (add symlinks for each func name if more)
    • each source file name corresponds to a require (single file sourced)
    • each subdirectory corresponds to an include (all in dir are sourced)
  3. use include and require within libs to declare interdependencies

Example

$ git clone -q https://github.com/smemsh/libsh ~/lib/sh

$ cat << . > test.sh
source ~/lib/sh/include
include time setenv
require field pidenv
setenv now $(fecho time_t_to_timefmt `date +%s`)
echo "$(now) is $now for window $(field = 2 <<< $(pidenv $$ WINDOWID))"
.

$ bash test.sh
20160108120010 is 20160108120010 for window 4194311

Rationale

  • The interface requires sourcing only one stub file (which can be located anywhere), to install the 'include' and 'require' functions in the shell's execution context. This then makes everything else available selectively, by the use of these keywords in a script.
  • Obviates need to impose an initialization order on the sourcing of shell startup files. The order will be self-imposed as dependencies are automatically resolved.
  • Removes the problem of deciding which functions from a library are worth exporting to child environments. Instead we can simply export none of them; all inclusion is upon request only: preconfigured groups of commands can be requested with include and single commands can be requested with require
  • Protects against redundant inclusion. Early termination of include procedures if already defined. This can be implemented wholly: per include; or partially: per function (i.e. requires).
  • Potential for automatic generation and maintenance. The list of functions provided by a source file can be determined from bash itself.
  • Allows standalone executable scripts to participate in the system as well as forked children that have sourced login/profile scripts. Sometimes the use of standalone scripts to provide simple commands is preferable to the use of functions.
  • Code reuse and all the usual good reasons for having libraries.

About

lib: bash source file inclusion system and small function library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 100.0%