-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed enhancements to runcoms repo documentation #1540
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,61 +10,199 @@ in */etc* by default. | |||||||||||||
|
||||||||||||||
User-local configuration files have the same name as their global counterparts | ||||||||||||||
but are prefixed with a dot (hidden). Zsh looks for these files in the path | ||||||||||||||
stored in the `$ZDOTDIR` environmental variable. However, if said variable is | ||||||||||||||
not defined, Zsh will use the user's home directory. | ||||||||||||||
stored in the `$ZDOTDIR` environment variable. However, if said variable is | ||||||||||||||
not defined, Zsh will use the user's home directory. This is found on the | ||||||||||||||
config scripts as `${ZDOTDIR:-$HOME}` and is a `zsh` idiomatic way of doing | ||||||||||||||
something like this: | ||||||||||||||
|
||||||||||||||
File Descriptions | ||||||||||||||
----------------- | ||||||||||||||
|
||||||||||||||
The configuration files are read in the following order: | ||||||||||||||
|
||||||||||||||
01. /etc/zshenv | ||||||||||||||
02. ~/.zshenv | ||||||||||||||
03. /etc/zprofile | ||||||||||||||
04. ~/.zprofile | ||||||||||||||
05. /etc/zshrc | ||||||||||||||
06. ~/.zshrc | ||||||||||||||
07. ~/.zpreztorc | ||||||||||||||
08. /etc/zlogin | ||||||||||||||
09. ~/.zlogin | ||||||||||||||
10. ~/.zlogout | ||||||||||||||
11. /etc/zlogout | ||||||||||||||
```bash | ||||||||||||||
if [[ -n $ZDOTDIR ]]; then | ||||||||||||||
DOTFILES_PATH=$ZDOTDIR | ||||||||||||||
else | ||||||||||||||
DOTFILES_PATH=$HOME | ||||||||||||||
fi | ||||||||||||||
source $DOTFILES_PATH/.zshenv | ||||||||||||||
|
||||||||||||||
### zshenv | ||||||||||||||
#pro tip! set $ZDOTDIR on /etc/zshenv to ~/.zconf to have all runcoms live there instead of cluttering ~ =) | ||||||||||||||
``` | ||||||||||||||
the above is the same as: `source ${ZDOTDIR:-$HOME}/.zshenv` is equivalent to: | ||||||||||||||
|
||||||||||||||
This file is sourced by all instances of Zsh, and thus, it should be kept as | ||||||||||||||
small as possible and should only define environment variables. | ||||||||||||||
|
||||||||||||||
### zprofile | ||||||||||||||
Sourcing of these confguration files depends mostly on 2 things: | ||||||||||||||
|
||||||||||||||
This file is similar to zlogin, but it is sourced before zshrc. It was added | ||||||||||||||
for [KornShell][1] fans. See the description of zlogin below for what it may | ||||||||||||||
contain. | ||||||||||||||
1. Whether you are running a *login shell* | ||||||||||||||
2. Whether the `RCS` and `GLOBAL_RCS` options are set. They are usually | ||||||||||||||
set by default | ||||||||||||||
|
||||||||||||||
zprofile and zlogin are not meant to be used concurrently but can be done so. | ||||||||||||||
|
||||||||||||||
### zshrc | ||||||||||||||
File Descriptions | ||||||||||||||
----------------- | ||||||||||||||
|
||||||||||||||
This file is sourced by interactive shells. It should define aliases, | ||||||||||||||
functions, shell options, and key bindings. | ||||||||||||||
|
||||||||||||||
### zpreztorc | ||||||||||||||
| always runs | when `GLOBAL_RCS` is set | when `RCS` is set | Purpose | stuff that usually goes there, and notes | | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This table is a bit wide... I think we could probably drop a column by having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quite right! i thought so too. and good idea i'll make it so the headers go something lije this:
|
||||||||||||||
|------------------|-----------------------------------------|-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||||||||||||||
| `/etc/zshenv` | | | system provided minimal environment | Always runs! should be minimal set ZDOTDIR, minimal environment. system paths | ||||||||||||||
| | | `${ZDOTDIR:-$HOME}/.zshenv` | user environment overrides non-interactive, non-login shells (when invoked via shebang in a script or via `zsh -c [script]` or when invoked by `make` | personal environment overrides, such as `MANPATH`, `TERM`, `fpath` *non interactive scripts should have their environment completly set up here* ) | ||||||||||||||
| | `/etc/zshprofile` | | system profile for login shells (`zsh -ls zsh - or via _ssh forced command_`) | minimal system paths for remote interaction, site `fpath`, site `$LOCALE`, lang. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The man pages I looked at refer to this as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O.o indeed... my mistake. i was having tunnel vision or "shop" blindness because i dint catch it even on proofbreading.. haha 😮 |
||||||||||||||
| | | `${ZDOTDIR:-$HOME}/.zshprofile` | personal preferences for interactive login shells | your preferred `$LOCALE`, `$LANG`, `readlne` config, `cdpath`, session managers, additional `fpath` ) login shells (but non necessarily **ineractive** as when invoked via _ssh remote cmd_ ) will read config up to this point | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, this was |
||||||||||||||
| | `/etc/zshrc` | | system provided startup script, for interactive shells, (local shells that live in an `XTerm`, `URxvt`, `gnome-terminal`) or subshells (like running `xterm` from the command prompt of a _login xterm_, | site login accounting, security monitors, site command logging policy | ||||||||||||||
| | | `${ZDOTDIR:-$HOME}/.zshrc` | user customization of their *interactive* environment for terminals | sourcing custom completions (`gcloud.comp.inc`), custom user frameworks (zprezto is invoked here), additional path required by custom software installed in `/opt/*` | ||||||||||||||
| | `/etc/zshlogin` | | additional customization for interactive **login** shells, such as those accessed via ssh | tmux attach to existing session | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| | | `${ZDOTDIR:-$HOME}/.zshlogin` | user script for *login shell startup* (this shell is a session leader, and allocates a `ptty` | aliases, keybindings, personal startup programs, time tracking apps, session managers, quote of the day, fortunes | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| .. | ... your shell session happens here ... | | ||||||||||||||
| | | `${ZDOTDIR:-$HOME}/.zshlogout` | personal cleanup tasks | setting personal `crontabs` or `at` tasks, logging checout to your time tracking software, fortune to say goodbye. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| `/etc/zshlogout` | | | site cleanup tasks | site command logging policy stop, login accounting records, security context spindown, etcThe configuration files are read in the following order: | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
|
||||||||||||||
Discussion | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite a few of the comments in this section are very useful, but I feel like most people are going to ignore a large block of text this big. Is there any way to pare this down a bit to focus on the recommendations and why they're being recommended? Perhaps even moving most of the recommendations to the table and mainly giving explanations here? EDIT: After looking at the conclusion later, it seems like this was written as an essay, examining the different zsh configuration files and determining why prezto did things the way it did... and it does a good job of that. However, I'd still prefer to see slightly more focused documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prezto's repo has no wiki enabled. if you wish you can add a link to the original write-up (with corrections coming, i'm still working a bit though) so that way any reference material that may be of help to users is still tied to the repo. I'll be adding that on my fork's wiki in case you want to add a wik to the official repo, we can just move it over here =) Here's the link to the wiki article: https://github.com/hlecuanda/prezto/wiki/Prezto-Startup-Discussion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on an unrelated note.. I remember you mentioning that you wanted to start clearing the backlog on PRs and Issues. I'll try and triage the oldest PRs that are likely to contain conflicts from recently updated changes and try to resolve them so merging back to master won't be too much of a hassle. Unless you have a better suggestion of where to start? I'll be happy to go through that. may not be as glamorous as coming up with new code, but someone has to do it right? haha Let me know 😃 |
||||||||||||||
---------- | ||||||||||||||
|
||||||||||||||
There are several places to add personal configuration and preferences in | ||||||||||||||
the files already provided for startup, it’s just a matter of placing them | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably github's markdown parser's fault, but it looks like there's a manual newline after this in the rendered text. |
||||||||||||||
in the appropriate place. Most of them should probably go in | ||||||||||||||
`${ZDOTDIR:-$HOME}/.zshrc` **before** invoking zprezto init, to choose | ||||||||||||||
the modules that should get loaded, and using the appropriate `zstyle` | ||||||||||||||
calls form preferences (`zstyle` is a kind of _registry_ for shell configuration | ||||||||||||||
native to `zsh`) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
Any tweaks to prezto’s behavior should go **after** invoking zprezto init | ||||||||||||||
in `zshrc` or, in `${ZDOTDIR:-$HOME}/.zlogin` . Note however that the | ||||||||||||||
`zlogin` (sysem or user) files will be sourced **only for login shells**. | ||||||||||||||
|
||||||||||||||
That means, when logging in to a remote system via ssh for example or | ||||||||||||||
when calling say, `XTerm` or your favorite emulator by specifying you | ||||||||||||||
want a **login** shell (by calling `zsh -ls` instead of plain `zsh`). | ||||||||||||||
Otherwise, the `zlogin` files are ignored. | ||||||||||||||
|
||||||||||||||
Also, note that another difference between interactive login shells and | ||||||||||||||
plain interactive shells, is that, besides sourcing `zlogin` files, | ||||||||||||||
interactive login shells also allocate a pseudo-tty (you can see them when | ||||||||||||||
invoking `w`. Login shells have a pty assigned, while interactive non-login | ||||||||||||||
shells don't.) | ||||||||||||||
|
||||||||||||||
Why is this designed this way? because login shells are assumed to be | ||||||||||||||
the main point of interaction with a user while non login shells would | ||||||||||||||
be spawned as _sub-shells_ of a *login shell* , when executing scripts | ||||||||||||||
that call `zsh` as a command interpreter, for example, when the *shebang* is | ||||||||||||||
`#!/usr/bin/env zsh` or equivalent. | ||||||||||||||
|
||||||||||||||
When launching a new terminal within an *X11* session, it is safe to | ||||||||||||||
assume that you are *already logged in* so any terminal emulator will | ||||||||||||||
launch an *interactive-non-login* shell. Which is, _per specification_ | ||||||||||||||
the correct behavior, but not the behavior most users *expect*. | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
There is a reason for this _specified_ behaviour: `zlogin` files should | ||||||||||||||
be used for *interaction oriented settings* such as custom completion, | ||||||||||||||
keybindings, `tmux` session setup, and most `alias`es. | ||||||||||||||
|
||||||||||||||
The advantage of grouping all interaction oriented settings in | ||||||||||||||
`.zlogin` is that non-interactive shells (executing scripts via | ||||||||||||||
`zsh -c [script]`, the *shebang*, subshells or `make` invoked shells, | ||||||||||||||
for example) will not be burdened by additional config settings making | ||||||||||||||
them faster and more responsive, as _keybindings_ and _aliases_ are not | ||||||||||||||
even loaded at startup, after all, an _executable non-interactive script_, | ||||||||||||||
should never call on keybindings or aliases (assuming they were properly | ||||||||||||||
written to be portable) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
Finally, it is a common source of frustration amongst graphical environment | ||||||||||||||
users, to spend some time adding their customizations to `.zlogin` only | ||||||||||||||
to see them ignored when launching a new `XTerm` or `tmux` pane. | ||||||||||||||
|
||||||||||||||
This can be solved by calling (or aliasing) your terminal emulator with | ||||||||||||||
the required option to invoke a *login* shell, for `XTerm`, for example | ||||||||||||||
you would call `xterm -e zsh -ls` on tmux you may add one of the following | ||||||||||||||
lines to your `.tmux.conf`: | ||||||||||||||
|
||||||||||||||
```config | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is meant to be |
||||||||||||||
#tmux.conf: | ||||||||||||||
|
||||||||||||||
set -g default-command 'exec /usr/bin/zsh -ls' #this will make zsh a login shell AND a session leader | ||||||||||||||
set -g default-shell '/usr/bin/zsh -ls' | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
Here is an examplefor *i3wm* on ubuntu | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plus, should be backwards... u.u There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/examplefor/example for |
||||||||||||||
```bash | ||||||||||||||
|
||||||||||||||
#i3wm.conf: | ||||||||||||||
... | ||||||||||||||
set $XTERM_CMD='xterm -e zsh -ls` | ||||||||||||||
bind $mod+x $XTERM_CMD | ||||||||||||||
... | ||||||||||||||
``` | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nit-pick, but I prefer to see new-lines between paragraphs, even if it's just a code block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the end i decided to drop the indent and make the example more concise. In this case, purposely added something that looked like ellipsis ( . . . ) to mean that we were only looking at a section of thee file and that further lines followed, as well as more lines before... maybe using ellipsis is not as common a convention as i thought it was... 🤔 |
||||||||||||||
if you want to replace your non-login shell on your emulator with a brand-new | ||||||||||||||
shiny *login* shell you can issue `exec zsh -ls` at your command prompt. | ||||||||||||||
Doing this, however **will not write that terminal’s history to file** unless | ||||||||||||||
`INC_APPEND_HISTORY` was set when you strted the shell | ||||||||||||||
|
||||||||||||||
`INC_APPEND_HISTORY` makes `zsh` append history entries as soon as the | ||||||||||||||
command is finished. *zprezto* helpfuly sets `INC_APPEND_HISTORY`, | ||||||||||||||
`INC_APPEND_HISTORY_TIME`, and `SHARE_HISTORY` which makes your history | ||||||||||||||
available immediately from different terminals on command completion, | ||||||||||||||
and records execution time on the history file. Pretty neat, huh?) | ||||||||||||||
|
||||||||||||||
You could tack-on all interactive customizations on `zshrc` but you will | ||||||||||||||
end up with bloated shells on non-interactive environments. Perhaps desktop | ||||||||||||||
workstation users will not notice any difference, but in resource-constrained | ||||||||||||||
environments it may be significant in terms of execution time and energy | ||||||||||||||
consumption (v.gr when running a Raspberry PI on batteries or on a cell | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. v.gr : shorthand of verbi gratia / "for example" although literal latin translation would be "for the sake of a word"... she's Q.E.D.'s (Quod Erat Demostrandum) ugly cousin... 😺 |
||||||||||||||
phone environment such as `termux`) | ||||||||||||||
|
||||||||||||||
You may be thinking... why is `zpreztorc` not invoked on `.zlogin` instead | ||||||||||||||
of `.zshrc`? I believe it was a wise design decision, in order to | ||||||||||||||
eliminate complexity by having the whole of *prezto* configured and | ||||||||||||||
launched from a single point, as some of the modules need to be sourced | ||||||||||||||
early in the startup process, `editor` and `gnu-utls` come to mind. | ||||||||||||||
If invoked later on the startup, such as would be the case in `.zlogin` | ||||||||||||||
would makee it easier to conflict with stuff users may add on `zshrc`. | ||||||||||||||
Also, it avoids **not being loaded** and causing user frustration if | ||||||||||||||
the user launches *non-login shells* from graphical environments, as | ||||||||||||||
discussed above. | ||||||||||||||
|
||||||||||||||
## Conclusion | ||||||||||||||
|
||||||||||||||
For customization of your environment, use your `.zshrc` after zprezto | ||||||||||||||
has been invoked, or before to remove or activate packages via `zstyle` | ||||||||||||||
calls | ||||||||||||||
|
||||||||||||||
or | ||||||||||||||
|
||||||||||||||
use `.zshlogin` to override or tweak zprezto behavior. there is also | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
`.zpreztorc` but you may want to leave that one alone. | ||||||||||||||
|
||||||||||||||
In any case, this question is often brought up by users that use the | ||||||||||||||
distributed *runcoms* **as is** which is a terrible idea, since doing | ||||||||||||||
`git pull` to update your distribution will clobber your customizations. | ||||||||||||||
|
||||||||||||||
it’s a better idea to *copy* the distributed *runcoms* to your `$ZDOTDIR` a | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit of a larger discussion. There have been talks about adding The original workflow with prezto was essentially fork the repo and make your own tweaks and changes there... which I understand, but I think it does the opposite of what was intended - a smaller amount of useful changes make it back into the main repo. I believe this is the reason the runcoms are symlinked. It also removes one step of debugging if you're using the official runcoms... because we don't need to go through all the zsh startup files and figure out where loading prezto went wrong. I don't know what to do here, but I'd be happy to see a larger discussion come from this (Probably in a new issue)... however, even if I don't agree with it, I don't think documentation included with the prezto repo should be saying that the official recommendation (at least what we're currently recommending) is a "terrible idea" and that it's a better idea to do something different from what we suggest in the main README. That being said, there are a number of easy to make mistakes, so providing a list of potential pitfalls and how to avoid them would be useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your feedback! I'll try and incorporate your observations, and yup there are a bunch of typos and dyslexyc mistakes. let's see how the second round comes up. =) |
||||||||||||||
nd merge any changes an update may bring, if any (they are usually | ||||||||||||||
confined to `.zpreztorc`) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
This file configures Prezto. | ||||||||||||||
|
||||||||||||||
### zlogin | ||||||||||||||
Troubleshooting | ||||||||||||||
--------------- | ||||||||||||||
|
||||||||||||||
1. if prezto and some of your settings are loaded, but others are not; | ||||||||||||||
make sure you are running an *interactive login shell* (you should have | ||||||||||||||
a tty allocated, visible on the `w` list) and the `$TTY` variable should | ||||||||||||||
be set, if that is not the case, check the above discussion, you can | ||||||||||||||
'replace' your shell _in situ_ by issuing the command `exec zsh -l` | ||||||||||||||
|
||||||||||||||
This file is sourced by login shells after zshrc, and thus, it should contain | ||||||||||||||
commands that need to execute at login. It is usually used for messages such as | ||||||||||||||
[fortune][2], [msgs][3], or for the creation of files. | ||||||||||||||
|
||||||||||||||
This is not the file to define aliases, functions, shell options, and key | ||||||||||||||
bindings. It should not change the shell environment. | ||||||||||||||
2. if you notice that none of your settings are loaded, check that | ||||||||||||||
`/etc/zshenv` does not disable them. In any case | ||||||||||||||
|
||||||||||||||
```bash | ||||||||||||||
setopt global_rcs | ||||||||||||||
setopt rcs | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
in `/etc/zshenv` should set them both. This issue would be extremely rare. | ||||||||||||||
|
||||||||||||||
### zlogout | ||||||||||||||
|
||||||||||||||
This file is sourced by login shells during logout. It should be used for | ||||||||||||||
displaying messages and the deletion of files. | ||||||||||||||
|
||||||||||||||
Authors | ||||||||||||||
------- | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: can you remove a space from the beginning here to be consistent with the
else
branch?