@kmean/header-maker 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # Header Maker
2
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3
+ [![GitHub release](https://img.shields.io/github/release/KMean/header-maker.svg)](https://github.com/KMean/header-maker/releases/)
4
+
5
+
6
+ Header Maker is a versatile header generation tool for your source code files. It supports multiple languages and provides customizable options like timestamps, footers, custom alignment, multiline titles, and dynamic templates to make your code headers both informative and consistent.
7
+
8
+ ## Features
9
+
10
+ - **Multi-Language Support:**
11
+ Generate headers for Python, SQL, HTML, JavaScript, C, Java, Shell, CSS, PHP, Go, Rust, Lua, Solidity, and more.
12
+
13
+ - **Custom Border:**
14
+ Specify any character for your header's border using the `--char` option.
15
+
16
+ - **Timestamp Integration:**
17
+ Automatically include the current date and time in the header borders with the `--timestamp` flag.
18
+
19
+ - **Footer Block:**
20
+ Append a footer to your header using the `--footer` option for additional notes or end-of-script markers.
21
+
22
+ - **Custom Alignment:**
23
+ Align your header text to the left, center, or right with the `--align` option.
24
+
25
+ - **Multiline Titles:**
26
+ Provide multiple title lines—each non-flag argument is treated as a separate line in your header.
27
+
28
+ - **Template Support:**
29
+ Dynamically insert shell variables and command outputs (e.g., user name, date) into your header using the `--template` option.
30
+
31
+ ## Installation
32
+
33
+ ### Via npm (Recommended)
34
+
35
+ Header Maker is available as an npm package. To install it globally, run:
36
+
37
+ ```bash
38
+ npm install -g @kmean/header-maker
39
+
40
+ ```
41
+ ## Manual Installation from GitHub
42
+ Clone the repository and make the script executable:
43
+
44
+ ```bash
45
+ git clone https://github.com/KMean/header-maker.git
46
+ cd header-maker
47
+ chmod +x bin/header.sh
48
+ ```
49
+ Then run the script directly:
50
+
51
+ ```bash
52
+ ./bin/header.sh --py "My Header Title"
53
+ ```
54
+ ## Installation via install.sh Script
55
+ You can also install Header Maker into /usr/local/bin using the provided install.sh script:
56
+
57
+ ```bash
58
+ curl -o install.sh https://raw.githubusercontent.com/KMean/header-maker/master/install.sh
59
+ chmod +x install.sh
60
+ sudo ./install.sh
61
+ ```
62
+ This downloads the header script and places it as header in /usr/local/bin, allowing you to run:
63
+
64
+ ```bash
65
+ header --py "My Header Title"
66
+ ```
67
+ Note: Installing to /usr/local/bin requires sudo privileges.
68
+
69
+ ## Usage
70
+
71
+ check what options you have by running
72
+ ```bash
73
+ header -h
74
+ ```
75
+ Run the script with your desired options. Here are a few examples:
76
+
77
+ ## Basic Usage
78
+ Generate a simple Solidity header with a centered title:
79
+
80
+ ```bash
81
+ header --sol "My Header Title"
82
+ ```
83
+ Example Output:
84
+ ```bash
85
+ //----------------------------------------------------------------------//
86
+ // My Header Title //
87
+ //----------------------------------------------------------------------//
88
+ ```
89
+ Generate a simple Python header with right aligned title:
90
+ ```bash
91
+ header --py --align right "My Header Title"
92
+ ```
93
+ Example Output:
94
+ ```bash
95
+ #------------------------------------------------------------------------#
96
+ # My Header Title #
97
+ #------------------------------------------------------------------------#
98
+ ```
99
+
100
+ Generate a simple HTML Header with centered Uppercase title
101
+ ```bash
102
+ header --html --uc "My Header Title"
103
+ ```
104
+ Example Output:
105
+ ```
106
+ <!-- ----------------------------------------------------------------- -->
107
+ <!-- MY HEADER TITLE -->
108
+ <!-- ----------------------------------------------------------------- -->
109
+ ```
110
+
111
+ Advanced Usage
112
+ Generate a Solidity header with a timestamp in the border, right-aligned title, dynamic template, and a footer:
113
+
114
+ ```bash
115
+ header --sol --timestamp --template "Author: \$USER, Date: \$(date '+%Y-%m-%d')" --footer "END OF SCRIPT" "Custom Header Title" "Additional Info"
116
+ ```
117
+
118
+ Example Output:
119
+
120
+ ```bash
121
+ //------------------------ 2025-02-14 19:51:19 -------------------------//
122
+ // Custom Header Title //
123
+ // Additional Info //
124
+ // Author: kmean, Date: 2025-02-14 //
125
+ //------------------------ 2025-02-14 19:51:19 -------------------------//
126
+
127
+ //----------------------------------------------------------------------//
128
+ // END OF SCRIPT //
129
+ //----------------------------------------------------------------------//
130
+ ```
131
+ ## Custom Border Example
132
+ Generate an HTML header with a custom border character (+):
133
+
134
+ ```bash
135
+ header --html --char "+" "My Header Title"
136
+ ```
137
+ Example Output:
138
+
139
+ ```bash
140
+ <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
141
+ <!-- My Header Title -->
142
+ <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
143
+ ```
144
+ ## Contributing
145
+ Contributions are welcome! Feel free to fork the repository, open issues, and submit pull requests for improvements or additional features.
package/bin/header.sh ADDED
@@ -0,0 +1,330 @@
1
+ #!/bin/bash
2
+ # Extended header generator with timestamp, footer, alignment, multiline, and template support
3
+
4
+ # Default values
5
+ TOTAL_WIDTH=74
6
+ CUSTOM_PADDING=-1 # -1 means auto-calculate padding
7
+ UPPERCASE=false
8
+ BORDER_CHAR="-" # Default border character
9
+ ALIGN="center" # Alignment options: left, center, right
10
+ TIMESTAMP=false
11
+ FOOTER="" # Footer text (optional)
12
+ TEMPLATE="" # Template text (optional)
13
+
14
+ # Flags to indicate next parameter value
15
+ NEXT_IS_CHAR=0
16
+ NEXT_IS_WIDTH=0
17
+ NEXT_IS_PADDING=0
18
+ NEXT_IS_FOOTER=0
19
+ NEXT_IS_ALIGN=0
20
+ NEXT_IS_TEMPLATE=0
21
+
22
+ # Array to hold one or more title lines
23
+ declare -a TITLE_LINES=()
24
+
25
+ usage() {
26
+ echo "Usage: header [--py | --html | --sql | --js | --c | --java | --sh | --css | --php | --go | --rs | --lua | --sol] [options] <title lines>"
27
+ echo ""
28
+ echo "Options:"
29
+ echo " --py Python header (#)"
30
+ echo " --sql SQL header (--)"
31
+ echo " --html HTML header (<!-- -->)"
32
+ echo " --js JavaScript header (//)"
33
+ echo " --c C/C++ header (//)"
34
+ echo " --java Java header (//)"
35
+ echo " --sh Shell/Bash header (#)"
36
+ echo " --css CSS header (/* */)"
37
+ echo " --php PHP header (//)"
38
+ echo " --go Go header (//)"
39
+ echo " --rs Rust header (//)"
40
+ echo " --lua Lua header (--)"
41
+ echo " --sol Solidity header (// or /* */)"
42
+ echo " --width Set custom total width (default: 74)"
43
+ echo " --padding Set custom padding width (default: auto)"
44
+ echo " --char Set custom border character (default: '-')"
45
+ echo " --align Set alignment: left, center, or right (default: center)"
46
+ echo " --timestamp Insert current timestamp in the border lines"
47
+ echo " --template Add a template line (supports shell variables, e.g. \$USER, \$(date))"
48
+ echo " --footer Add a footer block below the header"
49
+ echo " --uppercase or --uc Convert title (and template/footer) to uppercase"
50
+ echo " --help Show this help message"
51
+ exit 0
52
+ }
53
+
54
+ # If no arguments or help flag, display usage.
55
+ if [ "$#" -eq 0 ] || [[ "$1" == "--help" || "$1" == "--h" ]]; then
56
+ usage
57
+ fi
58
+
59
+ # Initialize variables for comment style.
60
+ COMMENT_CHAR=""
61
+ COMMENT_START=""
62
+ COMMENT_END=""
63
+ LANGUAGE_FLAG=""
64
+
65
+ # Parse arguments
66
+ while [[ $# -gt 0 ]]; do
67
+ case "$1" in
68
+ --py|--sh)
69
+ COMMENT_CHAR="#"
70
+ LANGUAGE_FLAG="$1"
71
+ ;;
72
+ --sql|--lua)
73
+ COMMENT_CHAR="--"
74
+ LANGUAGE_FLAG="$1"
75
+ ;;
76
+ --html)
77
+ COMMENT_START="<!--"
78
+ COMMENT_END="-->"
79
+ LANGUAGE_FLAG="$1"
80
+ ;;
81
+ --js|--c|--java|--php|--go|--rs|--sol)
82
+ COMMENT_CHAR="//"
83
+ LANGUAGE_FLAG="$1"
84
+ ;;
85
+ --css|--sol-block)
86
+ COMMENT_START="/*"
87
+ COMMENT_END="*/"
88
+ LANGUAGE_FLAG="$1"
89
+ ;;
90
+ --width)
91
+ NEXT_IS_WIDTH=1
92
+ ;;
93
+ --padding)
94
+ NEXT_IS_PADDING=1
95
+ ;;
96
+ --char)
97
+ NEXT_IS_CHAR=1
98
+ ;;
99
+ --align)
100
+ NEXT_IS_ALIGN=1
101
+ ;;
102
+ --timestamp)
103
+ TIMESTAMP=true
104
+ ;;
105
+ --template)
106
+ NEXT_IS_TEMPLATE=1
107
+ ;;
108
+ --footer)
109
+ NEXT_IS_FOOTER=1
110
+ ;;
111
+ --uppercase|--uc)
112
+ UPPERCASE=true
113
+ ;;
114
+ *)
115
+ if [ "$NEXT_IS_WIDTH" -eq 1 ]; then
116
+ if [[ "$1" =~ ^[0-9]+$ ]] && [ "$1" -gt 10 ]; then
117
+ TOTAL_WIDTH="$1"
118
+ NEXT_IS_WIDTH=0
119
+ else
120
+ echo "Error: Invalid width. Must be a number greater than 10."
121
+ exit 1
122
+ fi
123
+ elif [ "$NEXT_IS_PADDING" -eq 1 ]; then
124
+ if [[ "$1" =~ ^[0-9]+$ ]] && [ "$1" -ge 0 ]; then
125
+ CUSTOM_PADDING="$1"
126
+ NEXT_IS_PADDING=0
127
+ else
128
+ echo "Error: Invalid padding. Must be a non-negative number."
129
+ exit 1
130
+ fi
131
+ elif [ "$NEXT_IS_CHAR" -eq 1 ]; then
132
+ BORDER_CHAR="${1:0:1}"
133
+ NEXT_IS_CHAR=0
134
+ elif [ "$NEXT_IS_ALIGN" -eq 1 ]; then
135
+ case "$1" in
136
+ left|center|right)
137
+ ALIGN="$1"
138
+ ;;
139
+ *)
140
+ echo "Error: Alignment must be one of: left, center, right."
141
+ exit 1
142
+ ;;
143
+ esac
144
+ NEXT_IS_ALIGN=0
145
+ elif [ "$NEXT_IS_TEMPLATE" -eq 1 ]; then
146
+ TEMPLATE="$1"
147
+ NEXT_IS_TEMPLATE=0
148
+ elif [ "$NEXT_IS_FOOTER" -eq 1 ]; then
149
+ FOOTER="$1"
150
+ NEXT_IS_FOOTER=0
151
+ else
152
+ # Accumulate each non-flag argument as a separate title line.
153
+ TITLE_LINES+=( "$1" )
154
+ fi
155
+ ;;
156
+ esac
157
+ shift
158
+ done
159
+
160
+ # If no title lines were provided, show usage.
161
+ if [ ${#TITLE_LINES[@]} -eq 0 ]; then
162
+ echo "Error: No title provided."
163
+ usage
164
+ fi
165
+
166
+ # Optionally convert title lines, template, and footer to uppercase.
167
+ if $UPPERCASE; then
168
+ for i in "${!TITLE_LINES[@]}"; do
169
+ TITLE_LINES[$i]=$(echo "${TITLE_LINES[$i]}" | tr '[:lower:]' '[:upper:]')
170
+ done
171
+ TEMPLATE=$(echo "$TEMPLATE" | tr '[:lower:]' '[:upper:]')
172
+ FOOTER=$(echo "$FOOTER" | tr '[:lower:]' '[:upper:]')
173
+ fi
174
+
175
+ # Ensure a language flag was selected.
176
+ if [ -z "$LANGUAGE_FLAG" ]; then
177
+ echo "Error: You must specify a language flag (e.g., --py, --sql, --sol)."
178
+ usage
179
+ fi
180
+
181
+ # ---------------------------
182
+ # Function to create a repeated string of a given character
183
+ repeat_char() {
184
+ local count="$1"
185
+ local char="$2"
186
+ printf "%*s" "$count" "" | tr ' ' "$char"
187
+ }
188
+
189
+ # ---------------------------
190
+ # Function to print a formatted line for block comment styles.
191
+ # It calculates left/right padding based on dash_length (global variable in block section).
192
+ print_text_line_block() {
193
+ local text="$1"
194
+ local text_length=${#text}
195
+ local left_spaces=0
196
+ local right_spaces=0
197
+ if [ "$CUSTOM_PADDING" -ge 0 ]; then
198
+ left_spaces="$CUSTOM_PADDING"
199
+ right_spaces=$(( dash_length - text_length - left_spaces ))
200
+ [ "$right_spaces" -lt 0 ] && right_spaces=0
201
+ else
202
+ case "$ALIGN" in
203
+ left)
204
+ left_spaces=0
205
+ right_spaces=$(( dash_length - text_length ))
206
+ ;;
207
+ right)
208
+ left_spaces=$(( dash_length - text_length ))
209
+ right_spaces=0
210
+ ;;
211
+ center)
212
+ left_spaces=$(( (dash_length - text_length) / 2 ))
213
+ right_spaces=$(( dash_length - text_length - left_spaces ))
214
+ ;;
215
+ esac
216
+ fi
217
+ left_pad=$(repeat_char "$left_spaces" " ")
218
+ right_pad=$(repeat_char "$right_spaces" " ")
219
+ printf "%s %s%s%s %s\n" "$COMMENT_START" "$left_pad" "$text" "$right_pad" "$COMMENT_END"
220
+ }
221
+
222
+ # ---------------------------
223
+ # Print header for single-line comment markers (e.g. #, //, --)
224
+ if [[ "$COMMENT_CHAR" ]]; then
225
+ comment_len=${#COMMENT_CHAR}
226
+ avail_width=$(( TOTAL_WIDTH - 2 * comment_len ))
227
+
228
+ # Function to build a border line.
229
+ build_border_line() {
230
+ local bw="$1" # available width
231
+ if $TIMESTAMP; then
232
+ local ts
233
+ ts=$(date '+%Y-%m-%d %H:%M:%S')
234
+ local ts_length=${#ts}
235
+ # Total space taken by timestamp including one space on each side.
236
+ local ts_total=$(( ts_length + 2 ))
237
+ # Calculate left and right border lengths
238
+ local left_len=$(( (bw - ts_total) / 2 ))
239
+ local right_len=$(( bw - ts_total - left_len ))
240
+ echo "$(repeat_char "$left_len" "$BORDER_CHAR") $ts $(repeat_char "$right_len" "$BORDER_CHAR")"
241
+ else
242
+ echo "$(repeat_char "$bw" "$BORDER_CHAR")"
243
+ fi
244
+ }
245
+
246
+ BORDER_LINE=$(build_border_line "$avail_width")
247
+
248
+ # Print top border
249
+ echo "${COMMENT_CHAR}${BORDER_LINE}${COMMENT_CHAR}"
250
+
251
+ # Function to print a formatted line for single-line comments.
252
+ print_text_line() {
253
+ local text="$1"
254
+ local text_length=${#text}
255
+ local left_spaces=0
256
+ local right_spaces=0
257
+ if [ "$CUSTOM_PADDING" -ge 0 ]; then
258
+ left_spaces="$CUSTOM_PADDING"
259
+ right_spaces=$(( avail_width - text_length - left_spaces ))
260
+ [ "$right_spaces" -lt 0 ] && right_spaces=0
261
+ else
262
+ case "$ALIGN" in
263
+ left)
264
+ left_spaces=1
265
+ right_spaces=$(( avail_width - text_length - left_spaces ))
266
+ ;;
267
+ right)
268
+ left_spaces=$(( avail_width - text_length - 1 ))
269
+ right_spaces=1
270
+ ;;
271
+ center)
272
+ left_spaces=$(( (avail_width - text_length) / 2 ))
273
+ right_spaces=$(( avail_width - text_length - left_spaces ))
274
+ ;;
275
+ esac
276
+ fi
277
+ left_pad=$(repeat_char "$left_spaces" " ")
278
+ right_pad=$(repeat_char "$right_spaces" " ")
279
+ printf "%s%s%s%s%s\n" "${COMMENT_CHAR}" "${left_pad}" "${text}" "${right_pad}" "${COMMENT_CHAR}"
280
+ }
281
+
282
+ # Print each title line.
283
+ for line in "${TITLE_LINES[@]}"; do
284
+ print_text_line "$line"
285
+ done
286
+
287
+ # If a template is provided, evaluate it and print.
288
+ if [ -n "$TEMPLATE" ]; then
289
+ eval_template=$(eval "echo \"$TEMPLATE\"")
290
+ print_text_line "$eval_template"
291
+ fi
292
+
293
+ # Print bottom border (same as top)
294
+ echo "${COMMENT_CHAR}${BORDER_LINE}${COMMENT_CHAR}"
295
+
296
+ # If footer text is provided, print a footer block.
297
+ if [ -n "$FOOTER" ]; then
298
+ echo "" # blank line between header and footer
299
+ footer_border=$(repeat_char "$avail_width" "$BORDER_CHAR")
300
+ echo "${COMMENT_CHAR}${footer_border}${COMMENT_CHAR}"
301
+ print_text_line "$FOOTER"
302
+ echo "${COMMENT_CHAR}${footer_border}${COMMENT_CHAR}"
303
+ fi
304
+
305
+ # ---------------------------
306
+ # For languages using block comments (HTML, CSS, etc.)
307
+ elif [[ "$COMMENT_START" && "$COMMENT_END" ]]; then
308
+ dash_length=$(( TOTAL_WIDTH - ${#COMMENT_START} - ${#COMMENT_END} - 2 ))
309
+ DASHES=$(repeat_char "$dash_length" "$BORDER_CHAR")
310
+ echo "$COMMENT_START $DASHES $COMMENT_END"
311
+
312
+ # Print each title line using the block comment alignment function.
313
+ for line in "${TITLE_LINES[@]}"; do
314
+ print_text_line_block "$line"
315
+ done
316
+
317
+ if [ -n "$TEMPLATE" ]; then
318
+ eval_template=$(eval "echo \"$TEMPLATE\"")
319
+ print_text_line_block "$eval_template"
320
+ fi
321
+
322
+ echo "$COMMENT_START $DASHES $COMMENT_END"
323
+
324
+ if [ -n "$FOOTER" ]; then
325
+ echo "" # blank line
326
+ echo "$COMMENT_START $DASHES $COMMENT_END"
327
+ print_text_line_block "$FOOTER"
328
+ echo "$COMMENT_START $DASHES $COMMENT_END"
329
+ fi
330
+ fi
package/install.sh ADDED
@@ -0,0 +1,16 @@
1
+ #!/bin/bash
2
+
3
+ INSTALL_DIR="/usr/local/bin"
4
+ SCRIPT_NAME="header"
5
+
6
+ # Download the header.sh script from GitHub and save it as 'header'
7
+ curl -o "$INSTALL_DIR/$SCRIPT_NAME" "https://raw.githubusercontent.com/KMean/header-maker/master/bin/header.sh" || {
8
+ echo "Error downloading the script."
9
+ exit 1
10
+ }
11
+
12
+ # Make it executable
13
+ chmod +x "$INSTALL_DIR/$SCRIPT_NAME"
14
+
15
+ echo "Installation complete! Use 'header --py \"YOUR AWESOME HEADER\"' to generate headers."
16
+ echo "For more information, visit https://github.com/KMean/header-maker."
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@kmean/header-maker",
3
+ "version": "1.0.2",
4
+ "description": "A versatile header generator for source code files.",
5
+ "bin": {
6
+ "header": "bin/header.sh"
7
+ },
8
+ "scripts": {
9
+ "test": "echo \"No tests yet\""
10
+ },
11
+ "keywords": [
12
+ "header",
13
+ "generator",
14
+ "cli",
15
+ "bash",
16
+ "tool"
17
+ ],
18
+ "author": "Kim Ranzani - KMean",
19
+ "license": "MIT"
20
+ }