You are not logged in.

#1 2018-11-25 11:49:07

damo
....moderator....
Registered: 2015-08-20
Posts: 4,378

Openbox Menu to display application Keyboard Shortcuts

Pipemenu to display application keyboard shortcuts

This uses a tint2 button to show a menu containing a variety of application keybinds, as well as the main Openbox keyboard pipemenu.

Some of them require a textfile for the shortcuts, because I haven't found a way of extracting them from the application configs hmm

keybinds.th.jpg
_________________________________________________

menu.xml

Add this section. Comment out any you don't want, or add your own:

    <menu id="keybinds-menu" label="keybinds">
        <separator label="Keyboard Shortcuts"/><separator/>
        <menu execute="keybinds-pipemenu --openbox" id="openbox" label="Openbox Keybinds"/>
        <menu execute="keybinds-pipemenu --aliases" id="aliases" label="Bash Aliases"/>
        <menu execute="keybinds-pipemenu --geany" id="geany" label="Geany"/>
        <menu execute="keybinds-pipemenu --thunar" id="thunar" label="Thunar"/>
        <menu execute="keybinds-pipemenu --mirage" id="mirage" label="Mirage"/>
        <menu execute="keybinds-pipemenu --gimp" id="GIMP" label="GIMP"/>
        <menu execute="keybinds-pipemenu --mpv" id="MPV Player" label="MPV"/>
        <menu execute="keybinds-pipemenu --vlc" id="VLC Player" label="VLC"/>
        <menu execute="keybinds-pipemenu --terminator" id="terminator" label="Terminator"/>
        <menu execute="keybinds-pipemenu --firefox" id="firefox" label="Firefox"/>
    </menu>

_________________________________________________

rc.xml

Add the menu keyboard shortcut. If you want to use something else then you also need to change it for the tint2 button.

Obviously the menu can be run with the shortcut, without needing a clickable icon in Tint2.

    <keybind key="C-A-space">
      <action name="ShowMenu">
        <menu>keybinds-menu</menu>
      </action>
    </keybind>

_________________________________________________

Tint2 Button
# Show keybinds
button = new
button_icon = /usr/share/icons/HighContrast/scalable/devices/input-keyboard.svg     # set the path to the icon you want
button_text =
button_tooltip = Keyboard Shortcuts
button_lclick_command = xdotool key control+alt+space       # this must match the keybind in rc.xml
button_rclick_command =
button_mclick_command =
button_uwheel_command =
button_dwheel_command =
button_font_color = #ffffff 100
button_padding = 2 2
button_background_id = 
button_centered = 1
button_max_icon_size = 24

_________________________________________________

keybinds-pipemenu

Put this in ~/bin

#!/bin/bash
#    keybinds-pipemenu - an Bunsenlabs Openbox pipemenu for displaying keyboard shortcuts
#                        for the Window Manager, and various applications.
#    Copyright (C) 2015/2018 damo    <damo@bunsenlabs.org>
#                  2016 John Crawley    <john@bunsenlabs.org>
#
#    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.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# NB The keybinds in the Openbox 'Run' commands menu are clickable

# 'bl-kb' is used to parse 'rc.xml' and send the output to a textfile

HELP='    
    "keybinds-pipemenu": an Openbox Pipe Menu for displaying keyboard shortcuts.
                         It should normally be called from an Openbox menu.

    Options (usually passed from the menu):
    
        -h --help   show this message
        
        --openbox       display keybindings defined in rc.xml.
                        (The "Run commands" keybinds in the menu are clickable)         
        --aliases       output from "~/.bash_aliases"
        --geany         Geany Text Editor
        --thunar        Thunar File Manager
        --gimp          GIMP Image Editor
        --mirage        Mirage Image Viewer
        --mpv           Mpv Media Player
        --vlc           VLC Media Player
        --terminator    bespoke textfile containing Terminator terminal keybinds
        --firefox        bespoke textfile containing Firefox Web Browser keybinds

    NOTE: Some of the functionality of this pipemenu depends on the script
    "/usr/bin/bl-kb" which is provided by the package "bunsen-utilities".
