Subject: bug#70198: M-x shell: deal with environment variables present when tab expanding

From: Eli Zaretskii <[email-masked]>
Date: Wed, 10 Jul 2024 20:45:11 +0300

> Cc: [email-masked]
> Date: Wed, 10 Jul 2024 18:22:35 +0200
> From:  Federico Tedin via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> +	         (save-match-data (not (string-match "[~/]" filename)))
> +	         (eq (match-beginning 0)
> +		         (save-excursion
> +                   ;; Go back to beginning of command
> +                   (shell-backward-command 1)
> +                   ;; Skip any potential environment variables
> +                   (shell--skip-environment-variables pt)
> +                   (point))))
> +	    (shell--command-completion-data))))
> +
> +(defun shell--skip-environment-variables (pt)
> +  "Move forward up to PT through any present environment variables."
> +  (while (re-search-forward "=" pt t)
> +    (skip-syntax-forward "^ " pt)
> +    (skip-syntax-forward " " pt)))

What happens if the command itself has embedded '='?
What happens if the '=' character is quoted?

I think a better idea might be first to try to find what is "the word
at point", and then complete only that word.  WDYT?