The Offirmo Shell Lib (OSL) is a collection of useful shell functions for robust and advanced shell scripts.
Requirements : I use bash.
Available at : https://github.com/Offirmo/offirmo-shell-lib
Note : The OSL has unit tests for maximum quality.
The user story
I found myself having to write a lot of shell scripts, for work and for home.
Over the time, I had to develop a lot of useful functions.
One day, I cleaned them up and packed them in this lib. Enjoy !
The OSL is targeted at bash. Never tested with another shell.
Get a copy of the files and set your path to point to the OSL "bin" dir. You can check if it works by typing :
In your scripts, add this as soon as possible (ideally first instruction in your script for maximum features) :
On demand, source other OSL files as needed :
osl_lib_archive.sh--> decompress any archive file
osl_lib_capabilities.sh--> detect version and check capabilities of host OS
osl_lib_exit.sh--> to abort execution with nice messages
osl_lib_file.sh--> path manipulations, ensure a line is
osl_lib_init.sh--> allow output saving and various nice hacks
osl_lib_mutex.sh--> create and use mutexes (note : use 'rsrc' wrapper for additional features)
osl_lib_output.sh--> various display functions : error, warnings...
osl_lib_rsrc.sh--> safe rsrc manipulation protected by mutex
osl_lib_sspec.sh--> shell unit tests, inspired from rspec
osl_lib_stamp.sh--> manip of stamp files to detect access time and interferences (note : use 'rsrc' wrapper for additional features)
osl_lib_string.sh--> string utilities
osl_lib_ui.sh--> UI functions like asking yes or no, pause...
osl_lib_version.sh--> version comparison utilities (newer/older)
osl_inc_ansi_codes.sh--> defines ANSI codes for color
Special files :
osl_help.sh--> callable, display current OSL version
osl_inc_env.sh--> various constants
Experimental / in progress :
osl_lib_interrupt_func.sh--> exit hook (for mutex auto release)
Env variables : OSL will respond to a few environment variables :
- OSL_console_has_light_scheme=true (default false) will adjust colored output styles to be more readable on a white background
That's it. You can now use the features.
For now, look inside the unit tests of the file you're interested in, or look in the file itself.
- Better doc ;)
- improve decompression function
- refactor mutex code to avoid duplication
- mutex switch from read to write ?
- forward and aggregate state in rsrc fuctions
- Make default values redefinable
- Make it easier to disable color
- remove "bashisms"
- asserts ?