|
1 |
| -BASH_PS1_MISC |
2 |
| -============= |
| 1 | +bash-config |
| 2 | +=========== |
3 | 3 |
|
4 |
| -Generic Bash PS1 (bashrc) Configuration |
| 4 | +AOSC's bash & sh startup files in `/etc`. |
5 | 5 |
|
6 |
| - |
| 6 | +Features |
| 7 | +-------- |
7 | 8 |
|
8 |
| -bashrc |
9 |
| ---- |
10 |
| -The main bashrc file. |
| 9 | +* Colored PS1 with VCS branch display and return-value based prompt |
| 10 | +  |
| 11 | +* OS X-like `/etc/paths` management scheme. |
| 12 | +* Regular `somefile.d` directorys. |
| 13 | +* Common aliases. |
11 | 14 |
|
12 |
| -bashrc\_repo |
13 |
| ---- |
14 |
| -Provides repo branch/status PS1 function. |
| 15 | +Structure |
| 16 | +--------- |
15 | 17 |
|
16 |
| -By default, it reads bashrc\_foo to load the repo status function |
17 |
| -for foo version control system. |
| 18 | +* `bashrc` - Bash's global startup file, sourced by `~/.bashrc`. Contains |
| 19 | + stuffs that we think is good for all users. |
| 20 | + * Sources `profile` for environmental variables |
| 21 | + * Sets some variables for colors |
| 22 | + * Sources `bashrc.d` |
| 23 | + * Sets up the PS1 |
| 24 | + * Sets up aliases |
| 25 | + * Sets up some bash-specific variables. |
| 26 | + * Prepares the `_lastdir` functions for saving last directory on logout. |
| 27 | +* `profile` - Environment variables for all POSIX login shells |
| 28 | + * Sets up `$PATH` and `$MANPATH`: |
| 29 | + * Ignores lines starting with `#`. |
| 30 | + * Adds each line of `/etc/paths.d/._pre*` to `$PATH`, |
| 31 | + * Adds each line of `/etc/paths` to `$PATH`, |
| 32 | + * Adds each line of `/etc/paths.d/*` to `$PATH`. |
| 33 | + * Then do almost the same for `manpaths`. |
| 34 | + * If those are still empty, default values `{,/usr{,/local}}/{s,}bin` and |
| 35 | + `/usr/{,local/}man` are used. |
| 36 | + * Sets up `$TZ` and some common history variables. |
| 37 | + * Sources `profile.d`. |
| 38 | +* `skel` - `$HOME` Skeleton. Contains what we think is good for most users. |
| 39 | + * `.bashrc` - User bash startup, sources `/etc/bashrc`, runs `_lastdir_go`. |
| 40 | + * `.bash_profile` - User bash login, sources `~/.bashrc`. |
| 41 | + * `.bash_logout` - User bash logout, runs `_lastdir_rec`. |
| 42 | +* `bashrc.d` - Files sourced by `/etc/bashrc`. |
| 43 | + * `20-vcs` - VCS aliases and PS1. Provides `_vcs_status`. |
| 44 | + * `.vcs_*` - VCS Implementations. |
| 45 | +* `profile.d` - Files sourced by `/etc/profile`. |
18 | 46 |
|
19 |
| -###bashrc\_git |
20 |
| -Provides git branch and status info in the PS1. |
| 47 | +Dependencies |
| 48 | +------------ |
21 | 49 |
|
22 |
| -Also provides aliases. |
| 50 | +* GNU Bash for `bashrc` stuffs. When we are happy, we try to make most parts of |
| 51 | + `bashrc` compatible with other bourne/POSIX-like shells, e.g. `hush`/`ash`. |
| 52 | +* At least a mostly POSIX-compatible shell for `profile`. We try our best to |
| 53 | + guarantee that it's written fully POSIXly. Send us an issue if it's not. |
| 54 | +* Coreutils for `profile`. More specifically, `cat`, `sed` and `mkdir`. |
| 55 | + GNU/Busybox ones are preferred. See [#Porting](#Porting) for more info. |
23 | 56 |
|
24 |
| -###bashrc\_hg |
25 |
| -Provides hg branch and status info in the PS1. |
| 57 | +Invocation |
| 58 | +---------- |
| 59 | + |
| 60 | +This briefly describes how bash processes the files. and put here as a sort of |
| 61 | +reference: |
| 62 | + |
| 63 | +On Startup: |
| 64 | +```Bash |
| 65 | +# Pseudo-code functions: |
| 66 | +# _bash_optarg: The argument for an option. |
| 67 | +# _bash_opts: If this option is set. |
| 68 | +_is_sh(){ [ "$(basename "$BASH")" == "sh" ]; } |
| 69 | +_is_posix(){ shopt -oq posix; } |
| 70 | +_is_interactive() { case "$-" in *i*) return 0; esac; return 1; } |
| 71 | +_is_login(){ [ "${0:0:1}" == - ] || _bash_opts --login || _bash_opts -l; } |
| 72 | +# Real bash doesn't change the return value, just for convenience with || |
| 73 | +load_if_exists(){ [ -r "$1" ] || return 1; . "$@"; true; } |
| 74 | +if _is_interactive; then |
| 75 | + if _is_login && ! _bash_opts --noprofile; then |
| 76 | + load_if_exists /etc/profile |
| 77 | + if ! _is_sh; then |
| 78 | + load_if_exists ~/.bash_profile || |
| 79 | + load_if_exists ~/.bash_login || |
| 80 | + load_if_exists ~/.profile |
| 81 | + else |
| 82 | + load_if_exists ~/.profile |
| 83 | + fi |
| 84 | + elif ! _bash_opts --norc; then |
| 85 | + if ! _is_posix; then |
| 86 | + _is_sh || load_if_exists "$(_bash_optarg --rcfile || echo ~/.bashrc)" |
| 87 | + else |
| 88 | + load_if_exists "$ENV" |
| 89 | + fi |
| 90 | + elif _is_network_input; then |
| 91 | + is_sh || load_if_exists ~/.bashrc |
| 92 | + fi |
| 93 | +# Non-interactive (i.e. To run a script) |
| 94 | +else |
| 95 | + if ! _is_sh; then |
| 96 | + load_if_exists "$BASH_ENV" |
| 97 | + fi |
| 98 | +fi |
| 99 | +_is_sh && shopt -os posix |
| 100 | +``` |
| 101 | +
|
| 102 | +On exit: |
| 103 | +```Bash |
| 104 | +if _is_login && ! _is_sh && ! _is_posix; then |
| 105 | + load_if_exists ~/.bash_logout |
| 106 | +fi |
| 107 | +``` |
| 108 | +
|
| 109 | +Porting |
| 110 | +------- |
26 | 111 |
|
27 |
| -Also provides aliases. |
28 | 112 |
|
29 |
| -Porting to other platforms |
30 |
| ---- |
31 | 113 | The master branch of this repo can be easily ported to other platforms
|
32 | 114 | with bash and an echo with -e flag.
|
33 | 115 |
|
34 |
| -If you use BSD coreutils, just change `ls --color=auto` to `ls -G`.<br /> |
| 116 | +If you use BSD coreutils, just change `ls --color=auto` to `ls -G`. |
| 117 | +
|
35 | 118 | If you use OS X or wants to make an OS X distribution, you had better include
|
36 |
| -the workaround mentioned [Here](https://github.com/AOSC-Dev/BASH_PS1_MISC/issues/3), |
37 |
| -the issue #3, in order to avoid "Please install XCode Developer Tools" |
| 119 | +the workaround mentioned in |
| 120 | +[#3](https://github.com/AOSC-Dev/BASH_PS1_MISC/issues/3), |
| 121 | +in order to avoid "Please install XCode Developer Tools" |
38 | 122 | from appearing too many times.
|
39 | 123 |
|
40 |
| -This package provides an example: [Bash 4.3 for OS X](http://pan.baidu.com/s/1c0xlkFu) |
| 124 | +This package provides an example: |
| 125 | +[Bash 4.3 for OS X](http://pan.baidu.com/s/1c0xlkFu). |
0 commit comments