summaryrefslogtreecommitdiff
path: root/purge_path/purge_path.py
blob: dab14e405c7c4b678938435a11948884726f5606 (plain) (blame)
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
#!/usr/bin/env python
from __future__ import print_function
import os
import sys


def purge(path, pattern):
    if not isinstance(path, list):
        path = path.split(':')

    path_new = ''
    for rec in path:
        if rec == pattern:
            # ignore pattern
            continue
        path_new += rec + ':'

    return path_new[:-1]


def main():
    args = sys.argv[1:]
    path_orig = os.environ['PATH']
    path_new = path_orig

    for arg in args:
        path_new = purge(path_new, arg)

    if path_new:
        print(path_new)
    else:
        print(path_orig)


if __name__ in '__main__':
    main()