zsh-users
 help / color / mirror / code / Atom feed
* how to either ignore or deal with Icon$'\r' files on macOS
@ 2019-06-21  0:04 TJ Luoma
  2019-06-21  1:26 ` Ray Andrews
  2019-06-21  1:38 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: TJ Luoma @ 2019-06-21  0:04 UTC (permalink / raw)
  To: zsh-users

I never thought I'd hate anything more than the .DS_Store files that
macOS makes, but it turns out there's something much worse:

Icon$'\r'

These are some kind of file that is uses to give a special icon to a
folder when viewed in the Finder, but the files themselves aren't
visible in Finder (why they didn't make them '.icon' files, I have no
idea).

Most of the time I can just ignore them, but I've run into one folder
where I need to be able to do something like

for i in *
do
      whatever
done

but I do NOT want to do whatever if "$i" is one of these stupid Icon$'\r' files.

The problem is that I can't figure out how to match it.

for i in *
do
    if [ "$i" != "Icon$'\r'" ]
    then
        echo "$i"
    fi
done

doesn't work. It will echo "Icon" without the last character(s).

I don't even know what to try to match, because it shows up as that
weird "$'\r'" thing, but not if I do `ls`

% /bin/ls -l Icon$'\r'
-rw-rw-rw-@ 1 luomat  staff  0 Jun 20 18:42 Icon?

and if I run `ls` through `cat -v` I get this:

%  /bin/ls -l | fgrep -i icon | cat -v
-rw-rw-rw-@ 1 luomat  staff          0 Jun 20 18:42 Icon^M

I don't even know how to `rm` it reliably and safely, and macOS will
just re-generate it anyway, so it felt like it was time to figure out
how to properly ignore it.

Any suggestions welcome.

Tj

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

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

* Re: how to either ignore or deal with Icon$'\r' files on macOS
  2019-06-21  0:04 how to either ignore or deal with Icon$'\r' files on macOS TJ Luoma
@ 2019-06-21  1:26 ` Ray Andrews
  2019-06-21  1:38 ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Ray Andrews @ 2019-06-21  1:26 UTC (permalink / raw)
  To: zsh-users

On 2019-06-20 5:04 p.m., TJ Luoma wrote:
> I never thought I'd hate anything more than the .DS_Store files that
> macOS makes, but it turns out there's something much worse:
>
> Icon$'\r'

God's wrath upon those who use weird filenames.  Sorry, just had to say.



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

* Re: how to either ignore or deal with Icon$'\r' files on macOS
  2019-06-21  0:04 how to either ignore or deal with Icon$'\r' files on macOS TJ Luoma
  2019-06-21  1:26 ` Ray Andrews
@ 2019-06-21  1:38 ` Bart Schaefer
  2019-06-21  8:20   ` Roman Perepelitsa
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2019-06-21  1:38 UTC (permalink / raw)
  To: TJ Luoma; +Cc: Zsh Users

On Thu, Jun 20, 2019 at 5:06 PM TJ Luoma <luomat@gmail.com> wrote:
>
> Icon$'\r'

So, $'\r' is zsh's representation of a carriage return character.
It's very strange that anything would deliberately be using
carriage-return in a file name, but ...

> for i in *
> do
>     if [ "$i" != "Icon$'\r'" ]
>     then
>         echo "$i"
>     fi
> done

$'\r' is already a form of quoting,  just *don't* put it in double-quotes:

for i in *
do
    if [[ "$i" != Icon$'\r' ]]
    then
        # whatever
    fi
done

You should know better by now than to expect echo to faithfully
reproduce things on its output, it does way too much interpretation of
the argument strings.  In this case, however, the trailing
carriage-return is already "invisible" and echo isn't going to do
anything to make it appear.

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

* Re: how to either ignore or deal with Icon$'\r' files on macOS
  2019-06-21  1:38 ` Bart Schaefer
@ 2019-06-21  8:20   ` Roman Perepelitsa
  0 siblings, 0 replies; 4+ messages in thread
From: Roman Perepelitsa @ 2019-06-21  8:20 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: TJ Luoma, Zsh Users

I'll add to Bart's reply that you can print strings with unprintable
characters like this:

    print -r -- ${(q)i}

The printed string round-trips, meaning that you can copy it into your
code for the purpose of comparison via == and the like. For the icon
files you'd get Icon$'\r'.

For strings with many unprintable characters it may be more convenient
to use ${(qqqq)i}. It puts the whole string inside a single $'...', as
in $'Icon\r'.

Roman.

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-21  0:04 how to either ignore or deal with Icon$'\r' files on macOS TJ Luoma
2019-06-21  1:26 ` Ray Andrews
2019-06-21  1:38 ` Bart Schaefer
2019-06-21  8:20   ` Roman Perepelitsa

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).