Skip to content

Instantly share code, notes, and snippets.

@dkchiem
Created June 9, 2020 03:50
Show Gist options
  • Save dkchiem/59fc8092fb42251f2d753561646a63e4 to your computer and use it in GitHub Desktop.
Save dkchiem/59fc8092fb42251f2d753561646a63e4 to your computer and use it in GitHub Desktop.
Create organized comments

Create comments

This will generate a comment to put into code files

read -p 'Title: ' text
read -p 'Number of characters on each side [default 10]: ' sideCharacters
read -p 'Prefix [enter for none]: ' prefix
echo This is the generated comment for \""${text}"\":
echo 

sideCharacters=${sideCharacters:-10}
chr=$(((2 * ${sideCharacters}) + ${#text}))

printf_new() {
 num=$1
 printf "%${num}s\n" "" | sed -e 's/ /*/g'
}

printf_title() {
 sides=$1
 title=$2
 num=$((${sides} - 1))
 printf "%${num}s\n" "" | sed -e 's/ /*/g' | tr -d '\n'
 printf " " | tr -d '\n'
 printf "${title}" | tr -d '\n'
 printf " " | tr -d '\n'
 printf "%${num}s\n" "" | sed -e 's/ /*/g'
}

printf "${prefix} ";
printf_new ${chr}

printf "${prefix} "; 
printf_title ${sideCharacters} "${text}"

printf "${prefix} "; 
printf_new ${chr}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment