0

I've been struggling with an issue that I cannot find mentioned anywhere and I cannot trace down. I can't leverage any of the alias command functionality in fish, which also breaks fish integrations that rely on that command (like zoxide init fish). I can manually define aliases fine (they're just functions after all), but commands like alias ls "ls -lah" don't work.

My suspicion is that somehow it's prefering to interpret alias as the macOS executable rather than the fish built-in:

> alias foo="echo foo"
> foo
fish: Unknown command: foo
> type -a alias
alias is /usr/bin/alias
> alias --help
/usr/bin/alias: line 4: alias: --: invalid option
alias: usage: alias [-p] [name[=value] ... ]

I have many fish aliases defined manually in my configs and they work, just the alias built-in itself seems to be broken.

Follow-up

Some requested additional details that don't fit in a comment:

> fish --version
fish, version 3.7.0
> set -S fish_function_path
$fish_function_path: set in global scope, unexported, with 6 elements
$fish_function_path[1]: |/Users/<REDACTED>/.config/fish/functions|
$fish_function_path[2]: |/opt/homebrew/etc/fish/functions|
$fish_function_path[3]: |/Users/<REDACTED>/.local/share/fish/vendor_functions.d|
$fish_function_path[4]: |/opt/homebrew/Cellar/fish/3.7.0/share/fish/vendor_functions.d|
$fish_function_path[5]: |/opt/homebrew/share/fish/vendor_functions.d|
$fish_function_path[6]: |/opt/homebrew/Cellar/fish/3.7.0/share/fish/functions|
2
  • alias is defined as a function in fish. What is your fish version? What is the contents of $fish_function_path -- set -S fish_function_path Commented Mar 5 at 5:25
  • @glennjackman thank you for this, this got me some headway - I edited the question to include the output, and also started grepping those paths to find where alias is defined, and found that if I explicitly source /opt/homebrew/Cellar/fish/3.7.0/share/fish/functions/alias.fish then the alias command works normally in that session. Any idea why that would be necessary when that file is already in the search path?
    – Adrian
    Commented Mar 5 at 14:56

2 Answers 2

-1

I would simply use abbr instead:

abbr -a ls ls -lah

Abbreviations are better for multiple reasons:

  • if you overwrite a basic command like ls, they let you skip the auto-expansion at times, if needed. It's not unikely to encounter such situations and you won't have to temporarily remove the alias if they occur.
  • they work much better with autocompletions
  • they save the original expanded command in the history. Which could be a slight disadvantage if it's your own machine and you prefer to save aliases instead to e.g. remember them. But otherwise, if working with multiple people especially, saving the original commands makes debugging easier.
1
  • This does not solve the problem for third party scripts which (rightly) assume that alias works, such as zoxide init fish which was mentioned in the question.
    – Adrian
    Commented Mar 4 at 17:54
-1

It turns out the issue was with function auto-loading - I had a file ~/.config/fish/functions/alias.fish with some aliases in it, but this caused fish not to read the main definition at /opt/homebrew/Cellar/fish/3.7.0/share/fish/functions/alias.fish because fish explicitly looks for the first file whose name matches the function name. Renaming the file solved the issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .