Index: src/nautilus-application.c
===================================================================
--- src/nautilus-application.c	(revision 14443)
+++ src/nautilus-application.c	(working copy)
@@ -373,6 +373,25 @@ nautilus_make_uri_list_from_shell_strv (
 	return uri_list;
 }
 
+static Nautilus_URIList *
+nautilus_uri_list_sort_basename (Nautilus_URIList *list)
+{
+	int r, h, i;
+	char *temp;
+	for (i = 0; i < list->_length; i++) {
+		for (h = i+1; h < list->_length; h++) {
+			r = strcmp(get_dirname(list->_buffer[i]), get_dirname(list->_buffer[h]));
+            		if (r > 0) {
+				temp = list->_buffer[i];
+				list->_buffer[i] = list->_buffer[h];
+				list->_buffer[h] = temp;
+			}
+		}
+	}
+	
+	return list;
+}
+
 static void
 menu_provider_items_updated_handler (NautilusMenuProvider *provider, GtkWidget* parent_window, gpointer data)
 {
@@ -539,7 +558,8 @@ nautilus_application_startup (NautilusAp
 			      const char *startup_id,
 			      const char *geometry,
 			      const char *session_to_load,
-			      const char *urls[])
+			      const char *urls[],
+			      const char *as_selection[])
 {
 	CORBA_Environment ev;
 	Nautilus_Shell shell;
@@ -547,12 +567,14 @@ nautilus_application_startup (NautilusAp
 	const char *message, *detailed_message;
 	GtkDialog *dialog;
 	Nautilus_URIList *url_list;
+	Nautilus_URIList *selection_list;
 	const CORBA_char *corba_startup_id;
 	const CORBA_char *corba_geometry;
 	int num_failures;
 
 	num_failures = 0;
-
+	url_list = NULL;
+	selection_list = NULL;
 	/* Check the user's ~/.nautilus directories and post warnings
 	 * if there are problems.
 	 */
@@ -707,8 +729,19 @@ nautilus_application_startup (NautilusAp
 	  	/* Create the other windows. */
 		if (urls != NULL) {
 			url_list = nautilus_make_uri_list_from_shell_strv (urls);
-			Nautilus_Shell_open_windows (shell, url_list, corba_startup_id, corba_geometry, browser_window, &ev);
-			CORBA_free (url_list);
+		}
+		if (as_selection != NULL) {
+			selection_list = nautilus_make_uri_list_from_shell_strv (as_selection);
+			selection_list = nautilus_uri_list_sort_basename (selection_list);
+		}
+		if (urls != NULL || as_selection != NULL) {
+			Nautilus_Shell_open_windows (shell, url_list, selection_list, corba_startup_id, corba_geometry, browser_window, &ev);
+			if (url_list != NULL) {
+				CORBA_free (url_list);
+			}
+			if (selection_list != NULL) {
+				CORBA_free (selection_list);
+			}
 		} else if (!no_default_window) {
 			g_assert (session_to_load == NULL);
 			Nautilus_Shell_open_default_window (shell, corba_startup_id, corba_geometry, browser_window, &ev);
Index: src/nautilus-application.h
===================================================================
--- src/nautilus-application.h	(revision 14443)
+++ src/nautilus-application.h	(working copy)
@@ -76,7 +76,8 @@ void                 nautilus_applicatio
 							     const char          *startup_id,
 							     const char          *default_geometry,
 							     const char          *session_to_load,
-							     const char          *urls[]);
+							     const char          *urls[],
+							     const char          *as_selection[]);
 GList *              nautilus_application_get_window_list           (void);
 GList *              nautilus_application_get_spatial_window_list    (void);
 unsigned int         nautilus_application_get_n_windows            (void);
Index: src/nautilus-shell-interface.idl
===================================================================
--- src/nautilus-shell-interface.idl	(revision 14443)
+++ src/nautilus-shell-interface.idl	(working copy)
@@ -10,7 +10,7 @@ module Nautilus {
 	typedef sequence<URI> URIList;
 
 	interface Shell : ::Bonobo::Unknown {
-		void open_windows (in URIList uris, in string startup_id, in string geometry, in boolean browser_window);
+		void open_windows (in URIList uris, in URIList as_selection, in string startup_id, in string geometry, in boolean browser_window);
 		void open_default_window (in string startup_id, in string geometry, in boolean browser_window);
 		void start_desktop ();
 		void stop_desktop ();
Index: src/nautilus-shell.c
===================================================================
--- src/nautilus-shell.c	(revision 14443)
+++ src/nautilus-shell.c	(working copy)
@@ -57,6 +57,7 @@ struct NautilusShellDetails {
 static void     finalize                         (GObject              *shell);
 static void     corba_open_windows              (PortableServer_Servant  servant,
 						 const Nautilus_URIList *list,
+						 const Nautilus_URIList *as_selection,
 						 const CORBA_char       *startup_id,
 						 const CORBA_char       *geometry,
 						 CORBA_boolean           browser_window,
@@ -77,6 +78,18 @@ static void     corba_quit              
 						 CORBA_Environment      *ev);
 static void     corba_restart                   (PortableServer_Servant  servant,
 						 CORBA_Environment      *ev);
+static void     open_window                     (NautilusShell *shell, 
+						 const char *uri, 
+						 const char *startup_id,
+						 const char *geometry,
+						 gboolean browser_window,
+						 gboolean got_filetype,
+						 GFileType file_type,
+						 GList *as_selection);
+void            get_file_type_cb		(GObject *source_object, 
+						 GAsyncResult *res, 
+						 gpointer user_data);
+char *		get_dirname 			(const char* uri);
 
 BONOBO_CLASS_BOILERPLATE_FULL (NautilusShell, nautilus_shell,
 			       Nautilus_Shell,
@@ -123,12 +136,86 @@ nautilus_shell_new (NautilusApplication 
 	return shell;
 }
 
+char *
+get_dirname (const char* uri) {
+	GFile *f1;
+	GFile *f2;
+	char *ret;
+
+	f1 = g_file_new_for_uri (uri);
+	f2 = g_file_get_parent (f1);
+	ret = g_file_get_uri (f2);
+	g_object_unref (f1);
+	g_object_unref (f2);
+
+	return ret;
+}
+
+
+typedef struct {
+	NautilusShell *shell;
+	char *uri;
+	char *startup_id;
+	char *geometry;
+	gboolean browser_window;
+	GFile *file;
+	GList *as_selection;
+} get_type_data;
+
+void
+get_file_type_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) {
+	get_type_data *data;
+	GFileInfo *info;
+	GFileType ftype;
+	data = (get_type_data *) user_data;
+	info = g_file_query_info_finish (data->file, res, NULL);
+	ftype = (GFileType) g_file_info_get_attribute_uint32 (info, "standard::type");
+	open_window (data->shell, 
+		data->uri, 
+		data->startup_id, 
+		data->geometry, 
+		data->browser_window, 
+		TRUE,
+		ftype,
+		data->as_selection);
+	g_object_unref (data->file);
+	g_free (data->uri);
+	g_free (data->startup_id);
+	g_free (data->geometry);
+	g_list_foreach (data->as_selection, (GFunc) g_object_unref, NULL);
+	g_list_free (data->as_selection);
+}
+
 static void
-open_window (NautilusShell *shell, const char *uri, const char *startup_id,
-	     const char *geometry, gboolean browser_window)
+open_window (NautilusShell *shell, const char *uri, const char *startup_id, const char *geometry,
+	     gboolean browser_window, gboolean got_filetype, GFileType file_type, GList *as_selection)
 {
 	GFile *location;
+	GFile *location_dir;
+	GList *selection;
 	NautilusWindow *window;
+	get_type_data *cb_data;
+
+	location = NULL;
+	selection = NULL;
+
+	if (uri != NULL) {
+		location = g_file_new_for_uri (uri);
+			if (!got_filetype) {
+				cb_data = g_new0 (get_type_data, 1);
+				cb_data->shell = shell;
+				cb_data->uri = g_strdup (uri);
+				cb_data->startup_id = g_strdup (startup_id);
+				cb_data->geometry = (geometry) ? g_strdup (geometry) : NULL;
+				cb_data->browser_window = browser_window;
+				cb_data->file = location;
+				cb_data->as_selection = as_selection;
+				g_file_query_info_async (location, "standard::type", 
+							 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, 
+							 G_PRIORITY_DEFAULT, NULL, get_file_type_cb, cb_data);
+				return;
+			}
+	}
 
 	if (browser_window ||
 	    eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER)) {
@@ -138,23 +225,61 @@ open_window (NautilusShell *shell, const
 		if (uri == NULL) {
 			nautilus_window_go_home (window);
 		} else {
-			location = g_file_new_for_uri (uri);
-			nautilus_window_go_to (window, location);
-			g_object_unref (location);
+
+			if (file_type != G_FILE_TYPE_DIRECTORY && file_type != G_FILE_TYPE_UNKNOWN) {
+				location_dir = g_file_get_parent (location);
+				selection = g_list_prepend (selection, location);
+				nautilus_window_go_to_with_selection (window, location_dir, selection);
+				g_object_unref (location);
+				g_object_unref (location_dir);
+				g_list_free (selection);
+			} else {
+				if (as_selection != NULL) {
+					nautilus_window_go_to_with_selection (window, location, as_selection);
+				} else {
+					nautilus_window_go_to (window, location);	
+				}
+				g_object_unref (location);
+			}
 		}
 	} else {
+
 		if (uri == NULL) {
+			g_object_unref (location);
 			location = g_file_new_for_path (g_get_home_dir ());
+		}
+
+		if (file_type != G_FILE_TYPE_DIRECTORY && file_type != G_FILE_TYPE_UNKNOWN) {
+			location_dir = g_file_get_parent (location);
+			selection = g_list_prepend (selection, location);			
+			window = nautilus_application_present_spatial_window_with_selection (shell->details->application,
+										             NULL,
+										             startup_id,
+										             location_dir,
+										             selection,
+										             gdk_screen_get_default ());
+			g_object_unref (location_dir);
 		} else {
-			location = g_file_new_for_uri (uri);
+
+			if (as_selection != NULL) {
+				window = nautilus_application_present_spatial_window_with_selection (shell->details->application,
+										             NULL,
+										             startup_id,
+										             location,
+										             as_selection,
+										             gdk_screen_get_default ());
+			} else {
+				window = nautilus_application_present_spatial_window (shell->details->application,
+										      NULL,
+										      startup_id,
+										      location,
+										      gdk_screen_get_default ());
+			}
 		}
-		
-		window = nautilus_application_present_spatial_window (shell->details->application,
-								      NULL,
-								      startup_id,
-								      location,
-								      gdk_screen_get_default ());
 		g_object_unref (location);
+		if (selection) {
+			g_list_free (selection);
+		}
 	}
 	
 	if (geometry != NULL && !GTK_WIDGET_VISIBLE (window)) {
@@ -175,6 +300,7 @@ typedef struct {
 	char *startup_id;
 	char *geometry;
 	GList *uris;
+	GList *as_selection;
 	gboolean browser_window;
 } OpenWindowData;
 
@@ -183,22 +309,51 @@ open_windows_at_idle (gpointer _data)
 {
 	OpenWindowData *data = _data;
 	char *uri;
+	char *dir;
 	GList *l;
+	GList *selection;
+
+	selection = NULL;
 
-	if (data->uris == NULL) {
+	if (data->uris == NULL && data->as_selection == NULL) {
 		/* Open a window pointing at the default location. */
 		open_window (data->shell, NULL, data->startup_id,
-			     data->geometry, data->browser_window);
+			     data->geometry, data->browser_window, FALSE, 0, NULL);
 	} else {
-		/* Open windows at each requested location. */
-		for (l = data->uris; l != NULL; l = l->next) {
-			uri = (char *)l->data;
-			open_window (data->shell, uri, data->startup_id,
-				     data->geometry, data->browser_window);
+		if (data->uris != NULL) {
+			/* Open windows at each requested location. */
+			for (l = data->uris; l != NULL; l = l->next) {
+				uri = (char *)l->data;
+				open_window (data->shell, uri, data->startup_id,
+					     data->geometry, data->browser_window, FALSE, 0, NULL);
+				g_free (uri);
+			}
+		}
+		if (data->as_selection != NULL) {
+			uri = (char *) data->as_selection->data;
+			dir = get_dirname (uri);
+			selection = g_list_prepend (selection, g_file_new_for_uri (uri));
 			g_free (uri);
+			/* Open windows by directory and select items inside. */
+			for (l = data->as_selection->next; l != NULL; l = l->next) {
+				uri = (char *)l->data;
+				if (strcmp (dir, get_dirname (uri)) != 0) {
+					open_window (data->shell, dir, data->startup_id,
+						     data->geometry, data->browser_window, FALSE, 0, selection);
+					dir = get_dirname (uri);
+					selection = NULL;
+					selection = g_list_prepend (selection, g_file_new_for_uri (uri));
+				} else {
+					selection = g_list_prepend (selection, g_file_new_for_uri (uri));
+				}
+				g_free (uri);
+			}
+			open_window (data->shell, dir, data->startup_id,
+						     data->geometry, data->browser_window, FALSE, 0, selection);
 		}
 	}
 
+	g_list_free (data->as_selection);
 	g_free (data->startup_id);
 	g_free (data->geometry);
 	g_list_free (data->uris);
@@ -209,6 +364,7 @@ open_windows_at_idle (gpointer _data)
 static void
 corba_open_windows (PortableServer_Servant servant,
 		    const Nautilus_URIList *list,
+		    const Nautilus_URIList *as_selection,
 		    const CORBA_char *startup_id,
 		    const CORBA_char *geometry,
 		    CORBA_boolean browser_window,
@@ -224,13 +380,22 @@ corba_open_windows (PortableServer_Serva
 	data->geometry = strcmp (geometry, "") ? g_strdup (geometry) : NULL;
 	data->browser_window = browser_window;
 
-	for (i = 0; i < list->_length; i++) {
-		g_assert (list->_buffer[i] != NULL);
-		data->uris = g_list_prepend (data->uris,
+	if (list != NULL) {
+		for (i = 0; i < list->_length; i++) {
+			g_assert (list->_buffer[i] != NULL);
+			data->uris = g_list_prepend (data->uris,
 					     g_strdup (list->_buffer[i]));
+		}
+		data->uris = g_list_reverse (data->uris);
+	}
+	if (as_selection != NULL) {
+		for (i = 0; i < as_selection->_length; i++) {
+			g_assert (as_selection->_buffer[i] != NULL);
+			data->as_selection = g_list_prepend (data->as_selection,
+						     g_strdup (as_selection->_buffer[i]));
+		}
+		data->as_selection = g_list_reverse (data->as_selection);
 	}
-	data->uris = g_list_reverse (data->uris);
-
 	g_idle_add (open_windows_at_idle, data);
 	
 }
Index: src/nautilus-shell.h
===================================================================
--- src/nautilus-shell.h	(revision 14443)
+++ src/nautilus-shell.h	(working copy)
@@ -51,5 +51,6 @@ typedef struct {
 
 GType          nautilus_shell_get_type (void);
 NautilusShell *nautilus_shell_new      (NautilusApplication *application);
+char          *get_dirname             (const char* uri);
 
 #endif /* NAUTILUS_SHELL_H */
Index: src/nautilus-main.c
===================================================================
--- src/nautilus-main.c	(revision 14443)
+++ src/nautilus-main.c	(working copy)
@@ -376,6 +376,7 @@ main (int argc, char *argv[])
 	char *session_to_load;
 	gchar *geometry;
 	const gchar **remaining;
+	const gchar **as_selection;
 	gboolean perform_self_check;
 	GOptionContext *context;
 	NautilusApplication *application;
@@ -399,6 +400,8 @@ main (int argc, char *argv[])
 		  N_("Quit Nautilus."), NULL },
 		{ "restart", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &restart_shell,
 		  N_("Restart Nautilus."), NULL },
+		{ "show-as-selection", 's', 0, G_OPTION_ARG_FILENAME_ARRAY, &as_selection,
+		  N_("Reveal and select the specified files."), NULL },
 		{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL,  N_("[URI...]") },
 		{ "load-session", 'l', 0, G_OPTION_ARG_STRING, &session_to_load,
 		  /* Translators: --no-default-window is a nautilus command line parameter, don't modify it. */
@@ -443,6 +446,7 @@ main (int argc, char *argv[])
 
 	/* Get parameters. */
 	remaining = NULL;
+	as_selection = NULL;
 	geometry = NULL;
 	session_to_load = NULL;
 	kill_shell = FALSE;
@@ -504,7 +508,7 @@ main (int argc, char *argv[])
 						    gdk_display_get_name (gdk_display_get_default()));
 	
 
-	if (perform_self_check && remaining != NULL) {
+	if (perform_self_check && (remaining != NULL || as_selection != NULL)) {
 		/* translators: %s is an option (e.g. --check) */
 		fprintf (stderr, _("nautilus: %s cannot be used with URIs.\n"),
 			"--check");
@@ -514,12 +518,12 @@ main (int argc, char *argv[])
 		fprintf (stderr, _("nautilus: --check cannot be used with other options.\n"));
 		return EXIT_FAILURE;
 	}
-	if (kill_shell && remaining != NULL) {
+	if (kill_shell && (remaining != NULL || as_selection != NULL)) {
 		fprintf (stderr, _("nautilus: %s cannot be used with URIs.\n"),
 			"--quit");
 		return EXIT_FAILURE;
 	}
-	if (restart_shell && remaining != NULL) {
+	if (restart_shell && (remaining != NULL || as_selection != NULL)) {
 		fprintf (stderr, _("nautilus: %s cannot be used with URIs.\n"),
 			"--restart");
 		return EXIT_FAILURE;
@@ -571,7 +575,8 @@ main (int argc, char *argv[])
 			 startup_id_copy,
 			 geometry,
 			 session_to_load,
-			 remaining);
+			 remaining,
+			 as_selection);
 		g_free (startup_id_copy);
 
 		/* The application startup does things in an idle, so
