Skip to content

Instantly share code, notes, and snippets.

@robertherdzik
Last active August 21, 2018 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertherdzik/5d14cc47eabcd8c10f026a751854db63 to your computer and use it in GitHub Desktop.
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
#!/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
@robertherdzik
Copy link
Author

robertherdzik commented Apr 18, 2018

TODO:

XXXX-888 shouldn't be lowercased - fixed

@robertherdzik
Copy link
Author

robertherdzik commented Jun 21, 2018

remove special characters like:
/, ', ",... , etc...
Check which characters are not allowed also

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