Author Topic: Interactive bspwm configuration tool?  (Read 3146 times)

0 Members and 1 Guest are viewing this topic.

Offline tanaymkis

  • Jr. Mitglied
  • **
  • Posts: 72
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: i3
  • Kernel: 3.18.22-1-MANJARO i686
  • Skill: Novice
Re: Interactive bspwm configuration tool?
« Reply #15 on: 26. February 2016, 14:36:43 »
@Chrysostomus: While the points are valid, pacli was a huge hit and everyone found it beginner friendly. It would also be easier to edit the source code/bash script then editing the code for a ncurses based app.

Also IMO, if people are using the bspwm edition or any tiling wm they are more likely to use the keyboard / start using it more due to the nature of tiling WMs
« Last Edit: 26. February 2016, 14:39:49 by tanaymkis »

Offline Chrysostomus

  • Maintainer
  • ***
  • Posts: 1634
  • Neckbeards are cool
    • Git
  • Branch: unstable
  • Desktop: Gnome, bspwm
  • GPU Card: Intel HD4000
  • GPU driver: free
  • Kernel: linux44-x64
  • Skill: Intermediate
Re: Interactive bspwm configuration tool?
« Reply #16 on: 26. February 2016, 15:09:50 »
A fair point. Maybe I'll begin with something I know how to do.

Offline tanaymkis

  • Jr. Mitglied
  • **
  • Posts: 72
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: i3
  • Kernel: 3.18.22-1-MANJARO i686
  • Skill: Novice
Re: Interactive bspwm configuration tool?
« Reply #17 on: 26. February 2016, 15:33:32 »
That would be the best. Hope to see something nice.

Offline Chrysostomus

  • Maintainer
  • ***
  • Posts: 1634
  • Neckbeards are cool
    • Git
  • Branch: unstable
  • Desktop: Gnome, bspwm
  • GPU Card: Intel HD4000
  • GPU driver: free
  • Kernel: linux44-x64
  • Skill: Intermediate
Re: Interactive bspwm configuration tool?
« Reply #18 on: 26. February 2016, 16:09:31 »
Okay, here is initial sketch:

Code: [Select]
#!/bin/bash

RED='\e[41m'
BLUE='\e[44m'
ORANGE='\e[46m'
NC='\e[0m'

rule_ops()
{
touch /tmp/rule_ops
echo -e "state=$(echo -e "tiling\npseudo-tiling\nfloating\nfullscreen" | fzf-tmux -e --reverse --prompt='Select state for chosen window class >')" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read
window_manage=$(echo -e "on\noff" | fzf-tmux -e --reverse --prompt='manage= >')
echo -e "manage=$window_manage" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read
window_layer=$(echo -e "below\nnormal\nabove" | fzf-tmux -e --reverse --prompt='layer= >')
echo -e "layer=$window_layer" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read
window_flags=$(echo -e "sticky=on\nprivate=on\nlocked=on\nurgent=on\n' '" | fzf-tmux -e -m --reverse --prompt='Choose window flags (tab to select multiple) >')
echo -e "$window_flags" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read
}
add_rule()
{
echo -e "Click on the window you wish to rule..."
class=$(xprop | awk '/WM_CLASS/ {print substr($4, 1, length($4)-1)}' | awk NR==1 | cut -c 2-)
echo ""
echo -e "You have chosen $class."
rule_ops
rule_command="bspc rule -a $class $(cat /tmp/rule_ops | xargs)"
$rule_command
echo "your rule is $rule_command. Would you like to make this rule permanent? (y/N)"
read -s -n1 yesno
case yesno in
y|Y)
echo -e "$rule_command" >> $HOME/.config/bspwm/bspwmrc
;;
*)
echo ""
echo -e "Okay. Press Return to continue"
read
;;
esac
rm /tmp/rule_ops
}
disable_rule()
{
for rule in $(bspc rule -l | fzf-tmux -e -m  --reverse --prompt='Select rules to disable (use TAB to toggle selection) >' | awk '{print substr($1, 1, length($1)-2)}'); do
bspc rule -r $rule
done
}

