I have this in my profile script.
$AddablePaths = @{
"python3"=";C:\Python32";
"python2"=";C:\Python27";
"D"=";C:\D\dmd2\windows\bin";
"gcc"=";C:\MinGW\bin";
"verge"=";C:\Users\Cold\Dev\Verge\tools";
"ruby"=";C:\Ruby192\bin";
"git"=";C:\Program Files\Git\cmd";
"cmake"=";C:\Program Files\CMake 2.8\bin";
"emacs"=";C:\Users\Cold\Dev\emacs\bin";
"notepad++"=";C:\Program Files\Notepad++";
"boost-build"=";C:\Users\Cold\Dev\C++\boost-build\bin";
"svn"=";C:\Program FIles\SlikSvn\bin";
"gtk2"=";C:\Program Files\GTK2-Runtime\bin";
"qt"=";C:\Qt\bin";
"komodo"=";C:\Program Files\ActiveState Komodo Edit 6\";
"hg"=";C:\Program Files\TortoiseHg\"
}
$AddedPaths = @()
function AddPath($keys)
{
if ($keys.Count -eq 0) { return }
foreach ($key in $keys)
{
if ($AddablePaths.Contains($key))
{
if (!($AddedPaths -contains $key))
{
$env:Path += $AddablePaths[$key]
$AddedPaths += $key
}
}
else
{
Write-Host "Invalid path option. Options are:"
foreach ($key in $AddablePaths.keys) {
Write " $key"
}
}
}
}
It's purpose is to allow me to be able to easily add to my path only the things that I need. For example, I can call AddPath("ruby","git","notepad++") to add those three things to my path. I want that it doesn't add items if I already added them, so I created the $AddedPaths array to keep track of what's been added already. However, it doesn't update when I call the function, so duplicates can still be added. What am I doing wrong?