@@ -2062,7 +2062,7 @@ def _perform_completion(
2062
2062
if custom_settings is None :
2063
2063
# Check if a macro was entered
2064
2064
if command in self .macros :
2065
- completer_func = self .path_complete
2065
+ completer_func = self .macro_arg_complete
2066
2066
2067
2067
# Check if a command was entered
2068
2068
elif command in self .get_all_commands ():
@@ -3542,6 +3542,27 @@ def _alias_list(self, args: argparse.Namespace) -> None:
3542
3542
# Parsers and functions for macro command and subcommands
3543
3543
#############################################################
3544
3544
3545
+ def macro_arg_complete (
3546
+ self ,
3547
+ text : str ,
3548
+ line : str ,
3549
+ begidx : int ,
3550
+ endidx : int ,
3551
+ ) -> list [str ]:
3552
+ """Tab completes arguments to a macro.
3553
+
3554
+ Its default behavior is to call path_complete, but you can override this as needed.
3555
+
3556
+ The args required by this function are defined in the header of Python's cmd.py.
3557
+
3558
+ :param text: the string prefix we are attempting to match (all matches must begin with it)
3559
+ :param line: the current input line with leading whitespace removed
3560
+ :param begidx: the beginning index of the prefix text
3561
+ :param endidx: the ending index of the prefix text
3562
+ :return: a list of possible tab completions
3563
+ """
3564
+ return self .path_complete (text , line , begidx , endidx )
3565
+
3545
3566
# Top-level parser for macro
3546
3567
@staticmethod
3547
3568
def _build_macro_parser () -> Cmd2ArgumentParser :
@@ -3579,11 +3600,11 @@ def _build_macro_create_parser(cls) -> Cmd2ArgumentParser:
3579
3600
"\n " ,
3580
3601
"The following creates a macro called my_macro that expects two arguments:" ,
3581
3602
"\n " ,
3582
- " macro create my_macro make_dinner --meat {1} --veggie {2}" ,
3603
+ " macro create my_macro make_dinner --meat {1} --veggie {2}" ,
3583
3604
"\n " ,
3584
3605
"When the macro is called, the provided arguments are resolved and the assembled command is run. For example:" ,
3585
3606
"\n " ,
3586
- " my_macro beef broccoli ---> make_dinner --meat beef --veggie broccoli" ,
3607
+ " my_macro beef broccoli ---> make_dinner --meat beef --veggie broccoli" ,
3587
3608
)
3588
3609
macro_create_parser = argparse_custom .DEFAULT_ARGUMENT_PARSER (description = macro_create_description )
3589
3610
@@ -3598,19 +3619,19 @@ def _build_macro_create_parser(cls) -> Cmd2ArgumentParser:
3598
3619
"first argument will populate both {1} instances."
3599
3620
),
3600
3621
"\n " ,
3601
- " macro create ft file_taxes -p {1} -q {2} -r {1}" ,
3622
+ " macro create ft file_taxes -p {1} -q {2} -r {1}" ,
3602
3623
"\n " ,
3603
3624
"To quote an argument in the resolved command, quote it during creation." ,
3604
3625
"\n " ,
3605
- " macro create backup !cp \" {1}\" \" {1}.orig\" " ,
3626
+ " macro create backup !cp \" {1}\" \" {1}.orig\" " ,
3606
3627
"\n " ,
3607
3628
"If you want to use redirection, pipes, or terminators in the value of the macro, then quote them." ,
3608
3629
"\n " ,
3609
- " macro create show_results print_results -type {1} \" |\" less" ,
3630
+ " macro create show_results print_results -type {1} \" |\" less" ,
3610
3631
"\n " ,
3611
3632
(
3612
- "Because macros do not resolve until after hitting Enter, tab completion "
3613
- "will only complete paths while typing a macro."
3633
+ "Since macros don't resolve until after you press Enter, their arguments tab complete as paths. "
3634
+ "This default behavior changes if custom tab completion for macro arguments has been implemented ."
3614
3635
),
3615
3636
)
3616
3637
macro_create_parser .epilog = macro_create_parser .create_text_group ("Notes" , macro_create_notes )
0 commit comments