rm_rule()
{
for rule in $(bspc rule -l | fzf-tmux -e -m  --reverse --prompt='Select rules to remove (use TAB to toggle selection) >' | awk '{print substr($1, 1, length($1)-2)}'); do
sed -i "/rule -a $rule/d" $HOME/.config/bspwm/bspwmrc
sed -i "/rule --add $rule/d" $HOME/.config/bspwm/bspwmrc
done
}

bspwm_cfg()
{
for cfg in borderless_monocle gapless_monocle paddingless_monocle single_monocle history_aware_focus focus_by_distance focus_follows_pointer pointer_follows_focus ignore_emwh_focus center_pseudo-tiled remove_disabled_monitors remove_unplugged_monitors merge_overlapping_monitors; do
echo "$cfg $(bspc config $cfg)" >> /tmp/bspwm-configs
done
toggles=$(cat /tmp/bspwm-configs | fzf-tmux -e -m  --reverse --prompt='Select configs to toggle (use TAB to toggle selection) >')
for tog in $toggles; do
toggle=$(bspc config $tog | \
    awk -vtoggle="true" \
    '{ if ($1 == "true") toggle="false"; print toggle }')

bspc config $tog $toggle
done
rm /tmp/bspwm-configs
}


main()
{
    while true; do
    clear
    echo ""
    echo -e "                     ::Bspwm settings:: "
    echo -e " ┌─────────────────────────────────────────────────────────────┐"
    echo -e " │    1   Add a rule                   2   Remove a rule       │"
    echo -e " │    3   Configure settings           4   Disable a rule      │"
    echo -e " │    5   Edit keydindings             6   Edit .profile       │"   
    echo -e " │    7   Edit autostart               8   Edit bspwmrc        │"
    echo -e " └─────────────────────────────────────────────────────────────┘"
    echo -e "          Select an item       -       0   Exit "
    echo ""
    read -s -n1 choix
    case $choix in
        1)
            echo
            add_rule
            echo ""
            ;;
        2)
            echo
            rm_rule
            echo ""
            ;;
        3)
            echo
            bspwm_cfg
            echo ""
            ;;
        4)
            echo
            disable_rule
            echo ""
            ;;
        5)
            echo
            $EDITOR $HOME/.config/sxhkd/sxhkdrc
            echo ""
            ;;
        6)
            echo
            $EDITOR $HOME/.profile
            echo ""
            ;;
        7)
            echo
            $EDITOR $HOME/.config/bspwm/autostart
            echo ""
            ;;
        8)
            echo
            $EDITOR $HOME/.config/bspwm/bspwmrc
            echo ""
            ;;
        0)
            clear && exit
            read
            ;;
        *)
            echo -e "$RED Wrong option $NC"
            echo "Wait and try again later..."
            echo ""
            sleep 1
            clear
            ;;
    esac
    done
}

main

Option 3 cannot yet deal with settings that are initially not true or false, and option 1 is not made yet. That one is the biggest one.
« Last Edit: 27. February 2016, 07:53:51 by Chrysostomus »

Offline Chrysostomus

  • Maintainer
  • ***
  • Posts: 1634
  • Neckbeards are cool
    • Git
  • Branch: unstable
  • Desktop: Gnome, bspwm
  • GPU Card: Intel HD4000
  • GPU driver: free
  • Kernel: linux44-x64
  • Skill: Intermediate
Re: Interactive bspwm configuration tool?
« Reply #19 on: 26. February 2016, 16:44:13 »
Here is second sketch. Now option 1 lets you choose the window with mouse (requires xprop), makes rule concerning that window class and offers to add it to bspwmrc.

I still need to make helper function to choose options for the rule. Right now the placeholder just sets the ruled window floating...

Code: [Select]
#!/bin/bash

RED='\e[41m'
BLUE='\e[44m'
ORANGE='\e[46m'
NC='\e[0m'

