From 803a8e2963f091aa4dbfe164b73182eb2dcdec2c Mon Sep 17 00:00:00 2001 From: Doeke Zanstra Date: Tue, 16 Aug 2022 17:30:11 +0200 Subject: [PATCH] Added --summary --- ok-show.py | 9 +++++++-- ok.sh | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ok-show.py b/ok-show.py index a747de2..cb47036 100755 --- a/ok-show.py +++ b/ok-show.py @@ -263,7 +263,7 @@ def main(): parser.add_argument('--terminal_width', '-t', metavar='TW', type=int, default=None, help='number of columns of the terminal (tput cols)') parser.add_argument('--internal_commands', '-I', metavar='IC', type=str, default='list,list-once,list-prompt,help', help='Internal commands of ok (that cannot be used as named lines)') - parser.add_argument('command', metavar='CMD', type=str, nargs='?', help='The command name or line number to show (system commands: .list_commands)') + parser.add_argument('command', metavar='CMD', type=str, nargs='?', help='The command name or line number to show (system commands: .list_commands; .list_named_commands)') args = parser.parse_args() if args.terminal_width is None: @@ -313,8 +313,13 @@ def main(): format_lines(p_lines, args.heading_align, args.comment_align, nr_positions_line_nr, args.terminal_width) if system_command: + all_commands = [p_line.get_line_name_or_number() for p_line in p_lines if p_line.name is not None] if args.command == '.list_commands': - print(' '.join([p_line.get_line_name_or_number() for p_line in p_lines if p_line.name is not None]+internal_commands)) + print(' '.join(all_commands)) + elif args.command in ('.list_named_commands', '.summary'): + named_commands = list(set(all_commands) - set(internal_commands)) + named_commands.sort() + print(' '.join(named_commands)) else: print('Unknown system command "{}"'.format(args.command)) sys.exit(1) diff --git a/ok.sh b/ok.sh index 2f87d1d..0533e35 100755 --- a/ok.sh +++ b/ok.sh @@ -28,6 +28,7 @@ command (use one): list-prompt Show the list and wait for input at the ok-prompt (like --list and in one command).$list_prompt_default help Show this usage page. options: + -s, --summary Show all named commands, space seperated -c, --comment-align N Level of comment alignment. See \$_OK_COMMENT_ALIGN -v, --verbose Show more output, mostly errors. Also it shows environment-variables in this screen. -q, --quiet Only show really necessary output, so surpress echoing the command. @@ -156,8 +157,9 @@ environment variables (for internal use): -f | --file) if [[ $# -gt 1 && -r "$2" || "-" == "$2" ]]; then ok_file="$2"; shift; else _ok_cmd_usage "No file provided, or file is not readable ($2)" || return $?; fi;; -a | --alias) if [[ $# -gt 1 && -n "$2" ]]; then args="$2"; shift; else _ok_cmd_usage "Empty or no alias provided" || return $?; fi;; #system options + -s | --summary) cmd=".list_named_commands";; --sys-cmds) cmd=".list_commands";; - --sys-opts) cmd=noop; echo "--version --help --verbose --quiet --comment-align --file --alias";; + --sys-opts) cmd=noop; echo "--version --help --verbose --quiet --comment-align --file --alias --summary";; -*) cmd=usage; usage_error="Illegal option '$1'";; *) if [[ $1 =~ $re_is_cmd ]]; then cmd=run