diff --git a/twander.py b/twander.py index f079586..2162604 100755 --- a/twander.py +++ b/twander.py @@ -1,10 +1,10 @@ #!/usr/bin/env python # twander - Wander around the file system # Copyright (c) 2002 TundraWare Inc. All Rights Reserved. - +# For Updates See: http://www.tundraware.com/Software/twander PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.90 2002/12/06 21:23:18 tundra Exp $" +RCSID = "$Id: twander.py,v 1.91 2002/12/09 17:35:41 tundra Exp $" VERSION = RCSID.split()[2] @@ -144,8 +144,9 @@ ##### -WARN = TRUE # Warnings on AUTOREFRESH = TRUE # Automatically refresh the directory display +DEBUG = FALSE # Debugging on +WARN = TRUE # Warnings on ##### # Constants @@ -206,14 +207,20 @@ ASSIGN = "=" # Assignment for variable definitions CONF = "" # Config file user selected with -c option COMMENT = r"#" # Comment character -DIRNAME = r'[DIRECTORY]' # Substitution field in config files ENVVBL = r'$' # Symbol denoting an environment variable -FILE = r'[FILE]' # Substitution field in config files -FILES = r'[FILES]' # Ditto MAXNESTING = 32 # Maximum depth of nested variable definitions reVAR = r"\[.*?\]" # Regex describing variable notation +# Builtins + +DIR = r'[DIR]' +DSELECTION = r'[DSELECTION]' +DSELECTIONS = r'[DSELECTIONS]' +PROMPT = r'[PROMPT]' +SELECTION = r'[SELECTION]' +SELECTIONS = r'[SELECTIONS]' + #----------------------------------------------------------# # Prompts, & Application Strings # @@ -270,6 +277,7 @@ " -b color background color (default: black)", " -c file name of configuration file (default: $HOME/." + PROGNAME + " or PROGDIR/." + PROGNAME + ")", + " -d turn on debugging", " -f color foreground color (default: green)", " -h print this help information", " -n name name of font to use (default: courier)", @@ -369,6 +377,11 @@ cf.close() + # Dump tables if we're debugging + if DEBUG: + print "SYMBOL TABLE: ", UI.SymTable + print "COMMAND TABLE: ", UI.CmdTable + # End of 'ParseConfFile()' @@ -424,7 +437,7 @@ else: cmdkey = fields[0] cmdname = fields[1] - cmd = line.split(fields[1])[1] + cmd = line.split(fields[1])[1].strip() # Evaluate the command line, replacing # variables as needed @@ -775,29 +788,34 @@ def KeystrokeHandler(event): - # If the key pressed is a command key, - # get its associated string and - # execute the command. + # If the key pressed is a command key (i.e., it is in the table of + # defined commands), get its associated string and execute the command. - cmd = UI.rcfile.get(event.char, ["",""])[1] + cmd = UI.CmdTable.get(event.char, ["", "", ""])[1] + # cmd == null means no matching command key - do nothing # Otherwise, replace config tokens with actual file/dir names if cmd: - # Replace runtime-determined tokens - cmd = cmd.replace(FILE, UI.LastInSelection()) + cmd = cmd.replace(SELECTION, UI.LastInSelection()) fstring = "" for selected in UI.AllSelection(): fstring += selected + " " - cmd = cmd.replace(FILES, fstring) - cmd = cmd.replace(DIRNAME, UI.CurrentDir) + cmd = cmd.replace(SELECTIONS, fstring) + cmd = cmd.replace(DIR, UI.CurrentDir) - # Actually execute the command - thread.start_new_thread(os.system, (cmd,)) + # Just dump command if we're debugging + + if DEBUG: + print cmd + + # Otherwise,actually execute the command + else: + thread.start_new_thread(os.system, (cmd,)) # end of 'KeystrokeHandler()' @@ -1421,7 +1439,7 @@ # Command line processing try: - opts, args = getopt.getopt(sys.argv[1:], '-b:c:f:hn:qrs:vw:x:y:') + opts, args = getopt.getopt(sys.argv[1:], '-b:c:df:hn:qrs:vw:x:y:') except getopt.GetoptError: Usage() sys.exit(1) @@ -1433,6 +1451,8 @@ BCOLOR = val if opt == "-c": CONF = val + if opt == "-d": + DEBUG = TRUE if opt == "-f": FCOLOR = val if opt == "-h":