diff options
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 36 |
1 files changed, 28 insertions, 8 deletions
| @@ -28,6 +28,10 @@ | |||
| 28 | #include <libutil.h> | 28 | #include <libutil.h> |
| 29 | #endif | 29 | #endif |
| 30 | 30 | ||
| 31 | #define USAGE \ | ||
| 32 | "st-" VERSION ", (c) 2010 st engineers\n" \ | ||
| 33 | "usage: st [-t title] [-e cmd] [-v]\n" | ||
| 34 | |||
| 31 | /* Arbitrary sizes */ | 35 | /* Arbitrary sizes */ |
| 32 | #define ESC_TITLE_SIZ 256 | 36 | #define ESC_TITLE_SIZ 256 |
| 33 | #define ESC_BUF_SIZ 256 | 37 | #define ESC_BUF_SIZ 256 |
| @@ -210,6 +214,8 @@ static CSIEscape escseq; | |||
| 210 | static int cmdfd; | 214 | static int cmdfd; |
| 211 | static pid_t pid; | 215 | static pid_t pid; |
| 212 | static Selection sel; | 216 | static Selection sel; |
| 217 | static char *opt_cmd = NULL; | ||
| 218 | static char *opt_title = NULL; | ||
| 213 | 219 | ||
| 214 | void | 220 | void |
| 215 | selinit(void) { | 221 | selinit(void) { |
| @@ -329,9 +335,12 @@ die(const char *errstr, ...) { | |||
| 329 | 335 | ||
| 330 | void | 336 | void |
| 331 | execsh(void) { | 337 | execsh(void) { |
| 332 | char *args[3] = {getenv("SHELL"), "-i", NULL}; | 338 | char *args[] = {getenv("SHELL"), "-i", NULL}; |
| 333 | DEFAULT(args[0], SHELL); /* if getenv() failed */ | 339 | if(opt_cmd) |
| 334 | putenv("TERM=" TNAME); | 340 | args[0] = opt_cmd, args[1] = NULL; |
| 341 | else | ||
| 342 | DEFAULT(args[0], SHELL); | ||
| 343 | putenv("TERM="TNAME); | ||
| 335 | execvp(args[0], args); | 344 | execvp(args[0], args); |
| 336 | } | 345 | } |
| 337 | 346 | ||
| @@ -1189,7 +1198,7 @@ xinit(void) { | |||
| 1189 | 1198 | ||
| 1190 | XMapWindow(xw.dis, xw.win); | 1199 | XMapWindow(xw.dis, xw.win); |
| 1191 | xhints(); | 1200 | xhints(); |
| 1192 | XStoreName(xw.dis, xw.win, "st"); | 1201 | XStoreName(xw.dis, xw.win, opt_title ? opt_title : "st"); |
| 1193 | XSync(xw.dis, 0); | 1202 | XSync(xw.dis, 0); |
| 1194 | } | 1203 | } |
| 1195 | 1204 | ||
| @@ -1429,10 +1438,21 @@ run(void) { | |||
| 1429 | 1438 | ||
| 1430 | int | 1439 | int |
| 1431 | main(int argc, char *argv[]) { | 1440 | main(int argc, char *argv[]) { |
| 1432 | if(argc == 2 && !strncmp("-v", argv[1], 3)) | 1441 | int i; |
| 1433 | die("st-" VERSION ", (c) 2010 st engineers\n"); | 1442 | |
| 1434 | else if(argc != 1) | 1443 | for(i = 1; i < argc; i++) { |
| 1435 | die("usage: st [-v]\n"); | 1444 | switch(argv[i][0] != '-' || argv[i][2] ? -1 : argv[i][1]) { |
| 1445 | case 't': | ||
| 1446 | if(++i < argc) opt_title = argv[i]; | ||
| 1447 | break; | ||
| 1448 | case 'e': | ||
| 1449 | if(++i < argc) opt_cmd = argv[i]; | ||
| 1450 | break; | ||
| 1451 | case 'v': | ||
| 1452 | default: | ||
| 1453 | die(USAGE); | ||
| 1454 | } | ||
| 1455 | } | ||
| 1436 | setlocale(LC_CTYPE, ""); | 1456 | setlocale(LC_CTYPE, ""); |
| 1437 | tnew(80, 24); | 1457 | tnew(80, 24); |
| 1438 | ttynew(); | 1458 | ttynew(); |
