Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Possibly dumb question... Constructing PATH



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