Remove jq dependency from sway_tree script
This commit is contained in:
parent
38915b0a0a
commit
08ecfff92d
|
@ -23,42 +23,35 @@
|
|||
// └───> [Alacritty]
|
||||
|
||||
use std::io::{self, BufRead, BufReader};
|
||||
use std::process::{Command, Stdio, ChildStdout};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::cmp::min;
|
||||
|
||||
fn main() {
|
||||
let sway_tree = match get_tree() {
|
||||
Ok(tree) => BufReader::new(tree).lines().map(|l| l.unwrap()),
|
||||
Err(e) => panic!("Failed to get sway tree: {}", e),
|
||||
};
|
||||
let sway_tree = get_tree().expect("Failed to get sway tree");
|
||||
|
||||
for (i, line) in sway_tree.enumerate() {
|
||||
for (i, line) in sway_tree.iter().enumerate() {
|
||||
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")
|
||||
.arg("-t")
|
||||
.arg("get_tree")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
let jq = Command::new("jq")
|
||||
.arg(".nodes[1].nodes[].representation")
|
||||
.stdin(swaymsg.stdout.unwrap())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("`jq` binary is not available");
|
||||
let swaymsg_out = swaymsg.stdout.expect("Swaymsg didn't return window tree");
|
||||
|
||||
let tr = Command::new("tr")
|
||||
.arg("-d")
|
||||
.arg("\"")
|
||||
.stdin(jq.stdout.unwrap())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?;
|
||||
let repr: Vec<String> = BufReader::new(swaymsg_out)
|
||||
.lines()
|
||||
.map(|l| l.unwrap().trim().to_string())
|
||||
.filter(|l| &l[..min(16, l.len())] == "\"representation\"")
|
||||
.map(|l| l[19..l.len()-1].to_string())
|
||||
.collect();
|
||||
|
||||
Ok(tr.stdout.unwrap())
|
||||
Ok(repr)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,14 +13,21 @@ Some key terms:
|
|||
|
||||
The opens an ssh tunnel without obstructing the current terminal:
|
||||
```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> &
|
||||
```
|
||||
|
||||
# In config file
|
||||
The syntax in the config is quite similar
|
||||
The syntax in the `~/.ssh/config` is quite similar
|
||||
|
||||
```ssh
|
||||
Host mirrorside
|
||||
User emiliko
|
||||
Hostname cs.ox.ac.uk
|
||||
LocalForward 8001 localhost:7000
|
||||
```
|
||||
|
||||
The general format looks like
|
||||
```ssh
|
||||
LocalForward <client-port> <host-address>:<host-port>
|
||||
```
|
||||
|
|
|
@ -36,6 +36,7 @@ configs_pointer_is_setup() {
|
|||
swayland_checks() {
|
||||
check_sway_wallpaper
|
||||
check_swaylock_wallpaper
|
||||
check_swaytree_compilation
|
||||
}
|
||||
|
||||
check_sway_wallpaper() {
|
||||
|
@ -71,6 +72,25 @@ check_swaylock_wallpaper() {
|
|||
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
|
||||
####################
|
||||
|
|
Loading…
Reference in a new issue