diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-02-21 11:21:35 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-02-21 11:21:35 +0100 |
| commit | a4c56fb432e8fd75df930647427bcb582e989344 (patch) | |
| tree | f2216c45a7b82dece6fc45fd0cd52db25e740e7a | |
| parent | 06fa97bfcf255fd033d3b5bd77d77d68ec8beef6 (diff) | |
| download | kazbek-a4c56fb432e8fd75df930647427bcb582e989344.tar.gz | |
Add a script changing file extensions
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | README.md | 6 | ||||
| -rwxr-xr-x | bin/rename.rb | 29 | ||||
| -rw-r--r-- | config/tea-cleaner.toml.dist | 4 |
4 files changed, 40 insertions, 1 deletions
@@ -1,4 +1,4 @@ /dist-newstyle/ -/config.toml +/config/tea-cleaner.toml /log/ /tmp/ @@ -57,4 +57,10 @@ script should work on Mac OS with preinstalled GNU tools and case-sensitive file system and Linux. The resulting GCC is to be found in `./tmp/rootfs/bin/riscv32-unknown-linux-gnu-*`. +## rename.rb + +Changes the extension of all files matching a pattern in the given directory. +Call the `rename.rb` without arguments to see the usage information and an +example. + ## tea-cleaner diff --git a/bin/rename.rb b/bin/rename.rb new file mode 100755 index 0000000..654f220 --- /dev/null +++ b/bin/rename.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# This Source Code Form is subject to the terms of the Mozilla Public License, +# v. 2.0. If a copy of the MPL was not distributed with this file, You can +# obtain one at https://mozilla.org/MPL/2.0/. -} + +# frozen_string_literal: true + +require 'fileutils' + +if ARGV.length == 3 + Dir.glob("#{ARGV[0]}/**/*.#{ARGV[1]}").each do |original| + new_name = original.sub /\.#{Regexp.escape(ARGV[1])}$/, ARGV[2] + + puts "Renaming #{original} to #{new_name}." + FileUtils.mv original, new_name + end +else + $stderr.puts <<~USAGE + Usage: + #{$0} directory old_extension new_extension + + The directory is searched recursively. + The old and new extensions should not begin with a dot (.). + + Example: #{$0} src ce.vue vue + Changes the extensions of all files matching src/**/*.ce.vue to .vue. + USAGE + exit 1 +end diff --git a/config/tea-cleaner.toml.dist b/config/tea-cleaner.toml.dist new file mode 100644 index 0000000..b09ed3b --- /dev/null +++ b/config/tea-cleaner.toml.dist @@ -0,0 +1,4 @@ +# Gitea access token. The token should have permissions to manage users. +token = "" +# The gitea instance URL beginning wth "https://". +server = "https://" |
