Skip to main content
added 1274 characters in body
Source Link
toppk
  • 687
  • 3
  • 6

I am really surprised by that other post you mentioned, as it can be very misleading. Just because an alias doesn't use parameters doesn't mean that aliases cannot set parameters. Of course you can put options in an alias, but it is just restricted, meaning, the alias is replaced in one place.

$ alias ls='ls -l'
$ ls 
# will run: ls -l
$ ls foo
# will run: ls -l foo

The problem that other question poses is if you want to add options to a alias that has a argument.

so if you had an alias:

$ alias movetotrash='mv  ~/Trash'
# no way to use inject anything inside 'mv' and '~/Trash'

So in your case

$ alias locate='locate -i -A'
# will expand to 'locate -i -A' and then whatever else you type.

As for your specific questions:

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'. So it can be considered a standard way of providing better defaults to users and uses the same name of the underlying binary. If a user doesn't want to use an alias and it is set in the standard environment, they can use unalias to unset the alias permanently, or when running a command using a backslash, such as \mv a b will prevent alias expansion for that execution (as does using the full path, like /usr/bin/mv a b)

I don't believe that zsh provides any extra capabilities in this area, and certainly nothing that would be a "standard". People often write wrapper shell scripts and sometimes shell functions. But for trivial software, alias is often the solution people use. If the program is complicated enough, it will usually gain an rc file for common user preferences.

I think one tool that tried to make options a bit easier was the popt library, which allowed users to create their own options to software, but the popt library isn't widely used, and I don't think it had the ability to set the default.

I am really surprised by that other post you mentioned, as it can be very misleading. Just because an alias doesn't use parameters doesn't mean that aliases cannot set parameters. Of course you can put options in an alias, but it is just restricted, meaning, the alias is replaced in one place.

$ alias ls='ls -l'
$ ls 
# will run: ls -l
$ ls foo
# will run: ls -l foo

The problem that other question poses is if you want to add options to a alias that has a argument.

so if you had an alias:

$ alias movetotrash='mv  ~/Trash'
# no way to use inject anything inside 'mv' and '~/Trash'

So in your case

$ alias locate='locate -i -A'
# will expand to 'locate -i -A' and then whatever else you type.

I am really surprised by that other post you mentioned, as it can be very misleading. Just because an alias doesn't use parameters doesn't mean that aliases cannot set parameters. Of course you can put options in an alias, but it is just restricted, meaning, the alias is replaced in one place.

$ alias ls='ls -l'
$ ls 
# will run: ls -l
$ ls foo
# will run: ls -l foo

The problem that other question poses is if you want to add options to a alias that has a argument.

so if you had an alias:

$ alias movetotrash='mv  ~/Trash'
# no way to use inject anything inside 'mv' and '~/Trash'

So in your case

$ alias locate='locate -i -A'
# will expand to 'locate -i -A' and then whatever else you type.

As for your specific questions:

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'. So it can be considered a standard way of providing better defaults to users and uses the same name of the underlying binary. If a user doesn't want to use an alias and it is set in the standard environment, they can use unalias to unset the alias permanently, or when running a command using a backslash, such as \mv a b will prevent alias expansion for that execution (as does using the full path, like /usr/bin/mv a b)

I don't believe that zsh provides any extra capabilities in this area, and certainly nothing that would be a "standard". People often write wrapper shell scripts and sometimes shell functions. But for trivial software, alias is often the solution people use. If the program is complicated enough, it will usually gain an rc file for common user preferences.

I think one tool that tried to make options a bit easier was the popt library, which allowed users to create their own options to software, but the popt library isn't widely used, and I don't think it had the ability to set the default.

added 131 characters in body
Source Link
toppk
  • 687
  • 3
  • 6

I am really surprised by that other post you mentioned, as it can be very misleading. Just because an alias doesn't use parameters doesn't mean that aliases cannot set parameters. Of course you can put options in an alias, but it is just restricted, meaning, the alias is replaced in one place.

$ alias ls='ls -l'
$ ls 
# will run: ls -l
$ ls foo
# will run: ls -l foo

The problem that other question poses is if you want to add options to a alias that has a argument.

so if you had an alias:

$ alias movetotrash='mv  ~/Trash'
# no way to use inject anything inside 'mv' and '~/Trash'

So in your case

$ alias locate='locate -i -A'
# will expand to 'locate -i -A' and then whatever else you type.

I am really surprised by that other post you mentioned. Of course you can put options in an alias, but it is just restricted, meaning, the alias is replaced in one place.

$ alias ls='ls -l'
$ ls 
# will run: ls -l
$ ls foo
# will run: ls -l foo

The problem that other question poses is if you want to add options to a alias that has a argument.

so if you had an alias:

$ alias movetotrash='mv  ~/Trash'
# no way to use inject anything inside 'mv' and '~/Trash'

So in your case

$ alias locate='locate -i -A'
# will expand to 'locate -i -A' and then whatever else you type.

I am really surprised by that other post you mentioned, as it can be very misleading. Just because an alias doesn't use parameters doesn't mean that aliases cannot set parameters. Of course you can put options in an alias, but it is just restricted, meaning, the alias is replaced in one place.

$ alias ls='ls -l'
$ ls 
# will run: ls -l
$ ls foo
# will run: ls -l foo

The problem that other question poses is if you want to add options to a alias that has a argument.

so if you had an alias:

$ alias movetotrash='mv  ~/Trash'
# no way to use inject anything inside 'mv' and '~/Trash'

So in your case

$ alias locate='locate -i -A'
# will expand to 'locate -i -A' and then whatever else you type.
Source Link
toppk
  • 687
  • 3
  • 6

I am really surprised by that other post you mentioned. Of course you can put options in an alias, but it is just restricted, meaning, the alias is replaced in one place.

$ alias ls='ls -l'
$ ls 
# will run: ls -l
$ ls foo
# will run: ls -l foo

The problem that other question poses is if you want to add options to a alias that has a argument.

so if you had an alias:

$ alias movetotrash='mv  ~/Trash'
# no way to use inject anything inside 'mv' and '~/Trash'

So in your case

$ alias locate='locate -i -A'
# will expand to 'locate -i -A' and then whatever else you type.