knpwrs
knpwrs

Reputation: 16426

What does `(.N)` do in this extended glob?

The Prezto documentation has the following example script for setting up symlinks:

setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done

I understand everything in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N) up until (.N). What does (.N) mean here?

Bonus question, what is ${rcfile:t}? I understand that it resolves to the name of the rcfile but I don't know what the :t is for.

Upvotes: 3

Views: 683

Answers (2)

Montalvao
Montalvao

Reputation: 31

The glob (extended glob, actually) ^README.md(.N) expands to all files except README.md, or returns null (an empty string).

extended: Set by the setopt line. Needed for the ^ (see below).

files: The dot in (.N) stands for files (not directories nor links).

except README.md: The ^. Think of ^ inside brackets in a regex. That does not mean files beginning with README.md.

null: The N in (.N). It says the globbing to return a null string if the expansion fails. Otherwise that line would return an error if ${ZDOTDIR:-$HOME}"/.zprezto/runcoms/" had only the README.md file or no files at all.

Upvotes: 2

SergioAraujo
SergioAraujo

Reputation: 11790

The bellow piece denies or negates (.N) all content wich starts '^' with README.md ^README.md(.N)

The ^ symbol is a regular expression the means the beginning of something.

The ${rcfile:t} part allows only the name stripping the dir name of string. Therefore the loop will create a needed symlink for each configuration file of your zpresto dir.

Upvotes: 4

Related Questions