mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-03 04:23:42 -05:00
also accept . in ssh hostname
This commit is contained in:
parent
8b6b494830
commit
b0ee6ab8dd
4 changed files with 82 additions and 60 deletions
|
@ -49,7 +49,7 @@ Settings config = {
|
|||
.run_key = "mod1+F2",
|
||||
.ssh_key = "mod1+F3",
|
||||
#ifdef I3
|
||||
.mark_key = "mod1+F5",
|
||||
.mark_key = "mod1+F5",
|
||||
#endif
|
||||
.location = CENTER,
|
||||
.wmode = VERTICAL,
|
||||
|
|
|
@ -51,32 +51,36 @@
|
|||
#include <time.h>
|
||||
#endif
|
||||
|
||||
static char * escape_name(const char *mark, ssize_t *length)
|
||||
static char * escape_name( const char *mark, ssize_t *length )
|
||||
{
|
||||
// Escape the mark.
|
||||
// Max length is twice the old size + trailing \0.
|
||||
char *escaped_mark = malloc(sizeof(char)*(strlen(mark)*2+1));
|
||||
ssize_t lm = strlen(mark);
|
||||
*length = 0;
|
||||
for(ssize_t iter = 0; iter < lm; iter++) {
|
||||
if(mark[iter] == '\'' || mark[iter] == '\"' || mark[iter] == '\\') {
|
||||
escaped_mark[(*length)++] = '\\';
|
||||
}
|
||||
escaped_mark[(*length)++] = mark[iter];
|
||||
escaped_mark[(*length)] = '\0';
|
||||
}
|
||||
return escaped_mark;
|
||||
// Escape the mark.
|
||||
// Max length is twice the old size + trailing \0.
|
||||
char *escaped_mark = malloc( sizeof( char )*( strlen( mark )*2+1 ) );
|
||||
ssize_t lm = strlen( mark );
|
||||
*length = 0;
|
||||
|
||||
for ( ssize_t iter = 0; iter < lm; iter++ ) {
|
||||
if ( mark[iter] == '\'' || mark[iter] == '\"' || mark[iter] == '\\' ) {
|
||||
escaped_mark[( *length )++] = '\\';
|
||||
}
|
||||
|
||||
escaped_mark[( *length )++] = mark[iter];
|
||||
escaped_mark[( *length )] = '\0';
|
||||
}
|
||||
|
||||
return escaped_mark;
|
||||
}
|
||||
|
||||
|
||||
static void exec_mark(const char *mark)
|
||||
static void exec_mark( const char *mark )
|
||||
{
|
||||
int s, t, len;
|
||||
struct sockaddr_un remote;
|
||||
if(config.i3_mode == 0) {
|
||||
fprintf(stderr, "Cannot use marks without i3 running\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
if ( config.i3_mode == 0 ) {
|
||||
fprintf( stderr, "Cannot use marks without i3 running\n" );
|
||||
return ;
|
||||
}
|
||||
|
||||
if ( strlen( i3_socket_path ) > UNIX_PATH_MAX ) {
|
||||
fprintf( stderr, "Socket path is to long. %zd > %d\n", strlen( i3_socket_path ), UNIX_PATH_MAX );
|
||||
|
@ -100,10 +104,10 @@ static void exec_mark(const char *mark)
|
|||
|
||||
|
||||
// Formulate command
|
||||
ssize_t lem = 0;
|
||||
char *escaped_mark = escape_name(mark, &lem);
|
||||
ssize_t lem = 0;
|
||||
char *escaped_mark = escape_name( mark, &lem );
|
||||
char command[lem+20];
|
||||
snprintf( command, lem+20, "[con_mark=\"%s\"] focus", escaped_mark);
|
||||
snprintf( command, lem+20, "[con_mark=\"%s\"] focus", escaped_mark );
|
||||
|
||||
// Prepare header.
|
||||
i3_ipc_header_t head;
|
||||
|
@ -127,17 +131,19 @@ static void exec_mark(const char *mark)
|
|||
|
||||
close( s );
|
||||
|
||||
free(escaped_mark);
|
||||
free( escaped_mark );
|
||||
}
|
||||
|
||||
static char ** get_mark ( )
|
||||
{
|
||||
unsigned int retv_index = 0;
|
||||
char **retv = NULL;
|
||||
if(config.i3_mode == 0) {
|
||||
fprintf(stderr, "Cannot use marks without i3 running\n");
|
||||
return retv;
|
||||
}
|
||||
|
||||
if ( config.i3_mode == 0 ) {
|
||||
fprintf( stderr, "Cannot use marks without i3 running\n" );
|
||||
return retv;
|
||||
}
|
||||
|
||||
#ifdef TIMING
|
||||
struct timespec start, stop;
|
||||
clock_gettime( CLOCK_REALTIME, &start );
|
||||
|
@ -171,7 +177,7 @@ static char ** get_mark ( )
|
|||
// Formulate command
|
||||
// Prepare header.
|
||||
memcpy( head.magic, I3_IPC_MAGIC, 6 );
|
||||
head.size = 0;
|
||||
head.size = 0;
|
||||
head.type = I3_IPC_MESSAGE_TYPE_GET_MARKS;
|
||||
// Send header.
|
||||
send( s, &head, sizeof( head ),0 );
|
||||
|
@ -179,40 +185,48 @@ static char ** get_mark ( )
|
|||
t = recv( s, &head, sizeof( head ),0 );
|
||||
|
||||
if ( t == sizeof( head ) ) {
|
||||
char *result = malloc(sizeof(char)*(head.size+1));
|
||||
ssize_t index = 0;
|
||||
// Grab results.
|
||||
while(index < head.size) {
|
||||
t= recv( s, &result[index], (head.size-t), 0 );
|
||||
if(t < 0 ) break;
|
||||
result[index+t] = '\0';
|
||||
index+=t;
|
||||
}
|
||||
for(int iter_start = 1; iter_start < index-1 ; iter_start++) {
|
||||
// Skip , and opening "
|
||||
if(result[iter_start] == '"' || result[iter_start] == ',') continue;
|
||||
int iter_end = iter_start;
|
||||
char *result = malloc( sizeof( char )*( head.size+1 ) );
|
||||
ssize_t index = 0;
|
||||
|
||||
// Find closing tag.. make sure to ignore escaped chars.
|
||||
// Copy the un-escaped string into the first part.
|
||||
int rindex = 0;
|
||||
do{
|
||||
result[rindex++] = result[iter_end];
|
||||
iter_end++;
|
||||
if(result[iter_end] == '\\') iter_end+=1;
|
||||
}while(result[iter_end] != '"');
|
||||
result[rindex] = '\0';
|
||||
// Grab results.
|
||||
while ( index < head.size ) {
|
||||
t= recv( s, &result[index], ( head.size-t ), 0 );
|
||||
|
||||
// Add element to list.
|
||||
retv = realloc( retv, ( retv_index+2 )*sizeof( char* ) );
|
||||
retv[retv_index] = strndup(result,rindex);
|
||||
retv[retv_index+1] = NULL;
|
||||
retv_index++;
|
||||
if ( t < 0 ) break;
|
||||
|
||||
iter_start = iter_end;
|
||||
}
|
||||
result[index+t] = '\0';
|
||||
index+=t;
|
||||
}
|
||||
|
||||
free(result);
|
||||
for ( int iter_start = 1; iter_start < index-1 ; iter_start++ ) {
|
||||
// Skip , and opening "
|
||||
if ( result[iter_start] == '"' || result[iter_start] == ',' ) continue;
|
||||
|
||||
int iter_end = iter_start;
|
||||
|
||||
// Find closing tag.. make sure to ignore escaped chars.
|
||||
// Copy the un-escaped string into the first part.
|
||||
int rindex = 0;
|
||||
|
||||
do {
|
||||
result[rindex++] = result[iter_end];
|
||||
iter_end++;
|
||||
|
||||
if ( result[iter_end] == '\\' ) iter_end+=1;
|
||||
} while ( result[iter_end] != '"' );
|
||||
|
||||
result[rindex] = '\0';
|
||||
|
||||
// Add element to list.
|
||||
retv = realloc( retv, ( retv_index+2 )*sizeof( char* ) );
|
||||
retv[retv_index] = strndup( result,rindex );
|
||||
retv[retv_index+1] = NULL;
|
||||
retv_index++;
|
||||
|
||||
iter_start = iter_end;
|
||||
}
|
||||
|
||||
free( result );
|
||||
}
|
||||
|
||||
close( s );
|
||||
|
|
|
@ -1185,11 +1185,14 @@ void run_switcher( int fmode, SwitcherMode mode )
|
|||
} else if ( mode == SSH_DIALOG ) {
|
||||
retv = ssh_switcher_dialog( &input );
|
||||
}
|
||||
|
||||
#ifdef I3
|
||||
else if ( mode == MARK_DIALOG ) {
|
||||
retv = mark_switcher_dialog ( &input );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if ( retv == NEXT_DIALOG ) {
|
||||
mode = ( mode+1 )%NUM_DIALOGS;
|
||||
} else {
|
||||
|
@ -1225,11 +1228,14 @@ void handle_keypress( XEvent *ev )
|
|||
key == sshdialog_keysym ) {
|
||||
run_switcher( FORK , SSH_DIALOG );
|
||||
}
|
||||
|
||||
#ifdef I3
|
||||
|
||||
if ( ( markdialog_modmask == AnyModifier || ev->xkey.state & markdialog_modmask ) &&
|
||||
key == markdialog_keysym ) {
|
||||
run_switcher( FORK , MARK_DIALOG );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -176,7 +176,9 @@ static char ** get_ssh ( )
|
|||
|
||||
for ( start=4; isspace( buffer[start] ); start++ );
|
||||
|
||||
for ( stop=start; isalnum( buffer[stop] ) || buffer[stop] == '_' ; stop++ );
|
||||
for ( stop=start; isalnum( buffer[stop] ) ||
|
||||
buffer[stop] == '_' ||
|
||||
buffer[stop] == '.' ; stop++ );
|
||||
|
||||
int found = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue