Created
February 17, 2011 14:58
-
-
Save mpg/831865 to your computer and use it in GitHub Desktop.
start a cmd.exe windows with another TeX distro activated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- distsel.lua: start a cmd.exe windows with another TeX distro activated | |
-- Manuel Pégourié-Gonnard, 2010. WTFPL v2. | |
local usage = [[texlua c:\path\to\distsel.lua DistName C:\path\to\distro]] | |
-- arguments | |
if not arg[2] then | |
io.stderr:write('Usage: ' .. usage) | |
os.exit(1) | |
end | |
local new_distro_name = arg[1] | |
-- for some reason, path arguments get their \ turned to /, undo that | |
local new_distro_path = arg[2]:gsub('/', '\\') | |
-- get our own location | |
kpse.set_program_name(arg[-1]) | |
local my_dir = kpse.var_value('SELFAUTOLOC') | |
-- normalize a path for comparison | |
local function normalize_path(name) | |
return name:lower():gsub('/', '\\') | |
end | |
local current_distro = normalize_path(my_dir) | |
-- compute new path | |
local new_path_dirs = {} | |
local old_path = os.getenv('PATH') | |
for _, dir in ipairs(old_path:explode(';')) do | |
local newdir = dir | |
if normalize_path(dir) == current_distro then | |
newdir = new_distro_path | |
end | |
table.insert(new_path_dirs, newdir) | |
end | |
local new_path = table.concat(new_path_dirs, ';') | |
-- set the new path and open a cmd.exe window | |
os.setenv('PATH', new_path) | |
os.execute('start "'..new_distro_name..'" cmd.exe') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment