Skip to content

Conversation

janniks
Copy link
Owner

@janniks janniks commented Mar 21, 2020

If you'll allow it, I'd love to include some of your changes... ☺️

Copy link
Owner Author

@janniks janniks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yrave Love the changes so far 🚀 Let me know what you think...

@@ -1,12 +1,13 @@
#!/bin/sh
#!/bin/bash
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for the switch to bash ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe @schnappfuesch can help 😊

Copy link

@schnappfuesch schnappfuesch Mar 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The for-loop is using an invalid bracket syntax (((...))) for sh. The bash is a sh extension that understand this format. I'm also not sure if you can use the counter in the for-loop at all (using sh).
On most linuxe the sh is no longer directly installed but a replacement, which is linked to a different shell, so depending on the outcome of this link, the command might work (e.g. on ubuntu sh is linked to dash, which will fail).

If you pipe the script into sh using the curl command, you will also get this error:
Syntax error: Bad for loop variable.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more portable solution would be

Suggested change
#!/bin/bash
#!/usr/bin/env bash

which works on all systems (including the more obscure ones like NixOS, where /bin/bash does not exist)

PLACEHOLDER_LOGGING_VERBOSE="true"

GITHUB_SCRIPT_URL="https://raw.githubusercontent.com/janniks/prepare-commit-msg/master/scripts/prepare-commit-msg"
PLACEHOLDER_NEW_COMMIT_MESSAGE="#{issue_number.upcase}: #{original_commit_message.gsub(/(\s[[:punct:]])+$/, '')}"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of parameterizing the new commit message. I can also add this to the install script 👍

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That was actually the main reason why I forked your project


printf -- " - Downloading git hook...\n"
curl -s "$GITHUB_SCRIPT_URL" > "$HOOK_FILE"
if [ "$should_use_file_from_github_url" = true ] ; then
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a very nice feature 🙌 I might also like to add this to the install script

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :) I was too lazy to add it to the advanced option and I used it only for testing

exit
fi

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👾


replace_placeholder_with_value () {
if [ $(uname -s) == "Linux" ]; then
sed -i "s/${1}/${2}/g" "$HOOK_FILE"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Is this important/relevant for all Linux?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve worked on other scripts that use the sed command and it’s been relevant for all Linux user.

@yrave
Copy link

yrave commented Mar 21, 2020

If you'll allow it, I'd love to include some of your changes... ☺️

Yes, please, of course! And thank you for the script. It's been really helpful so far :)

@yrave yrave force-pushed the master branch 4 times, most recently from c29738d to 68730b2 Compare May 6, 2020 11:45
@yrave
Copy link

yrave commented May 6, 2020

I updated the script so that it can now use different message styles and different message regexes. Let me know what you think and if you want to merge it :)

yrave
yrave previously approved these changes May 6, 2020
@janniks
Copy link
Owner Author

janniks commented Jan 30, 2021

Sorry for the delay! I want to merge this 🙈 I'll try in ~ 1-2 weeks, as I am a bit busy currently...


```bash
sh <(curl -s https://raw.githubusercontent.com/janniks/prepare-commit-msg/master/scripts/install.sh)
sh <(curl -s https://raw.githubusercontent.com/yrave/prepare-commit-msg/master/scripts/install.sh)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced in PR?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sh <(curl -s https://raw.githubusercontent.com/yrave/prepare-commit-msg/master/scripts/install.sh)
sh <(curl -s https://raw.githubusercontent.com/janniks/prepare-commit-msg/master/scripts/install.sh)

@@ -1,12 +1,13 @@
#!/bin/sh
#!/bin/bash
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more portable solution would be

Suggested change
#!/bin/bash
#!/usr/bin/env bash

which works on all systems (including the more obscure ones like NixOS, where /bin/bash does not exist)

PLACEHOLDER_NEW_COMMIT_MESSAGE="[#{issue_number.upcase}] #{original_commit_message.gsub(/(\s[[:punct:]])+$/, '')}"
PLACEHOLDER_NEW_COMMIT_MESSAGE_ONE="[#{issue_number.upcase}] #{original_commit_message.gsub(/(\s[[:punct:]])+$/, '')}"
PLACEHOLDER_NEW_COMMIT_MESSAGE_TWO="#{issue_number.upcase}: #{original_commit_message.gsub(/(\s[[:punct:]])+$/, '')}"
GITHUB_SCRIPT_URL="https://raw.githubusercontent.com/yrave/prepare-commit-msg/master/scripts/prepare-commit-msg"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GITHUB_SCRIPT_URL="https://raw.githubusercontent.com/yrave/prepare-commit-msg/master/scripts/prepare-commit-msg"
GITHUB_SCRIPT_URL="https://raw.githubusercontent.com/janniks/prepare-commit-msg/master/scripts/prepare-commit-msg"


```bash
sh <(curl -s https://raw.githubusercontent.com/janniks/prepare-commit-msg/master/scripts/install.sh)
sh <(curl -s https://raw.githubusercontent.com/yrave/prepare-commit-msg/master/scripts/install.sh)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sh <(curl -s https://raw.githubusercontent.com/yrave/prepare-commit-msg/master/scripts/install.sh)
sh <(curl -s https://raw.githubusercontent.com/janniks/prepare-commit-msg/master/scripts/install.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants