List macros.
(self, args: argparse.Namespace)
| 4171 | |
| 4172 | @as_subcommand_to("macro", "list", _build_macro_list_parser, help="list macros") |
| 4173 | def _macro_list(self, args: argparse.Namespace) -> None: |
| 4174 | """List macros.""" |
| 4175 | self.last_result = {} # dict[macro_name, macro_value] |
| 4176 | |
| 4177 | tokens_to_quote = (*constants.REDIRECTION_TOKENS, *self.statement_parser.terminators) |
| 4178 | |
| 4179 | to_list = ( |
| 4180 | utils.remove_duplicates(args.names) |
| 4181 | if args.names |
| 4182 | else sorted( |
| 4183 | self.macros, |
| 4184 | key=utils.DEFAULT_STR_SORT_KEY, |
| 4185 | ) |
| 4186 | ) |
| 4187 | |
| 4188 | not_found: list[str] = [] |
| 4189 | for name in to_list: |
| 4190 | if name not in self.macros: |
| 4191 | not_found.append(name) |
| 4192 | continue |
| 4193 | |
| 4194 | # Quote redirection and terminator tokens for the 'macro create' command |
| 4195 | tokens = shlex_split(self.macros[name].value) |
| 4196 | command = tokens[0] |
| 4197 | command_args = tokens[1:] |
| 4198 | utils.quote_specific_tokens(command_args, tokens_to_quote) |
| 4199 | |
| 4200 | val = command |
| 4201 | if command_args: |
| 4202 | val += " " + " ".join(command_args) |
| 4203 | |
| 4204 | self.poutput(f"macro create {name} {val}") |
| 4205 | self.last_result[name] = val |
| 4206 | |
| 4207 | for name in not_found: |
| 4208 | self.perror(f"Macro '{name}' not found") |
| 4209 | |
| 4210 | def complete_help_command(self, text: str, line: str, begidx: int, endidx: int) -> Completions: |
| 4211 | """Completes the command argument of help.""" |
nothing calls this directly
no test coverage detected