# -*- shell-script -*-

################################################################################

function §registry.add {

    local mode="$bashrun_mode"
    local widfile="$bashrun_cache_home/${mode}-wid"
    local pidfile="$bashrun_cache_home/${mode}-pid"
    
    # remove stale wid and pid files
    [[ -f "$widfile" ]] && /bin/rm "$widfile" 
    [[ -f "$pidfile" ]] && /bin/rm "$pidfile"
    
    # write new wid and pidfile
    printf '%s' "$$" > "$pidfile"
    printf '%s' "$WINDOWID" > "$widfile"
    return 0
}

function §registry.remove {

    local widfile="$bashrun_cache_home/${bashrun_mode:-terminal}-wid"
    local pidfile="$bashrun_cache_home/${bashrun_mode:-terminal}-pid"

    if [[ -f "$pidfile" ]]; then
	/bin/rm "$pidfile"
    fi

    if [[ -f "$widfile" ]]; then
	/bin/rm "$widfile"
    fi

}


