From ccc606e17ceea4cdc9666131506c19b74a528d1a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 4 Oct 2020 16:50:35 +0200 Subject: Merging upstream version 1.5.5. Signed-off-by: Daniel Baumann --- identify/identify.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'identify/identify.py') 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 -- cgit v1.2.3