You are not logged in.

#1 2020-03-01 23:49:23

damo
....moderator....
Registered: 2015-08-20
Posts: 6,403

jgmenu - Some methods to display submenu items

Methods to display submenu items

All the examples here can be run with:

jgmenu --simple --csv-file=~/.config/jgmenu/mymenu.csv
  • From a menu csv file

    # mymenu.csv
    
    ^sep(Menu)
    First item,^checkout(first)
    Second item,^checkout(second)
    
    ^tag(first)
        submenu 1
        submenu 2,^checkout(sub2)
        
    ^tag(second)
        submenu 3,^checkout(sub3)
        submenu 4
    
    ^tag(sub2)
        item 1
        item 2
        item 3
    
    ^tag(sub2)
        item 1
        item 2
        item 3

                                sPpyus5m.jpg


                               

  • Sourcing files

    # mymenu.csv
    
    . ~/.config/jgmenu/mymenu-source

    This simple one-liner will source the menu from...

    # mymenu-source
    
    ^sep(Menu)
    First item,^checkout(first)
    Second item,^checkout(second)
    
    ^tag(first)
        submenu 1
        submenu 2,^checkout(sub1)
    
    ^tag(second)
        submenu 3,^checkout(sub2)
        submenu 4
    
    ^tag(sub1)
        item 1
        item 2
        item 3
    
    ^tag(sub2)
        item 1
        item 2
        item 3

    ...and produce the same result   sPpyus5m.jpg



    However, chaining source files together is problematic in this example, because the second source will appear below the last tag written by the first, and be a submenu of that instead. Try doing this:

    . ~/.config/jgmenu/mymenu-source
    . ~/.config/jgmenu/mymenu-source2
    # mymenu-source2
    
    ^sep()
    Third item,^checkout(third)
    Fourth item,^checkout(fourth)
    
    ^tag(third)
        submenu 1
        submenu 2,^checkout(sub3)
    
    ^tag(fourth)
        submenu 3,^checkout(sub4)
        submenu 4
    
    ^tag(sub3)
        item 1
        item 2
        item 3
    
    ^tag(sub4)
        item 1
        item 2
        item 3

                                1nOWLCfm.jpg
                               

                               

  • From a piped array

    A neat way of keeping a stock of menu items is to include them in an array in a pipemenu.
    (NB, beware using comma characters - see the next section)

    ^sep(Menu)
    Menu item1,^pipe(./.config/jgmenu/scripts/menu-pipe menu1)
    Menu item2,^pipe(./.config/jgmenu/scripts/menu-pipe menu2)
    #!/bin/bash
    ##
    ## menu-pipe
    
    item="$1"
    declare -A MENU_ARR
    
    MENU_ARR[menu1]='
    #^tag(menu)
        First,^checkout(first)
        Second,^checkout(second)
        Third,^checkout(third)
    
        ^tag(first)
            1.1
            1.2
            1.3
        ^tag(second)
            2.1
            2.2
            2.3
        ^tag(third)
            3.1
            3.2
            3.2
    '
    
    MENU_ARR[menu2]='
    #^tag(menu2)
        First,^checkout(first)
        Second,^checkout(second)
        Third,^checkout(third)
    
        ^tag(first)
            1.1
            1.2
            1.3
        ^tag(second)
            2.1
            2.2
            2.3
        ^tag(third)
            3.1
            3.2
            3.2
    '
    
    echo "${MENU_ARR[${item}]}"

                                Bee4798m.jpg
                               

                               

  • Displaying text

    • Sourced or piped arrays can be used to display text as a menu item - handy for remembering commandline args and script usage. NB: some characters may need escaping due to the pango markup used by jgmenu (see the next section).

      Example from jgmenu_run usage output:

      # mymenu.csv
      
      ^sep(Menu)
      Menu item1,^pipe(./.config/jgmenu/scripts/menu-pipe menu1)
      Menu item2,^pipe(./.config/jgmenu/scripts/menu-pipe menu2)
      jgmenu_run USAGE,^checkout(jgusage)
      
      ^tag(jgusage)
          init,^pipe(./.config/jgmenu/usage/cmd-usage init)
          greeneye,^pipe(./.config/jgmenu/usage/cmd-usage greeneye)
          obtheme,^pipe(./.config/jgmenu/usage/cmd-usage obtheme)
          themes,^pipe(./.config/jgmenu/usage/cmd-usage themes)
          pmenu,^pipe(./.config/jgmenu/usage/cmd-usage pmenu)
          config,^pipe(./.config/jgmenu/usage/cmd-usage config)
      #!/bin/bash
      ##
      # jgmenu_run scripts usage text
      
      item="$1"
      declare -A USG_ARR
      
      USG_ARR[init]='
      Usage: jgmenu_run init [<options>]
             jgmenu_run init [--config-file=<file>] --regression-check
             
      Create/amend/check config files
      
      Options include:
          -h|--help             Display this message
          -i|--interactive      Enter interactive mode
          --config-file=<file>  Specify config file
          --theme=<theme>       Create config file with a particular theme
          --list-themes         Display all available themes
          --regression-check    Only check for config options no longer valid
          --apply-obtheme       Apply current openbox theme to menu
          --apply-gtktheme      Apply gtk theme (optional package)
          --verbose             Be more verbose
      '
      
      USG_ARR[greeneye]='
      Usage: jgmenu_run greeneye [options]
      
      Output config file and widget lines for a menu with the following layout:
      
       +----------------+-----------------------+
       |                |  a - search box       |
       |                |-----------------------|
       |                |                       |
       | b - categories |                       |
       |                |  c - applications     |
       |                |                       |
       |                |                       |
       +----------------+-----------------------+
      
      Options:
          --widgets     print widget lines
          --config      print config lines
      
      Example:
          jgmenu_run greeneye --config  >$HOME/.config/jgmenu/jgmenurc
          jgmenu_run greeneye --widgets >$HOME/.config/jgmenu/prepend.csv
      '
      
      
      USG_ARR[obtheme]='
      Usage: jgmenu_run obtheme <jgmenu-config-filename>
      
      Imitate look of current openbox menu by parsing current openbox theme and
      setting variables in specified jgmenu config file.
      
      The theme name will be obtained from the following list (in order of precedence):
      
        * ~/.config/openbox/bl-rc.xml
        * ~/.config/openbox/rc.xml
        * /etc/xdg/openbox/rc.xml
        
      The above list can be overridden by setting environment variable JGMENU_RCXML.
      
      Openbox theme files will be searched for in:
      
        * ~/.themes/
        * /usr/share/themes/
      '
      
      USG_ARR[themes]='
      Usage: jgmenu_run themes <theme>_<mode>
      
      Output config files for themes
      
      <mode> is one of config, prepend and append
      '
      
      USG_ARR[pmenu]='
      Usage: jgmenu_run pmenu [-h] [--append-file FILE] [--prepend-file FILE] [--locale LOCALE]
      
      Options:
        -h, --help           show this help message and exit
        --append-file FILE   Path to menu file to append to the root menu
        --prepend-file FILE  Path to menu file to prepend to the root menu
        --locale LOCALE      Use a custom locale (e.g. "en_US.UTF-8"; available
                             locales can be shown by running "locale -a")
      '
      
      USG_ARR[config]='
      Usage: jgmenu_run config [options]
      
      Creates or amend config file
      
      Options:
          -a <file>      amend config file with missing items
          -c                   write default config file to stdout
          -k <key>       specify key (needed for -s)
          -s <file>      set key/value pair (add if does not exist)
          -v <value>     specify value (needed for -s)
          -h                   display this message
      '
      
      echo "${USG_ARR[${item}]}"

                                  bn6FkTZm.jpg
                                 



    • From a textfile

      Text can be loaded from a text file, but text lines need to be triple-quoted if they contain commas, because jgmenu uses ' , ' as a field-delimiter.
      The easiest way I've found to get around this is to triple-quote every line:

      awk '{ print "\"\"\""$0"\"\"\""}' input.txt > output.txt

      This also applies in fields in the csv file:

      foo,""“^pipe(find . -printf '%f,display %p,%p\n')”""

      Other Special Characters may also need to be dealt with. The description field is parsed as pango markup, so these 3 characters need escaping:

      • &    escape as &

      • <     escape as &lt;

      • >     escape as &gt;

      Text can be processed with:

      sed -i -e 's/&/\&amp;/g' -e 's/>/\&gt;/g' -e 's/</\&lt;/g' input.txt

      This could result in:

      # mymenu.csv
      
      ^sep(Menu)
      Menu item1,^pipe(./.config/jgmenu/scripts/menu-pipe menu1)
      Menu item2,^pipe(./.config/jgmenu/scripts/menu-pipe menu2)
      jgmenu puff,^pipe(cat ~/usage.txt)

                                  ZweB5ajm.jpg

                                 


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