Last active
August 21, 2018 07:12
-
-
Save robertherdzik/5d14cc47eabcd8c10f026a751854db63 to your computer and use it in GitHub Desktop.
Script takes from 'Clipboard' (Ctrl+v) string value and create branch lowercased and under scored name. See example INPUT/OUTPUT in the script comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
###### | |
# Example: | |
# INPUT: "XXXX-888 [iOS] Fix Floating Button" | |
# OUTPUT: "feature/xxxx-888_fix_floating_button" | |
###### | |
remove_spaces () | |
{ | |
echo $1 | tr ' ' _ | |
} | |
lowercase () | |
{ | |
echo $1 | awk '{print tolower($0)}' | |
} | |
remove_ios_keyword () | |
{ | |
echo ${1//\[iOS\]_/} | |
} | |
switch_to_dev_branch () | |
{ | |
git pull | |
git checkout dev | |
} | |
create_and_switch_to_branch () | |
{ | |
branch_name=$1 | |
git checkout -b $branch_name | |
git checkout $branch_name | |
} | |
# lowercase, change spaces to '_' and remove [ios] from passed string | |
prepare_branch_name () | |
{ | |
raw_name="$1" | |
branch_path_name=$(remove_spaces "$raw_name") | |
branch_path_name=$(remove_ios_keyword $branch_path_name) | |
echo "feature/"$branch_path_name | |
} | |
run () | |
{ | |
clipboard_value=$(pbpaste) | |
branch_name=$(prepare_branch_name "$clipboard_value") | |
echo "Create branch [y/n]: "$branch_name | |
read decision | |
if [ $decision == "y" ] | |
then | |
switch_to_dev_branch | |
create_and_switch_to_branch $branch_name | |
echo "💥 Branch created: "$branch_name | |
fi | |
} | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
remove special characters like:
/, ', ",... , etc...
Check which characters are not allowed also