rule_ops()
{
echo state=floating
}
add_rule()
{
echo -e "Click on the window you wish to rule..."
class=$(xprop | awk '/WM_CLASS/ {print substr($4, 1, length($4)-1)}' | awk NR==1 | cut -c 2-)
rule_options=$(rule_ops)
echo -e "You have chosen $class. Press any key to proceed..."
read
rule_command="bspc rule -a $class $rule_options"
$rule_command
echo "your rule is $rule_command. Would you like to make this rule permanent? (y/N)"
read -s -n1 yesno
case yesno in
y|Y)
echo -e "$rule_command" >> $HOME/.config/bspwm/bspwmrc
;;
*)
echo ""
echo -e "Okay. Press any key to continue"
read
;;
esac
}
disable_rule()
{
for rule in $(bspc rule -l | fzf-tmux -e -m  --reverse --prompt='Select rules to disable (use TAB to toggle selection) >' | awk '{print substr($1, 1, length($1)-2)}'); do
bspc rule -r $rule
done
}

rm_rule()
{
for rule in $(bspc rule -l | fzf-tmux -e -m  --reverse --prompt='Select rules to remove (use TAB to toggle selection) >' | awk '{print substr($1, 1, length($1)-2)}'); do
sed -i "/rule -a $rule/d" $HOME/.config/bspwm/bspwmrc
sed -i "/rule --add $rule/d" $HOME/.config/bspwm/bspwmrc
done
}

bspwm_cfg()
{
for cfg in borderless_monocle gapless_monocle paddingless_monocle single_monocle history_aware_focus focus_by_distance focus_follows_pointer pointer_follows_focus ignore_emwh_focus center_pseudo-tiled remove_disabled_monitors remove_unplugged_monitors merge_overlapping_monitors; do
echo "$cfg $(bspc config $cfg)" >> /tmp/bspwm-configs
done
toggles=$(cat /tmp/bspwm-configs | fzf-tmux -e -m  --reverse --prompt='Select configs to toggle (use TAB to toggle selection) >')
for tog in $toggles; do
toggle=$(bspc config $tog | \
    awk -vtoggle="true" \
    '{ if ($1 == "true") toggle="false"; print toggle }')

bspc config $tog $toggle
done
rm /tmp/bspwm-configs
}


main()
{
    while true; do
    clear
    echo ""
    echo -e "                     ::Bspwm settings:: "
    echo -e " ┌─────────────────────────────────────────────────────────────┐"
    echo -e " │    1   Add a rule                   2   Remove a rule       │"
    echo -e " │    3   Configure settings           4   Disable a rule      │"
    echo -e " │    5   Edit keydindings             6   Edit .profile       │"   
    echo -e " │    7   Edit autostart               8   Edit bspwmrc        │"
    echo -e " └─────────────────────────────────────────────────────────────┘"
    echo -e "          Select an item       -       0   Exit "
    echo ""
    read -s -n1 choix
    case $choix in
        1)
            echo
            add_rule
            echo ""
            ;;
        2)
            echo
            rm_rule
            echo ""
            ;;
        3)
            echo
            bspwm_cfg
            echo ""
            ;;
        4)
            echo
            disable_rule
            echo ""
            ;;
        5)
            echo
            $EDITOR $HOME/.config/sxhkd/sxhkdrc
            echo ""
            ;;
        6)
            echo
            $EDITOR $HOME/.profile
            echo ""
            ;;
        7)
            echo
            $EDITOR $HOME/.config/bspwm/autostart
            echo ""
            ;;
        8)
            echo
            $EDITOR $HOME/.config/bspwm/bspwmrc
            echo ""
            ;;
        0)
            clear && exit
            read
            ;;
        *)
            echo -e "$RED Wrong option $NC"
            echo "Wait and try again later..."
            echo ""
            sleep 1
            clear
            ;;
    esac
    done
}

main

Offline tanaymkis

  • Jr. Mitglied
  • **
  • Posts: 72
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: i3
  • Kernel: 3.18.22-1-MANJARO i686
  • Skill: Novice
Re: Interactive bspwm configuration tool?
« Reply #20 on: 27. February 2016, 07:46:49 »
So far so good! Everything seems to be working the way it should.

Offline Chrysostomus

  • Maintainer
  • ***
  • Posts: 1634
  • Neckbeards are cool
    • Git
  • Branch: unstable
  • Desktop: Gnome, bspwm
  • GPU Card: Intel HD4000
  • GPU driver: free
  • Kernel: linux44-x64
  • Skill: Intermediate
