Skip to content

Commit c434cb2

Browse files
committed
Pure bash killport
0 parents  commit c434cb2

File tree

11 files changed

+429
-0
lines changed

11 files changed

+429
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: 'bug'
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Run the command '...'
16+
2. See the error
17+
18+
**Expected behavior**
19+
A clear and concise description of what you expected to happen.
20+
21+
**Screenshots**
22+
If applicable, add screenshots to help explain your problem.
23+
24+
**Environment (please complete the following information):**
25+
- OS: [e.g. Ubuntu 20.04, macOS 12.0]
26+
- Rust version: [e.g. 1.57.0]
27+
- killport version: [e.g. 0.1.0]
28+
29+
**Additional context**
30+
Add any other context about the problem here.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: 'enhancement'
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/pull_request_template.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: Pull Request
3+
about: Submit a pull request to contribute to the project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Description of the changes**
11+
Please provide a clear and concise description of the changes you made.
12+
13+
**Related issue(s)**
14+
If this PR is related to an existing issue, please link to it using the `Fixes #issue_number` or `Closes #issue_number` syntax.
15+
16+
**Type of change**
17+
Please select one or multiple of the following options:
18+
- [ ] Bug fix (non-breaking change which fixes an issue)
19+
- [ ] New feature (non-breaking change which adds functionality)
20+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
21+
- [ ] Code cleanup (refactoring or improving code quality)
22+
- [ ] Documentation update (adding or updating documentation, updating README)
23+
24+
**Checklist:**
25+
- [ ] I have read the [CONTRIBUTING](CONTRIBUTING.md) document.
26+
- [ ] My code follows the code style of this project.
27+
- [ ] My change requires a change to the documentation.
28+
- [ ] I have updated the documentation accordingly.
29+
- [ ] I have added tests to cover my changes.
30+
- [ ] All new and existing tests passed.
31+
32+
**Additional information**
33+
Add any other information or screenshots about the pull request here.

.github/workflows/build.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
strategy:
11+
matrix:
12+
target:
13+
- x86_64-unknown-linux-gnu
14+
- i686-unknown-linux-gnu
15+
- aarch64-unknown-linux-gnu
16+
- armv7-unknown-linux-gnueabihf
17+
- arm-unknown-linux-gnueabihf
18+
- powerpc64le-unknown-linux-gnu
19+
- s390x-unknown-linux-gnu
20+
- aarch64-apple-darwin
21+
- x86_64-apple-darwin
22+
runs-on: ${{ (matrix.target == 'aarch64-apple-darwin' || matrix.target == 'x86_64-apple-darwin') && 'macos-latest' || 'ubuntu-latest' }}
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v2
26+
27+
- name: Install Rust
28+
uses: actions-rs/toolchain@v1
29+
with:
30+
toolchain: stable
31+
target: ${{ matrix.target }}
32+
override: true
33+
34+
- name: Build target
35+
uses: actions-rs/cargo@v1
36+
with:
37+
use-cross: true
38+
command: build
39+
args: --release --target ${{ matrix.target }}

.github/workflows/release.yml

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
check_release:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
releaseExists: ${{ steps.check_release.outputs.releaseExists }}
16+
steps:
17+
- name: Check if release exists
18+
id: check_release
19+
uses: actions/github-script@v5
20+
with:
21+
script: |
22+
const { owner, repo } = context.repo;
23+
const version = "${{ env.VERSION }}";
24+
const tag = `v${version}`;
25+
26+
let releaseExists = false;
27+
try {
28+
await github.rest.repos.getReleaseByTag({
29+
owner,
30+
repo,
31+
tag,
32+
});
33+
releaseExists = true;
34+
} catch (error) {
35+
if (error.status !== 404) {
36+
throw error;
37+
}
38+
}
39+
40+
return { releaseExists };
41+
42+
release:
43+
needs: check_release
44+
if: ${{ needs.check_release.outputs.releaseExists == 'false' }}
45+
strategy:
46+
matrix:
47+
target:
48+
- x86_64-unknown-linux-gnu
49+
- i686-unknown-linux-gnu
50+
- aarch64-unknown-linux-gnu
51+
- armv7-unknown-linux-gnueabihf
52+
- arm-unknown-linux-gnueabihf
53+
- powerpc64le-unknown-linux-gnu
54+
- s390x-unknown-linux-gnu
55+
- aarch64-apple-darwin
56+
- x86_64-apple-darwin
57+
runs-on: ${{ (matrix.target == 'aarch64-apple-darwin' || matrix.target == 'x86_64-apple-darwin') && 'macos-latest' || 'ubuntu-latest' }}
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v2
61+
62+
- name: Install Rust
63+
uses: actions-rs/toolchain@v1
64+
with:
65+
toolchain: stable
66+
target: ${{ matrix.target }}
67+
override: true
68+
69+
- name: Build target
70+
uses: actions-rs/cargo@v1
71+
with:
72+
use-cross: true
73+
command: build
74+
args: --release --target ${{ matrix.target }}
75+
76+
- name: Package binaries
77+
shell: bash
78+
run: |
79+
cd target/${{ matrix.target }}/release
80+
short_target=$(echo "${{ matrix.target }}" | sed 's/-unknown//')
81+
tar czvf ../../../killport-${short_target}.tar.gz killport
82+
cd -
83+
84+
- name: Extract version from Cargo.toml
85+
id: get_version
86+
run: |
87+
VERSION=$(grep '^version =' Cargo.toml | head -n 1 | awk '{print $3}' | tr -d '"' | tr -d "\n")
88+
echo "VERSION=$VERSION" >> $GITHUB_ENV
89+
echo "Found version: $VERSION"
90+
echo "::set-output name=version::$VERSION"
91+
92+
- name: Create release and upload assets
93+
uses: softprops/action-gh-release@v1
94+
with:
95+
tag_name: v${{ env.VERSION }}
96+
name: Release v${{ env.VERSION }}
97+
files: 'killport*'
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
101+
publish:
102+
needs: release
103+
runs-on: ubuntu-latest
104+
steps:
105+
- name: Checkout repository
106+
uses: actions/checkout@v2
107+
108+
- name: Install Rust
109+
uses: actions-rs/toolchain@v1
110+
with:
111+
toolchain: stable
112+
override: true
113+
114+
- name: Publish to crates.io
115+
run: cargo publish --token ${{ secrets.CRATES_IO }}

