Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSI3 - Doesnt work if config has varbles #10

Closed
HeCodes2Much opened this issue Sep 11, 2021 · 22 comments
Closed

CSI3 - Doesnt work if config has varbles #10

HeCodes2Much opened this issue Sep 11, 2021 · 22 comments
Labels
Feature Request A new feature is requested.

Comments

@HeCodes2Much
Copy link

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

@HeCodes2Much
Copy link
Author

HeCodes2Much commented Sep 11, 2021

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

@terminalforlife terminalforlife added the Bug Report A bug has been found and reported. label Sep 11, 2021
@terminalforlife
Copy link
Owner

terminalforlife commented Sep 11, 2021

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 terminalforlife added the Feature Request A new feature is requested. label Sep 11, 2021
@HeCodes2Much
Copy link
Author

HeCodes2Much commented Sep 12, 2021

bindsym is set as a variable as displayed below :)

image

also its using the latest version :)

@HeCodes2Much HeCodes2Much changed the title Doesnt work if config has varbles CSI3 - Doesnt work if config has varbles Sep 12, 2021
@terminalforlife terminalforlife removed the Bug Report A bug has been found and reported. label Sep 12, 2021
@terminalforlife
Copy link
Owner

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.

@HeCodes2Much
Copy link
Author

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 :)

@terminalforlife
Copy link
Owner

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.

@HeCodes2Much
Copy link
Author

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

@terminalforlife
Copy link
Owner

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.

@HeCodes2Much
Copy link
Author

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

@terminalforlife
Copy link
Owner

terminalforlife commented Sep 12, 2021

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.

@HeCodes2Much
Copy link
Author

HeCodes2Much commented Sep 12, 2021

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

@terminalforlife
Copy link
Owner

terminalforlife commented Sep 12, 2021

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. :)

@HeCodes2Much
Copy link
Author

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 :)

@HeCodes2Much
Copy link
Author

HeCodes2Much commented Sep 12, 2021

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 :)

@HeCodes2Much
Copy link
Author

HeCodes2Much commented Sep 12, 2021

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

@terminalforlife
Copy link
Owner

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.

@HeCodes2Much
Copy link
Author

HeCodes2Much commented Sep 12, 2021

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

@HeCodes2Much
Copy link
Author

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 :)

@HeCodes2Much
Copy link
Author

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 :)

@HeCodes2Much
Copy link
Author

HeCodes2Much commented Sep 26, 2021

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

@terminalforlife
Copy link
Owner

terminalforlife commented Sep 28, 2021

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 added a commit that referenced this issue May 30, 2023
Updated the 'README.md' and man page to reflect these changes. There's
a new flag which disables this functionality, as explained in the man
page and the comments in the new code included in this commit.

Admittedly, I'm not _yet_ 100% sure this is stable, but I've no reason
to expect it to fail, it's just that there are a lot of moving parts.
Testing showed this works fine. I'm actually amazed not only how well
it works, but how fast BASH can manage to do all of this.
@terminalforlife
Copy link
Owner

I finally did it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request A new feature is requested.
Projects
None yet
Development

No branches or pull requests

2 participants