mediamtx: 1.9.2 -> 1.9.3 (#352624)
[NixPkgs.git] / pkgs / build-support / setup-hooks / patch-rc-path-hooks / patch-rc-path-fish.sh
blob3d3e08c57a11e3824bda91f247ebc76fc7c5e75c
1 patchRcPathFish(){
2 local FILE_TO_PATCH="$1"
3 local SOURCETIME_PATH="$2"
4 local FILE_TO_WORK_ON="$(mktemp "$(basename "$FILE_TO_PATCH").XXXXXX.tmp")"
5 cat <<EOF >> "$FILE_TO_WORK_ON"
6 # Lines to add to PATH the source-time utilities for Nixpkgs packaging
7 if set -q NIXPKGS_SOURCETIME_PATH && test (count \$NIXPKGS_SOURCETIME_PATH) -gt 0
8 set --unpath NIXPKGS_SOURCETIME_PATH_OLD "\$NIXPKGS_SOURCETIME_PATH" \$NIXPKGS_SOURCETIME_PATH_OLD
9 end
10 set --path NIXPKGS_SOURCETIME_PATH $SOURCETIME_PATH
11 set -g --path PATH \$NIXPKGS_SOURCETIME_PATH \$PATH
12 # End of lines to add to PATH source-time utilities for Nixpkgs packaging
13 EOF
14 cat "$FILE_TO_PATCH" >> "$FILE_TO_WORK_ON"
15 cat <<EOF >> "$FILE_TO_WORK_ON"
16 # Lines to clean up inside PATH the source-time utilities for Nixpkgs packaging
17 if set -q PATH && test "\$PATH" != "" && test (count \$PATH) -ge (count \$NIXPKGS_SOURCETIME_PATH)
18 # Remove the inserted section
19 for i in (seq 0 (math (count \$PATH) - (count \$NIXPKGS_SOURCETIME_PATH)))
20 for j in (seq 1 (count \$NIXPKGS_SOURCETIME_PATH))
21 if test \$PATH[(math \$i + \$j)] != \$NIXPKGS_SOURCETIME_PATH[\$j]
22 set i -1
23 break
24 end
25 end
26 if test \$i -eq -1
27 continue
28 end
29 if test \$i -eq 0
30 set -g --path PATH \$PATH[(math (count \$NIXPKGS_SOURCETIME_PATH) + 1)..]
31 else
32 set -g --path PATH \$PATH[..\$i] \$PATH[(math (count \$NIXPKGS_SOURCETIME_PATH) + 1 + \$i)..]
33 end
34 break
35 end
36 end
37 if set -q NIXPKGS_SOURCETIME_PATH_OLD && test (count \$NIXPKGS_SOURCETIME_PATH_OLD) -gt 0
38 set --path NIXPKGS_SOURCETIME_PATH \$NIXPKGS_SOURCETIME_PATH_OLD[1]
39 set --unpath NIXPKGS_SOURCETIME_PATH_OLD \$NIXPKGS_SOURCETIME_PATH_OLD[2..]
40 else
41 set -e NIXPKGS_SOURCETIME_PATH
42 end
43 if set -q NIXPKGS_SOURCETIME_PATH_OLD && test (count \$NIXPKGS_SOURCETIME_PATH_OLD) -eq 0
44 set -e NIXPKGS_SOURCETIME_PATH_OLD
45 end
46 # End of lines to clean up inside PATH the source-time utilities for Nixpkgs packaging
47 EOF
48 cat "$FILE_TO_WORK_ON" > "$FILE_TO_PATCH"
49 rm "$FILE_TO_WORK_ON"