summaryrefslogtreecommitdiff
path: root/vish/builtin.py
blob: ccfc5b36970d72c9e6df40c7ce37118d33a2ce44 (plain)
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
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()