Last active
October 25, 2023 16:16
-
-
Save smmr0/83efd2ab5d00a7a167f03effa18f2cc9 to your computer and use it in GitHub Desktop.
Todo.txt: Action helper: Filter with `python3` as `python`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# Mainly for use with <https://github.com/FND/todo.txt-cli/blob/1bdbdf41464826cc85e84ae8c3c17336e24a2922/futureTasks> | |
# Installation: | |
# 1. `cd "$TODO_ACTIONS_DIR"` | |
# 2. `mkdir -p helpers` | |
# 3. `mkdir -p filters` | |
# 4. `ln -s /path/to/filter_with_python3_as_python helpers/` (where `/path/to/filter_with_python3_as_python` is this file) | |
# 5. `ln -s /path/to/filter_cmd filters/` (where `/path/to/filter_cmd` is to be used as `TODOTXT_FINAL_FILTER`) | |
# 6. `ln -s helpers/filter_with_python3_as_python filter_cmd` | |
set -euf | |
if [ "$#" -ge 1 ]; then | |
filter="$1" | |
shift | |
else | |
filter="$TODOTXT_DEFAULT_ACTION" | |
fi | |
export TODOTXT_FINAL_FILTER="$TODO_ACTIONS_DIR/filters/$filter | $TODOTXT_FINAL_FILTER" | |
if command -v python > /dev/null 2>&1 || ! which python3 > /dev/null 2>&1; then | |
exec "$TODO_SH" ls "$@" | |
fi | |
exit_code=0 | |
temp_python_path="$(mktemp -d)" | |
ln -s "$(which python3)" "$temp_python_path/python" | |
export PATH="$PATH:$temp_python_path" | |
"$TODO_SH" ls "$@" || exit_code="$?" | |
rm -r "$temp_python_path" | |
exit "$exit_code" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment