NAME

Terminal::Identify - Perl extension for identifying the terminal emulator which is in use by the logged-in user

SYNOPSIS

# Standard usage of the Perl command use.
use Terminal::Identify;

# Optional usage of the Perl command use.
use Terminal::Identify qw(whichterminalami);

# Standard way for the identification of the terminal emulator.
whichterminalami(["PROC"|"PATH"|"FTN"]);

# Alternate way for the identification of the terminal emulator.
Terminal::Identify::whichterminalami(["PROC"|"PATH"|"FTN"]);

The strings in square brackets are optional. Without subroutine argument the process name of the terminal is identified. The key words are separated by a logical or. They are controlling the format of the output of the identified terminal.

# Standard usage of the global output format flag.
$OutputFormat = "PROC"|"PATH"|"FTN"

# Optional usage of the global output format flag.
$Terminal::Identify::OutputFormat = "PROC"|"PATH"|"FTN"

The introduced global package variable can also be used for controlling the format of the output of the identified terminal. If the global variable is used, the subroutine arguments are ignored.

DESCRIPTION

The main objective of this package is to provide a method which is capable of identifying the terminal emulator a logged-in user is actual using.

The logged-in user is related to a login shell. Knowing this, the logged-in user as well as the login shell of the logged-in user are determined. Next the terminal path to the pseudo terminal shell is identified. Based on this informations the related process of logged in user, his login shell and the terminal path is identified. The evaluation of the PPID of this process results in the parents process ID. The command related to this PID is the name of the terminal in use.

The terminal emulator in use by the logged-in user can be identified by the main command whichterminalami and the other defined aliases.

Not only a terminal emulator can be identified by this package, it is also able to detect that a system console is being used by a logged-in user.

OUTPUT FORMAT

  • PROC

  • PATH

  • FTN

EXAMPLES

# Declare the terminal variable.
my $terminal;

$terminal = whichterminalami();
print $terminal . "\n";

$term = whichterminalami("PROC");
print $terminal . "\n";

$term = whichterminalami("PATH"); 
print $terminal . "\n";

$term = whichterminalami("FTN");
print $terminal . "\n";

$term = whichterminalami();
print $terminal . "\n";

VARIABLES EXPLANATION

No variables yet

ERROR CODES

No error codes yet

NOTES

No notes yet

SYSTEM COMPATIBILITY

The module should work on Linux maybe on Unix or Unix-like operating systems in general until something else was shown.

FUNCTIONALITY REQUIREMENT

  • ps

  • users

  • shells

  • passwd

  • which

METHOD ALIASES

Aliases for whichterminalami, which can be used are:

whichtermami       <=  whichterminalami
which_terminal     <=  whichterminalami
identify_terminal  <=  whichterminalami

TERMINALS TESTED

Terminal emulators tested so far with the package:

  • Aterm

  • Cool Retro Term

  • Deepin Terminal

  • Eterm

  • Guake Terminal

  • kitty

  • LXTerminal

  • MATE-Terminal

  • QTerminal

  • ROXTerm

  • Sakura

  • Terminator

  • Terminology

  • Termit

  • Tilda

  • Tilix

  • UXTerm

  • Xfce4-Terminal-Emulator

  • xiterm+thai

  • Xterm

  • Yakuake

LIMITATIONS

Not known yet

OPEN ISSUES

None so far

KNOWN BUGS

Not known yet

ABSTRACT

The module identifies the terminal emulator which the logged-in user is using currently. For this purpose, the login shells and the logged-in users are determined. The Perl script from which we identify the terminal emulator itself runs in a pseudo terminal shell (pts) with its own identification number. This pseudo terminal shell (pts) is identified, too. Based on all the former informations, the terminal emulator in use can be determined. If the Perl script runs from within the system console, the output returns the system console.

SEE ALSO

users(1) - Linux manual page

shells(5) - Linux manual page

passwd(5) - Linux manual page

ps(1) - Linux manual page

which(1) - Linux manual page

AUTHOR

Dr. Peter Netz, <ztenretep@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2022 by Dr. Peter Netz

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.30.0 or, at your option, any later version of Perl 5 you may have available.