diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-10-04 14:50:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-10-04 14:50:32 +0000 |
commit | ede3da3368e77e464dda151b9d3f7807aacf07eb (patch) | |
tree | 113ea3ed873fdedfbdd29bfeed975b5813bbd172 /identify/identify.py | |
parent | Adding upstream version 1.4.29. (diff) | |
download | identify-ede3da3368e77e464dda151b9d3f7807aacf07eb.tar.xz identify-ede3da3368e77e464dda151b9d3f7807aacf07eb.zip |
Adding upstream version 1.5.5.upstream/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 |