0

If I run echo -en "aap\0icon\x1f${icon}\n" like:

#!/usr/bin/env bash

array="Alacritty vscodium firefox-esr io.github.cboxdoerfer.FSearch folder"

for icon in ${array}; do
    echo -en "aap\0icon\x1f${icon}\n"
    echo -en "aap\0icon\x1f${icon}\n" | head -1 | od -c
done

The output of the command is:

$ ./test
aapiconAlacritty
0000000   a   a   p  \0   i   c   o   n 037   A   l   a   c   r   i   t
0000020   t   y  \n
0000023
aapiconvscodium
0000000   a   a   p  \0   i   c   o   n 037   v   s   c   o   d   i   u
0000020   m  \n
0000022
aapiconfirefox-esr
0000000   a   a   p  \0   i   c   o   n 037   f   i   r   e   f   o   x
0000020   -   e   s   r  \n
0000025
aapiconio.github.cboxdoerfer.FSearch
0000000   a   a   p  \0   i   c   o   n 037   i   o   .   g   i   t   h
0000020   u   b   .   c   b   o   x   d   o   e   r   f   e   r   .   F
0000040   S   e   a   r   c   h  \n
0000047
aapiconfolder
0000000   a   a   p  \0   i   c   o   n 037   f   o   l   d   e   r  \n
0000020

However, If I run echo -en "aap\0icon\x1f${icon}\n" like:

#!/usr/bin/env bash

json=$(dbus-send --print-reply=literal --session --dest=org.gnome.Shell /org/gnome/Shell/Extensions/GnomeUtilsWorkspaces org.gnome.Shell.Extensions.GnomeUtilsWorkspaces.GetWorkspaces)

workspace_names=$(echo $json | jq -c -r .workspace_names[])

for w in ${workspace_names}; do

all_normal_windows_of_nth_workspaces=$(echo $json | jq ".all_normal_windows_of_workspaces .$w" | jq -c '.[]' )

    for item in ${all_normal_windows_of_nth_workspaces}; do
        icon=$(dbus-send --print-reply=literal --session --dest=org.gnome.Shell /org/gnome/Shell/Extensions/GnomeUtilsWindows org.gnome.Shell.Extensions.GnomeUtilsWindows.GetIconFromWinID uint32:$item)
        echo -en "aap\0icon\x1f${icon}\n"
        echo -en "aap\0icon\x1f${icon}\n" | head -1 | od -c
    done
done

The output is like:

./test
aapicon   firefox-esr
0000000   a   a   p  \0   i   c   o   n 037               f   i   r   e
0000020   f   o   x   -   e   s   r  \n
0000030
aapicon   Alacritty
0000000   a   a   p  \0   i   c   o   n 037               A   l   a   c
0000020   r   i   t   t   y  \n
0000026
aapicon   firefox-esr
0000000   a   a   p  \0   i   c   o   n 037               f   i   r   e
0000020   f   o   x   -   e   s   r  \n
0000030
aapicon   firefox-esr
0000000   a   a   p  \0   i   c   o   n 037               f   i   r   e
0000020   f   o   x   -   e   s   r  \n
0000030
aapicon   vscodium
0000000   a   a   p  \0   i   c   o   n 037               v   s   c   o
0000020   d   i   u   m  \n
0000025

As a result I am unable to render the icons in rofi using ./test | rofi -dmenu or, rofi -show gn -modi "gn:./test".

One sample for rofi script can be found in https://github.com/davatorium/rofi/blob/next/Examples/test_script_mode.sh

Documentation also says that we need to render icon using echo -en "aap\0icon\x1ffolder\n".

I do not understand control characters well. Why does it work differently here. How can I have same output as first example, in the second code?

P.S. This is not necessary but if you want to know what is this script and how does it work then please check https://github.com/davatorium/rofi/discussions/1871

Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87
  • @jhnc do you mean the first script (`for icon in ${array};`) does not give any output? – Ahmad Ismail Jul 22 '23 at 13:22
  • 1
    please update the question with the expected output; in the 2nd set of code it's not clear (to me) that `icon` contains the same exact data as in the 1st set of code's array – markp-fuso Jul 22 '23 at 13:27
  • 1
    when I run the 1st set of code (in cygwin/bash, in Ubuntu/bash) the first line of output is `aapiconAlacritty`; when I pipe that through `| head -1 | od -c` I get `a a p \0 i c o n 037 A l a c r i t t y \n`; not sure how you manage to get just `Alacritty` in your output (setting aside the fact that the 1st set of output has 4 lines of output instead of the expected 5, one item is duplciated, the ordering is not the same as in the array) – markp-fuso Jul 22 '23 at 13:30
  • for second script add `declare -p icon` after `icon=$(...)` line and see what is shown. and you can do `echo -en "..." | od -c` to check that – jhnc Jul 22 '23 at 13:32
  • I have updated the question with `head -1 | od -c` output. – Ahmad Ismail Jul 22 '23 at 13:41
  • 1
    with the latest update it looks like the 2nd set of code is deailing with some leading white space in the value assigned to the `icon` variable; so, just remove the leading white space? eg, `${icon##+( )}` or `${icon##+([[:space:]])}` ... in this case the `+` could be replaced with `*` – markp-fuso Jul 22 '23 at 14:00
  • @markp-fuso yes sir i think you have hit the bull's eye here. Let me check the code. Too many tabs open. Getting back to you. – Ahmad Ismail Jul 22 '23 at 14:13
  • @markp-fuso your diagnosys is correct. Solved the problem with ` | xargs` like `icon=$(dbus-send --print-reply=literal --session --dest=org.gnome.Shell /org/gnome/Shell/Extensions/GnomeUtilsWindows org.gnome.Shell.Extensions.GnomeUtilsWindows.GetIconFromWinID uint32:$item | xargs) – Ahmad Ismail Jul 22 '23 at 14:21
  • 1
    Try this: `read -ra workspace_names < <(dbus-send --print-reply=literal --session --dest=org.gnome.Shell /org/gnome/Shell/Extensions/GnomeUtilsWorkspaces org.gnome.Shell.Extensions.GnomeUtilsWorkspaces.GetWorkspaces | jq -cr '.workspace_names[]' )`... Then `for w in "${workspace_names[@]}"; do` – F. Hauri - Give Up GitHub Jul 22 '23 at 14:27
  • @markp-fuso if you kindly give the answer in answer section, i can accept it. – Ahmad Ismail Jul 22 '23 at 14:48
  • 1
    @AhmadIsmail all I did was mention the leading whitespace; I didn't mention `xargs` so .... if you're using `xargs` (to strip leading/trailing spaces, to squeeze multi-spaces into a single space) then I'd suggest you go ahead and write up an answer detailing what you've done to address your issue – markp-fuso Jul 22 '23 at 15:18

0 Answers0