- 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`
···2424installManPage() {
2525 local path
2626 for path in "$@"; do
2727- if (( "${NIX_DEBUG:-0}" >= 1 )); then
2828- echo "installManPage: installing $path"
2929- fi
3027 if test -z "$path"; then
3131- echo "installManPage: error: path cannot be empty" >&2
2828+ nixErrorLog "${FUNCNAME[0]}: path cannot be empty"
3229 return 1
3330 fi
3131+ nixInfoLog "${FUNCNAME[0]}: installing $path"
3432 local basename
3533 basename=$(stripHash "$path") # use stripHash in case it's a nix store path
3634 local trimmed=${basename%.gz} # don't get fooled by compressed manpages
3735 local suffix=${trimmed##*.}
3836 if test -z "$suffix" -o "$suffix" = "$trimmed"; then
3939- echo "installManPage: error: path missing manpage section suffix: $path" >&2
3737+ nixErrorLog "${FUNCNAME[0]}: path missing manpage section suffix: $path"
4038 return 1
4139 fi
4240 local outRoot
···4543 else
4644 outRoot=${!outputMan:?}
4745 fi
4848- install -Dm644 -T "$path" "${outRoot}/share/man/man$suffix/$basename" || return
4646+ local outPath="${outRoot}/share/man/man$suffix/$basename"
4747+ install -D --mode=644 --no-target-directory "$path" "$outPath"
4948 done
5049}
5150···107106 --name)
108107 name=$1
109108 shift || {
110110- echo 'installShellCompletion: error: --name flag expected an argument' >&2
109109+ nixErrorLog "${FUNCNAME[0]}: --name flag expected an argument"
111110 return 1
112111 }
113112 continue;;
···118117 --cmd)
119118 cmdname=$1
120119 shift || {
121121- echo 'installShellCompletion: error: --cmd flag expected an argument' >&2
120120+ nixErrorLog "${FUNCNAME[0]}: --cmd flag expected an argument"
122121 return 1
123122 }
124123 continue;;
···127126 cmdname=${arg#--cmd=}
128127 continue;;
129128 --?*)
130130- echo "installShellCompletion: warning: unknown flag ${arg%%=*}" >&2
129129+ nixWarnLog "${FUNCNAME[0]}: unknown flag ${arg%%=*}"
131130 retval=2
132131 continue;;
133132 --)
···136135 continue;;
137136 esac
138137 fi
139139- if (( "${NIX_DEBUG:-0}" >= 1 )); then
140140- echo "installShellCompletion: installing $arg${name:+ as $name}"
141141- fi
138138+ nixInfoLog "${FUNCNAME[0]}: installing $arg${name:+ as $name}"
142139 # if we get here, this is a path or named pipe
143140 # Identify shell and output name
144141 local curShell=$shell
145142 local outName=''
146143 if [[ -z "$arg" ]]; then
147147- echo "installShellCompletion: error: empty path is not allowed" >&2
144144+ nixErrorLog "${FUNCNAME[0]}: empty path is not allowed"
148145 return 1
149146 elif [[ -p "$arg" ]]; then
150147 # this is a named fd or fifo
151148 if [[ -z "$curShell" ]]; then
152152- echo "installShellCompletion: error: named pipe requires one of --bash, --fish, or --zsh" >&2
149149+ nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --bash, --fish, or --zsh"
153150 return 1
154151 elif [[ -z "$name" && -z "$cmdname" ]]; then
155155- echo "installShellCompletion: error: named pipe requires one of --cmd or --name" >&2
152152+ nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --cmd or --name"
156153 return 1
157154 fi
158155 else
···168165 *)
169166 if [[ "$argbase" = _* && "$argbase" != *.* ]]; then
170167 # probably zsh
171171- echo "installShellCompletion: warning: assuming path \`$arg' is zsh; please specify with --zsh" >&2
168168+ nixWarnLog "${FUNCNAME[0]}: assuming path \`$arg' is zsh; please specify with --zsh"
172169 curShell=zsh
173170 else
174174- echo "installShellCompletion: warning: unknown shell for path: $arg" >&2
171171+ nixWarnLog "${FUNCNAME[0]}: unknown shell for path: $arg" >&2
175172 retval=2
176173 continue
177174 fi;;
···188185 zsh) outName=_$cmdname;;
189186 *)
190187 # Our list of shells is out of sync with the flags we accept or extensions we detect.
191191- echo 'installShellCompletion: internal error' >&2
188188+ nixErrorLog "${FUNCNAME[0]}: internal: shell $curShell not recognized"
192189 return 1;;
193190 esac
194191 fi
···206203 fi;;
207204 *)
208205 # Our list of shells is out of sync with the flags we accept or extensions we detect.
209209- echo 'installShellCompletion: internal error' >&2
206206+ nixErrorLog "${FUNCNAME[0]}: internal: shell $curShell not recognized"
210207 return 1;;
211208 esac
212209 # Install file
···217214 mkdir -p "$outDir" \
218215 && cat "$arg" > "$outPath"
219216 else
220220- install -Dm644 -T "$arg" "$outPath"
221221- fi || return
217217+ install -D --mode=644 --no-target-directory "$arg" "$outPath"
218218+ fi
222219223220 if [ ! -s "$outPath" ]; then
224224- echo "installShellCompletion: error: installed shell completion file \`$outPath' does not exist or has zero size" >&2
221221+ nixErrorLog "${FUNCNAME[0]}: installed shell completion file \`$outPath' does not exist or has zero size"
225222 return 1
226223 fi
227224 # Clear the per-path flags
228225 name=
229226 done
230227 if [[ -n "$name" ]]; then
231231- echo 'installShellCompletion: error: --name flag given with no path' >&2
228228+ nixErrorLog "${FUNCNAME[0]}: --name flag given with no path" >&2
232229 return 1
233230 fi
234231 return $retval
···240237installBin() {
241238 local path
242239 for path in "$@"; do
243243- if (( "${NIX_DEBUG:-0}" >= 1 )); then
244244- echo "installBin: installing $path"
245245- fi
246240 if test -z "$path"; then
247247- echo "installBin: error: path cannot be empty" >&2
241241+ nixErrorLog "${FUNCNAME[0]}: path cannot be empty"
248242 return 1
249243 fi
244244+ nixInfoLog "${FUNCNAME[0]}: installing $path"
245245+250246 local basename
251247 # use stripHash in case it's a nix store path
252248 basename=$(stripHash "$path")
···254250 local outRoot
255251 outRoot=${!outputBin:?}
256252257257- install -D --mode=755 --no-target-directory "$path" "${outRoot}/bin/$basename" || return
253253+ local outPath="${outRoot}/bin/$basename"
254254+ install -D --mode=755 --no-target-directory "$path" "${outRoot}/bin/$basename"
258255 done
259256}