aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2016-07-30 16:31:56 +0200
committerBoris Faure <billiob@gmail.com>2016-07-30 16:31:56 +0200
commit0e0105e55931ab5483668dee9c972e6ec4cec279 (patch)
treeb9a22013eb0dd8f3f9f877813c2e7c26edc5f1a9
parentterminology: Fix issue of icon not showing under wayland (diff)
downloadterminology-0e0105e55931ab5483668dee9c972e6ec4cec279.tar.gz
make ty* fail nicely when in tmux/screen
-rw-r--r--src/bin/Makefile.am14
-rw-r--r--src/bin/tyalpha.c6
-rw-r--r--src/bin/tybg.c7
-rw-r--r--src/bin/tycat.c5
-rw-r--r--src/bin/tycommon.c21
-rw-r--r--src/bin/tycommon.h18
-rw-r--r--src/bin/tyls.c6
-rw-r--r--src/bin/typop.c8
-rw-r--r--src/bin/tyq.c8
9 files changed, 80 insertions, 13 deletions
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index f34b168..8d600dc 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -63,43 +63,48 @@ gravatar.c gravatar.h \
tty_keys.h
tybg_SOURCES = \
+tycommon.c \
tybg.c
tybg_CPPFLAGS = -I. \
-DPACKAGE_BIN_DIR=\"$(bindir)\" -DPACKAGE_LIB_DIR=\"$(libdir)\" \
--DPACKAGE_DATA_DIR=\"$(pkgdatadir)\"
+-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" @TERMINOLOGY_CFLAGS@
tybg_LDADD =
tyalpha_SOURCES = \
+tycommon.c \
tyalpha.c
tyalpha_CPPFLAGS = -I. \
-DPACKAGE_BIN_DIR=\"$(bindir)\" -DPACKAGE_LIB_DIR=\"$(libdir)\" \
--DPACKAGE_DATA_DIR=\"$(pkgdatadir)\"
+-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" @TERMINOLOGY_CFLAGS@
tyalpha_LDADD =
typop_SOURCES = \
+tycommon.c \
typop.c
typop_CPPFLAGS = -I. \
-DPACKAGE_BIN_DIR=\"$(bindir)\" -DPACKAGE_LIB_DIR=\"$(libdir)\" \
--DPACKAGE_DATA_DIR=\"$(pkgdatadir)\"
+-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" @TERMINOLOGY_CFLAGS@
typop_LDADD =
tyq_SOURCES = \
+tycommon.c \
tyq.c
tyq_CPPFLAGS = -I. \
-DPACKAGE_BIN_DIR=\"$(bindir)\" -DPACKAGE_LIB_DIR=\"$(libdir)\" \
--DPACKAGE_DATA_DIR=\"$(pkgdatadir)\"
+-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" @TERMINOLOGY_CFLAGS@
tyq_LDADD =
tycat_SOURCES = \
tycat.c \
+tycommon.c \
extns.c extns.h
tycat_CPPFLAGS = -I. \
@@ -110,6 +115,7 @@ tycat_LDADD = @TERMINOLOGY_LIBS@
tyls_SOURCES = \
tyls.c \
+tycommon.c \
extns.h
tyls_CPPFLAGS = -I. \
diff --git a/src/bin/tyalpha.c b/src/bin/tyalpha.c
index ac189d7..7b55b7a 100644
--- a/src/bin/tyalpha.c
+++ b/src/bin/tyalpha.c
@@ -4,12 +4,16 @@
#include <unistd.h>
#include <string.h>
+#include <Eina.h>
+#include "tycommon.h"
+
int
main(int argc, char **argv)
{
int i, perm = 0;
- if (!getenv("TERMINOLOGY")) return 0;
+ ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
+
if (argc <= 1)
{
printf("Usage: %s [-p] on|off|<opacity level>\n"
diff --git a/src/bin/tybg.c b/src/bin/tybg.c
index 722c598..cc3df43 100644
--- a/src/bin/tybg.c
+++ b/src/bin/tybg.c
@@ -4,12 +4,17 @@
#include <unistd.h>
#include <string.h>
+#include <Eina.h>
+#include "tycommon.h"
+
+
int
main(int argc, char **argv)
{
int i, perm = 0;
- if (!getenv("TERMINOLOGY")) return 0;
+ ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
+
if (argc > 1 &&
(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))
{
diff --git a/src/bin/tycat.c b/src/bin/tycat.c
index 1dec71c..709640d 100644
--- a/src/bin/tycat.c
+++ b/src/bin/tycat.c
@@ -11,6 +11,8 @@
#include <unistd.h>
#include <string.h>
+#include "tycommon.h"
+
enum {
CENTER,
FILL,
@@ -308,7 +310,8 @@ main(int argc, char **argv)
char *rp;
Eina_List *file_q = NULL;
- if (!getenv("TERMINOLOGY")) return 0;
+ ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
+
if (argc <= 1)
{
print_usage(argv[0]);
diff --git a/src/bin/tycommon.c b/src/bin/tycommon.c
new file mode 100644
index 0000000..6ae6efb
--- /dev/null
+++ b/src/bin/tycommon.c
@@ -0,0 +1,21 @@
+#include <stdlib.h>
+#include <Eina.h>
+#include "tycommon.h"
+
+
+Eina_Bool
+is_running_in_terminology(void)
+{
+ if (!getenv("TERMINOLOGY"))
+ return EINA_FALSE;
+
+ // Terminology's escape codes do not got through tmux
+ if (getenv("TMUX"))
+ return EINA_FALSE;
+
+ // Terminology's escape codes do not got through screen
+ if (getenv("STY"))
+ return EINA_FALSE;
+
+ return EINA_TRUE;
+}
diff --git a/src/bin/tycommon.h b/src/bin/tycommon.h
new file mode 100644
index 0000000..f29b247
--- /dev/null
+++ b/src/bin/tycommon.h
@@ -0,0 +1,18 @@
+#ifndef _TY_COMMON_H__
+#define _TY_COMMON_H__ 1
+
+Eina_Bool is_running_in_terminology(void);
+
+#define ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1() \
+ do \
+ { \
+ if (!is_running_in_terminology()) \
+ { \
+ fprintf(stderr, "not running in terminology\n"); \
+ exit(1); \
+ } \
+ } \
+ while (0)
+
+
+#endif
diff --git a/src/bin/tyls.c b/src/bin/tyls.c
index 8469ff7..9bdd305 100644
--- a/src/bin/tyls.c
+++ b/src/bin/tyls.c
@@ -11,6 +11,7 @@
#include <unistd.h>
#include <string.h>
#include <fnmatch.h>
+#include "tycommon.h"
// this code sucks. just letting you know... in advance... in case you
// might be tempted to think otherwise... :)
@@ -725,8 +726,9 @@ main(int argc, char **argv)
char *path;
Eina_List *dirs = NULL;
Tyls_Options options = {SMALL, EINA_FALSE};
-
- if (!getenv("TERMINOLOGY")) return 0;
+
+ ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
+
if ((argc == 2) && (!strcmp(argv[1], "-h")))
{
printf("Usage: %s [-a] [-s|-m] FILE1 [FILE2 ...]\n"
diff --git a/src/bin/typop.c b/src/bin/typop.c
index d777d3a..569ade5 100644
--- a/src/bin/typop.c
+++ b/src/bin/typop.c
@@ -4,12 +4,16 @@
#include <unistd.h>
#include <string.h>
+#include <Eina.h>
+#include "tycommon.h"
+
int
main(int argc, char **argv)
{
int i;
-
- if (!getenv("TERMINOLOGY")) return 0;
+
+ ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
+
if (argc <= 1)
{
printf("Usage: %s FILE1 [FILE2 ...]\n"
diff --git a/src/bin/tyq.c b/src/bin/tyq.c
index 1a73c4e..f78fcc0 100644
--- a/src/bin/tyq.c
+++ b/src/bin/tyq.c
@@ -4,12 +4,16 @@
#include <unistd.h>
#include <string.h>
+#include <Eina.h>
+#include "tycommon.h"
+
int
main(int argc, char **argv)
{
int i;
-
- if (!getenv("TERMINOLOGY")) return 0;
+
+ ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
+
if (argc <= 1)
{
printf("Usage: %s FILE1 [FILE2 ...]\n"