mirror of
https://github.com/house-of-vanity/tmux-helper.git
synced 2026-02-04 17:57:58 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31c3237a5c | ||
|
|
46f641220c | ||
|
|
7e793c68c2 | ||
|
|
942e767c7e | ||
|
|
a276c1a2aa | ||
|
|
2150aaf5cd | ||
|
|
b1e418a633 | ||
|
|
8e569078de | ||
|
|
5d23b7da2d | ||
|
|
5cf2ab0e40 | ||
|
|
7c7d9070a4 | ||
|
|
456d423f47 |
33
.github/workflows/PKGBUILD
vendored
Normal file
33
.github/workflows/PKGBUILD
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# Maintainer: Alexandr Bogomyakov (ultradesu) <ab@hexor.ru>
|
||||
|
||||
pkgname=tmux-helper
|
||||
pkgver=0.2.1
|
||||
pkgrel=1
|
||||
pkgdesc="Tmux helper"
|
||||
url="https://github.com/house-of-vanity/tmux-helper.git"
|
||||
arch=($CARCH)
|
||||
license=(WTFPL custom)
|
||||
depends=(tmux dbus)
|
||||
makedepends=(cargo git dbus)
|
||||
source=("git+https://github.com/house-of-vanity/$pkgname")
|
||||
sha512sums=('SKIP')
|
||||
|
||||
pkgver() {
|
||||
cd "$srcdir/$pkgname"
|
||||
git describe --long --tags | awk -F '-' '{print $1}'| sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
|
||||
}
|
||||
|
||||
prepare() {
|
||||
cd "$srcdir/$pkgname"
|
||||
cargo fetch --target $CARCH-unknown-linux-gnu
|
||||
}
|
||||
|
||||
build() {
|
||||
cd "$srcdir/$pkgname"
|
||||
cargo build --release --frozen --all-targets
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "$srcdir/$pkgname"
|
||||
install -Dt "$pkgdir/usr/bin" target/release/$pkgname
|
||||
}
|
||||
95
.github/workflows/build.yml
vendored
Normal file
95
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
name: Build and publish
|
||||
on:
|
||||
push:
|
||||
# Sequence of patterns matched against refs/tags
|
||||
tags:
|
||||
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
|
||||
|
||||
jobs:
|
||||
make_bin:
|
||||
name: Build binary
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Pre-build
|
||||
run: sudo apt install -y libdbus-1-dev pkg-config libdbus-1-3 libfuse-dev
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build binary
|
||||
run: cargo build --release
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: tmux-helper
|
||||
path: ./target/release/tmux-helper
|
||||
make_arch:
|
||||
name: Make Arch Linux package
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: archlinux
|
||||
options: --privileged
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build Arch Linux package
|
||||
uses: FFY00/build-arch-package@master
|
||||
with:
|
||||
PKGBUILD: $GITHUB_WORKSPACE/.github/workflows/PKGBUILD
|
||||
OUTDIR: $HOME/arch-packages
|
||||
- run: mv $HOME/arch-packages/*pkg.tar.zst tmux-helper-x86_64.pkg.tar.zst
|
||||
- name: Upload Arch Package
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: arch_linux_tmux-helper-x86_64.pkg.tar.zst
|
||||
path: ./tmux-helper-x86_64.pkg.tar.zst
|
||||
|
||||
publish:
|
||||
name: Publish release
|
||||
needs: [make_bin, make_arch]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Get the version (git tag)
|
||||
id: get_version
|
||||
run: |
|
||||
echo ${GITHUB_REF/refs\/tags\/v/}
|
||||
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
|
||||
echo ::set-output name=FULL_TAG::${GITHUB_REF/refs\/tags\//}
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: Release ${{ github.ref }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
- name: Download binary
|
||||
uses: actions/download-artifact@v1
|
||||
with:
|
||||
name: tmux-helper
|
||||
path: ./
|
||||
- name: Download Arch Package
|
||||
uses: actions/download-artifact@v1
|
||||
with:
|
||||
name: arch_linux_tmux-helper-x86_64.pkg.tar.zst
|
||||
path: ./
|
||||
- name: Upload binary assets
|
||||
run: |
|
||||
wget https://github.com/aktau/github-release/releases/download/v0.7.2/linux-amd64-github-release.tar.bz2
|
||||
tar xjf linux-amd64-github-release.tar.bz2
|
||||
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
|
||||
./bin/linux/amd64/github-release upload -u house-of-vanity -r tmux-helper --tag ${{ steps.get_version.outputs.FULL_TAG }} --name arch_linux_tmux-helper-${{ steps.get_version.outputs.VERSION }}-x86_64.pkg.tar.zst --file ./tmux-helper-x86_64.pkg.tar.zst
|
||||
./bin/linux/amd64/github-release upload -u house-of-vanity -r tmux-helper --tag ${{ steps.get_version.outputs.FULL_TAG }} --name tmux-helper-${{ steps.get_version.outputs.VERSION }} --file ./tmux-helper
|
||||
|
||||
# SCP to arch repo
|
||||
- name: Copy package to repository
|
||||
uses: appleboy/scp-action@master
|
||||
with:
|
||||
host: ${{ secrets.SSH_HOST }}
|
||||
username: github_deploy
|
||||
port: 22
|
||||
key: ${{ secrets.SSH_KEY }}
|
||||
source: "./tmux-helper-x86_64.pkg.tar.zst"
|
||||
target: "/srv/arch-repo/"
|
||||
20
.github/workflows/push-build.yml
vendored
20
.github/workflows/push-build.yml
vendored
@@ -1,20 +0,0 @@
|
||||
name: Rust
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Pre-build
|
||||
run: sudo apt install -y libdbus-1-dev pkg-config libdbus-1-3
|
||||
- name: Build
|
||||
run: cargo build --verbose --release
|
||||
env:
|
||||
RUST_BACKTRACE: 1
|
||||
- name: Strip
|
||||
run: strip target/release/tmux-helper
|
||||
|
||||
25
.github/workflows/release-upload.yml
vendored
25
.github/workflows/release-upload.yml
vendored
@@ -1,25 +0,0 @@
|
||||
name: Rust
|
||||
|
||||
on: release
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Pre-build
|
||||
run: sudo apt install -y libdbus-1-dev pkg-config libdbus-1-3
|
||||
- name: Build
|
||||
run: cargo build --verbose --release
|
||||
env:
|
||||
RUST_BACKTRACE: 1
|
||||
- name: Strip
|
||||
run: strip target/release/tmux-helper
|
||||
- name: Upload to release
|
||||
uses: JasonEtco/upload-to-release@master
|
||||
with:
|
||||
args: target/release/tmux-helper application/x-pie-executable
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -1,9 +1,10 @@
|
||||
[package]
|
||||
name = "tmux-helper"
|
||||
version = "0.1.0"
|
||||
version = "0.2.2"
|
||||
authors = ["Ultra Desu <ultradesu@hexor.ru>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
sys-info = "*"
|
||||
dbus = "*"
|
||||
chrono = "*"
|
||||
|
||||
109
src/main.rs
109
src/main.rs
@@ -1,16 +1,19 @@
|
||||
extern crate chrono;
|
||||
extern crate dbus;
|
||||
|
||||
use crate::dbus::blocking::stdintf::org_freedesktop_dbus::Properties;
|
||||
use chrono::{DateTime, Local, Utc};
|
||||
use dbus::{arg, blocking::Connection};
|
||||
use std::{env, fs, time::Duration};
|
||||
use std::{env, time::Duration};
|
||||
use sys_info;
|
||||
|
||||
const LOW: &str = "#[fg=colour2]";
|
||||
const MID: &str = "#[fg=colour3]";
|
||||
const HIGH: &str = "#[fg=colour1]";
|
||||
const END: &str = "#[fg=colour7]";
|
||||
const TRACK_NAME: &str = "#[fg=colour3]";
|
||||
const TRACK_ARTIST: &str = "#[fg=colour3]";
|
||||
const TRACK_TIME: &str = "#[bg=colour252 fg=colour235 bold]";
|
||||
const LOW: &str = "#[fg=colour119]";
|
||||
const MID: &str = "#[fg=colour220]";
|
||||
const HIGH: &str = "#[fg=colour197]";
|
||||
const END: &str = "#[fg=colour153]";
|
||||
const TRACK_NAME: &str = "#[fg=colour46]";
|
||||
const TRACK_ARTIST: &str = "#[fg=colour46]";
|
||||
const TRACK_TIME: &str = "#[fg=colour153]";
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct TrackInfo {
|
||||
@@ -21,10 +24,6 @@ struct TrackInfo {
|
||||
status: String,
|
||||
}
|
||||
|
||||
fn read_file(file_path: &str) -> String {
|
||||
fs::read_to_string(file_path).expect("Cant read file.")
|
||||
}
|
||||
|
||||
fn to_bar(value: i32, max: i32, low: f32, mid: f32) {
|
||||
let mut bar = "".to_string();
|
||||
let bar_sym = "▮".to_string();
|
||||
@@ -56,18 +55,21 @@ fn mem_load_bar(bar_len: i32) {
|
||||
let len =
|
||||
((memory.total - memory.avail) as f32 / (memory.total as f32) * bar_len as f32) as i32;
|
||||
to_bar(len, bar_len, 0.7, 0.9);
|
||||
print!("{:.0} MiB", memory.avail / 1024);
|
||||
print!("{:.0} MiB#[default]", memory.avail / 1024);
|
||||
}
|
||||
|
||||
fn cpu_load_bar(bar_len: i32) {
|
||||
let load = read_file("/proc/loadavg");
|
||||
let load_data = load.split_whitespace().collect::<Vec<&str>>();
|
||||
let _cpu_count = read_file("/proc/cpuinfo");
|
||||
let cpu_count = _cpu_count.matches("model name").count();
|
||||
let one: f32 = load_data[0].parse().unwrap();
|
||||
let len: f32 = one as f32 / cpu_count as f32 * bar_len as f32;
|
||||
let cpu_count = match sys_info::cpu_num() {
|
||||
Ok(c) => c,
|
||||
Err(e) => panic!("{:?}", e),
|
||||
};
|
||||
let la_one: f32 = match sys_info::loadavg() {
|
||||
Ok(l) => l.one as f32,
|
||||
Err(e) => panic!("{:?}", e),
|
||||
};
|
||||
let len: f32 = la_one as f32 / cpu_count as f32 * bar_len as f32;
|
||||
to_bar(len as i32, bar_len, 0.3, 0.7);
|
||||
print!("{:.2} LA1", one);
|
||||
print!("{:.2} LA1#[default]", la_one);
|
||||
}
|
||||
|
||||
fn get_player() -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
||||
@@ -153,9 +155,24 @@ fn format_time(sec: i64) -> String {
|
||||
result.to_string()
|
||||
}
|
||||
|
||||
fn get_time(utc: bool, mut format: &str) {
|
||||
// Format reference: https://docs.rs/chrono/0.4.10/chrono/format/strftime/index.html
|
||||
if format.len() == 0 {
|
||||
format = "%H:%M";
|
||||
}
|
||||
if utc {
|
||||
let local_time = Local::now();
|
||||
let utc_time = DateTime::<Utc>::from_utc(local_time.naive_utc(), Utc);
|
||||
println!("{}", utc_time.format(format));
|
||||
} else {
|
||||
let local_time = Local::now();
|
||||
println!("{}", local_time.format(format));
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let help_text: &str = "Available commands -mb, -cb";
|
||||
let help_text: &str = "Available commands -mb, -cb, -tl <TIME FORMAT>, -tu <TIME FORMAT>, -p";
|
||||
match args.len() {
|
||||
1 => {
|
||||
panic!(help_text);
|
||||
@@ -163,12 +180,34 @@ fn main() {
|
||||
2 => match args[1].as_ref() {
|
||||
"-cb" => cpu_load_bar(15),
|
||||
"-mb" => mem_load_bar(15),
|
||||
"-tl" => get_time(false, ""),
|
||||
"-tu" => get_time(true, ""),
|
||||
"-p" => match player_info(get_player().unwrap()) {
|
||||
Ok(mut track_info) => {
|
||||
let mut title_len = 30;
|
||||
let mut artist_len = 30;
|
||||
let mut separator: String = " - ".to_string();
|
||||
let mut separator: String = " — ".to_string();
|
||||
let max_shift = 6;
|
||||
if track_info.artist.chars().count() == 0 {
|
||||
separator = "".to_string();
|
||||
title_len += artist_len;
|
||||
}
|
||||
if artist_len + max_shift >= track_info.artist.chars().count() {
|
||||
artist_len = track_info.artist.chars().count()
|
||||
}
|
||||
if track_info.artist.len() > artist_len {
|
||||
let mut artist: String = String::new();
|
||||
let mut counter = 0;
|
||||
for ch in track_info.artist.chars() {
|
||||
if counter == artist_len {
|
||||
artist.push_str("..");
|
||||
break;
|
||||
}
|
||||
artist.push(ch);
|
||||
counter += 1;
|
||||
}
|
||||
track_info.artist = artist;
|
||||
}
|
||||
if title_len + max_shift >= track_info.title.chars().count() {
|
||||
title_len = track_info.title.chars().count()
|
||||
}
|
||||
@@ -177,33 +216,16 @@ fn main() {
|
||||
let mut counter = 0;
|
||||
for ch in track_info.title.chars() {
|
||||
if counter == title_len {
|
||||
title.push_str("..");
|
||||
break;
|
||||
}
|
||||
title.push(ch);
|
||||
counter += 1;
|
||||
}
|
||||
title.push_str("..");
|
||||
track_info.title = title;
|
||||
}
|
||||
if artist_len + max_shift >= track_info.artist.chars().count() {
|
||||
artist_len = track_info.artist.chars().count()
|
||||
}
|
||||
if track_info.artist.chars().count() == 0 {separator = "".to_string()}
|
||||
if track_info.artist.len() > artist_len {
|
||||
let mut artist: String = String::new();
|
||||
let mut counter = 0;
|
||||
for ch in track_info.artist.chars() {
|
||||
if counter == artist_len {
|
||||
break;
|
||||
}
|
||||
artist.push(ch);
|
||||
counter += 1;
|
||||
}
|
||||
artist.push_str("..");
|
||||
track_info.artist = artist;
|
||||
}
|
||||
println!(
|
||||
"#[none]#[bold]{}{}{}#[none]{}{}{}{} {}[{}/{}] {} {}",
|
||||
"#[none]#[bold]{}{}{}#[none]{}{}{}{} {}[{}/{}] {} {}#[default]",
|
||||
TRACK_NAME,
|
||||
track_info.title,
|
||||
END,
|
||||
@@ -222,6 +244,11 @@ fn main() {
|
||||
},
|
||||
_ => panic!(help_text),
|
||||
},
|
||||
3 => match args[1].as_ref() {
|
||||
"-tl" => get_time(false, args[2].as_ref()),
|
||||
"-tu" => get_time(true, args[2].as_ref()),
|
||||
_ => panic!(help_text),
|
||||
},
|
||||
_ => {
|
||||
panic!(help_text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user