
@echo off
goto start:


@REM code below borrowed from https://stackoverflow.com/a/1430570 (CC-BY-SA 2.5)
@REM Author: Cheeso, Sep 16, 2009

:removeFromPath
SETLOCAL ENABLEDELAYEDEXPANSION

@REM  ~fs = remove quotes, full path, short names
set fqElement=%~fs1

@REM convert path to a list of quote-delimited strings, separated by spaces
set fpath="%PATH:;=" "%"

@REM iterate through those path elements
for %%p in (%fpath%) do (
    @REM  ~fs = remove quotes, full path, short names
    set p2=%%~fsp
    @REM is this element NOT the one we want to remove?
    if /i NOT "!p2!"=="%fqElement%" (
        if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p)
    )
)

set PATH=!tpath!
ENDLOCAL & set PATH=%tpath%
goto :EOF


@REM code below borrowed from https://stackoverflow.com/a/1430570 (CC-BY-SA 2.5)
@REM Author: Cheeso, Sep 16, 2009

:removeFromYARP_DATA_DIRSList
SETLOCAL ENABLEDELAYEDEXPANSION

@REM  ~fs = remove quotes, full path, short names
set fqElement=%~fs1

@REM convert path to a list of quote-delimited strings, separated by spaces
set fpath="%YARP_DATA_DIRS:;=" "%"

@REM iterate through those path elements
for %%p in (%fpath%) do (
    @REM  ~fs = remove quotes, full path, short names
    set p2=%%~fsp
    @REM is this element NOT the one we want to remove?
    if /i NOT "!p2!"=="%fqElement%" (
        if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p)
    )
)

set YARP_DATA_DIRS=!tpath!
ENDLOCAL & set YARP_DATA_DIRS=%tpath%
goto :EOF


@REM code below borrowed from https://stackoverflow.com/a/1430570 (CC-BY-SA 2.5)
@REM Author: Cheeso, Sep 16, 2009

:removeFromROS_PACKAGE_PATHList
SETLOCAL ENABLEDELAYEDEXPANSION

@REM  ~fs = remove quotes, full path, short names
set fqElement=%~fs1

@REM convert path to a list of quote-delimited strings, separated by spaces
set fpath="%ROS_PACKAGE_PATH:;=" "%"

@REM iterate through those path elements
for %%p in (%fpath%) do (
    @REM  ~fs = remove quotes, full path, short names
    set p2=%%~fsp
    @REM is this element NOT the one we want to remove?
    if /i NOT "!p2!"=="%fqElement%" (
        if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p)
    )
)

set ROS_PACKAGE_PATH=!tpath!
ENDLOCAL & set ROS_PACKAGE_PATH=%tpath%
goto :EOF


@REM code below borrowed from https://stackoverflow.com/a/1430570 (CC-BY-SA 2.5)
@REM Author: Cheeso, Sep 16, 2009

:removeFromGAZEBO_RESOURCE_PATHList
SETLOCAL ENABLEDELAYEDEXPANSION

@REM  ~fs = remove quotes, full path, short names
set fqElement=%~fs1

@REM convert path to a list of quote-delimited strings, separated by spaces
set fpath="%GAZEBO_RESOURCE_PATH:;=" "%"

@REM iterate through those path elements
for %%p in (%fpath%) do (
    @REM  ~fs = remove quotes, full path, short names
    set p2=%%~fsp
    @REM is this element NOT the one we want to remove?
    if /i NOT "!p2!"=="%fqElement%" (
        if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p)
    )
)

set GAZEBO_RESOURCE_PATH=!tpath!
ENDLOCAL & set GAZEBO_RESOURCE_PATH=%tpath%
goto :EOF


@REM code below borrowed from https://stackoverflow.com/a/1430570 (CC-BY-SA 2.5)
@REM Author: Cheeso, Sep 16, 2009

:removeFromAMENT_PREFIX_PATHList
SETLOCAL ENABLEDELAYEDEXPANSION

@REM  ~fs = remove quotes, full path, short names
set fqElement=%~fs1

@REM convert path to a list of quote-delimited strings, separated by spaces
set fpath="%AMENT_PREFIX_PATH:;=" "%"

@REM iterate through those path elements
for %%p in (%fpath%) do (
    @REM  ~fs = remove quotes, full path, short names
    set p2=%%~fsp
    @REM is this element NOT the one we want to remove?
    if /i NOT "!p2!"=="%fqElement%" (
        if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p)
    )
)

set AMENT_PREFIX_PATH=!tpath!
ENDLOCAL & set AMENT_PREFIX_PATH=%tpath%
goto :EOF


@REM code below borrowed from https://stackoverflow.com/a/1430570 (CC-BY-SA 2.5)
@REM Author: Cheeso, Sep 16, 2009

:removeFromGAZEBO_MODEL_PATHList
SETLOCAL ENABLEDELAYEDEXPANSION

@REM  ~fs = remove quotes, full path, short names
set fqElement=%~fs1

@REM convert path to a list of quote-delimited strings, separated by spaces
set fpath="%GAZEBO_MODEL_PATH:;=" "%"

@REM iterate through those path elements
for %%p in (%fpath%) do (
    @REM  ~fs = remove quotes, full path, short names
    set p2=%%~fsp
    @REM is this element NOT the one we want to remove?
    if /i NOT "!p2!"=="%fqElement%" (
        if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p)
    )
)

set GAZEBO_MODEL_PATH=!tpath!
ENDLOCAL & set GAZEBO_MODEL_PATH=%tpath%
goto :EOF

:start
if "%COMSPEC%" NEQ "" (
    call :removeFromYARP_DATA_DIRSList "%CONDA_PREFIX%\Library\share\iCub"
    call :removeFromROS_PACKAGE_PATHList "%CONDA_PREFIX%\Library\share"
    call :removeFromAMENT_PREFIX_PATHList "%CONDA_PREFIX%\Library"
    call :removeFromGAZEBO_MODEL_PATHList "%CONDA_PREFIX%\Library\share\gazebo\models"
    call :removeFromGAZEBO_RESOURCE_PATHList "%CONDA_PREFIX%\Library\share\gazebo\worls"
) else (
    call :removeFromYARP_DATA_DIRSList "%CONDA_PREFIX%\share/iCub"
    call :removeFromROS_PACKAGE_PATHList "%CONDA_PREFIX%\share"
    call :removeFromAMENT_PREFIX_PATHList "%CONDA_PREFIX%"
    call :removeFromGAZEBO_MODEL_PATHList "%CONDA_PREFIX%\share/gazebo/models"
    call :removeFromGAZEBO_RESOURCE_PATHList "%CONDA_PREFIX%\share/gazebo/worls"
)

if "%COMSPEC%" NEQ "" (
    call :removeFromGAZEBO_MODEL_PATHList "%CONDA_PREFIX%\Library\share\iCub\robots"
) else (
    call :removeFromGAZEBO_MODEL_PATHList "%CONDA_PREFIX%\share/iCub/robots"
)

if "%COMSPEC%" NEQ "" (
    call :removeFromGAZEBO_MODEL_PATHList "%CONDA_PREFIX%\Library\share"
) else (
    call :removeFromGAZEBO_MODEL_PATHList "%CONDA_PREFIX%\share"
)
