From 6e40f9bdd5fa6de121cd8f87bc6350e52723e452 Mon Sep 17 00:00:00 2001 From: jackun Date: Sun, 15 Mar 2020 16:57:49 +0200 Subject: [PATCH] Expand tilde to home dir if string param start with `~` --- src/overlay_params.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index 483ccfb0..f02790eb 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -27,7 +27,8 @@ #include #include #include -#include "X11/keysym.h" +#include +#include #include "imgui.h" #include "overlay_params.h" @@ -142,9 +143,24 @@ parse_signed(const char *str) return strtol(str, NULL, 0); } -static const char * +static std::string parse_str(const char *str) { +#ifdef _XOPEN_SOURCE + // Expand ~/ to home dir + if (str[0] == '~') { + std::string s; + wordexp_t e; + int ret; + + if (!(ret = wordexp(str, &e, 0))) + s = e.we_wordv[0]; + wordfree(&e); + + if (!ret) + return s; + } +#endif return str; }