]> git.phdru.name Git - dotfiles.git/commitdiff
Feat(recode-filenames-recursive): Allow to omit parameters
authorOleg Broytman <phd@phdru.name>
Mon, 19 Feb 2024 20:11:34 +0000 (23:11 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 19 Feb 2024 20:11:34 +0000 (23:11 +0300)
bin/recode-filenames-recursive.py

index b7787e491cea8b6c53d3863dcab94dd0b7c96b56..54085636506bf1f642663a8fc5697541a762935b 100755 (executable)
@@ -1,14 +1,34 @@
 #! /usr/bin/env python3
 
 import sys, os
-from recode_filenames import _recode
 
-if len(sys.argv) == 3:
+from m_lib.defenc import default_encoding
+
+if len(sys.argv) == 1:
+    src_encoding = default_encoding
+    if src_encoding == 'utf-8':
+        sys.exit("Usage: %s [[src_enc] dst_enc [start_dir]]" % sys.argv[0])
+    else:
+        dst_encoding = 'utf-8'
+    start_dir = '.'
+elif len(sys.argv) == 2:
+    src_encoding = default_encoding
+    dst_encoding = sys.argv[1]
     start_dir = '.'
+elif len(sys.argv) == 3:
+    src_encoding = default_encoding
+    dst_encoding = sys.argv[1]
+    start_dir = sys.argv[2]
 elif len(sys.argv) == 4:
+    src_encoding = sys.argv[1]
+    dst_encoding = sys.argv[2]
     start_dir = sys.argv[3]
 else:
-    sys.exit("Usage: %s src_enc dst_enc [start_dir]" % sys.argv[0])
+    sys.exit("Usage: %s [[src_enc] dst_enc [start_dir]]" % sys.argv[0])
+
+# Fake for recode_filenames.py
+sys.argv = ['', src_encoding, dst_encoding]
+from recode_filenames import _recode
 
 
 def _onerror(exc):