From 7b51b6435a48efc3667f016b48b39d462158f1bb Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sat, 21 Mar 2020 11:55:00 +0100 Subject: Add a few builtins Signed-off-by: Olivier Gayot --- vish/builtin.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 vish/builtin.py (limited to 'vish') 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() -- cgit v1.2.3