zsh-users
 help / color / mirror / code / Atom feed
* suffix alias where the app has a space in it
@ 2019-08-08 11:14 ` TJ Luoma
  2019-08-08 11:47   ` Peter Stephenson
  2019-08-08 11:50   ` Stephane Chazelas
  0 siblings, 2 replies; 6+ messages in thread
From: TJ Luoma @ 2019-08-08 11:14 UTC (permalink / raw)
  To: Zsh MailingList

I'm trying to use suffix aliases, but I ran into one issue I can't
figure out: What do I do when I want to assign "The Unarchiver" as an
app for archives such as .xz

alias -s  xz="the unarchiver"

But that tries to use 'the' to open 'xz' files.

Is there a way to encode a space in the app name?

I tried googling but either the terms are too vague or no one has
written about this before.

Thanks!

TjL


p.s. - https://macpaw.com/the-unarchiver for anyone using a Mac who
isn't familiar with the app

--
TJ Luoma
TJ @ MacStories
Personal Website: luo.ma (aka RhymesWithDiploma.com)
Twitter: @tjluoma

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: suffix alias where the app has a space in it
  2019-08-08 11:14 ` suffix alias where the app has a space in it TJ Luoma
@ 2019-08-08 11:47   ` Peter Stephenson
  2019-08-08 12:09     ` TJ Luoma
  2019-08-08 11:50   ` Stephane Chazelas
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2019-08-08 11:47 UTC (permalink / raw)
  To: zsh-users

On Thu, 2019-08-08 at 07:14 -0400, TJ Luoma wrote:
> I'm trying to use suffix aliases, but I ran into one issue I can't
> figure out: What do I do when I want to assign "The Unarchiver" as an
> app for archives such as .xz
> 
> alias -s  xz="the unarchiver"
> 
> But that tries to use 'the' to open 'xz' files.
> 
> Is there a way to encode a space in the app name?

The thing to remember about aliases is they are expanded very early in
the shell processing --- basically, replacement text is just dumped in
as a raw string where it'll be picked up exactly as is.  So simply
adding a backslash works.

alias -s xz='the\ unarchiver'

pws




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: suffix alias where the app has a space in it
  2019-08-08 11:14 ` suffix alias where the app has a space in it TJ Luoma
  2019-08-08 11:47   ` Peter Stephenson
@ 2019-08-08 11:50   ` Stephane Chazelas
  1 sibling, 0 replies; 6+ messages in thread
From: Stephane Chazelas @ 2019-08-08 11:50 UTC (permalink / raw)
  To: TJ Luoma; +Cc: Zsh MailingList

2019-08-08 07:14:21 -0400, TJ Luoma:
> I'm trying to use suffix aliases, but I ran into one issue I can't
> figure out: What do I do when I want to assign "The Unarchiver" as an
> app for archives such as .xz
> 
> alias -s  xz="the unarchiver"
> 
> But that tries to use 'the' to open 'xz' files.
> 
> Is there a way to encode a space in the app name?
> 
> I tried googling but either the terms are too vague or no one has
> written about this before.
[...]

alias replacement is token replacement before parsing of the
syntax. That applies to suffix aliases as well. You can even do
something as crazy as:

alias -s xz='for cmd (echo "the unarchiver") $cmd'

And when you enter:

foo.xz

that gets replaced with 

for cmd (echo "the unarchiver") $cmd foo.xz

In your case, just do:

alias -s "xz='the unarchiver'"

-- 
Stephane

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: suffix alias where the app has a space in it
  2019-08-08 11:47   ` Peter Stephenson
@ 2019-08-08 12:09     ` TJ Luoma
  2019-08-08 17:40       ` TJ Luoma
  0 siblings, 1 reply; 6+ messages in thread
From: TJ Luoma @ 2019-08-08 12:09 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh MailingList

Thanks to you (and Stephane) for explaining this. It seems obvious now
that you've explained it.

Cheers,

Tj

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: suffix alias where the app has a space in it
  2019-08-08 12:09     ` TJ Luoma
@ 2019-08-08 17:40       ` TJ Luoma
  2019-08-08 21:30         ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: TJ Luoma @ 2019-08-08 17:40 UTC (permalink / raw)
  To: Zsh MailingList

Related Question: is there a way to set a default command to use for
all suffixes, and then make additional aliases for other suffixes?

Something like this:

alias -s '*'='open'

or

alias -s \*='open'

and then

alias -s txt='pico'

would override the original.

I tried the first two but neither seemed to work, but there may be a
way that I'm overlooking.

Tj

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: suffix alias where the app has a space in it
  2019-08-08 17:40       ` TJ Luoma
@ 2019-08-08 21:30         ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2019-08-08 21:30 UTC (permalink / raw)
  To: TJ Luoma; +Cc: Zsh MailingList

On Thu, Aug 8, 2019 at 1:18 PM TJ Luoma <luomat@gmail.com> wrote:
>
> Related Question: is there a way to set a default command to use for
> all suffixes, and then make additional aliases for other suffixes?

Not with alias.  You could try a command-not-found handler.

> Something like this:
>
> alias -s '*'='open'

What that means is that if you type

% foo.*

then "open foo.*" will be executed.  It does NOT mean that the alias
will be invoked when you type

% foo.bar

Aliases do not do pattern matching.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-08-08 21:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20190808111626epcas1p28034457322a4f06a363aed6763a5b859@epcas1p2.samsung.com>
2019-08-08 11:14 ` suffix alias where the app has a space in it TJ Luoma
2019-08-08 11:47   ` Peter Stephenson
2019-08-08 12:09     ` TJ Luoma
2019-08-08 17:40       ` TJ Luoma
2019-08-08 21:30         ` Bart Schaefer
2019-08-08 11:50   ` Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).