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.
@@ -55,6 +56,7 @@ alias cd..='cd ..' # Common misspelling for going up one directory
alias ...='cd ../..' # Go up two directories
alias ....='cd ../../..' # Go up three directories
alias -- -='cd -' # Go back
alias d='cd /home/$USER/Downloads' # Go to the Downloads directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit too short and already taken by a function for the fasd plugin. please rename to something that won't clobber or move to your private alias file.

@@ -183,3 +183,16 @@ if ! _command_exists del; then
mkdir -p /tmp/.trash && mv "$@" /tmp/.trash
}
fi

# replace multiple file extensions at once
function rex() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a package in Ubuntu and other distros called rex and I would rather not have them clash. Could you consider naming it renex or rext?

# replace multiple file extensions at once
function rex() {
about 'mass replace of the extension of multiple files'
param '1: extension to replace'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation is mixed spaces and tabs, please align all to just tabs. Thanks!

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.

2 participants