Skip to content

Commit

Permalink
Detect terminfo in more portable way
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
  • Loading branch information
legionus committed Aug 25, 2021
1 parent 1c4692b commit 7537d23
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/create-initrd
Expand Up @@ -151,7 +151,7 @@ FILES+=(

for n in \
/lib/udev/{edd_id,vol_id,path_id,usb_id,firmware} \
/usr/share/terminfo/l \
$(find-terminfo linux) \
/var/resolv \
"$KERNEL_MODULES_DIR"/modules.{builtin,order,builtin.modinfo} \
/etc/modprobe.conf;
Expand Down
80 changes: 80 additions & 0 deletions tools/find-terminfo
@@ -0,0 +1,80 @@
#!/bin/bash -efu

. shell-error

show_usage()
{
cat <<-EOF
Usage: $PROG [options] [termname]
The utility shows the path to terminfo entry.
Options:
-f, --first show only first found result;
-h, --help show this text and exit.
Report bugs to authors.
EOF
exit
}

TEMP=`getopt -n "$PROG" -o "f" -l "first" -- "$@"` ||
show_usage
eval set -- "$TEMP"

only_first=
while :; do
case "$1" in
-f|--first)
only_first=1
;;
-h|--help)
show_usage
;;
--) shift; break
;;
*) fatal "unrecognized option: $1"
;;
esac
shift
done

case "$#" in
0) set -- "$TERM" ;;
1) ;;
*) fatal "one argument expected" ;;
esac

[ -n "$1" ] ||
fatal "a non-empty argument is expected"

DIRS=(
"/usr/share/terminfo"
"/lib/terminfo"
"/etc/terminfo"
)

if infocmp=$(type -P infocmp); then
readarray -t DIRS < <($infocmp -D)
elif toe="$(type -P toe)"; then
readarray -t DIRS < <(toe -a -s | grep '^-\+>' |cut -d\ -f2-)
fi

sub=
[ -z "${1##*/*}" ] ||
sub="${1:0:1}/"

found=
for dir in "${DIRS[@]}"; do
if [ -f "$dir/$sub$1" ]; then
printf '%s\n' "$dir/$sub$1"
found=1

[ -z "$only_first" ] ||
break
fi
done

[ -n "$found" ] ||
fatal "'$1' not found"

0 comments on commit 7537d23

Please sign in to comment.