1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
diff --git a/src/CLI2.cpp b/src/CLI2.cpp
index a6c1305b..b43a7820 100644
--- a/src/CLI2.cpp
+++ b/src/CLI2.cpp
@@ -36,6 +36,8 @@
#include <util.h>
#include <i18n.h>
+#include <CurrentContext.h>
+
extern Context context;
// Overridden by rc.abbreviation.minimum.
@@ -568,7 +570,7 @@ void CLI2::addContextFilter ()
return;
// Detect if any context is set, and bail out if not
- std::string contextName = context.config.get ("context");
+ std::string contextName = getCurrentContext (context);
if (contextName == "")
{
context.debug ("No context.");
diff --git a/src/CurrentContext.h b/src/CurrentContext.h
new file mode 100644
index 00000000..8dc79828
--- /dev/null
+++ b/src/CurrentContext.h
@@ -0,0 +1,20 @@
+/*
+ * CurrentContext.h
+ * Copyright (C) 2016 Ivan Čukić <ivan.cukic(at)kde.org>
+ *
+ * Distributed under terms of the MIT license.
+ */
+
+#ifndef CURRENTCONTEXT_H
+#define CURRENTCONTEXT_H
+
+inline std::string getCurrentContext (Context &context)
+{
+ // If the currently set context was deleted, unset it
+ const char * currentContextOverride = getenv ("TASK_CONTEXT");
+
+ return currentContextOverride ? std::string (currentContextOverride)
+ : context.config.get ("context");
+}
+
+#endif /* !CURRENTCONTEXT_H */
diff --git a/src/commands/CmdContext.cpp b/src/commands/CmdContext.cpp
index e507f403..d8e4619b 100644
--- a/src/commands/CmdContext.cpp
+++ b/src/commands/CmdContext.cpp
@@ -35,6 +35,8 @@
#include <util.h>
#include <text.h>
+#include <CurrentContext.h>
+
extern Context context;
////////////////////////////////////////////////////////////////////////////////
@@ -190,6 +192,8 @@ void CmdContext::deleteContext (const std::vector <std::string>& words, std::str
auto rc = CmdConfig::unsetConfigVariable(name, confirmation);
// If the currently set context was deleted, unset it
+ // We are not using the environment variable override here,
+ // but the actual configured value
if (context.config.get ("context") == words[1])
CmdConfig::unsetConfigVariable("context", false);
@@ -230,7 +234,7 @@ void CmdContext::listContexts (std::stringstream& out)
view.colorHeader (label);
}
- std::string activeContext = context.config.get ("context");
+ std::string activeContext = getCurrentContext (context);
for (auto& userContext : contexts)
{
@@ -292,7 +296,7 @@ void CmdContext::setContext (const std::vector <std::string>& words, std::string
//
void CmdContext::showContext (std::stringstream& out)
{
- auto currentContext = context.config.get ("context");
+ auto currentContext = getCurrentContext (context);
if (currentContext == "")
out << STRING_CMD_CONTEXT_SHOW_EMPT << "\n";
|