functions: add new helpers that create a dir and cd/pushd into it
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jul 24 20:08:13 2011 +0200 (2011-07-24)
changeset 28987e0af0188fc3
parent 2897 8e793413baae
child 2899 0b594b10c63b
functions: add new helpers that create a dir and cd/pushd into it

A lot of places are currently doing:
mkdir -p foo/bar
cd foo/bar

Or even:
mkdir -p foo/bar
pushd foo/bar
[...]
popd

Provide both wrapper to ease doing this.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
scripts/functions
     1.1 --- a/scripts/functions	Sun Jul 24 19:24:02 2011 +0200
     1.2 +++ b/scripts/functions	Sun Jul 24 20:08:13 2011 +0200
     1.3 @@ -323,6 +323,22 @@
     1.4      popd >/dev/null 2>&1
     1.5  }
     1.6  
     1.7 +# Create a dir and cd or pushd into it
     1.8 +# Usage: CT_mkdir_cd <dir/to/create>
     1.9 +#        CT_mkdir_pushd <dir/to/create>
    1.10 +CT_mkdir_cd() {
    1.11 +    local dir="${1}"
    1.12 +
    1.13 +    mkdir -p "${dir}"
    1.14 +    cd "${dir}"
    1.15 +}
    1.16 +CT_mkdir_pushd() {
    1.17 +    local dir="${1}"
    1.18 +
    1.19 +    mkdir -p "${dir}"
    1.20 +    CT_Pushd "${dir}"
    1.21 +}
    1.22 +
    1.23  # Creates a temporary directory
    1.24  # $1: variable to assign to
    1.25  # Usage: CT_MktempDir foo