- Use FUNCNAME to track the name of function being called - use long options for install commands - use nix*Log functions for logging, instead of custom echoes - remove silent error construction `|| return`
···24installManPage() {
25 local path
26 for path in "$@"; do
27- if (( "${NIX_DEBUG:-0}" >= 1 )); then
28- echo "installManPage: installing $path"
29- fi
30 if test -z "$path"; then
31- echo "installManPage: error: path cannot be empty" >&2
32 return 1
33 fi
034 local basename
35 basename=$(stripHash "$path") # use stripHash in case it's a nix store path
36 local trimmed=${basename%.gz} # don't get fooled by compressed manpages
37 local suffix=${trimmed##*.}
38 if test -z "$suffix" -o "$suffix" = "$trimmed"; then
39- echo "installManPage: error: path missing manpage section suffix: $path" >&2
40 return 1
41 fi
42 local outRoot
···45 else
46 outRoot=${!outputMan:?}
47 fi
48- install -Dm644 -T "$path" "${outRoot}/share/man/man$suffix/$basename" || return
049 done
50}
51···107 --name)
108 name=$1
109 shift || {
110- echo 'installShellCompletion: error: --name flag expected an argument' >&2
111 return 1
112 }
113 continue;;
···118 --cmd)
119 cmdname=$1
120 shift || {
121- echo 'installShellCompletion: error: --cmd flag expected an argument' >&2
122 return 1
123 }
124 continue;;
···127 cmdname=${arg#--cmd=}
128 continue;;
129 --?*)
130- echo "installShellCompletion: warning: unknown flag ${arg%%=*}" >&2
131 retval=2
132 continue;;
133 --)
···136 continue;;
137 esac
138 fi
139- if (( "${NIX_DEBUG:-0}" >= 1 )); then
140- echo "installShellCompletion: installing $arg${name:+ as $name}"
141- fi
142 # if we get here, this is a path or named pipe
143 # Identify shell and output name
144 local curShell=$shell
145 local outName=''
146 if [[ -z "$arg" ]]; then
147- echo "installShellCompletion: error: empty path is not allowed" >&2
148 return 1
149 elif [[ -p "$arg" ]]; then
150 # this is a named fd or fifo
151 if [[ -z "$curShell" ]]; then
152- echo "installShellCompletion: error: named pipe requires one of --bash, --fish, or --zsh" >&2
153 return 1
154 elif [[ -z "$name" && -z "$cmdname" ]]; then
155- echo "installShellCompletion: error: named pipe requires one of --cmd or --name" >&2
156 return 1
157 fi
158 else
···168 *)
169 if [[ "$argbase" = _* && "$argbase" != *.* ]]; then
170 # probably zsh
171- echo "installShellCompletion: warning: assuming path \`$arg' is zsh; please specify with --zsh" >&2
172 curShell=zsh
173 else
174- echo "installShellCompletion: warning: unknown shell for path: $arg" >&2
175 retval=2
176 continue
177 fi;;
···188 zsh) outName=_$cmdname;;
189 *)
190 # Our list of shells is out of sync with the flags we accept or extensions we detect.
191- echo 'installShellCompletion: internal error' >&2
192 return 1;;
193 esac
194 fi
···206 fi;;
207 *)
208 # Our list of shells is out of sync with the flags we accept or extensions we detect.
209- echo 'installShellCompletion: internal error' >&2
210 return 1;;
211 esac
212 # Install file
···217 mkdir -p "$outDir" \
218 && cat "$arg" > "$outPath"
219 else
220- install -Dm644 -T "$arg" "$outPath"
221- fi || return
222223 if [ ! -s "$outPath" ]; then
224- echo "installShellCompletion: error: installed shell completion file \`$outPath' does not exist or has zero size" >&2
225 return 1
226 fi
227 # Clear the per-path flags
228 name=
229 done
230 if [[ -n "$name" ]]; then
231- echo 'installShellCompletion: error: --name flag given with no path' >&2
232 return 1
233 fi
234 return $retval
···240installBin() {
241 local path
242 for path in "$@"; do
243- if (( "${NIX_DEBUG:-0}" >= 1 )); then
244- echo "installBin: installing $path"
245- fi
246 if test -z "$path"; then
247- echo "installBin: error: path cannot be empty" >&2
248 return 1
249 fi
00250 local basename
251 # use stripHash in case it's a nix store path
252 basename=$(stripHash "$path")
···254 local outRoot
255 outRoot=${!outputBin:?}
256257- install -D --mode=755 --no-target-directory "$path" "${outRoot}/bin/$basename" || return
0258 done
259}
···24installManPage() {
25 local path
26 for path in "$@"; do
00027 if test -z "$path"; then
28+ nixErrorLog "${FUNCNAME[0]}: path cannot be empty"
29 return 1
30 fi
31+ nixInfoLog "${FUNCNAME[0]}: installing $path"
32 local basename
33 basename=$(stripHash "$path") # use stripHash in case it's a nix store path
34 local trimmed=${basename%.gz} # don't get fooled by compressed manpages
35 local suffix=${trimmed##*.}
36 if test -z "$suffix" -o "$suffix" = "$trimmed"; then
37+ nixErrorLog "${FUNCNAME[0]}: path missing manpage section suffix: $path"
38 return 1
39 fi
40 local outRoot
···43 else
44 outRoot=${!outputMan:?}
45 fi
46+ local outPath="${outRoot}/share/man/man$suffix/$basename"
47+ install -D --mode=644 --no-target-directory "$path" "$outPath"
48 done
49}
50···106 --name)
107 name=$1
108 shift || {
109+ nixErrorLog "${FUNCNAME[0]}: --name flag expected an argument"
110 return 1
111 }
112 continue;;
···117 --cmd)
118 cmdname=$1
119 shift || {
120+ nixErrorLog "${FUNCNAME[0]}: --cmd flag expected an argument"
121 return 1
122 }
123 continue;;
···126 cmdname=${arg#--cmd=}
127 continue;;
128 --?*)
129+ nixWarnLog "${FUNCNAME[0]}: unknown flag ${arg%%=*}"
130 retval=2
131 continue;;
132 --)
···135 continue;;
136 esac
137 fi
138+ nixInfoLog "${FUNCNAME[0]}: installing $arg${name:+ as $name}"
00139 # if we get here, this is a path or named pipe
140 # Identify shell and output name
141 local curShell=$shell
142 local outName=''
143 if [[ -z "$arg" ]]; then
144+ nixErrorLog "${FUNCNAME[0]}: empty path is not allowed"
145 return 1
146 elif [[ -p "$arg" ]]; then
147 # this is a named fd or fifo
148 if [[ -z "$curShell" ]]; then
149+ nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --bash, --fish, or --zsh"
150 return 1
151 elif [[ -z "$name" && -z "$cmdname" ]]; then
152+ nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --cmd or --name"
153 return 1
154 fi
155 else
···165 *)
166 if [[ "$argbase" = _* && "$argbase" != *.* ]]; then
167 # probably zsh
168+ nixWarnLog "${FUNCNAME[0]}: assuming path \`$arg' is zsh; please specify with --zsh"
169 curShell=zsh
170 else
171+ nixWarnLog "${FUNCNAME[0]}: unknown shell for path: $arg" >&2
172 retval=2
173 continue
174 fi;;
···185 zsh) outName=_$cmdname;;
186 *)
187 # Our list of shells is out of sync with the flags we accept or extensions we detect.
188+ nixErrorLog "${FUNCNAME[0]}: internal: shell $curShell not recognized"
189 return 1;;
190 esac
191 fi
···203 fi;;
204 *)
205 # Our list of shells is out of sync with the flags we accept or extensions we detect.
206+ nixErrorLog "${FUNCNAME[0]}: internal: shell $curShell not recognized"
207 return 1;;
208 esac
209 # Install file
···214 mkdir -p "$outDir" \
215 && cat "$arg" > "$outPath"
216 else
217+ install -D --mode=644 --no-target-directory "$arg" "$outPath"
218+ fi
219220 if [ ! -s "$outPath" ]; then
221+ nixErrorLog "${FUNCNAME[0]}: installed shell completion file \`$outPath' does not exist or has zero size"
222 return 1
223 fi
224 # Clear the per-path flags
225 name=
226 done
227 if [[ -n "$name" ]]; then
228+ nixErrorLog "${FUNCNAME[0]}: --name flag given with no path" >&2
229 return 1
230 fi
231 return $retval
···237installBin() {
238 local path
239 for path in "$@"; do
000240 if test -z "$path"; then
241+ nixErrorLog "${FUNCNAME[0]}: path cannot be empty"
242 return 1
243 fi
244+ nixInfoLog "${FUNCNAME[0]}: installing $path"
245+246 local basename
247 # use stripHash in case it's a nix store path
248 basename=$(stripHash "$path")
···250 local outRoot
251 outRoot=${!outputBin:?}
252253+ local outPath="${outRoot}/bin/$basename"
254+ install -D --mode=755 --no-target-directory "$path" "${outRoot}/bin/$basename"
255 done
256}