diff --git a/twander.py b/twander.py index 5bb40c8..c33869a 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ # For Updates See: http://www.tundraware.com/Software/twander PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.95 2002/12/10 02:47:31 tundra Exp $" +RCSID = "$Id: twander.py,v 1.96 2002/12/11 21:54:54 tundra Exp $" VERSION = RCSID.split()[2] @@ -204,13 +204,13 @@ ##### -ASSIGN = "=" # Assignment for variable definitions -CONF = "" # Config file user selected with -c option -COMMENT = r"#" # Comment character -ENVVBL = r'$' # Symbol denoting an environment variable -MAXNESTING = 32 # Maximum depth of nested variable definitions -QUOTECHAR = '\"' # Character to use when quoting builtin substitutions -reVAR = r"\[.*?\]" # Regex describing variable notation +ASSIGN = "=" # Assignment for variable definitions +CONF = "" # Config file user selected with -c option +COMMENT = r"#" # Comment character +ENVVBL = r'$' # Symbol denoting an environment variable +MAXNESTING = 32 # Maximum depth of nested variable definitions +QUOTECHAR = '\"' # Character to use when quoting builtin substitutions +reVAR = r"\[.+?\]" # Regex describing variable notation # Builtins @@ -218,7 +218,7 @@ DIR = r'[DIR]' DSELECTION = r'[DSELECTION]' DSELECTIONS = r'[DSELECTIONS]' -PROMPT = r'[PROMPT]' +PROMPT = r'[PROMPT:' SELECTION = r'[SELECTION]' SELECTIONS = r'[SELECTIONS]' @@ -468,8 +468,14 @@ # which we are changing during the iteration. for x in vbls[:]: - vbl = x[1:-1] - if UI.BuiltIns.has_key(vbl): + + # Ignore references to builtins here - They are + # processed at runtime. + + if UI.BuiltIns.has_key(x): + vbls.remove(x) + + elif x.startswith(PROMPT): vbls.remove(x) if vbls: @@ -802,7 +808,8 @@ # 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.CmdTable.get(event.char, ["", "", ""])[1] + cmd = UI.CmdTable.get(event.char, ["", "", ""])[1] + name = UI.CmdTable.get(event.char, ["", "", ""])[0] # cmd == null means no matching command key - do nothing @@ -811,12 +818,31 @@ if cmd: # Replace runtime-determined tokens + # First do any prompting required + + for x in range(cmd.count(PROMPT)): + b = cmd.find(PROMPT) + e = cmd.find("]", b) + prompt = cmd[b + len(PROMPT):e] + val = askstring(name, prompt) + + # Make sure our program gets focus back + UI.DirList.focus() + + if val: + cmd = cmd.replace(cmd[b:e+1], val) + + # Null input means the command is being aborted + else: + return + + # Now do files & directories + selection = UI.LastInSelection() selections = "" dselections = "" for selected in UI.AllSelection(): - dselections += QUOTECHAR + UI.CurrentDir + selected + QUOTECHAR + " " cmd = cmd.replace(DIR, QUOTECHAR + UI.CurrentDir + QUOTECHAR) @@ -861,7 +887,7 @@ thread.start_new_thread(os.system, (cmd,)) UI.DirList.focus() -# End of 'ChangeDir()' +# End of 'KeyRunCommand()' ##### @@ -1164,6 +1190,9 @@ for x in contents: UI.DirList.insert(END, x) + # Also move the program context to the new directory + os.chdir(newdir) + # And update the title to reflect changes UI.UpdateTitle(UIroot) @@ -1532,8 +1561,8 @@ STARTDIR = os.path.abspath(STARTDIR) # Setup builtin variables -UI.BuiltIns = {"DIR":"", "SELECTION":"", "SELECTIONS":"", "DSELECTION":"", - "DSELECTIONS":"", "PROMPT:":""} +UI.BuiltIns = {DIR:"", SELECTION:"", SELECTIONS:"", DSELECTION:"", + DSELECTIONS:"", PROMPT:""} # Parse the and store configuration file, if any ParseConfFile(None)