Hamish
unread,Apr 3, 2008, 4:18:19 PM4/3/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Hotwire Shell
Started writing some code to import my aliases from my .bash_aliases
file. Not sure where it should be hooked into the code, and there are
a few issues to think about. In particular this first cut of code
assumes that sys is the correct thing to prepend to the command. But
if it is a builtin (such as ls) then which should we use? I'd also
need to check for the commands that need to be run in a term (is there
some way to share that info with the current set?). Then there are
aliases that use bash variables (eg $EDITOR) ...
Do folk reckon this is worth persuing? I think it would be pretty
cool to try out hotwire and have your usual aliases working as if by
magic :)
All feedback appreciated.
--- CODE STARTS ---
import re
import os.path
from hotwire.cmdalias import AliasRegistry
# this regex works for
# alias ls='ls -l'
# style aliases (good for bash and zsh)
bashalias_re = re.compile ("""
^\s* alias \s+ # find the alias at the start
([-a-zA-Z0-9_.]+) # the name of the alias
\s*=\s* # separator from command
(?: # which is in one of these formats:
'([^']+)' # the command in single quotes
| # or ...
\"([^"])\" # the command in double quotes
| # or ...
(\w+) # the command as a single word
)
\s*$
""",re.VERBOSE)
# this regex works for
# alias tcsh '/usr/bin/tcsh -l'
# style aliases (good for tcsh and csh)
cshalias_re = re.compile ("""
^\s* alias \s+ # find the alias at the start
([-a-zA-Z0-9_.]+) # the name of the alias
\s+ # separator from command
(?: # which is in one of these formats:
'([^']+)' # the command in single quotes
| # or ...
\"([^"])\" # the command in double quotes
| # or ...
(\w+) # the command as a single word
)
\s*$
""",re.VERBOSE)
# need to add extra fro tcsh ...
filelist = [ "~/.bashrc", "~/.bash_aliases", "~/.zshrc" ]
for filename in filelist:
filename = os.path.expanduser(filename)
if not os.path.isfile(filename):
continue
for line in open(filename):
# TODO: need to decide which regex to use here
m = bashalias_re.match(line)
if m:
# make into a hotwire alias
name = m.group(1)
target = 'sys ' + m.group(m.lastindex)
# print "name: " + name + " target: " + target
# TODO: do we want to check the alias for possible
conflict with
# builtin command? For commands that need term rather
than sys ...
AliasRegistry.getInstance().insert(name, target)