Initial commit

This commit is contained in:
akulij 2024-09-09 17:41:54 +03:00
commit 28fcdddcca
5 changed files with 97 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

16
Cargo.lock generated Normal file
View File

@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "libc"
version = "0.2.157"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "374af5f94e54fa97cf75e945cce8a6b201e88a1a07e688b47dfd2a59c66dbd86"
[[package]]
name = "mybar"
version = "0.1.0"
dependencies = [
"libc",
]

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "mybar"
version = "0.1.0"
edition = "2021"
[dependencies]
libc = "*"

8
run.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
scriptDir=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")
hyprctl activeworkspace -j | jq .id # set initial value
# ./target/debug/mybar workspace\> | awk -F '>>' '{print $2}'
cd "$scriptDir"
./target/debug/mybar workspace\> split

65
src/main.rs Normal file
View File

@ -0,0 +1,65 @@
use std::fmt::format;
use std::os::fd::AsFd;
use std::{default, env, mem};
use std::os::unix::net::UnixStream;
use std::io::{prelude::*, stdout, BufReader};
use libc::{signal, SIGPIPE, SIG_DFL, SIG_IGN};
fn main() {
let args : Vec<String> = env::args().collect();
unsafe {signal(SIGPIPE, SIG_IGN);}
let mut filter_mode = false;
let mut split_mode = false;
if args.len() > 1 {
filter_mode = true;
}
for arg in &args[1..] {
if arg == "split" {
split_mode = true;
}
}
let mut stream = UnixStream::connect(get_hypr_socket_path()).unwrap();
//let mut buf = [0u8; 1024];
let reader = BufReader::new(stream);
if !filter_mode {
for line in reader.lines() {
write!(stdout(), "{}\n", line.unwrap()).unwrap();
stdout().flush().unwrap();
}
} else {
for line in reader.lines() {
let mut line = line.unwrap();
let contains: bool = {
let mut contains = false;
for filter in &args[1..] {
// if line.contains(filter) {
if line.starts_with(filter) {
contains = true;
break;
}
};
contains
};
if contains {
//write!(stdout(), "{}\n", line).unwrap();
//stdout().write(line.as_bytes()).unwrap();
//stdout().write_fmt(format_args!("{}\n", line)).unwrap();
//stdout().flush().unwrap();
let mut idx = 0;
if split_mode {
idx = line.find(">>").unwrap();
}
println!("{}", line.split_off(idx+2));
}
}
}
}
fn get_hypr_socket_path() -> String {
let instance = env::var("HYPRLAND_INSTANCE_SIGNATURE").unwrap();
format!("/tmp/hypr/{instance}/.socket2.sock")
}