Renaming Typo3 plugins created by the "kickstarter" extension


Unfortunately it is not possible to give meaningful names to the plugins created by the kickstarter extension, so they’re all named pi1, pi2 and so on. Because this can get rather tiresome if you’ve got multiple plugins inside the same extensions, I’ve written a small ruby script to rename them.

Note that it is a very early version of the script and I am going to improve it for sure. It may contain some bugs, so please make sure you’ve got your plugins checked into some kind of version control before you using it. I do not take responsibility for any issues the script may cause, but if you are having problems with it, feel free to leave a comment and I’ll try to fix them.

The source (tested with Ruby 1.9 under Mac OS X 10.7):


#!/usr/bin/env ruby

require 'fileutils'

dryRun = false
removeBackups = true

# Check preconditions

abort("Usage: mv_t3plugin old_dir new_dir") if ARGV.length < 2
abort("You are not in an extension directory.") if not File.exists? "./ext_emconf.php"

oldDir = ARGV[0].gsub("/", "")
newDir = ARGV[1].gsub("/", "")

abort("The plugin to be moved does not exist.") if not Dir.exists? oldDir
abort("The new plugin name seems to be already taken.") if Dir.exists? newDir


# Replace occurences of old plugin name

puts "-> About to move plugin '#{oldDir}' to '#{newDir}'."
puts "Dry run!" if dryRun

sedParams = dryRun ? "" : "-i .sedbak"
%x[find . -type f | xargs sed #{sedParams} 's/#{oldDir}/#{newDir}/g']



abort("sed returned with an error. You may restore broken files from the .sedbak backups") if $? != 0


# Rename old plugin folder and files

FileUtils.mv(oldDir, newDir, {:noop => dryRun, :verbose => true})

renameDir = dryRun ? oldDir : newDir
filesToRename = %x[find #{renameDir} -name "*#{oldDir}*" -type f].split("\n")

filesToRename.each do |file|
  newName = file.gsub(oldDir, newDir)
  FileUtils.mv(file, newName, {:noop => dryRun, :verbose => true})
end


# Remove backup files

abort(".sedbak backup files have not been removed (removeBackups disabled)") if not removeBackups

backups = %x[find . -name "*.sedbak" -type f].split("\n")
FileUtils.rm( backups )