diff --git a/README.md b/README.md index 5b2ce3f..b01549e 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,8 @@ Before I explain these helpers, I'd like to show the `ok`-command help screen, b -q, --quiet Only show really necessary output, so surpress echoing the command. -f, --file Use a custom file instead of '.ok'; use '-' for stdin -a, --alias When using 'ok' in an alias, is used to keep the history correct when used with 'list-prompt'. + -V, --version Show version number and exit + -h, --help Show this help screen script-arguments: ... These are passed through, when a line is executed (you can enter these too at the ok-prompt) @@ -234,7 +236,7 @@ You can think up anything you want; the sky is the limit. I intent to keep a lis ## Development -`ok` should run on a standard _Linux_ or _macOS_ installation. That means minimum _bash 3.2_ and _python 2.7_. +`ok` should run on a standard _Linux_ or _macOS_ installation. That means minimum _bash 3.2_ and _python 2.7_ (python code should also work in _python 3.5+_). For testing: if you don't want to source the script after every change you make: you can run `./ok.sh test ...` as a shortcut. This starts a sub-shell, so there won't be any side effects (like `cd`). diff --git a/ok-show.py b/ok-show.py index f981a58..3997bab 100755 --- a/ok-show.py +++ b/ok-show.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python #both python2 and python3 # -*- coding: utf-8 -*- from __future__ import print_function @@ -100,7 +100,7 @@ def format_lines(l, elastic_tab, nr_positions_line_nr, max_width): max_pos = ansi_len(x.line)+1 if x.pos is None else x.pos if start_group is not None: # We are in a group if x.t == 'code': - max_pos = max(max_pos, x.pos) + max_pos = max(max_pos, 0 if x.pos is None else x.pos) has_no_next_item = i+1>=len(l) if has_no_next_item or l[i+1].t in group_reset: max_command_width = max_width - nr_positions_line_nr - len('. ') diff --git a/ok.sh b/ok.sh index fbef2f0..6ed5507 100755 --- a/ok.sh +++ b/ok.sh @@ -31,6 +31,8 @@ options: -q, --quiet Only show really necessary output, so surpress echoing the command. -f, --file Use a custom file instead of '.ok'; use '-' for stdin -a, --alias When using 'ok' in an alias, is used to keep the history correct when used with 'list-prompt'. + -V, --version Show version number and exit + -h, --help Show this help screen script-arguments: ... These are passed through, when a line is executed (you can enter these too at the ok-prompt)\\n" @@ -88,9 +90,10 @@ environment variables (for internal use): export "$x"="${!x}" done + local -r version="0.8.0" # used for colored output (see: https://stackoverflow.com/a/20983251/56) # notice: this is partly a duplication from code in ok-show.py - local c_nc=$(tput sgr0) + local -r c_nc=$(tput sgr0) if [ -z ${_OK_C_NUMBER+x} ]; then local c_number=$(tput setaf 6); else local c_number=$_OK_C_NUMBER; fi #NUMBER defaults to CYAN if [ -z ${_OK_C_PROMPT+x} ]; then local c_prompt=$c_number; else local c_prompt=$_OK_C_PROMPT; fi #PROMPT defaults to same color as NUMBER # other customizations (some environment variables can be overridden by arguments) @@ -127,6 +130,7 @@ environment variables (for internal use): p | list-prompt) cmd=list; show_prompt=1; once_check=0;; h | help) cmd=usage;; #options + -V | --version) cmd=version;; -\? | -h | --help) cmd=usage;; -v | --verbose) verbose=2;; -q | --quiet) verbose=0;; @@ -141,6 +145,8 @@ environment variables (for internal use): if [[ $cmd == usage ]]; then _ok_cmd_usage "$usage_error" || return $? + elif [[ $cmd == version ]]; then + echo "ok-bash $version" elif [[ - == "$ok_file" || -r "$ok_file" ]]; then if [[ $cmd == run ]]; then _ok_cmd_run "$line_nr" "$@" || return $?