Skip to content

Instantly share code, notes, and snippets.

@emanuele6
Last active November 21, 2024 06:00
Show Gist options
  • Save emanuele6/31bec2a0e1b61d0ba8b0434409f13e38 to your computer and use it in GitHub Desktop.
Save emanuele6/31bec2a0e1b61d0ba8b0434409f13e38 to your computer and use it in GitHub Desktop.

Revisions

  1. emanuele6 revised this gist Nov 21, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/sh --
    # \
    exec jq -Crf "$0" -- "$@"
    exec jq -Crf -- "$0" "$@"

    def children:
    objects |
  2. emanuele6 revised this gist Feb 4, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sxhkdrc
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    # Visualise the bspwm tree of the focused desktop in the floating window
    # Visualise the bspwm tree of the focused desktop in a floating window
    super + ctrl + t
    BSPSHOWTREE_FLOAT= bspshowtree
  3. emanuele6 revised this gist Aug 31, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/sh --
    # \
    exec jq -L '' -Crf "$0" -- "$@"
    exec jq -Crf "$0" -- "$@"

    def children:
    objects |
  4. emanuele6 revised this gist Aug 30, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/sh --
    # \
    exec jq -Crf "$0" -- "$@"
    exec jq -L '' -Crf "$0" -- "$@"

    def children:
    objects |
  5. emanuele6 revised this gist Aug 30, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions bsptreeupdatedot
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,14 @@

    case $# in
    0)
    : "${BSPTREEUPDATEPNG_OUTFILE:=/tmp/bsptree_$$.dot}"
    : "${BSPTREEUPDATEDOT_OUTFILE:=/tmp/bsptree_$$.dot}"
    ;;
    1)
    if [ -z "$1" ]; then
    printf 'Invalid empty argument.\n' >&2
    exit 2
    fi
    BSPTREEUPDATEPNG_OUTFILE=$1
    BSPTREEUPDATEDOT_OUTFILE=$1
    ;;
    *)
    printf 'Too many arguments.\n' >&2
  6. emanuele6 revised this gist Aug 30, 2022. 1 changed file with 11 additions and 4 deletions.
    15 changes: 11 additions & 4 deletions bsptreeupdatedot
    Original file line number Diff line number Diff line change
    @@ -2,17 +2,24 @@

    case $# in
    0)
    printf 'No arguments given.\n' >&2
    exit 2
    : "${BSPTREEUPDATEPNG_OUTFILE:=/tmp/bsptree_$$.dot}"
    ;;
    1)
    if [ -z "$1" ]; then
    printf 'Invalid empty argument.\n' >&2
    exit 2
    fi
    BSPTREEUPDATEPNG_OUTFILE=$1
    ;;
    [!1])
    *)
    printf 'Too many arguments.\n' >&2
    exit 2
    esac

    while
    tree=$(bspc query -T -d) &&
    printf '%s\n' "$tree" | bspdeskjson2dot > "$1" &&
    printf '%s\n' "$tree" |
    bspdeskjson2dot > "$BSPTREEUPDATEDOT_OUTFILE" &&
    bspc subscribe -c 1 desktop node > /dev/null
    do
    :
  7. emanuele6 revised this gist Aug 30, 2022. 2 changed files with 23 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion bspshowtree
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,6 @@ awk '
    NR == 1 && "BSPSHOWTREE_FLOAT" in ENVIRON {
    system("bspc rule -a \\* -o state=floating")
    }
    { print | "bspdeskjson2dot | dot -Tx11" }
    { print | "bspdeskjson2dot | dot -Txlib" }
    END { exit NR == 0 }
    '
    22 changes: 22 additions & 0 deletions bsptreeupdatedot
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/bin/sh --

    case $# in
    0)
    printf 'No arguments given.\n' >&2
    exit 2
    ;;
    [!1])
    printf 'Too many arguments.\n' >&2
    exit 2
    esac

    while
    tree=$(bspc query -T -d) &&
    printf '%s\n' "$tree" | bspdeskjson2dot > "$1" &&
    bspc subscribe -c 1 desktop node > /dev/null
    do
    :
    done

    # Now, you can open the output file with `dot -Txlib' and see the tree
    # update live! :D
  8. emanuele6 revised this gist Aug 29, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,7 @@ def node:
    end
    ):\(.splitRatio)"
    ),
    "\(.id)",
    .id,
    (
    select(isNonVacantLeaf).rectangle |
    objects |
  9. emanuele6 revised this gist Aug 29, 2022. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,7 @@ def node:
    "blue" # receptacle
    end
    )]",
    "[label=\"\(
    "[label=<\(
    [
    pathString,
    (
    @@ -51,7 +51,7 @@ def node:
    end
    ):\(.splitRatio)"
    ),
    .id,
    "\(.id)",
    (
    select(isNonVacantLeaf).rectangle |
    objects |
    @@ -60,13 +60,12 @@ def node:
    (
    .client |
    objects |
    "\(.className):\(.instanceName)"
    @json "\(.className):\(.instanceName)"
    ) |
    tostring |
    gsub("[\\\\\"]"; "\\" + .)
    @html
    ] |
    join("\\n")
    )\"]",
    join("<BR/>")
    )>]",
    "-> \(children.id | values)"
    );";

  10. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -73,7 +73,7 @@ def node:
    "digraph BSPTree {",
    (
    objects.root |
    objects |
    select(type == "object" and (.path | type | IN("string", "null"))) |
    recurse(children) |
    node
    ),
  11. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,6 @@ def pathString:
    def node:
    "\t\(.id) \(
    "[color=\(
    . as $node |
    if isInnerNode then
    numberOfBranchesWithNonVacantLeaves |
    if . == 0 then
  12. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,7 @@ def isInnerNode:
    def isNonVacantLeaf:
    .vacant or isInnerNode | not;
    def numberOfBranchesWithNonVacantLeaves:
    [ children ] |
    map(select(any(recurse(children); isNonVacantLeaf))) |
    [ children | select(any(recurse(children); isNonVacantLeaf)) ] |
    length;
    def pathString:
    "@\(.path // "/")";
  13. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 9 additions and 7 deletions.
    16 changes: 9 additions & 7 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -43,14 +43,16 @@ def node:
    "[label=\"\(
    [
    pathString,
    "\(
    (
    select(numberOfBranchesWithNonVacantLeaves == 2) |
    if .splitType == "vertical" then
    "V"
    else
    "H"
    end
    ):\(.splitRatio)",
    "\(
    if .splitType == "vertical" then
    "V"
    else
    "H"
    end
    ):\(.splitRatio)"
    ),
    .id,
    (
    select(isNonVacantLeaf).rectangle |
  14. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 7 additions and 9 deletions.
    16 changes: 7 additions & 9 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -43,16 +43,14 @@ def node:
    "[label=\"\(
    [
    pathString,
    (
    "\(
    select(numberOfBranchesWithNonVacantLeaves == 2) |
    "\(
    if .splitType == "vertical" then
    "V"
    else
    "H"
    end
    ):\(.splitRatio)"
    ),
    if .splitType == "vertical" then
    "V"
    else
    "H"
    end
    ):\(.splitRatio)",
    .id,
    (
    select(isNonVacantLeaf).rectangle |
  15. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -26,18 +26,18 @@ def node:
    if isInnerNode then
    numberOfBranchesWithNonVacantLeaves |
    if . == 0 then
    "gray" # fully vacant inner node
    "gray" # fully vacant inner node
    elif . == 1 then
    "yellow" # non-splitting inner node
    "yellow" # non-splitting inner node
    else
    empty # splitting inner node
    empty # splitting inner node
    end
    elif .vacant then
    "red" # vacant window
    "red" # vacant window
    elif .client != null then
    "green" # non-vacant window
    "green" # non-vacant window
    else
    "blue" # receptacle
    "blue" # receptacle
    end
    )]",
    "[label=\"\(
  16. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -32,14 +32,12 @@ def node:
    else
    empty # splitting inner node
    end
    elif isNonVacantLeaf then
    if .client != null then
    "green" # non-vacant window
    else
    "blue" # receptacle
    end
    else
    elif .vacant then
    "red" # vacant window
    elif .client != null then
    "green" # non-vacant window
    else
    "blue" # receptacle
    end
    )]",
    "[label=\"\(
  17. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 15 additions and 17 deletions.
    32 changes: 15 additions & 17 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -12,43 +12,41 @@ def isInnerNode:
    any(children; true);
    def isNonVacantLeaf:
    .vacant or isInnerNode | not;
    def numberOfBranchesWithNonVacantLeaves:
    [ children ] |
    map(select(any(recurse(children); isNonVacantLeaf))) |
    length;
    def pathString:
    "@\(.path // "/")";

    def node:
    "\t\(.id) \(
    "[color=\(
    . as $node |
    [ limit(2; recurse(children) | select(isNonVacantLeaf)) ] |
    length |
    if . == 0 then
    if $node.client != null then
    "red" # vacant window
    if isInnerNode then
    numberOfBranchesWithNonVacantLeaves |
    if . == 0 then
    "gray" # fully vacant inner node
    elif . == 1 then
    "yellow" # non-splitting inner node
    else
    "grey" # fully vacant inner node
    empty # splitting inner node
    end
    elif . == 1 then
    $node |
    elif isNonVacantLeaf then
    if .client != null then
    "green" # window
    elif isInnerNode then
    "yellow" # inner node with single non-vacant
    "green" # non-vacant window
    else
    "blue" # receptacle
    end
    else
    empty # normal inner node
    "red" # vacant window
    end
    )]",
    "[label=\"\(
    [
    pathString,
    (
    select(
    [ children ] |
    length >= 2 and
    all(any(recurse(children); isNonVacantLeaf))
    ) |
    select(numberOfBranchesWithNonVacantLeaves == 2) |
    "\(
    if .splitType == "vertical" then
    "V"
  18. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ def node:
    (
    select(
    [ children ] |
    length != 0 and
    length >= 2 and
    all(any(recurse(children); isNonVacantLeaf))
    ) |
    "\(
  19. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ def isInnerNode:
    def isNonVacantLeaf:
    .vacant or isInnerNode | not;
    def pathString:
    "@" + (.path // "/");
    "@\(.path // "/")";

    def node:
    "\t\(.id) \(
  20. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ def children:
    def isInnerNode:
    any(children; true);
    def isNonVacantLeaf:
    .vacant or isInnerNode | not;
    .vacant or isInnerNode | not;
    def pathString:
    "@" + (.path // "/");

  21. emanuele6 revised this gist Aug 28, 2022. 1 changed file with 8 additions and 5 deletions.
    13 changes: 8 additions & 5 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,10 @@ def children:
    (.firstChild | objects | .path = $p + "/1"),
    (.secondChild | objects | .path = $p + "/2") |
    select(has("id"));
    def isInnerNode:
    any(children; true);
    def isNonVacantLeaf:
    (.vacant | not) and isempty(children);
    .vacant or isInnerNode | not;
    def pathString:
    "@" + (.path // "/");

    @@ -26,12 +28,13 @@ def node:
    "grey" # fully vacant inner node
    end
    elif . == 1 then
    if $node.client != null then
    $node |
    if .client != null then
    "green" # window
    elif isempty($node | children) then
    "blue" # receptacle
    else
    elif isInnerNode then
    "yellow" # inner node with single non-vacant
    else
    "blue" # receptacle
    end
    else
    empty # normal inner node
  22. emanuele6 revised this gist Aug 27, 2022. 1 changed file with 10 additions and 15 deletions.
    25 changes: 10 additions & 15 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,15 @@
    #!/bin/sh --
    # \
    exec jq -rf "$0" -- "$@"
    exec jq -Crf "$0" -- "$@"

    def children:
    objects |
    .path as $p |
    (.firstChild | objects | .path = $p + "/1"),
    (.secondChild | objects | .path = $p + "/2") |
    select(has("id"));
    def isInnerNode:
    .firstChild != null;
    def isNonVacantLeaf:
    isInnerNode or .vacant | not;
    (.vacant | not) and isempty(children);
    def pathString:
    "@" + (.path // "/");

    @@ -58,17 +56,14 @@ def node:
    ),
    .id,
    (
    select(isNonVacantLeaf) |
    (
    .rectangle |
    objects |
    "\(.width)x\(.height)+\(.x)+\(.y)"
    ),
    (
    .client |
    objects |
    "\(.className):\(.instanceName)"
    )
    select(isNonVacantLeaf).rectangle |
    objects |
    "\(.width)x\(.height)+\(.x)+\(.y)"
    ),
    (
    .client |
    objects |
    "\(.className):\(.instanceName)"
    ) |
    tostring |
    gsub("[\\\\\"]"; "\\" + .)
  23. emanuele6 revised this gist Aug 27, 2022. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/sh --
    # \
    exec jq -Crf "$0" -- "$@"
    exec jq -rf "$0" -- "$@"

    def children:
    objects |
    @@ -58,14 +58,15 @@ def node:
    ),
    .id,
    (
    select(.client != null) |
    select(isNonVacantLeaf) |
    (
    select(.vacant | not) |
    .client.tiledRectangle |
    .rectangle |
    objects |
    "\(.width)x\(.height)+\(.x)+\(.y)"
    ),
    (
    .client |
    objects |
    "\(.className):\(.instanceName)"
    )
    ) |
  24. emanuele6 revised this gist Aug 27, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sxhkdrc
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    # Visualise the bspwm tree of the focused desktop in the floating window
    super + ctrl + t
    BSPSHOWTREE_FLOAT= bspshowtree
    BSPSHOWTREE_FLOAT= bspshowtree
  25. emanuele6 revised this gist Aug 27, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bsptreeupdatepng
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ case $# in
    esac

    while
    tree=$(bspc query -T -d ) &&
    tree=$(bspc query -T -d) &&
    printf '%s\n' "$tree" |
    bspdeskjson2dot |
    dot -Tpng -o "$BSPTREEUPDATEPNG_OUTFILE" &&
  26. emanuele6 revised this gist Aug 27, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bsptreeupdatepng
    Original file line number Diff line number Diff line change
    @@ -26,5 +26,5 @@ do
    :
    done

    # Now, you can open the outputfile in an image viewer and see the tree
    # Now, you can open the output file in an image viewer and see the tree
    # update live! :D
  27. emanuele6 revised this gist Aug 27, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bsptreeupdatepng
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ while
    printf '%s\n' "$tree" |
    bspdeskjson2dot |
    dot -Tpng -o "$BSPTREEUPDATEPNG_OUTFILE" &&
    bspc subscribe desktop node -c 1 > /dev/null
    bspc subscribe -c 1 desktop node > /dev/null
    do
    :
    done
  28. emanuele6 revised this gist Aug 27, 2022. 2 changed files with 10 additions and 12 deletions.
    2 changes: 1 addition & 1 deletion bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/sh --
    # \
    exec jq -C -rf "$0" -- "$@"
    exec jq -Crf "$0" -- "$@"

    def children:
    objects |
    20 changes: 9 additions & 11 deletions bsptreeupdatepng
    Original file line number Diff line number Diff line change
    @@ -16,17 +16,15 @@ case $# in
    exit 2
    esac

    bspc subscribe node |
    while IFS=' ' read -r event m desk r; do
    [ "$event" = node_stack ] && continue # incompatible format
    bspc query -T -d "$desk.focused" |
    awk '
    { print | "bspdeskjson2dot | dot -Tpng" }
    ' |
    BSPTREEUPDATEPNG_OUTFILE=$BSPTREEUPDATEPNG_OUTFILE awk '
    { print > ENVIRON["BSPUPDATEPNGTREE_OUTFILE"] }
    '
    while
    tree=$(bspc query -T -d ) &&
    printf '%s\n' "$tree" |
    bspdeskjson2dot |
    dot -Tpng -o "$BSPTREEUPDATEPNG_OUTFILE" &&
    bspc subscribe desktop node -c 1 > /dev/null
    do
    :
    done

    # Now, you can open the outputfile in an image viewer and see the tree
    # update live! :D
    # update live! :D
  29. emanuele6 revised this gist Aug 27, 2022. 2 changed files with 35 additions and 0 deletions.
    32 changes: 32 additions & 0 deletions bsptreeupdatepng
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/bin/sh --

    case $# in
    0)
    : "${BSPTREEUPDATEPNG_OUTFILE:=/tmp/bsptree_$$.png}"
    ;;
    1)
    if [ -z "$1" ]; then
    printf 'Invalid empty argument.\n' >&2
    exit 2
    fi
    BSPTREEUPDATEPNG_OUTFILE=$1
    ;;
    *)
    printf 'Too many arguments.\n' >&2
    exit 2
    esac

    bspc subscribe node |
    while IFS=' ' read -r event m desk r; do
    [ "$event" = node_stack ] && continue # incompatible format
    bspc query -T -d "$desk.focused" |
    awk '
    { print | "bspdeskjson2dot | dot -Tpng" }
    ' |
    BSPTREEUPDATEPNG_OUTFILE=$BSPTREEUPDATEPNG_OUTFILE awk '
    { print > ENVIRON["BSPUPDATEPNGTREE_OUTFILE"] }
    '
    done

    # Now, you can open the outputfile in an image viewer and see the tree
    # update live! :D
    3 changes: 3 additions & 0 deletions sxhkdrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    # Visualise the bspwm tree of the focused desktop in the floating window
    super + ctrl + t
    BSPSHOWTREE_FLOAT= bspshowtree
  30. emanuele6 revised this gist Aug 27, 2022. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions bspdeskjson2dot
    Original file line number Diff line number Diff line change
    @@ -43,14 +43,10 @@ def node:
    [
    pathString,
    (
    (.firstChild or .client | not) as $x |
    select(
    select($x) |= debug |
    [ children ] |
    select($x) |= debug |
    length != 0 and
    (select($x) |= debug |
    all(any(recurse(children); isNonVacantLeaf)))
    all(any(recurse(children); isNonVacantLeaf))
    ) |
    "\(
    if .splitType == "vertical" then