All pastes #244221 Raw Edit

Untitled

public text v1 · immutable
#244221 ·published 2006-11-09 14:47 UTC
rendered paste body
# mkmv - creates a new directory and moves the file into it, in 1 step
# Usage: mkmv <file> <directory>
mkmv() {
    mkdir "$2"
    mv "$1" "$2"
}

# sanitize - set file/directory owner and permissions to normal values (644/755)
# Usage: sanitize <file>
sanitize() {
    chmod -R u=rwX,go=rX "$@"
    chown -R ${USER}.users "$@"
}

# extract - extract the specified file
# Usage: extract <file>
extract () {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2)   tar xjf $1    ;;
            *.tar.gz)    tar xzf $1    ;;
            *.bz2)       bunzip2 $1    ;;
            *.rar)       rar x $1      ;;
            *.gz)        gunzip $1     ;;
            *.tar)       tar xf $1     ;;
            *.tbz2)      tar xjf $1    ;;
            *.tgz)       tar xzf $1    ;;
            *.zip)       unzip $1      ;;
            *.Z)         uncompress $1 ;;
            *.7z)        7z x $1       ;;
            *)           echo "'$1' cannot be extracted via extract()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

function compress() { tar czf "${1%%/}.tar.gz" "${1%%/}/"; }
function mkmine() { sudo chown -R ${USER} ${1:-.}; }

# run - compile a simple c or cpp file, run the program, afterwards delete it
# Usage: run <file> [params]
run() {
    filename="${1%%.*}"
    extension="${1##*.}"
    file="$1"
    shift
    params="$@"
    command=""

    if [ $extension = "cc" -o $extension = "cpp" -o $extension = "c++" ]; then
        command="g++"
    elif [ $extension = "c" ]; then
        command="gcc"
    else
        echo "Invalid file extension!"
        return 1
    fi

    $command -Wall -o $filename $file
    chmod a+x $filename
    ./$filename $params
    rm -f $filename 2>/dev/null
}