Compare commits

...

10 Commits
1.0w ... master

Author SHA1 Message Date
wdlkmpx f3ff2c62eb update gmrun.1
forgot to update this for release 1.1w ...
2021-03-06 15:44:47 +08:00
wdlkmpx f3043727dc gmrun 1.1w 2021-03-06 15:22:44 +08:00
wdlkmpx e8dd889f24 merge data/zrelease into autogen.sh .. 2021-03-06 10:09:32 +08:00
wdlkmpx 802a4bda50 main.c (gtk3.4+): G_APPLICATION_NON_UNIQUE 2021-02-22 15:07:05 +08:00
wdlkmpx e390c1e063 main.c: main() gtk3.4+: hide cmd line args from GApplication
Handling cmd line args with GApplication is a nightmare
https://developer.gnome.org/gtkmm-tutorial/stable/sec-multi-item-containers.html.en#boxes-command-line-options
2021-02-22 15:00:58 +08:00
wdlkmpx 0573d99082 gmrunrc: EXT syntax-> EXT:ext,etc = handler '%s' 2021-02-22 08:21:46 +08:00
wdlkmpx ee2560d57f rename USE_XDG to USE_GLIB_XDG 2021-02-22 08:11:40 +08:00
PRESFIL 8e1c8718ae Fix xterm -e handling with multiword queryes
* `xterm`'s `-e` option is an option with a **variable number of parameters*.
  It does not perform word splitting on its own and takes all argv's words
  after it.  Therefore, the quotation marks in man and info prevent you from
  passing them switches and multiple arguments.

* Some commands (like `xdg`-gues) takes 1 argument and they can contain
  shell-symbols -> must be braced

* Some of them (like man & info) can take multiple arguments and (as it seems
  to me) cannot contain shell-symbloc -> must not be braced to split query to
  multiple words.
2021-02-22 20:47:37 +08:00
wdlkmpx c9e22f006a main.c: ext_check(): escape spaces only if USE_XDG = 1
otherwise unescape spaces

ref #5
2021-02-22 07:36:01 +08:00
wdlkmpx 78cac66790 restore system(3) call as the default option to run commands
Use libc's system(3) to run commands, this includes any shell command
   and special stuff that only a shell interpreter can understand
 Set to 0 if you want a more conservative approach where the file to run
   is validated and errors running files are reported (without closing the gmrun window)

SHELL_RUN = 1

ref #4
2021-02-18 17:51:38 +08:00
8 changed files with 108 additions and 60 deletions

View File

@ -10,6 +10,7 @@ Henning Schild
Makoto Nokata
mishoo
Paweł Błaszczyk
PRESFIL
R. Tyler Croy
Samuel Bauer
sonofkojak

View File

@ -1,3 +1,20 @@
==========
gmrun 1.1w
==========
PRESFIL (1):
Fix xterm -e handling with multiword queryes
wdlkmpx (7):
restore system(3) call as the default option to run commands
main.c: ext_check(): escape spaces only if USE_XDG = 1
rename USE_XDG to USE_GLIB_XDG
gmrunrc: EXT syntax-> EXT:ext,etc = handler '%s'
main.c: main() gtk3.4+: hide cmd line args from GApplication
main.c (gtk3.4+): G_APPLICATION_NON_UNIQUE
merge data/zrelease into autogen.sh ..
==========
gmrun 1.0w
==========

View File

