Remove jq dependency from sway_tree script
This commit is contained in:
parent
2b1baf7bd1
commit
7e35a0feea
|
@ -23,42 +23,35 @@
|
||||||
// └───> [Alacritty]
|
// └───> [Alacritty]
|
||||||
|
|
||||||
use std::io::{self, BufRead, BufReader};
|
use std::io::{self, BufRead, BufReader};
|
||||||
use std::process::{Command, Stdio, ChildStdout};
|
use std::process::{Command, Stdio};
|
||||||
|
use std::cmp::min;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let sway_tree = match get_tree() {
|
let sway_tree = get_tree().expect("Failed to get sway tree");
|
||||||
Ok(tree) => BufReader::new(tree).lines().map(|l| l.unwrap()),
|
|
||||||
Err(e) => panic!("Failed to get sway tree: {}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (i, line) in sway_tree.enumerate() {
|
for (i, line) in sway_tree.iter().enumerate() {
|
||||||
println!("Workspace {} :: {}", i+1, line);
|
println!("Workspace {} :: {}", i+1, line);
|
||||||
println!("{}", ParserTree::from(&line).format());
|
println!("{}", ParserTree::from(line).format());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tree() -> io::Result<ChildStdout> {
|
fn get_tree() -> io::Result<Vec<String>> {
|
||||||
let swaymsg = Command::new("swaymsg")
|
let swaymsg = Command::new("swaymsg")
|
||||||
.arg("-t")
|
.arg("-t")
|
||||||
.arg("get_tree")
|
.arg("get_tree")
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
|
|
||||||
let jq = Command::new("jq")
|
let swaymsg_out = swaymsg.stdout.expect("Swaymsg didn't return window tree");
|
||||||
.arg(".nodes[1].nodes[].representation")
|
|
||||||
.stdin(swaymsg.stdout.unwrap())
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.expect("`jq` binary is not available");
|
|
||||||
|
|
||||||
let tr = Command::new("tr")
|
let repr: Vec<String> = BufReader::new(swaymsg_out)
|
||||||
.arg("-d")
|
.lines()
|
||||||
.arg("\"")
|
.map(|l| l.unwrap().trim().to_string())
|
||||||
.stdin(jq.stdout.unwrap())
|
.filter(|l| &l[..min(16, l.len())] == "\"representation\"")
|
||||||
.stdout(Stdio::piped())
|
.map(|l| l[19..l.len()-1].to_string())
|
||||||
.spawn()?;
|
.collect();
|
||||||
|
|
||||||
Ok(tr.stdout.unwrap())
|
Ok(repr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,21 @@ Some key terms:
|
||||||
|
|
||||||
The opens an ssh tunnel without obstructing the current terminal:
|
The opens an ssh tunnel without obstructing the current terminal:
|
||||||
```bash
|
```bash
|
||||||
ssh -p10011 -NL 7000:localhost:8080 emiliko@localhost &
|
ssh -NL 8001:localhost:7000 emiliko@cs.ox.ac.uk &
|
||||||
ssh -NL <client-port>:<url-from-host>:<host-port> <user>@<host-address> &
|
ssh -NL <client-port>:<url-from-host>:<host-port> <user>@<host-address> &
|
||||||
```
|
```
|
||||||
|
|
||||||
# In config file
|
# In config file
|
||||||
The syntax in the config is quite similar
|
The syntax in the `~/.ssh/config` is quite similar
|
||||||
|
|
||||||
```ssh
|
```ssh
|
||||||
|
Host mirrorside
|
||||||
|
User emiliko
|
||||||
|
Hostname cs.ox.ac.uk
|
||||||
LocalForward 8001 localhost:7000
|
LocalForward 8001 localhost:7000
|
||||||
|
```
|
||||||
|
|
||||||
|
The general format looks like
|
||||||
|
```ssh
|
||||||
LocalForward <client-port> <host-address>:<host-port>
|
LocalForward <client-port> <host-address>:<host-port>
|
||||||
```
|
```
|
||||||
|
|
|
@ -36,6 +36,7 @@ configs_pointer_is_setup() {
|
||||||
swayland_checks() {
|
swayland_checks() {
|
||||||
check_sway_wallpaper
|
check_sway_wallpaper
|
||||||
check_swaylock_wallpaper
|
check_swaylock_wallpaper
|
||||||
|
check_swaytree_compilation
|
||||||
}
|
}
|
||||||
|
|
||||||
check_sway_wallpaper() {
|
check_sway_wallpaper() {
|
||||||
|
@ -71,6 +72,25 @@ check_swaylock_wallpaper() {
|
||||||
return $return_code
|
return $return_code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_swaytree_compilation() {
|
||||||
|
local src=~/.configs_pointer/bin/sway_tree.rs
|
||||||
|
local exe="${src%.*}"
|
||||||
|
|
||||||
|
if [[ -x "$exe" ]]; then
|
||||||
|
return 0
|
||||||
|
elif command -v rustc &>/dev/null; then
|
||||||
|
rustc -C opt-level=3 "$src" -o "$exe"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [[ -x "$exe" ]]; then
|
||||||
|
printf "ERR: Uncompiled sway_tree.rs script\n"
|
||||||
|
printf "\tInstall a rust compiler and rerun this script\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Tmux
|
# Tmux
|
||||||
####################
|
####################
|
||||||
|
|
Loading…
Reference in a new issue