Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Possibly dumb question... Constructing PATH
- X-seq: zsh-users 14376
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Possibly dumb question... Constructing PATH
- Date: Mon, 14 Sep 2009 20:08:10 -0700
- In-reply-to: <d6d6637f0909141811q1fbf3f0fs3f3af6904d78d7b@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <d6d6637f0909141811q1fbf3f0fs3f3af6904d78d7b@xxxxxxxxxxxxxx>
On Sep 14, 9:11pm, Christopher Browne wrote:
} Subject: Possibly dumb question... Constructing PATH
}
} I'm redoing some of my .rc files, and was wondering if there's a
} common idiom for "add that path to PATH, if it's missing"?
}
} In my .emacs/init.el, I have this concept...
} (defun add-extra-path (raw-proposal)
} (let ((proposal (expand-file-name raw-proposal)))
} (if (not (member proposal load-path))
} (setq load-path (cons proposal load-path)))))
If you want to do this literally ...
let ((proposal (expand-file-name raw-proposal)))
is
local proposal=$~raw
(member proposal load-path)
is
$path[(er)$proposal]
or with extendedglob
${(M)path#$proposal(#e)}
(cons proposal load-path)
is
path=($proposal $path)
So, you get something like
function add-extra-path {
local proposal=$~1
[[ -z $path[(er)$proposal] ]] && path=($proposal $path)
}
However, as John E. has already pointed out, zsh has a built-in way
to perform this operation for you, namely "typeset -U path".
Messages sorted by:
Reverse Date,
Date,
Thread,
Author