summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2020-03-21 11:55:00 +0100
committerOlivier Gayot <olivier.gayot@sigexec.com>2020-03-21 12:59:52 +0100
commit7b51b6435a48efc3667f016b48b39d462158f1bb (patch)
tree43c146459ee4b619ec571d319f977d339a81357e
parent6d76fbd80a1d633c7b5583730e0a0247f365ae10 (diff)
Add a few builtins
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rw-r--r--vish/builtin.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/vish/builtin.py b/vish/builtin.py
new file mode 100644
index 0000000..ccfc5b3
--- /dev/null
+++ b/vish/builtin.py
@@ -0,0 +1,29 @@
+import os
+import sys
+
+class TooManyArguments(Exception):
+ pass
+
+
+def pwd(args: list, stdin=sys.stdin, stdout=sys.stdout):
+ if not len(args) == 0:
+ raise TooManyArguments()
+
+ print(os.getcwd(), file=stdout)
+
+
+def chdir(args: list, stdin=sys.stdin, stdout=sys.stdout):
+ if len(args) == 0:
+ os.chdir(os.getenv("HOME"))
+ elif len(args) == 1:
+ os.chdir(next(iter(args)))
+ else:
+ raise TooManyArguments()
+
+
+def export(args: list, stdin=sys.stdin, stdout=sys.stdout):
+ if len(args) == 0:
+ for key, value in sorted(os.environ.items()):
+ print(f"{key}={value}", file=stdout)
+ else:
+ raise NotImplementedError()