Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make _fresh_preamble POSIX-compliant #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bin/fresh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ fresh_after_build() {
_fresh_preamble() {
if [ -z "${__FRESH_PREAMBLE_DONE__:-}" ]; then
if [ -z "${FRESH_NO_PATH_EXPORT:-}" ]; then
echo "__FRESH_BIN_PATH__="${FRESH_BIN_PATH/#$HOME/\$HOME}"; [[ ! \$PATH =~ (^|:)\$__FRESH_BIN_PATH__(:|\$) ]] && export PATH=\"\$__FRESH_BIN_PATH__:\$PATH\"; unset __FRESH_BIN_PATH__" >> "$FRESH_PATH/build.new/shell.sh"
cat <<EOF >> "$FRESH_PATH/build.new/shell.sh"
__FRESH_BIN_PATH__=${FRESH_BIN_PATH/#$HOME/\$HOME}
case ":\$PATH:" in
*:\$__FRESH_BIN_PATH__:*) : ;;
*) export PATH="\$__FRESH_BIN_PATH__:\$PATH" ;;
esac
unset __FRESH_BIN_PATH__
EOF
fi
echo "export FRESH_PATH=\"$FRESH_PATH\"" >> "$FRESH_PATH/build.new/shell.sh"
__FRESH_PREAMBLE_DONE__=1
Expand Down
7 changes: 6 additions & 1 deletion spec/fresh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,12 @@
expect(File.read(fresh_bin_path)).to eq "test file\n"
expect_readlink(fresh_bin_path).to eq (fresh_path + 'build/bin/fresh').to_s
expect(File.read(shell_sh_path)).to eq <<-EOF.strip_heredoc
__FRESH_BIN_PATH__=$HOME/Applications/bin; [[ ! $PATH =~ (^|:)$__FRESH_BIN_PATH__(:|$) ]] && export PATH="$__FRESH_BIN_PATH__:$PATH"; unset __FRESH_BIN_PATH__
__FRESH_BIN_PATH__=$HOME/Applications/bin
case ":$PATH:" in
*:$__FRESH_BIN_PATH__:*) : ;;
*) export PATH="$__FRESH_BIN_PATH__:$PATH" ;;
esac
unset __FRESH_BIN_PATH__
export FRESH_PATH="#{fresh_path}"
EOF

Expand Down
11 changes: 8 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,20 @@ def expect_shell_sh
expect(shell_sh_path).to_not be_executable

empty_shell_sh = <<-EOF.strip_heredoc
__FRESH_BIN_PATH__=$HOME/bin; [[ ! $PATH =~ (^|:)$__FRESH_BIN_PATH__(:|$) ]] && export PATH="$__FRESH_BIN_PATH__:$PATH"; unset __FRESH_BIN_PATH__
__FRESH_BIN_PATH__=$HOME/bin
case ":$PATH:" in
*:$__FRESH_BIN_PATH__:*) : ;;
*) export PATH="$__FRESH_BIN_PATH__:$PATH" ;;
esac
unset __FRESH_BIN_PATH__
export FRESH_PATH="#{fresh_path}"
EOF

shell_sh_content_lines = File.read(shell_sh_path).lines

expect(shell_sh_content_lines[0..1].join).to eq empty_shell_sh
expect(shell_sh_content_lines[0..6].join).to eq empty_shell_sh

content = shell_sh_content_lines[3..-1] || []
content = shell_sh_content_lines[8..-1] || []
expect(content.join)
end

Expand Down