@ -1,6 +1,22 @@
#!/bin/sh
# Run this to generate all the initial makefiles, etc.
if test "$1" == "release" || test "$1" == "--release" ; then
pkg="$(grep -m1 AC_INIT configure.ac | cut -f 2 -d '[' | cut -f 1 -d ']')"
ver="$(grep -m1 AC_INIT configure.ac | cut -f 3 -d '[' | cut -f 1 -d ']')"
ver=$(echo $ver)
dir=${pkg}-${ver}
rm -rf ../$dir
mkdir -p ../$dir
cp -rf $PWD/* ../$dir
( cd ../$dir ; ./autogen.sh )
cd ..
tar -Jcf ${dir}.tar.xz $dir
exit
fi
#===========================================================================
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
cd $srcdir

View File

@ -1,6 +1,6 @@
# Process this file with autoconf to produce a configure script.
AC_INIT([gmrun], [1.0w])
AC_INIT([gmrun], [1.1w])
AM_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE([-Wall foreign])
AC_CONFIG_MACRO_DIR([m4])

View File

@ -1,7 +1,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH gmrun 1 "2020"
.TH gmrun 1.1w "2021"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -54,10 +54,10 @@ Whether to show the last command as initial text, or an empty textarea (1 or 0).
Whether the initial text should be selected or not (1 or 0).
.SH URL/File HANDLING
.TP
.B USE_XDG = 1
.B USE_GLIB_XDG = 1
For automatic URL and File handling using the freedesktop specification.
.TP
See /etc/gmrunrc for custom URL and extension handlers (USE_XDG = 0)
See /etc/gmrunrc for custom URL and extension handlers (USE_GLIB_XDG = 0)
.TP
The included configuration files have a few examples which you can work with. You should also note that the protocol part of URL_protocol can be *anything*. You can set up "URL_foobarbazcustom", and so long as you enter in "foobarbazcustom:<whatever>", it will use the given program.
.SH SEE ALSO

View File

@ -28,26 +28,35 @@ ShowDotFiles = 0
# Set this to NULL if don't like this feature.
TabTimeout = 0
# Use libc's system(3) to run commands, this includes any shell command
# and special stuff that only a shell interpreter can understand
# Set to 0 if you want a more conservative approach where the file to run
# is validated and errors running files are reported (without closing the gmrun window)
SHELL_RUN = 1
# use GLib XDG handling? (freedesktop specification)
USE_XDG = 0
USE_GLIB_XDG = 0
#=======================================================================
# if not using XDG, you can specify URL and extension Handlers...
# USE_GLIB_XDG = 0, you can specify URL and extension Handlers...
#=======================================================================
# URL handlers
# If the entered text is "http://www.google.com" then:
# - %u gets replaced with the whole URL ("http://www.google.com")
# - %s gets replaced with "//www.google.com". This is useful for URL-s
# like "man:printf" --> %s will get replaced with "printf"
URL_http = xdg-open %u
URL_mailto = xdg-email %u
URL_file = xdg-open %s
URL_man = ${TermExec} 'man %s'
URL_info = ${TermExec} 'info %s'
# - %s gets replaced with "//www.google.com".
# useful for URL's like "man:printf" --> %s becomes printf
URL_http = xdg-open '%u'
URL_mailto = xdg-email '%u'
URL_file = xdg-open '%s'
URL_man = ${TermExec} man %s
URL_info = ${TermExec} info %s
URL_search = xdg-open 'http://www.google.com/search?q=%s'
# extension handlers
# Customize your own extension handler.
EXT:doc,rtf,txt,cc,cpp,h,java,html,htm,epl,tex,latex,js,css,xml,xsl,am,ps,pdf = xdg-open %s
# syntax-> EXT:ext,etc = handler '%s'
EXT:doc,rtf,txt,cc,cpp,h,java,html,htm,epl,tex,latex,js,css,xml,xsl,am,ps,pdf = xdg-open '%s'
EXT:mkv,mp4,avi,asf,wmv = xdg-open '%s'
EXT:mp3,flac,ogg,aac,wav = xdg-open '%s'

View File

@ -1,24 +0,0 @@
#!/bin/sh
pkg=gmrun
ver=$(grep AC_INIT configure.ac | cut -f 3 -d '[' | cut -f 1 -d ']')
dir=${pkg}-${ver}
mkdir -p ../$dir
cp -rf $PWD/* ../$dir
(
cd ../$dir
./autogen.sh
rm -rf autom4te.cache
#rm -rf m4
rm -f make-release
)
cd ..
tar -Jcf ${dir}.tar.xz $dir
### END ###

View File

@ -31,6 +31,8 @@
#include "gtkcompletionline.h"
#include "config_prefs.h"
#define CMD_LENGTH 1024
enum
{
W_TEXT_STYLE_NORMAL,
@ -50,7 +52,8 @@ GtkWidget * wlabel;
GtkWidget * wlabel_search;
/* preferences */
int USE_XDG = 0;
int USE_GLIB_XDG = 0;
int SHELL_RUN = 1;
/// BEGIN: TIMEOUT MANAGEMENT
@ -93,12 +96,30 @@ static void set_info_text_color (GtkWidget *w, const char *text, int spec)
}
}
static void
run_the_command (const char * cmd)
static void run_the_command (char * cmd)
{
#if DEBUG
fprintf (stderr, "command: %s\n", cmd);
#endif
if (SHELL_RUN)
{
// need to add extra &
if (strlen (cmd) < (CMD_LENGTH-10)) {
strcat (cmd, " &"); /* safe to use in this case */
}
int ret = system (cmd);
if (ret != -1) {
gmrun_exit ();
} else {
char errmsg[256];
snprintf (errmsg, sizeof(errmsg)-1, "ERROR: %s", strerror (errno));
set_info_text_color (wlabel, errmsg, W_TEXT_STYLE_NOTFOUND);
add_search_off_timeout (3000, NULL);
}
}
else // glib - more conservative approach and robust error reporting
{
GError * error = NULL;
gboolean success;
int argc;
@ -110,7 +131,6 @@ run_the_command (const char * cmd)
add_search_off_timeout (3000, NULL);
return;
}
success = g_spawn_async (NULL, argv, NULL,
G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
if (argv) {
@ -123,12 +143,14 @@ run_the_command (const char * cmd)
g_error_free (error);
add_search_off_timeout (3000, NULL);
}
}
}
static void
on_ext_handler (GtkCompletionLine *cl, const char * filename)
{
if (USE_XDG) // GLib XDG handling (freedesktop specification)
if (USE_GLIB_XDG) // GLib XDG handling (freedesktop specification)
{
gchar * content_type, * mime_type, * msg;
const gchar * handler;
@ -172,9 +194,10 @@ on_ext_handler (GtkCompletionLine *cl, const char * filename)
}
}
static void on_compline_runwithterm (GtkCompletionLine *cl)
{
char cmd[512];
char cmd[CMD_LENGTH];
char * term;
char * entry_text = g_strdup (gtk_entry_get_text (GTK_ENTRY(cl)));
g_strstrip (entry_text);
@ -285,7 +308,7 @@ static void xdg_app_run_command (GAppInfo *app, const gchar *args)
/* Handler for URLs */
static gboolean url_check (GtkCompletionLine *cl, char * entry_text)
{
if (USE_XDG) // GLib XDG handling (freedesktop specification)
if (USE_GLIB_XDG) // GLib XDG handling (freedesktop specification)
{
char * delim;
const char * url, * protocol;
@ -379,8 +402,7 @@ static gboolean url_check (GtkCompletionLine *cl, char * entry_text)
static char * escape_spaces (char * entry_text)
{ // this for EXT handlers: replace " " with "\ "
// it's the only way to make the command run if the filename contains spaces
{ // run file with glib: replace " " with "\ "
GRegex * regex;
char * quoted;
if (!strstr (entry_text, "\\ ")) {
@ -396,7 +418,7 @@ static char * escape_spaces (char * entry_text)
/* Handler for extensions */
static gboolean ext_check (GtkCompletionLine *cl, char * entry_text)
{
if (USE_XDG) // GLib XDG handling (freedesktop specification)
if (USE_GLIB_XDG) // GLib XDG handling (freedesktop specification)
{
char *quoted, *content_type, *mime_type;
GAppInfo *app_info;
@ -432,7 +454,7 @@ static gboolean ext_check (GtkCompletionLine *cl, char * entry_text)
}
else //-------- custom EXTension handlers
{
// example: file.html -> `xdg-open %s` -> `xdg-open file.html`
// example: file.html | xdg-open '%s' -> xdg-open 'file.html'
char * cmd, * quoted;
char * ext = strrchr (entry_text, '.');
char * handler_format = NULL;
@ -440,11 +462,12 @@ static gboolean ext_check (GtkCompletionLine *cl, char * entry_text)
handler_format = config_get_handler_for_extension (ext);
}
if (handler_format) {
quoted = escape_spaces (entry_text);
if (strchr (handler_format, '%')) { // xdg-open %s
quoted = g_strcompress (entry_text); /* unescape chars */
if (strstr (handler_format, "%s")) {
cmd = g_strdup_printf (handler_format, quoted);
} else { // xdg-open
cmd = g_strconcat (handler_format, " ", quoted, NULL);
}
else { // xdg-open
cmd = g_strconcat (handler_format, " '", quoted, "'", NULL);
}
history_append (cl->hist, entry_text);
run_the_command (cmd);
@ -470,7 +493,7 @@ static void on_compline_activated (GtkCompletionLine *cl)
return;
}
char cmd[512];
char cmd[CMD_LENGTH];
char * AlwaysInTerm = NULL;
char ** term_progs = NULL;
char * selected_term_prog = NULL;
@ -510,7 +533,6 @@ static void on_compline_activated (GtkCompletionLine *cl)
static void gmrun_activate(void)
{
GtkWidget *dialog, * main_vbox;
GtkWidget *label_search;
GtkWidget * window = gtk_application_window_new (gmrun_app);
@ -546,6 +568,10 @@ static void gmrun_activate(void)
gtk_widget_set_name (compline, "gmrun_compline");
gtk_box_pack_start (GTK_BOX (main_vbox), compline, TRUE, TRUE, 0);
if (!config_get_int ("SHELL_RUN", &SHELL_RUN)) {
SHELL_RUN = 1;
}
// don't show files starting with "." by default
if (!config_get_int ("ShowDotFiles", &(GTK_COMPLETION_LINE(compline)->show_dot_files))) {
GTK_COMPLETION_LINE(compline)->show_dot_files = 0;
@ -554,8 +580,8 @@ static void gmrun_activate(void)
if (!config_get_int ("TabTimeout", &tmp)) {
((GtkCompletionLine*)compline)->tabtimeout = tmp;
}
if (!config_get_int ("USE_XDG", &USE_XDG)) {
USE_XDG = 0;
if (!config_get_int ("USE_GLIB_XDG", &USE_GLIB_XDG)) {
USE_GLIB_XDG = 0;
}
g_signal_connect(G_OBJECT(compline), "cancel",
@ -731,8 +757,11 @@ int main(int argc, char **argv)
config_init ();
parse_command_line (argc, argv);
#if GTK_CHECK_VERSION(3, 0, 0)
gmrun_app = gtk_application_new ("org.gtk.gmrun", G_APPLICATION_FLAGS_NONE);
#if GTK_CHECK_VERSION(3, 4, 0)
// Handling cmd line args with GApplication is a nightmare
// follow this: https://developer.gnome.org/gtkmm-tutorial/stable/sec-multi-item-containers.html.en#boxes-command-line-options
argc = 1; /* hide args from GApplication */
gmrun_app = gtk_application_new ("org.gtk.gmrun", G_APPLICATION_NON_UNIQUE);
g_signal_connect (gmrun_app, "activate", gmrun_activate, NULL);
status = g_application_run (G_APPLICATION (gmrun_app), argc, argv);
g_object_unref (gmrun_app);