User Tools

Site Tools


show_keybindings.sh

Show current uzbl keybindings

Description

This script shows the current keybindings of uzbl in the active instance of uzbl.

Source

#!/bin/sh

# Script to display Keyboard-Bindings of UZBL.
# Possible invokation from config-file:
#   menu_add Keybindings = spawn @scripts_dir/show_keybindings.sh "Group"
# Requires sed, tempfile and sort.

cd

tmpfile="$(tempfile)"

case "$8" in
	Group|group|g|G) # Commands will be rudimentarily grouped.
		sort="Group";;
	Search|search|s|S) # Only Web-Searching Shortcuts will be shown.
		sort="Search";;
	* ) # Commands will be sorted, to allow looking for overlapping commands.
		sort="Sort";;
esac

if [ "$sort" = "Group" ] ; then
	echo "   Keybindings\n   ===========\n\n      (defined in $1)" > "$tmpfile"
	
	out="$(sed -n -e "s/^[ 	]*@bind[ 	]*/ /p" "$1")"
	if [ -n "$out" ] ; then echo "\n\nGlobal\n------\n\n$out\n" >> "$tmpfile" ; fi

	if [ -n "$(sed -n -e "s/^[ 	]*@cbind[ 	]*//p" "$1")" ] ; then echo "\nCmd-Mode\n--------\n" >> "$tmpfile" ; fi

	out="$(sed -n -e "s/^[ 	]*@cbind[ 	]*/ /; T end; s/= uri htt//; t end; p; :end" "$1")"
	if [ -n "$out" ] ; then echo "$out" >> "$tmpfile" ; fi

	out="$(sed -n -e "s/^[ 	]*@cbind[ 	]*/ /; T end; s/\\\\@<encodeURIComponent(%r)>\\\\@/%s/p; :end d" "$1")"
	if [ -n "$out" ] ; then echo "\nWeb-Searching\n$out" >> "$tmpfile" ; fi

	out="$(sed -n -e "s/^[ 	]*@cbind[ 	]*/ /; T end; s/\\\\@<encodeURIComponent(%r)>\\\\@/%s/; t end; s/= uri htt/= uri htt/p; :end d" "$1")"
	if [ -n "$out" ] ; then echo "\nHard-Bookmarks\n$out" >> "$tmpfile" ; fi

	out="$(sed -n -e "s/^[ 	]*@ebind[ 	]*/ /p" "$1")"
	if [ -n "$out" ] ; then echo "\n\nIns-Mode\n--------\n\n$out\n" >> "$tmpfile" ; fi
elif [ "$sort" = "Search" ] ; then
	echo "   Keybindings\n   ===========\n\n      (Web-Searches defined in $1)\n\n" > "$tmpfile"
	sed -n -e "s/^[ 	]*@cbind[ 	]*//; T end; s/\\\\@<encodeURIComponent(%r)>\\\\@/%s/p; :end d" "$1" | sort >> "$tmpfile"
else
	echo "$(sed -n -e "s/^[ 	]*@[ec]bind[ 	]*//p" "$1")" > "$tmpfile"
	echo "$(sed -n -e "s/^[ 	]*@bind[ 	]*//p" "$1")" >> "$tmpfile"
	list="$(cat "$tmpfile")"
	echo "   Keybindings\n   ===========\n\n      (defined in $1)\n\n" > "$tmpfile"
	echo "$list" | sort >> "$tmpfile"
fi

echo "uri file://$tmpfile" > "$4"

Installation

Add something like this to your uzbl config:

menu_add Keybindings = spawn @scripts_dir/show_keybindings.sh "Group"
show_keybindings.sh.txt · Last modified: 2016/08/31 14:10 (external edit)