--- drush_views/drush_views.drush.inc	2009-05-04 14:40:10.000000000 +0100
+++ drush_views.drush.inc	2010-05-27 15:44:46.000000000 +0100
@@ -38,6 +38,17 @@
      case 'drush:views delete':
        return t("Usage: drush [options] views delete <views>\n\n"
                  ."Delete the specified views. Use 'ALL' to delete all normal/overridden views.");
+     case 'drush:views copy':
+       return t("Usage: drush [options] views copy <source view> [ <fields> <destination views> ]\n\n"
+                ."<fields> should be a comma separated list of fields to copy. The list of available fields "
+                ."for a given view can be listed by running views copy with only one view name as argument.\n"
+                ."<destination views> is a comma separated list of views\n\n"
+                ."Available options:\n"
+                ."--source-display=DISPLAY\n"
+                ." The source display to copy from. Default is 'default'.\n"
+                ."--destination-display=DISPLAY\n"
+                ." The destination display to copy to. Default is to use the same as the source display.\n"
+                ." This list of available displays for a view can be listed by running views copy with only one view name as argument.\n");
   }
 }
 
@@ -62,6 +73,10 @@
     'callback' => 'drush_views_delete',
     'description' => 'Delete or revert a view.',
   );
+  $items['views copy'] = array(
+    'callback' => 'drush_views_copy',
+    'description' => 'Copy fields from one view to other views.',
+  );
   return $items;
 }
 
@@ -238,3 +253,132 @@
     }
   }
 }
+
+/**
+ * Command callback: views copy.
+ */
+function drush_views_copy($source_name = NULL, $field_list = NULL, $destination_names = NULL) {
+  if (!$source_name) {
+    drush_die(t("Provide at lease a source view."));
+    return;
+  }
+
+  // Set up options
+  $source_display = drush_get_option('source-display');
+  if (!$source_display) {
+    $source_display = 'default';
+  }
+  $destination_display = drush_get_option('destination-display');
+  if (!$destination_display) {
+    $destination_display = $source_display;
+  }
+
+  // Load source view and do basic checks
+  views_include('view');
+  $source_view = views_get_view($source_name);
+  if (!$source_view) {
+    drush_die(t("Cannot find source view @source_name",
+      array('@source_name' => $source_name)));
+    return;
+  }
+  if (!isset($source_view->display[$source_display])) {
+    drush_die(t("No such display @display for view @view_name. Run drush views copy @view_name to get list of available displays.", array(
+      '@view_name' => $source_name,
+      '@display'   => $source_display
+    )));
+    return;
+  }
+
+  $available_fields = array_keys($source_view->display[$source_display]->display_options);
+  
+  // Display list of available displays and fields 
+  if (!$field_list || !$destination_names) {
+    $available_displays = array_keys($source_view->display);
+    drush_print(t("Available displays for view @view_name :\n @display_list\n", array(
+      '@view_name' => $source_name, 
+      '@display_list' => implode(', ', $available_displays),
+    )));
+
+    drush_print(t("Available fields to copy for view @view_name and display @display :\n @fields", array(
+      '@view_name' => $source_name,
+      '@display'  => $source_display,
+      '@fields'    => implode(', ', $available_fields),
+    )));
+    return;
+  }
+
+  // Check the list of fields to copy
+  $fields = explode(',', $field_list);
+  $fields_to_copy = array();
+  $missing_fields = array();
+  foreach ($fields as $field) {
+    $field = trim($field);
+
+    if (!in_array($field, $available_fields)) {
+      $missing_fields[] = $field;
+    } else {
+      $fields_to_copy[] = $field;
+    }
+  }
+
+  if (count($missing_fields)) {
+    drush_print(t("The following fields are not available in the source view and will not be copied :\n @fields", array('@fields' => implode(', ', $missing_fields))));
+    if (!drush_confirm(t("Do you want to continue importing the remaining fields ?"))) {
+      drush_print("Aborting view copy.");
+      return;
+    }
+  }
+  if (empty($fields_to_copy)) {
+    drush_die("No fields to copy. Aborint view copy.");
+    return;
+  }
+
+  // Potentially there could be problems with some plugins - it's hard to tell,
+  // so better warn the user first !
+  if (!drush_confirm(t("This could potentially damage your database. If you have not tried this before with your current set of fields and views plugin, it would be safe to backup your database first. Do you want to go ahead ?"))) {
+    drush_print("Aborint view copy.");
+    return;
+  }
+
+  foreach(explode(",",$destination_names) as $destination_name) {
+    $destination_view = views_get_view(trim($destination_name));
+    if (!$destination_view) {
+      drush_print(t("Could not find destination view @view. Skipping.",
+        array('@view' => $destination_view)));
+      continue;
+    }
+
+    if (!isset($destination_view->display[$destination_display])) {
+      drush_print(t("Could not find display @display for destination view @view. Skipping.", 
+        array('@view' => $destination_view, '@display' => $destination_display)
+      ));
+      continue;
+    }
+
+    $missing_fields = array();
+    foreach ($fields_to_copy as $field) {
+      if (!isset($destination_view->display[$destination_display]->display_options[$field])) {
+        $missing_fields[] = $field;
+      } else {
+        $destination_view->display[$destination_display]->display_options[$field] =
+          $source_view->display[$destination_display]->display_options[$field];
+      }
+    }
+    $destination_view->save();
+    views_object_cache_clear('view', $view->name);
+
+    if (count($missing_fields)) {
+      drush_print(t("The following fields were not present in destination view @view and display @display, and so were not copied :\n @fields",
+        array('@view' => $destination_name,
+              '@display' => $destination_display,
+              '@fields' => implode(', ', $missing_fields))
+      ));
+    }
+    drush_print(t("Destination view @view was saved.", array('@view' => $destination_name)));
+  }
+
+  menu_rebuild();
+  cache_clear_all('*', 'cache_views');
+  cache_clear_all();
+  drush_print("Views copy finished, and cache was cleared.");
+} 
