JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Applying the patch of Roberto Caballero to set WINDOWID and all the pwuid()
[st.git] / st.c
diff --git a/st.c b/st.c
index e19cefd..f54e4d5 100644 (file)
--- a/st.c
+++ b/st.c
@@ -5,6 +5,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <locale.h>
+#include <pwd.h>
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -678,7 +679,7 @@ bpress(XEvent *e) {
 
 void
 selcopy(void) {
-       char *str, *ptr, *p;
+       char *str, *ptr;
        int x, y, bufsize, is_selected = 0, size;
        Glyph *gp;
 
@@ -693,11 +694,12 @@ selcopy(void) {
                        for(x = 0; x < term.col; x++) {
                                gp = &term.line[y][x];
 
-                               if(!(is_selected = selected(x, y)))
+                               if(!(is_selected = selected(x, y))
+                                               || !(gp->state & GLYPH_SET)) {
                                        continue;
-                               p = (gp->state & GLYPH_SET) ? gp->c : " ";
-                               size = utf8size(p);
-                               memcpy(ptr, p, size);
+                               }
+                               size = utf8size(gp->c);
+                               memcpy(ptr, gp->c, size);
                                ptr += size;
                        }
                        /* \n at the end of every selected line except for the last one */
@@ -880,11 +882,23 @@ void
 execsh(void) {
        char **args;
        char *envshell = getenv("SHELL");
+       const struct passwd *pass = getpwuid(getuid());
+       char buf[sizeof(long) * 8 + 1];
 
        unsetenv("COLUMNS");
        unsetenv("LINES");
        unsetenv("TERMCAP");
 
+       if(pass) {
+               setenv("LOGNAME", pass->pw_name, 1);
+               setenv("USER", pass->pw_name, 1);
+               setenv("SHELL", pass->pw_shell, 0);
+               setenv("HOME", pass->pw_dir, 0);
+       }
+
+       snprintf(buf, sizeof(buf), "%lu", xw.win);
+       setenv("WINDOWID", buf, 1);
+
        signal(SIGCHLD, SIG_DFL);
        signal(SIGHUP, SIG_DFL);
        signal(SIGINT, SIG_DFL);
@@ -2794,8 +2808,8 @@ main(int argc, char *argv[]) {
 run:
        setlocale(LC_CTYPE, "");
        tnew(80, 24);
-       ttynew();
        xinit();
+       ttynew();
        selinit();
        run();
        return 0;