You are not logged in.

#1 2019-10-19 21:18:33

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,992
Website

Screenfetch and neofetch as pipe menus

Two scripts to generate a primitive openbox pipe menu to give user some sysinfo using screen/neofetch stdout. At the end there can be only one.

pipeScreenfetch, pipeNeofetch.

scrot17819.th.png

Neofetch version is slightly faster and gives slightly better info.

License: YYCPL0, This scripts are published under ‘Yes You Can 0’ permissive license.

Debug:
- There is some unexpected string movement issues when underline '_' char is in the game, current workaround is to replace it with a dot ' . ', so  x86_64 becomes x86.64 for example. I'am assuming this is not xml related, but could be some sort of openbox feature (more research needed).

This all

<item label="t&#x5F;e_s_t"></item>
<item label="t&#t_e_s_t"></item>
<item label="'t_e_s_t'"></item>

fails.

edit: Found the problem, this

<item label="t__e__s__t"></item>

works and it's related to http://openbox.org/wiki/Help:Menus

openbox wrote:

Specifying menu shortcuts
The first character in the label is used for a keyboard shortcut to directly use the menu item. This can be overridden by using the "_" character in front of the character, you wish to use for the shortcut. For example, "The _shortcut" would make "s" the shortcut key for this menu item. If you want a "_" character to appear in the string, you can use two underscores together, such as in "An __ underscore".

and fixed by replacing all _ with __.

Last edited by brontosaurusrex (2019-10-22 19:57:06)

Offline

#2 2019-10-19 21:48:14

damo
....moderator....
Registered: 2015-08-20
Posts: 5,633

Re: Screenfetch and neofetch as pipe menus

After some weird perl regex to get rid of unwanted ascii escape codes, it was a relief to discover the --stdout parameter!

There is a problem with the "Terminal" output though sad  It works in the terminal, when looking for the parent process, but finds "Openbox" when run in a script.

neofetch-menu.th.jpg

neofetch is very configurable.

#!/bin/bash
# pipeNeofetch by @brontosaurusrex, modified by @damo

# call from .config/openbox/menu.xml like
#        <menu id="neofetch" label="neofetch" execute="pipeNeofetch" />

# header
header () {
cat << HEAD
<openbox_pipe_menu>
HEAD
}

# footer
footer () {
cat << FOOT
</openbox_pipe_menu>
FOOT
}

# checks critical
command -v neofetch >/dev/null 2>&1 || { header; echo "<item label=\"Horrible error, I need neofetch installed.\" />"; footer ; exit 1; }

header
# items loop over lines, and remove last empty line
neofetch --stdout --disable title underline | while read -r line 
do
    line=${line//_/__}   # Replace all underscores with double-underscores, so keyboard accelerators aren't displayed
    [[ "$line" == "" ]] && continue || echo "<item label=\"$line\" />"
done
footer

Last edited by damo (2019-10-21 00:17:28)


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2019-10-19 22:07:41

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,992
Website

Re: Screenfetch and neofetch as pipe menus

It works in the terminal, when looking for the parent process, but finds "Openbox" when run in a script.

Seems correct (but useless in this context) to me, perhaps just disable 'term' var?

Last edited by brontosaurusrex (2019-10-20 08:04:10)

Offline

#4 2019-10-20 15:29:37

vasa1
Member
Registered: 2015-09-29
Posts: 178

Re: Screenfetch and neofetch as pipe menus

Butting in here to suggest looking at inxi as well.


Using the Openbox (3.5.2) session of Lubuntu 14.04 LTS but very interested in BL :)

Offline

#5 2019-10-20 23:57:39

damo
....moderator....
Registered: 2015-08-20
Posts: 5,633

Re: Screenfetch and neofetch as pipe menus

An underscore in an OB menu defines a keyboard accelerator.

I've used parameter substitution to add another underscore:

line=${line//_/__}

So "x8664" becomes "x86_64"

(I've edited the script above to include it)

Last edited by damo (2019-10-21 00:18:12)


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#6 2019-10-21 04:47:54

Dobbie03
Resident Metalhead
From: New Zealand
Registered: 2015-09-29
Posts: 2,502
Website

Re: Screenfetch and neofetch as pipe menus

This is some cool stuff Bronto.  I might have to add this to the AL openbox session, with your blessing of course.


One of the ArchLabs dudes
Obssesive Metalhead and practiced beer drinker
\m/

Offline

#7 2019-10-21 06:03:16

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,992
Website

Re: Screenfetch and neofetch as pipe menus

@Dobbie, sure, feel free. I'am never sure if short scripts like this need any licensing, I guess they could/should inherit whatever screen/neofetch are under? So that would be gpl for screen and mit for neofetch?

@vasa1; Do you see inxi version as single block of data or multiple submenus?

Last edited by brontosaurusrex (2019-10-21 08:29:19)

Offline

#8 2019-10-21 13:54:30

clusterF
Member
Registered: 2019-05-07
Posts: 520

Re: Screenfetch and neofetch as pipe menus

Interesting idea, i wonder what else you could pipe similar to this. Possibly man pages using more or less maybe?

Last edited by clusterF (2019-10-21 13:55:09)


"Ad Astra Incrementis"

git: clusterF

Offline

#9 2019-10-21 14:31:42

clusterF
Member
Registered: 2019-05-07
Posts: 520

Re: Screenfetch and neofetch as pipe menus

for inxi and piping through awk, i was able to get a nice line similar to neofetch.

inxi | awk 'NR==1 {print $1,$4,$5,$6} NR==1 {print $14,$15} NR==1 {print $17,$18,$19} NR==2 {print $1,$2,$3} NR==2 {print $5,$6,$7} NR==2 {print $10,$11} NR==2 {print $12,$13,$14} NR==2 {print $15,$16}'

my output

CPU: Intel Core i7
Kernel: 4.19.0-6-amd64
Up: 3h 02m
Mem: 1451.0/3876.9 MiB
Storage: 698.64 GiB
Procs: 165
Shell: bash 5.0.3
inxi: 3.0.32

neofetch is still king though, inxi better suited to the terminal.

Last edited by clusterF (2019-10-21 14:33:58)


"Ad Astra Incrementis"

git: clusterF

Offline

#10 2019-10-21 14:54:55

damo
....moderator....
Registered: 2015-08-20
Posts: 5,633

Re: Screenfetch and neofetch as pipe menus

brontosaurusrex wrote:

@Dobbie, sure, feel free. I'am never sure if short scripts like this need any licensing, I guess they could/should inherit whatever screen/neofetch are under? So that would be gpl for screen and mit for neofetch?
...

The scripts don't use any code from screenfetch/neofetch - it is all originally yours, so licence it how you like. Look at the header comments in the BL scripts for what we use: they include

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#11 2019-10-21 20:37:00

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,992
Website

Re: Screenfetch and neofetch as pipe menus

@clusterF;  That's some expert awk stuff.
@damo, seems wordy for such short scripts.

A try at pipeInxi. Quite slow and ugly, but quite configurable, add or remove options to array. Would need some serious prettify pass or two ...

scrot06332.th.png

Any openbox menu tricks to make clicking an item paste it's label text into clipboard?

Last edited by brontosaurusrex (2019-10-22 08:57:45)

Offline

#12 2019-10-22 01:40:16

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,383
Website

Re: Screenfetch and neofetch as pipe menus

^BTW just FYI BL won't be using the Openbox menu in Lithium.
You might consider adapting to jgmenu? (The syntax is quite simple.)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#13 2019-10-22 02:21:57

damo
....moderator....
Registered: 2015-08-20
Posts: 5,633

Re: Screenfetch and neofetch as pipe menus

johnraff wrote:

^BTW just FYI BL won't be using the Openbox menu in Lithium.
You might consider adapting to jgmenu? (The syntax is quite simple.)

I periodically try to use jgmenu, but keep returning to my trusty traditional one!  monkey


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#14 2019-10-22 17:59:46

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,992
Website

Re: Screenfetch and neofetch as pipe menus

Jgmenu

1. This in prepend.csv,  using the same xml generating script is working (the underscore problem resurfaces now with literal two __)

Neofetch,^pipe(jgmenu_run ob --cmd="pipeNeofetch" --tag="neofetch")

jgmenu.th.png

2. This from term is also working

neofetch --off --stdout --disable title term model | awk 'NF' | jgmenu --simple --icon-size=0

a. Assuming that future is xmlsless, how would I plug this 2nd example into jgmenu 'simple' pipe menu ?
b. Assuming we want full backward compatibility with openbox menu, then 1. ? (with double underscore fix wink)
edit: pipeNeofetch changed so that underscores are now dots, which should make both ob and jgmenu happy.
c. Should one base any logic on parent? Or should we call this unwanted 'jgmenu_run ob' behaviour?

parent="$(ps $PPID | tail -n 1 | awk "{print \$5}")" # this could be openbox or jgmenu or ...

Last edited by brontosaurusrex (2019-10-22 19:58:34)

Offline

#15 2019-10-28 17:13:15

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,992
Website

Re: Screenfetch and neofetch as pipe menus

And a neofetch geany version, as template;

cd ~/.config/geany/templates/files
echo "{command:neofetch --off --stdout --disable title term model --memory_percent on}" > neofetch

And next time in geany there will be a new 'New with template' option. Because we can.

Offline

#16 2019-10-29 04:02:48

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,383
Website

Re: Screenfetch and neofetch as pipe menus

brontosaurusrex wrote:

Assuming that future is xmlsless, how would I plug this 2nd example into jgmenu 'simple' pipe menu ?

Of course malm is the guy, but till he shows up: make a script that outputs csv, just like any jgmenu, then call it in the parent menu with, eg:

Take Screenshot,^pipe(bl-scrot-pipemenu)

bl-scrot-pipemenu is in /usr/bin/

Assuming we want full backward compatibility with openbox menu...

I think that's entirely up to you. For BL Lithium csv only is enough. The xml parsing is an extra process that might slow down the menu display (not much in practice though). We are still shipping some xml pipemenus because they work, so why take the time to rewrite them, but csv is easier IMO and pipe menus I write in the future will probably be native jgmenu.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#17 2019-10-29 10:40:45

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,992
Website

Re: Screenfetch and neofetch as pipe menus

@john, Thanks. Not completely unrelated, freedesktop seems to be specific about using xml for menus, but I can't dig an info on why.
https://specifications.freedesktop.org/ … c-1.0.html

Offline

#18 2019-10-29 12:02:11

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,383
Website

Re: Screenfetch and neofetch as pipe menus

^Those freedesktop xml "menu" files are descriptions of how a menu-generating app (like jgmenu...) should go about generating a dynamic menu from the .desktop files in /usr/share/applications. They don't directly define menus the way a jgmenu csv file or openbox menu.xml does.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#19 2019-10-29 13:09:17

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,992
Website

Re: Screenfetch and neofetch as pipe menus

Right.

Offline

#20 2020-02-22 21:42:24

damo
....moderator....
Registered: 2015-08-20
Posts: 5,633

Re: Screenfetch and neofetch as pipe menus

A combined script that can be used by either Openbox or jgmenu, and with a choice of neofetch or screenfetch. Use it like

In menu.xml:
<menu id="neofetch" label="neofetch" execute="termfetch-pipemenu --ob --neo" />

By jgmenu:
termfetch-pipemenu --jg --screen | jgmenu --simple

In prepend.csv:
Neofetch,^pipe(termfetch-pipemenu --jg --neo)
Screenfetch,^pipe(jgmenu_run ob --cmd="termfetch-pipemenu --ob --screen")
#!/bin/bash
#
# termfetch-pipemenu:
# A combination of scripts from @brontosaurusrex (pipeNeofetch and pipeScreenfetch)
#
# by @damo Feb2020
#
########################################################################

USAGE='
USAGE:    termfetch-pipemenu --[ob|jg] --[neo|screen] <[-h|--help]>
-----

    -h|--help   This USAGE

    --ob        Output xml for use in an Openbox menu. For example:
    
                <menu id="neofetch" label="neofetch" execute="termfetch-pipemenu --ob --neo" />

    --jg        Output for jgmenu. For example:

                Run separately: "termfetch-pipemenu --jg --screen | jgmenu --simple"

                Run in menu: "Neofetch,^pipe(termfetch-pipemenu --jg --neo)"
                          or "Screenfetch,^pipe(jgmenu_run ob --cmd="termfetch-pipemenu --ob --screen"

    --screen    Use screenfetch output for display.

    --neo       Use neofetch output for display.
'

function getargs(){
    while [[ ${#} != 0 ]]; do
        case "$1" in
            --jg        )   menu="jg_menu"
                            ;;
            --ob        )   menu="ob_menu"
                            ;;
            --neo       )   if type neofetch >/dev/null;then
                                term_cmd="neo"
                            else
                                echo -e "\nneofetch needs to be installed!\n"
                                exit 1
                            fi
                            ;;
            --screen    )   if type screenfetch >/dev/null;then
                                term_cmd="scrnfetch"
                            else
                                echo -e "\nscreenfetch needs to be installed!\n"
                                exit 1
                            fi
                            ;;
            -h|--help   )   echo "${USAGE}"
                            exit 0
                            ;;
            *           )   message="\nFailed to parse options...\n"
                                echo -e "${message}" >&2
                                echo "${USAGE}" 
                                exit 1
                                ;;
        esac
        shift
    done || { echo "Failed to parse options" >&2 && exit 1; }
}

function write_ob(){
    echo "<openbox_pipe_menu>"
    if [[ ${term_cmd} = "neo" ]];then
        neofetch --stdout --disable title underline model term | \
        while read -r line;do   # items loop over lines
            line=${line//_/__}  # Replace all underscores with double-underscores, so keyboard accelerator aren't displayed
            [[ "$line" == "" ]] && continue ||  echo "<item label=\"$line\" />" 
        done
    elif [[ ${term_cmd} = "scrnfetch" ]];then
        screenfetch -nN | while read -r line;do 
                            echo "<item label=\"$line\" />"
                            done
    fi
    echo "</openbox_pipe_menu>"
}

function write_jg(){
    if [[ ${term_cmd} = "neo" ]];then
        cmd="neofetch --stdout --disable title underline model term"
    else
        cmd="screenfetch -nN"
    fi
    while read -r line;do
        output="${output}${line}\n"
    done <<< $(${cmd})

    echo -e "${output}"
}

function write_menu(){
    if [[ ${menu} = "ob_menu" ]];then
        write_ob
    elif [[ ${menu} = "jg_menu" ]];then
        write_jg
    fi
}

[[ ${#} == 0 ]] && echo "No script args" && exit 1
declare output
getargs "${@}"
write_menu

Last edited by damo (2020-02-23 00:33:20)


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

Board footer

Powered by FluxBB