Bash-it / bash-it

A community Bash framework.
MIT License
14.3k stars 2.29k forks source link

Add new feature to base.plugin.bash #2257

Open TheMadTomato opened 4 months ago

TheMadTomato commented 4 months ago

Description

New function labeled rex() servers a single purpose. Replace the file extensions of multiple file at once. File extensions usually does not quite matter in bash, but there is a few cases when one might needs to and this function simplifies the process from multiple commands into one.

The Function

function rex() {
    about 'mass replace of the extension of multiple files'
    param '1: extension to replace'
    param '2: new extenstion'
    example 'rex txt md'
        group 'base'
    local ext2replace="${1:-}"
    local newext="${2:-}"
    local files=(`ls *.$ext2replace`)
    for file in "${files[@]}"; do mv "$file" "${file/%.$ext2replace/.$newext}"; done
}

How Has This Been Tested?

Created multiple test files with different extensions, than proceeded to use rex to only change the specified extension which worked flawlessly

Testing Environment

Screenshots (if appropriate):

Types of changes

Checklist: