7

In my emacs alias file located at .emacs.d/eshell/alias, I have the following:

alias mv mv -v $*

Whenever I execute the alias in eshell, for example: mv from_here.txt to_here.text, I get the error:

mv: missing destination file or directory

How can this alias issue be fixed? Thanks.

5

At first a comment on your alias. While the emacswiki-page suggests that alias mv 'mv -v $*' is right the corresponding official manual page says that you should use alias mv mv -v instead. In the following I assume that the manual page is right.

It looks like eshell-maybe-replace-by-alias is buggy (at least in emacs 25.2.1).

The current implementation is

(defun eshell-maybe-replace-by-alias (command args)
  "If COMMAND has an alias definition, call that instead using ARGS."
  (unless (and eshell-prevent-alias-expansion
           (member command eshell-prevent-alias-expansion))
    (let ((alias (eshell-lookup-alias command)))
      (if alias
      (throw 'eshell-replace-command
         `(let ((eshell-command-name ',eshell-last-command-name)
                        (eshell-command-arguments ',eshell-last-arguments)
                        (eshell-prevent-alias-expansion
                         ',(cons command eshell-prevent-alias-expansion)))
                    ,(eshell-parse-command (nth 1 alias))))))))

The throw form replaces the command to be executed. In eshell-parse-command the alias is replaced but the arguments are lost.

My eshell shows the expected alias behavior if I add args to eshell-parse-command via the following override:

(defun eshell-maybe-replace-by-alias-bugfix-25.2.1 (command args)
  "If COMMAND has an alias definition, call that instead using ARGS."
  (unless (and eshell-prevent-alias-expansion
           (member command eshell-prevent-alias-expansion))
    (let ((alias (eshell-lookup-alias command)))
      (if alias
      (throw 'eshell-replace-command
         `(let ((eshell-command-name ',eshell-last-command-name)
                        (eshell-command-arguments ',eshell-last-arguments)
                        (eshell-prevent-alias-expansion
                         ',(cons command eshell-prevent-alias-expansion)))
                    ,(eshell-parse-command (nth 1 alias) args)))))))

(advice-add #'eshell-maybe-replace-by-alias :override #'eshell-maybe-replace-by-alias-bugfix-25.2.1)

Note that I already sent a bug-report to bug-gnu-emacs@gnu.org.

Thanks for fixing this problem in the master branch of emacs goes to Noam Postavsky: http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=e66e81679c3c91d6bf8f62c7abcd968430b4d1fe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.