ShellProjects icon indicating copy to clipboard operation
ShellProjects copied to clipboard

CSI3 - Doesnt work if config has varbles

Open CreativeCodeCat opened this issue 4 years ago • 21 comments
trafficstars

when using a config like DotFiles/main/i3/.config/i3/config it does not seem to wanna work as displayed in the image below

image

only seems to work on 1 liners and without varbles when it should convert the varbles in my opnion

CreativeCodeCat avatar Sep 11 '21 17:09 CreativeCodeCat

this may help to see how i did this kind of thing for dmenu, rofi, yad and fzf

#!/usr/bin/env bash

cmd="\grep -A 1 Description ""$HOME""/.config/i3/config | sed -e s/--/\ /g"
case $1 in
	fzf) cmd="$cmd -e s/Description:\ //gI" && eval "$cmd" | sed -e 's/[\\$]//g' | sed -e 's/_b//g' | sed -e 's/+/ + /g' | awk '/^[a-z]/ && last {print last,$0,";"} {last=""} /^#/{last=$0}' | column -t -s ';' | fzf;;
	yad) cmd="$cmd -e s/Description:\ //gI" && eval "$cmd" | sed -e 's/[\\$]//g' | sed -e 's/_b//g' | sed -e 's/+/ + /g' | awk '/^[a-z]/ && last {print last,$0,";"} {last=""} /^#/{last=$0}' | column -t -s ';' | yad --text-info --width=800 --height=800;;
	dmenu) cmd="$cmd -e s/Description:\ //gI" && eval "$cmd" | sed -e 's/[\\$]//g' | sed -e 's/_b//g' | sed -e 's/+/ + /g' | awk '/^[a-z]/ && last {print last,$0,";"} {last=""} /^#/{last=$0}' | column -t -s ';' | dmenu -l 10 -p "Search Keybind";;
	rofi) cmd="$cmd -e s/Description:\ //gI" && eval "$cmd" | sed -e 's/[\\$]//g' | sed -e 's/_b//g' | sed -e 's/+/ + /g' | awk '/^[a-z]/ && last {print last,$0,";"} {last=""} /^#/{last=$0}' | column -t -s ';' | rofi -dmenu -i -width 1000 -p "Search Keybind";;
	*) cmd="$cmd -e s/Description:\ //gI" && eval "$cmd" | sed -e 's/[\\$]//g' | sed -e 's/_b//g' | sed -e 's/+/ + /g' | awk '/^[a-z$]/ && last {print last,$0,";"} {last=""} /^#/{last=$0}' | column -t -s ';' | dmenu -i -c -l 10 -p "Search Keybind" -wm;;
esac

example image

CreativeCodeCat avatar Sep 11 '21 17:09 CreativeCodeCat

Yeah, I should've taken note of it not reading the modifier key if it's set using a variable, but it wouldn't be too much to look for that assignment, then substitute that assigned key whenever it sees the variable which assigns it. Unfortunately, you can name a variable anything you like, so it's not really going to be a perfect system. :\

Thanks for reporting this and for showing your configuration. Unfortunately, from looking at your file more closely, it's pretty clear that it's not going to be practical to support it. You've gone above and beyond to make it considerably different to the standard approach, even splitting up the lines which set bindings. I could add a bunch of code to handle it, but it'd add unnecessary heft and complexity to CSi3.

I also see a lack of bindsym lines, on which CSi3 depends. For which version of i3 are you using that file? Is it new syntax?

terminalforlife avatar Sep 11 '21 19:09 terminalforlife

bindsym is set as a variable as displayed below :)

image

also its using the latest version :)

CreativeCodeCat avatar Sep 12 '21 13:09 CreativeCodeCat

Thanks to you making this issue, in the recent update for CSi3, I supported the use of $mod (case insensitive). :)

I could handle the edge case of having bindsym in a variable, but since it's non-standard, I'll leave it as-is. What you could do, is use bindsym in the standard way, then those lines would be matched. Unfortunately, you'd have to make quite a few changes to your 'config' for it work, because you've still split up bindsym lines a lot.

terminalforlife avatar Sep 12 '21 16:09 terminalforlife

i really like seeing these kind of scripts and watching them evolve over time :) keep up the grate work. also feel free to close this if you are done :)

CreativeCodeCat avatar Sep 12 '21 16:09 CreativeCodeCat

Actually, I've just noticed something else: modes aren't supported at all. I should probably try to support that, but I dunno how reliable that would be. I've been adding to the README.md for CSi3, for the Caveat(s) section.

...and thanks. :) Your issue reports are very welcome.

terminalforlife avatar Sep 12 '21 16:09 terminalforlife

I use DWM mostly but i did use i3 from 2009 until 2020 when i switched over to using dwm :) so i also checked out the dwm script and found issues/11

CreativeCodeCat avatar Sep 12 '21 16:09 CreativeCodeCat

I've figured out a way I could begin to parse your configuration file. I'm pretty sure I'd have to pre-process it, unfortunately. The first time would be to determine the correct output based on the variables you've set, then the second time would be as normal. It still wouldn't read the modes properly.

Catching the newlines in the middle of the commands might just be a case of detecting \, ignoring it, then reading from the rest of the command on the line immediately below it. It'd probably wind up taking a lot more code.

I wonder if i3 has a way to display all of the bindings, even in a raw format, which CSi3 could instead or alternatively parse. Like how you can output all of the workspaces, windows, and their information.

terminalforlife avatar Sep 12 '21 17:09 terminalforlife

i3 does have an api to it that can get the current used config but im not sure if you can get just the keybinds from that

CreativeCodeCat avatar Sep 12 '21 17:09 CreativeCodeCat

Are you thinking of i3-msg -t get_tree? Because that only gets the workspace and window information, not the bindings. :( There's get_config, but that just spits out the config file's contents. There's a couple of types for getting the mode state and current mode, but that's not much use here.

There's an AnyEvent::I3 PERL module which I sometimes use, but I don't know if that will show bindings; if it does, that'd be amazing, because I could just rewrite CSi3 in PERL, using that module.

terminalforlife avatar Sep 12 '21 17:09 terminalforlife

i know python and purl has i3ipc that can get info from i3 but im not 100% sure if it can break down the info to bindings only

CreativeCodeCat avatar Sep 12 '21 17:09 CreativeCodeCat

Just spent about an hour working on it. It wound up being so convoluted and complicated, that I've decided to never try that again, at least not in Shell. Lol It was worth a try. Here's what I came up with (ignore AE on the right):

Screenshot_2021-09-12_19:15:42

The new code is the top-most section and the new block in the main while loop. I thought I had it, honestly, but it just wasn't working out, and it was quite slow, because of the nested looping. I just couldn't get the contents of the variables to substitute properly, and even if they would, it wouldn't be reliable.

I could just preprocess with sed(1), but then it wouldn't be pure-BASH, and it would wind up really clunky. Honestly, I may just rewrite it in PERL anyway, at which point I might have more luck doing this stuff. At last $mod is correctly being substituted. :)

terminalforlife avatar Sep 12 '21 18:09 terminalforlife

welcome to my world :) bash can sure be a pain to deal with at times but when it all works out its sure fun in the end :) now others can have funny configs and not just stick with the defaults :)

CreativeCodeCat avatar Sep 12 '21 18:09 CreativeCodeCat

I just had a try of grep -A 1 super_b $HOME/.config/i3/config | sed -e s/--/\ /g and that picked up all commands that have the super key in them if that is any help :)

CreativeCodeCat avatar Sep 12 '21 18:09 CreativeCodeCat

this code block below will get the list of commands but then they need converted back to being on 1 line again instead of 2 lines but it works to get them

cat $HOME/.config/i3/config | \
    sed 's/$super_b/bindsym Mod4/g' | \
    sed 's/$super/Mod4/g' | \

    sed 's/$alt_b/bindsym Mod1/g' | \
    sed 's/$alt/Mod1/g' | \

    sed 's/$control_b/bindsym Ctrl/g' | \
    sed 's/$control/Ctrl/g' | \

    sed 's/$shift_b/bindsym Shift/g' | \
    sed 's/$shift/Shift/g' | \

    sed 's/$exe_always/exec --no-startup-i/g' | \
    sed 's/$exe/exec_always --no-startup-id/g' | \
    sed 's/$print_b/bindsym Print/g' | \
    grep -A 1 bindsym

also cat $HOME/.config/i3/config | grep -A 0 "^set " | sed -e '1,/^--/d' -e '/^--/,$d' this can get the list of sets so if we could use sed and awk on each line to replace field 2 with field 3+ that could any of the sets :)

image

CreativeCodeCat avatar Sep 12 '21 18:09 CreativeCodeCat

You've somehow got me thinking: AWK would probably do this quite well, because it can substitute in a sed(1)-like way with sub() and gsub(). The entirety of CSi3 could be written in AWK.

terminalforlife avatar Sep 12 '21 19:09 terminalforlife

so this is an example what what i have come up with now its just to parse the list above :) instead of using all them sed commands

example below image

CreativeCodeCat avatar Sep 12 '21 19:09 CreativeCodeCat

This is really tempting me to move back to i3 from dwm as I don't use layouts in dwm anyways so who knows what I'll do when I get back home from work :)

CreativeCodeCat avatar Sep 14 '21 11:09 CreativeCodeCat

Going back to my good old i3 and get this working :) I miss my i3 and dwm really isn't kicking it for me after 8 months using it after 11 years using i3 :)

CreativeCodeCat avatar Sep 23 '21 07:09 CreativeCodeCat

@terminalforlife do you know if there is a way to chain keybinds in i3 without using modes

CreativeCodeCat avatar Sep 26 '21 09:09 CreativeCodeCat

Not quite sure what you mean, but on the off-chance you're referring to, for example, this, then yes:

bindsym Mod1+Enter exec xfce4-terminal; exec notify-send 'Terminal opened.'

terminalforlife avatar Sep 28 '21 21:09 terminalforlife

I finally did it. :)

terminalforlife avatar May 30 '23 22:05 terminalforlife