Skip to content

Instantly share code, notes, and snippets.

@kentquirk
Created December 7, 2017 02:58
Show Gist options
  • Save kentquirk/9345edbbd972fea31139c45251701e3f to your computer and use it in GitHub Desktop.
Save kentquirk/9345edbbd972fea31139c45251701e3f to your computer and use it in GitHub Desktop.
fixpath.py is a script to clean up a path
#! /usr/bin/env python
# returns a path with some special front/back values and dups removed
import os
import sys
def getenv(name):
try:
return os.environ[name].split(':')
except KeyError:
return []
front=getenv('PATH_FIRST')
path =getenv('PATH')
back =getenv('PATH_LAST')
mypath = []
def additems(bucket):
for i in bucket:
if i not in mypath:
mypath.append(i)
additems(front)
additems(path)
additems(back)
sys.stdout.write(':'.join(mypath))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment