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

Mini stuff #8

Merged
merged 3 commits into from
Feb 7, 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file> Use a custom file instead of '.ok'; use '-' for stdin
-a, --alias <name> When using 'ok' in an alias, <name> 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)

Expand Down Expand Up @@ -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`).

Expand Down
4 changes: 2 additions & 2 deletions ok-show.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python #both python2 and python3
# -*- coding: utf-8 -*-

from __future__ import print_function
Expand Down Expand Up @@ -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('. ')
Expand Down
8 changes: 7 additions & 1 deletion ok.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ options:
-q, --quiet Only show really necessary output, so surpress echoing the command.
-f, --file <file> Use a custom file instead of '.ok'; use '-' for stdin
-a, --alias <name> When using 'ok' in an alias, <name> 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"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;;
Expand All @@ -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 $?
Expand Down