'
BL_COMMON_LIBDIR="/usr/lib/bunsen/common"
USR_CFG_DIR="$HOME/.config/openbox"
KBSCRIPT="bl-kb"
KBTEXT="$USR_CFG_DIR/kbinds.txt"
AL_FILE="$HOME/.bash_aliases"
GEANY_FILE="$HOME/.config/geany/keybindings.conf"
THUNAR_FILE="$HOME/.config/Thunar/accels.scm"
GIMP_FILE="$HOME/.config/GIMP/2.10/menurc"
MPV_FILE="/etc/mpv/input.conf"
VLC_FILE="$HOME/.config/vlc/vlcrc"
MIR_FILE="$HOME/.config/mirage/accel_map"
TERM_FILE="$HOME/terminator-keybinds.txt" # this must previously have been written. Adjust path as required.
FF_FILE="$HOME/firefox-keybinds.txt"       # this must previously have been written. Adjust path as required.

# look for a help option somewhere 
if [[ $# -eq 0 ]] ; then 
    echo "$HELP"
    exit 0
else
    for i in "$@"
        do
            case "$i" in
            -h|--help)
                echo "$HELP"
                exit 0
                ;;
            esac
        done
fi

if ! . "$BL_COMMON_LIBDIR/bl-include.cfg" 2> /dev/null; then
    echo $"Error: Failed to locate bl-include.cfg in $BL_COMMON_LIBDIR" >&2
    exit 1
fi

# test if bl-kb exists in path
if ! type "$KBSCRIPT" &> /dev/null;then
    menuStart
    menuSeparator "$KBSCRIPT is not available. Try installing bunsen-utilities."
    menuEnd
    exit 1
fi

# check config file exists
function check_file(){
    if [ ! -f "$1" ] &> /dev/null; then
        menuStart
        menuSeparator "$1 not found."
        menuEnd
        exit 1
    fi
}

function write_aliases(){
    TEMP_FILE=$(mktemp)
    ALVAR=""
    
    check_file "$AL_FILE"
    
    ALVAR=$(awk '$1 ~ /^alias/{$1 = "";print}' "$AL_FILE")

    echo -e "$ALVAR" > "$TEMP_FILE"
    
    menuStart
    menuSeparator "Bash Aliases"
    menuSeparator
    while read -r line;do
        [[ ! -n ${line// /} ]] && continue
        currItem="$line"
        menuItem "$currItem" "echo >/dev/null 2>&1"
    done < "$TEMP_FILE"
    menuEnd
    
    rm "$TEMP_FILE"
    exit 0
}

function write_ob_keybinds(){
    # run script to write kbinds.txt, suppress terminal output
    "$KBSCRIPT" > /dev/null
    menuStart
    menuSeparator "Openbox window commands"
    menuSeparator
    while read -r a b c;do      # write out Openbox commands (not clickable)
        if [[ "$a" = "o" ]];then
            curItem=$(printf "%-20s %s" "$b" "$c")
            menuItem "$curItem" "echo >/dev/null 2>&1"
        fi
    done < "$KBTEXT"

    menuSeparator "'Run' commands"
    menuSeparator
    while read -r a b c;do      # write out 'Run' commands (clickable)
        if [[ "$a" = "x" ]];then
            curItem=$(printf "%-20s %s" "$b" "$c")
            menuItem "$curItem" "$c"
        fi
    done < "$KBTEXT"
    menuEnd
    exit 0   
}

function write_geany_keybinds(){
    TEMP_FILE=$(mktemp)
    GEANYVAR=""
    
    check_file "$GEANY_FILE"
    
    # Skip first line;skip lines without keybinds;replace patterns
    GVARLINE=$(sed '1d;/=$/d;s/<Primary>/Control+/;s/<Shift>/Shift+/;s/<Alt>/Alt+/;s/bracketleft/[/;s/bracketright/]/;s/=/  --  /' "$GEANY_FILE")
    echo -e "$GVARLINE" > "$TEMP_FILE"

    menuStart
    menuSeparator "Geany Keybinds"
    menuSeparator
    while read -r a b c;do
        currItem=$(printf "%-20s %5s %20s" "$a" "$b" "$c")
        menuItem "$currItem" "echo >/dev/null 2>&1"
    done < "$TEMP_FILE"
    menuEnd

    rm "$TEMP_FILE" 
    exit 0
}

function write_thunar_keybinds(){
    TEMP_FILE=$(mktemp)
    THVAR=""
    
    check_file "$THUNAR_FILE"
    
    # Skip first line;skip lines without keybinds;replace patterns
    THVARLINE=$(awk -F '[/|"]' '{print $4,$6}' "$THUNAR_FILE" | \
    sed '/ $/d;s/<Primary>/Control+/;s/<Alt>/Alt+/;s/<Shift>/Shift+/;s/ /  --  /')

    echo -e "$THVARLINE" > "$TEMP_FILE"

    menuStart
    menuSeparator "Thunar Keybinds"
    menuSeparator
    while read -r a b c;do
        currItem=$(printf "%-20s %-5s %s" "$a" "$b" "$c")
        menuItem "$currItem" "echo >/dev/null 2>&1"
    done < "$TEMP_FILE"
    menuEnd

    rm "$TEMP_FILE" 
    exit 0
}

function write_gimp_keybinds(){
    TEMP_FILE=$(mktemp)
    GIMPVAR=""
    
    check_file "$GIMP_FILE"
    
    # Extract strings;replace patterns
    GIMPVARLINE=$(awk -F '[/|"]' '{print $4,$6}' "$GIMP_FILE" | \
    sed '/ $/d;s/<Primary>/Control+/;s/<Alt>/Alt+/;s/<Shift>/Shift+/;s/ /  --  /')

    echo -e "$GIMPVARLINE" > "$TEMP_FILE"

    menuStart
    menuSeparator "GIMP Keybinds"
    menuSeparator
    while read -r a b c;do
        currItem=$(printf "%-20s %-5s %s" "$a" "$b" "$c")
        menuItem "$currItem" "echo >/dev/null 2>&1"
    done < "$TEMP_FILE"
    menuEnd

    rm "$TEMP_FILE" 
    exit 0
}

function write_mirage_keybinds(){
    TEMP_FILE=$(mktemp)
    MIRVAR=""
    
    check_file "$MIR_FILE"
    
    # Extract strings, replace patterns
    MIRVARLINE=$(awk -F '/' '{print $3}' "$MIR_FILE" | \
                sed 's/" "/   --   /;s/")//;s/<Primary>/Control+/;s/<Alt>/Alt+/;s/<Shift>/Shift+/')

    echo -e "$MIRVARLINE" > "$TEMP_FILE"

    menuStart
    menuSeparator "Mirage Keybinds"
    menuSeparator
    while read -r line;do
        str=${line#*--}                     # select keybind chars
        [[ ! -n ${str// /} ]] && continue   # if no string then skip line
        currItem="$line"
        menuItem "$currItem" "echo >/dev/null 2>&1"
    done < "$TEMP_FILE"
    menuEnd

    rm "$TEMP_FILE" 
    exit 0
}

function write_mpv_keybinds(){
    TEMP_FILE=$(mktemp)
    MPVVAR=""
    
    check_file "$MPV_FILE"
    
    MPVVARLINE=$(awk '{printf "%-10s %-5s %s %s %s\n", $1,"  --  ",$2,$3,$4}' "$MPV_FILE")

    echo -e "$MPVVARLINE" > "$TEMP_FILE"

    menuStart
    menuSeparator "MPV Keybinds"
    menuSeparator
    while read -r line;do
        currItem="$line"
        menuItem "$currItem" "echo >/dev/null 2>&1"
    done < "$TEMP_FILE"
    menuEnd

    rm "$TEMP_FILE" 
    exit 0
}

function write_vlc_keybinds(){
    TEMP_FILE=$(mktemp)
    VLCVAR=""
    
    check_file "$VLC_FILE"
    
    # Skip first line;skip lines without keybinds;replace patterns
    VLCVARLINE=$( awk '/^#key/' "$VLC_FILE" | sed 's/#key-//;/=$/d;s/=/  --  /')

    echo -e "$VLCVARLINE" > "$TEMP_FILE"

    menuStart
    menuSeparator "VLC Keybinds"
    menuSeparator
    while read -r a b;do
        currItem=$(printf "%-20s %s" "$a" "$b")
        menuItem "$currItem" "echo >/dev/null 2>&1"
    done < "$TEMP_FILE"

    menuEnd

    rm "$TEMP_FILE" 
    exit 0
}

function write_terminator_keybinds(){
    TEMP_FILE=$(mktemp)
    MPVVAR=""
    
    check_file "$TERM_FILE"
    
    TERMVARLINE=$(awk -F "[.|,]" '{print $1}' "$TERM_FILE")

    echo -e "$TERMVARLINE" > "$TEMP_FILE"

    menuStart
    menuSeparator "Terminator Keybinds"
    menuSeparator
    while read -r line;do
        currItem="$line"
        menuItem "$currItem" "echo >/dev/null 2>&1"
    done < "$TEMP_FILE"
    menuEnd

    rm "$TEMP_FILE" 
    exit 0
}

function write_firefox_keybinds(){
    TEMP_FILE=$(mktemp)
    MPVVAR=""
    
    check_file "$FF_FILE"
    
    FFVARLINE=$(awk -F "[.|,]" '{print $1}' "$FF_FILE")

    echo -e "$FFVARLINE" > "$TEMP_FILE"

    menuStart
    menuSeparator "Firefox Keybinds"
    menuSeparator
    while read -r line;do
        currItem="$line"
        menuItem "$currItem" "echo >/dev/null 2>&1"
    done < "$TEMP_FILE"
    menuEnd

    rm "$TEMP_FILE" 
    exit 0
}

# Comment out any of these, if the application isn't installed
case "$1" in
    --aliases   ) write_aliases;;
    --openbox   ) write_ob_keybinds;;
    --geany     ) write_geany_keybinds;;
    --thunar    ) write_thunar_keybinds;;
    --gimp      ) write_gimp_keybinds;;
    --mirage    ) write_mirage_keybinds;;
    --mpv       ) write_mpv_keybinds;;
    --vlc       ) write_vlc_keybinds;;
    --terminator) write_terminator_keybinds;;
    --firefox    ) write_firefox_keybinds;;
    *           ) echo "$HELP"
                  exit 0;;
esac

_________________________________________________

User-defined textfiles for shortcuts

Most of the menu entries are parsed from the application configs, but for a couple I have had to hard-code them in textfiles.
So for terminator and firefox I created terminator-keybinds.txt and firefox-keybinds.txt. Don't forget to adjust the paths to these files if you use them!
This is where you can add your own: use one of the "write_" functions as a template.

terminator-keybinds.txt

Ctrl+Shift+O -- Split terminals Horizontally.
Ctrl+Shift+E -- Split terminals Vertically.
Ctrl+Shift+Right -- Move parent dragbar Right.
Ctrl+Shift+Left -- Move parent dragbar Left.
Ctrl+Shift+Up -- Move parent dragbar Up.
Ctrl+Shift+Down -- Move parent dragbar Down.
Ctrl+Shift+S -- Hide/Show Scrollbar.
Ctrl+Shift+F -- Search within terminal scrollback
Ctrl+Shift+N -- Next terminal within the same tab
Ctrl+Tab -- Next terminal within the same tab
Ctrl+Shift+P   Previous terminal within the same tab
Ctrl+Shift+Tab -- Previous terminal within the same tab
Alt+Up -- Move to the terminal above the current one.
Alt+Down -- Move to the terminal below the current one.
Alt+Left -- Move to the terminal left of the current one.
Alt+Right -- Move to the terminal right of the current one.
Ctrl+Shift+C -- Copy selected text to clipboard
Ctrl+Shift+V -- Paste clipboard text
Ctrl+Shift+W -- Close the current terminal.
Ctrl+Shift+Q -- Quits Terminator
Ctrl+Shift+X -- Toggle all terminals and current one (maximise).
Ctrl+Shift+Z -- Toggle all terminals and current one (zoom).
Ctrl+Shift+T -- Open new tab
Ctrl+Shift+Alt+T -- Open new tab at root level, if using extreme_tabs.
Ctrl+PageDown -- Move to next Tab
Ctrl+PageUp -- Move to previous Tab
Ctrl+Shift+PageDown -- Swap tab position with next Tab
Ctrl+Shift+PageUp -- Swap tab position with previous Tab
Ctrl+Shift+F -- Open buffer search bar. Escape to cancel.
Ctrl+Plus (+) -- Increase font size.
Ctrl+Minus (-) -- Decrease font size
Ctrl+Zero (0) -- Restore font size to original setting.
F11 -- Toggle fullscreen
Ctrl+Shift+R -- Reset terminal state
Ctrl+Shift+G -- Reset terminal state and clear window 

firefox-keybinds.txt

F5 -- Refresh current page, frame, or tab.
F11 -- Toggle Fullscreen
Esc -- Stop page or download from loading.
Spacebar -- Moves down a page at a time.
Alt+Home -- Open Homepage.
Alt+DownArrow -- Display all previous text entered in a text box.
Alt+LeftArrow -- Back a page.
Alt+RightArrow -- Forward a page.
Ctrl+(-/+) -- Increase or decrease the font size.
Ctrl+0 -- Reset font size back to default.
Ctrl+D -- Add a bookmark for current page.
Ctrl+F -- Find text on current page.
Ctrl+H -- View browsing history.
Ctrl+I -- Display available bookmarks.
Ctrl+J -- Display the download window.
Ctrl+K -- Move the cursor to the search box.
Ctrl+E -- Move the cursor to the search box.
Ctrl+L -- Move cursor to address box.
Ctrl+N -- Open New browser window.
Ctrl+O -- Access the Open File window.
Ctrl+P -- Print current page or frame.
Ctrl+T -- Opens a new tab.
Ctrl+F4 Close the currently selected tab.
Ctrl+W -- Close the currently selected tab.
Ctrl+F5 -- Force full refresh the page (ignores Internet cache).
Ctrl+Enter -- Quickly complete an address.
Ctrl+Tab -- Moves through each of the open tabs.
Ctrl+Shift+Del -- Open the Clear Data window to quickly clear private data.
Ctrl+Shift+B -- Open the Bookmarks window to view all bookmarks in Firefox.
Ctrl+Shift+J -- Open the Browser Console to troubleshoot script error.
Ctrl+Shift+P -- Open a new Private Browsing window.
Ctrl+Shift+T -- Undo the close of a window.
Ctrl+Shift+W -- Close the Firefox browser window.
Shift+Spacebar -- Moves up a page at a time.

Last edited by damo (2018-11-25 19:49:24)


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#2 2018-11-25 13:42:50

S7.L
Member
Registered: 2018-09-16
Posts: 102

Re: Openbox Menu to display application Keyboard Shortcuts

Very cool, thanks for sharing damo.


"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate."...Voilà!

~ V

Offline

#3 2018-11-25 14:27:38

onlain
Member
Registered: 2016-04-22
Posts: 31

Re: Openbox Menu to display application Keyboard Shortcuts

Great work, damo

Offline

#4 2018-11-27 13:08:51

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 867
Website

Re: Openbox Menu to display application Keyboard Shortcuts

Thanks so much for the time and opportunity to make it damo, I will use it with pleasure. I have made a simple text just yesterday

A+F2 = gmrun
---
Print = scrot
A+Print = scrot -s
---
A+X = close
A+T = urxvt/top
A+S = spacefm
A+Z = urxvt
A+Q = openbox --exit
A+P = wallpaper --feh
A+M = deadbeef
A+B = palemoon
A+A = urxvt/amixer
A+U = undecorated
A+D = decorate
A+J = junkclean
---
C+M = urxvt/tmux
C+Up = amixer vol UP
C+Down = amixer vol DOWN

incompleted ones, but seeing your post, I'll pass it here.
Thank you!

Best regards,
Nili


Nothing beats peace and quiet. - Tomoki Sakurai

Offline

#5 2018-11-27 13:59:30

damo
....moderator....
Registered: 2015-08-20
Posts: 4,378

Re: Openbox Menu to display application Keyboard Shortcuts

Nice idea - that is the kind of thing I use as well. The Openbox keybinds pipemenu shows all that, but they can get lost in the noise.


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

Board footer

Powered by FluxBB