Re: Interactive bspwm configuration tool?
« Reply #21 on: 27. February 2016, 07:50:55 »
Code: [Select]
#!/bin/bash

RED='\e[41m'
BLUE='\e[44m'
ORANGE='\e[46m'
NC='\e[0m'

rule_ops()
{
touch /tmp/rule_ops
echo -e "state=$(echo -e "tiling\npseudo-tiling\nfloating\nfullscreen" | fzf-tmux -e --reverse --prompt='Select state for chosen window class >')" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read
window_manage=$(echo -e "on\noff" | fzf-tmux -e --reverse --prompt='manage= >')
echo -e "manage=$window_manage" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read
window_layer=$(echo -e "below\nnormal\nabove" | fzf-tmux -e --reverse --prompt='layer= >')
echo -e "layer=$window_layer" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read
window_flags=$(echo -e "sticky=on\nprivate=on\nlocked=on\nurgent=on\n' '" | fzf-tmux -e -m --reverse --prompt='Choose window flags (tab to select multiple) >')
echo -e "$window_flags" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read
}
add_rule()
{
echo -e "Click on the window you wish to rule..."
class=$(xprop | awk '/WM_CLASS/ {print substr($4, 1, length($4)-1)}' | awk NR==1 | cut -c 2-)
echo ""
echo -e "You have chosen $class."
rule_ops
rule_command="bspc rule -a $class $(cat /tmp/rule_ops | xargs)"
$rule_command
echo "your rule is $rule_command. Would you like to make this rule permanent? (y/N)"
read -s -n1 yesno
case yesno in
y|Y)
echo -e "$rule_command" >> $HOME/.config/bspwm/bspwmrc
;;
*)
echo ""
echo -e "Okay. Press Return to continue"
read
;;
esac
rm /tmp/rule_ops
}
disable_rule()
{
for rule in $(bspc rule -l | fzf-tmux -e -m  --reverse --prompt='Select rules to disable (use TAB to toggle selection) >' | awk '{print substr($1, 1, length($1)-2)}'); do
bspc rule -r $rule
done
}

rm_rule()
{
for rule in $(bspc rule -l | fzf-tmux -e -m  --reverse --prompt='Select rules to remove (use TAB to toggle selection) >' | awk '{print substr($1, 1, length($1)-2)}'); do
sed -i "/rule -a $rule/d" $HOME/.config/bspwm/bspwmrc
sed -i "/rule --add $rule/d" $HOME/.config/bspwm/bspwmrc
done
}

bspwm_cfg()
{
for cfg in borderless_monocle gapless_monocle paddingless_monocle single_monocle history_aware_focus focus_by_distance focus_follows_pointer pointer_follows_focus ignore_emwh_focus center_pseudo-tiled remove_disabled_monitors remove_unplugged_monitors merge_overlapping_monitors; do
echo "$cfg $(bspc config $cfg)" >> /tmp/bspwm-configs
done
toggles=$(cat /tmp/bspwm-configs | fzf-tmux -e -m  --reverse --prompt='Select configs to toggle (use TAB to toggle selection) >')
for tog in $toggles; do
toggle=$(bspc config $tog | \
    awk -vtoggle="true" \
    '{ if ($1 == "true") toggle="false"; print toggle }')

bspc config $tog $toggle
done
rm /tmp/bspwm-configs
}


main()
{
    while true; do
    clear
    echo ""
    echo -e "                     ::Bspwm settings:: "
    echo -e " ┌─────────────────────────────────────────────────────────────┐"
    echo -e " │    1   Add a rule                   2   Remove a rule       │"
    echo -e " │    3   Configure settings           4   Disable a rule      │"
    echo -e " │    5   Edit keydindings             6   Edit .profile       │"   
    echo -e " │    7   Edit autostart               8   Edit bspwmrc        │"
    echo -e " └─────────────────────────────────────────────────────────────┘"
    echo -e "          Select an item       -       0   Exit "
    echo ""
    read -s -n1 choix
    case $choix in
        1)
            echo
            add_rule
            echo ""
            ;;
        2)
            echo
            rm_rule
            echo ""
            ;;
        3)
            echo
            bspwm_cfg
            echo ""
            ;;
        4)
            echo
            disable_rule
            echo ""
            ;;
        5)
            echo
            $EDITOR $HOME/.config/sxhkd/sxhkdrc
            echo ""
            ;;
        6)
            echo
            $EDITOR $HOME/.profile
            echo ""
            ;;
        7)
            echo
            $EDITOR $HOME/.config/bspwm/autostart
            echo ""
            ;;
        8)
            echo
            $EDITOR $HOME/.config/bspwm/bspwmrc
            echo ""
            ;;
        0)
            clear && exit
            read
            ;;
        *)
            echo -e "$RED Wrong option $NC"
            echo "Wait and try again later..."
            echo ""
            sleep 1
            clear
            ;;
    esac
    done
}

main

Now there is rudimentary rule adding tool. I tried to make it optional to set different options, but that did not seem to work. So you have to choose flags for all ruled windows, etc. This needs to be fixed before release.
« Last Edit: 27. February 2016, 07:54:12 by Chrysostomus »

Offline tanaymkis

  • Jr. Mitglied
  • **
  • Posts: 72
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: i3
  • Kernel: 3.18.22-1-MANJARO i686
  • Skill: Novice
Re: Interactive bspwm configuration tool?
« Reply #22 on: 27. February 2016, 08:06:31 »
That's great! What about different apps going to different workspaces ?

Offline Chrysostomus

  • Maintainer
  • ***
  • Posts: 1634
  • Neckbeards are cool
    • Git
  • Branch: unstable
  • Desktop: Gnome, bspwm
  • GPU Card: Intel HD4000
  • GPU driver: free
  • Kernel: linux44-x64
  • Skill: Intermediate
Re: Interactive bspwm configuration tool?
« Reply #23 on: 27. February 2016, 08:59:43 »
Can be done, but I don't want to add that before making parts of rule script optional. Current hack is choosing empty option woth fzf, but I wish to make something better. Like give 'any' option and pipe it through case statement.

Offline tanaymkis

  • Jr. Mitglied
  • **
  • Posts: 72
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: i3
  • Kernel: 3.18.22-1-MANJARO i686
  • Skill: Novice
Re: Interactive bspwm configuration tool?
« Reply #24 on: 27. February 2016, 09:04:23 »
Well, is there anything I can do to help ?

Offline Chrysostomus

  • Maintainer
  • ***
  • Posts: 1634
  • Neckbeards are cool
    • Git
  • Branch: unstable
  • Desktop: Gnome, bspwm
  • GPU Card: Intel HD4000
  • GPU driver: free
  • Kernel: linux44-x64
  • Skill: Intermediate
Re: Interactive bspwm configuration tool?
« Reply #25 on: 27. February 2016, 09:30:04 »
Make suggestions here: https://github.com/Chrysostomus/bspwm-ruler/blob/master/bspwm-ruler and send pull request?

I can probably do the change myself, I just have limited time (and do things by trial and error)

Offline Chrysostomus

  • Maintainer
  • ***
  • Posts: 1634
  • Neckbeards are cool
    • Git
  • Branch: unstable
  • Desktop: Gnome, bspwm
  • GPU Card: Intel HD4000
  • GPU driver: free
  • Kernel: linux44-x64
  • Skill: Intermediate
Re: Interactive bspwm configuration tool?
« Reply #26 on: 27. February 2016, 15:15:05 »
Okay, now it has also option not to give flags or desktop, but can give them:

Code: [Select]
#!/bin/bash

RED='\e[41m'
BLUE='\e[44m'
ORANGE='\e[46m'
NC='\e[0m'

rule_ops()
{
# make a temporary file for options
touch /tmp/rule_ops
# choose window state
echo -e "state=$(echo -e "tiling\npseudo-tiling\nfloating\nfullscreen" | fzf-tmux -e --reverse --prompt='Select state for chosen window class >')" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read -s -n1
# choose if window  should be managed
window_manage=$(echo -e "on\noff" | fzf-tmux -e --reverse --prompt='Manage= >')
echo -e "manage=$window_manage" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read -s -n1
# choose window layer
window_layer=$(echo -e "below\nnormal\nabove" | fzf-tmux -e --reverse --prompt='Layer= >')
echo -e "layer=$window_layer" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read -s -n1
# choose window flags
window_flags=$(echo -e "sticky=on\nprivate=on\nlocked=on\nurgent=on\n " | fzf-tmux -e -m --reverse --prompt='Choose window flags (tab to select multiple, choose empty if you want none) >')
echo -e "$window_flags" >> /tmp/rule_ops
cat /tmp/rule_ops | xargs
read -s -n1
window_desktop=$(echo -e "$(bspc query -D)\nAny" | fzf-tmux -e --reverse --prompt='Desktop= >')
echo "$window_desktop" | {
read desk
if [ "$desk" = 'Any' ] ; then
echo ""
else
echo -e "$desk" >> /tmp/rule_ops
fi
}
cat /tmp/rule_ops | xargs
read -s -n1
}
add_rule()
{
echo -e "Click on the window you wish to rule..."
class=$(xprop | awk '/WM_CLASS/ {print substr($4, 1, length($4)-1)}' | awk NR==1 | cut -c 2-)
echo ""
echo -e "You have chosen $class."
rule_ops
rule_command="bspc rule -a $class $(cat /tmp/rule_ops | xargs)"
$rule_command
echo "your rule is $rule_command. Would you like to make this rule permanent? (y/N)"
read -s -n1 yesno
case yesno in
y|Y)
echo -e "$rule_command" >> $HOME/.config/bspwm/bspwmrc
;;
*)
echo ""
echo -e "Okay. Press Return to continue"
read
;;
esac
rm /tmp/rule_ops
}
disable_rule()
{
for rule in $(bspc rule -l | fzf-tmux -e -m  --reverse --prompt='Select rules to disable (use TAB to toggle selection) >' | awk '{print substr($1, 1, length($1)-2)}'); do
bspc rule -r $rule
done
}

rm_rule()
{
for rule in $(bspc rule -l | fzf-tmux -e -m  --reverse --prompt='Select rules to remove (use TAB to toggle selection) >' | awk '{print substr($1, 1, length($1)-2)}'); do
sed -i "/rule -a $rule/d" $HOME/.config/bspwm/bspwmrc
sed -i "/rule --add $rule/d" $HOME/.config/bspwm/bspwmrc
done
}

bspwm_cfg()
{
for cfg in borderless_monocle gapless_monocle paddingless_monocle single_monocle history_aware_focus focus_by_distance focus_follows_pointer pointer_follows_focus ignore_emwh_focus center_pseudo-tiled remove_disabled_monitors remove_unplugged_monitors merge_overlapping_monitors; do
echo "$cfg $(bspc config $cfg)" >> /tmp/bspwm-configs
done
toggles=$(cat /tmp/bspwm-configs | fzf-tmux -e -m  --reverse --prompt='Select configs to toggle (use TAB to toggle selection) >')
for tog in $toggles; do
toggle=$(bspc config $tog | \
    awk -vtoggle="true" \
    '{ if ($1 == "true") toggle="false"; print toggle }')

bspc config $tog $toggle
done
rm /tmp/bspwm-configs
}


main()
{
    while true; do
    clear
    echo ""
    echo -e "                     ::Bspwm settings:: "
    echo -e " ┌─────────────────────────────────────────────────────────────┐"
    echo -e " │    1   Add a rule                   2   Remove a rule       │"
    echo -e " │    3   Configure settings           4   Disable a rule      │"
    echo -e " │    5   Edit keydindings             6   Edit .profile       │"   
    echo -e " │    7   Edit autostart               8   Edit bspwmrc        │"
    echo -e " └─────────────────────────────────────────────────────────────┘"
    echo -e "          Select an item       -       0   Exit "
    echo ""
    read -s -n1 choix
    case $choix in
        1)
            echo
            add_rule
            echo ""
            ;;
        2)
            echo
            rm_rule
            echo ""
            ;;
        3)
            echo
            bspwm_cfg
            echo ""
            ;;
        4)
            echo
            disable_rule
            echo ""
            ;;
        5)
            echo
            $EDITOR $HOME/.config/sxhkd/sxhkdrc
            echo ""
            ;;
        6)
            echo
            $EDITOR $HOME/.profile
            echo ""
            ;;
        7)
            echo
            $EDITOR $HOME/.config/bspwm/autostart
            echo ""
            ;;
        8)
            echo
            $EDITOR $HOME/.config/bspwm/bspwmrc
            echo ""
            ;;
        0)
            clear && exit
            read
            ;;
        *)
            echo -e "$RED Wrong option $NC"
            echo "Wait and try again later..."
            echo ""
            sleep 1
            clear
            ;;
    esac
    done
}

main

Offline Chrysostomus

  • Maintainer
  • ***
  • Posts: 1634
  • Neckbeards are cool
    • Git
  • Branch: unstable
  • Desktop: Gnome, bspwm
  • GPU Card: Intel HD4000
  • GPU driver: free
  • Kernel: linux44-x64
  • Skill: Intermediate
Re: Interactive bspwm configuration tool?
« Reply #27 on: 28. February 2016, 16:35:25 »
Okay, I sorted the problem with option 3 and made it easier to avoid giving rulings you dont want. Pressing ctrl+c in fzf now leaves that section of the rule undecided.

This now practically usable:


Code: [Select]
#!/bin/bash

RED='\e[41m'
BLUE='\e[44m'
ORANGE='\e[46m'
NC='\e[0m'

trap '[[ -e /tmp/rule_ops ]] && rm /tmp/rule_ops' EXIT SIGTERM
rule_ops()
{
# make a temporary file for options
touch /tmp/rule_ops
# choose window state
window_state=$(echo -e "tiling\npseudo_tiled\nfloating\nfullscreen" | fzf-tmux -e --reverse --prompt='Select state for chosen window class >')
[ -n "$window_state" ] && echo -e "state=$window_state" >> /tmp/rule_ops

# choose if window  should be managed
window_manage=$(echo -e "on\noff" | fzf-tmux -e --reverse --prompt='Manage= >')
[ -n "$window_manage" ] && echo -e "manage=$window_manage" >> /tmp/rule_ops

# choose window layer
window_layer=$(echo -e "below\nnormal\nabove" | fzf-tmux -e --reverse --prompt='Layer= >')
[ -n "$window_layer" ] && echo -e "layer=$window_layer" >> /tmp/rule_ops

# choose window flags
window_flags=$(echo -e "sticky=on\nprivate=on\nlocked=on\nurgent=on\n " | fzf-tmux -e -m --reverse --prompt='Choose window flags (tab to select multiple, choose empty if you want none) >')
[ -n "$window_flags" ] && echo -e "$window_flags" >> /tmp/rule_ops

window_desktop=$(echo -e "$(bspc query -D)\nAny" | fzf-tmux -e --reverse --prompt='Desktop= >')
echo "$window_desktop" | {
read desk
if [ "$desk" = 'Any' ] ; then
echo ""
else
[ -n "$desk" ] && echo -e "desktop=$desk" >> /tmp/rule_ops
fi
}
# choose if window should be followed if it spawns on another desktop
window_follow=$(echo -e "on\noff" | fzf-tmux -e --reverse --prompt='Follow= >')
[ -n "$window_follow" ] && echo -e "follow=$window_follow" >> /tmp/rule_ops
}
add_rule()
{
echo -e "Click on the window you wish to rule..."
class=$(xprop | awk '/WM_CLASS/ {print substr($4, 1, length($4)-1)}' | awk NR==1 | cut -c 2-)
echo ""
echo -e "You have chosen $class."
read -s -n1
rule_ops
rule_command="bspc rule -a $class $(cat /tmp/rule_ops | xargs)"
$rule_command
echo "your rule is $rule_command. Would you like to make this rule permanent? (y/N)"
read -s -n1 yesno
case $yesno in
y|Y)
echo -e "$rule_command" >> $HOME/.config/bspwm/bspwmrc
echo -e "The command has been added to your bspwmrc. Press any key to continue."
read -s -n1
;;
*)
echo ""
echo -e "Okay. Press any key to continue."
read -s -n1
;;
esac
rm /tmp/rule_ops
}
disable_rule()
{
for rule in $(bspc rule -l | fzf-tmux -e -m  --reverse --prompt='Select rules to disable (use TAB to toggle selection) >' | awk '{print substr($1, 1, length($1)-2)}'); do
bspc rule -r $rule
done
}

rm_rule()
{
for rule in $(bspc rule -l | fzf-tmux -e -m  --reverse --prompt='Select rules to remove (use TAB to toggle selection) >' | awk '{print substr($1, 1, length($1)-2)}'); do
sed -i "/rule -a $rule/d" $HOME/.config/bspwm/bspwmrc
sed -i "/rule --add $rule/d" $HOME/.config/bspwm/bspwmrc
done
}

bspwm_cfg()
{
for cfg in borderless_monocle gapless_monocle paddingless_monocle single_monocle history_aware_focus focus_by_distance focus_follows_pointer pointer_follows_focus ignore_ewmh_focus center_pseudo_tiled remove_disabled_monitors remove_unplugged_monitors merge_overlapping_monitors ; do
echo "$cfg $(bspc config $cfg)" >> /tmp/bspwm-configs
done
toggles=$(cat /tmp/bspwm-configs | fzf-tmux -e -m  --reverse --prompt='Select configs to toggle (use TAB to toggle selection) >')
for tog in $toggles; do
toggle=$(bspc config $tog | \
    awk -vtoggle="true" \
    '{ if ($1 == "true") toggle="false"; print toggle }')

[[ ! "$toggle" == 'true' && ! "$toggle" == 'false' ]] && bspc config $tog true
bspc config $tog $toggle
done
rm /tmp/bspwm-configs
}


main()
{
    while true; do
    clear
    echo ""
    echo -e "                     ::Bspwm settings:: "
    echo -e " ┌─────────────────────────────────────────────────────────────┐"
    echo -e " │    1   Add a rule                   2   Remove a rule       │"
    echo -e " │    3   Configure settings           4   Disable a rule      │"
    echo -e " │    5   Edit keydindings             6   Edit .profile       │"   
    echo -e " │    7   Edit autostart               8   Edit bspwmrc        │"
    echo -e " └─────────────────────────────────────────────────────────────┘"
    echo -e "          Select an item       -       0   Exit "
    echo ""
    read -s -n1 choix
    case $choix in
        1)
            echo
            add_rule
            echo ""
            ;;
        2)
            echo
            rm_rule
            echo ""
            ;;
        3)
            echo
            bspwm_cfg
            echo ""
            ;;
        4)
            echo
            disable_rule
            echo ""
            ;;
        5)
            echo
            $EDITOR $HOME/.config/sxhkd/sxhkdrc
            echo ""
            ;;
        6)
            echo
            $EDITOR $HOME/.profile
            echo ""
            ;;
        7)
            echo
            $EDITOR $HOME/.config/bspwm/autostart
            echo ""
            ;;
        8)
            echo
            $EDITOR $HOME/.config/bspwm/bspwmrc
            echo ""
            ;;
        0)
            clear && exit
            read
            ;;
        *)
            echo -e "$RED Wrong option $NC"
            echo "Wait and try again later..."
            echo ""
            sleep 1
            clear
            ;;
    esac
    done
}

main

Offline Chrysostomus

  • Maintainer
  • ***
  • Posts: 1634
  • Neckbeards are cool
    • Git
  • Branch: unstable
  • Desktop: Gnome, bspwm
  • GPU Card: Intel HD4000
  • GPU driver: free
  • Kernel: linux44-x64
  • Skill: Intermediate
Re: Interactive bspwm configuration tool?
« Reply #28 on: 04. March 2016, 04:37:48 »
The tools is now in the repos, under the name "bspwm-ruler".

Please test and comment if you have time.

Offline ThatKawaiiGuy

  • Neuling
  • *
  • Posts: 13
  • Branch: Testing
  • Desktop: i3
  • Kernel: Linux40-x64
  • Skill: Novice
Re: Interactive bspwm configuration tool?
« Reply #29 on: 06. March 2016, 08:31:38 »
It's neat, I like it. When I try to edit bspwmrc it does some funky stuff but I'm pretty sure that's cause my rc is wonky.

I couldn't find it on the repos btw, I just found it on your github.