-
Notifications
You must be signed in to change notification settings - Fork 1
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
Create cross-platform rename
alias
#3
Comments
Do we really need to ship a Any how, what about wrapping import os
import re
def _srename(args, stdin=None):
pattern, repl, files, options = _parse_srename_args(args)
if options['invert']:
pattern, repl = repl, pattern
for old_name in files:
if not os.path.exists(old_name):
print(f'Warning: {old_name} does not exist')
continue
new_name = re.sub(pattern, repl, old_name)
if (old_name == new_name):
continue
if os.path.exists(new_name):
print(f'Warning: {new_name} already exists')
continue
if options['dry-run']:
print(f'Info: {old_name} → {new_name} (not renaming as dry run)')
else:
os.rename(old_name, new_name)
def _parse_srename_args(args):
options = {'dry-run': False, 'invert': False}
if '--dry-run' in args:
args.remove('--dry-run')
options['dry-run'] = True
if '--invert' in args:
args.remove('--invert')
options['invert'] = True
pattern, repl, *rest = args
return pattern, repl, rest, options
aliases['srename'] = _srename e.g.
|
Initial xontrib draft, comments welcome. |
This would be great to have in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference xonsh/xonsh#308
Create a
rename
alias that works across platforms. This is currently unavailable on e.g. MacOS.For community
⬇️ Please click the 👍 reaction instead of leaving a
+1
or 👍 commentThe text was updated successfully, but these errors were encountered: