Create or overwrite an alias.
(self, args: argparse.Namespace)
| 3789 | |
| 3790 | @as_subcommand_to("alias", "create", _build_alias_create_parser, help="create or overwrite an alias") |
| 3791 | def _alias_create(self, args: argparse.Namespace) -> None: |
| 3792 | """Create or overwrite an alias.""" |
| 3793 | self.last_result = False |
| 3794 | |
| 3795 | # Validate the alias name |
| 3796 | valid, errmsg = self.statement_parser.is_valid_command(args.name) |
| 3797 | if not valid: |
| 3798 | self.perror(f"Invalid alias name: {errmsg}") |
| 3799 | return |
| 3800 | |
| 3801 | if args.name in self.get_all_commands(): |
| 3802 | self.perror("Alias cannot have the same name as a command") |
| 3803 | return |
| 3804 | |
| 3805 | if args.name in self.macros: |
| 3806 | self.perror("Alias cannot have the same name as a macro") |
| 3807 | return |
| 3808 | |
| 3809 | # Unquote redirection and terminator tokens |
| 3810 | tokens_to_unquote = (*constants.REDIRECTION_TOKENS, *self.statement_parser.terminators) |
| 3811 | utils.unquote_specific_tokens(args.command_args, tokens_to_unquote) |
| 3812 | |
| 3813 | # Build the alias value string |
| 3814 | value = args.command |
| 3815 | if args.command_args: |
| 3816 | value += " " + " ".join(args.command_args) |
| 3817 | |
| 3818 | # Set the alias |
| 3819 | result = "overwritten" if args.name in self.aliases else "created" |
| 3820 | self.poutput(f"Alias '{args.name}' {result}") |
| 3821 | |
| 3822 | self.aliases[args.name] = value |
| 3823 | self.last_result = True |
| 3824 | |
| 3825 | # alias -> delete |
| 3826 | @classmethod |
nothing calls this directly
no test coverage detected