List some or all aliases as 'alias create' commands.
(self, args: argparse.Namespace)
| 3883 | |
| 3884 | @as_subcommand_to("alias", "list", _build_alias_list_parser, help="list aliases") |
| 3885 | def _alias_list(self, args: argparse.Namespace) -> None: |
| 3886 | """List some or all aliases as 'alias create' commands.""" |
| 3887 | self.last_result = {} # dict[alias_name, alias_value] |
| 3888 | |
| 3889 | tokens_to_quote = (*constants.REDIRECTION_TOKENS, *self.statement_parser.terminators) |
| 3890 | |
| 3891 | to_list = ( |
| 3892 | utils.remove_duplicates(args.names) |
| 3893 | if args.names |
| 3894 | else sorted( |
| 3895 | self.aliases, |
| 3896 | key=utils.DEFAULT_STR_SORT_KEY, |
| 3897 | ) |
| 3898 | ) |
| 3899 | |
| 3900 | not_found: list[str] = [] |
| 3901 | for name in to_list: |
| 3902 | if name not in self.aliases: |
| 3903 | not_found.append(name) |
| 3904 | continue |
| 3905 | |
| 3906 | # Quote redirection and terminator tokens for the 'alias create' command |
| 3907 | tokens = shlex_split(self.aliases[name]) |
| 3908 | command = tokens[0] |
| 3909 | command_args = tokens[1:] |
| 3910 | utils.quote_specific_tokens(command_args, tokens_to_quote) |
| 3911 | |
| 3912 | val = command |
| 3913 | if command_args: |
| 3914 | val += " " + " ".join(command_args) |
| 3915 | |
| 3916 | self.poutput(f"alias create {name} {val}") |
| 3917 | self.last_result[name] = val |
| 3918 | |
| 3919 | for name in not_found: |
| 3920 | self.perror(f"Alias '{name}' not found") |
| 3921 | |
| 3922 | ############################################################# |
| 3923 | # Parsers and functions for macro command and subcommands |
nothing calls this directly
no test coverage detected