mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Add support custom command.
This commit is contained in:
parent
7ee64b258d
commit
a28b6df307
10 changed files with 118 additions and 58 deletions
|
@ -63,6 +63,8 @@ Settings config = {
|
||||||
.ssh_command = "{terminal} -e {ssh-client} {host}",
|
.ssh_command = "{terminal} -e {ssh-client} {host}",
|
||||||
/** Command when running */
|
/** Command when running */
|
||||||
.run_command = "{cmd}",
|
.run_command = "{cmd}",
|
||||||
|
/** Command used to list executable commands. empty -> internal */
|
||||||
|
.run_list_command = "",
|
||||||
/** Command executed when running application in terminal */
|
/** Command executed when running application in terminal */
|
||||||
.run_shell_command = "{terminal} -e {cmd}",
|
.run_shell_command = "{terminal} -e {cmd}",
|
||||||
/** Key binding */
|
/** Key binding */
|
||||||
|
|
|
@ -6,13 +6,14 @@ rofi - A window switcher, run dialog and dmenu replacement
|
||||||
|
|
||||||
## SYNOPSIS
|
## SYNOPSIS
|
||||||
|
|
||||||
**rofi** [ -width *pct_scr* ] [ -lines *lines* ] [ -columns *columns* ] [ -font *pangofont* ] [ -fg *color* ]
|
**rofi** [ -width *pct_scr* ] [ -lines *lines* ] [ -columns *columns* ] [ -font *pangofont* ] [ -fg
|
||||||
[ -bg *color* ] [ -hlfg *color* ] [ -hlbg *color* ] [ -key *combo* ] [ -dkey *comdo* ] [ -rkey *comdo* ]
|
*color* ] [ -bg *color* ] [ -hlfg *color* ] [ -hlbg *color* ] [ -key *combo* ] [ -dkey *comdo* ] [
|
||||||
[ -terminal *terminal* ] [ -location *position* ] [ -hmode ] [ -fixed-num-lines ] [ -padding *padding* ]
|
-rkey *comdo* ] [ -terminal *terminal* ] [ -location *position* ] [ -hmode ] [ -fixed-num-lines ] [
|
||||||
[ -opacity *opacity%* ] [ -display *display* ] [ -bc *color* ] [ -bw *width* ] [ -dmenu [ -p *prompt* ] ]
|
-padding *padding* ] [ -opacity *opacity%* ] [ -display *display* ] [ -bc *color* ] [ -bw *width* ]
|
||||||
[ -ssh-client *client* ] [ -ssh-command *command* ] [ -now ] [ -rnow ] [ -snow ] [ -version ]
|
[ -dmenu [ -p *prompt* ] ] [ -ssh-client *client* ] [ -ssh-command *command* ] [ -now ] [ -rnow ] [
|
||||||
[ -help] [ -dump-xresources ] [ -disable-history ] [ -levenshtein-sort ] [ -show *mode* ] [ -switcher
|
-snow ] [ -version ] [ -help] [ -dump-xresources ] [ -disable-history ] [ -levenshtein-sort ] [
|
||||||
*mode1,mode2* ] [ -e *message*] [ -sep *separator* ] [ -eh *element height* ] [ -l *selected line* ]
|
-show *mode* ] [ -switcher *mode1,mode2* ] [ -e *message*] [ -sep *separator* ] [ -eh *element
|
||||||
|
height* ] [ -l *selected line* ] [ -run-list-command *cmd* ]
|
||||||
|
|
||||||
## DESCRIPTION
|
## DESCRIPTION
|
||||||
|
|
||||||
|
@ -281,6 +282,10 @@ The default key combinations are:
|
||||||
Set the command to execute when running an application in a shell.
|
Set the command to execute when running an application in a shell.
|
||||||
See *PATTERN*.
|
See *PATTERN*.
|
||||||
|
|
||||||
|
`-run-list-command` *cmd*
|
||||||
|
|
||||||
|
If set, use an external tool to generate list of executable commands. Uses 'run-command'
|
||||||
|
|
||||||
### History and Sorting
|
### History and Sorting
|
||||||
|
|
||||||
`-disable-history`
|
`-disable-history`
|
||||||
|
|
31
doc/rofi.1
31
doc/rofi.1
|
@ -4,13 +4,14 @@
|
||||||
rofi \- A window switcher, run dialog and dmenu replacement
|
rofi \- A window switcher, run dialog and dmenu replacement
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.PP
|
.PP
|
||||||
\fBrofi\fP [ \-width \fIpct_scr\fP ] [ \-lines \fIlines\fP ] [ \-columns \fIcolumns\fP ] [ \-font \fIpangofont\fP ] [ \-fg \fIcolor\fP ]
|
\fBrofi\fP [ \-width \fIpct_scr\fP ] [ \-lines \fIlines\fP ] [ \-columns \fIcolumns\fP ] [ \-font \fIpangofont\fP ] [ \-fg
|
||||||
[ \-bg \fIcolor\fP ] [ \-hlfg \fIcolor\fP ] [ \-hlbg \fIcolor\fP ] [ \-key \fIcombo\fP ] [ \-dkey \fIcomdo\fP ] [ \-rkey \fIcomdo\fP ]
|
\fIcolor\fP ] [ \-bg \fIcolor\fP ] [ \-hlfg \fIcolor\fP ] [ \-hlbg \fIcolor\fP ] [ \-key \fIcombo\fP ] [ \-dkey \fIcomdo\fP ] [
|
||||||
[ \-terminal \fIterminal\fP ] [ \-location \fIposition\fP ] [ \-hmode ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fP ]
|
\-rkey \fIcomdo\fP ] [ \-terminal \fIterminal\fP ] [ \-location \fIposition\fP ] [ \-hmode ] [ \-fixed\-num\-lines ] [
|
||||||
[ \-opacity \fIopacity%\fP ] [ \-display \fIdisplay\fP ] [ \-bc \fIcolor\fP ] [ \-bw \fIwidth\fP ] [ \-dmenu [ \-p \fIprompt\fP ] ]
|
\-padding \fIpadding\fP ] [ \-opacity \fIopacity%\fP ] [ \-display \fIdisplay\fP ] [ \-bc \fIcolor\fP ] [ \-bw \fIwidth\fP ]
|
||||||
[ \-ssh\-client \fIclient\fP ] [ \-ssh\-command \fIcommand\fP ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ]
|
[ \-dmenu [ \-p \fIprompt\fP ] ] [ \-ssh\-client \fIclient\fP ] [ \-ssh\-command \fIcommand\fP ] [ \-now ] [ \-rnow ] [
|
||||||
[ \-help] [ \-dump\-xresources ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-show \fImode\fP ] [ \-switcher
|
\-snow ] [ \-version ] [ \-help] [ \-dump\-xresources ] [ \-disable\-history ] [ \-levenshtein\-sort ] [
|
||||||
\fImode1,mode2\fP ] [ \-e \fImessage\fP] [ \-sep \fIseparator\fP ] [ \-eh \fIelement height\fP ] [ \-l \fIselected line\fP ]
|
\-show \fImode\fP ] [ \-switcher \fImode1,mode2\fP ] [ \-e \fImessage\fP] [ \-sep \fIseparator\fP ] [ \-eh \fIelement
|
||||||
|
height\fP ] [ \-l \fIselected line\fP ] [ \-run\-list\-command \fIcmd\fP ]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.PP
|
.PP
|
||||||
\fBrofi\fP is an X11 popup window switcher. A list is displayed center\-screen showing open window titles, WM_CLASS, and desktop number.
|
\fBrofi\fP is an X11 popup window switcher. A list is displayed center\-screen showing open window titles, WM_CLASS, and desktop number.
|
||||||
|
@ -354,6 +355,10 @@ See \fIPATTERN\fP\&.
|
||||||
.IP
|
.IP
|
||||||
Set the command to execute when running an application in a shell.
|
Set the command to execute when running an application in a shell.
|
||||||
See \fIPATTERN\fP\&.
|
See \fIPATTERN\fP\&.
|
||||||
|
.PP
|
||||||
|
\fB\fC\-run\-list\-command\fR \fIcmd\fP
|
||||||
|
.IP
|
||||||
|
If set, use an external tool to generate list of executable commands. Uses 'run\-command'
|
||||||
.SS History and Sorting
|
.SS History and Sorting
|
||||||
.PP
|
.PP
|
||||||
\fB\fC\-disable\-history\fR
|
\fB\fC\-disable\-history\fR
|
||||||
|
@ -516,18 +521,14 @@ Check quotes used on the commandline: e.g. used “ instead of ".
|
||||||
.SH WEBSITE
|
.SH WEBSITE
|
||||||
.PP
|
.PP
|
||||||
\fBrofi\fP website can be found at here
|
\fBrofi\fP website can be found at here
|
||||||
.UR https://davedavenport.github.io/rofi/
|
\[la]https://davedavenport.github.io/rofi/\[ra]
|
||||||
.UE
|
|
||||||
.PP
|
.PP
|
||||||
\fBrofi\fP bugtracker can be found here
|
\fBrofi\fP bugtracker can be found here
|
||||||
.UR https://github.com/DaveDavenport/rofi/issues
|
\[la]https://github.com/DaveDavenport/rofi/issues\[ra]
|
||||||
.UE
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
.PP
|
.PP
|
||||||
Qball Cow
|
Qball Cow
|
||||||
.MT qball@gmpclient.org
|
\[la]qball@gmpclient.org\[ra]
|
||||||
.ME
|
|
||||||
.PP
|
.PP
|
||||||
Original code based on work by: Sean Pringle
|
Original code based on work by: Sean Pringle
|
||||||
.MT sean.pringle@gmail.com
|
\[la]sean.pringle@gmail.com\[ra]
|
||||||
.ME
|
|
||||||
|
|
|
@ -103,4 +103,13 @@ int token_match ( char **tokens, const char *input,
|
||||||
__attribute__( ( unused ) ) int index,
|
__attribute__( ( unused ) ) int index,
|
||||||
__attribute__( ( unused ) ) void *data );
|
__attribute__( ( unused ) ) void *data );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param cmd The command to execute.
|
||||||
|
*
|
||||||
|
* Execute cmd using config.run_command and outputs the result (stdout) to the opened file
|
||||||
|
* descriptor.
|
||||||
|
*
|
||||||
|
* @returns a valid file descriptor on success, or -1 on failure.
|
||||||
|
*/
|
||||||
|
int execute_generator ( char * cmd ) __attribute__( ( nonnull ) );
|
||||||
#endif // __HELPER_H__
|
#endif // __HELPER_H__
|
||||||
|
|
|
@ -169,6 +169,8 @@ typedef struct _Settings
|
||||||
char * run_command;
|
char * run_command;
|
||||||
/** Command for executing an application in a terminal */
|
/** Command for executing an application in a terminal */
|
||||||
char * run_shell_command;
|
char * run_shell_command;
|
||||||
|
/** Command for listing executables */
|
||||||
|
char * run_list_command;
|
||||||
|
|
||||||
/** Key to open window switcher */
|
/** Key to open window switcher */
|
||||||
char * window_key;
|
char * window_key;
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <rofi.h>
|
|
||||||
#include <helper.h>
|
#include <helper.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
#include <rofi.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `fgets` implementation with custom separator.
|
* `fgets` implementation with custom separator.
|
||||||
|
@ -276,3 +276,38 @@ int token_match ( char **tokens, const char *input,
|
||||||
g_free ( compk );
|
g_free ( compk );
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int execute_generator ( char * cmd )
|
||||||
|
{
|
||||||
|
char **args = NULL;
|
||||||
|
int argv = 0;
|
||||||
|
helper_parse_setup ( config.run_command, &args, &argv, "{cmd}", cmd, NULL );
|
||||||
|
|
||||||
|
int fd = -1;
|
||||||
|
GError *error = NULL;
|
||||||
|
g_spawn_async_with_pipes ( NULL,
|
||||||
|
args,
|
||||||
|
NULL,
|
||||||
|
G_SPAWN_SEARCH_PATH,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL, &fd, NULL,
|
||||||
|
&error );
|
||||||
|
|
||||||
|
if ( error != NULL ) {
|
||||||
|
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd,
|
||||||
|
error->message );
|
||||||
|
#ifdef error_dialog
|
||||||
|
error_dialog ( msg );
|
||||||
|
#else
|
||||||
|
fputs ( msg, stderr );
|
||||||
|
#endif
|
||||||
|
g_free ( msg );
|
||||||
|
// print error.
|
||||||
|
g_error_free ( error );
|
||||||
|
fd = -1;
|
||||||
|
}
|
||||||
|
g_strfreev ( args );
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
|
@ -2188,6 +2188,7 @@ static void parse_cmd_options ( int argc, char ** argv )
|
||||||
find_arg_str ( argc, argv, "-ssh-client", &( config.ssh_client ) );
|
find_arg_str ( argc, argv, "-ssh-client", &( config.ssh_client ) );
|
||||||
find_arg_str ( argc, argv, "-ssh-command", &( config.ssh_command ) );
|
find_arg_str ( argc, argv, "-ssh-command", &( config.ssh_command ) );
|
||||||
find_arg_str ( argc, argv, "-run-command", &( config.run_command ) );
|
find_arg_str ( argc, argv, "-run-command", &( config.run_command ) );
|
||||||
|
find_arg_str ( argc, argv, "-run-list-command", &( config.run_list_command ) );
|
||||||
find_arg_str ( argc, argv, "-run-shell-command", &( config.run_shell_command ) );
|
find_arg_str ( argc, argv, "-run-shell-command", &( config.run_shell_command ) );
|
||||||
|
|
||||||
// Keybindings
|
// Keybindings
|
||||||
|
@ -2425,17 +2426,14 @@ int main ( int argc, char *argv[] )
|
||||||
|
|
||||||
// determine numlock mask so we can bind on keys with and without it
|
// determine numlock mask so we can bind on keys with and without it
|
||||||
XModifierKeymap *modmap = XGetModifierMapping ( display );
|
XModifierKeymap *modmap = XGetModifierMapping ( display );
|
||||||
|
KeyCode kc = XKeysymToKeycode ( display, XK_Num_Lock );
|
||||||
for ( int i = 0; i < 8; i++ ) {
|
for ( int i = 0; i < 8; i++ ) {
|
||||||
for ( int j = 0; j < ( int ) modmap->max_keypermod; j++ ) {
|
for ( int j = 0; j < ( int ) modmap->max_keypermod; j++ ) {
|
||||||
if ( modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode ( display, XK_Num_Lock ) ) {
|
if ( modmap->modifiermap[i * modmap->max_keypermod + j] == kc ) {
|
||||||
NumlockMask = ( 1 << i );
|
NumlockMask = ( 1 << i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
XFreeModifiermap ( modmap );
|
XFreeModifiermap ( modmap );
|
||||||
|
|
||||||
cache_client = winlist_new ();
|
cache_client = winlist_new ();
|
||||||
|
|
|
@ -124,6 +124,38 @@ static int sort_func ( const void *a, const void *b )
|
||||||
}
|
}
|
||||||
return strcasecmp ( astr, bstr );
|
return strcasecmp ( astr, bstr );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* External spider to get list of executables.
|
||||||
|
*/
|
||||||
|
static char ** get_apps_external ( char **retv, unsigned int *length )
|
||||||
|
{
|
||||||
|
int fd = execute_generator ( config.run_list_command );
|
||||||
|
if ( fd >= 0 ) {
|
||||||
|
FILE *inp = fdopen ( fd, "r" );
|
||||||
|
if ( inp ) {
|
||||||
|
char buffer[1024];
|
||||||
|
while ( fgets ( buffer, 1024, inp ) != NULL ) {
|
||||||
|
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) );
|
||||||
|
retv[( *length )] = g_strdup ( buffer );
|
||||||
|
retv[( *length ) + 1] = NULL;
|
||||||
|
|
||||||
|
// Filter out line-end.
|
||||||
|
if ( retv[( *length )][strlen ( buffer ) - 1] == '\n' ) {
|
||||||
|
retv[( *length )][strlen ( buffer ) - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
( *length )++;
|
||||||
|
}
|
||||||
|
fclose ( inp );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal spider used to get list of executables.
|
||||||
|
*/
|
||||||
static char ** get_apps ( unsigned int *length )
|
static char ** get_apps ( unsigned int *length )
|
||||||
{
|
{
|
||||||
unsigned int num_favorites = 0;
|
unsigned int num_favorites = 0;
|
||||||
|
@ -247,7 +279,11 @@ SwitcherMode run_switcher_dialog ( char **input, G_GNUC_UNUSED void *data )
|
||||||
SwitcherMode retv = MODE_EXIT;
|
SwitcherMode retv = MODE_EXIT;
|
||||||
// act as a launcher
|
// act as a launcher
|
||||||
unsigned int cmd_list_length = 0;
|
unsigned int cmd_list_length = 0;
|
||||||
char **cmd_list = get_apps ( &cmd_list_length );
|
char **cmd_list = NULL;
|
||||||
|
cmd_list = get_apps ( &cmd_list_length );
|
||||||
|
if ( config.run_list_command != NULL && config.run_list_command[0] != '\0' ) {
|
||||||
|
cmd_list = get_apps_external ( cmd_list, &cmd_list_length );
|
||||||
|
}
|
||||||
|
|
||||||
if ( cmd_list == NULL ) {
|
if ( cmd_list == NULL ) {
|
||||||
cmd_list = g_malloc_n ( 2, sizeof ( char * ) );
|
cmd_list = g_malloc_n ( 2, sizeof ( char * ) );
|
||||||
|
|
|
@ -40,35 +40,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pid_t execute_generator ( char * cmd )
|
|
||||||
{
|
|
||||||
char **args = NULL;
|
|
||||||
int argv = 0;
|
|
||||||
helper_parse_setup ( config.run_command, &args, &argv, "{cmd}", cmd, NULL );
|
|
||||||
|
|
||||||
int fd = -1;
|
|
||||||
GError *error = NULL;
|
|
||||||
g_spawn_async_with_pipes ( NULL,
|
|
||||||
args,
|
|
||||||
NULL,
|
|
||||||
G_SPAWN_SEARCH_PATH,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL, &fd, NULL,
|
|
||||||
&error );
|
|
||||||
|
|
||||||
if ( error != NULL ) {
|
|
||||||
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd,
|
|
||||||
error->message );
|
|
||||||
error_dialog ( msg );
|
|
||||||
g_free ( msg );
|
|
||||||
// print error.
|
|
||||||
g_error_free ( error );
|
|
||||||
}
|
|
||||||
g_strfreev ( args );
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char **get_script_output ( char *command, unsigned int *length )
|
static char **get_script_output ( char *command, unsigned int *length )
|
||||||
|
|
|
@ -101,6 +101,7 @@ static XrmOption xrmOptions[] = {
|
||||||
{ xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL },
|
{ xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL },
|
||||||
{ xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL },
|
{ xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL },
|
||||||
{ xrm_String, "run-command", { .str = &config.run_command }, NULL },
|
{ xrm_String, "run-command", { .str = &config.run_command }, NULL },
|
||||||
|
{ xrm_String, "run-list-command", { .str = &config.run_list_command }, NULL },
|
||||||
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL },
|
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL },
|
||||||
|
|
||||||
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL },
|
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL },
|
||||||
|
|
Loading…
Reference in a new issue