@objctp/opencode-shell-routines 1.2.0
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/LICENSE +21 -0
- package/README.md +114 -0
- package/agents/shell-architect.md +88 -0
- package/agents/shell-expert.md +60 -0
- package/commands/shell-audit.md +47 -0
- package/commands/shell-batch-exec.md +48 -0
- package/commands/shell-new.md +57 -0
- package/commands/shell-routines-setup.md +66 -0
- package/commands/shell-test-run.md +46 -0
- package/opencode.json +19 -0
- package/package.json +34 -0
- package/plugins/shell-hooks.ts +150 -0
- package/scripts/lib-batch.sh +297 -0
- package/scripts/lib-common.sh +332 -0
- package/skills/shell-batch-operations/SKILL.md +97 -0
- package/skills/shell-batch-operations/assets/batch-template.sh +124 -0
- package/skills/shell-batch-operations/examples/data-pipeline.sh +157 -0
- package/skills/shell-batch-operations/examples/file-batch.sh +140 -0
- package/skills/shell-batch-operations/references/decision-tree.md +53 -0
- package/skills/shell-best-practices/SKILL.md +313 -0
- package/skills/shell-best-practices/assets/library.sh +142 -0
- package/skills/shell-best-practices/assets/minimal.sh +54 -0
- package/skills/shell-best-practices/assets/posix.sh +180 -0
- package/skills/shell-best-practices/assets/standard.sh +203 -0
- package/skills/shell-best-practices/references/patterns.md +386 -0
- package/skills/shell-best-practices/references/security.md +195 -0
- package/skills/shell-debugging/SKILL.md +115 -0
- package/skills/shell-debugging/examples/debug-session.md +165 -0
- package/skills/shell-debugging/references/debugging-guide.md +336 -0
- package/skills/shell-profiling/SKILL.md +154 -0
- package/skills/shell-profiling/examples/profile-session.md +225 -0
- package/skills/shell-profiling/references/optimisation-patterns.md +373 -0
- package/skills/shell-profiling/references/profiling-tools.md +318 -0
- package/skills/shell-profiling/scripts/bench.sh +82 -0
- package/skills/shell-profiling/scripts/trace-aggregate.sh +34 -0
- package/skills/shell-review/SKILL.md +61 -0
- package/skills/shell-review/examples/sample-review.md +42 -0
- package/skills/shell-review/references/guidelines.md +48 -0
- package/skills/shell-review/references/review-template.md +56 -0
- package/skills/shell-security/SKILL.md +128 -0
- package/skills/shell-security/examples/dangerous-command-review.md +231 -0
- package/skills/shell-security/examples/secure-script-example.sh +317 -0
- package/skills/shell-security/references/dangerous-commands.md +561 -0
- package/skills/shell-security/references/security-patterns.md +30 -0
- package/skills/shell-security/references/sensitive-files.md +525 -0
- package/skills/shell-security/scripts/security-audit.sh +208 -0
- package/skills/shell-test/SKILL.md +237 -0
- package/skills/shell-test/examples/test-example.md +74 -0
- package/skills/shell-test/references/advanced-patterns.md +52 -0
- package/skills/shell-test/references/assertions.md +184 -0
- package/skills/shell-test/references/test-template.md +60 -0
- package/skills/shell-test/scripts/public-coverage.sh +93 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#
|
|
3
|
+
# Description: [BRIEF DESCRIPTION OF WHAT THIS SCRIPT DOES]
|
|
4
|
+
# Usage: [SCRIPT_NAME] [ARGUMENTS]
|
|
5
|
+
#
|
|
6
|
+
# Arguments:
|
|
7
|
+
# $1 - [FIRST_ARGUMENT]: [DESCRIPTION]
|
|
8
|
+
#
|
|
9
|
+
# Options:
|
|
10
|
+
# -h Show this help message
|
|
11
|
+
# -v Enable verbose output
|
|
12
|
+
#
|
|
13
|
+
# Examples:
|
|
14
|
+
# [SCRIPT_NAME] input.txt
|
|
15
|
+
# [SCRIPT_NAME] -v data.txt
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
set -eu
|
|
19
|
+
|
|
20
|
+
###
|
|
21
|
+
### :::: Constants :::: ###############
|
|
22
|
+
###
|
|
23
|
+
|
|
24
|
+
# shellcheck disable=SC2034 # template placeholder, used after scaffolding
|
|
25
|
+
script_name=$(basename "$0")
|
|
26
|
+
# shellcheck disable=SC2034
|
|
27
|
+
readonly script_name
|
|
28
|
+
|
|
29
|
+
###
|
|
30
|
+
### :::: Globals :::: #################
|
|
31
|
+
###
|
|
32
|
+
|
|
33
|
+
VERBOSE=0
|
|
34
|
+
|
|
35
|
+
###
|
|
36
|
+
### :::: Private functions :::: #######
|
|
37
|
+
###
|
|
38
|
+
|
|
39
|
+
# Logging
|
|
40
|
+
_log_info() {
|
|
41
|
+
printf '[INFO] %s\n' "$*" >&2
|
|
42
|
+
return 0
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_log_warn() {
|
|
46
|
+
printf '[WARN] %s\n' "$*" >&2
|
|
47
|
+
return 0
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_log_error() {
|
|
51
|
+
printf '[ERROR] %s\n' "$*" >&2
|
|
52
|
+
return 0
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_log_debug() {
|
|
56
|
+
[ "$VERBOSE" -eq 1 ] && printf '[DEBUG] %s\n' "$*" >&2
|
|
57
|
+
return 0
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# Display help message
|
|
61
|
+
_show_help() {
|
|
62
|
+
cat <<'EOF'
|
|
63
|
+
Usage: [SCRIPT_NAME] [OPTIONS] [ARGUMENTS]
|
|
64
|
+
|
|
65
|
+
Arguments:
|
|
66
|
+
$1 - [FIRST_ARGUMENT]: [DESCRIPTION]
|
|
67
|
+
|
|
68
|
+
Options:
|
|
69
|
+
-h Show this help message
|
|
70
|
+
-v Enable verbose output
|
|
71
|
+
|
|
72
|
+
Examples:
|
|
73
|
+
[SCRIPT_NAME] input.txt
|
|
74
|
+
[SCRIPT_NAME] -v data.txt
|
|
75
|
+
EOF
|
|
76
|
+
exit 0
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# Cleanup
|
|
80
|
+
_cleanup() {
|
|
81
|
+
_log_debug "Cleaning up..."
|
|
82
|
+
# Remove temporary files here
|
|
83
|
+
# rm -f "$tmp_file"
|
|
84
|
+
return 0
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
trap _cleanup EXIT INT TERM HUP
|
|
88
|
+
|
|
89
|
+
# Validate inputs
|
|
90
|
+
# shellcheck disable=SC3043 # local is widely supported in POSIX-compatible shells
|
|
91
|
+
_validate_inputs() {
|
|
92
|
+
local input="$1"
|
|
93
|
+
|
|
94
|
+
if [ -z "$input" ]; then
|
|
95
|
+
_log_error "Input is required"
|
|
96
|
+
_show_help
|
|
97
|
+
# shellcheck disable=SC2317
|
|
98
|
+
exit 2
|
|
99
|
+
fi
|
|
100
|
+
|
|
101
|
+
if [ ! -r "$input" ]; then
|
|
102
|
+
_log_error "Cannot read: $input"
|
|
103
|
+
exit 1
|
|
104
|
+
fi
|
|
105
|
+
|
|
106
|
+
return 0
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# Main processing function
|
|
110
|
+
# shellcheck disable=SC3043 # local is widely supported in POSIX-compatible shells
|
|
111
|
+
_process() {
|
|
112
|
+
local input_path="$1"
|
|
113
|
+
|
|
114
|
+
_log_info "Processing: $input_path"
|
|
115
|
+
|
|
116
|
+
# Your processing logic here
|
|
117
|
+
while IFS= read -r line; do
|
|
118
|
+
printf '%s\n' "$line"
|
|
119
|
+
done <"$input_path"
|
|
120
|
+
|
|
121
|
+
_log_info "Complete"
|
|
122
|
+
return 0
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
###
|
|
126
|
+
### :::: Public functions :::: ########
|
|
127
|
+
###
|
|
128
|
+
|
|
129
|
+
# Main entry point
|
|
130
|
+
# POSIX sh does not support :: in function names.
|
|
131
|
+
# Use shroutines_ prefix with single underscore separator.
|
|
132
|
+
shroutines_main() {
|
|
133
|
+
# Parse command-line arguments
|
|
134
|
+
while [ $# -gt 0 ]; do
|
|
135
|
+
case "$1" in
|
|
136
|
+
-h)
|
|
137
|
+
_show_help
|
|
138
|
+
;;
|
|
139
|
+
-v)
|
|
140
|
+
VERBOSE=1
|
|
141
|
+
shift
|
|
142
|
+
;;
|
|
143
|
+
--)
|
|
144
|
+
shift
|
|
145
|
+
break
|
|
146
|
+
;;
|
|
147
|
+
-*)
|
|
148
|
+
_log_error "Unknown option: $1"
|
|
149
|
+
_show_help
|
|
150
|
+
# shellcheck disable=SC2317
|
|
151
|
+
exit 2
|
|
152
|
+
;;
|
|
153
|
+
*)
|
|
154
|
+
break
|
|
155
|
+
;;
|
|
156
|
+
esac
|
|
157
|
+
done
|
|
158
|
+
|
|
159
|
+
# Check for required arguments
|
|
160
|
+
if [ $# -lt 1 ]; then
|
|
161
|
+
_log_error "Missing required arguments"
|
|
162
|
+
_show_help
|
|
163
|
+
# shellcheck disable=SC2317
|
|
164
|
+
exit 2
|
|
165
|
+
fi
|
|
166
|
+
|
|
167
|
+
_validate_inputs "$1"
|
|
168
|
+
_process "$1"
|
|
169
|
+
return 0
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
###
|
|
173
|
+
### :::: Guard and execution :::: #####
|
|
174
|
+
###
|
|
175
|
+
|
|
176
|
+
# POSIX sh has no BASH_SOURCE equivalent.
|
|
177
|
+
# Test files should set _SKIP_MAIN=1 before sourcing this script.
|
|
178
|
+
if [ -z "${_SKIP_MAIN:-}" ]; then
|
|
179
|
+
shroutines_main "$@"
|
|
180
|
+
fi
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# Description: [BRIEF DESCRIPTION OF WHAT THIS SCRIPT DOES]
|
|
4
|
+
# Usage: [SCRIPT_NAME] [ARGUMENTS]
|
|
5
|
+
#
|
|
6
|
+
# Arguments:
|
|
7
|
+
# $1 - [FIRST_ARGUMENT]: [DESCRIPTION]
|
|
8
|
+
# $2 - [SECOND_ARGUMENT]: [DESCRIPTION]
|
|
9
|
+
#
|
|
10
|
+
# Options:
|
|
11
|
+
# -h, --help Show this help message
|
|
12
|
+
# -v, --verbose Enable verbose output
|
|
13
|
+
# -o FILE Output to FILE instead of stdout
|
|
14
|
+
#
|
|
15
|
+
# Examples:
|
|
16
|
+
# [SCRIPT_NAME] input.txt output.txt
|
|
17
|
+
# [SCRIPT_NAME] --verbose --output result.txt data.txt
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
set -euo pipefail
|
|
21
|
+
|
|
22
|
+
###
|
|
23
|
+
### :::: Constants :::: ###############
|
|
24
|
+
###
|
|
25
|
+
|
|
26
|
+
SCRIPT_NAME=${0##*/}
|
|
27
|
+
# shellcheck disable=SC2034 # template placeholder, used after scaffolding
|
|
28
|
+
readonly SCRIPT_NAME
|
|
29
|
+
# shellcheck disable=SC2034
|
|
30
|
+
readonly VERSION="0.1.0"
|
|
31
|
+
|
|
32
|
+
###
|
|
33
|
+
### :::: Globals :::: #################
|
|
34
|
+
###
|
|
35
|
+
|
|
36
|
+
VERBOSE=0
|
|
37
|
+
OUTPUT_FILE=""
|
|
38
|
+
|
|
39
|
+
###
|
|
40
|
+
### :::: Private functions :::: #######
|
|
41
|
+
###
|
|
42
|
+
|
|
43
|
+
# Logging
|
|
44
|
+
function _log_info() {
|
|
45
|
+
printf '[INFO] %s\n' "$*" >&2
|
|
46
|
+
return 0
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function _log_warn() {
|
|
50
|
+
printf '[WARN] %s\n' "$*" >&2
|
|
51
|
+
return 0
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _log_error() {
|
|
55
|
+
printf '[ERROR] %s\n' "$*" >&2
|
|
56
|
+
return 0
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function _log_debug() {
|
|
60
|
+
if ((VERBOSE)); then
|
|
61
|
+
printf '[DEBUG] %s\n' "$*" >&2
|
|
62
|
+
fi
|
|
63
|
+
return 0
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
# Display help message
|
|
67
|
+
function _show_help() {
|
|
68
|
+
cat <<'EOF'
|
|
69
|
+
Usage: [SCRIPT_NAME] [OPTIONS] [ARGUMENTS]
|
|
70
|
+
|
|
71
|
+
Arguments:
|
|
72
|
+
$1 - [FIRST_ARGUMENT]: [DESCRIPTION]
|
|
73
|
+
$2 - [SECOND_ARGUMENT]: [DESCRIPTION]
|
|
74
|
+
|
|
75
|
+
Options:
|
|
76
|
+
-h, --help Show this help message
|
|
77
|
+
-v, --verbose Enable verbose output
|
|
78
|
+
-o FILE Output to FILE instead of stdout
|
|
79
|
+
|
|
80
|
+
Examples:
|
|
81
|
+
[SCRIPT_NAME] input.txt output.txt
|
|
82
|
+
[SCRIPT_NAME] --verbose --output result.txt data.txt
|
|
83
|
+
EOF
|
|
84
|
+
exit 0
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# Cleanup
|
|
88
|
+
function _cleanup() {
|
|
89
|
+
_log_debug "Cleaning up..."
|
|
90
|
+
# Remove temporary files here
|
|
91
|
+
# rm -f "$tmp_file"
|
|
92
|
+
return 0
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
trap _cleanup EXIT INT TERM HUP
|
|
96
|
+
|
|
97
|
+
# Validate inputs
|
|
98
|
+
function _validate_inputs() {
|
|
99
|
+
local input="$1"
|
|
100
|
+
|
|
101
|
+
if [[ -z "$input" ]]; then
|
|
102
|
+
_log_error "Input file is required"
|
|
103
|
+
_show_help
|
|
104
|
+
# shellcheck disable=SC2317
|
|
105
|
+
exit 2
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
if [[ ! -r "$input" ]]; then
|
|
109
|
+
_log_error "Cannot read file: $input"
|
|
110
|
+
exit 1
|
|
111
|
+
fi
|
|
112
|
+
|
|
113
|
+
return 0
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# Parse command-line arguments
|
|
117
|
+
function _parse_args() {
|
|
118
|
+
while [[ $# -gt 0 ]]; do
|
|
119
|
+
case "$1" in
|
|
120
|
+
-h | --help)
|
|
121
|
+
_show_help
|
|
122
|
+
;;
|
|
123
|
+
-v | --verbose)
|
|
124
|
+
VERBOSE=1
|
|
125
|
+
shift
|
|
126
|
+
;;
|
|
127
|
+
-o | --output)
|
|
128
|
+
OUTPUT_FILE="$2"
|
|
129
|
+
shift 2
|
|
130
|
+
;;
|
|
131
|
+
--)
|
|
132
|
+
shift
|
|
133
|
+
break
|
|
134
|
+
;;
|
|
135
|
+
-*)
|
|
136
|
+
_log_error "Unknown option: $1"
|
|
137
|
+
_show_help
|
|
138
|
+
# shellcheck disable=SC2317
|
|
139
|
+
exit 2
|
|
140
|
+
;;
|
|
141
|
+
*)
|
|
142
|
+
break
|
|
143
|
+
;;
|
|
144
|
+
esac
|
|
145
|
+
done
|
|
146
|
+
|
|
147
|
+
REMAINING_ARGS=("$@")
|
|
148
|
+
return 0
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
###
|
|
152
|
+
### :::: Public functions :::: ########
|
|
153
|
+
###
|
|
154
|
+
|
|
155
|
+
# Main processing function
|
|
156
|
+
function shroutines::process_file() {
|
|
157
|
+
local input_path="$1"
|
|
158
|
+
local output="${2:-/dev/stdout}"
|
|
159
|
+
|
|
160
|
+
_log_info "Processing: $input_path"
|
|
161
|
+
|
|
162
|
+
# Your processing logic here
|
|
163
|
+
while IFS= read -r line; do
|
|
164
|
+
# Process each line
|
|
165
|
+
echo "$line"
|
|
166
|
+
done <"$input_path" >"$output"
|
|
167
|
+
|
|
168
|
+
_log_info "Complete: $output"
|
|
169
|
+
return 0
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
# Main entry point
|
|
173
|
+
function shroutines::main() {
|
|
174
|
+
_parse_args "$@"
|
|
175
|
+
|
|
176
|
+
# Check for required arguments
|
|
177
|
+
if [[ ${#REMAINING_ARGS[@]} -lt 1 ]]; then
|
|
178
|
+
_log_error "Missing required arguments"
|
|
179
|
+
_show_help
|
|
180
|
+
# shellcheck disable=SC2317
|
|
181
|
+
exit 2
|
|
182
|
+
fi
|
|
183
|
+
|
|
184
|
+
local input_file="${REMAINING_ARGS[0]}"
|
|
185
|
+
_validate_inputs "$input_file"
|
|
186
|
+
|
|
187
|
+
# Process file
|
|
188
|
+
if [[ -n "$OUTPUT_FILE" ]]; then
|
|
189
|
+
shroutines::process_file "$input_file" "$OUTPUT_FILE"
|
|
190
|
+
else
|
|
191
|
+
shroutines::process_file "$input_file"
|
|
192
|
+
fi
|
|
193
|
+
|
|
194
|
+
return 0
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
###
|
|
198
|
+
### :::: Guard and execution :::: #####
|
|
199
|
+
###
|
|
200
|
+
|
|
201
|
+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
202
|
+
shroutines::main "$@"
|
|
203
|
+
fi
|