Skip to content

Instantly share code, notes, and snippets.

@hyamamoto
Created December 22, 2014 03:25
Show Gist options
  • Save hyamamoto/9f3e70e68eca41c03926 to your computer and use it in GitHub Desktop.
Save hyamamoto/9f3e70e68eca41c03926 to your computer and use it in GitHub Desktop.
The script what greps terminfo entries and print the related information. It's useful to find a key corresponding to an unknown character sequence.

Reverse terminfo entry lookup

What's this

This script searches terminfo entries and print its information.

Technically, it does the same as the 1-liner below does.

infocmp -1x | grep 'OA' \
  | sed 's/^ *//' | tee /dev/tty | sed 's/=.*$//' \
  | xargs -l sh -c 'man 5 terminfo | grep -F "  $0  "'
#!/bin/sh
# Reverse terminfo Lookup Command.
#
# Author: Hiroshi Yamamoto ([email protected])
# Licennse: WTFPL 2.0 (Do Whate[omitted]))
param_code=$1
param_term=$2
if [ -z "$1" ]; then
echo "Usage: $0 [part of a terminfo entry] [termname]"
echo "Example:"
echo " $0 kent"
echo " $0 OA xterm"
echo " $0 kcuu1 putty"
echo " $0 \\\\EA rxvt"
echo " $0 kf1= xterm"
exit 1
fi
echo "Searching for \"$param_code\"."
if [ -z "$2" ]; then
echo "TERM value is \"$TERM (default)\"."
else
echo "TERM value is \"$param_term\"."
fi
entries=`infocmp -1x $param_term \
| grep '=' | grep -F $param_code \
| sed 's/=^ *//' | sed 's/,$//'`
if [ -z "$entries" ]; then
echo "No entry found"
exit 1
fi
for entry in $entries
do
echo ---
echo "entry :" $entry
code=`echo $entry | sed 's/=.*$//'`
# echo "code :" $code
hint=`man 5 terminfo 2> /dev/null | grep " $code " `
echo "hint :" $hint
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment