mirror of
https://github.com/davatorium/rofi.git
synced 2025-02-10 15:44:41 -05:00
Fix issue #271 expand path.
This commit is contained in:
parent
e196df01fa
commit
2da1207b7d
3 changed files with 34 additions and 1 deletions
|
@ -339,4 +339,13 @@ struct _Mode
|
||||||
#define color_cyan_bold "\033[1;36m"
|
#define color_cyan_bold "\033[1;36m"
|
||||||
|
|
||||||
int show_error_message ( const char *msg, int markup );
|
int show_error_message ( const char *msg, int markup );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param input The path to expand
|
||||||
|
*
|
||||||
|
* Expand path, both `~` and `~<user>`
|
||||||
|
*
|
||||||
|
* @returns path
|
||||||
|
*/
|
||||||
|
char *rofi_expand_path ( const char *input );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -185,7 +185,7 @@ Mode *script_switcher_parse_setup ( const char *str )
|
||||||
g_strlcpy ( sw->name, token, 32 );
|
g_strlcpy ( sw->name, token, 32 );
|
||||||
}
|
}
|
||||||
else if ( index == 1 ) {
|
else if ( index == 1 ) {
|
||||||
sw->ed = (void *) g_strdup ( token );
|
sw->ed = (void *) rofi_expand_path ( token );
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
#include "x11-helper.h"
|
#include "x11-helper.h"
|
||||||
|
@ -661,3 +662,26 @@ int is_not_ascii ( const char * str )
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *rofi_expand_path ( const char *input )
|
||||||
|
{
|
||||||
|
char **str = g_strsplit ( input, G_DIR_SEPARATOR_S, -1 );
|
||||||
|
for ( unsigned int i = 0; str && str[i]; i++ ) {
|
||||||
|
// Replace ~ with current user homedir.
|
||||||
|
if ( str[i][0] == '~' && str[i][1] == '\0' ) {
|
||||||
|
g_free ( str[i] );
|
||||||
|
str[i] = g_strdup ( g_get_home_dir () );
|
||||||
|
}
|
||||||
|
// If other user, ask getpwnam.
|
||||||
|
else if ( str[i][0] == '~' ) {
|
||||||
|
struct passwd *p = getpwnam ( &( str[i][1] ) );
|
||||||
|
if ( p != NULL ) {
|
||||||
|
g_free ( str[i] );
|
||||||
|
str[i] = g_strdup ( p->pw_dir );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
char *retv = g_build_filenamev ( str );
|
||||||
|
g_strfreev ( str );
|
||||||
|
return retv;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue