Commit 44761794 authored by Paolo Borelli's avatar Paolo Borelli

Handle stdin

Note that we now require "-" to be specified on the command line.
parent 7cf53f7a
......@@ -3,8 +3,13 @@
\fBgedit\fP \- text editor for the GNOME Desktop
.SH SYNOPSIS
.br
.B gedit
[\fIOPTION\fR...] [\fIFILE\fR...] [+\fILINE\fR[:\fICOLUMN\fR]]
.br
.B gedit
[\fIOPTION\fR...] -
.SH DESCRIPTION
.B gedit
is the official text editor of the GNOME desktop environment.
......@@ -75,6 +80,9 @@ of a webpage to
, like "http://www.gnome.org", or load a file from a FTP server,
like "ftp://ftp.gnome.org/robots.txt".
.TP
\fB-\fR
.B gedit will read from stdin
.TP
\fB+LINE\fR
For the first file, go to the line specified by LINE (do not insert a space between the "+" sign and the number).
If LINE is missing, go to the last line.
......
......@@ -114,6 +114,7 @@ static gboolean background = FALSE;
static gboolean standalone = FALSE;
static gchar **remaining_args = NULL;
static const GeditEncoding *encoding = NULL;
static GInputStream *stdin_stream = NULL;
static GSList *file_list = NULL;
static gint line_position = 0;
static gint column_position = 0;
......@@ -485,6 +486,19 @@ gedit_app_activate (GApplication *application)
geometry);
}
if (stdin_stream)
{
gedit_debug_message (DEBUG_APP, "Load stdin");
doc_created = gedit_window_create_tab_from_stream (window,
stdin_stream,
encoding,
line_position,
column_position,
TRUE) != NULL;
g_input_stream_close (stdin_stream, NULL, NULL);
}
if (file_list != NULL)
{
GSList *loaded;
......@@ -496,7 +510,7 @@ gedit_app_activate (GApplication *application)
line_position,
column_position);
doc_created = loaded != NULL;
doc_created = doc_created || loaded != NULL;
g_slist_free (loaded);
}
......@@ -556,6 +570,7 @@ clear_options (void)
g_free (encoding_charset);
g_strfreev (remaining_args);
g_free (geometry);
g_clear_object (&stdin_stream);
g_slist_free_full (file_list, g_object_unref);
help = FALSE;
......@@ -665,6 +680,10 @@ gedit_app_command_line (GApplication *application,
&column_position);
}
}
else if (*remaining_args[i] == '-' && *(remaining_args[i] + 1) == '\0')
{
stdin_stream = g_application_command_line_get_stdin (command_line);
}
else
{
GFile *file;
......
......@@ -1540,24 +1540,6 @@ gedit_utils_decode_uri (const gchar *uri,
return TRUE;
}
gboolean
gedit_utils_can_read_from_stdin (void)
{
#ifdef G_OS_UNIX
if (!isatty (STDIN_FILENO))
{
struct stat sbuffer;
if (fstat (STDIN_FILENO, &sbuffer) == 0 &&
(S_ISREG (sbuffer.st_mode) || S_ISFIFO (sbuffer.st_mode) || S_ISLNK (sbuffer.st_mode)))
{
return TRUE;
}
}
#endif
return FALSE;
}
GeditDocumentCompressionType
gedit_utils_get_compression_type_from_content_type (const gchar *content_type)
{
......
......@@ -148,8 +148,6 @@ gboolean gedit_utils_decode_uri (const gchar *uri,
/* Turns data from a drop into a list of well formatted uris */
gchar **gedit_utils_drop_get_uris (GtkSelectionData *selection_data);
gboolean gedit_utils_can_read_from_stdin (void);
GeditDocumentCompressionType
gedit_utils_get_compression_type_from_content_type
(const gchar *content_type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment