It is quite common for linux distributions to ship with default "options" via aliases, for example, ls frequently has a alias ls 'ls -color=auto' or for root login you might see alias mv 'mv -i'. # will expand to 'locate -i -A' and then whatever else you type. So in your case $ alias locate='locate -i -A' # no way to use inject anything inside 'mv' and '~/Trash' So if you had an alias: $ alias movetotrash='mv ~/Trash' The problem that other question poses is if you want to add options to a alias that has a argument. Of course you can put options in an alias, but it is just restricted, meaning, the alias is replaced in one place. Just because an alias doesn't use parameters doesn't mean that aliases cannot set parameters. I am really surprised by that other post you mentioned, as it can be very misleading. Does zsh or some other tool provide a more direct way to default flags for a specific command?.Is it alright/idiomatic to override an existing command with an alias/function?.That brought me to another thought: is it an anti-pattern to override an existing command? I've always done it because it allows me to skip an association in my head: e.g., "Why doesn't ll have a man page? Oh yeah: ll really means ls -la. I was about to finally create such a function when I had this thought: this is a common pattern for me, wanting to default flags for command is there an easier way of going about it? Perhaps zsh provides a better solution to this problem? Usually I stop there because the idea of a function with the same name as a command feels wrong to me, though I can't say why. But according to this question, aliases can't accept arguments, so I have to use a function instead. Usually, if I can get away with it, I create an alias with the same name as the existing command to do this. Every time I use locate, I want to pass the -i and -A flags.
0 Comments
Leave a Reply. |