Skip to content

Commit

Permalink
ttar: Allow custom python path
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Ziemke <github@5pi.de>
  • Loading branch information
discordianfish committed Jul 18, 2022
1 parent f74c35e commit c34dfd6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions ttar
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ path=""
CMD=""
ARG_STRING="$*"

PYTHON=${PYTHON:-python}

#------------------------------------------------------------------------------
# Not all sed implementations can work on null bytes. In order to make ttar
# work out of the box on macOS, use Python as a stream editor.

USE_PYTHON=0

PYTHON_CREATE_FILTER=$(cat << 'PCF'
#!/usr/bin/env python
import re
import sys
Expand All @@ -51,8 +51,6 @@ PCF
)

PYTHON_EXTRACT_FILTER=$(cat << 'PEF'
#!/usr/bin/env python
import re
import sys
Expand Down Expand Up @@ -239,7 +237,7 @@ function extract {
# Remove EOF unless preceded by backslash
# Remove one backslash in front of EOF
if [ $USE_PYTHON -eq 1 ]; then
echo -n "$line" | python -c "$PYTHON_EXTRACT_FILTER" >> "$path"
echo -n "$line" | $PYTHON -c "$PYTHON_EXTRACT_FILTER" >> "$path"
else
# The repeated pattern makes up for sed's lack of negative
# lookbehind assertions (for consecutive null bytes).
Expand Down Expand Up @@ -358,7 +356,7 @@ function _create {
# Add backslash in front of NULLBYTE
# Replace null byte with NULLBYTE
if [ $USE_PYTHON -eq 1 ]; then
< "$file" python -c "$PYTHON_CREATE_FILTER"
< "$file" $PYTHON -c "$PYTHON_CREATE_FILTER"
else
< "$file" \
sed 's/EOF/\\EOF/g;
Expand Down

0 comments on commit c34dfd6

Please sign in to comment.