The way I did it was with a quick python script:
import sys
import string
import os
import glob
def listAll():
for infile in glob.glob("c:\\aliases\\*.bat"):
fileName = infile
fileName = fileName[len("c:\\aliases\\"):len(fileName)-4]
fileContents = open("c:\\aliases\\" + fileName + ".bat", "r")
fileContents.readline()
fileContentString=fileContents.readline()
fileName += " is aliased to "
fileName += fileContentString[0:len(fileContentString)-3]
print fileName
def listSome(which):
for infile in glob.glob("c:\\aliases\\*.bat"):
fileName = infile
fileName = fileName[len("c:\\aliases\\"):len(fileName)-4]
fileContents = open("c:\\aliases\\" + fileName + ".bat", "r")
fileContents.readline()
fileContentString=fileContents.readline()
if fileName.find(which)==0:
fileName += " is aliased to "
fileName += fileContentString[0:len(fileContentString)-3]
print fileName
if len(sys.argv)>1:
if sys.argv[1]!="-p":
file = open("c:\\aliases\\"+sys.argv[1]+".bat", "w")
file.write("@ECHO OFF\n")
counter=0
totalInput=""
counter=0
for arg in sys.argv:
if counter > 1:
totalInput+= arg + " "
counter+=1
if totalInput.find(".exe")!=-1:
file.write("\"")
counter=0
for arg in sys.argv:
if counter > 1:
file.write(arg)
if sys.argv[1]==sys.argv[2]:
if counter==2:
file.write(".exe")
temparg=str(arg)
if temparg.find(".exe")!=-1:
file.write("\"")
file.write(" ")
counter+=1
file.write("%*")
print "Aliased " + sys.argv[1] + " to " + totalInput
else:
if len(sys.argv)>2:
listSome(sys.argv[2])
else:
listAll()
else:
listAll()
Apologies for the poor scripting, but the usage is quite nice, imo.
Place it somewhere in your path, add .py to your PATHEXT, and add c:\aliases to your PATH too (or change it, whatever suits), then use:
alias <command> <action>
to alias (Yep, no =, though it wouldn't be hard to add a .split in there), and:
alias -p <command or part of>
To display what something is.
Hackish, but stupidly useful. There's an equivalent unalias script, but I'm sure you can work that one out.
edit: This obviously requires python, written on v26 but will probably work in anything recent. As before, sorry for the quality :)
edit2: Actually, something like this but to add to the doskey stuff would be better. You can add startup commands to cmd with the autorun registry key, too, so that could be much cleaner.