-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.sh
More file actions
executable file
Β·234 lines (184 loc) Β· 6.54 KB
/
Copy pathpackage.sh
File metadata and controls
executable file
Β·234 lines (184 loc) Β· 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/bash
# dt packaging script
# Build a distributable bundle with binary and docs
set -e
PROJECT_NAME="dt"
# Read version from Cargo.toml
VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)
TARGET_DIR="target/release"
BINARY_NAME="dt"
PACKAGE_NAME="${PROJECT_NAME}-${VERSION}"
echo "π¦ Start packaging ${PROJECT_NAME} v${VERSION}..."
# Create package directory
mkdir -p "package/${PACKAGE_NAME}"
# Build release binary to ensure latest changes are packaged
echo "π¨ Building release binary..."
cargo build --release >/dev/null
# Copy binary
echo "π Copying binary..."
cp "${TARGET_DIR}/${BINARY_NAME}" "package/${PACKAGE_NAME}/"
# Copy docs
echo "π Copying docs..."
cp "README.md" "package/${PACKAGE_NAME}/" 2>/dev/null || echo "β οΈ README.md missing"
cp "LICENSE" "package/${PACKAGE_NAME}/" 2>/dev/null || echo "β οΈ LICENSE missing"
cp "THIRD_PARTY_NOTICES.md" "package/${PACKAGE_NAME}/" 2>/dev/null || echo "β οΈ THIRD_PARTY_NOTICES.md missing"
# Generate third-party dependency report (prefers cargo-about, falls back to cargo-license)
echo "π Generating third-party dependency report..."
REPORT_OUT_MD="package/${PACKAGE_NAME}/THIRD_PARTY_DEPENDENCIES.md"
REPORT_OUT_JSON="package/${PACKAGE_NAME}/THIRD_PARTY_DEPENDENCIES.json"
if command -v cargo-about >/dev/null 2>&1; then
TEMPLATE="package/about_template.hbs"
CONFIG="package/about.hjson"
if [[ -f "$TEMPLATE" && -f "$CONFIG" ]]; then
cargo about generate "$CONFIG" "$TEMPLATE" --workspace -o "$REPORT_OUT_MD" >/dev/null || {
echo "β οΈ cargo-about generation failed; continuing";
}
else
echo "β οΈ Missing cargo-about template or config (package/about_template.hbs, package/about.hjson)"
fi
elif command -v cargo-license >/dev/null 2>&1; then
cargo license --json > "$REPORT_OUT_JSON" || echo "β οΈ cargo-license failed; continuing"
else
echo "β οΈ Neither cargo-about nor cargo-license found; skipping generation"
fi
# Maintain a stable symlink to the latest package for demos/recordings
ln -sfn "${PACKAGE_NAME}" "package/latest"
# Create English usage guide
cat > "package/${PACKAGE_NAME}/USAGE.md" << 'EOF'
# dt - Command Execution Time Diff Tool
## Installation
1. Copy the `dt` binary to a directory in your PATH, for example:
```bash
sudo cp dt /usr/local/bin/
```
2. Or use it directly in the current directory:
```bash
./dt --help
```
## Basic Usage
### Execute commands and record
```bash
# Simple commands
dt run "ls -la"
# Commands with pipes (need to be quoted)
dt run "ls | head -5"
dt run "ps aux | grep dt"
dt run "find . -name '*.rs' | wc -l"
# Run and immediately diff with a short code (-d is alias for --diff-code)
dt run -d ab "ls | head -5"
```
### Compare command output differences
```bash
# Compare different executions of the same command
dt diff "ls | head -5"
# Force strict line-by-line comparison (no cross-line alignment)
dt diff --linewise "ls | head -5"
```
#### Interactive Diff UI (keys)
- j/k or β/β: move selection
- Enter: pick first and second records to compare
- Tab/Space: toggle select current record
- o or β/β: toggle preview between stdout/stderr
- Backspace: delete last filter char
- Delete: clear filter input
- Esc: quit
- Shift+Backspace or Ctrl+X: delete the highlighted record (two-press confirm)
- First press shows a confirmation message in the status bar
- Press again to permanently delete the record and refresh the list
### View history records
```bash
dt ls
dt ls "ls | head" --json
```
### Clean history records
```bash
# Clean by command search (supports dry-run)
dt clean search "ls" --dry-run
dt clean search "ls"
# Clean by file (supports dry-run)
dt clean file /path/to/file --dry-run
dt clean file /path/to/file
# Clean all records
dt clean all
```
## Configuration
Configuration file is located at `~/.dt/config.toml`:
```toml
[storage]
max_retention_days = 365 # Maximum retention days
auto_archive = true # Auto archive
[display]
max_history_shown = 10 # Maximum history records to show
language = "auto" # Language setting (auto/en/zh)
```
## Data Directory
By default dt stores data under `~/.dt/`. To isolate environments (e.g., for demos/tests), override the data directory:
```bash
# Use a custom directory for index and records
dt --data-dir /tmp/dt_demo_data run "date"
dt --data-dir /tmp/dt_demo_data diff "date"
```
## Licenses
This software includes third-party components (e.g., fuzzy-matcher with Skim-style algorithm). See `THIRD_PARTY_NOTICES.md` and the generated `THIRD_PARTY_DEPENDENCIES.md` (or `.json`) for dependency license details.
## Features
- β
Support for simple commands and piped commands
- β
Colored diff output
- β
Auto archive historical data
- β
Multi-language support (Chinese/English)
- β
Date filtering selection (skim-like)
- β
Configuration file management
- β
Clean by file and command search
EOF
# Create installer script
cat > "package/${PACKAGE_NAME}/install.sh" << 'EOF'
#!/bin/bash
# dt installer
set -e
BINARY_NAME="dt"
INSTALL_DIR="/usr/local/bin"
# Require root to install into /usr/local/bin
if [[ $EUID -ne 0 ]]; then
echo "β οΈ This script needs root to install into /usr/local/bin"
echo "π‘ Try: sudo ./install.sh"
echo "π‘ Or copy manually: cp dt ~/.local/bin/ (if ~/.local/bin is in PATH)"
exit 1
fi
echo "π Installing ${BINARY_NAME}..."
# Copy binary
cp "${BINARY_NAME}" "${INSTALL_DIR}/"
# Make executable
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
echo "β
Installed!"
echo ""
echo "π Usage:"
echo " ${BINARY_NAME} --help"
echo ""
echo "ποΈ Config file will be created at ~/.dt/config.toml on first run"
EOF
chmod +x "package/${PACKAGE_NAME}/install.sh"
# Create archives
echo "ποΈ Creating archives..."
cd package
tar -czf "${PACKAGE_NAME}-$(uname -m)-$(uname -s | tr '[:upper:]' '[:lower:]').tar.gz" "${PACKAGE_NAME}/"
# Create zip for Windows users
zip -r "${PACKAGE_NAME}-$(uname -m)-$(uname -s | tr '[:upper:]' '[:lower:]').zip" "${PACKAGE_NAME}/"
cd ..
echo ""
echo "β
Packaging completed!"
echo ""
echo "π¦ Generated files:"
ls -la package/*.tar.gz package/*.zip 2>/dev/null || echo "Only tar.gz created"
echo ""
echo "π Package includes:"
echo " - ${BINARY_NAME} binary"
echo " - USAGE.md"
echo " - THIRD_PARTY_NOTICES.md"
echo " - THIRD_PARTY_DEPENDENCIES.md (or .json if cargo-about unavailable)"
echo " - install.sh"
echo " - README.md (if present)"
echo " - LICENSE (if present)"
echo ""
echo "π Distribution notes:"
echo " - Linux/macOS: use .tar.gz"
echo " - Windows: use .zip"
echo " - Run install.sh or copy the binary into PATH manually"