diff options
Diffstat (limited to 'vish')
| -rw-r--r-- | vish/builtin.py | 29 | 
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()  | 
