Skip to content

Conversation

@TheMadTomato
Copy link
Contributor

@TheMadTomato TheMadTomato commented Jul 3, 2024

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

  • OS : Debian GNU/Linux 12 (bookworm) x86_64
  • VER: 6.1.0-21-amd64
  • Bash Ver: 5.2.12
  • Computer: Lenovo Thinkpad P52s

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

2 New aliases:
d: go to Downloads directory from anywhere
rmrf: force delete any file or directory recursively
Update general.aliases.bash, 2 new aliases
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.
@seefood seefood self-assigned this Nov 7, 2024
@seefood seefood marked this pull request as draft December 28, 2024 19:28
@seefood
Copy link
Contributor

seefood commented Feb 27, 2025

@TheMadTomato hey paul, would you like to try merging with the master and fix the suggested problems please?

@TheMadTomato
Copy link
Contributor Author

Hello, Sorry i missed your comments.
I will tend to all the points you have given me very soon.

@seefood seefood marked this pull request as ready for review March 22, 2025 15:11
@seefood seefood merged commit fd12c4a into Bash-it:master Mar 23, 2025
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants