diff --git a/.editorconfig b/.editorconfig index 9e9506e..c25c645 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,7 @@ # Space or Tabs? # https://stackoverflow.com/questions/35649847/objective-reasons-for-using-spaces-instead-of-tabs-for-indentation # https://stackoverflow.com/questions/12093748/how-to-use-tabs-instead-of-spaces-in-a-shell-script +# https://github.com/editorconfig/editorconfig-defaults/blob/master/editorconfig-defaults.json # # 1. What happens when I press the Tab key in my text editor? # 2. What happens when I request my editor to indent one or more lines? @@ -57,302 +58,3 @@ indent_size = 4 [*.{cs,csx,cake,vb,vbx}] # Default Severity for all .NET Code Style rules below dotnet_analyzer_diagnostic.severity = warning - -# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#net-style-rules -[*.{cs,csx,cake,vb,vbx}] -# "this." and "Me." qualifiers -dotnet_style_qualification_for_field = true:warning -dotnet_style_qualification_for_property = true:warning -dotnet_style_qualification_for_method = true:warning -dotnet_style_qualification_for_event = true:warning -# Language keywords instead of framework type names for type references -dotnet_style_predefined_type_for_locals_parameters_members = true:warning -dotnet_style_predefined_type_for_member_access = true:warning -# Modifier preferences -dotnet_style_require_accessibility_modifiers = always:warning -csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:warning -visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:warning -dotnet_style_readonly_field = true:warning -# Parentheses preferences -dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_other_operators = never_if_unnecessary:warning -# Expression-level preferences -dotnet_style_object_initializer = true:warning -dotnet_style_collection_initializer = true:warning -dotnet_style_explicit_tuple_names = true:warning -dotnet_style_prefer_inferred_tuple_names = true:warning -dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning -dotnet_style_prefer_auto_properties = true:warning -dotnet_style_prefer_conditional_expression_over_assignment = false:suggestion -dotnet_diagnostic.IDE0045.severity = suggestion -dotnet_style_prefer_conditional_expression_over_return = false:suggestion -dotnet_diagnostic.IDE0046.severity = suggestion -dotnet_style_prefer_compound_assignment = true:warning -dotnet_style_prefer_simplified_interpolation = true:warning -dotnet_style_prefer_simplified_boolean_expressions = true:warning -# Null-checking preferences -dotnet_style_coalesce_expression = true:warning -dotnet_style_null_propagation = true:warning -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning -# File header preferences -# file_header_template = \n© PROJECT-AUTHOR\n -# If you use StyleCop, you'll need to disable SA1636: File header copyright text should match. -# dotnet_diagnostic.SA1636.severity = none -# Undocumented -dotnet_style_operator_placement_when_wrapping = end_of_line:warning -csharp_style_prefer_null_check_over_type_check = true:warning - -# C# Style Rules -# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#c-style-rules -[*.{cs,csx,cake}] -# 'var' preferences -csharp_style_var_for_built_in_types = true:warning -csharp_style_var_when_type_is_apparent = true:warning -csharp_style_var_elsewhere = true:warning -# Expression-bodied members -csharp_style_expression_bodied_methods = true:warning -csharp_style_expression_bodied_constructors = true:warning -csharp_style_expression_bodied_operators = true:warning -csharp_style_expression_bodied_properties = true:warning -csharp_style_expression_bodied_indexers = true:warning -csharp_style_expression_bodied_accessors = true:warning -csharp_style_expression_bodied_lambdas = true:warning -csharp_style_expression_bodied_local_functions = true:warning -# Pattern matching preferences -csharp_style_pattern_matching_over_is_with_cast_check = true:warning -csharp_style_pattern_matching_over_as_with_null_check = true:warning -csharp_style_prefer_switch_expression = true:warning -csharp_style_prefer_pattern_matching = true:warning -csharp_style_prefer_not_pattern = true:warning -# Expression-level preferences -csharp_style_inlined_variable_declaration = true:warning -csharp_prefer_simple_default_expression = true:warning -csharp_style_pattern_local_over_anonymous_function = true:warning -csharp_style_deconstructed_variable_declaration = true:warning -csharp_style_prefer_index_operator = true:warning -csharp_style_prefer_range_operator = true:warning -csharp_style_implicit_object_creation_when_type_is_apparent = true:warning -# "Null" checking preferences -csharp_style_throw_expression = true:warning -csharp_style_conditional_delegate_call = true:warning -# Code block preferences -csharp_prefer_braces = true:warning -csharp_prefer_simple_using_statement = true:suggestion -dotnet_diagnostic.IDE0063.severity = suggestion -# 'using' directive preferences -csharp_using_directive_placement = inside_namespace:warning -# Modifier preferences -csharp_prefer_static_local_function = true:warning - -# .NET Unnecessary code rules -[*.{cs,csx,cake,vb,vbx}] -dotnet_code_quality_unused_parameters = all:warning -dotnet_remove_unnecessary_suppression_exclusions = none:warning - -# C# Unnecessary code rules -[*.{cs,csx,cake}] -csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion -dotnet_diagnostic.IDE0058.severity = suggestion -csharp_style_unused_value_assignment_preference = discard_variable:suggestion -dotnet_diagnostic.IDE0059.severity = suggestion - -# .NET formatting rules -# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#net-formatting-rules -[*.{cs,csx,cake,vb,vbx}] -# Organize using directives -dotnet_sort_system_directives_first = true -dotnet_separate_import_directive_groups = false -# Dotnet namespace options -dotnet_style_namespace_match_folder = true:suggestion -dotnet_diagnostic.IDE0130.severity = suggestion - -# C# formatting rules -# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#c-formatting-rules -[*.{cs,csx,cake}] -# Newline options -# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#new-line-options -csharp_new_line_before_open_brace = all -csharp_new_line_before_else = true -csharp_new_line_before_catch = true -csharp_new_line_before_finally = true -csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_between_query_expression_clauses = true -# Indentation options -# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#indentation-options -csharp_indent_case_contents = true -csharp_indent_switch_labels = true -csharp_indent_labels = no_change -csharp_indent_block_contents = true -csharp_indent_braces = false -csharp_indent_case_contents_when_block = false -# Spacing options -# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#spacing-options -csharp_space_after_cast = false -csharp_space_after_keywords_in_control_flow_statements = true -csharp_space_between_parentheses = false -csharp_space_before_colon_in_inheritance_clause = true -csharp_space_after_colon_in_inheritance_clause = true -csharp_space_around_binary_operators = before_and_after -csharp_space_between_method_declaration_parameter_list_parentheses = false -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false -csharp_space_between_method_declaration_name_and_open_parenthesis = false -csharp_space_between_method_call_parameter_list_parentheses = false -csharp_space_between_method_call_empty_parameter_list_parentheses = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_after_comma = true -csharp_space_before_comma = false -csharp_space_after_dot = false -csharp_space_before_dot = false -csharp_space_after_semicolon_in_for_statement = true -csharp_space_before_semicolon_in_for_statement = false -csharp_space_around_declaration_statements = false -csharp_space_before_open_square_brackets = false -csharp_space_between_empty_square_brackets = false -csharp_space_between_square_brackets = false -# Wrap options -# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#wrap-options -csharp_preserve_single_line_statements = false -csharp_preserve_single_line_blocks = true -# Namespace options -# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#namespace-options -csharp_style_namespace_declarations = file_scoped:warning - -[*.{cs,csx,cake,vb,vbx}] - -# camel_case_style - Define the camelCase style -dotnet_naming_style.camel_case_style.capitalization = camel_case -# pascal_case_style - Define the PascalCase style -dotnet_naming_style.pascal_case_style.capitalization = pascal_case -# first_upper_style - The first character must start with an upper-case character -dotnet_naming_style.first_upper_style.capitalization = first_word_upper -# prefix_interface_with_i_style - Interfaces must be PascalCase and the first character of an interface must be an 'I' -dotnet_naming_style.prefix_interface_with_i_style.capitalization = pascal_case -dotnet_naming_style.prefix_interface_with_i_style.required_prefix = I -# prefix_type_parameters_with_t_style - Generic Type Parameters must be PascalCase and the first character must be a 'T' -dotnet_naming_style.prefix_type_parameters_with_t_style.capitalization = pascal_case -dotnet_naming_style.prefix_type_parameters_with_t_style.required_prefix = T -# disallowed_style - Anything that has this style applied is marked as disallowed -dotnet_naming_style.disallowed_style.capitalization = pascal_case -dotnet_naming_style.disallowed_style.required_prefix = ____RULE_VIOLATION____ -dotnet_naming_style.disallowed_style.required_suffix = ____RULE_VIOLATION____ -# internal_error_style - This style should never occur... if it does, it indicates a bug in file or in the parser using the file -dotnet_naming_style.internal_error_style.capitalization = pascal_case -dotnet_naming_style.internal_error_style.required_prefix = ____INTERNAL_ERROR____ -dotnet_naming_style.internal_error_style.required_suffix = ____INTERNAL_ERROR____ - -# All public/protected/protected_internal constant fields must be PascalCase -# https://docs.microsoft.com/dotnet/standard/design-guidelines/field -dotnet_naming_symbols.public_protected_constant_fields_group.applicable_accessibilities = public, protected, protected_internal -dotnet_naming_symbols.public_protected_constant_fields_group.required_modifiers = const -dotnet_naming_symbols.public_protected_constant_fields_group.applicable_kinds = field -dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.symbols = public_protected_constant_fields_group -dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.style = pascal_case_style -dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.severity = warning - -# All public/protected/protected_internal static readonly fields must be PascalCase -# https://docs.microsoft.com/dotnet/standard/design-guidelines/field -dotnet_naming_symbols.public_protected_static_readonly_fields_group.applicable_accessibilities = public, protected, protected_internal -dotnet_naming_symbols.public_protected_static_readonly_fields_group.required_modifiers = static, readonly -dotnet_naming_symbols.public_protected_static_readonly_fields_group.applicable_kinds = field -dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.symbols = public_protected_static_readonly_fields_group -dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.style = pascal_case_style -dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.severity = warning - -# No other public/protected/protected_internal fields are allowed -# https://docs.microsoft.com/dotnet/standard/design-guidelines/field -dotnet_naming_symbols.other_public_protected_fields_group.applicable_accessibilities = public, protected, protected_internal -dotnet_naming_symbols.other_public_protected_fields_group.applicable_kinds = field -dotnet_naming_rule.other_public_protected_fields_disallowed_rule.symbols = other_public_protected_fields_group -dotnet_naming_rule.other_public_protected_fields_disallowed_rule.style = disallowed_style -dotnet_naming_rule.other_public_protected_fields_disallowed_rule.severity = error - -# All constant fields must be PascalCase -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1303.md -dotnet_naming_symbols.stylecop_constant_fields_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected, private -dotnet_naming_symbols.stylecop_constant_fields_group.required_modifiers = const -dotnet_naming_symbols.stylecop_constant_fields_group.applicable_kinds = field -dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.symbols = stylecop_constant_fields_group -dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.style = pascal_case_style -dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.severity = warning - -# All static readonly fields must be PascalCase -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1311.md -dotnet_naming_symbols.stylecop_static_readonly_fields_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected, private -dotnet_naming_symbols.stylecop_static_readonly_fields_group.required_modifiers = static, readonly -dotnet_naming_symbols.stylecop_static_readonly_fields_group.applicable_kinds = field -dotnet_naming_rule.stylecop_static_readonly_fields_must_be_pascal_case_rule.symbols = stylecop_static_readonly_fields_group -dotnet_naming_rule.stylecop_static_readonly_fields_must_be_pascal_case_rule.style = pascal_case_style -dotnet_naming_rule.stylecop_static_readonly_fields_must_be_pascal_case_rule.severity = warning - -# No non-private instance fields are allowed -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1401.md -dotnet_naming_symbols.stylecop_fields_must_be_private_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected -dotnet_naming_symbols.stylecop_fields_must_be_private_group.applicable_kinds = field -dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.symbols = stylecop_fields_must_be_private_group -dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.style = disallowed_style -dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.severity = error - -# Private fields must be camelCase -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1306.md -dotnet_naming_symbols.stylecop_private_fields_group.applicable_accessibilities = private -dotnet_naming_symbols.stylecop_private_fields_group.applicable_kinds = field -dotnet_naming_rule.stylecop_private_fields_must_be_camel_case_rule.symbols = stylecop_private_fields_group -dotnet_naming_rule.stylecop_private_fields_must_be_camel_case_rule.style = camel_case_style -dotnet_naming_rule.stylecop_private_fields_must_be_camel_case_rule.severity = warning - -# Local variables must be camelCase -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1312.md -dotnet_naming_symbols.stylecop_local_fields_group.applicable_accessibilities = local -dotnet_naming_symbols.stylecop_local_fields_group.applicable_kinds = local -dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.symbols = stylecop_local_fields_group -dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.style = camel_case_style -dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.severity = silent - -# This rule should never fire. However, it's included for at least two purposes: -# First, it helps to understand, reason about, and root-case certain types of issues, such as bugs in .editorconfig parsers. -# Second, it helps to raise immediate awareness if a new field type is added (as occurred recently in C#). -dotnet_naming_symbols.sanity_check_uncovered_field_case_group.applicable_accessibilities = * -dotnet_naming_symbols.sanity_check_uncovered_field_case_group.applicable_kinds = field -dotnet_naming_rule.sanity_check_uncovered_field_case_rule.symbols = sanity_check_uncovered_field_case_group -dotnet_naming_rule.sanity_check_uncovered_field_case_rule.style = internal_error_style -dotnet_naming_rule.sanity_check_uncovered_field_case_rule.severity = error - -# All of the following must be PascalCase: -# - Namespaces -# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-namespaces -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1300.md -# - Classes and Enumerations -# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1300.md -# - Delegates -# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces#names-of-common-types -# - Constructors, Properties, Events, Methods -# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-type-members -dotnet_naming_symbols.element_group.applicable_kinds = namespace, class, enum, struct, delegate, event, method, property -dotnet_naming_rule.element_rule.symbols = element_group -dotnet_naming_rule.element_rule.style = pascal_case_style -dotnet_naming_rule.element_rule.severity = warning - -# Interfaces use PascalCase and are prefixed with uppercase 'I' -# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces -dotnet_naming_symbols.interface_group.applicable_kinds = interface -dotnet_naming_rule.interface_rule.symbols = interface_group -dotnet_naming_rule.interface_rule.style = prefix_interface_with_i_style -dotnet_naming_rule.interface_rule.severity = warning - -# Generics Type Parameters use PascalCase and are prefixed with uppercase 'T' -# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces -dotnet_naming_symbols.type_parameter_group.applicable_kinds = type_parameter -dotnet_naming_rule.type_parameter_rule.symbols = type_parameter_group -dotnet_naming_rule.type_parameter_rule.style = prefix_type_parameters_with_t_style -dotnet_naming_rule.type_parameter_rule.severity = warning - -# Function parameters use camelCase -# https://docs.microsoft.com/dotnet/standard/design-guidelines/naming-parameters -dotnet_naming_symbols.parameters_group.applicable_kinds = parameter -dotnet_naming_rule.parameters_rule.symbols = parameters_group -dotnet_naming_rule.parameters_rule.style = camel_case_style -dotnet_naming_rule.parameters_rule.severity = warning diff --git a/.github/workflows/zsh-n.yml b/.github/workflows/zsh-n.yml new file mode 100644 index 0000000..72c2666 --- /dev/null +++ b/.github/workflows/zsh-n.yml @@ -0,0 +1,57 @@ +--- +name: "✅ Zsh" +on: + push: + paths: + - "**/*.ch" + - "**/*.zsh" + - "tests/*" + - "share/*" + - "themes/*" + - "functions/*" + pull_request: + paths: + - "**/*.ch" + - "**/*.zsh" + - "tests/*" + - "share/*" + - "themes/*" + - "functions/*" + workflow_dispatch: {} + +jobs: + zsh-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: ⤵️ Check out code from GitHub + uses: actions/checkout@v3 + - name: "⚡ Set matrix output" + id: set-matrix + run: | + MATRIX="$(find . -type d -name 'doc' -prune -o -type f \( -iname '*.zsh' -o -iname '*.ch' -o -iname 'fast-*' \) -print | jq -ncR '{"include": [{"file": inputs}]}')" + echo "MATRIX=${MATRIX}" >&2 + echo "matrix=${MATRIX}" >> $GITHUB_OUTPUT + zsh-n: + runs-on: ubuntu-latest + needs: zsh-matrix + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.zsh-matrix.outputs.matrix) }} + steps: + - name: ⤵️ Check out code from GitHub + uses: actions/checkout@v3 + - name: "⚡ Install dependencies" + run: sudo apt update && sudo apt-get install -yq zsh + - name: "⚡ zsh -n: ${{ matrix.file }}" + env: + ZSH_FILE: ${{ matrix.file }} + run: | + zsh -n "${ZSH_FILE}" + - name: "⚡ zcompile ${{ matrix.file }}" + env: + ZSH_FILE: ${{ matrix.file }} + run: | + zsh -fc "zcompile ${ZSH_FILE}"; rc=$? + ls -al "${ZSH_FILE}.zwc"; exit "$rc" diff --git a/.github/workflows/zunit.yml b/.github/workflows/zunit.yml index 4c8304c..78d107d 100644 --- a/.github/workflows/zunit.yml +++ b/.github/workflows/zunit.yml @@ -4,9 +4,21 @@ name: 🛡️ ZUnit on: workflow_dispatch: push: - branches: ["main", "develop"] + paths: + - "**/*.ch" + - "**/*.zsh" + - "tests/*" + - "share/*" + - "themes/*" + - "functions/*" pull_request_target: - branches: ["main", "develop"] + paths: + - "**/*.ch" + - "**/*.zsh" + - "tests/*" + - "share/*" + - "themes/*" + - "functions/*" jobs: build-macos: diff --git a/.gitignore b/.gitignore index 7fda70a..6711d38 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ test/res hold/* *.zwc ._zi +out.parse ### Vim # Swap diff --git a/.trunk/.gitignore b/.trunk/.gitignore index 507283d..cf2f254 100644 --- a/.trunk/.gitignore +++ b/.trunk/.gitignore @@ -1,3 +1,7 @@ *out *logs -external +*actions +*notifications +plugins +user_trunk.yaml +user.yaml diff --git a/.github/.markdownlint.yaml b/.trunk/configs/.markdownlint.yaml similarity index 94% rename from .github/.markdownlint.yaml rename to .trunk/configs/.markdownlint.yaml index 465a928..fb94039 100644 --- a/.github/.markdownlint.yaml +++ b/.trunk/configs/.markdownlint.yaml @@ -8,4 +8,3 @@ line_length: false spaces: false url: false whitespace: false -MD041: false diff --git a/.trunk/configs/.shellcheckrc b/.trunk/configs/.shellcheckrc new file mode 100644 index 0000000..8c7b1ad --- /dev/null +++ b/.trunk/configs/.shellcheckrc @@ -0,0 +1,7 @@ +enable=all +source-path=SCRIPTDIR +disable=SC2154 + +# If you're having issues with shellcheck following source, disable the errors via: +# disable=SC1090 +# disable=SC1091 diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index f256861..60c6f16 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,25 +1,32 @@ version: 0.1 cli: - version: 0.15.1-beta -repo: - repo: - host: github.com - owner: z-shell - name: F-Sy-H + version: 1.3.2 +plugins: + sources: + - id: trunk + ref: v0.0.8 + uri: https://github.com/trunk-io/plugins lint: - linters: - - name: markdownlint - command: - [markdownlint, -q, --config, .github/.markdownlint.yaml, "${target}"] - direct_configs: [.github/.markdownlint.yaml] enabled: - - git-diff-check@SYSTEM - - actionlint@1.6.15 - - gitleaks@8.9.0 - - markdownlint@0.32.1 - - prettier@2.7.1 + - gitleaks@8.15.3 + - shellcheck@0.9.0 + - git-diff-check + - actionlint@1.6.23 - shfmt@3.5.0 + - markdownlint@0.33.0 + - oxipng@8.0.0 + - prettier@2.8.3 ignore: - linters: [ALL] paths: - "share/test/**" +runtimes: + enabled: + - go@1.18.3 + - node@18.12.1 +actions: + enabled: + - trunk-announce + - trunk-check-pre-push + - trunk-fmt-pre-commit + - trunk-upgrade-available diff --git a/.vscode/settings.json b/.vscode/settings.json index 5081fb3..dad4de1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,11 +1,8 @@ { - "conventionalCommits.scopes": [ - "maintenance", - "workspace", - "general", - "theme" - ], - "markdownlint.config": { - "extends": ".github/.markdownlint.yaml" + "files.associations": { + "*za-*": "shellscript", + ".ch": "shellscript", + "fast-*": "shellscript", + ".fast-*": "shellscript" } } diff --git a/.zunit.yml b/.zunit.yml index e4fd57f..984fc97 100644 --- a/.zunit.yml +++ b/.zunit.yml @@ -1,8 +1,6 @@ tap: false directories: tests: tests - output: tests/_output - support: tests/_support time_limit: 0 fail_fast: false allow_risky: false diff --git a/F-Sy-H.plugin.zsh b/F-Sy-H.plugin.zsh old mode 100644 new mode 100755 index 3acb789..1b1415c --- a/F-Sy-H.plugin.zsh +++ b/F-Sy-H.plugin.zsh @@ -26,51 +26,46 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- - - -# Standarized way of handling finding plugin dir, +# +# Standardized way of handling finding plugin dir, # regardless of functionargzero and posixargzero, # and with an option for a plugin manager to alter # the plugin directory (i.e. set ZERO parameter) # # Standardized $0 Handling -# https://z.digitalclouds.dev/community/zsh_plugin_standard#zero-handling +# https://wiki.zshell.dev/community/zsh_plugin_standard#zero-handling 0="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}" 0="${${(M)0:#/*}:-$PWD/$0}" -typeset -g FAST_HIGHLIGHT_VERSION=1.66 -typeset -g FAST_BASE_DIR="${0:h}" -typeset -ga _FAST_MAIN_CACHE -# Holds list of indices pointing at brackets that -# are complex, i.e. e.g. part of "[[" in [[ ... ]] -typeset -ga _FAST_COMPLEX_BRACKETS - # Functions Directory -# https://z.digitalclouds.dev/community/zsh_plugin_standard#funtions-directory +# https://wiki.zshell.dev/community/zsh_plugin_standard#funtions-directory if [[ $PMSPEC != *f* ]]; then fpath+=( "${0:h}/functions" ) fi -# Check if Zsh's cache directory exist. -if [[ -d $ZSH_CACHE_DIR ]]; then - # Use Zsh's default cache directory. - typeset -g FAST_WORK_DIR=${FAST_WORK_DIR:-${ZSH_CACHE_DIR}/fsh} -else - # Use common values to set default working directory. - typeset -g FAST_WORK_DIR=${FAST_WORK_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/fsh} -fi +# Default global variables +typeset -g FAST_HIGHLIGHT_VERSION=1.67 +typeset -g FAST_BASE_DIR="${0:h}" +typeset -ga _FAST_MAIN_CACHE +# Holds list of indices pointing at brackets that are complex, i.e. e.g. part of "[[" in [[ ... ]] +typeset -ga _FAST_COMPLEX_BRACKETS + +# Allow user to override the working directory, +# but default to $XDG_CACHE_HOME/f-sy-h and fall back to $FAST_BASE_DIR. +typeset -g FAST_WORK_DIR=${FAST_WORK_DIR:-${XDG_CACHE_HOME:-~/.cache}/f-sy-h} : ${FAST_WORK_DIR:=$FAST_BASE_DIR} -# Expand any tilde in the (supposed) path. FAST_WORK_DIR=${~FAST_WORK_DIR} # Create working directory if it doesn't exist. -[[ -w $FAST_WORK_DIR ]] || command mkdir -p "$FAST_WORK_DIR" +[[ -w $FAST_WORK_DIR ]] || command mkdir -p "$FAST_WORK_DIR" || { + print -u2 "f-sy-h: cannot create working directory $FAST_WORK_DIR" + return 1 +} # Invokes each highlighter that needs updating. # This function is supposed to be called whenever the ZLE state changes. -_zsh_highlight() -{ +_zsh_highlight() { # Store the previous command return code to restore it whatever happens. local ret=$? @@ -81,8 +76,8 @@ _zsh_highlight() return $ret fi - emulate -LR zsh - setopt extendedglob warncreateglobal typesetsilent noshortloops + builtin emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace} + builtin setopt extended_glob typeset_silent no_short_loops rc_quotes no_auto_pushd local REPLY # don't leak $REPLY into global scope local -a reply @@ -141,13 +136,16 @@ _zsh_highlight() fi # yank / paste (zsh-5.1.1 and newer) - (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END" + (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && \ + _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END" # isearch - (( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END" + (( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && \ + _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END" # suffix - (( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END" + (( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && \ + _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END" return $ret @@ -202,16 +200,16 @@ _zsh_highlight_apply_zle_highlight() { # Whether the command line buffer has been modified or not. # # Returns 0 if the buffer has changed since _zsh_highlight was last called. -_zsh_highlight_buffer_modified() -{ - [[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]] || [[ "$REGION_ACTIVE" != "$_ZSH_HIGHLIGHT_PRIOR_RACTIVE" ]] || { _zsh_highlight_cursor_moved && [[ "$REGION_ACTIVE" = 1 || "$REGION_ACTIVE" = 2 ]] } +_zsh_highlight_buffer_modified() { + [[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]] || \ + [[ "$REGION_ACTIVE" != "$_ZSH_HIGHLIGHT_PRIOR_RACTIVE" ]] || \ + { _zsh_highlight_cursor_moved && [[ "$REGION_ACTIVE" = 1 || "$REGION_ACTIVE" = 2 ]] } } # Whether the cursor has moved or not. # # Returns 0 if the cursor has moved since _zsh_highlight was last called. -_zsh_highlight_cursor_moved() -{ +_zsh_highlight_cursor_moved() { [[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR)) } @@ -221,8 +219,7 @@ _zsh_highlight_cursor_moved() # Helper for _zsh_highlight_bind_widgets # $1 is name of widget to call -_zsh_highlight_call_widget() -{ +_zsh_highlight_call_widget() { integer ret builtin zle "$@" ret=$? @@ -231,15 +228,14 @@ _zsh_highlight_call_widget() } # Rebind all ZLE widgets to make them invoke _zsh_highlights. -_zsh_highlight_bind_widgets() -{ - setopt localoptions noksharrays +_zsh_highlight_bind_widgets() { + builtin setopt local_options no_ksh_arrays local -F2 SECONDS local prefix=orig-s${SECONDS/./}-r$(( RANDOM % 1000 )) # unique each time, in case we're sourced more than once # Load ZSH module zsh/zleparameter, needed to override user defined widgets. zmodload zsh/zleparameter 2>/dev/null || { - print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' + builtin print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' return 1 } @@ -290,7 +286,7 @@ _zsh_highlight_bind_widgets() zle -N -- $cur_widget _zsh_highlight_widget_$cur_widget else # Default: unhandled case. - print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}" + builtin print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}" fi esac done @@ -302,13 +298,12 @@ _zsh_highlight_bind_widgets() # Try binding widgets. _zsh_highlight_bind_widgets || { - print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.' + builtin print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.' return 1 } -# Reset scratch variables when commandline is done. -_zsh_highlight_preexec_hook() -{ +# Reset scratch variables when command line is done. +_zsh_highlight_preexec_hook() { typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER= typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=0 typeset -ga _FAST_MAIN_CACHE @@ -317,35 +312,65 @@ _zsh_highlight_preexec_hook() autoload -Uz add-zsh-hook add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || { - print -r -- >&2 'zsh-syntax-highlighting: failed loading add-zsh-hook.' + builtin print -r -- >&2 'zsh-syntax-highlighting: failed loading add-zsh-hook.' } -/fshdbg() { - print -r -- "$@" >>! /tmp/reply +/f-sy-h-debug() { + builtin print -r -- "$@" >>! /tmp/reply } -ZSH_HIGHLIGHT_MAXLENGTH=10000 +typeset -g ZSH_HIGHLIGHT_MAXLENGTH=10000 # Load zsh/parameter module if available zmodload zsh/parameter 2>/dev/null zmodload zsh/system 2>/dev/null -autoload -Uz -- is-at-least fast-theme \ +autoload -Uz -- is-at-least \ .fast-read-ini-file .fast-run-git-command \ .fast-make-targets .fast-run-command .fast-zts-read-all -autoload -Uz -- →chroma/-git.ch →chroma/-hub.ch →chroma/-lab.ch →chroma/-example.ch \ - →chroma/-grep.ch →chroma/-perl.ch →chroma/-make.ch →chroma/-awk.ch \ - →chroma/-vim.ch →chroma/-source.ch →chroma/-sh.ch →chroma/-docker.ch \ - →chroma/-autoload.ch →chroma/-ssh.ch →chroma/-scp.ch →chroma/-which.ch \ - →chroma/-printf.ch →chroma/-ruby.ch →chroma/-whatis.ch →chroma/-alias.ch \ - →chroma/-subcommand.ch →chroma/-autorandr.ch →chroma/-nmcli.ch \ - →chroma/-fast-theme.ch →chroma/-node.ch →chroma/-fpath_peq.ch \ - →chroma/-precommand.ch →chroma/-subversion.ch →chroma/-ionice.ch \ - →chroma/-nice.ch →chroma/main-chroma.ch →chroma/-ogit.ch →chroma/-zi.ch +# Disabled: chroma/-vim.ch chroma/-which.ch +autoload -Uz -- \ + chroma/-alias.ch \ + chroma/-autoload.ch \ + chroma/-autorandr.ch \ + chroma/-awk.ch \ + chroma/-docker.ch \ + chroma/-fpath_peq.ch \ + chroma/-git.ch \ + chroma/-grep.ch \ + chroma/-hub.ch \ + chroma/-ionice.ch \ + chroma/-lab.ch \ + chroma/-make.ch \ + chroma/-nice.ch \ + chroma/-nmcli.ch \ + chroma/-node.ch \ + chroma/-ogit.ch \ + chroma/-perl.ch \ + chroma/-precommand.ch \ + chroma/-printf.ch \ + chroma/-ruby.ch \ + chroma/-scp.ch \ + chroma/-sh.ch \ + chroma/-source.ch \ + chroma/-ssh.ch \ + chroma/-subcommand.ch \ + chroma/-subversion.ch \ + chroma/-whatis.ch \ + chroma/-zi.ch \ + chroma/main-chroma.ch + +if (( FAST_THEME_MANAGER_DISABLED )) { + unset '_comps[fast-theme]' 2>/dev/null + unset -f chroma/-fast-theme.ch 2>/dev/null +} else { + autoload -Uz -- fast-theme chroma/-fast-theme.ch chroma/-example.ch + alias f-sy-h=fast-theme +} -source "${0:h}/fast-highlight" -source "${0:h}/fast-string-highlight" +source "${0:h}/functions/fast-highlight" +source "${0:h}/functions/fast-string-highlight" local __fsyh_theme zstyle -s :plugin:fast-syntax-highlighting theme __fsyh_theme @@ -367,25 +392,17 @@ zstyle -s :plugin:fast-syntax-highlighting theme __fsyh_theme unset __fsyh_theme -alias fsh-alias=fast-theme - -fast-highlight-fill-option-variables + if [[ ! -e $FAST_WORK_DIR/secondary_theme.zsh ]] { + local theme_link=https://raw.githubusercontent.com/z-shell/F-Sy-H/main/share/free_theme.zsh if { type curl &>/dev/null } { - curl -fsSL -o "$FAST_WORK_DIR/secondary_theme.zsh" \ - https://raw.githubusercontent.com/z-shell/F-Sy-H/main/share/free_theme.zsh \ - &>/dev/null + command curl -fsSL -o "$FAST_WORK_DIR/secondary_theme.zsh" $theme_link &>/dev/null } elif { type wget &>/dev/null } { - wget -O "$FAST_WORK_DIR/secondary_theme.zsh" \ - https://raw.githubusercontent.com/z-shell/F-Sy-H/main/share/free_theme.zsh \ - &>/dev/null + command wget -O "$FAST_WORK_DIR/secondary_theme.zsh" $theme_link &>/dev/null } touch "$FAST_WORK_DIR/secondary_theme.zsh" -} - -if [[ $(uname -a) = (#i)*darwin* ]] { - typeset -gA FAST_HIGHLIGHT - FAST_HIGHLIGHT[chroma-man]= + unset theme_link } [[ $COLORTERM == (24bit|truecolor) || ${terminfo[colors]} -eq 16777216 ]] || zmodload zsh/nearcolor &>/dev/null || true diff --git "a/\342\206\222chroma/-alias.ch" b/chroma/-alias.ch old mode 100644 new mode 100755 similarity index 100% rename from "\342\206\222chroma/-alias.ch" rename to chroma/-alias.ch index 91462d0..e10edc5 --- "a/\342\206\222chroma/-alias.ch" +++ b/chroma/-alias.ch @@ -1,5 +1,7 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # + (( next_word = 2 | 8192 )) [[ "$__arg_type" = 3 ]] && return 2 @@ -28,5 +30,3 @@ fi _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git a/chroma/-autoload.ch b/chroma/-autoload.ch new file mode 100755 index 0000000..fccb74d --- /dev/null +++ b/chroma/-autoload.ch @@ -0,0 +1,103 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# +# Tracks autoload command - highlights function names if they exist somewhere +# in $fpath. Also warns that the autoload function is already defined. +# +# $1 - 0 or 1, denoting if it's first call to the chroma, or following one +# +# $2 - the current token, also accessible by $__arg from the above scope - +# basically a private copy of $__arg; the token can be eg.: "grep" +# +# $3 - a private copy of $_start_pos, i.e. the position of the token in the +# command line buffer, used to add region_highlight entry (see man), +# because Zsh colorizes by *ranges* in command line buffer +# +# $4 - a private copy of $_end_pos from the above scope +# + +(( next_word = 2 | 8192 )) + +local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" +local __style __chars +integer __idx1 __idx2 +local -a __results __deserialized __noshsplit + +# First call, i.e. command starts, i.e. "grep" token etc. +(( __first_call )) && { + FAST_HIGHLIGHT[chroma-autoload-counter]=0 + FAST_HIGHLIGHT[chroma-autoload-counter-all]=1 + FAST_HIGHLIGHT[chroma-autoload-message]="" + #FAST_HIGHLIGHT[chroma-autoload-message-shown]="" + [[ -z ${FAST_HIGHLIGHT[chroma-autoload-message-shown-at]} ]] && FAST_HIGHLIGHT[chroma-autoload-message-shown-at]=0 + FAST_HIGHLIGHT[chroma-autoload-elements]="" + __style=${FAST_THEME_NAME}command + +} || { + if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then + return 1 + fi + (( FAST_HIGHLIGHT[chroma-autoload-counter-all] += 1, __idx2 = FAST_HIGHLIGHT[chroma-autoload-counter-all] )) + + # Following call, i.e. not the first one. + + # Check if chroma should end – test if token is of type + # "starts new command", if so pass-through – chroma ends + [[ "$__arg_type" = 3 ]] && return 2 + + if [[ "$__wrd" = [-+]* ]]; then + # Detected option, add style for it. + [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ + __style=${FAST_THEME_NAME}single-hyphen-option + else + # Count non-option tokens. + (( FAST_HIGHLIGHT[chroma-autoload-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-autoload-counter] )) + + if [[ $__wrd != (\$|\"\$)* && $__wrd != (/|\"/|\'/)* && $__wrd != \`* ]]; then + __results=( ${^fpath}/$__wrd(N) ) + __deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-fpath_peq-elements]}}" ) + __results+=( ${^__deserialized}/$__wrd(N) ) + [[ "${#__results}" -gt 0 ]] && { + __style=${FAST_THEME_NAME}correct-subtle + __deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-autoload-elements]}}" ) + [[ -z "${__deserialized[1]}" && ${#__deserialized} -eq 1 ]] && __deserialized=() + # Cannot use ${abc:+"$abc"} trick with ${~...}, so handle most + # cases of the possible shwordsplit through an additional array + __noshsplit=( ${~__wrd} ) + __deserialized+=( "${(j: :)__noshsplit}" ) + FAST_HIGHLIGHT[chroma-autoload-elements]="${(j: :)${(q@)__deserialized}}" + # Make the function defined for big-loop's *main-type mechanism + __fast_highlight_main__command_type_cache[${(j: :)__noshsplit}]="function" + } || __style=${FAST_THEME_NAME}incorrect-subtle + fi + + if (( ${+functions[${(Q)__wrd}]} )); then + FAST_HIGHLIGHT[chroma-autoload-message]+="Warning: Function ${(Q)__wrd} already defined (e.g. loaded)"$'\n' + fi + fi + + # Display only when processing last autoload argument + if (( ${#${(z)BUFFER}} == FAST_HIGHLIGHT[chroma-autoload-counter-all] )); then + # Display only if already shown message differs or when it timeouts + if [[ ${FAST_HIGHLIGHT[chroma-autoload-message]} != ${FAST_HIGHLIGHT[chroma-autoload-message-shown]} || \ + $(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-autoload-message-shown-at] )) -gt 7 ]]; then + FAST_HIGHLIGHT[chroma-autoload-message-shown]=${FAST_HIGHLIGHT[chroma-autoload-message]} + FAST_HIGHLIGHT[chroma-autoload-message-shown-at]=$EPOCHSECONDS + zle -M "${FAST_HIGHLIGHT[chroma-autoload-message]}" + fi + fi +} + +# Add region_highlight entry (via `reply' array). +# +# This is a common place of adding such entry, but any above code +# can do it itself and skip setting __style to disable this code. +[[ -n "$__style" ]] && \ + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ + reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") + +# We aren't passing-through (no return 1 occurred), do obligatory things ourselves. +(( this_word = next_word )) +_start_pos=$_end_pos + +return 0 diff --git a/chroma/-autorandr.ch b/chroma/-autorandr.ch new file mode 100755 index 0000000..4ba4e0b --- /dev/null +++ b/chroma/-autorandr.ch @@ -0,0 +1,24 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et + +(( next_word = 2 | 8192 )) +[[ "$__arg_type" = 3 ]] && return 2 + +local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" + +if (( __first_call )) || [[ "$__wrd" = -* ]]; then + return 1 +else + if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then + return 1 + fi + if [[ -d "${XDG_CONFIG_HOME:-$HOME/.config}/autorandr/$__wrd" ]] then + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ + && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") + fi +fi + +(( this_word = next_word )) +_start_pos=$_end_pos + +return 0 diff --git a/chroma/-awk.ch b/chroma/-awk.ch new file mode 100755 index 0000000..afcfd89 --- /dev/null +++ b/chroma/-awk.ch @@ -0,0 +1,106 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# +# $1 - 0 or 1, denoting if it's first call to the chroma, or following one +# +# $2 - the current token, also accessible by $__arg from the above scope - +# basically a private copy of $__arg; the token can be eg.: "grep" +# +# $3 - a private copy of $_start_pos, i.e. the position of the token in the +# command line buffer, used to add region_highlight entry (see man), +# because Zsh colorizes by *ranges* in command line buffer +# +# $4 - a private copy of $_end_pos from the above scope +# + +(( next_word = 2 | 8192 )) + +local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" +local __style __chars __val __style2 +integer __idx1 __idx2 + +# First call, i.e. command starts, i.e. "grep" token etc. +(( __first_call )) && { + FAST_HIGHLIGHT[chroma-awk-counter]=0 + FAST_HIGHLIGHT[chroma-awk-f-seen]=0 + return 1 +} || { + # Following call, i.e. not the first one. + + if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then + return 1 + fi + + # Check if chroma should end – test if token is of type + # "starts new command", if so pass-through – chroma ends + [[ "$__arg_type" = 3 ]] && return 2 + + if [[ "$__wrd" = -* ]]; then + # Detected option, add style for it. + [[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ + __style=${FAST_THEME_NAME}single-hyphen-option + [[ "$__wrd" = "-f" ]] && FAST_HIGHLIGHT[chroma-awk-f-seen]=1 + else + # Count non-option tokens. + (( FAST_HIGHLIGHT[chroma-awk-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-awk-counter] )) + + # First non-option token is the pattern (regex), we will + # highlight it. + if (( FAST_HIGHLIGHT[chroma-awk-counter] == 1 && FAST_HIGHLIGHT[chroma-awk-f-seen] == 0 )); then + if print -r -- "${(Q)__wrd}" | gawk --source 'BEGIN { exit } END { exit 0 }' -f - >/dev/null 2>&1; then + __style2="${FAST_THEME_NAME}subtle-bg" + else + __style2="${FAST_THEME_NAME}incorrect-subtle" + fi + + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ + reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style2]}") + + # Highlight keywords + FSH_LIST=() + : "${__wrd//(#m)(BEGIN|END|FIELDWIDTHS|RS|ARGC|ARGV|ENVIRON|NF|NR|IGNORECASE|FILENAME|if|then|else|while|toupper|tolower|function|print|sub)/$(( fsh_sy_h_append($MBEGIN, $MEND) ))}"; + for __val in "${FSH_LIST[@]}" ; do + [[ ${__wrd[${__val%%;;*}]} = [a-zA-Z0-9_] || ${__wrd[${__val##*;;}+1]} = [a-zA-Z0-9_] ]] && continue + __idx1=$(( __start_pos + ${__val%%;;*} )) + __idx2=__idx1+${__val##*;;}-${__val%%;;*}+1 + (( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}-1, __start >= 0 )) && \ + reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}reserved-word]},${FAST_HIGHLIGHT_STYLES[$__style2]}") + done + + # Highlight regex characters + __chars="*+\\)(\{\}[]^" + __idx1=__start_pos + __idx2=__start_pos + while [[ "$__wrd" = (#b)[^$__chars]#([\\][\\])#((+|\*|\[|\]|\)|\(|\^|\}|\{)|[\\](+|\*|\[|\]|\)|\(|\^|\{|\}))(*) ]]; do + if [[ -n "${match[3]}" ]]; then + __idx1+=${mbegin[3]}-1 + __idx2=__idx1+${mend[3]}-${mbegin[3]}+1 + (( __start=__idx1-${#PREBUFFER}, __end=__idx2-${#PREBUFFER}, __start >= 0 )) && \ + reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]},${FAST_HIGHLIGHT_STYLES[$__style2]}") + __idx1=__idx2 + else + __idx1+=${mbegin[5]}-1 + fi + __wrd="${match[5]}" + done + elif (( FAST_HIGHLIGHT[chroma-awk-counter] >= 2 || FAST_HIGHLIGHT[chroma-awk-f-seen] == 1 )); then + FAST_HIGHLIGHT[chroma-awk-f-seen]=0 + # Handle paths, etc. normally - just pass-through to the big + # highlighter (the main f-sy-h highlighter, used before chromas). + return 1 + fi +fi +} + +# Add region_highlight entry (via `reply' array). +# +# This is a common place of adding such entry, but any above +# code can do it itself (and it does) and skip setting __style +# to disable this code. +[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") + +# We aren't passing-through (no return 1 occurred), do obligatory things ourselves. +(( this_word = next_word )) +_start_pos=$_end_pos + +return 0 diff --git "a/\342\206\222chroma/-docker.ch" b/chroma/-docker.ch old mode 100644 new mode 100755 similarity index 99% rename from "\342\206\222chroma/-docker.ch" rename to chroma/-docker.ch index 25994b4..c418a6b --- "a/\342\206\222chroma/-docker.ch" +++ b/chroma/-docker.ch @@ -1,4 +1,5 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # # Chroma function for command `docker'. It verifies command line, by denoting # wrong and good arguments by color. Currently implemented: verification of @@ -56,7 +57,6 @@ local -a __lines_list if [[ "${FAST_HIGHLIGHT[chroma-docker-subcommand]}" = "image" ]]; then [[ "$__wrd" != -* ]] && { (( FAST_HIGHLIGHT[chroma-docker-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-docker-counter] )) - if (( __idx1 == 2 )); then __style=${FAST_THEME_NAME}subcommand elif (( __idx1 == 3 )); then @@ -85,5 +85,3 @@ local -a __lines_list _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-example.ch" b/chroma/-example.ch old mode 100644 new mode 100755 similarity index 91% rename from "\342\206\222chroma/-example.ch" rename to chroma/-example.ch index e171fe8..50e0c36 --- "a/\342\206\222chroma/-example.ch" +++ b/chroma/-example.ch @@ -2,7 +2,7 @@ # # Example chroma function. It colorizes first two arguments as `builtin' style, # third and following arguments as `globbing' style. First two arguments may -# be "strings", they will be passed through to normal higlighter (by returning 1). +# be "strings", they will be passed through to normal highlighter (by returning 1). # # $1 - 0 or 1, denoting if it's first call to the chroma, or following one # @@ -16,10 +16,10 @@ # $4 - a private copy of $_end_pos from the above scope # # -# Overall functioning is: when command "example" is occured, this function +# Overall functioning is: when command "example" is occurred, this function # is called with $1 == 1, it ("example") is the first token ($2), then for any # following token, this function is called with $1 == 0, until end of command -# is occured (i.e. till enter is pressed or ";" is put into source, or the +# is occurred (i.e. till enter is pressed or ";" is put into source, or the # command line simply ends). # # Other tips are: @@ -38,7 +38,7 @@ # Remember to reset the hash and others at __first_call == 1, so that you have # a fresh state for new command. -# Keep chroma-takever state meaning: until ;, handle highlighting via chroma. +# Keep chroma-takeover state meaning: until ;, handle highlighting via chroma. # So the below 8192 assignment takes care that next token will be routed to chroma. (( next_word = 2 | 8192 )) @@ -83,7 +83,7 @@ integer __idx1 __idx2 # Colorize 1..2 as builtin, 3.. as glob if (( FAST_HIGHLIGHT[chroma-example-counter] <= 2 )); then if [[ "$__wrd" = \"* ]]; then - # Pass through, fsh main code will do the highlight! + # Pass through, f-sy-h main code will do the highlight! return 1 else __style=${FAST_THEME_NAME}builtin @@ -106,7 +106,7 @@ integer __idx1 __idx2 [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") # We aren't passing-through, do obligatory things ourselves. -# _start_pos=$_end_pos advainces pointers in command line buffer. +# _start_pos=$_end_pos advances pointers in command line buffer. # # To pass through means to `return 1'. The highlighting of # this single token is then done by fast-syntax-highlighting's diff --git a/chroma/-fast-theme.ch b/chroma/-fast-theme.ch new file mode 100755 index 0000000..1cc918b --- /dev/null +++ b/chroma/-fast-theme.ch @@ -0,0 +1,43 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et + +(( next_word = 2 | 8192 )) +[[ "$__arg_type" = 3 ]] && return 2 + +local __first_call="$1" __wrd="${(Q)2}" __start_pos="$3" __end_pos="$4" +local __style + +if (( __first_call )); then + FAST_HIGHLIGHT[chroma-fast-theme-first]=0 + return 1 +elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then + return 1 +elif (( ${FAST_HIGHLIGHT[chroma-fast-theme-first]} )) || [[ $__wrd = -* ]]; then + return 1 +else + FAST_HIGHLIGHT[chroma-fast-theme-first]=1 +fi + +if [[ "$__wrd" = */* || "$__wrd" = (CONFIG|CACHE|LOCAL|HOME|OPT):* ]]; then + __wrd="${${__wrd/(#s)CONFIG:/${${XDG_CONFIG_HOME:-$HOME/.config}%/}/f-sy-h/}%.ini}.ini" + __wrd="${${__wrd/(#s)CACHE:/${${XDG_CACHE_HOME:-$HOME/.cache}%/}/f-sy-h/}%.ini}.ini" + __wrd="${${__wrd/(#s)LOCAL://usr/local/share/f-sy-h/}%.ini}.ini" + __wrd="${${__wrd/(#s)HOME:/$HOME/.f-sy-h/}%.ini}.ini" + __wrd="${${__wrd/(#s)OPT://opt/local/share/f-sy-h/}%.ini}.ini" + __wrd=${~__wrd} # allow user to quote ~ +else + __wrd="$FAST_BASE_DIR/themes/$__wrd.ini" +fi + +if [[ -f $__wrd ]]; then + __style=${FAST_THEME_NAME}path +else + __style=${FAST_THEME_NAME}incorrect-subtle +fi + +(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ + && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") +(( this_word = next_word )) +_start_pos=$_end_pos + +return 0 diff --git "a/\342\206\222chroma/-fpath_peq.ch" b/chroma/-fpath_peq.ch old mode 100644 new mode 100755 similarity index 93% rename from "\342\206\222chroma/-fpath_peq.ch" rename to chroma/-fpath_peq.ch index 149df8c..de08465 --- "a/\342\206\222chroma/-fpath_peq.ch" +++ b/chroma/-fpath_peq.ch @@ -1,14 +1,15 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # # This chroma does a narrow, obscure but prestigious parsing of fpath+=( elem1 # elem2 ... ) construct to provide *the* *future* contents of $fpath to # -autoload.ch, so that it can detect functions in those provided directories # `elem1', `elem2', etc. and highlight the functions with `correct-subtle' -# instead of `incorrect-subtle'. Basically all thit is for command-lines like: +# instead of `incorrect-subtle'. Basically all this is for command-lines like: # # % fpath+=( `pwd` ); autoload my-fun-from-PWD -# Keep chroma-takever state meaning: until ; or similar (see $__arg_type below) +# Keep chroma-takeover state meaning: until ; or similar (see $__arg_type below) # The 8192 sum takes care that the next token will be routed to this chroma (( next_word = 2 | 8192 )) @@ -56,5 +57,3 @@ local -a deserialized _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git a/chroma/-git.ch b/chroma/-git.ch new file mode 100755 index 0000000..e5a8a6e --- /dev/null +++ b/chroma/-git.ch @@ -0,0 +1,930 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# +# Chroma function for command `git'. It colorizes the part of command line that holds `git' invocation. + +(( FAST_HIGHLIGHT[-git.ch-chroma-def] )) && return 1 + +FAST_HIGHLIGHT[-git.ch-chroma-def]=1 + +typeset -gA fsh__git__chroma__def +fsh__git__chroma__def=( + ## + ## No subcommand + ## + ## {{{ + + subcmd:NULL "NULL_0_opt" + NULL_0_opt " + (-C|--exec-path=|--git-dir=|--work-tree=|--namespace=|--super-prefix=|--config-env=| + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || -c + <<>> __style=\${FAST_THEME_NAME}single-hyphen-option // NO-OP + <<>> __style=\${FAST_THEME_NAME}optarg-string // NO-OP + || (-v|--version|-h|--help|--html-path|--man-path|--info-path|-p|--paginate| + -P|--no-pager|--no-replace-objects|--bare) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + "subcommands" "::chroma/-git-get-subcommands" # run a function (the :: causes this) and use `reply' + #"subcommands" "(fetch|pull)" # run a function (the :: causes this) and use `reply' + "subcmd-hook" "chroma/-git-check-if-alias" + "subcommands-blacklist" "mv,other" + + ## }}} + + ## + ## `FETCH' + ## + ## {{{ + + subcmd:fetch "FETCH_MULTIPLE_0_opt^ // FETCH_ALL_0_opt^ // FETCH_0_opt // + REMOTE_GR_1_arg // REF_#_arg // NO_MATCH_#_opt" + + # Special options (^ - has directives, currently - an :add and :del directive) + "FETCH_MULTIPLE_0_opt^" " + --multiple + <<>> __style=\${FAST_THEME_NAME}double-hyphen-option // NO-OP + || --multiple:add + <<>> REMOTE_GR_#_arg + || --multiple:del + <<>> REMOTE_GR_1_arg // REF_#_arg" # when --multiple is passed, then + # there is no refspec argument, only remotes-ids + # follow unlimited # of them, hence the # in the + # REMOTE_GR_#_arg + + # Special options (^ - has directives - an :del-directive) + "FETCH_ALL_0_opt^" " + --all + <<>> __style=\${FAST_THEME_NAME}double-hyphen-option // NO-OP + || --all:del + <<>> REMOTE_GR_1_arg // REF_#_arg" # --all can be only followed by options + + # FETCH_0_opt. FETCH-options (FETCH is an identifier) at position 0 -> + # -> before any argument + FETCH_0_opt " + (--depth=|--deepen=|--shallow-exclude=|--shallow-since=|--receive-pack=|--filter=| + --refmap=|--recurse-submodules=|-j|--jobs=|--submodule-prefix=|--recurse-submodules-default=| + -o|--server-option=|--upload-pack=|--negotiation-tip=|--set-upstream=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (-h|--help|--all|-a|--append|--unshallow|--atomic|--auto-maintenance|--update-shallow|--dry-run|-f|--force| + -k|--keep|-m|--multiple|-p|--prune|-n|--no-tags|-t|--tags|--prefetch |--no-recurse-submodules|--negotiation-tip| + --auto-gc|--filter|--write-fetch-head|--write-commit-graph|--show-forced-updates|-P|--prune-tags|--negotiate-only| + -u|--update-head-ok|-q|--quiet|-v|--verbose|--progress|--refetch|-4|--ipv4|-6|--ipv6|--stdin) + <<>> __style=\${FAST_THEME_NAME}single-hyphen-option // NO-OP" + # Above: note the two <<>>-separated blocks for options that have + # some arguments – the second pair of action/handler is being + # run when an option argument is occurred (first one: the option + # itself). If there is only one <<>>-separated block, then the option + # is set to be argument-less. The argument is a) -o/--option argument + # and b) -o/--option=argument. + + REMOTE_GR_1_arg "NO-OP // ::chroma/-git-verify-remote-or-group" # This definition is generic, reused later + "REF_#_arg" "NO-OP // ::chroma/-git-verify-ref" # This too + "REMOTE_GR_#_arg" "NO-OP // ::chroma/-git-verify-remote-or-group" # and this too + # The hash `#' above denotes: an argument at any position + # It will nicely match any following (above the first explicitly + # numbered ones) arguments passed when using --multiple + + # A generic action + NO_MATCH_\#_opt "* <<>> __style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP" + NO_MATCH_\#_arg "__style=\${FAST_THEME_NAME}incorrect-subtle // NO-OP" + + ## }}} + + ## + ## PUSH + ## + ## {{{ + + subcmd:push "PUSH_0_opt // REMOTE_1_arg // REF_#_arg // NO_MATCH_#_opt" + + PUSH_0_opt " + (--receive-pack=|--exec=|--repo=|--push-option=|--signed=| + --force-with-lease=|--recurse-submodules=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (-h|--help|--all|--mirror|--tags|--follow-tags|-n|--dry-run|--porcelain| + -d|--delete|--signed|--no-signed|--atomic|--no-atomic| + -o|--push-option|--prune|--force-with-lease|--no-force-with-lease|-f|--force| + --force-if-includes|-u|--set-upstream|--thin|--no-thin|-q|--quiet|-v|--verbose| + --progress|--no-recurse-submodules|--verify|--no-verify|-4|--ipv4|-6|--ipv6) + <<>> __style=\${FAST_THEME_NAME}single-hyphen-option // NO-OP" + REMOTE_1_arg "NO-OP // ::chroma/-git-verify-remote" # This definition is generic, reused later + + ### }}} + + ## + ## PULL + ## + ## {{{ + + subcmd:pull "PULL_0_opt // REMOTE_1_arg // REF_#_arg // NO_MATCH_#_opt" + + PULL_0_opt " + (--recurse-submodules=|-S|--gpg-sign=|--log=|-s|--strategy=|-X|-j|--jobs=| + --strategy-option=|--rebase=|--depth=|--deepen=|--shallow-exclude=| + --shallow-since=|--signoff=|--negotiation-tip=|--upload-pack|-o|--server-option=| + --no-recurse-submodules=|--refmap=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (-h|--help|-q|--quiet|-v|--verbose|--progress|--no-recurse-submodules|--dry-run| + --commit|--no-commit|--cleanup|--edit|--no-edit|--ff|--no-ff|--ff-only|--log|--no-log| + --signoff|--no-signoff|--stat|-n|--no-stat|--squash|--show-forced-updates|--no-squash| + --verify|--verify-signatures|--no-verify-signatures|--summary|--set-upstream|--no-summary| + --allow-unrelated-histories|-r|--rebase|--no-rebase|--autostash|--no-autostash|--all| + -a|--append|--unshallow|--update-shallow|-f|--force|-p|--prune|-k|--keep|-t|--tags|--no-tags| + -u|--update-head-ok|--progress|-4|--ipv4|-6|--ipv6) + <<>> __style=\${FAST_THEME_NAME}single-hyphen-option // NO-OP" + + ## }}} + + ## + ## COMMIT + ## + ## {{{ + + subcmd:commit "COMMIT_#_opt // FILE_#_arg // NO_MATCH_#_opt" + + "COMMIT_#_opt" " + (-m|--message=|-am) + <<>> NO-OP // ::chroma/-git-commit-msg-opt-action + <<>> NO-OP // ::chroma/-git-commit-msg-opt-ARG-action + || (-h|--help|-a|--all|-p|--patch|--reset-author|--short|--branch| + --porcelain|--long|-z|--null|-s|--signoff|-n|--no-verify| + --allow-empty|--allow-empty-message|-e|--edit|--no-edit| + --amend|--no-post-rewrite|-i|--include|-o|--only|--untracked-files| + -v|--verbose|-q|--quiet|--dry-run|--status|--no-status|--no-gpg-sign) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + || (-C|--reuse-message=|-c|--reedit-message=|--fixup=|--squash=| + -F|--file=|--author=|--date=|-t|--template=|--cleanup=| + -u|--untracked-files=|-S|--gpg-sign=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action" + + # A generic action + "FILE_#_arg" "NO-OP // ::chroma/-git-verify-file" + + ## }}} + + ## + ## MERGE + ## + ## {{{ + + subcmd:merge "MERGE_0_opt // COMMIT_#_arg" + MERGE_0_opt " + (-m) + <<>> NO-OP // ::chroma/-git-commit-msg-opt-action + <<>> NO-OP // ::chroma/-git-commit-msg-opt-ARG-action + (-S|--gpg-sign=|--log=|-e|--strategy=|-X|--strategy-option=|-F|--file|--cleanup=| + --into-name=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (-h|--help|--commit|--no-commit|-e|--edit|--no-edit|--ff|--no-ff|--ff-only|--autostash| + --log|--no-log|--signoff|--no-signoff|-n|--stat|--no-stat|--squash|--overwrite-ignore| + --no-squash|--verify-signatures|--no-verify|--no-verify-signatures|--summary|--no-summary| + -q|--quiet|-v|--verbose|--progress|--no-progress|--allow-unrelated-histories| + --rerere-autoupdate|--no-rerere-autoupdate|--abort|--quit|--continue) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + COMMIT_\#_arg "NO-OP // ::chroma/-git-verify-commit" + + ## }}} + + ## + ## RESET + ## + ## {{{ + + subcmd:reset "RESET_0_opt^ // RESET_0_opt // RESET_#_arg // NO_MATCH_#_opt" + "RESET_0_opt^" " + (--soft|--mixed|--hard|--merge|--keep) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + || (--soft|--mixed|--hard|--merge|--keep):del + <<>> RESET_0_opt // RESET_#_arg + || (--soft|--mixed|--hard|--merge|--keep):add + <<>> RESET_1_arg // NO_MATCH_#_arg" + + RESET_0_opt " + (--recurse-submodules=|--pathspec-from-file=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (-h|--help|-q|--quiet|-p|--patch|-N|--intent-to-add|--pathspec-file-nul) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + RESET_1_arg "NO-OP // ::chroma/-git-verify-commit" + + "RESET_#_arg" "NO-OP // ::chroma/-git-RESET-verify-commit-or-file" + + + ## }}} + + ## + ## REVERT + ## + ## {{{ + + subcmd:revert "REVERT_SEQUENCER_0_opt^ // REVERT_0_opt // REVERT_#_arg // NO_MATCH_#_opt" + REVERT_0_opt " + (-m|--mainline|-S|--gpg-sign=|--strategy=|-X|--strategy-option=|--cleanup=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (-h|--help|-e|--edit|--no-edit|-n|--no-commit|-s|--signoff|--reference|--rerere-autoupdate) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + "REVERT_SEQUENCER_0_opt^" " + (--continue|--quit|--abort|--skip) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + || (--continue|--quit|--abort|--skip):del + <<>> REVERT_0_opt // REVERT_#_arg + || (--continue|--quit|--abort|--skip):add + <<>> NO_MATCH_#_arg" + + "REVERT_#_arg" "NO-OP // ::chroma/-git-verify-commit" + + ## }}} + + ## + ## DIFF + ## + ## TODO: #10 When a second argument is also a path and it points to a directory, then + ## git appends the previous file name to it – good to implement this too + ## {{{ + + subcmd:diff "DIFF_NO_INDEX_0_opt^ // DIFF_0_opt // COMMIT_FILE_DIR_#_arg // NO_MATCH_#_opt" + + "DIFF_NO_INDEX_0_opt^" " + --no-index + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + || --no-index:del + <<>> COMMIT_FILE_DIR_#_arg + || --no-index:add + <<>> FILE_1_arg // FILE_2_arg // NO_MATCH_#_arg" + DIFF_0_opt " + (-U|--unified=|--anchored=|--diff-algorithm=|--stat=|--stat-width=|--stat-name-width=| + --stat-graph-width|-X|--dirstat|--dirstat-by-file=|--stat-count=|--submodule=|--color=| + --color-moved=|--color-moved-ws=|--word-diff=|--word-diff-regex=|--color-words=| + --ws-error-highlight=|--abbrev=|-B|--break-rewrites=|-M|--find-renames=|-C|--find-copies=|-l| + --diff-filter=|-S|-G|--find-object=|--relative=|-O|--relative=|--inter-hunk-context=|--output=| + --output-indicator-new=|--output-indicator-old=|--output-indicator-context=|--ignore-submodules=| + --src-prefix=|--dst-prefix=|--line-prefix=|-I|--ignore-matching-lines=|--rotate-to=|--skip-to=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (-h|--help|-p|--patch|-u|-s|--no-patch|--raw|--patch-with-raw|--indent-heuristic| + --no-indent-heuristic|--minimal|--patience|--histogram|--stat|--cumulative| + --compact-summary|--numstat|--shortstat|--dirstat|--summary| + --patch-with-stat|-z|--name-only|--name-status|--submodule|--no-color| + --color-moved|--word-diff|--color-words|--no-renames|--check| + --full-index|--binary|--abbrev|--break-rewrites|--find-renames|--rename-empty| + --find-copies|--find-copies-harder|-D|--pickaxe-all|--pickaxe-regex|--follow| + --irreversible-delete|-R|--relative|-a|--text|--ignore-cr-at-eol| + --ignore-space-at-eol|-b|--ignore-space-change|-w|--ignore-all-space| + --ignore-blank-lines|-W|--function-context|--exit-code|--quiet| + --ext-diff|--no-ext-diff|--textconv|--no-textconv|--ignore-submodules| + --no-prefix|--ita-invisible-in-index|--ita-visible-in-index|-1|--base|-2|--ours|-3|--theirs| + -0|--cached) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + # A generic action + "COMMIT_FILE_DIR_#_arg" "NO-OP // ::chroma/-git-verify-commit-or-file-or-dir" + + # A generic action + "FILE_1_arg" "NO-OP // ::chroma/-git-verify-file" + + # A generic action + "FILE_2_arg" "NO-OP // ::chroma/-git-verify-file" + + ## }}} + + ## + ## ADD + ## + ## {{{ + + subcmd:add "ADD_0_opt // FILE_OR_DIR_#_arg // NO_MATCH_#_opt" + + ADD_0_opt " + (--chmod=|--pathspec-from-file=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (-h|--help|-v|--verbose|-f|--force|-i|--interactive|-n|--dry-run|-p|--patch|-e|--edit| + --all|--no-all|-A|--ignore-removal|--no-ignore-removal|-u|--update|-N|--sparse| + --intent-to-add|--refresh|--ignore-errors|--ignore-missing|--renormalize| + --no-warn-embedded-repo|--pathspec-file-nul) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + FILE_OR_DIR_#_arg "NO-OP // ::chroma/-git-verify-file-or-dir" + + ## }}} + + ## + ## CHECKOUT + ## + ## {{{ + + subcmd:checkout "CHECKOUT_BRANCH_0_opt^ // + CHECKOUT_0_opt // FILE_OR_DIR_OR_BRANCH_OR_COMMIT_1_arg // FILE_#_arg // + FILE_#_arg // NO_MATCH_#_opt" + + "CHECKOUT_BRANCH_0_opt^" " + (-b|-B|--orphan) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + || (-b|-B|--orphan):del + <<>> FILE_OR_DIR_OR_BRANCH_OR_COMMIT_1_arg // FILE_#_arg // FILE_#_arg + || (-b|-B|--orphan):add + <<>> NEW_BRANCH_1_arg // COMMIT_2_arg // NO_MATCH_#_arg" + + NEW_BRANCH_1_arg "NO-OP // ::chroma/-git-verify-correct-branch-name" + + COMMIT_2_arg "NO-OP // ::chroma/-git-verify-commit" + + CHECKOUT_0_opt " + (--conflict=|--recurse-submodules=|--track=|--pathspec-from-file=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (-h|--help|-q|--quiet|--progress|--no-progress|-f|--force|-2|--ours|-3|--theirs|--guess|--overlay| + -b|-B|-t|--track|--no-track|-l|-d|--detach|--orphan|--ignore-skip-worktree-bits| + -m|--merge|-p|--patch|--ignore-other-worktrees|--no-ignore-other-worktrees|--overwrite-ignore| + --pathspec-file-nul) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + # A generic action + COMMIT_1_arg "NO-OP // ::chroma/-git-verify-commit" + + # Unused + FILE_OR_BRANCH_OR_COMMIT_1_arg "NO-OP // ::chroma/-git-file-or-ubranch-or-commit-verify" + FILE_OR_DIR_OR_BRANCH_OR_COMMIT_1_arg "NO-OP // ::chroma/-git-file-or-dir-or-ubranch-or-commit-verify" + + ## }}} + + ## + ## REMOTE + ## + ## {{{ + + subcmd:remote "REMOTE_0_opt // REMOTE_ADD_1_arg // REMOTE_RENAME_1_arg // REMOTE_REMOVE_1_arg // + REMOTE_SET_HEAD_1_arg // REMOTE_SET_BRANCHES_1_arg // + REMOTE_GET_URL_1_arg // REMOTE_SET_URL_1_arg // REMOTE_SHOW_1_arg // + REMOTE_PRUNE_1_arg // REMOTE_UPDATE_1_arg" + + REMOTE_0_opt "(-h|--help|-v|--verbose) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + REMOTE_ADD_1_arg "add ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>> + add:REMOTE_ADD_OPTS_1_opt // REMOTE_A_NAME_2_arg // + REMOTE_A_URL_3_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" + + REMOTE_RENAME_1_arg "rename ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>> + add:REMOTE_2_arg // REMOTE_A_NAME_3_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" + + REMOTE_REMOVE_1_arg "remove ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>> + add:REMOTE_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" + + REMOTE_SET_HEAD_1_arg "set-head ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>> + add:REMOTE_2_arg // BRANCH_3_arg // + REMOTE_SET_HEAD_OPTS_1_opt // REMOTE_SET_HEAD_OPTS_2_opt // + NO_MATCH_#_opt // NO_MATCH_#_arg" + + REMOTE_SET_BRANCHES_1_arg "set-branches ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>> + add:REMOTE_SET_BRANCHES_OPTS_1_opt // REMOTE_2_arg // + BRANCH_#_arg // NO_MATCH_#_opt" + + REMOTE_GET_URL_1_arg "get-url ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>> + add:REMOTE_GET_URL_OPTS_1_opt // REMOTE_2_arg // + NO_MATCH_#_opt // NO_MATCH_#_arg" + + REMOTE_SET_URL_1_arg "set-url ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>> + add:REMOTE_SET_URL_OPTS_1_opt^ // + REMOTE_2_arg // REMOTE_A_URL_3_arg // REMOTE_A_URL_4_arg // + NO_MATCH_#_opt // NO_MATCH_#_arg" + + REMOTE_SHOW_1_arg "show ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>> + add:REMOTE_SHOW_OPTS_1_opt // REMOTE_#_arg // NO_MATCH_#_opt" + + REMOTE_PRUNE_1_arg "prune ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>> + add:REMOTE_PRUNE_OPTS_1_opt // REMOTE_#_arg // NO_MATCH_#_opt" + + REMOTE_UPDATE_1_arg "update ::::: __style=${FAST_THEME_NAME}subcommand // NO-OP <<>> + add:REMOTE_UPDATE_OPTS_1_opt // REMOTE_GR_#_arg // NO_MATCH_#_opt" + + REMOTE_ADD_OPTS_1_opt " + (-t|-m|--mirror=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (-f|--tags|--no-tags) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + REMOTE_SET_HEAD_OPTS_1_opt " + (-a|--auto|-d|--delete) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + REMOTE_SET_HEAD_OPTS_2_opt " + (-a|--auto|-d|--delete) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + REMOTE_SET_BRANCHES_OPTS_1_opt " + --add + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + REMOTE_GET_URL_OPTS_1_opt " + (--push|--all) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + "REMOTE_SET_URL_OPTS_1_opt^" " + --push|--add|--delete + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + || (--add|--delete):del + <<>> REMOTE_A_URL_4_arg" + + REMOTE_SHOW_OPTS_1_opt " + -n + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + REMOTE_PRUNE_OPTS_1_opt " + (-n|--dry-run) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + REMOTE_UPDATE_OPTS_1_opt " + (-p|--prune) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + REMOTE_A_NAME_2_arg "NO-OP // ::chroma/-git-verify-correct-branch-name" + REMOTE_A_NAME_3_arg "NO-OP // ::chroma/-git-verify-correct-branch-name" + REMOTE_A_URL_3_arg "NO-OP // ::chroma/main-chroma-std-verify-url" + REMOTE_A_URL_4_arg "NO-OP // ::chroma/main-chroma-std-verify-url" + BRANCH_3_arg "NO-OP // ::chroma/-git-verify-branch" + BRANCH_\#_arg "NO-OP // ::chroma/-git-verify-branch" + REMOTE_2_arg "NO-OP // ::chroma/-git-verify-remote" + REMOTE_\#_arg "NO-OP // ::chroma/-git-verify-remote" + + ## }}} + + ## + ## LOG + ## + + subcmd:log "LOG_0_opt // LOG_1_arg // FILE_#_arg // NO_MATCH_#_opt" + + LOG_0_opt " + (--decorate=|--decorate-refs=|--decorate-refs-exclude=|-L|-n|--max-count=| + --skip=|--since=|--after=|--until=|--before=|--author=|--committer=| + --grep-reflog=|--grep=|--min-parents=|--max-parents=|--branches=|--tags=| + --remotes=|--glob=|--exclude=|--no-walk=|--pretty=|--format=|--encoding=| + --expand-tabs=|--notes=|--show-notes=|--date=|--show-linear-break=|-U| + --unified=|--anchored=|--diff-algorithm=|--stat=|--dirstat=|--submodule=| + --color=|--color-moved=|--color-moved-ws=|--word-diff=|--word-diff-regex=| + --color-words=|--ws-error-highlight=|--abbrev=|-B|--break-rewrites=|-M| + --find-renames=|-C|--find-copies=|-l|--diff-filter=|-S|-G|--find-object=| + --relative=|-O|--relative=|--inter-hunk-context=|--ignore-submodules=| + --src-prefix=|--dst-prefix=|--line-prefix=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + + || (-h|--help|--follow|--decorate|--no-decorate|--source|--use-mailmap|--full-diff| + --log-size|--all-match|--invert-grep|-i|--regexp-ignore-case|--basic-regexp| + -E|--extended-regexp|-F|--fixed-strings|-P|--perl-regexp|--remove-empty| + --merges|--no-merges|--no-min-parents|--no-max-parents|--first-parent| + --not|--all|--branches|--tags|--remotes|--reflog|--single-worktree| + --ignore-missing|--bisect|--stdin|--cherry-mark|--cherry-pick|--left-only| + --right-only|--cherry|-g|--walk-reflogs|--merge|--boundary|--simplify-by-decoration| + --full-history|--dense|--sparse|--simplify-merges|--ancestry-path|--date-order| + --author-date-order|--topo-order|--reverse|--no-walk|--do-walk|--pretty| + --abbrev-commit|--no-abbrev-commit|--oneline|--expand-tabs|--no-expand-tabs| + --notes|--no-notes|--show-notes|--no-standard-notes|--show-signature| + --relative-date|--parents|--children|--left-right|--graph|--show-linear-break| + -c|--cc|-m|-r|-t|-p|-u|--patch|-s|--no-patch|--raw|--patch-with-raw| + --indent-heuristic|--no-indent-heuristic|--minimal|--patience|--histogram| + --stat|--compact-summary|--numstat|--shortstat|--dirstat|--summary| + --patch-with-stat|-z|--name-only|--name-status|--submodule|--color|--no-color| + --color-moved|--word-diff|--color-words|--no-renames|--check|--full-index| + --binary|--abbrev|--break-rewrites|--find-renames| + --find-copies|--find-copies-harder|-D|--irreversible-delete| + --pickaxe-all|--pickaxe-regex|-R|--relative|-a|--text|--ignore-cr-at-eol| + --ignore-space-at-eol|-b|--ignore-space-change|-w|--ignore-all-space| + --ignore-blank-lines|-W|--function-context|--ext-diff|--no-ext-diff| + --textconv|--no-textconv|--ignore-submodules|--no-prefix| + --ita-invisible-in-index) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + LOG_1_arg "NO-OP // ::chroma/-git-verify-rev-range-or-file" + + ## + ## TAG + ## + + subcmd:tag "TAG_D_0_opt^ // TAG_L_0_opt^ // TAG_V_0_opt^ // TAG_0_opt^" + + "TAG_0_opt^" " + (-u|--local-user=|--cleanup=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || -m + <<>> NO-OP // ::chroma/-git-commit-msg-opt-action + <<>> NO-OP // ::chroma/-git-commit-msg-opt-ARG-action + || (-F|--file) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/-git-verify-file + || (-a|--annotate|-s|--sign|-f|-e|--edit) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + || (-h|--help|-u|--local-user=|--cleanup=|-m|-F|--file|-a|--annotate|-s|--sign| + -f|-e|--edit):add + <<>> TAG_NEW_1_arg // COMMIT_2_arg // NO_MATCH_#_arg // + NO_MATCH_#_opt" + + TAG_NEW_1_arg "NO-OP // ::chroma/-git-verify-correct-branch-name" + + TAG_1_arg "NO-OP // ::chroma/-git-verify-tag-name" + + "TAG_D_0_opt^" " + (-d) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + || -d:add + <<>> TAG_#_arg // NO_MATCH_#_opt + || -d:del + <<>> TAG_0_opt // TAG_NEW_1_arg // COMMIT_2_arg" + + "TAG_#_arg" "NO-OP // ::chroma/-git-verify-tag-name" + + "TAG_L_0_opt^" " + (-l) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + || -l:add + <<>> TAG_L_0_opt // TAG_PAT_#_arg // NO_MATCH_#_opt + || -l:del + <<>> TAG_0_opt // TAG_NEW_1_arg // COMMIT_2_arg" + + TAG_L_0_opt " + (-n|--contains|--no-contains|--points-at|--column=|--sort=|--format=| + --color=) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action + || (--column|--no-column|--create-reflog|--merged|--no-merged|--color|-i) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" + + "TAG_PAT_#_arg" "NO-OP // ::chroma/main-chroma-std-verify-pattern" + + "TAG_V_0_opt^" " + (-v) + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + || -v:add + <<>> TAG_V_0_opt // TAG_#_arg // NO_MATCH_#_opt + || -v:del + <<>> TAG_0_opt // TAG_NEW_1_arg // COMMIT_2_arg" + + TAG_V_0_opt " + --format= + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action + <<>> NO-OP // ::chroma/main-chroma-std-aopt-ARG-action" + + ## + ## All remaining subcommands + ## + ## {{{ + + "subcmd:*" "CATCH_ALL_#_opt" + "CATCH_ALL_#_opt" "* <<>> NO-OP // ::chroma/main-chroma-std-aopt-SEMI-action" + + ## }}} +) + +# Called after entering just "git" on the command line +chroma/-git-first-call() { + # Called for the first time - new command FAST_HIGHLIGHT is used because it survives between calls, + # and allows to use a single global hash only, instead of multiple global variables + FAST_HIGHLIGHT[chroma-git-counter]=0 + FAST_HIGHLIGHT[chroma-git-got-subcommand]=0 + FAST_HIGHLIGHT[chroma-git-subcommand]="" + FAST_HIGHLIGHT[chrome-git-got-msg1]=0 + FAST_HIGHLIGHT[chrome-git-got-anymsg]=0 + FAST_HIGHLIGHT[chrome-git-occurred-double-hyphen]=0 + FAST_HIGHLIGHT[chroma-git-checkout-new]=0 + FAST_HIGHLIGHT[chroma-git-fetch-multiple]=0 + FAST_HIGHLIGHT[chroma-git-branch-change]=0 + FAST_HIGHLIGHT[chroma-git-option-with-argument-active]=0 + FAST_HIGHLIGHT[chroma-git-reset-etc-saw-commit]=0 + FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file]=0 + return 1 +} + +chroma/-git-check-if-alias() { + local _wrd="$1" + local -a _result + + typeset -ga fsh__chroma__git__aliases + _result=( ${(M)fsh__chroma__git__aliases[@]:#${_wrd}[[:space:]]##*} ) + chroma/main-chroma-print "Got is-alias-_result: $_result" + [[ -n "$_result" ]] && \ + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]="${${${_result#* }## ##}%% *}" +} + +# A hook that returns the list of git's +# available subcommands in $reply +chroma/-git-get-subcommands() { + local __svalue + integer __ivalue + LANG=C .fast-run-command "git help -a" chroma-${FAST_HIGHLIGHT[chroma-current]}-subcmd-list "" $(( 15 * 60 )) + + if [[ "${__lines_list[1]}" = See* ]]; then + # (**) + # git >= v2.20, the aliases in the `git help -a' command + __lines_list=( ${${${${(M)__lines_list[@]:#([[:space:]](#c3,3)[a-zA-Z0-9_]*|Command aliases)}##[[:space:]]##}//(#s)Command\ aliases(#e)/Command_aliases}} ) + __svalue="+${__lines_list[(I)Command_aliases]}" + __lines_list[1,__svalue-1]=( ${(@)__lines_list[1,__svalue-1]%%[[:space:]]##*} ) + else + # (**) + # git < v2.20, add aliases through extra code + __lines_list=( ${(s: :)${(M)__lines_list[@]:# [a-z]*}} ) + __svalue=${#__lines_list} + # This allows to check if the command is an alias - we want to + # highlight the aliased command just like the target command of the alias + .fast-run-command "+git config --get-regexp 'alias.*'" chroma-${FAST_HIGHLIGHT[chroma-current]}-alias-list "[[:space:]]#alias." $(( 15 * 60 )) + fi + + __tmp=${#__lines_list} + typeset -ga fsh__chroma__git__aliases + fsh__chroma__git__aliases=( ${__lines_list[__svalue+1,__tmp]} ) + [[ ${__lines_list[__svalue]} != "Command_aliases" ]] && (( ++ __svalue, __ivalue=0, 1 )) || (( __ivalue=1 )) + __lines_list[__svalue,__tmp]=( ${(@)__lines_list[__svalue+__ivalue,__tmp]%%[[:space:]]##*} ) + reply=( "${__lines_list[@]}" ) +} + +# A generic handler +chroma/-git-verify-remote() { + local _wrd="$4" + .fast-run-git-command "git remote" "chroma-git-remotes-$PWD" "" 10 + [[ -n ${__lines_list[(r)$_wrd]} ]] && { + __style=${FAST_THEME_NAME}correct-subtle; return 0 + } || { + [[ $_wrd != *:* ]] && { __style=${FAST_THEME_NAME}incorrect-subtle; return 1; } + } +} + +# A generic handler - checks if given ref is correct +chroma/-git-verify-ref() { + local _wrd="$4" + _wrd="${_wrd%%:*}" + .fast-run-git-command "git for-each-ref --format='%(refname:short)' refs/heads" "chroma-git-refs-$PWD" "refs/heads" 10 + [[ -n ${__lines_list[(r)$_wrd]} ]] && \ + { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \ + { __style=${FAST_THEME_NAME}incorrect-subtle; return 1; } +} + +# A generic handler - checks if given remote or group is correct +chroma/-git-verify-remote-or-group() { + chroma/-git-verify-remote "$@" && return 0 + # The check for a group is to follow below + integer _start="$2" _end="$3" + local _scmd="$1" _wrd="$4" +} + +# A generic handler - checks whether the file exists +chroma/-git-verify-file() { + integer _start="$2" _end="$3" __pos __start __end + local _wrd="$4" bg + + [[ -f $_wrd ]] && { + (( __start=_start, __end=_end, __start >= 0 )) && \ + reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") + bg=${(M)FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]%bg=*} + ((1)) + } || { + (( __start=_start, __end=_end, __start >= 0 )) && \ + reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") + bg=${(M)FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]%bg=*} + } + + [[ -n ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} && \ + ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]} != \ + ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} + ]] && \ + for (( __pos = 1; __pos <= (_end-_start); __pos++ )) { + [[ ${_wrd[__pos]} == "/" ]] && { + [[ ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} = *bg=* ]] && { + (( __start=_start+__pos-__PBUFLEN, __start >= 0 )) && \ + reply+=("$(( __start - 1 )) $__start ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}") + ((1)) + } || { + (( __start=_start+__pos-__PBUFLEN, __start >= 0 )) && \ + reply+=("$(( __start - 1 )) $__start ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}${bg:+,$bg}") + } + } + } +} + +# A generic handler - checks whether the file exists +chroma/-git-verify-file-or-dir() { + integer _start="$2" _end="$3" __pos __start __end retval + local _wrd="$4" bg + + __style= + [[ -f $_wrd || -d $_wrd ]] && { + (( __start=_start, __end=_end, __start >= 0 )) && \ + reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") + bg=${(M)FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]%bg=*} + ((1)) + } || { + (( __start=_start, __end=_end, __start >= 0 )) && \ + reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") + bg=${(M)FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]%bg=*} + retval=1 + } + + [[ -n ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} && \ + ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]} != \ + ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} + ]] && \ + for (( __pos = 1; __pos <= (_end-_start); __pos++ )) { + [[ ${_wrd[__pos]} == "/" ]] && { + [[ ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} = *bg=* ]] && { + (( __start=_start+__pos-__PBUFLEN, __start >= 0 )) && \ + reply+=("$(( __start - 1 )) $__start ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}") + ((1)) + } || { + (( __start=_start+__pos-__PBUFLEN, __start >= 0 )) && \ + reply+=("$(( __start - 1 )) $__start ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}${bg:+,$bg}") + } + } + } + return $retval +} + +chroma/-git-verify-branch() { + local _wrd="$4" + .fast-run-git-command "git for-each-ref --format='%(refname:short)'" "chroma-git-branches-$PWD" "refs/heads" 10 + if [[ -n ${__lines_list[(r)$_wrd]} ]] { + __style=${FAST_THEME_NAME}correct-subtle; return 0 + } elif [[ -n ${__lines_list[(r)origin/$_wrd]} ]] { + __style=${FAST_THEME_NAME}correct-subtle; return 0 + } else { + __style=${FAST_THEME_NAME}incorrect-subtle; return 1 + } +} + +chroma/-git-verify-also-unfetched-ref() { + local _wrd="$4" + .fast-run-git-command "git config --get checkout.defaultRemote" "chroma-git-defaultRemote-$PWD" "" 10 + local remote="${__lines_list[1]:-origin}" + .fast-run-git-command "git rev-list --count --no-walk --glob=\"refs/remotes/$remote/$_wrd\"" \ + "chroma-git-unfetched-ref-$PWD" "" 10 + + (( __lines_list[1] )) && { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \ + { __style=${FAST_THEME_NAME}incorrect-subtle; return 1; } +} + +# A generic handler +chroma/-git-file-or-ubranch-or-commit-verify() { + chroma/-git-verify-commit "$@" && return + chroma/-git-verify-file "$@" && return + chroma/-git-verify-branch "$@" && return + chroma/-git-verify-also-unfetched-ref "$@" +} + +# A generic handler +chroma/-git-file-or-dir-or-ubranch-or-commit-verify() { + chroma/-git-verify-commit "$@" && return + chroma/-git-verify-file-or-dir "$@" && return + chroma/-git-verify-branch "$@" && return + chroma/-git-verify-also-unfetched-ref "$@" +} + +# A generic handler +chroma/-git-verify-correct-branch-name() { + local _wrd="$4" + chroma/-git-verify-commit "$@" && { __style=${FAST_THEME_NAME}incorrect-subtle; return 0; } + + chroma/-git-verify-remote "$@" && { __style=${FAST_THEME_NAME}incorrect-subtle; return 0; } + + [[ "$_wrd" != ./* && "$_wrd" != *..* && "$_wrd" != *[~\^\ $'\t']* && \ + "$_wrd" != */ && "$_wrd" != *.lock && "$_wrd" != *\\* ]] && \ + { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \ + { __style=${FAST_THEME_NAME}incorrect-subtle; return 1; } +} + +# A generic handler that checks if given commit reference is correct +chroma/-git-verify-commit() { + local _wrd="$4" + __lines_list=() + .fast-run-git-command --status "git rev-parse --verify --quiet \"$_wrd\"" \ + "chroma-git-commits-$PWD-$_wrd" "" $(( 1.5 * 60 )) + if (( __lines_list[1] == 0 )); then + __style=${FAST_THEME_NAME}correct-subtle + return 0 + fi + __style=${FAST_THEME_NAME}incorrect-subtle + return 1 +} + +# A generic handler that checks if given commit reference +# is correct or if it's a file that exists +chroma/-git-verify-commit-or-file() { + chroma/-git-verify-commit "$@" && return + chroma/-git-verify-file "$@" +} + +# A generic handler that checks if given commit reference +# is correct or if it's a file or directives that exists +chroma/-git-verify-commit-or-file-or-dir() { + chroma/-git-verify-commit "$@" && return + chroma/-git-verify-file-or-dir "$@" +} + +# A generic handler that checks if given revision range +# is correct or if a file of that name exists +chroma/-git-verify-rev-range-or-file() { + local _wrd="$4" + chroma/-git-verify-commit "$@" && return 0 + + if [[ "$_wrd" = *..* ]]; then + (( FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file] )) && { + chroma/-git-verify-file "$@" && return 0 + __style=${FAST_THEME_NAME}unknown-token + return 1 + } + __style="" + return 0 + fi + + chroma/-git-verify-file "$@" && { FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file]=1; return 0; } + + __style="" + return 1 +} + +chroma/-git-verify-tag-name() { + local _wrd="$4" + .fast-run-git-command "git tag" "chroma-git-tags-$PWD" "" $(( 2*60 )) + [[ -n ${__lines_list[(r)$_wrd]} ]] && \ + __style=${FAST_THEME_NAME}correct-subtle || __style=${FAST_THEME_NAME}incorrect-subtle +} + +# A handler for the commit's -m/--message options.Currently +# does the same what chroma/main-chroma-std-aopt-action does +chroma/-git-commit-msg-opt-action() { + chroma/main-chroma-std-aopt-action "$@" +} + +# A handler for the commit's -m/--message options' argument +chroma/-git-commit-msg-opt-ARG-action() { + integer _start="$2" _end="$3" + local _scmd="$1" _wrd="$4" + + (( __start >= 0 )) || return + + # Match the message body in case of an --message= option + if [[ "$_wrd" = (#b)(--message=)(*) && -n "${match[2]}" ]]; then + _wrd="${(Q)${match[2]//\`/x}}" + # highlight --message=>>something<< + reply+=("$(( __start+10 )) $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}") + elif [[ "$_wrd" != --message ]]; then + # highlight the message's body + reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}") + fi + + integer length=${FAST_HIGHLIGHT[git-cmsg-len]:-70} + + if (( ${#_wrd} > length )); then + for (( __idx1 = 1, __idx2 = 1; __idx1 <= length; ++ __idx1, ++ __idx2 )); do + # Use __arg from the fast-highlight-process's scope + while [[ "${__arg[__idx2]}" != "${_wrd[__idx1]}" ]]; do + (( ++ __idx2 )) + (( __idx2 > __asize )) && { __idx2=-1; break; } + done + (( __idx2 == -1 )) && break + done + if (( __idx2 != -1 )); then + if [[ -n "${match[1]}" ]]; then + reply+=("$(( __start+__idx2 )) $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") + else + reply+=("$(( __start+__idx2-1 )) $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") + fi + fi + fi +} + +# A RESET handler +# TODO: differentiate tree-ish from commit +chroma/-git-RESET-verify-commit-or-file() { + chroma/-git-verify-commit "$@" && { + chroma/-git-verify-file "$@" && { + # TODO: with -p/--patch, the are optional, + # and this argument will be taken as a commit in a + # specific circumstances + FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file]=1 + return 0 + } + + (( FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file] || FAST_HIGHLIGHT[chroma-git-reset-etc-saw-commit] )) && \ + { __style=${FAST_THEME_NAME}unknown-token; return 1; } + + FAST_HIGHLIGHT[chroma-git-reset-etc-saw-commit]=1 + __style=${FAST_THEME_NAME}correct-subtle + return 0 + } + + chroma/-git-verify-file "$@" && { FAST_HIGHLIGHT[chroma-git-reset-etc-saw-file]=1; return 0; } + + return 1 +} + +return 0 diff --git "a/\342\206\222chroma/-grep.ch" b/chroma/-grep.ch old mode 100644 new mode 100755 similarity index 95% rename from "\342\206\222chroma/-grep.ch" rename to chroma/-grep.ch index 3713e43..e0b0433 --- "a/\342\206\222chroma/-grep.ch" +++ b/chroma/-grep.ch @@ -66,7 +66,7 @@ integer __idx1 __idx2 done elif (( FAST_HIGHLIGHT[chroma-grep-counter] == 2 )); then # Handle paths, etc. normally - just pass-through to the big - # highlighter (the main FSH highlighter, used before chromas). + # highlighter (the main f-sy-h highlighter, used before chromas). return 1 fi fi @@ -79,7 +79,7 @@ integer __idx1 __idx2 # to disable this code. [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") -# We aren't passing-through (no return 1 occured), do obligatory things ourselves. +# We aren't passing-through (no return 1 occurred), do obligatory things ourselves. (( this_word = next_word )) _start_pos=$_end_pos diff --git "a/\342\206\222chroma/-hub.ch" b/chroma/-hub.ch old mode 100644 new mode 100755 similarity index 99% rename from "\342\206\222chroma/-hub.ch" rename to chroma/-hub.ch index 84864c6..e9f720c --- "a/\342\206\222chroma/-hub.ch" +++ b/chroma/-hub.ch @@ -1,5 +1,6 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- -# +# vim: ft=zsh sw=2 ts=2 et + (( next_word = 2 | 8192 )) local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" @@ -50,5 +51,3 @@ if [[ "$__wrd" != -* ]] && (( FAST_HIGHLIGHT[chroma-git-got-subcommand] == 0 )); fi chroma/-git.ch $* - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-ionice.ch" b/chroma/-ionice.ch old mode 100644 new mode 100755 similarity index 93% rename from "\342\206\222chroma/-ionice.ch" rename to chroma/-ionice.ch index e78c7b0..4ed4a98 --- "a/\342\206\222chroma/-ionice.ch" +++ b/chroma/-ionice.ch @@ -1,4 +1,5 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # # ------------------------------------------------------------------------------------------------- # Copyright (c) 2018 Sebastian Gniazdowski @@ -29,7 +30,7 @@ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ------------------------------------------------------------------------------------------------- -setopt local_options extendedglob warn_create_global typeset_silent +builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd local_options # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. # So the below 8192 assignment takes care that next token will be routed to chroma. @@ -102,10 +103,12 @@ local -a match mbegin mend # This is a common place of adding such entry, but any above code can do # it itself (and it does in other chromas) and skip setting __style to # this way disable this code. -[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") +[[ -n "$__style" ]] && \ + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \ + reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") # We aren't passing-through, do obligatory things ourselves. -# _start_pos=$_end_pos advainces pointers in command line buffer. +# _start_pos=$_end_pos advances pointers in command line buffer. # # To pass through means to `return 1'. The highlighting of # this single token is then done by fast-syntax-highlighting's @@ -114,5 +117,3 @@ local -a match mbegin mend _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-lab.ch" b/chroma/-lab.ch old mode 100644 new mode 100755 similarity index 99% rename from "\342\206\222chroma/-lab.ch" rename to chroma/-lab.ch index 8dacad8..6e8cb79 --- "a/\342\206\222chroma/-lab.ch" +++ b/chroma/-lab.ch @@ -1,4 +1,5 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # # The `lab' tool after which this chroma is modeled after: # https://github.com/zaquestion/lab @@ -57,5 +58,3 @@ if [[ "$__wrd" != -* ]] && (( FAST_HIGHLIGHT[chroma-git-got-subcommand] == 0 )); fi chroma/-git.ch $* - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-make.ch" b/chroma/-make.ch old mode 100644 new mode 100755 similarity index 100% rename from "\342\206\222chroma/-make.ch" rename to chroma/-make.ch diff --git "a/\342\206\222chroma/-nice.ch" b/chroma/-nice.ch old mode 100644 new mode 100755 similarity index 97% rename from "\342\206\222chroma/-nice.ch" rename to chroma/-nice.ch index 164c095..83de3d4 --- "a/\342\206\222chroma/-nice.ch" +++ b/chroma/-nice.ch @@ -1,4 +1,5 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # # ------------------------------------------------------------------------------------------------- # Copyright (c) 2018 Sebastian Gniazdowski @@ -29,7 +30,7 @@ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ------------------------------------------------------------------------------------------------- -setopt local_options extendedglob warn_create_global typeset_silent +builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. # So the below 8192 assignment takes care that next token will be routed to chroma. @@ -126,7 +127,7 @@ local -a match mbegin mend [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") # We aren't passing-through, do obligatory things ourselves. -# _start_pos=$_end_pos advainces pointers in command line buffer. +# _start_pos=$_end_pos advances pointers in command line buffer. # # To pass through means to `return 1'. The highlighting of # this single token is then done by fast-syntax-highlighting's @@ -135,5 +136,3 @@ local -a match mbegin mend _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git a/chroma/-nmcli.ch b/chroma/-nmcli.ch new file mode 100755 index 0000000..cfd3ea7 --- /dev/null +++ b/chroma/-nmcli.ch @@ -0,0 +1,60 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et + +(( next_word = 2 | 8192 )) +[[ "$__arg_type" = 3 ]] && return 2 + +typeset -A subcommands +local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" subcommand +subcommands=( + help "_" + general "help status hostname permissions logging _" + networking "help on off connectivity _" + radio "help all wifi wwan _" + connection "help show up down add modify clone edit delete monitor reload load import export _" + device "help status show set connect reapply modify disconnect delete monitor wifi lldp _" + agent "help secret polkit all _" + monitor "help _" + _ "_" +) + +if (( __first_call )); then + FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]="" + FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]="" + return 1 +elif (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then + return 1 +elif [[ "$2" = -* ]]; then + return 1 +elif [[ -z ${FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]} ]]; then + for subcommand in ${(@k)subcommands}; do + [[ $subcommand = $__wrd* ]] && break || subcommand="_" + done + if [[ $subcommand = _ ]]; then + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ + && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") + else + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ + && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") + fi + FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]="$subcommand" +elif [[ -z ${FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]} ]]; then + for subcommand in ${(s. .)subcommands[${FAST_HIGHLIGHT[chroma-nmcli-subcommand-a]}]}; do + [[ "$subcommand" = $__wrd* ]] && break || subcommand="_" + done + if [[ $subcommand = _ ]]; then + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ + && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") + else + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ + && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}subcommand]}") + fi + FAST_HIGHLIGHT[chroma-nmcli-subcommand-b]="$subcommand" +else + return 1 +fi + +(( this_word = next_word )) +_start_pos=$_end_pos + +return 0 diff --git "a/\342\206\222chroma/-node.ch" b/chroma/-node.ch old mode 100644 new mode 100755 similarity index 99% rename from "\342\206\222chroma/-node.ch" rename to chroma/-node.ch index f7d2f13..07d6f2a --- "a/\342\206\222chroma/-node.ch" +++ b/chroma/-node.ch @@ -1,5 +1,6 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- -# +# vim: ft=zsh sw=2 ts=2 et + (( next_word = 2 | 8192 )) [[ "$__arg_type" = 3 ]] && return 2 @@ -36,5 +37,3 @@ elif (( FAST_HIGHLIGHT[chroma-node-file] )); then fi return 1 - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-ogit.ch" b/chroma/-ogit.ch old mode 100644 new mode 100755 similarity index 100% rename from "\342\206\222chroma/-ogit.ch" rename to chroma/-ogit.ch diff --git a/chroma/-perl.ch b/chroma/-perl.ch new file mode 100755 index 0000000..139bd18 --- /dev/null +++ b/chroma/-perl.ch @@ -0,0 +1,78 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# +# Chroma function for command `perl'. It highlights code passed to perl +# with -e option - does syntax check by calling `perl -ce', then highlights +# as correct or incorrect code. +# +# $1 - 0 or 1, denoting if it's first call to the chroma, or following one +# $2 - the current token, also accessible by $__arg from the above scope - +# basically a private copy of $__arg +# $3 - a private copy of $_start_pos, i.e. the position of the token in the +# command line buffer, used to add region_highlight entry (see man), +# because Zsh colorizes by *ranges* in command line buffer +# $4 - a private copy of $_end_pos from the above scope +# + +(( next_word = 2 | 8192 )) + +local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" +local __style +integer __idx1 __idx2 + +(( __first_call )) && { + # Called for the first time - new command. + # FAST_HIGHLIGHT is used because it survives between calls, and + # allows to use a single global hash only, instead of multiple + # global variables. + FAST_HIGHLIGHT[chrome-perl-got-eswitch]=0 + return 1 +} || { + # Following call, i.e. not the first one. + + # Check if chroma should end – test if token is of type + # "starts new command", if so pass-through – chroma ends + [[ "$__arg_type" = 3 ]] && return 2 + + if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then + return 1 + fi + + if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-perl-got-subcommand]} -eq 0 ]]; then + __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option} + + if [[ "$__wrd" = "-e" || ("$__wrd" = -*e* && "$__wrd" != --*) ]]; then + FAST_HIGHLIGHT[chrome-perl-got-eswitch]=1 + fi + else + __wrd="${__wrd//\`/x}" + __arg="${__arg//\`/x}" + __wrd="${(Q)__wrd}" + if (( FAST_HIGHLIGHT[chrome-perl-got-eswitch] == 1 )); then + FAST_HIGHLIGHT[chrome-perl-got-eswitch]=0 + if perl -ce "$__wrd" >/dev/null 2>&1; then + # Add correct-subtle style + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") + else + # Add incorrect-subtle style + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}") + fi + else + # Pass-through to the big-loop outside + return 1 + fi + fi +} + +# Add region_highlight entry (via `reply' array) +# +# This is a common place of adding such entry, but any above +# code can do it itself (and it does) and skip setting __style +# to disable this code. +[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") + +# We aren't passing-through, do obligatory things ourselves +(( this_word = next_word )) +_start_pos=$_end_pos + +return 0 diff --git "a/\342\206\222chroma/-precommand.ch" b/chroma/-precommand.ch old mode 100644 new mode 100755 similarity index 54% rename from "\342\206\222chroma/-precommand.ch" rename to chroma/-precommand.ch index 0a9211d..449801e --- "a/\342\206\222chroma/-precommand.ch" +++ b/chroma/-precommand.ch @@ -1,19 +1,19 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et + local __first_call="$1" __start_pos="$3" __end_pos="$4" [[ "$__arg_type" = 3 ]] && return 2 (( __first_call )) && { - (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ - && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}precommand]}") - (( next_word = (next_word & ~2) | 4 | 1 )) + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ + && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}precommand]}") + (( next_word = (next_word & ~2) | 4 | 1 )) } || { - return 1 + return 1 } (( this_word = next_word )) _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-printf.ch" b/chroma/-printf.ch old mode 100644 new mode 100755 similarity index 100% rename from "\342\206\222chroma/-printf.ch" rename to chroma/-printf.ch diff --git "a/\342\206\222chroma/-ruby.ch" b/chroma/-ruby.ch old mode 100644 new mode 100755 similarity index 100% rename from "\342\206\222chroma/-ruby.ch" rename to chroma/-ruby.ch diff --git "a/\342\206\222chroma/-scp.ch" b/chroma/-scp.ch old mode 100644 new mode 100755 similarity index 100% rename from "\342\206\222chroma/-scp.ch" rename to chroma/-scp.ch diff --git "a/\342\206\222chroma/-sh.ch" b/chroma/-sh.ch old mode 100644 new mode 100755 similarity index 100% rename from "\342\206\222chroma/-sh.ch" rename to chroma/-sh.ch diff --git a/chroma/-source.ch b/chroma/-source.ch new file mode 100755 index 0000000..ee7a529 --- /dev/null +++ b/chroma/-source.ch @@ -0,0 +1,72 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# +# Chroma for `source' builtin - verifies if file to be sourced compiles +# correctly. +# +# $1 - 0 or 1, denoting if it's first call to the chroma, or following one +# +# $2 - the current token, also accessible by $__arg from the above scope - +# basically a private copy of $__arg; the token can be eg.: "grep" +# +# $3 - a private copy of $_start_pos, i.e. the position of the token in the +# command line buffer, used to add region_highlight entry (see man), +# because Zsh colorizes by *ranges* in command line buffer +# +# $4 - a private copy of $_end_pos from the above scope +# + +(( next_word = 2 | 8192 )) + +local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" +local __style __chars __home=$FAST_WORK_DIR +integer __idx1 __idx2 + +# First call, i.e. command starts, i.e. "grep" token etc. +(( __first_call )) && { + FAST_HIGHLIGHT[chroma-src-counter]=0 + __style=${FAST_THEME_NAME}builtin + + } || { + + # Following call, i.e. not the first one. + # Check if chroma should end – test if token is of type + # "starts new command", if so pass-through – chroma ends + [[ "$__arg_type" = 3 ]] && return 2 + + if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then + return 1 + fi + + if [[ "$__wrd" = -* ]]; then + # Detected option, add style for it. + [[ "$__wrd" = --* ]] && \ + __style=${FAST_THEME_NAME}double-hyphen-option || __style=${FAST_THEME_NAME}single-hyphen-option + else + # Count non-option tokens. + (( FAST_HIGHLIGHT[chroma-src-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-src-counter] )) + if (( FAST_HIGHLIGHT[chroma-src-counter] == 1 )); then + command mkdir -p "$__home" + command cp -f "${__wrd}" "$__home" 2>/dev/null && { + zcompile "$__home"/"${__wrd:t}" 2>/dev/null 1>&2 && \ + __style=${FAST_THEME_NAME}correct-subtle || __style=${FAST_THEME_NAME}incorrect-subtle + } + elif (( FAST_HIGHLIGHT[chroma-src-counter] == 2 )); then + # Handle paths, etc. normally - just pass-through to the big highlighter (the main f-sy-h highlighter, used before chromas). + return 1 + fi + fi +} + +# Add region_highlight entry (via `reply' array). +# +# This is a common place of adding such entry, but any above +# code can do it itself (and it does) and skip setting __style +# to disable this code. +[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") + +# We aren't passing-through (no return 1 occurred), do obligatory things ourselves. +(( this_word = next_word )) +_start_pos=$_end_pos + +return 0 diff --git "a/\342\206\222chroma/-ssh.ch" b/chroma/-ssh.ch old mode 100644 new mode 100755 similarity index 97% rename from "\342\206\222chroma/-ssh.ch" rename to chroma/-ssh.ch index 6be459f..cec0d65 --- "a/\342\206\222chroma/-ssh.ch" +++ b/chroma/-ssh.ch @@ -1,4 +1,5 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # # Copyright (C) 2019 by Philippe Troin (F-i-f on GitHub) # @@ -16,8 +17,8 @@ # $4 - a private copy of $_end_pos from the above scope # -emulate -LR zsh -setopt extended_glob warn_create_global typeset_silent +builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace} +builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd # This chroma guards that port number isn't passed in hostname (no :{port} occurs). @@ -155,5 +156,3 @@ local -a match mbegin mend completions_users completions_host _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-subcommand.ch" b/chroma/-subcommand.ch old mode 100644 new mode 100755 similarity index 99% rename from "\342\206\222chroma/-subcommand.ch" rename to chroma/-subcommand.ch index 2e64851..36602bb --- "a/\342\206\222chroma/-subcommand.ch" +++ b/chroma/-subcommand.ch @@ -1,5 +1,6 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- -# +# vim: ft=zsh sw=2 ts=2 et + (( next_word = 2 | 8192 )) [[ "$__arg_type" = 3 ]] && return 2 @@ -24,5 +25,3 @@ fi _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-subversion.ch" b/chroma/-subversion.ch old mode 100644 new mode 100755 similarity index 91% rename from "\342\206\222chroma/-subversion.ch" rename to chroma/-subversion.ch index fc5ee47..6f38de7 --- "a/\342\206\222chroma/-subversion.ch" +++ b/chroma/-subversion.ch @@ -1,4 +1,5 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # # ------------------------------------------------------------------------------------------------- # Copyright (c) 2018 Sebastian Gniazdowski @@ -29,8 +30,8 @@ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ------------------------------------------------------------------------------------------------- -→chroma/-subversion.ch/parse-revision() { - setopt local_options extendedglob warn_create_global typeset_silent +chroma/-subversion.ch/parse-revision() { + builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd local_options local __wrd="$1" __start_pos="$2" __end_pos="$3" __style __start __end case $__wrd in (r|)[0-9]##) __style=${FAST_THEME_NAME}mathnum ;; @@ -41,8 +42,8 @@ (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") } -→chroma/-subversion.ch/parse-target() { - setopt local_options extendedglob warn_create_global typeset_silent +chroma/-subversion.ch/parse-target() { + builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd local_options local __wrd="$1" __start_pos="$2" __end_pos="$3" __style __start __end if [[ $__wrd == *@[^/]# ]] then @@ -56,13 +57,13 @@ fi (( __start=__start_pos-${#PREBUFFER}+$#place, __end=__end_pos-${#PREBUFFER}-$#rev, __start >= 0 )) \ && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-separator]}") - →chroma/-subversion.ch/parse-revision $rev $((__start_pos+$#place+1)) $__end_pos + chroma/-subversion.ch/parse-revision $rev $((__start_pos+$#place+1)) $__end_pos else return 1 fi } -setopt local_options extendedglob warn_create_global + builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd local_options # Keep chroma-takever state meaning: until ;, handle highlighting via chroma. # So the below 8192 assignment takes care that next token will be routed to chroma. @@ -180,21 +181,21 @@ integer __idx1 __idx2 || __style=${FAST_THEME_NAME}incorrect-subtle ;; revision) - →chroma/-subversion.ch/parse-revision $__wrd $__start_pos $__end_pos + chroma/-subversion.ch/parse-revision $__wrd $__start_pos $__end_pos ;; revision-pair) local -a match mbegin mend if [[ $__wrd = (#b)(\{[^}]##\}|[^:]##)(:)(*) ]]; then - →chroma/-subversion.ch/parse-revision $match[1] $__start_pos $(( __end_pos - ( mend[3]-mend[2] ) - 1 )) - →chroma/-subversion.ch/parse-revision $match[3] $(( __start_pos + ( mbegin[3]-mbegin[1] ) )) $__end_pos + chroma/-subversion.ch/parse-revision $match[1] $__start_pos $(( __end_pos - ( mend[3]-mend[2] ) - 1 )) + chroma/-subversion.ch/parse-revision $match[3] $(( __start_pos + ( mbegin[3]-mbegin[1] ) )) $__end_pos (( __start=__start_pos-${#PREBUFFER}+(mbegin[2]-mbegin[1]), __end=__end_pos-${#PREBUFFER}-(mend[3]-mend[2]), __start >= 0 )) \ && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-separator]}") else - →chroma/-subversion.ch/parse-revision $__wrd $__start_pos $__end_pos + chroma/-subversion.ch/parse-revision $__wrd $__start_pos $__end_pos fi ;; target) - →chroma/-subversion.ch/parse-target $__wrd $__start_pos $__end_pos || return $? + chroma/-subversion.ch/parse-target $__wrd $__start_pos $__end_pos || return $? ;; cmd) this_word=1 @@ -219,7 +220,7 @@ integer __idx1 __idx2 (( FAST_HIGHLIGHT[subversion-subcommand-arguments]+=1 )) if [[ ( $FAST_HIGHLIGHT[subversion-subcommand] == (checkout|co|export|log|merge|switch|sw) && $FAST_HIGHLIGHT[subversion-subcommand-arguments] -eq 1 ) \ || $FAST_HIGHLIGHT[subversion-subcommand] == (blame|praise|annotate|ann|cat|copy|cp|diff|info|list|ls|mergeinfo) ]]; then - →chroma/-subversion.ch/parse-target $__wrd $__start_pos $__end_pos || return $? + chroma/-subversion.ch/parse-target $__wrd $__start_pos $__end_pos || return $? else return 1 fi @@ -238,7 +239,7 @@ integer __idx1 __idx2 [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") # We aren't passing-through, do obligatory things ourselves. -# _start_pos=$_end_pos advainces pointers in command line buffer. +# _start_pos=$_end_pos advances pointers in command line buffer. # # To pass through means to `return 1'. The highlighting of # this single token is then done by fast-syntax-highlighting's @@ -247,5 +248,3 @@ integer __idx1 __idx2 _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-vim.ch" b/chroma/-vim.ch old mode 100644 new mode 100755 similarity index 95% rename from "\342\206\222chroma/-vim.ch" rename to chroma/-vim.ch index 9627043..134fa03 --- "a/\342\206\222chroma/-vim.ch" +++ b/chroma/-vim.ch @@ -1,4 +1,5 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # # Chroma for vim, shows last opened files under prompt. # @@ -41,10 +42,8 @@ local -a __viminfo # skip setting __style to disable this code. [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") -# We aren't passing-through (no return 1 occured), do obligatory things ourselves. +# We aren't passing-through (no return 1 occurred), do obligatory things ourselves. (( this_word = next_word )) _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-whatis.ch" b/chroma/-whatis.ch old mode 100644 new mode 100755 similarity index 91% rename from "\342\206\222chroma/-whatis.ch" rename to chroma/-whatis.ch index bfe7363..e2795a3 --- "a/\342\206\222chroma/-whatis.ch" +++ b/chroma/-whatis.ch @@ -1,27 +1,28 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- -# +# vim: ft=zsh sw=2 ts=2 et + (( next_word = 2 | 8192 )) local THEFD check __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4" local __style (( ! ${+FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]} )) && \ - FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]=0 + FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]=0 (( ! ${+FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]} )) && { - is-at-least 5.0.6 && local __res=1 || local __res=0 - FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]="$__res" + is-at-least 5.0.6 && local __res=1 || local __res=0 + FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]="$__res" } -fast-whatis-chroma-callback() { - emulate -L zsh - setopt extendedglob warncreateglobal typesetsilent + builtin emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace} + builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd - local THEFD="$1" input check=2 nl=$'\n' __wrd __style + local THEFD="$1" input check=2 nl=$'\n' __wrd __style - .fast-zts-read-all "$THEFD" input + .fast-zts-read-all "$THEFD" input - zle -F "$THEFD" - exec {THEFD}<&- + zle -F "$THEFD" + exec {THEFD}<&- __wrd="${${input#[^$nl]#$nl}%%$nl*}" if [[ "$input" = test* ]]; then @@ -133,5 +134,3 @@ fi _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-which.ch" b/chroma/-which.ch old mode 100644 new mode 100755 similarity index 99% rename from "\342\206\222chroma/-which.ch" rename to chroma/-which.ch index a7209c0..b0dc082 --- "a/\342\206\222chroma/-which.ch" +++ b/chroma/-which.ch @@ -1,4 +1,5 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # # Outputs (under prompt) result of query done with `which', `type -w', # `whence -v', `whereis', `whatis'. @@ -91,5 +92,3 @@ local -a __results _start_pos=$_end_pos return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git "a/\342\206\222chroma/-zi.ch" b/chroma/-zi.ch old mode 100644 new mode 100755 similarity index 82% rename from "\342\206\222chroma/-zi.ch" rename to chroma/-zi.ch index 4af0adb..7019664 --- "a/\342\206\222chroma/-zi.ch" +++ b/chroma/-zi.ch @@ -1,4 +1,5 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et # # Chroma function for command `zi'. It colorizes the part of command line that holds `zi' invocation. @@ -15,7 +16,7 @@ fsh__zi__chroma__def=( subcmd:NULL "NULL_0_opt" NULL_0_opt "(-help|--help|-h) - <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" "subcommands" "(help|subcmds|icemods|analytics|man|self-update|times|zstatus|load|light|unload|snippet|ls|ice||update|status|report|delete|loaded|list|cd|create|edit|glance|stress|changes|recently|clist|completions|cclear|cdisable|cenable|creinstall|cuninstall|csearch|compinit|dtrace|dstart|dstop|dunload|dreport|dclear|compile|uncompile|compiled|cdlist|cdreplay|cdclear|srv|recall|env-whitelist|bindkeys|module|add-fpath|run)" ## }}} @@ -32,7 +33,7 @@ fsh__zi__chroma__def=( subcmd:ice "ICE_#_arg // NO_MATCH_#_opt" - "ICE_#_arg" "NO-OP // ::→chroma/-zi-check-ice-mod" + "ICE_#_arg" "NO-OP // ::chroma/-zi-check-ice-mod" ## ## `snippet' @@ -42,9 +43,9 @@ fsh__zi__chroma__def=( subcmd:snippet "SNIPPET_0_opt // SNIPPET_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" SNIPPET_0_opt "(-h|--help|-f|--force|--command|-x) - <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" - SNIPPET_1_arg "NO-OP // ::→chroma/-zi-verify-snippet" + SNIPPET_1_arg "NO-OP // ::chroma/-zi-verify-snippet" ## }}} @@ -55,9 +56,9 @@ fsh__zi__chroma__def=( "subcmd:load" "LOAD_1_arg // LOAD_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" - LOAD_1_arg "NO-OP // ::→chroma/-zi-verify-plugin" + LOAD_1_arg "NO-OP // ::chroma/-zi-verify-plugin" - LOAD_2_arg "NO-OP // ::→chroma/-zi-verify-plugin" + LOAD_2_arg "NO-OP // ::chroma/-zi-verify-plugin" ## }}} @@ -69,9 +70,9 @@ fsh__zi__chroma__def=( "subcmd:(compile|uncompile|stress|edit|glance|recall|status|cd|changes)" "PLGSNP_1_arg // PLGSNP_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" - PLGSNP_1_arg "NO-OP // ::→chroma/-zi-verify-plugin-or-snippet" + PLGSNP_1_arg "NO-OP // ::chroma/-zi-verify-plugin-or-snippet" - PLGSNP_2_arg "NO-OP // ::→chroma/-zi-verify-plugin-or-snippet" + PLGSNP_2_arg "NO-OP // ::chroma/-zi-verify-plugin-or-snippet" ## }}} @@ -84,7 +85,7 @@ fsh__zi__chroma__def=( UPDATE_0_opt " (-L|--plugins|-s|--snippets|-p|--parallel|-a|--all|-q|--quiet|-r|--reset|-u|--urge|-n|--no-pager|-v|--verbose|-h|--help) - <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" ## }}} @@ -96,7 +97,7 @@ fsh__zi__chroma__def=( subcmd:light "LIGHT_0_opt // LOAD_1_arg // LOAD_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" LIGHT_0_opt "-h|--help|-b - <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" ## }}} @@ -108,11 +109,11 @@ fsh__zi__chroma__def=( subcmd:unload "UNLOAD_0_opt // UNLOAD_1_arg // UNLOAD_2_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" UNLOAD_0_opt "-h|--help|-q|--quiet - <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" - UNLOAD_1_arg "NO-OP // ::→chroma/-zi-verify-loaded-plugin" + UNLOAD_1_arg "NO-OP // ::chroma/-zi-verify-loaded-plugin" - UNLOAD_2_arg "NO-OP // ::→chroma/-zi-verify-loaded-plugin" + UNLOAD_2_arg "NO-OP // ::chroma/-zi-verify-loaded-plugin" ## }}} @@ -125,7 +126,7 @@ fsh__zi__chroma__def=( NO_MATCH_#_arg" REPORT_0_opt "--all - <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" ## }}} @@ -139,7 +140,7 @@ fsh__zi__chroma__def=( DELETE_0_opt " (-a|--all|-c|--clean|-y|--yes|-q|--quiet|-h|--help) - <<>> NO-OP // ::→chroma/main-chroma-std-aopt-action" + <<>> NO-OP // ::chroma/main-chroma-std-aopt-action" ## }}} @@ -150,7 +151,7 @@ fsh__zi__chroma__def=( subcmd:cenable "COMPLETION_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" - COMPLETION_1_arg "NO-OP // ::→chroma/-zi-verify-disabled-completion" + COMPLETION_1_arg "NO-OP // ::chroma/-zi-verify-disabled-completion" ## }}} @@ -161,7 +162,7 @@ fsh__zi__chroma__def=( subcmd:cdisable "DISCOMPLETION_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" - DISCOMPLETION_1_arg "NO-OP // ::→chroma/-zi-verify-completion" + DISCOMPLETION_1_arg "NO-OP // ::chroma/-zi-verify-completion" ## }}} @@ -173,7 +174,7 @@ fsh__zi__chroma__def=( subcmd:uncompile "UNCOMPILE_1_arg // NO_MATCH_#_opt // NO_MATCH_#_arg" - UNCOMPILE_1_arg "NO-OP // ::→chroma/-zi-verify-compiled-plugin" + UNCOMPILE_1_arg "NO-OP // ::chroma/-zi-verify-compiled-plugin" ## }}} @@ -183,17 +184,17 @@ fsh__zi__chroma__def=( ## {{{ "subcmd:*" "CATCH_ALL_#_opt" - "CATCH_ALL_#_opt" "* <<>> NO-OP // ::→chroma/main-chroma-std-aopt-SEMI-action" + "CATCH_ALL_#_opt" "* <<>> NO-OP // ::chroma/main-chroma-std-aopt-SEMI-action" ## }}} ) -#→chroma/-zi-first-call() { +#chroma/-zi-first-call() { # This is being done in the proper place - in -fast-highlight-process #FAST_HIGHLIGHT[chroma-zi-ice-elements-svn]=0 #} -→chroma/-zi-verify-plugin() { +chroma/-zi-verify-plugin() { local _scmd="$1" _wrd="$4" [[ -d "$_wrd" ]] && { __style=${FAST_THEME_NAME}correct-subtle; return 0; } @@ -209,12 +210,12 @@ fsh__zi__chroma__def=( return 0 } -→chroma/-zi-verify-plugin-or-snippet() { - →chroma/-zi-verify-plugin "$1" "" "" "$4" || →chroma/-zi-verify-snippet "$1" "" "" "$4" +chroma/-zi-verify-plugin-or-snippet() { + chroma/-zi-verify-plugin "$1" "" "" "$4" || chroma/-zi-verify-snippet "$1" "" "" "$4" return $? } -→chroma/-zi-verify-loaded-plugin() { +chroma/-zi-verify-loaded-plugin() { local _scmd="$1" _wrd="$4" typeset -a plugins absolute1 absolute2 absolute3 normal plugins=( "${ZI_REGISTERED_PLUGINS[@]:#_local/zi}" ) @@ -234,7 +235,7 @@ fsh__zi__chroma__def=( return 0 } -→chroma/-zi-verify-completion() { +chroma/-zi-verify-completion() { local _scmd="$1" _wrd="$4" # Find enabled completions typeset -a completions @@ -248,7 +249,7 @@ fsh__zi__chroma__def=( return 0 } -→chroma/-zi-verify-disabled-completion() { +chroma/-zi-verify-disabled-completion() { local _scmd="$1" _wrd="$4" # Find enabled completions typeset -a completions @@ -261,7 +262,7 @@ fsh__zi__chroma__def=( return 0 } -→chroma/-zi-verify-compiled-plugin() { +chroma/-zi-verify-compiled-plugin() { local _scmd="$1" _wrd="$4" typeset -a plugins @@ -283,7 +284,7 @@ fsh__zi__chroma__def=( return 1 } -→chroma/-zi-verify-snippet() { +chroma/-zi-verify-snippet() { local _scmd="$1" url="$4" dirname local_dir url="${${url#"${url%%[! $'\t']*}"}%/}" id_as="${FAST_HIGHLIGHT[chroma-zi-ice-elements-id-as]:-${ZI_ICE[id-as]:-$url}}" @@ -307,7 +308,7 @@ fsh__zi__chroma__def=( } } -→chroma/-zi-check-ice-mod() { +chroma/-zi-check-ice-mod() { local _scmd="$1" _wrd="$4" [[ "$_wrd" = (svn(\'|\")*|svn) ]] && FAST_HIGHLIGHT[chroma-zi-ice-elements-svn]=1 [[ "$_wrd" = (#b)(id-as(:|)(\'|\")(*)(\'|\")|id-as:(*)|id-as(*)) ]] && \ @@ -346,5 +347,3 @@ fsh__zi__chroma__def=( } return 0 - -# vim: ft=zsh sw=2 ts=2 et diff --git a/chroma/main-chroma.ch b/chroma/main-chroma.ch new file mode 100755 index 0000000..90da55d --- /dev/null +++ b/chroma/main-chroma.ch @@ -0,0 +1,439 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# +# Main chroma function. It allows to create the command-dedicated chromas +# (like -git.ch) through a definition provided by `chroma_def' array (read +# from the upper scope). +# +# $1 - 0 or 1, denoting if it's first call to the chroma, or following one +# $2 - the current token, also accessible by $__arg from the above scope - +# basically a private copy of $__arg +# $3 - a private copy of $_start_pos, i.e. the position of the token in the +# command line buffer, used to add region_highlight entry (see man), +# because Zsh colorizes by *ranges* in command line buffer +# $4 - a private copy of $_end_pos from the above scope +# + +(( next_word = 2 | 8192 )) + +chroma/main-chroma-print() { + (( FAST_HIGHLIGHT[DEBUG] )) && print "$@" >> /tmp/fsh-dbg +} + +local __chroma_name="${1#\%}" __first_call="$2" __wrd="$3" __start_pos="$4" __end_pos="$5" + +# Not a well formed chroma name +[[ -z "$__chroma_name" ]] && return 1 + +# Load the fsh_{name-of-the-chroma}_chroma_def array +(( !FAST_HIGHLIGHT[-${__chroma_name}.ch-chroma-def] )) && chroma/-${__chroma_name}.ch + +chroma/main-chroma-print -r -- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +chroma/main-chroma-print -r -- @@@@@@@ local __chroma_name="${1#\%}" __first_call="$2" __wrd="$3" __start_pos="$4" __end_pos="$5" @@@@@@@ +local __style __entry __value __action __handler __tmp __svalue __hspaces=$'\t ' __nl=$'\n' __ch_def_name +integer __idx1 __idx2 __start __end __ivalue __have_value=0 +local -a __lines_list __avalue +local -A map +map=( "#" "_H" "^" "_D" "*" "_S" ) + +(( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN )) + +# Handler that highlights the options +chroma/main-chroma-std-aopt-action() { + integer _start="$2" _end="$3" + local _scmd="$1" _wrd="$4" + + [[ "$_wrd" = (#b)(--[a-zA-Z0-9_-]##)=(*) ]] && { + reply+=("$_start $(( _end - mend[2] + mbegin[2] - 1 )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-hyphen-option]}") + } || { +[[ "$_wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ + __style=${FAST_THEME_NAME}single-hyphen-option + } +} + +# Handler that highlights the options' arguments +chroma/main-chroma-std-aopt-ARG-action() { + integer _start="$2" _end="$3" + local _scmd="$1" _wrd="$4" + + [[ "$_wrd" = (#b)(--[a-zA-Z0-9_-]##)=(*) ]] && { + reply+=("$(( _start + 1 + mend[1] )) $_end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}optarg-${${${(M)match[2]:#<->}:+number}:-string}]}") + } || __style=${FAST_THEME_NAME}optarg-${${${(M)_wrd:#(-|)<->}:+number}:-string} +} + +# This handler also highlights explicit arguments, i.e. --opt=the-explicit-arg +chroma/main-chroma-std-aopt-SEMI-action() { + integer _start="$2" _end="$3" + local _scmd="$1" _wrd="$4" + + [[ "$_wrd" = (#b)(--[a-zA-Z0-9_-]##)=(*) ]] && { + reply+=("$_start $(( _end - mend[2] + mbegin[2] - 1 )) ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-hyphen-option]}") + reply+=("$(( _start + 1 + mend[1] )) $_end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}optarg-${${${(M)match[2]:#<->}:+number}:-string}]}") + } || { + [[ "$_wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \ + __style=${FAST_THEME_NAME}single-hyphen-option + } +} + +# A handler which verifies the token as an GIT url +chroma/main-chroma-std-verify-url() { + setopt localoptions extendedglob + local _wrd="$4" + integer url_correct=0 + # Correct matches + # Correct matches + if [[ "$_wrd" = (#b)(git|http|https|ftp|ftps|file)://([a-zA-Z0-9._~-]##)(:[0-9]##)(#c0,1)(/([a-zA-Z0-9./_~:-]##))(#c0,1) ]]; then + url_correct=1 + elif [[ "$_wrd" = (#b)rsync://([a-zA-Z0-9._~-]##)(/([a-zA-Z0-9./_~:-]##))(#c0,1) ]]; then + url_correct=1 + elif [[ "$_wrd" = (#b)ssh://([a-zA-Z0-9._~-]##@)(#c0,1)([a-zA-Z0-9._~-]##)(:[0-9]##)(#c0,1)(/([a-zA-Z0-9./_~:-]##))(#c0,1) ]]; then + url_correct=1 + elif [[ "$_wrd" = (#b)([a-zA-Z0-9._~-]##@)(#c0,1)([a-zA-Z0-9._~-]##):([a-zA-Z0-9./_~:-](#c0,1)[a-zA-Z0-9._~:-][a-zA-Z0-9./_~:-]#)(#c0,1) ]]; then + url_correct=1 + elif [[ "$_wrd" = (#b)[[:alnum:]/_~:.-]## ]]; then + url_correct=1 + fi + + (( url_correct )) && \ + { __style=${FAST_THEME_NAME}correct-subtle; return 0; } || \ + { __style=${FAST_THEME_NAME}incorrect-subtle; return 1; } +} + +# A handler which verifies the token as a shell wildcard +chroma/main-chroma-std-verify-pattern() { + setopt localoptions extendedglob + local _wrd="$4" + __style=${FAST_THEME_NAME}globbing-ext +} + +# Creates a hash table for given option set (an *_opt field in the chroma def.) +chroma/main-create-OPTION-hash.ch() { + local __subcmd="$1" __option_set_id="$2" __the_hash_name="$3" __ __e __el __the_hash_name __var_name + local -a __split __sp __s + + chroma/main-chroma-print -rl "======================" " **## STARTING ##** chroma/main-##CREATE##-option-HASH.ch // subcmd:$__subcmd // option_set_id:$__option_set_id // h-nam:$__the_hash_name" + chroma/main-chroma-print "[D] Got option-set: ${(j:,:)__option_set_id}" + typeset -gA "$__the_hash_name" + chroma/main-chroma-print "[E] __the_hash_name ${__the_hash_name}:[$__option_set_id]" + + # Split on || + __ch_def_name="fsh__${__chroma_name}__chroma__def[${__option_set_id}]" + __split=( "${(P@s:||:)__ch_def_name}" ) + [[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && __split=() + # Remove only leading and trailing whitespace + __split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + + chroma/main-chroma-print -rl "[F] Got ||-__split: _________" ${${(@)${${__split[@]##[[:space:]]##}[@]//[${__hspaces}]##/ }[@]//[${__nl}]##/$__nl}[@]//(#s)/:::} "_________" + for __el in $__split; do + __sp=( "${(@s:<<>>:)__el}" ) + [[ ${#__sp} -eq 1 && -z "${__sp[1]}" ]] && __sp=() + __sp=( "${__sp[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + chroma/main-chroma-print -l -- "Processing an ||-part - got <<>>-split: _________" "${${__sp[@]}[@]/(#s)/-\\t}" "_________" + __e="${__sp[1]}" + local __e1=${${__e#\(}%\)(:add|:del|)} + local __e2=${(M)__e##\(*\)(:add|:del)} + # Split on | with the ( and ) and :add/:del stripped and then append + # the :add or :del depending on what's on the input line + __s=() + for __ in ${(@s:|:)__e1}; do + __s+=( $__${__e2:+${(M)__e%(:add|:del)}} ) + done + [[ ${#__s} -eq 1 && -z "${__s[1]}" ]] && __s=() + __s=( "${__s[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + shift __sp + for __ in $__s; do + __=${__%\^} + [[ "$__" = -*:(add|del) ]] && __var_name="${__the_hash_name}[${__}-directive]" || __var_name="${__the_hash_name}[${__}-opt-action]" + chroma/main-chroma-print "${(r:70:: :):-${__var_name}} := >>${__sp[1]}${${${#__sp}:#(0|1)}:+ +}<<" + : ${(P)__var_name::=${__sp[1]}${${${#__sp}:#(0|1)}:+ +}} + if (( ${#__sp} >= 2 )); then + __var_name="${__the_hash_name}[${__}-opt-arg-action]" + chroma/main-chroma-print "${(r:70:: :):-${__var_name}} := >>${__sp[2]}<<}" + : ${(P)__var_name::=$__sp[2]} + fi + done + done +} + +# Processes given token +chroma/main-process-token.ch() { + local __subcmd="$1" __wrd="$2" __val __var_name __main_hash_name __the_hash_name __i __size + local -a __splitted __split __added + + chroma/main-chroma-print "\n******************* Starting chroma/main-process-token <<$__wrd>>// subcmd:${(qq)__subcmd}" + __main_hash_name="fsh__chroma__main__${${FAST_HIGHLIGHT[chroma-current]//[^a-zA-Z0-9_]/_}//(#b)([\#\^\*])/${map[${match[1]}]}}" + __var_name="${__main_hash_name}[subcmd:$__subcmd]" + __splitted=( "${(@s://:P)__var_name}" ) + [[ ${#__splitted} -eq 1 && -z "${__splitted[1]}" ]] && __splitted=() + __splitted=( "${__splitted[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + + chroma/main-chroma-print -rl -- "[B] MAIN-PROCESS-TOKEN: got [OPTION/ARG-**S-E-T-S**] //-splitted from subcmd:$__subcmd: ${${(j:, :)__splitted}:-EMPTY-SET!}" "----- __splitted\\Deleted: -----" ${${(j:, :)${__splitted[@]:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})}}:-EMPTY-SET (deleted)!} "----- Added\\Deleted: -----" ${${(j:, :)${${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]}:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})}}:-EMPTY-SET (added)!} -----\ Deleted:\ ----- ${(j:, :)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}} >> /tmp/reply + + (( ! ${#__splitted} )) && { + __var_name="${__main_hash_name}[subcmd:*]" + __splitted=( "${(@s://:P)__var_name}" ) + [[ ${#__splitted} -eq 1 && -z "${__splitted[1]}" ]] && __splitted=() + __splitted=( "${__splitted[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + (( ! ${#__splitted} )) && return 1 + } + + chroma/main-chroma-print -rl -- "---NO-HASH-CREATE-FROM-NOW-ON---" + + if [[ -z "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]}" ]]; then + chroma/main-chroma-print -rl -- "-z OPT-WITH-ARG-ACTIVE == true" + if [[ "$__wrd" = -* ]]; then + chroma/main-chroma-print "1st-PATH (-z opt-with-arg-active, non-opt-arg branch, i.e. OPTION BRANCH) [#${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}]" + for __val in ${__splitted[@]:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})} ${${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]}:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})}; do + [[ "${__val}" != "${__val%%_([0-9]##|\#)##*}"_${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}_opt(\*|\^|) && "${__val}" != "${__val%%_([0-9]##|\#)*}"_"#"_opt(\*|\^|) ]] && { chroma/main-chroma-print "DIDN'T MATCH $__val / arg counter:${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}" ; continue; } || chroma/main-chroma-print "Got candidate: $__val" + # Create the hash cache-parameter if needed + __the_hash_name="fsh__chroma__${FAST_HIGHLIGHT[chroma-current]//[^a-zA-Z0-9_]/_}__${__subcmd//[^a-zA-Z0-9_]/_}__${${__val//(#b)([\#\^\*])/${map[${match[1]}]}}//[^a-zA-Z0-9_]/_}" + [[ "$__val" = *_opt(\*|\^|) && "${(P)+__the_hash_name}" -eq 0 ]] && chroma/main-create-OPTION-hash.ch "$__subcmd" "$__val" "$__the_hash_name" || chroma/main-chroma-print "Not creating, the hash already exists..." + # Try dedicated-entry for the option + __var_name="${__the_hash_name}[${${${${(M)__wrd#?*=}:+${__wrd%=*}=}:-$__wrd}}-opt-action]" + __split=( "${(@s://:P)__var_name}" ) + [[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && __split=() + # If no result, then try with catch-all entry + (( ! ${#__split} )) && { + chroma/main-chroma-print "% no ${(q-)${${${(M)__wrd#?*=}:+${__wrd%=*}=}:-$__wrd}}-opt-action, retrying with *-opt-action" "|__var_name|:$__var_name" + __var_name="${__the_hash_name}[*-opt-action]" + __split=( "${(@s://:P)__var_name}" ) + [[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && __split=() + } + __svalue="$__var_name" + # Remove whitespace + __split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + chroma/main-chroma-print -l -- "\`$__val' // ${#__split} // $__wrd: (ch.run #${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr]}), deref. of \`$__var_name'" + if (( ${#__split} )); then + chroma/main-chroma-print -l -- "Got split of {\$#__split:$#__split} ${__wrd}-opt-action or *-opt-action" "${${(q-)__split[@]}[@]/(#s)/->\\t}" + if [[ "${__split[2]}" = *[[:blank:]]+ ]]; then + chroma/main-chroma-print "YES handling the value (the OPT.ARGUMENT)! [${__split[2]}]" + if [[ "$__wrd" = *=* ]]; then + chroma/main-chroma-print "The-immediate Arg-Acquiring, of option" + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]="${__svalue%-opt-action\]}-opt-arg-action]" + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-arg]="${__wrd#*=}" + __have_value=2 + else + chroma/main-chroma-print "Enable Arg-Awaiting, of option" + chroma/main-chroma-print "FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]=\"${__svalue%-opt-action\]}-opt-arg-action]\"" + __have_value=0 + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]="${__svalue%-opt-action\]}-opt-arg-action]" + fi + fi + __action="${__split[1]}" + __handler="${__split[2]%[[:blank:]]+}" + # Check for directives (like :add) + if [[ "$__val" = *_opt\^ ]]; then + __var_name="${__the_hash_name}[${${${${(M)__wrd#?*=}:+${__wrd%=*}=}:-$__wrd}}:add-directive]" + (( ${(P)+__var_name} )) && __split=( "${(@s://:P)__var_name}" ) || __split=() + [[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && __split[1]=() + __ivalue=${#__split} + __var_name="${__var_name%:add-*}:del-directive]" + (( ${(P)+__var_name} )) && __split+=( "${(@s://:P)__var_name}" ) + [[ ${#__split} -eq $(( __ivalue + 1 )) && -z "${__split[__ivalue+1]}" ]] && __split[__ivalue+1]=() + __split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + __tmp=${#__split} + # First: del-directive + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]+="${(j: :)__split[__ivalue+1,__tmp]} " + chroma/main-chroma-print -rl ":add / :del directives: __ivalue:$__ivalue, THE __SPLIT[#$__tmp]: " "${__split[@]}" "//" "The FAST_HIGHLIGHT[chroma-*deleted-nodes]: " ${=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]} >> /tmp/reply + # Second: add-directive + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]+="${(j: :)__split[1,__ivalue]} " + fi + [[ "$__handler" = ::[^[:space:]]* ]] && __handler="${__handler#::}" || __handler="" + [[ -n "$__handler" && "$__handler" != "NO-OP" ]] && { chroma/main-chroma-print -rl -- "Running handler(1): $__handler" ; "$__handler" "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]:-NULL}" "$__start" "$__end" "$__wrd"; } + [[ "$__have_value" -ne 2 && -n "$__action" && "$__action" != "NO-OP" ]] && { chroma/main-chroma-print -rl "Running action (1): $__action" ; eval "() { $__action; }"; } + [[ "$__val" != *\* ]] && break + else + chroma/main-chroma-print -rl -- "NO-MATCH ROUTE TAKEN" + fi + done + else + chroma/main-chroma-print "1st-PATH-B (-z opt-with-arg-active, non-opt-arg branch, ARGUMENT BRANCH [#${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}]) //// added-nodes: ${=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]}" + for __val in ${__splitted[@]:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})} ${${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]}:#(${(~j:|:)${(@)=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}})}; do + [[ "${__val}" != "${__val%%_([0-9]##|\#)*}"_"${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}"_arg(\*|\^|) && "${__val}" != "${__val%%_([0-9]##|\#)*}"_"#"_arg(\*|\^|) ]] && { chroma/main-chroma-print "Continuing for $__val / arg counter ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}" ; continue } + # Create the hash cache-parameter if needed + __the_hash_name="fsh__chroma__${FAST_HIGHLIGHT[chroma-current]//[^a-zA-Z0-9_]/_}__${__subcmd//[^a-zA-Z0-9_]/_}__${${__val//\#/H}//[^a-zA-Z0-9_]/_}" + __action="" __handler="" + chroma/main-chroma-print "A hit, chosen __val:$__val!" + __ch_def_name="fsh__${__chroma_name}__chroma__def[$__val]" + __split=( "${(P@s:<<>>:)__ch_def_name}" ) + __split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + __sp=( "${(@s://:)__split[1]}" ) + __sp=( "${__sp[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + __action="${__sp[1]#*::::: ##}" + # Verify if it's the expected argument + [[ "${__sp[1]}" = *:::::* && "$__wrd" != ${~${__sp[1]%% ##:::::*}} ]] && \ + { chroma/main-chroma-print -r "mismatch ${__sp[1]%% ##:::::*} != $__wrd, continuing" ; continue; } + chroma/main-chroma-print -l -- "Got action record for $__val, i.e. the split:" "${__sp[@]//(#s)/-\t}" "_________" + [[ "${__sp[2]}" = ::[^[:space:]]* ]] && __handler="${__sp[2]#::}" || { [[ -n "$__handler" && "$__handler" != "NO-OP" ]] && chroma/main-chroma-print "=== Error === In chroma definition: a handler entry ${(q)__sp[2]} without leading \`::'" ; } + [[ -n "$__handler" && "$__handler" != "NO-OP" ]] && { chroma/main-chroma-print -rl -- "Running handler(3): $__handler" ; "$__handler" "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]:-NULL}" "$__start" "$__end" "$__wrd"; } + [[ -n "$__action" && "$__action" != "NO-OP" ]] && { chroma/main-chroma-print -rl -- "Running action(3): $__action" ; eval "() { $__action; } \"${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]:-NULL}\" \"$__start\" \"$__end\" \"$__wrd\""; } + # Check for argument directives (like :add) + if (( ${#__split} >= 2 )); then + for __ in "${(@)__split[2,-1]}"; do + __splitted=( "${(@s://:)__}" ) + if [[ "${__splitted[1]}" = add:* ]]; then + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]+="${__splitted[1]#add:} ${(j: :)__splitted[2,-1]} " + elif [[ "${__splitted[1]}" = del:* ]]; then + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]+="${__splitted[1]#del:} ${(j: :)__splitted[2,-1]} " + fi + done + chroma/main-chroma-print -l "ARGUMENT :add / :del directives: THE __SPLIT[#${#__split}]: " "${__split[@]//(#s)/-\\t}" "//" "The FAST_HIGHLIGHT[chroma-*deleted-nodes]: " ${(@)${=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]}//(#s)/-\\t} "The FAST_HIGHLIGHT[chroma-*added-nodes]: " ${(@)${=FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]}//(#s)/-\\t} + fi + [[ "$__val" != *\* ]] && break + done + fi + else + chroma/main-chroma-print -- "2nd-PATH (-n opt-with-arg-active) NON-EMPTY arg-active:\nThe actual opt-val <<< \$__wrd:$__wrd >>> store (after the \`Arg-Awaiting' in the chroma-run: #$(( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr]-1 )) [current: #$(( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr] ))])" + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-arg]="$__wrd" + __have_value=1 + fi + # Execute the action if not during simulated opt-argument (--opt=...) + chroma/main-chroma-print "** BEFORE: \`if (( __have_value ))'" + if (( __have_value )); then + chroma/main-chroma-print "In the \`if (( __have_value ))' [have_value: $__have_value]" + # Split + __var_name="${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]}" + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]="" + __split=( "${(@s://:P)__var_name}" ) + [[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && { chroma/main-chroma-print -rl "NULL at __var_name:$__var_name" ; __split=(); } + __split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + # Remember 1st level action + (( __have_value == 2 )) && __value="$__action" || __value="" + if (( ${#__split} )); then + chroma/main-chroma-print -l -- "Got //-split (3, for opt-ARG-action, from [$__var_name]):" "${${(q-)__split[@]}[@]/(#s)/+\\t}" + __action="${__split[1]}" + __handler="${__split[2]}" + [[ "$__handler" = ::[^[:space:]]* ]] && __handler="${__handler#::}" + [[ -n "$__handler" && "$__handler" != "NO-OP" ]] && \ + {chroma/main-chroma-print -rl -- "Running handler(2): $__handler" ; "$__handler" "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]:-NULL}" "$__start" "$__end" "$__wrd"; } + [[ -n "$__action" && "$__action" != "NO-OP" ]] && \ + { chroma/main-chroma-print -rl -- "Running action(2): $__action" ; eval "$__action"; } + chroma/main-chroma-print -rl -- "The __action value: [$__value]" + [[ "$__have_value" -eq 2 && -n "$__value" && "$__value" != "NO-OP" ]] && \ + { chroma/main-chroma-print -rl "Running action (of 1, at 2): $__value" ; eval "$__value"; } + fi + fi + chroma/main-chroma-print -- "_________ Exiting chroma/main-process-token.ch $__subcmd / $__wrd _________" +} + +# Iterates over the chroma def. fields and creates initial +# fields in the fsh__${__chroma_name}__chroma__def hash +chroma/-pre_process_chroma_def.ch() { + local __key __value __ke _val __the_hash_name="$1" __var_name + local -a __split + + chroma/main-chroma-print -rl -- "Starting PRE_PROCESS for __the_hash_name:$__the_hash_name" + + __ch_def_name="fsh__${__chroma_name}__chroma__def[subcommands]" + local __subcmds="${(P)__ch_def_name}" + if [[ "$__subcmds" = "::"* ]]; then + ${__subcmds#::} + __var_name="${__the_hash_name}[subcommands]" + : ${(P)__var_name::=(${(j:|:)reply})} + else + __var_name="${__the_hash_name}[subcommands]" + : ${(P)__var_name::=$__subcmds} + fi + chroma/main-chroma-print "Got SUBCOMMANDS: ${(P)__var_name}" + + __ch_def_name="fsh__${__chroma_name}__chroma__def[subcmd-hook]" + local __subcmd_hook="${(P)__ch_def_name}" + if [[ -n "$__subcmd_hook" ]]; then + __var_name="${__the_hash_name}[subcmd-hook]" + : ${(P)__var_name::=$__subcmd_hook} + fi + + __ch_def_name="fsh__${__chroma_name}__chroma__def[(I)subcmd:*]" + for __key in "${(P@)__ch_def_name}"; do + __split=( "${(@s:|:)${${__key##subcmd:\((#c0,1)}%\)}}" ) + [[ ${#__split} -eq 1 && -z "${__split[1]}" ]] && __split=() + __split=( "${__split[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + for __ke in "${__split[@]}"; do + __var_name="${__the_hash_name}[subcmd:$__ke]" + __ch_def_name="fsh__${__chroma_name}__chroma__def[$__key]" + : ${(P)__var_name::=${(P)__ch_def_name}} + chroma/main-chroma-print -rl -- "Stored ${__var_name}=chroma_def[$__key], i.e. = ${(P)__ch_def_name}" + done + done +} + +if (( __first_call )); then + chroma/-${__chroma_name}-first-call + FAST_HIGHLIGHT[chroma-current]="$__wrd" + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]=0 + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-got-subcommand]=0 + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]="" + FAST_HIGHLIGHT[chrome-${FAST_HIGHLIGHT[chroma-current]}-occurred-double-hyphen]=0 + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]="" + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-arg]="" + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr]=1 + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-added-nodes]="" + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-deleted-nodes]="" + __the_hash_name="fsh__chroma__main__${${FAST_HIGHLIGHT[chroma-current]//[^a-zA-Z0-9_]/_}//(#b)([\#\^])/${map[${match[1]}]}}" + (( 0 == ${(P)+__the_hash_name} )) && { + typeset -gA "$__the_hash_name" + chroma/-pre_process_chroma_def.ch "$__the_hash_name" + } || chroma/main-chroma-print "...No... [\${+$__the_hash_name} ${(P)+__the_hash_name}]" + return 1 +else + (( ++ FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr] )) + # Following call, i.e. not the first one + # Check if chroma should end – test if token is of type + # "starts new command", if so pass-through – chroma ends + [[ "$__arg_type" = 3 ]] && return 2 + chroma/main-chroma-print "== @@ Starting @@ #${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-call-nr]} Main-Chroma-call == // << __WORD:$__wrd >> ## Subcommand: ${${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]}:-NULL} //@@// -n option-with-arg-active:${(q-)FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]}" + if [[ "$__wrd" = -* || -n "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-option-with-arg-active]}" + ]]; then + chroma/main-chroma-print "## The \`if -*' i.e. \`IF OPTION' MAIN branch" + chroma/main-process-token.ch "${${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]}:-NULL}" "$__wrd" + else + # If at e.g. '>' or destination/source spec (of the redirection) + if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then + return 1 + elif (( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-got-subcommand] == 0 )) { + __the_hash_name="fsh__chroma__main__${${FAST_HIGHLIGHT[chroma-current]//[^a-zA-Z0-9_]/_}//(#b)([\#\^])/${map[${match[1]}]}}" + __var_name="${__the_hash_name}[subcommands]" + if [[ "$__wrd" = ${(P)~__var_name} ]]; then + chroma/main-chroma-print "GOT-SUBCOMMAND := $__wrd, subcmd verification / OK" + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-got-subcommand]=1 + FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]="$__wrd" + __var_name="${__the_hash_name}[subcmd-hook]" + (( ${(P)+__var_name} )) && { chroma/main-chroma-print -r -- "Running subcmd-hook: ${(P)__var_name}" ; "${(P)__var_name}" "$__wrd"; } + __style="${FAST_THEME_NAME}subcommand" + else + chroma/main-chroma-print "subcmd verif / NOT OK; Incrementing the COUNTER-ARG ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]} -> $(( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg] + 1 ))" >> /tmp/fsh-dbg + (( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg] += 1 )) + chroma/main-chroma-print "UNRECOGNIZED ARGUMENT ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}" + chroma/main-process-token.ch "${${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]}:-NULL}" "$__wrd" + fi + } else { + __wrd="${__wrd//\`/x}" + __arg="${__arg//\`/x}" + __wrd="${(Q)__wrd}" + local __tmp_def_name="fsh__${__chroma_name}__chroma__def[subcommands-blacklist]" + if [[ ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]} = \ + (${(~j:|:)${(@s:,:)${(PA)__tmp_def_name}}}) + ]] { + return 1 + } + chroma/main-chroma-print "Incrementing the COUNTER-ARG ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]} -> $(( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg] + 1 ))" + (( FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg] += 1 )) + chroma/main-chroma-print "ARGUMENT ${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-counter-arg]}" + chroma/main-chroma-print "ELSE *-got-subcommand == 1 is TRUE" + chroma/main-process-token.ch "${FAST_HIGHLIGHT[chroma-${FAST_HIGHLIGHT[chroma-current]}-subcommand]}" "$__wrd" + } + fi +fi + + +# Add region_highlight entry (via `reply' array) +if [[ -n "$__style" ]]; then + (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) \ + && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") +fi + +# We aren't passing-through, do obligatory things ourselves +(( this_word = next_word )) +_start_pos=$_end_pos + +return 0 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6274b14..474c1cb 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2018-08-09 -Added ideal string highlighting – FSH now handles any legal quoting and combination of `"`,`'` and `\` when +Added ideal string highlighting – f-sy-h now handles any legal quoting and combination of `"`,`'` and `\` when highlighting program arguments. See the introduction for an example (item #14). ## 2018-08-02 @@ -28,8 +28,8 @@ set_fast_theme() { ``` If you have set theme before an update of styles (e.g. recent addition of bracket highlighting) -then please repeat `fast-theme {theme}` call to regenerate theme files. (**2018-08-09**: FSH -now has full user-theme support, refer to [appropriate section of README](#customization)). +then please repeat `fast-theme {theme}` call to regenerate theme files. (**2018-08-09**: f-sy-h +now has full user-theme support, refer to [appropriate section of README](README.md#customization)). ## 2018-07-30 @@ -46,7 +46,7 @@ will be invoked everything will work as expected (Git chroma will be ran). ## 2018-07-11 -There were problems with Ctrl-C not working when using FSH. After many days I've found a fix +There were problems with Ctrl-C not working when using f-sy-h. After many days I've found a fix for this, it's pushed to main. Second, asynchronous path checking (useful on e.g. slow network drives, or when there are many files in directory) @@ -61,7 +61,7 @@ it shows functionality of `awk` – compiling of code and NOT running it. Perl c ## 2018-06-06 -FSH gained a new architecture – "chroma functions". They are similar to "completion functions", i.e. they +f-sy-h gained a new architecture – "chroma functions". They are similar to "completion functions", i.e. they are defined **per-command**, but instead of completing that command, they colorize it. Two chroma exist, for `Git` ([video](https://asciinema.org/a/185707), [video](https://asciinema.org/a/185811)) and for `grep` ([video](https://asciinema.org/a/185942)). Checkout @@ -91,7 +91,7 @@ For-loop is highlighted, it has separate settings in [theme file](https://github ## 2018-05-27 -Added support for 256-color themes. There are six themes shipped with FSH. The command to +Added support for 256-color themes. There are six themes shipped with f-sy-h. The command to switch theme is `fast-theme {theme-name}`, it has a completion which lists available themes and options. Checkout [asciinema recording](https://asciinema.org/a/183814) that presents the themes. @@ -137,7 +137,7 @@ Assignments are no more one-colour default-white. When used in assignment, highl Math mode is highlighted – expressions `(( ... ))` and `$(( ... ))`. Empty variables are colorized as red. There are 3 style names (fields of -[FAST_HIGHLIGHT_STYLES](https://github.com/zdharma/fast-syntax-highlighting/blob/main/fast-highlight#L34) +[FAST_HIGHLIGHT_STYLES](https://github.com/zdharma/fast-syntax-highlighting/blob/main/functions/fast-highlight#L34) hash) for math-variable, number and empty variable (error): `mathvar`, `mathnum`, `matherr`. You can set them (like the animation below shows) to change colors. diff --git a/docs/CHROMA_GUIDE.adoc b/docs/CHROMA_GUIDE.adoc index efb3614..0d2757e 100644 --- a/docs/CHROMA_GUIDE.adoc +++ b/docs/CHROMA_GUIDE.adoc @@ -134,7 +134,7 @@ integer __idx1 __idx2 # Colorize 1..2 as builtin, 3.. as glob if (( FAST_HIGHLIGHT[chroma-example-counter] <= 2 )); then if [[ "$__wrd" = \"* ]]; then - # Pass through, fsh main code will do the highlight! + # Pass through, f-sy-h main code will do the highlight! return 1 else __style=${FAST_THEME_NAME}builtin diff --git a/docs/CODE_OF_CONDUCT.md b/docs/CODE_OF_CONDUCT.md deleted file mode 100644 index 8b9cefc..0000000 --- a/docs/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,132 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -We as members, contributors, and leaders pledge to make participation in our -community a harassment-free experience for everyone, regardless of age, body -size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socio-economic status, -nationality, personal appearance, race, caste, color, religion, or sexual identity -and orientation. - -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our -community include: - -- Demonstrating empathy and kindness toward other people -- Being respectful of differing opinions, viewpoints, and experiences -- Giving and gracefully accepting constructive feedback -- Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -- Focusing on what is best not just for us as individuals, but for the - overall community - -Examples of unacceptable behavior include: - -- The use of sexualized language or imagery, and sexual attention or - advances of any kind -- Trolling, insulting or derogatory comments, and personal or political attacks -- Public or private harassment -- Publishing others' private information, such as a physical or email - address, without their explicit permission -- Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Enforcement Responsibilities - -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. - -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. - -## Scope - -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at -*team@zshell.dev*. -All complaints will be reviewed and investigated promptly and fairly. - -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. - -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series -of actions. - -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or -permanent ban. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. - -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. - -### 4. Permanent Ban - -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. - -**Consequence**: A permanent ban from any sort of public interaction within -the community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.1, available at -[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. - -Community Impact Guidelines were inspired by -[Mozilla's code of conduct enforcement ladder][mozilla coc]. - -For answers to common questions about this code of conduct, see the FAQ at -[https://www.contributor-covenant.org/faq][faq]. Translations are available -at [https://www.contributor-covenant.org/translations][translations]. - -[homepage]: https://www.contributor-covenant.org -[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html -[mozilla coc]: https://github.com/mozilla/diversity -[faq]: https://www.contributor-covenant.org/faq -[translations]: https://www.contributor-covenant.org/translations diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md deleted file mode 100644 index 87ad095..0000000 --- a/docs/CONTRIBUTING.md +++ /dev/null @@ -1,29 +0,0 @@ -# Contributing - -This Project welcomes contributions, suggestions, and feedback. All contributions, suggestions, and feedback you submitted are accepted under the [Project's license](../LICENSE). - -You represent that if you do not own copyright in the code that you have the authority to submit it under the [Project's license](../LICENSE). All feedback, suggestions, or contributions are not confidential. - -[Should be further filled in by the project - including defining the requirements to reach maintainer status] - -The Project abides by the Organization's [code of conduct](CODE-OF-CONDUCT.md) and [trademark policy](TRADEMARKS.md). - -## Community membership - -### New contributors - -New contributors should be welcomed to the community by existing members, helped with PR workflow, and directed to relevant documentation and communication channels. - -### Member - -Members are continuously active contributors in the community. They can have issues and PRs assigned to them, and pre-submit tests are automatically run for their PRs. Members are expected to remain active contributors to the community. - -### Established community members - -Established community members are expected to demonstrate their adherence to the principles in this document. -Familiarity with project organization, roles, policies, procedures, conventions, etc., and technical and/or writing ability. -Role-specific expectations, responsibilities. - ---- - -Licensed under the [CC-BY 4.0 License](https://creativecommons.org/licenses/by-sa/4.0/). diff --git a/docs/GOVERNANCE.md b/docs/GOVERNANCE.md deleted file mode 100644 index 2a57933..0000000 --- a/docs/GOVERNANCE.md +++ /dev/null @@ -1,45 +0,0 @@ -# Governance Policy - -This document provides the governance policy for the Project. Maintainers agree to this policy and to abide by all Project polices, including the [code of conduct](CODE-OF-CONDUCT.md), [trademark policy](TRADEMARKS.md), and [antitrust policy](ANTITRUST.md) by adding their name to the [maintainers.md file](MAINTAINERS.md). - -## 1. Roles - -This project may include the following roles. Additional roles may be adopted and documented by the Project. - -**1.1. Maintainers**. Maintainers are responsible for organizing activities around developing, maintaining, and updating the Project. Maintainers are also responsible for determining consensus. This Project may add or remove Maintainers with the approval of the current Maintainers. - -**1.2. Contributors**. Contributors are those that have made contributions to the Project. - -## 2. Decisions - -**2.1. Consensus-Based Decision Making**. Projects make decisions through consensus of the Maintainers. While explicit agreement of all Maintainers is preferred, it is not required for consensus. Rather, the Maintainers will determine consensus based on their good faith consideration of a number of factors, including the dominant view of the Contributors and nature of support and objections. The Maintainers will document evidence of consensus in accordance with these requirements. - -**2.2. Appeal Process**. Decisions may be appealed by opening an issue and that appeal will be considered by the Maintainers in good faith, who will respond in writing within a reasonable time. If the Maintainers deny the appeal, the appeal my be brought before the Organization Steering Committee, who will also respond in writing in a reasonable time. - -## 3. How We Work - -**3.1. Openness**. Participation is open to anyone who is directly and materially affected by the activity in question. There shall be no undue financial barriers to participation. - -**3.2. Balance**. The development process should balance the interests of Contributors and other stakeholders. Contributors from diverse interest categories shall be sought with the objective of achieving balance. - -**3.3. Coordination and Harmonization**. Good faith efforts shall be made to resolve potential conflicts or incompatibility between releases in this Project. - -**3.4. Consideration of Views and Objections**. Prompt consideration shall be given to the written views and objections of all Contributors. - -**3.5. Written procedures**. This governance document and other materials documenting this project's development process shall be available to any interested person. - -## 4. No Confidentiality - -Information disclosed in connection with any Project activity, including but not limited to meetings, contributions, and submissions, is not confidential, regardless of any markings or statements to the contrary. - -## 5. Trademarks - -Any names, trademarks, logos, or goodwill developed by and associated with the Project (the "Marks") are controlled by the Organization. Maintainers may only use these Marks in accordance with the Organization's trademark policy. If a Maintainer resigns or is removed, any rights the Maintainer may have in the Marks revert to the Organization. - -## 6. Amendments - -Amendments to this governance policy may be made by affirmative vote of 2/3 of all Maintainers, with approval by the Organization's Steering Committee. - ---- - -Licensed under the [CC-BY 4.0 License](https://creativecommons.org/licenses/by-sa/4.0/). diff --git a/docs/MAINTAINERS.md b/docs/MAINTAINERS.md deleted file mode 100644 index e1642bc..0000000 --- a/docs/MAINTAINERS.md +++ /dev/null @@ -1,11 +0,0 @@ -# Maintainers - -This document lists the Maintainers of the Project. Maintainers may be added once approved by the existing maintainers as described in the [Governance document](GOVERNANCE.md). By adding your name to this list you are agreeing to abide by the Project governance documents and to abide by all of the Organization's polices, including the [code of conduct](https://github.com/z-shell/.github/blob/main/governance/organization/CODE-OF-CONDUCT.md), [trademark policy](https://github.com/z-shell/.github/blob/main/governance/organization/TRADEMARKS.md), and [antitrust policy](https://github.com/z-shell/.github/blob/main/governance/organization/ANTITRUST.md). If you are participating because of your affiliation with another organization (designated below), you represent that you have the authority to bind that organization to these policies. - -| **NAME** | **Organization** | -| :---------------- | :--------------: | -| Salvydas Lukosius | Z-Shell | - ---- - -Licensed under the [CC-BY 4.0 License](https://creativecommons.org/licenses/by-sa/4.0/). diff --git a/docs/README.md b/docs/README.md index 6056232..0c347f5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,33 +1,35 @@

- - ❮ Zi ❯ - F-Sy-H -

+ Logo + ❮ Zi ❯ - F-Sy-H

Feature-rich Syntax Highlighting for Zsh

- 《❔》Ask a Question - 《💡》Search Wiki -《💜》Join -《🌐》Localize

+ 《❔ Ask a Question 》 + 《💡 Search Wiki 》 + 《💜 Join 》 + 《🌐 Localize 》 +

- - - + - -VIM + + ✅ ZUnit + + + ✅ Zsh Parse + + + ⭕ Trunk + + + VIM -Visual Studio Code


+ Visual Studio Code


- - + +


Related