Skip to content
/ on Public

Execute actions by triggering them with specific events.

License

Notifications You must be signed in to change notification settings

bpm-rocks/on

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BPM Library: On

Trigger actions based on specific events.

Installation

Add to your bpm.ini file the following dependency.

[dependencies]
on=*

Run bpm install to add the library. Finally, use it in your scripts.

#!/usr/bin/env bash
. bpm
bpm::include on

API

on::exit()

Run a command when the currently executing script or subshell ends. This overwrites the EXIT trap, but tries to do this in a polite way. If the trap is already assigned another command, that command is added to the list of commands to run at the end. Subsequent calls to on::exit will keep adding to this array.

  • $1 - The command to execute.
  • $2-@ - Optional arguments to pass to the command.

Examples

 # Download a file
 curl -O http://example.com/installer.tar.gz

 # When done, automatically clean it up.
 on::exit rm -f /tmp/installer.tar.gz

 # This triggers at the end of subshells as well.
 touch file1
 on::exit rm file1
 (
     touch file2
     on::exit rm file2
 )
 ls file1 file2    # Only shows file1

Returns nothing.

on::exitTrap()

Function that runs the on::exit commands. This is set as the EXIT trap in Bash to ensure that it always executes at the end of a script or subshell.

Examples

# Set up the trap. This happens automatically when `on::exit` executes.
# The example shown here is only for how it is to be used within the
# library. Users of the library don't need to run this.
trap on::exitTrap EXIT

Returns nothing.

License

This project is placed under an MIT License.

About

Execute actions by triggering them with specific events.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages