-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnlyfile
More file actions
95 lines (85 loc) · 2.59 KB
/
Copy pathOnlyfile
File metadata and controls
95 lines (85 loc) · 2.59 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
!version 0.4
!var cargo_flags = "--all-targets"
[help] Build only-cli {{cargo_flags}}
[pass] Build complete.
[fail] Build failed.
build(profile = "dev"):
cargo build --profile {{profile}}
[help] Run CI
[desc] Format, check, lint, test, and build.
[pass] CI passed.
[fail] CI failed.
ci()
& fmt
& check
& clippy
& test
[help] Format code
[pass] Format complete.
[fail] Format failed.
fmt():
cargo fmt --all
[help] Check code
[pass] Check passed.
[fail] Check failed.
check():
cargo check {{cargo_flags}}
[help] Lint code
[pass] Clippy passed.
[fail] Clippy failed.
clippy():
cargo clippy {{cargo_flags}} -- -D warnings
echo "Done"
[help] Run tests
[desc] Use cargo-nextest.
[pass] Tests passed.
[fail] Tests failed.
test() ? @has("cargo-nextest"):
cargo nextest run --no-fail-fast {{cargo_flags}}
[desc] Fall back to cargo test.
test():
cargo test --no-fail-fast {{cargo_flags}}
[help] Clean builds
[desc] Remove Cargo build artifacts.
[pass] Clean complete.
[fail] Clean failed.
clean():
cargo clean
[help] Install only
[desc] Install the Windows binary after exit.
[pass] Installed. Restart your shell.
[fail] Installation failed.
install()
? @os("windows")
& build("release")
shell~=pwsh
:
| # Resolve paths and processes.
| $installDir = Join-Path $env:LOCALAPPDATA "Programs\Only"
| $installPath = Join-Path $installDir "only.exe"
| $stagedPath = Join-Path $env:TEMP "only-install-staged.exe"
| $parentPid = (Get-CimInstance Win32_Process -Filter "ProcessId=$PID").ParentProcessId
| $shellPath = (Get-Process -Id $PID).Path
|
| # Stage the replacement.
| New-Item -ItemType Directory -Force -Path $installDir | Out-Null
| Copy-Item target/release/only.exe -Destination $stagedPath -Force
| $script = "Wait-Process -Id $parentPid; Copy-Item -LiteralPath '$stagedPath' -Destination '$installPath' -Force; Remove-Item -LiteralPath '$stagedPath' -Force"
| $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($script))
|
| # Install after only exits.
| Start-Process -WindowStyle Hidden -FilePath $shellPath -ArgumentList "-NoProfile", "-EncodedCommand", $encoded
[desc] Install to ~/.local/bin/only.
[pass] Installed to ~/.local/bin/only.
install() & build("release"):
| # Resolve paths.
| install_dir="$HOME/.local/bin"
| staged_path="$install_dir/.only-install"
|
| # Stage the executable.
| mkdir -p "$install_dir"
| cp target/release/only "$staged_path"
| chmod +x "$staged_path"
|
| # Replace the installed binary.
| mv "$staged_path" "$install_dir/only"