zsh-workers
 help / color / mirror / code / Atom feed
* managing PATH, MANPATH, LD_LIBRARY_PATH, etc.
@ 2015-01-28 18:06 Dave Yost
  2015-01-28 18:39 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Yost @ 2015-01-28 18:06 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 2222 bytes --]

AFAIK we have no choice in zsh but to tediously add things individually by hand to the various path environment variables. The Environment Modules System <https://en.wikipedia.org/wiki/Environment_Modules_(software)> for linux gives higher-level control, but it’s a whole ball of wax of its own. If I do this
	module load llvm/3.5.1
then the relevant directories from /usr/local/llvm/3.5.1 will be added to the front of PATH, LD_LIBRARY_PATH, LIBRARY_PATH, and CPATH, or whatever paths have been specified in the “modulefile” for llvm/3.5.1.

A zsh shell function could allow similarly convenient manipulation of paths, without buying into the whole Environment Modules thing.

Imagine a shell function called “paths”. Doing this:
	paths set /usr/local /usr /
wants to set PATH to this:
	/usr/local/bin
	/usr/local/sbin
	/usr/bin
	/usr/sbin
	/bin
	/sbin
and does so, except that directories that don’t exist, such as /usr/local/sbin, are not added.

An important convenience of the paths function would be that it also works similarly for MANPATH, LD_LIBRARY_PATH, LIBRARY_PATH, and CPATH.

You can also do these:
	paths remove /usr/local/llvm/3.5.1
	paths addlast /usr/local/llvm/3.5.1
	paths addfirst /usr/local/llvm/3.5.1
with the obvious effects (including removing from paths before adding at the desired position), and
	paths list
would output like this
	/usr/local/llvm/3.5.1
	/usr/local
	/usr
	/

One notable exception is adding “.” to PATH. The paths function could help here, too:
	paths --no-subdirs --only=PATH addlast .

On my Mac, here’s what’s in /etc/paths
	/usr/local/bin
	/usr/bin
	/bin
	/usr/sbin
	/sbin
But what about MANPATH, LD_LIBRARY_PATH, LIBRARY_PATH, and CPATH? The paths function could be smart enough to eat /etc/paths as input, stripping off the /bin part of each item and then doing:
	paths /usr/local /usr /
That way /etc/paths wouldn’t have to change. Better would be a new overriding file, called /etc/prefixes or something, that just has a list of arguments to the paths function:
	/usr/local
	/usr
	/

Comments? Volunteers? Is this already out there somewhere?

I do not plan to implement this anytime soon.

Dave

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

* Re: managing PATH, MANPATH, LD_LIBRARY_PATH, etc.
  2015-01-28 18:06 managing PATH, MANPATH, LD_LIBRARY_PATH, etc Dave Yost
@ 2015-01-28 18:39 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2015-01-28 18:39 UTC (permalink / raw)
  To: zsh-workers

On Jan 28, 10:06am, Dave Yost wrote:
}
} Imagine a shell function called "paths". Doing this:
} 	paths set /usr/local /usr /
} wants to set PATH to this:
} 	/usr/local/bin
} 	/usr/local/sbin
} 	/usr/bin
} 	/usr/sbin
} 	/bin
} 	/sbin
} and does so, except that directories that don't exist, such as
} /usr/local/sbin, are not added.

Two things that occur to me:

(1) It's often a policy thing that only adminstrator users have "sbin"
directories in their path.

(2) There's really no reason to exclude non-existent directories, they
have no interesting effect on path search particularly given zsh's use
of the command hash table.  Unless they cause some problem for other
programs' use of other PATH-like variables?

} An important convenience of the paths function would be that it also
} works similarly for MANPATH, LD_LIBRARY_PATH, LIBRARY_PATH, and CPATH.

CPATH is GCC specific and only for build environments (isn't it?).  How
many such special cases might there be, and how would "paths" decide
when to in/exclude them?

} You can also do these:
} 	paths remove /usr/local/llvm/3.5.1
} 	paths addlast /usr/local/llvm/3.5.1
} 	paths addfirst /usr/local/llvm/3.5.1

"append" and "prepend"?

} Comments? Volunteers? Is this already out there somewhere?

Seems pretty similar to "add-zsh-hook" except with some extra rules.


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

end of thread, other threads:[~2015-01-28 18:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-28 18:06 managing PATH, MANPATH, LD_LIBRARY_PATH, etc Dave Yost
2015-01-28 18:39 ` Bart Schaefer

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