.github/workflows/rustfmt.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Rustfmt
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
check_rustfmt:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
18+
- name: Install Rust
19+
uses: actions-rs/toolchain@v1
20+
with:
21+
toolchain: stable
22+
components: rustfmt
23+
override: true
24+
25+
- name: Check code formatting
26+
run: cargo fmt --all -- --check

.github/workflows/tests.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
18+
- name: Install Rust
19+
uses: actions-rs/toolchain@v1
20+
with:
21+
toolchain: stable
22+
override: true
23+
24+
- name: Run tests
25+
run: cargo test --all

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
/target/
4+
5+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
7+
Cargo.lock
8+
9+
# These are backup files generated by rustfmt
10+
**/*.rs.bk

README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# killport
2+
3+
`killport` is a command-line utility for killing processes listening on specific ports. It's designed to be simple, fast, and effective. Its a simple bash script and works on Linux and macOS.
4+
5+
## Features
6+
7+
- Kill processes by port number
8+
- Supports multiple port numbers
9+
- Verbosity control
10+
- Works on Linux and macOS
11+
12+
## Installation
13+
14+
### Using Homebrew
15+
16+
Run the following command to install killport using Homebrew.
17+
18+
```sh
19+
brew tap metacritical/killport
20+
brew install killport
21+
```
22+
23+
### Using install.sh
24+
25+
Run the following command to automatically download and install `killport`:
26+
27+
```sh
28+
curl -L https://bit.ly/3ABTXJR | sh
29+
```
30+
31+
Don't forget to add `$HOME/.local/bin` to your `PATH` environment variable, if it's not already present.
32+
33+
34+
### Binary Releases
35+
36+
You can download the binary releases for different architectures from the [releases page](https://github.com/metacritical/killport/releases) and manually install them.
37+
38+
## Usage
39+
40+
```sh
41+
kp [FLAGS] <ports>...
42+
```
43+
44+
### Examples
45+
46+
Kill a single process listening on port 8080:
47+
48+
```sh
49+
kp 8080
50+
```
51+
52+
Kill multiple processes listening on ports 8045, 8046, and 8080:
53+
54+
```sh
55+
kp 8045 8046 8080
56+
```
57+
### Flags
58+
59+
-v, --verbose
60+
Increase the verbosity level. Use multiple times for more detailed output.
61+
62+
-h, --help
63+
Display the help message and exit.
64+
65+
-V, --version
66+
Display the version information and exit.
67+
68+
## Contributing
69+
70+
# Please dont contrubute to silly oneline utilities its a pun software, just for gigs!
71+
72+
## License
73+
74+
WTFPL (yup thats the license for this.)

install.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -u
4+
5+
ARCH=$(uname -m)
6+
OS=$(uname)
7+
8+
REPO="https://github.com/metacritical/killport"
9+
LATEST_RELEASE_URL="$REPO/releases/download/0.0.1/kp"
10+
INSTALL_DIR="/usr/local/bin"
11+
12+
echo "Installing killport..."
13+
curl -L "$LATEST_RELEASE_URL" -o "${INSTALL_DIR}/kp"
14+
chmod +x "${INSTALL_DIR}/kp"

0 commit comments

Comments
 (0)