diff --git a/bin/sway_tree.rs b/bin/sway_tree.rs index 5f7c2b1..f12e74b 100644 --- a/bin/sway_tree.rs +++ b/bin/sway_tree.rs @@ -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 { +fn get_tree() -> io::Result> { 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 = 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) } diff --git a/notes/shell/ssh_port_forwarding.md b/notes/shell/ssh_port_forwarding.md index 2881b8f..da83d85 100644 --- a/notes/shell/ssh_port_forwarding.md +++ b/notes/shell/ssh_port_forwarding.md @@ -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 :: @ & ``` # 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 : ``` diff --git a/post_install.sh b/post_install.sh index c339869..d9f5ac1 100755 --- a/post_install.sh +++ b/post_install.sh @@ -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 ####################