Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new feature to base.plugin.bash #2257

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TheMadTomato
Copy link

@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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant