Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

other: Add autocomplete file generation #213

Merged
merged 5 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-Ctarget-feature=+crt-static"]
[target.i686-pc-windows-msvc]
rustflags = ["-Ctarget-feature=+crt-static"]
57 changes: 48 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ before_install:
powershell Install-WindowsFeature Net-Framework-Core;
choco install -y wixtoolset;
export PATH=$PATH:"/c/Program Files (x86)/WiX Toolset v3.11/bin";
choco install zip;
rustup target add i686-pc-windows-msvc;
fi
elif [[ $TRAVIS_OS_NAME == "osx" ]]; then
export TARGET=x86_64-apple-darwin;
Expand All @@ -45,49 +47,86 @@ notifications:
on_success: never

before_deploy:
- cargo install --path . --target $TARGET --locked --force;
- |
echo "Test whether installing works. This is mostly just a sanity check.";
cargo install --path . --target $TARGET --locked --force;
- |
echo "Building release..."
if [[ $TRAVIS_OS_NAME == "windows" ]]; then
choco install zip;
rustup target add x86_64-pc-windows-msvc;

echo "Building Windows 64-bit...";
cargo build --release --target x86_64-pc-windows-msvc;
local target_dir=$(ls target/release/build/bottom-*/out/rg.bash | head -n1 | xargs dirname)
cp -r $target_dir completions
mv "./target/x86_64-pc-windows-msvc/release/btm" "btm.exe";
strip "btm.exe"
zip bottom_x86_64-pc-windows-msvc.zip "btm.exe";
zip -r bottom_x86_64-pc-windows-msvc.zip "btm.exe" "completions";
rm "btm.exe"
rustup target add i686-pc-windows-msvc;
rm -r "completions"

echo "Building Windows 32-bit...";
cargo clean;
cargo build --release --target i686-pc-windows-msvc;
local target_dir=$(ls target/release/build/bottom-*/out/rg.bash | head -n1 | xargs dirname)
cp -r $target_dir completions
mv "./target/i686-pc-windows-msvc/release/btm" "btm.exe";
strip "btm.exe"
zip bottom_i686-pc-windows-msvc.zip "btm.exe";
zip -r bottom_i686-pc-windows-msvc.zip "btm.exe" "completions";
rm "btm.exe"
rm -r "completions"

echo "Building choco template...";
python "./deployment/windows/choco/choco_packager.py" "bottom_i686-pc-windows-msvc.zip" "bottom_x86_64-pc-windows-msvc.zip" $TRAVIS_TAG "./deployment/windows/choco/bottom.nuspec.template" "./deployment/windows/choco/chocolateyinstall.ps1.template" "./deployment/windows/choco/bottom.nuspec" "./deployment/windows/choco/tools/chocolateyinstall.ps1" "./deployment/windows/choco/tools/";
cd "./deployment/windows/choco/"
zip -r choco.zip "bottom.nuspec" "tools/";
cd "../../../";
mv "./deployment/windows/choco/choco.zip" "./choco.zip"

echo "Building msi file...";
cargo install cargo-wix;
cargo wix init;
cargo wix;
python "./deployment/packager.py" $TRAVIS_TAG "./deployment/windows/winget/winget.yaml.template" "$TRAVIS_TAG.yaml" "SHA256" "./bottom_x86_64_installer.msi" ;

echo "Building winget template...";
python "./deployment/packager.py" $TRAVIS_TAG "./deployment/windows/winget/winget.yaml.template" "$TRAVIS_TAG.yaml" "SHA256" "./bottom_x86_64_installer.msi";

echo "Done Windows pre-deploy!";
else
echo "Building release for macOS/Linux...";
cargo build --release;
cp ./target/release/btm btm;
strip btm;
local target_dir=$(ls target/release/build/bottom-*/out/rg.bash | head -n1 | xargs dirname)
cp -r $target_dir completions

if [[ $TRAVIS_OS_NAME == "linux" ]]; then
tar -czvf bottom_x86_64-unknown-linux-gnu.tar.gz btm;
echo "Tar-ing Linux binary and completions..."
tar -czvf bottom_x86_64-unknown-linux-gnu.tar.gz btm completions;

echo "Generating AUR template...";
python "./deployment/packager.py" $TRAVIS_TAG "./deployment/linux/arch/PKGBUILD_BIN.template" "./PKGBUILD_BIN" "SHA512" "./bottom_x86_64-unknown-linux-gnu.tar.gz";
curl -LO "https://github.com/ClementTsang/bottom/archive/$TRAVIS_TAG.tar.gz";

echo "Generating AUR binary template...";
python "./deployment/packager.py" $TRAVIS_TAG "./deployment/linux/arch/PKGBUILD.template" "./PKGBUILD" "SHA512" "./$TRAVIS_TAG.tar.gz";
rm "$TRAVIS_TAG.tar.gz";

echo "Tar-ing AUR PKGBUILDs...";
tar -czvf arch.tar.gz PKGBUILD_BIN PKGBUILD;

# Note this requires the completions directory in the current directory.
echo "Generating Debian install file...";
cargo install cargo-deb;
cargo deb;
cp ./target/debian/bottom_*.deb .;
elif [[ $TRAVIS_OS_NAME == "osx" ]]; then
tar -czvf bottom_x86_64-apple-darwin.tar.gz btm;

echo "Tar-ing macOS binary and completions..."
tar -czvf bottom_x86_64-apple-darwin.tar.gz btm completions;
# The bottom.rb file must be generated AFTER, since it relies on the Linux binary file.
fi

echo "Done macOS/Linux pre-deploy!";
fi

deploy:
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"markdownlint",
"memb",
"minwindef",
"n'th",
"noheader",
"ntdef",
"nuget",
Expand Down
11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ categories = ["command-line-utilities", "visualization"]
description = "A cross-platform graphical process/system monitor with a customizable interface and a multitude of features. Supports Linux, macOS, and Windows."
readme = "README.md"
default-run = "btm"
build = "build.rs"

[[bin]]
name = "btm"
Expand Down Expand Up @@ -55,14 +56,22 @@ winapi = "0.3.9"
assert_cmd = "1.0"
predicates = "1"

[build-dependencies]
clap = "2.33"

