Skip to content

Commit 01cbaa7

Browse files
committed
bashrc/zshrc -> rcfile, cleanup paths, docs
1 parent 7bb5f7f commit 01cbaa7

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ For usage examples see https://github.com/kilna/gnu-on
7878

7979
## Examples
8080

81-
First, enable in your shell (pick one):
81+
First, enable in your shell after install, if you haven't already:
8282

8383
```
84-
$ gnu bashrc
85-
$ gnu zshrc
84+
$ gnu rcfile
8685
```
8786

8887
Fire up a new shell session (or run `eval "$(gnu on)"` yourself) and check:

gnu

+15-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export _gnu_verbose=0
1212
export _gnu_shell=''
1313
while [ $# -gt 0 ]; do
1414
case "$1" in
15-
load|unload|on|off|status|env|bashrc|zshrc|autorc|help)
15+
load|unload|on|off|status|env|rcfile|help)
1616
_gnu_action="$1";;
1717
--verbose|-v) _gnu_verbose=1;;
1818
--help|-h) _gnu_action='help';;
@@ -102,13 +102,14 @@ _gnu_unload() {
102102
echo 'typeset -pf gnu >/dev/null 2>&1 && unset -f gnu'
103103
}
104104

105-
# Used to add/remove entries from PATH/MANPATH
105+
# Used to remove or prepend entries from PATH / MANPATH
106106
_gnu_pathspec() {
107107
pathvar="$1" # PATH or MANPATH
108-
exclude="$2" # path to be removed from the env var
109-
if [ -n "${3:-}" ]; then add="$3:"; else add=''; fi # Optional path to add
108+
action="$2" # + to prepend and cleanup, - to cleanup (remove) only
109+
exclude="$3" # path to be added / cleaned from the env var
110+
if [ "$action" == '+' ]; then add="$3:"; else add=''; fi
110111
echo -n 'export '$pathvar'="'$add'$('
111-
echo -n 'echo "$'$pathvar'"' # Gets PATH/MANPATH in : format
112+
echo -n 'echo "$'$pathvar'"' # Gets PATH / MANPATH in : format
112113
echo -n "|tr : '\n'" # Turns : into newlines
113114
echo -n "|grep -vxF '$exclude'" # Removes the path from entries
114115
echo -n '|uniq' # Removes duplicate entries
@@ -125,28 +126,30 @@ _gnu_on() {
125126

126127
_gnu_off() {
127128
_gnu_warn
128-
_gnu_pathspec PATH $_gnu_base/bin
129-
_gnu_pathspec MANPATH $_gnu_base/share/man
129+
_gnu_pathspec PATH - $_gnu_base/bin
130+
_gnu_pathspec MANPATH - $_gnu_base/share/man
130131
echo 'if [ "$MANPATH" = "" ]; then unset MANPATH; fi'
131132
}
132133

133134
_gnu_env() {
134-
_gnu_pathspec PATH $_gnu_base/bin $_gnu_base/bin
135-
_gnu_pathspec MANPATH $_gnu_base/share/man $_gnu_base/share/man
135+
_gnu_pathspec PATH + $_gnu_base/bin
136+
_gnu_pathspec MANPATH + $_gnu_base/share/man
136137
}
137138

138139
_gnu_rcfile() {
139140
local rcfile="${1:-$HOME/.${_gnu_shell}rc}"
140-
grep -xFq 'eval "$(gnu on)"' "$rcfile" && return
141+
if grep -Eq 'gnu (on|load|env)' "$rcfile"; then
142+
echo "The gnu shell extension is already in $rcfile"
143+
return
144+
fi
141145
echo "Adding gnu shell extension loader to $rcfile"
142146
echo 'eval "$(gnu on)"' >>"$rcfile"
143147
}
144148

145149
case "$_gnu_action" in
146150
help) _gnu_help;;
147151
install) /bin/bash -c "$(curl -fsSL $_gnu_url)";;
148-
*shrc) _gnu_rcfile "$HOME/.$_gnu_action";;
149-
autorc) _gnu_rcfile;;
152+
rcfile) _gnu_rcfile;;
150153
load) if _gnu_eval; then eval "$(_gnu_load)" || _gnu_fail
151154
else _gnu_load; fi;;
152155
unload) if _gnu_eval; then eval "$(_gnu_unload)" || _gnu_fail

install.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ for pkg in $packages; do
6060

6161
done
6262

63-
echo
64-
/usr/local/bin/gnu autorc
65-
echo
66-
echo "Your next new shell session will have the gnu shell extension enabled"
63+
cat <<'EOF'
6764
65+
66+
To enable in your shell as a shell extension, run:
67+
68+
$ gnu rcfile
69+
70+
Then you will be able to use 'gnu on' and 'gnu off' the next time you fire up
71+
a new shell.
72+
73+
EOF

0 commit comments

Comments
 (0)