lib/pvl/list.sh
author Tero Marttila <terom@paivola.fi>
Mon, 09 Mar 2015 23:31:13 +0200
changeset 738 3104fdf7ea26
parent 684 fbac5a08c9d3
permissions -rw-r--r--
pvl.hosts.hosts: drop support for instanced ip.* in favor of improved interface:ip.* =
### FS utils

function _list {
    local glob="$1"
    local test="$2"
    local prefix="$3"

    for file in $glob; do
        [ $test "$file" ] || continue
        [ -n "$prefix" ] && file="${file#$prefix}"

        echo -n "$file "
    done
}

## List names of all things in dir
function list {
    _list "$1/*" '-e' ${2:-$1/}
}

## List names of files in dir:
#
#   list_files $dir
#
function list_files {
    _list "$1/*" '-f' ${2:-$1/}
}

## List names of dirs in dir:
function list_dirs {
    _list "$1/*" '-d' ${2:-$1/}
}

## Expand a file or directory path to any files/directorys within that tree
function list_tree {
    _list "$1 $1/**" '-e' ''
}