expand ~ and ~user; upstream was kind enough to properly implement this instead

of relying on wordexp(), which wouldn't have worked for us.
This commit is contained in:
jasper 2015-12-07 09:04:38 +00:00
parent 11324b60a4
commit 523d1afbbb
4 changed files with 89 additions and 3 deletions

View File

@ -1,10 +1,10 @@
# $OpenBSD: Makefile,v 1.6 2015/11/18 20:16:07 jasper Exp $
# $OpenBSD: Makefile,v 1.7 2015/12/07 09:04:38 jasper Exp $
COMMENT = window switcher, run dialog and dmenu replacement
GH_PROJECT = rofi
GH_TAGNAME = 0.15.11
REVISION = 0
REVISION = 1
GH_ACCOUNT = DaveDavenPort
DISTNAME = ${GH_PROJECT}-${GH_TAGNAME}
@ -29,7 +29,7 @@ BUILD_DEPENDS+= ${MODGNU_AUTOMAKE_DEPENDS} \
${MODGNU_AUTOCONF_DEPENDS}
CONFIGURE_STYLE = gnu
CONFIGURE_ENV = CPPFLAGS=-I${LOCALBASE}/include
CONFIGURE_ENV = CPPFLAGS="-I${LOCALBASE}/include"
TEST_TARGET = test

View File

@ -0,0 +1,23 @@
$OpenBSD: patch-include_rofi_h,v 1.1 2015/12/07 09:04:38 jasper Exp $
From 2da1207b7df28bb0f9583debef75789e07c0777f Mon Sep 17 00:00:00 2001
From: Dave Davenport <qball@gmpclient.org>
Date: Fri, 27 Nov 2015 13:01:25 +0100
Subject: [PATCH] Fix issue #271 expand path.
--- include/rofi.h.orig Sun Nov 8 10:43:52 2015
+++ include/rofi.h Mon Dec 7 09:25:37 2015
@@ -324,4 +324,13 @@ struct _Switcher
#define color_cyan_bold "\033[1;36m"
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

View File

@ -0,0 +1,18 @@
$OpenBSD: patch-source_dialogs_script_c,v 1.1 2015/12/07 09:04:38 jasper Exp $
From 2da1207b7df28bb0f9583debef75789e07c0777f Mon Sep 17 00:00:00 2001
From: Dave Davenport <qball@gmpclient.org>
Date: Fri, 27 Nov 2015 13:01:25 +0100
Subject: [PATCH] Fix issue #271 expand path.
--- source/dialogs/script.c.orig Sun Nov 8 10:43:52 2015
+++ source/dialogs/script.c Mon Dec 7 09:25:37 2015
@@ -178,7 +178,7 @@ Switcher *script_switcher_parse_setup ( const char *st
g_strlcpy ( sw->name, token, 32 );
}
else if ( index == 1 ) {
- sw->ed = (void *) g_strdup ( token );
+ sw->ed = (void *) rofi_expand_path ( token );
}
index++;
}

View File

@ -0,0 +1,45 @@
$OpenBSD: patch-source_helper_c,v 1.1 2015/12/07 09:04:38 jasper Exp $
From 2da1207b7df28bb0f9583debef75789e07c0777f Mon Sep 17 00:00:00 2001
From: Dave Davenport <qball@gmpclient.org>
Date: Fri, 27 Nov 2015 13:01:25 +0100
Subject: [PATCH] Fix issue #271 expand path.
--- source/helper.c.orig Sun Nov 8 10:43:52 2015
+++ source/helper.c Mon Dec 7 09:25:37 2015
@@ -37,6 +37,7 @@
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
+#include <pwd.h>
#include <ctype.h>
#include "helper.h"
#include "x11-helper.h"
@@ -628,4 +629,27 @@ int is_not_ascii ( const char * str )
return 1;
}
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;
}