Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let ok.sh control python version #9

Merged
merged 1 commit into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ok-show.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python #both python2 and python3
# both python2 and python3
# -*- coding: utf-8 -*-

from __future__ import print_function
Expand Down
12 changes: 8 additions & 4 deletions ok.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pushd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null;
_OK__PATH_TO_ME=$(pwd)
popd > /dev/null;

# Don't let ok-show.py's shebang control the python version
_OK__PATH_TO_PYTHON=$(command -v python)


ok() {
function _ok_cmd_usage {
Expand Down Expand Up @@ -54,7 +57,8 @@ environment variables (other configuration):
_OK_VERBOSE Level ($v) of feedback ok provides. 0=quiet, 1=normal, 2=verbose. Defaults to 1. Can be overriden with --verbose or --quiet.
environment variables (for internal use):
_OK__LAST_PWD Remember the path ($_OK__LAST_PWD) that was last listed, for use with the list-once command.
_OK__PATH_TO_ME The path ($_OK__PATH_TO_ME) to the location of this script.\\n"
_OK__PATH_TO_ME The path ($_OK__PATH_TO_ME) to the location of this script.
_OK__PATH_TO_PYTHON The path ($_OK__PATH_TO_PYTHON) to the used python interpreter.\\n"
fi
if [[ -n $1 ]]; then
echo -e "$1\\n"
Expand All @@ -69,7 +73,7 @@ environment variables (for internal use):
shift
# get the line to be executed
local line_text
line_text="$(cat "$ok_file" | "${_OK__PATH_TO_ME}/ok-show.py" -v "$verbose" -c "$comment_align" -t "$(tput cols)" "$line_nr")"
line_text="$(cat "$ok_file" | "$_OK__PATH_TO_PYTHON" "${_OK__PATH_TO_ME}/ok-show.py" -v "$verbose" -c "$comment_align" -t "$(tput cols)" "$line_nr")"
local res=$?
if [[ $res -ne 0 ]]; then
#because stdout/stderr are swapped by ok-show.py in this case, handle this too
Expand All @@ -82,7 +86,7 @@ environment variables (for internal use):
function _ok_cmd_list {
unset -f _ok_cmd_list

cat "$ok_file" | "${_OK__PATH_TO_ME}/ok-show.py" -v "$verbose" -c "$comment_align" -t "$(tput cols)" || return $?
cat "$ok_file" | "$_OK__PATH_TO_PYTHON" "${_OK__PATH_TO_ME}/ok-show.py" -v "$verbose" -c "$comment_align" -t "$(tput cols)" || return $?
}

# export variables because python is a sub-process, and variables might have changed since initialization
Expand Down Expand Up @@ -190,7 +194,7 @@ environment variables (for internal use):
}

if [[ "$called" == "$0" ]]; then
if [[ -z $(command -v python) ]]; then
if [[ -z "$_OK__PATH_TO_PYTHON" ]]; then
>&2 echo "ERROR: python is required to run 'ok', but can't be found"
exit 1
fi
Expand Down