diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-10-04 14:50:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-10-04 14:50:35 +0000 |
commit | ccc606e17ceea4cdc9666131506c19b74a528d1a (patch) | |
tree | a00063fa71c7561768e1bae568e323b3030b2839 /identify/identify.py | |
parent | Releasing debian version 1.4.29-1. (diff) | |
download | identify-ccc606e17ceea4cdc9666131506c19b74a528d1a.tar.xz identify-ccc606e17ceea4cdc9666131506c19b74a528d1a.zip |
Merging upstream version 1.5.5.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'identify/identify.py')
-rw-r--r-- | identify/identify.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/identify/identify.py b/identify/identify.py index 8a21d8b..1c0e677 100644 --- a/identify/identify.py +++ b/identify/identify.py @@ -141,6 +141,27 @@ def _shebang_split(line): return line.split() +def _parse_nix_shebang(bytesio, cmd): + while bytesio.read(2) == b'#!': + next_line = bytesio.readline() + try: + next_line = next_line.decode('UTF-8') + except UnicodeDecodeError: + return cmd + + for c in next_line: + if c not in printable: + return cmd + + line_tokens = tuple(_shebang_split(next_line.strip())) + for i, token in enumerate(line_tokens[:-1]): + if token != '-i': + continue + # the argument to -i flag + cmd = (line_tokens[i + 1],) + return cmd + + def parse_shebang(bytesio): """Parse the shebang from a file opened for reading binary.""" if bytesio.read(2) != b'#!': @@ -159,6 +180,8 @@ def parse_shebang(bytesio): cmd = tuple(_shebang_split(first_line.strip())) if cmd and cmd[0] == '/usr/bin/env': cmd = cmd[1:] + if cmd == ('nix-shell',): + return _parse_nix_shebang(bytesio, cmd) return cmd |