-
-
Notifications
You must be signed in to change notification settings - Fork 772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for alias commands #1354
Comments
True, but only from within a shell, there is no $ type alias
alias is a shell builtin
$ command alias
zsh: command not found: alias
$ zsh -c alias # You have to invoke the shell to run the builtin
run-help=man
which-command=whence
$ zsh -ic alias # -i (interactive) is probably necessary to read the .*shrc that defines your aliases
ll='command ls -l --color=auto -v'
... So $ fd png -x ll
[fd error]: Command not found: ll
$ fd png -x zsh -ic 'll "$1"' zsh
-rw-r----- 1 tavianator tavianator 10183 Oct 10 2022 ./doc/logo.png Running an interactive shell is expensive so you probably want to use $ fd md -X zsh -ic 'll "$@"' zsh
-rw-r----- 1 tavianator tavianator 26976 May 3 08:54 ./CHANGELOG.md
-rw-r----- 1 tavianator tavianator 1639 May 3 08:54 ./CONTRIBUTING.md
-rw-r----- 1 tavianator tavianator 25176 May 3 08:54 ./README.md
-rw-r----- 1 tavianator tavianator 2543 Nov 25 2022 ./doc/release-checklist.md |
Thank you for your advice on how to use aliases in the current version of
To my understanding, the |
The bigger problem is that fd would have to know how to list the aliases for various shells (it is different for different shells) and how to parse the format of the output, which is again different for different shells. And then there are the aliases themselves. Different shells have different syntax for quoting/escaping that fd would have to understand. And what about aliases that use more complicated syntax? And we probably don't want to start an interactive terminal every time fd runs to parse aliases. Perhaps a better option would be to have separate options for using am interactive shell to run the command. But even then, I don't think it is worth the effort, since there is a workaround. Maybe we should just add more documentation about it? FWIW, fd is not unique in having this problem. Aliases also don't work with sudo, xargs, find, parallel, doas, etc. I don't know of any other program that does parse aliases like this. |
For the record I really don't think |
I like that idea 👍 |
I created an issue for an --exec-shell option in #1406 I'm going to close this in favor of that, unless someone comments otherwise. |
Issue Description
I would like to propose adding support for alias commands in fd. Alias commands would allow users to define and use custom shortcuts for commonly used search patterns or command-line options without having to retype them each time. Unfortunately, an error occurs stating
Command not found
when attempting to type a command such asfd -x ll
.Proposed Solution
Alias commands can be obtained by executing the
alias
command. Here is an illustrative example output retrieved from my MacBook:Although the alias can be complex, allowing the aliasing of multiple commands and even incorporating some shell features, the commonly used cases are often quite simple. These involve setting default options or command substitutions, such as
ll='ls -l'
orcat='bat'
.The most straightforward approach would be to utilize a hashmap data structure to create a mapping for aliases, thereby storing the aliases for simple cases. When a user enters a command, the program would first check the hashmap for a matching command. If a match is found, it would construct the corresponding
Command
and its associatedargs
, and then execute it accordingly.I believe that adding alias support to
fd
would greatly enhance its usability and provide a more refined and enhanced experience for users. Thank you for considering this feature request.The text was updated successfully, but these errors were encountered: