Initial commit
This commit is contained in:
commit
28fcdddcca
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
||||
16
Cargo.lock
generated
Normal file
16
Cargo.lock
generated
Normal 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
7
Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "mybar"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
libc = "*"
|
||||
8
run.sh
Executable file
8
run.sh
Executable 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
65
src/main.rs
Normal 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")
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user