|
| 1 | +#!/bin/bash - |
| 2 | +#title :mkscript.sh |
| 3 | +#description :This script will make a header for a bash script. |
| 4 | +#author :bgw |
| 5 | +#date :20111101 |
| 6 | +#version :0.4 |
| 7 | +#usage :bash mkscript.sh |
| 8 | +#notes :Install Vim and Emacs to use this script. |
| 9 | +#bash_version :4.1.5(1)-release |
| 10 | +#============================================================================== |
| 11 | + |
| 12 | +today=$(date +%Y%m%d) |
| 13 | +div======================================= |
| 14 | + |
| 15 | +/usr/bin/clear |
| 16 | + |
| 17 | +_select_title(){ |
| 18 | + |
| 19 | + # Get the user input. |
| 20 | + printf "Enter a title: " ; read -r title |
| 21 | + |
| 22 | + # Remove the spaces from the title if necessary. |
| 23 | + title=${title// /_} |
| 24 | + |
| 25 | + # Convert uppercase to lowercase. |
| 26 | + title=${title,,} |
| 27 | + |
| 28 | + # Add .sh to the end of the title if it is not there already. |
| 29 | + [ "${title: -3}" != '.sh' ] && title=${title}.sh |
| 30 | + |
| 31 | + # Check to see if the file exists already. |
| 32 | + if [ -e $title ] ; then |
| 33 | + printf "\n%s\n%s\n\n" "The script \"$title\" already exists." \ |
| 34 | + "Please select another title." |
| 35 | + _select_title |
| 36 | + fi |
| 37 | + |
| 38 | +} |
| 39 | + |
| 40 | +_select_title |
| 41 | + |
| 42 | +printf "Enter a description: " ; read -r dscrpt |
| 43 | +printf "Enter your name: " ; read -r name |
| 44 | +printf "Enter the version number: " ; read -r vnum |
| 45 | + |
| 46 | +# Format the output and write it to a file. |
| 47 | +printf "%-16s\n\ |
| 48 | +%-16s%-8s\n\ |
| 49 | +%-16s%-8s\n\ |
| 50 | +%-16s%-8s\n\ |
| 51 | +%-16s%-8s\n\ |
| 52 | +%-16s%-8s\n\ |
| 53 | +%-16s%-8s\n\ |
| 54 | +%-16s%-8s\n\ |
| 55 | +%-16s%-8s\n\ |
| 56 | +%s\n\n\n" '#!/bin/bash -' '#title' ":$title" '#description' \ |
| 57 | +":${dscrpt}" '#author' ":$name" '#date' ":$today" '#version' \ |
| 58 | +":$vnum" '#usage' ":./$title" '#notes' ':' '#bash_version' \ |
| 59 | +":${BASH_VERSION}" \#$div${div} > $title |
| 60 | + |
| 61 | +# Make the file executable. |
| 62 | +chmod +x $title |
| 63 | + |
| 64 | +/usr/bin/clear |
| 65 | + |
| 66 | +_select_editor(){ |
| 67 | + |
| 68 | + # Select between Vim or Emacs. |
| 69 | + printf "%s\n%s\n%s\n\n" "Select an editor." "1 for Vim." "2 for Emacs." |
| 70 | + read -r editor |
| 71 | + |
| 72 | + # Open the file with the cursor on the twelth line. |
| 73 | + case $editor in |
| 74 | + 1) vim +12 $title |
| 75 | + ;; |
| 76 | + 2) emacs +12 $title & |
| 77 | + ;; |
| 78 | + *) /usr/bin/clear |
| 79 | + printf "%s\n%s\n\n" "I did not understand your selection." \ |
| 80 | + "Press <Ctrl-c> to quit." |
| 81 | + _select_editor |
| 82 | + ;; |
| 83 | + esac |
| 84 | + |
| 85 | +} |
| 86 | + |
| 87 | +_select_editor |
0 commit comments