[package.metadata.deb]
section = "utility"
assets = [
["target/release/btm", "usr/bin/", "755"],
["LICENSE", "usr/share/doc/btm/", "644"],
["README.md", "usr/share/doc/btm/README", "644"],
["completions/btm.bash", "usr/share/bash-completion/completions/btm", "644"],
["completions/btm.fish", "usr/share/fish/vendor_completions.d/btm.fish", "644"],
["completions/_btm", "usr/share/zsh/vendor-completions/", "644"],
]
extended-description = """\
A cross-platform graphical process/system monitor with a customizable interface and a multitude of
features. Supports Linux, macOS, and Windows.

By default, bottom will look for a config file in ~/.config/bottom/bottom.toml.
If one is not specified it will fall back to defaults. If a config file does not
exist at the specified or default location, a blank one will be created for the user.
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ A cross-platform graphical process/system monitor with a customizable interface
- [Homebrew](#homebrew)
- [Scoop](#scoop)
- [Chocolatey](#chocolatey)
- [Auto-completion](#auto-completion)
- [Usage](#usage)
- [Flags](#flags)
- [Options](#options)
Expand Down Expand Up @@ -86,6 +87,9 @@ tar -xzvf 0.4.7.tar.gz
cargo install --path .
```

Or, you can just download the binary from the [latest release](https://github.com/ClementTsang/bottom/releases/latest) and install/use it
in whatever way you want.

### Cargo

```bash
Expand Down Expand Up @@ -152,6 +156,19 @@ choco install bottom
choco install bottom --version=0.4.7
```

### Auto-completion

Shell completions are included in binary releases, and are generated in the same directory as the
binary if bottom is manually built.

- For bash, move `btm.bash` to `$XDG_CONFIG_HOME/bash_completion or /etc/bash_completion.d/`.
- For fish, move `btm.fish` to `$HOME/.config/fish/completions/`.
- For zsh, move `_btm` to one of your `$fpath` directories.
- For PowerShell, add `. _btm.ps1` to your PowerShell
[profile](<https://docs.microsoft.com/en-us/previous-versions//bb613488(v=vs.85)>).

Some install scripts (i.e. AUR) will automatically do this for you.

## Usage

Run using `btm`.
Expand Down
31 changes: 31 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use clap::Shell;
use std::{env, fs, process};
include!("src/clap.rs");

fn main() {
// OUT_DIR is where extra build files are written to for Cargo.
let out_dir = match env::var_os("OUT_DIR") {
Some(out_dir) => out_dir,
None => {
eprintln!("The OUT_DIR environment variable was not set! Aborting...");
process::exit(1)
}
};
match fs::create_dir_all(&out_dir) {
Ok(()) => {}
Err(err) => {
eprintln!(
"Failed to create a directory at OUT_DIR location {:?}, encountered error {:?}. Aborting...",
out_dir, err
);
process::exit(1)
}
}

// Generate completions
let mut app = build_app();
app.gen_completions("btm", Shell::Bash, &out_dir);
app.gen_completions("btm", Shell::Zsh, &out_dir);
app.gen_completions("btm", Shell::Fish, &out_dir);
app.gen_completions("btm", Shell::PowerShell, &out_dir);
}
5 changes: 5 additions & 0 deletions deployment/linux/arch/PKGBUILD.template
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ package() {
cd $pkgname-$pkgver
install -Dm755 target/release/btm "$pkgdir/usr/bin/btm"
install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/${pkgname}/LICENSE"

local target_dir=$(ls target/release/build/bottom-*/out/rg.bash | head -n1 | xargs dirname)
install -Dm644 "$target_dir"/_btm "$pkgdir/usr/share/zsh/site-functions/_btm"
install -Dm644 "$target_dir"/btm.bash "$pkgdir/usr/share/bash-completion/completions/btm"
install -Dm644 "$target_dir"/btm.fish "$pkgdir/usr/share/fish/vendor_completions.d/btm.fish"
}
16 changes: 10 additions & 6 deletions deployment/linux/arch/PKGBUILD_BIN.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ arch=('x86_64')
url="https://github.com/ClementTsang/bottom"
license=(MIT)
source=(
archive-${pkgver}.tar.gz::${url}/releases/download/${pkgver}/bottom_x86_64-unknown-linux-gnu.tar.gz
LICENSE::${url}/raw/${pkgver}/LICENSE
archive-${pkgver}.tar.gz::${url}/releases/download/${pkgver}/bottom_x86_64-unknown-linux-gnu.tar.gz
LICENSE::${url}/raw/${pkgver}/LICENSE
)
sha512sums=(
'$hash1'
SKIP
'$hash1'
SKIP
)

package() {
install -Dm755 btm "$pkgdir"/usr/bin/btm
install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
install -Dm755 btm "$pkgdir"/usr/bin/btm
install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

install -Dm644 completion/_btm "$pkgdir/usr/share/zsh/site-functions/_btm"
install -Dm644 completion/btm.bash "$pkgdir/usr/share/bash-completion/completions/btm"
install -Dm644 completion/btm.fish "$pkgdir/usr/share/fish/vendor_completions.d/btm.fish"
}
2 changes: 2 additions & 0 deletions deployment/macos/homebrew/bottom.rb.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Bottom < Formula
end

def install
bash_completion.install "completion/rg.bash"
zsh_completion.install "completion/_rg"
bin.install "btm"
ohai "You're done! Run with \"btm\""
ohai "For runtime flags, see \"btm --help\""
Expand Down
2 changes: 1 addition & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() -> error::Result<()> {
{
utils::logging::init_logger()?;
}
let matches = get_matches();
let matches = clap::get_matches();

let config: Config = create_config(matches.value_of("CONFIG_LOCATION"))?;

Expand Down
Loading