[
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.md",
    "content": "---\nname: Bug report\nabout: Create a report to help us improve\ntitle: \"\"\nlabels: bug\nassignees: Gazorby\n---\n\n**Describe the bug**\nA clear and concise description of what the bug is.\n\n**To Reproduce**\nSteps to reproduce the behavior:\n\n**Expected behavior**\nA clear and concise description of what you expected to happen.\n\n**Screenshots**\nIf applicable, add screenshots to help explain your problem.\n\n**System (please complete the following information):**\n\n- fish version\n- Distribution `cat /etc/os-release`\n\n**Additional context**\nAdd any other context about the problem here.\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.md",
    "content": "---\nname: Feature request\nabout: Suggest an idea for this project\ntitle: \"\"\nlabels: enhancement\nassignees: \"\"\n---\n\n**Is your feature request related to a problem? Please describe.**\nA clear and concise description of what the problem is. Ex. I'm always frustrated when [...]\n\n**Describe the solution you'd like**\nA clear and concise description of what you want to happen.\n\n**Describe alternatives you've considered**\nA clear and concise description of any alternative solutions or features you've considered.\n\n**Additional context**\nAdd any other context or screenshots about the feature request here.\n"
  },
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: CI\n\non:\n  push:\n    branches: [main]\n  pull_request:\n\n  # Allows you to run this workflow manually from the Actions tab\n  workflow_dispatch:\n\njobs:\n  tests:\n    runs-on: ${{ matrix.os }}\n    strategy:\n      matrix:\n        os: [macos-latest, ubuntu-latest]\n\n    steps:\n      - uses: actions/checkout@v3\n      - uses: fish-actions/install-fish@v1.1.0\n\n      - name: Install abbreviation-tips with Fisher\n        uses: fish-shop/install-plugin@v1\n        with:\n          plugin-manager: fisher\n          plugins: gazorby/fifc\n\n      - name: Set up Homebrew\n        uses: Homebrew/actions/setup-homebrew@master\n        # Homebrew is only missing from ubuntu images per https://github.com/actions/runner-images/issues/6283\n        if: matrix.os == 'ubuntu-latest'\n\n      - name: Install fzf and fd\n        run: brew install fzf fd\n\n      - name: Run Fishtape tests\n        uses: fish-shop/run-fishtape-tests@v1\n        with:\n          pattern: tests/**.fish\n        # timeout in case tests get stuck on fzf\n        timeout-minutes: 3\n\n  syntax-check:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions/checkout@v3\n\n      - uses: fish-actions/install-fish@v1\n\n      - uses: fish-actions/syntax-check@v1\n\n  # check Fish format\n  format-check:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions/checkout@v3\n\n      - uses: fish-actions/install-fish@v1\n\n      - uses: fish-actions/format-check@v1\n\n  # check Markdown and Yaml format\n  prettier:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v3\n      - uses: actionsx/prettier@v2\n        with:\n          args: --check .\n"
  },
  {
    "path": ".pre-commit-config.yaml",
    "content": "repos:\n  - repo: https://github.com/pre-commit/pre-commit-hooks\n    rev: v5.0.0\n    hooks:\n      - id: check-toml\n      - id: mixed-line-ending\n      - id: check-case-conflict\n      - id: check-merge-conflict\n      - id: check-docstring-first\n      - id: check-added-large-files\n      - id: check-executables-have-shebangs\n      - id: debug-statements\n      - id: end-of-file-fixer\n      - id: fix-byte-order-marker\n      - id: trailing-whitespace\n\n  - repo: https://github.com/hugoh/pre-commit-fish.git\n    rev: v1.2\n    hooks:\n      - id: fish_syntax\n      - id: fish_indent\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "## v0.1.1 (2023-03-05)\n\n### Fix\n\n- **directories**: escape name with spaces instead of quoting them\n\n### Perf\n\n- improve completion group determination\n\n## v0.1.0 (2023-01-23)\n\n### Feat\n\n- use `$EDITOR` as default editor\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2022 Matthieu MN\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<div align=\"center\">\n\n# fifc 🐠\n\n_fish fzf completions_\n\n[![CI](https://github.com/gazorby/fifc/actions/workflows/ci.yml/badge.svg)](https://github.com/gazorby/fifc/actions/workflows/ci.yml)\n\nfifc brings fzf powers on top of fish completion engine and allows customizable completion rules\n\n</div>\n\n![gif usage](../assets/demo.gif)\n\n## ✅ Requirements\n\n- [fish](https://github.com/fish-shell/fish-shell) 3.4.0+\n\n## ✨ Features\n\n- Preview/open any file: text, image, gif, pdf, archive, binary (using external tools)\n- Preview/open command's man page\n- Preview/open function definitions\n- Preview/open full option description when completing commands\n- Recursively search for files and folders when completing paths (using [fd](https://github.com/sharkdp/fd))\n- Preview directory content\n- Preview process trees (using [procs](https://github.com/dalance/procs))\n- Modular: easily add your own completion rules\n- Properly handle paths with spaces (needs fish 3.4+)\n\n## 🚀 Install\n\n```fish\nfisher install gazorby/fifc\n```\n\n## 🔧 Usage\n\nYou only need to set one setting after install:\n\n```fish\nset -Ux fifc_editor <your-favorite-editor>\n```\n\nAnd enjoy built-in completions!\n\nBy default fifc override `tab`, but you can assign another keybinding:\n\n```fish\n# Bind fzf completions to ctrl-x\nset -U fifc_keybinding \\cx\n```\n\nfifc can use modern tools if available:\n\n| Prefer                                           | Fallback to | Used for                                  | Custom options     |\n| ------------------------------------------------ | ----------- | ----------------------------------------- | ------------------ |\n| [bat](https://github.com/sharkdp/bat)            | cat         | Preview files                             | `$fifc_bat_opts`   |\n| [chafa](https://github.com/hpjansson/chafa)      | file        | Preview images, gif, pdf etc              | `$fifc_chafa_opts` |\n| [hexyl](https://github.com/sharkdp/hexyl)        | file        | Preview binaries                          | `$fifc_hexyl_opts` |\n| [fd](https://github.com/sharkdp/fd)              | find        | Complete paths                            | `$fifc_fd_opts`    |\n| [exa](https://github.com/ogham/exa)              | ls          | Preview directories                       | `$fifc_exa_opts`   |\n| [ripgrep](https://github.com/BurntSushi/ripgrep) | pcregrep    | Search options in man pages               | -                  |\n| [procs](https://github.com/dalance/procs)        | ps          | Complete processes and preview their tree | `$fifc_procs_opts` |\n| [broot](https://github.com/Canop/broot)          | -           | Explore directory trees                   | `$fifc_broot_opts` |\n\nCustom options can be added for any of the commands used by fifc using the variable mentioned in the above table.\n\nExample:\n\nShow line number when previewing files:\n\n- `set -U fifc_bat_opts --style=numbers`\n\nShow hidden file by default:\n\n- `set -U fifc_fd_opts --hidden`\n\n⚠️ Don't use quotes in variables, set them as a list: `set -U fifc_exa_opts --icons --tree`\n\n## 🛠️ Write your own rules\n\nCustom rules can easily be added using the `fifc` command. Actually, all builtin rules are added this way: see [conf.d/fifc.fish](https://github.com/gazorby/fifc/blob/52ff966511ea97ed7be79db469fe178784e22fd8/conf.d/fifc.fish)\n\nSee `fifc -h` for more details.\n\nBasically, a rule allows you to trigger some commands based on specific conditions.\n\nA condition can be either:\n\n- A regex that must match commandline before the cursor position\n- An arbitrary command that must exit with a non-zero status\n\nIf conditions are met, you can bind custom commands:\n\n- **preview:** Command used for fzf preview\n- **source:** Command that feeds fzf input\n- **open:** Command binded to `fifc_open_keybinding` (defaults to ctrl-o)\n\nAll commands have access to the following variable describing the completion context:\n\n| Variable           | Description                                                                                        | Command availability |\n| ------------------ | -------------------------------------------------------------------------------------------------- | -------------------- |\n| `fifc_candidate`   | Currently selected item in fzf                                                                     | all except source    |\n| `fifc_commandline` | Commandline part before the cursor position                                                        | all                  |\n| `fifc_token`       | Last token from the commandline                                                                    | all                  |\n| `fifc_group`       | Group to which fish suggestions belong (possible values: directories, files, options or processes) | all                  |\n| `fifc_extracted`   | Extracted string from the currently selected item using the `extracted` regex, if any              | all except source    |\n| `fifc_query`       | fzf query. On source command, it is the initial fzf query (passed through `--query` option)        | all                  |\n\n### **fifc_group** values\n\nfifc test completion items to set `fifc_group` with the following conditions:\n\n| Group       | Condition                                                    |\n| ----------- | ------------------------------------------------------------ |\n| directories | All completion items are directories                         |\n| files       | Items can be either files _or_ directories                   |\n| options     | All items match the following regex: `\\h+\\-+\\h*$`            |\n| processes   | All items match the following regex `^[0-9]+$` (list of PID) |\n\n### Matching order\n\nBy default, fifc evaluate all rules in the order in which they have been defined and stops at the first where all conditions are met.\nIt does this each time it has to resolve source, preview and open commands.\n\nTake the following scenario:\n\n```fish\n# Rule 1\nfifc -n 'test \"$fifc_group\" = files' -p 'bat $fifc_candidate'\n# Rule 2\nfifc -n 'string match \"*.json\" \"$fifc_candidate\"' -p 'bat -l json $fifc_candidate'\n```\n\nWhen completing path, `$fifc_group` will be set to \"files\" so the first rule will always be valid in that case, and the second one will never be reached.\n\nAnother example:\n\n```fish\n# Rule 1\nfifc --condition 'test \"$fifc_group\" = files' --preview 'bat $fifc_candidate'\n# Rule 2\nfifc --condition 'test \"$fifc_group\" = files' --source 'fd . --color=always --hidden $HOME'\n```\n\nHere, even if both rules have the same conditions, they won't interfere because fifc has to resolve source commands _before_ the preview commands, so order doesn't matter in this case.\n\n### Override builtin rules\n\nIf you want to write your own rule based on the same conditions as one of the built-in ones, you can use fifc `--order` option.\nIt tells fifc to evaluate the rule in a predefined order, so you can set it to 1 to make sure it will be evaluated first.\n\nWhen omitting the `--order`, the rule will be declared unordered and will be evaluated _after_ all other ordered rules, and all other unordered rules defined before.\n\nAll built-in rules are unordered.\n\n### Examples\n\nHere is how the built-in rule for file preview/open is implemented:\n\n```fish\nfifc \\\n    # If selected item is a file\n    -n 'test -f \"$fifc_candidate\"' \\\n    # bind `_fifc_preview_file` to preview command\n    -p _fifc_preview_file \\\n    # and `_fifc_preview_file` when pressing ctrl-o\n    -o _fifc_open_file\n```\n\nInteractively search packages in archlinux:\n\n```fish\nfifc \\\n    -r '^(pacman|paru)(\\\\h*\\\\-S)?\\\\h+' \\\n    -s 'pacman --color=always -Ss \"$fifc_token\" | string match -r \\'^[^\\\\h+].*\\'' \\\n    -e '.*/(.*?)\\\\h.*' \\\n    -f \"--query ''\" \\\n    -p 'pacman -Si \"$fifc_extracted\"'\n```\n\n![gif usage](../assets/pacman.gif)\n\nSearch patterns in files and preview matches when commandline starts with `**<pattern>` (using [ripgrep](https://github.com/burntsushi/ripgrep) and [batgrep](https://github.com/eth-p/bat-extras/blob/master/doc/batgrep.md#bat-extras-batgrep)):\n\n```fish\nfifc \\\n    -r '.*\\*{2}.*' \\\n    -s 'rg --hidden -l --no-messages (string match -r -g \\'.*\\*{2}(.*)\\' \"$fifc_commandline\")' \\\n    -p 'batgrep --color --paging=never (string match -r -g \\'.*\\*{2}(.*)\\' \"$fifc_commandline\") \"$fifc_candidate\"' \\\n    -f \"--query ''\" \\\n    -o 'batgrep --color (string match -r -g \\'.*\\*{2}(.*)\\' \"$fifc_commandline\") \"$fifc_candidate\" | less -R' \\\n    -O 1\n```\n\n![gif usage](../assets/batgrep.gif)\n\n## ❤️ Credits\n\nThanks [PatrickF1](https://github.com/PatrickF1) (and collaborators!), for the great [fzf.fish](https://github.com/PatrickF1/fzf.fish) plugin which inspired me for the command-based configuration, and from which I copied the ci workflow.\n\n## 📝 License\n\n[MIT](https://github.com/gazorby/fifc/blob/87c965fe42a5b2ddb6e0ea84871ca56651db1cb2/LICENSE)\n"
  },
  {
    "path": "completions/fifc.fish",
    "content": "complete fifc --long condition --short -n --description \"Command or fish function to be evaluated\"\ncomplete fifc --long regex --short r --description \"Regex matching the part of the commandline before cursor\"\ncomplete fifc --long extract --short e --description \"Regex applied on the sele cted candidate(s) to extract string to bo appended to the commandline (using capture groups)\"\ncomplete fifc --long order --short O --description \"Order in which this rule must be evaluated\"\ncomplete fifc --long preview --short p --description \"Preview command to be evaluated on the current candidate\"\ncomplete fifc --long open --short o --description \"Open command to be evaluated on the current candidate\"\ncomplete fifc --long fzf-options --short f --description \"Custom fzf options\"\n"
  },
  {
    "path": "conf.d/fifc.fish",
    "content": "# Private\nset -gx _fifc_comp_count 0\nset -gx _fifc_unordered_comp\nset -gx _fifc_ordered_comp\n\nif status is-interactive\n    # Keybindings\n    set -qU fifc_keybinding\n    or set -U fifc_keybinding \\t\n\n    set -qU fifc_open_keybinding\n    or set -U fifc_open_keybinding ctrl-o\n\n    for mode in default insert\n        bind --mode $mode \\t _fifc\n        bind --mode $mode $fifc_keybinding _fifc\n    end\n\n    # Set sources rules\n    fifc \\\n        -n 'test \"$fifc_group\" = \"directories\"' \\\n        -s _fifc_source_directories\n    fifc \\\n        -n 'test \"$fifc_group\" = \"files\"' \\\n        -s _fifc_source_files\n    fifc \\\n        -n 'test \"$fifc_group\" = processes' \\\n        -s 'ps -ax -o pid=,command='\nend\n\n# Load fifc preview rules only when fish is launched fzf\nif set -q _fifc_launched_by_fzf\n    # Builtin preview/open commands\n    fifc \\\n        -n 'test \"$fifc_group\" = \"options\"' \\\n        -p _fifc_preview_opt \\\n        -o _fifc_open_opt\n    fifc \\\n        -n 'test \\( -n \"$fifc_desc\" -o -z \"$fifc_commandline\" \\); and type -q -f -- \"$fifc_candidate\"' \\\n        -r '^(?!\\\\w+\\\\h+)' \\\n        -p _fifc_preview_cmd \\\n        -o _fifc_open_cmd\n    fifc \\\n        -n 'test -n \"$fifc_desc\" -o -z \"$fifc_commandline\"' \\\n        -r '^(functions)?\\\\h+' \\\n        -p _fifc_preview_fn \\\n        -o _fifc_open_fn\n    fifc \\\n        -n 'test -f \"$fifc_candidate\"' \\\n        -p _fifc_preview_file \\\n        -o _fifc_open_file\n    fifc \\\n        -n 'test -d \"$fifc_candidate\"' \\\n        -p _fifc_preview_dir \\\n        -o _fifc_open_dir\n    fifc \\\n        -n 'test \"$fifc_group\" = processes -a (ps -p (_fifc_parse_pid \"$fifc_candidate\") &>/dev/null)' \\\n        -p _fifc_preview_process \\\n        -o _fifc_open_process \\\n        -e '^\\\\h*([0-9]+)'\nend\n\n\n# Fisher\nfunction _fifc_uninstall --on-event fifc_uninstall\nend\n"
  },
  {
    "path": "cz.yaml",
    "content": "---\ncommitizen:\n  annotated_tag: true\n  bump_message: v$new_version\n  name: cz_conventional_commits\n  style:\n    - - qmark\n      - fg:#ff9d00 bold\n    - - question\n      - bold\n    - - answer\n      - fg:#ff9d00 bold\n    - - pointer\n      - fg:#ff9d00 bold\n    - - highlighted\n      - fg:#ff9d00 bold\n    - - selected\n      - fg:#cc5454\n    - - separator\n      - fg:#cc5454\n    - - instruction\n      - \"\"\n    - - text\n      - \"\"\n    - - disabled\n      - fg:#858585 italic\n  tag_format: v$version\n  version: 0.1.1\n"
  },
  {
    "path": "functions/_fifc.fish",
    "content": "function _fifc\n    set -f --export SHELL (command --search fish)\n    set -l result\n    set -Ux _fifc_extract_regex\n    set -gx _fifc_complist_path (string join '' (mktemp) \"_fifc\")\n    set -gx _fifc_custom_fzf_opts\n    set -gx fifc_extracted\n    set -gx fifc_commandline\n    set -gx fifc_token (commandline --current-token)\n    set -gx fifc_query \"$fifc_token\"\n\n    # Get commandline buffer\n    if test \"$argv\" = \"\"\n        set fifc_commandline (commandline --cut-at-cursor)\n    else\n        set fifc_commandline $argv\n    end\n\n    if _fifc_test_version \"$FISH_VERSION\" -ge \"3.4\"\n        set complete_opts --escape\n    end\n\n    complete -C $complete_opts -- \"$fifc_commandline\" | string split '\\n' >$_fifc_complist_path\n\n    set -gx fifc_group (_fifc_completion_group)\n    set source_cmd (_fifc_action source)\n\n    set fifc_fzf_query (string trim --chars '\\'' -- \"$fifc_fzf_query\")\n\n    set -l fzf_cmd \"\n        _fifc_launched_by_fzf=1 SHELL=fish fzf \\\n            -d \\t \\\n            --exact \\\n            --tiebreak=length \\\n            --select-1 \\\n            --exit-0 \\\n            --ansi \\\n            --tabstop=4 \\\n            --multi \\\n            --reverse \\\n            --header '$header' \\\n            --preview '_fifc_action preview {} {q}' \\\n            --bind='$fifc_open_keybinding:execute(_fifc_action open {} {q} &> /dev/tty)' \\\n            --query '$fifc_query' \\\n            $_fifc_custom_fzf_opts\"\n\n    set -l cmd (string join -- \" | \" $source_cmd $fzf_cmd)\n    # We use eval hack because wrapping source command\n    # inside a function cause some delay before fzf to show up\n    eval $cmd | while read -l token\n        # don't escape '~' for path, `$` for environ\n        if string match --quiet '~*' -- $token\n            set -a result (string join -- \"\" \"~\" (string sub --start 2 -- $token | string escape))\n        else if string match --quiet '$*' -- $token\n            set -a result (string join -- \"\" \"\\$\" (string sub --start 2 -- $token | string escape))\n        else\n            set -a result (string escape --no-quoted -- $token)\n        end\n        # Perform extraction if needed\n        if test -n \"$_fifc_extract_regex\"\n            set result[-1] (string match --regex --groups-only -- \"$_fifc_extract_regex\" \"$token\")\n        end\n    end\n\n    # Add space trailing space only if:\n    # - there is no trailing space already present\n    # - Result is not a directory\n    # We need to unescape $result for directory test as we escaped it before\n    if test (count $result) -eq 1; and not test -d (string unescape -- $result[1])\n        set -l buffer (string split -- \"$fifc_commandline\" (commandline -b))\n        if not string match -- ' *' \"$buffer[2]\"\n            set -a result ''\n        end\n    end\n\n    if test -n \"$result\"\n        commandline --replace --current-token -- (string join -- ' ' $result)\n    end\n\n    commandline --function repaint\n\n    rm $_fifc_complist_path\n    # Clean state\n    set -e _fifc_extract_regex\n    set -e _fifc_custom_fzf_opts\n    set -e _fifc_complist_path\n    set -e fifc_token\n    set -e fifc_group\n    set -e fifc_extracted\n    set -e fifc_candidate\n    set -e fifc_commandline\n    set -e fifc_query\nend\n"
  },
  {
    "path": "functions/_fifc_action.fish",
    "content": "function _fifc_action\n    # Can be either \"preview\", \"open\" or \"source\"\n    set -l action $argv[1]\n    set -l comp $_fifc_ordered_comp $_fifc_unordered_comp\n    set -l regex_val (string escape --style=regex -- \"$argv[2]\")\n    # Escape '/' for sed processing\n    set regex_val (string replace '/' '\\/' --all \"$regex_val\")\n\n    # Variables exposed to evaluated commands\n    set -x fifc_desc (sed -nr (printf 's/^%s[[:blank:]]+(.*)/\\\\\\1/p' \"$regex_val\") $_fifc_complist_path | string trim)\n    set -x fifc_candidate \"$argv[2]\"\n    set -x fifc_extracted (string match --regex --groups-only -- \"$_fifc_extract_regex\" \"$argv[2]\")\n\n    if test \"$action\" = preview\n        set default_preview 1\n        set fifc_query \"$argv[3]\"\n\n    else if test \"$action\" = open\n        set fifc_query \"$argv[3]\"\n\n    else if test \"$action\" = source\n        set default_source 1\n    end\n\n    for i in (seq (count $comp))\n        set -l condition_cmd\n        set -l regex_cmd\n        set -l valid 1\n        if test -n \"$$comp[$i][1]\"\n            set condition_cmd \"$$comp[$i][1]\"\n        else\n            set condition_cmd true\n        end\n        if test -n \"$$comp[$i][2]\"\n            set -l val (string escape -- \"$fifc_commandline\")\n            set regex_cmd \"string match --regex --quiet -- '$$comp[$i][2]' $val\"\n        else\n            set regex_cmd true\n        end\n\n        if not eval \"$condition_cmd; and $regex_cmd\"\n            set valid 0\n            continue\n        end\n\n        set _fifc_extract_regex \"$$comp[$i][7]\"\n\n        if test \"$action\" = preview; and test -n \"$$comp[$i][3]\"\n            eval $$comp[$i][3]\n            set default_preview 0\n            break\n        else if test \"$action\" = open; and test -n \"$$comp[$i][4]\"\n            eval $$comp[$i][4]\n            break\n        else if test \"$action\" = source; and test -n \"$$comp[$i][5]\"\n            set _fifc_custom_fzf_opts \"$$comp[$i][6]\"\n            if functions \"$$comp[$i][5]\" 1>/dev/null\n                eval $$comp[$i][5]\n            else\n                echo $$comp[$i][5]\n            end\n            set default_source 0\n            break\n        end\n    end\n\n    # We are in preview mode, but nothing matched\n    # fallback to fish description\n    if test \"$default_preview\" = 1\n        echo \"$fifc_desc\"\n    else if test \"$default_source\" = 1\n        echo _fifc_parse_complist\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_completion_group.fish",
    "content": "function _fifc_completion_group -d \"Determine completion group\"\n    set -l path_candidate (_fifc_path_to_complete)\n    # Null means that either $path is empty or is not a directory\n    set -l is_null (ls -A -- $path_candidate 2> /dev/null | string collect)\n    set -l complist (string escape -- (_fifc_expand_tilde (_fifc_parse_complist)))\n    # Directories\n    set -l dir_test \"test -d $complist[1]\"\n    set dir_test (string join -- \" -a -d \" $dir_test $complist[2..-1])\n    if test -n \"$is_null\"; and eval \"$dir_test\"\n        echo directories\n        # Files\n        # When complist is big, avoid calling ls with all arguments if first is neither a file nor a directory\n    else if test -n \"$is_null\"; and echo $complist | xargs ls -d -- &>/dev/null\n        echo files\n        # Options\n    else if string match --regex --quiet -- '\\h+\\-+\\h*$' $fifc_commandline\n        set -e fifc_query\n        echo options\n        # PIDs\n    else if string join -- '' $complist | string match --regex --quiet '^[0-9]+$'\n        echo processes\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_expand_tilde.fish",
    "content": "function _fifc_expand_tilde\n    string replace --regex -- '^~' \"$HOME\" $argv\nend\n"
  },
  {
    "path": "functions/_fifc_file_type.fish",
    "content": "function _fifc_file_type -d \"Figure out file type (txt, json, image, pdf, archive, binary)\"\n    set -l mime (file --mime-type -b \"$argv\")\n    set -l binary 0\n    if string match --quiet '*binary*' -- (file --mime -b -L \"$argv\")\n        set binary 1\n    end\n\n    switch $mime\n        case application/{gzip,java-archive,x-{7z-compressed,bzip2,chrome-extension,rar,tar,xar},zip}\n            echo archive\n            return\n        case \"image/*\"\n            echo image\n            return\n    end\n\n    if test $binary = 1\n        echo binary\n    else\n        switch $mime\n            case application/pdf\n                echo pdf\n            case application/json\n                echo json\n            case \"*\"\n                echo txt\n        end\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_help.fish",
    "content": "function __fifc_help_print\n    argparse -s \"i/indentation=?\" \"l/level=?\" \"c/color=?\" e/escape n -- $argv\n    set -l spaces \"$_flag_i\"\n    set -l level \"$_flag_l\"\n    set -l color \"$_flag_c\"\n    set -l echo_opt\n\n    if test -z \"$spaces\"\n        set spaces 4\n    end\n    if test -z \"$level\"\n        set level 1\n    end\n    if test -n \"$_flag_e\"\n        set -a echo_opt -e\n    end\n    if test -n \"$_flag_n\"\n        set -a echo_opt -n\n    end\n    if test -z \"$_flag_c\"\n        set color -o white\n    end\n    set indent (string repeat --count (math $spaces x $level) \" \")\n\n    set_color $color\n    echo $echo_opt \"$indent$argv[1]\"\n    for line in $argv[2..-1]\n        set_color $color\n        echo $echo_opt \"\\n$indent$line\"\n    end\n    # end\n    set_color normal\nend\n\nfunction __fifc_help_section\n    __fifc_help_print -e -l0 --color=yellow (string join -- \"\" (string upper -- \"$argv\") \"\\n\")\nend\n\nfunction __fifc_help_opt\n    set -l opt (string split -- '=' $argv[1])\n    __fifc_help_print -n -e --color=green -l1 -- \"$opt[1]\"\n    if test (count $opt) -eq 2\n        set_color yellow\n        echo \"=$opt[2]\"\n    else\n        echo \"\"\n    end\n    set -l desc (string split -- '\\n' $argv[2..-1] | string trim)\n    __fifc_help_print -e -l2 -- $desc\n    echo \"\"\nend\n\nfunction _fifc_help -d \"Print fifc help message\"\n    __fifc_help_section NAME\n    __fifc_help_print -e \"fifc - Set custom completion rules for use with fifc fish plugin\\n\"\n\n    __fifc_help_section SYNOPSIS\n    __fifc_help_print -e \"fifc [OPTIONS]\\n\"\n\n    __fifc_help_section DESCRIPTION\n\n    __fifc_help_print -e -n \\\n        \"The fifc command allows you to add custom completion rules that can enhance fish completions or override them.\\n\" \\\n        \"A rule is composed of condition(s) that, if valid, trigger commands that can:\" \\\n        \"  - Change fzf preview (-p)\" \\\n        \"  - Feed fzf input (-s)\" \\\n        \"  - Execute when fifc_open_keybinding is pressed (defaults to ctrl-o) (-o)\"\n\n    __fifc_help_print -e \"\\n\\n\"\n\n    __fifc_help_print -e -n \\\n        \"A condition can be either:\" \\\n        \" - A regex that must match commandline before cursor position (-r)\" \\\n        \" - An arbitrary command that must exit with a non-zero status (-n)\"\n\n    __fifc_help_print -e \"\\n\"\n\n    __fifc_help_print -e -n \\\n        \"Rule are evaluated in the order in which they are defined,\" \\\n        \"and fifc will stop at the first rule where all conditions are met\"\n\n    __fifc_help_print -e \"\\n\\n\"\n\n    __fifc_help_opt \\\n        \"-r, --regex=REGEX\" \\\n        \"Regex that must match commandline preceding the cursor for the rule to be valid\"\n\n    __fifc_help_opt \\\n        \"-e, --extract=COMMAND\" \\\n        \"Regex used to extract string from selected results before appending them to the commandline\"\n\n    __fifc_help_opt \\\n        \"-n, --condition=COMMAND\" \\\n        \"Command or function that must exit with a non-zero status for the rule to be valid\"\n\n    __fifc_help_opt \\\n        \"-p, --preview=COMMAND\" \\\n        \"Preview command passed to fzf if the rule is valid\"\n\n    __fifc_help_opt \\\n        \"-s, --source=COMMAND\" \\\n        \"Command that will feed fzf input if the rule is valid\"\n\n    __fifc_help_opt \\\n        \"-o, --open=COMMAND\" \\\n        \"Command binded to fifc_open_keybinding (defaults to ctrl-o) when using fzf\"\n\n    __fifc_help_opt \\\n        \"-O, --order=INT\" \\\n        \"The order in which the rule is evaluated.\" \\\n        \"If missing, the rule will be evaluated after all ordered ones, and all unordered rules defined before.\"\n\n    __fifc_help_opt \\\n        \"-f, --fzf-options\" \\\n        \"Custom fzf options (can override previous ones)\"\n\n    __fifc_help_opt \\\n        \"-h, --help\" \\\n        \"Show this help\"\n\n    __fifc_help_print -e \"Examples:\\n\"\n\n    __fifc_help_print -e -l2 -- \"- Preview files using bat (already builtin):\\n\"\n    __fifc_help_print -e -l2 --color=white -- \\\n        '  fifc -n \\'test -f \"$fifc_candidate\"\\' -p \"bat --color=always $fifc_candidate\"'\n\n    __fifc_help_print -e \"\\n\"\n\n    __fifc_help_print -e -l2 -- \"- Use fd to search files recursively (already builtin):\\n\"\n    __fifc_help_print -e -l2 --color=white -- \\\n        '  fifc -n \\'test \"$fifc_group\" = files\\' -s \\'fd . --color=always --strip-cwd-prefix\\''\n\n    __fifc_help_print -e \"\\n\"\n\n    __fifc_help_print -e -l2 -- \"- Interactively search packages on archlinux:\\n\"\n    __fifc_help_print -e -n -l2 --color=white -- \\\n        \" fifc \\\\\" \\\n        \" -r '^pacman(\\h*\\-S)?\\h+\\w+' \\\\\" \\\n        \" -s 'pacman --color=always -Ss \"\\$fifc_token\" | string match -r \\\"^[^\\h+].*\\\"' \\\\\" \\\n        \" -e '.*/(.*?)\\h.*' \\\\\" \\\n        \" -f '--query \\\"\\\"' \\\\\" \\\n        \" -p 'pacman -Si \"\\$fifc_extracted\"' \\\\ \\n\"\nend\n"
  },
  {
    "path": "functions/_fifc_open_cmd.fish",
    "content": "function _fifc_open_cmd\n    _fifc_preview_cmd $fifc_candidate\nend\n"
  },
  {
    "path": "functions/_fifc_open_dir.fish",
    "content": "function _fifc_open_dir\n    if type -q broot\n        broot --color=yes $fifc_broot_opts $fifc_candidate\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_open_file.fish",
    "content": "function _fifc_open_file -d \"Open a file with the right tool depending on its type\"\n    set -l filepath \"$fifc_candidate\"\n\n    if test -n \"$argv\"\n        set filepath \"$argv\"\n    end\n\n    set -q fifc_editor || set -l fifc_editor \"$EDITOR\"\n\n    set -l file_type (_fifc_file_type \"$filepath\")\n\n    switch $file_type\n        case txt json archive\n            $fifc_editor \"$filepath\"\n        case image\n            if type -q chafa\n                chafa --watch $fifc_chafa_opts \"$filepath\"\n            else\n                $fifc_editor \"$filepath\"\n            end\n        case binary\n            if type -q hexyl\n                hexyl $fifc_hexyl_opts \"$filepath\" | less --RAW-CONTROL-CHARS\n            else\n                $fifc_editor \"$filepath\"\n            end\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_open_fn.fish",
    "content": "function _fifc_open_fn -d \"Open a function definition using open file wrapper\"\n    set -l pathname (functions --details $fifc_candidate 2>/dev/null)\n    if test -f $pathname\n        _fifc_open_file $pathname\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_open_opt.fish",
    "content": "function _fifc_open_opt -d \"Open a man page starting at the selected option\"\n    set -l cmd (string match --regex --groups-only -- '(^|\\h+)(\\w+) ?-*$' \"$fifc_commandline\")\n    set -l opt (string trim --chars '\\n ' -- \"$fifc_candidate\")\n    set -l regex \"^\\h*(-+[^\\n]*)*$opt\"\n\n    if type -q bat\n        man $cmd \\\n            | bat --color=always --language man $fifc_bat_opts \\\n            # --RAW-CONTROL-CHARS allow color output of bat to be displayed\n            | less --RAW-CONTROL-CHARS --pattern \"$regex\"\n    else\n        man $cmd | less --pattern \"$regex\"\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_open_process.fish",
    "content": "function _fifc_open_process -d \"Open the tree view of the selected process (procs only)\"\n    set -l pid (_fifc_parse_pid \"$fifc_candidate\")\n\n    if type -q procs\n        procs --color=always --tree --pager=always $fifc_procs_opts \"$pid\"\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_parse_complist.fish",
    "content": "function _fifc_parse_complist -d \"Extract the first column of fish completion list\"\n    cat $_fifc_complist_path \\\n        | string unescape \\\n        | uniq \\\n        | awk -F '\\t' '{ print $1 }'\nend\n"
  },
  {
    "path": "functions/_fifc_parse_pid.fish",
    "content": "function _fifc_parse_pid -d \"Extract pid at the beginning of ps output lines\"\n    string match --regex --groups-only -- \"^\\h*([0-9]+)\" \"$argv\"\nend\n"
  },
  {
    "path": "functions/_fifc_path_to_complete.fish",
    "content": "function _fifc_path_to_complete\n    set -l token (string unescape -- $fifc_token)\n    if string match --regex --quiet -- '.*(\\w|\\.|/)+$' \"$token\"\n        _fifc_expand_tilde \"$token\"\n    else\n        echo {$PWD}/\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_preview_cmd.fish",
    "content": "function _fifc_preview_cmd -d \"Open man page of the selected command\"\n    if type -q bat\n        man $fifc_candidate 2>/dev/null | bat --color=always --language man $fifc_bat_opts\n    else\n        man $fifc_candidate 2>/dev/null\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_preview_dir.fish",
    "content": "function _fifc_preview_dir -d \"List content of the selected directory\"\n    if type -q exa\n        exa --color=always $fifc_exa_opts $fifc_candidate\n    else\n        ls --color=always $fifc_ls_opts $fifc_candidate\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_preview_file.fish",
    "content": "function _fifc_preview_file -d \"Preview the selected file with the right tool depending on its type\"\n    set -l file_type (_fifc_file_type \"$fifc_candidate\")\n\n    switch $file_type\n        case txt\n            if type -q bat\n                bat --color=always $fifc_bat_opts \"$fifc_candidate\"\n            else\n                cat \"$fifc_candidate\"\n            end\n        case json\n            if type -q bat\n                bat --color=always -l json $fifc_bat_opts \"$fifc_candidate\"\n            else\n                cat \"$fifc_candidate\"\n            end\n        case image pdf\n            if type -q chafa\n                chafa $fifc_chafa_opts \"$fifc_candidate\"\n            else\n                _fifc_preview_file_default \"$fifc_candidate\"\n            end\n        case archive\n            if type -q 7z\n                7z l \"\"$fifc_candidate\"\" | tail -n +17 | awk '{ print $6 }'\n            else\n                _fifc_preview_file_default \"$fifc_candidate\"\n            end\n        case binary\n            if type -q hexyl\n                hexyl $fifc_hexyl_opts \"$fifc_candidate\"\n            else\n                _fifc_preview_file_default \"$fifc_candidate\"\n            end\n\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_preview_file_default.fish",
    "content": "function _fifc_preview_file_default -d \"Display informations about the selected file\"\n    set -l mime (file --mime-type -b \"$argv\")\n    set_color brgreen\n    echo -e \"$mime[1]\\n\"\n    set_color --bold white\n    file -b \"$argv\"\n    set_color normal\nend\n"
  },
  {
    "path": "functions/_fifc_preview_fn.fish",
    "content": "function _fifc_preview_fn -d \"Preview the function definition\"\n    if type -q bat\n        type $fifc_candidate | bat --color=always --language fish $fifc_bat_opts\n    else\n        type $fifc_candidate\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_preview_opt.fish",
    "content": "function _fifc_preview_opt -d \"Open man page of a command starting at the selected option\"\n    set -l regex \"(?s)^(\\-+[^\\n]+)*$fifc_candidate([^\\-\\w\\.]([^\\.\\n]|\\.{2,}|\\w+\\.)*|)\\n{1,2}.*?(^(\\-+[^\\n]+|\\w+))\"\n    set -l regex_replace '^\\h+(\\-+[^\\n]+.*)'\n    set -l cmd (string match --regex --groups-only -- '(^|\\h+)(\\w+) ?-*$' $fifc_commandline)\n    echo $group\n    set out (man $cmd 2>/dev/null | string replace -r $regex_replace '$1' \\\n        | begin\n            if type -q rg\n                rg --multiline $regex\n            else if type -q pcre2grep\n                pcre2grep --multiline $regex\n            else\n                pcregrep --multiline $regex\n            end\n        end \\\n        # Remove last line as it should describes the next option\n        | awk 'n>=1 { print a[n%1] } { a[n%1]=$0; n=n+1 }' \\\n        | string trim \\\n    )\n\n    # Fallback to fish description if there is no man page\n    if test -z \"$out\"\n        echo \"$fifc_desc\"\n    end\n\n    # Pretty printing\n    set_color brgreen\n    echo -e \"$out[1]\"\n    set_color --bold white\n    echo -e (string join -- \"\\n\" \"\" $out[2..-1])\n    set_color normal\nend\n"
  },
  {
    "path": "functions/_fifc_preview_process.fish",
    "content": "function _fifc_preview_process -d \"Preview process informations\"\n    set -l pid (_fifc_parse_pid \"$fifc_candidate\")\n    set -l err_msg \"\\nThe process exited\"\n\n    if type -q procs\n        procs --color=always --tree $fifc_procs_opts \"$pid\"\n    else\n        set -l ps_preview_fmt (string join ',' 'pid' 'ppid=PARENT' 'user' '%cpu' 'rss=RSS_IN_KB' 'start=START_TIME' 'command')\n        ps -o \"$ps_preview_fmt\" -p \"$pid\" 2>/dev/null\n    end\n    if not ps -p \"$pid\" &>/dev/null\n        set_color yellow\n        echo -e \"$err_msg\"\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_source_directories.fish",
    "content": "function _fifc_source_directories -d \"Return a command to recursively find directories\"\n    if type -q fd\n        set --local --export fifc_fd_opts -t d\n        _fifc_source_files\n    else\n        set --local --export fifc_find_opts -type d\n        _fifc_source_files\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_source_files.fish",
    "content": "function _fifc_source_files -d \"Return a command to recursively find files\"\n    set -l path (_fifc_path_to_complete | string escape)\n    set -l hidden (string match \"*.\" \"$path\")\n\n    if string match --quiet -- '~*' \"$fifc_query\"\n        set -e fifc_query\n    end\n\n    if type -q fd\n        if _fifc_test_version (fd --version) -ge \"8.3.0\"\n            set fd_custom_opts --strip-cwd-prefix\n        end\n\n        if test \"$path\" = {$PWD}/\n            echo \"fd . $fifc_fd_opts --color=always $fd_custom_opts\"\n        else if test \"$path\" = \".\"\n            echo \"fd . $fifc_fd_opts --color=always --hidden $fd_custom_opts\"\n        else if test -n \"$hidden\"\n            echo \"fd . $fifc_fd_opts --color=always --hidden -- $path\"\n        else\n            echo \"fd . $fifc_fd_opts --color=always -- $path\"\n        end\n    else if test -n \"$hidden\"\n        # Use sed to strip cwd prefix\n        echo \"find . $path $fifc_find_opts ! -path . -print 2>/dev/null | sed 's|^\\./||'\"\n    else\n        # Exclude hidden directories\n        echo \"find . $path $fifc_find_opts ! -path . ! -path '*/.*' -print 2>/dev/null | sed 's|^\\./||'\"\n    end\nend\n"
  },
  {
    "path": "functions/_fifc_test_version.fish",
    "content": "function _fifc_test_version -d \"Compare version numbers\"\n    set -l arg_1 (string replace --regex --all '[^\\d]' '' -- \"$argv[1]\")\n    set -l arg_2 (string replace --regex --all '[^\\d]' '' -- \"$argv[3]\")\n    set -l op \"$argv[2]\"\n\n    set -l v_diff (math (string length -- $arg_1) - (string length -- $arg_2))\n\n    # Ensure both versions are the same length\n    if test $v_diff -gt 0\n        set arg_2 (string join '' -- \"$arg_2\" (string repeat -N -n $v_diff '0'))\n    else if test $v_diff -lt 0\n        set v_diff (math abs $v_diff)\n        set arg_1 (string join '' -- \"$arg_1\" (string repeat -N -n $v_diff '0'))\n    end\n\n    set -l cmd (string collect -- \"test \" \"$arg_1\" \" $op \" \"$arg_2\")\n    eval $cmd\nend\n"
  },
  {
    "path": "functions/fifc.fish",
    "content": "function __fifc_check_flag -d \"Check flag value for fifc\"\n    switch $_flag_name\n        case O order\n            if not test 0 -lt $_flag_value\n                echo \"$_argparse_cmd: Order must be a positive integer\"\n                return 1\n            end\n            # Ensure regex is valid\n        case r regex\n            set -l out (string match --regex --quiet $_flag_value 2>&1 | string join '\\n')\n            if test -n \"$out\"\n                echo -e \"$_argparse_cmd:\\n$out\"\n            end\n    end\nend\n\nfunction fifc -d \"Add your own fish fzf completions\"\n    set -l option_spec 'n/condition=' 'p/preview=' 'o/open=' 's/source=' 'e/extract=' 'f/fzf-options=' h/help\n    set -a option_spec 'r/regex=!__fifc_check_flag' 'O/order=!__fifc_check_flag'\n\n    argparse --name fifc $option_spec -- $argv\n\n    if test \"$status\" != 0\n        return 1\n    end\n\n    if test -n \"$_flag_h\"\n        _fifc_help\n        return\n    end\n\n    if test \\( -n \"$_flag_n\" -o -n \"$_flag_r\" \\) \\\n            -a \\( -z \"$_flag_p\" -a -z \"$_flag_o\" -a -z \"$_flag_s\" -a -z \"$_flag_e\" -a -z \"$_flag_f\" \\)\n\n        echo \"fifc: You have not specified any binding (preview, open, source or extract)\"\n        return 1\n    end\n\n    set _fifc_comp_count (math $_fifc_comp_count + 1)\n    set -l count $_fifc_comp_count\n    # Ensure completion vars are empty before setting them\n    set -e \"_fifc_comp_$count\"\n    set -gx \"_fifc_comp_$count\"\n    set -a \"_fifc_comp_$count\" \"$_flag_n\"\n    set -a \"_fifc_comp_$count\" \"$_flag_r\"\n    set -a \"_fifc_comp_$count\" \"$_flag_p\"\n    set -a \"_fifc_comp_$count\" \"$_flag_o\"\n    set -a \"_fifc_comp_$count\" \"$_flag_s\"\n    set -a \"_fifc_comp_$count\" \"$_flag_f\"\n    set -a \"_fifc_comp_$count\" \"$_flag_e\"\n\n    if test -z \"$_flag_O\"\n        set -a _fifc_unordered_comp \"_fifc_comp_$count\"\n    else\n        set _fifc_ordered_comp[$_flag_O] \"_fifc_comp_$count\"\n    end\nend\n"
  },
  {
    "path": "tests/_resources/dir with spaces/file 1.txt",
    "content": "foo 1\n"
  },
  {
    "path": "tests/_resources/dir with spaces/file 2.txt",
    "content": "foo 2\n"
  },
  {
    "path": "tests/_resources/dir with spaces/file.json",
    "content": "{}\n"
  },
  {
    "path": "tests/_resources/target.txt",
    "content": "foo\n"
  },
  {
    "path": "tests/test_exposed_vars.fish",
    "content": "set curr_fifc_unordered_comp $_fifc_unordered_comp\nset dir \"tests/_resources/dir with spaces\"\nset _fifc_complist_path (mktemp)\n\nfunction _fifc_test_exposed_vars\n    switch $var\n        case candidate\n            echo -n \"$fifc_candidate\"\n        case extracted\n            echo -n \"$fifc_extracted\"\n        case query\n            echo -n \"$fifc_query\"\n    end\nend\n\n\nset comp_1 \\\n    'test -f $fifc_candidate' \\\n    '.*' \\\n    _fifc_test_exposed_vars \\\n    open_cmd \\\n    source_cmd \\\n    --fzf_option \\\n    '.*/(.*\\.txt)$'\n\nset _fifc_unordered_comp comp_1\n\nset var candidate\nset actual (_fifc_action \"preview\" \"$dir/file 1.txt\")\n@test \"exposed vars fifc_candidate\" \"$actual\" = \"$dir/file 1.txt\"\n\nset var extracted\nset -x fifc_extracted\nset _fifc_extract_regex '.*/(.*\\.txt)$'\nset actual (_fifc_action \"preview\" \"$dir/file 1.txt\")\n@test \"exposed vars fifc_extracted\" \"$actual\" = \"file 1.txt\"\n\nset var query\nset -x fifc_query\nset actual (_fifc_action \"preview\" \"$dir/file 1.txt\" \"1\")\n@test \"exposed vars fifc_query\" \"$actual\" = 1\n\nrm $_fifc_complist_path\n"
  },
  {
    "path": "tests/test_fifc.fish",
    "content": "set curr_fifc_unordered_comp $_fifc_unordered_comp\nset _fifc_unordered_comp\n\nfifc \\\n    -n 'test -n \"$fifc_desc\"' \\\n    -r '^functions\\h+|^\\h+' \\\n    -p _fifc_preview_fn \\\n    -o _fifc_open_fn\n\n@test \"fifc command completion added\" (count $_fifc_unordered_comp) = 1\n@test \"fifc command completion condition\" \"$$_fifc_unordered_comp[1][1]\" = 'test -n \"$fifc_desc\"'\n@test \"fifc command completion regex\" \"$$_fifc_unordered_comp[1][2]\" = '^functions\\h+|^\\h+'\n@test \"fifc command completion preview\" \"$$_fifc_unordered_comp[1][3]\" = _fifc_preview_fn\n@test \"fifc command completion open\" \"$$_fifc_unordered_comp[1][4]\" = _fifc_open_fn\n\n# set _fifc_unordered_comp\nfifc \\\n    -n 'test -n \"$fifc_desc\"' \\\n    -r '^functions\\h+|^\\h+' \\\n    -s source_cmd\n\n@test \"fifc source added\" (count $_fifc_unordered_comp) = 2\n@test \"fifc source condition\" \"$$_fifc_unordered_comp[2][1]\" = 'test -n \"$fifc_desc\"'\n@test \"fifc source regex\" \"$$_fifc_unordered_comp[2][2]\" = '^functions\\h+|^\\h+'\n@test \"fifc source command\" \"$$_fifc_unordered_comp[2][5]\" = source_cmd\n\nset -gx _fifc_unordered_comp $curr_fifc_unordered_comp\n"
  },
  {
    "path": "tests/test_file_type.fish",
    "content": "set actual (_fifc_file_type \"tests/_resources/dir with spaces/file 71.txt\")\n@test \"file type test txt\" \"$actual\" = txt\n\nset actual (_fifc_file_type \"tests/_resources/dir with spaces/file.json\")\n@test \"file type test json\" \"$actual\" = json -o \"$actual\" = txt\n\nset actual (_fifc_file_type \"tests/_resources/dir with spaces/fish.png\")\n@test \"file type test image\" \"$actual\" = image\n\nset actual (_fifc_file_type \"tests/_resources/dir with spaces/file.bin\")\n@test \"file type test binary\" \"$actual\" = binary\n\nset actual (_fifc_file_type \"tests/_resources/dir with spaces/file.7z\")\n@test \"file type test archive\" \"$actual\" = archive\n\nset actual (_fifc_file_type \"tests/_resources/dir with spaces/file.pdf\")\n@test \"file type test pdf\" \"$actual\" = pdf\n\nset actual_target (_fifc_file_type \"tests/_resources/target.txt\")\n@test \"file type test link target\" \"$actual_target\" = txt\n\nset actual_link (_fifc_file_type \"tests/_resources/dir with spaces/symlink.txt\")\n@test \"file type test link source\" \"$actual_link\" = \"$actual_target\"\n"
  },
  {
    "path": "tests/test_group.fish",
    "content": "set _fifc_complist_path (mktemp)\n\nset _commandline \"kill \"\ncomplete -C --escape -- \"$_commandline\" >$_fifc_complist_path\nset fifc_commandline \"$_commandline\"\nset actual (_fifc_completion_group)\n@test \"group test pid\" \"$actual\" = processes\n\nset _commandline \"ls tests/_resources/dir\\ with\\ spaces/\"\ncomplete -C --escape -- \"$_commandline\" >$_fifc_complist_path\nset fifc_commandline \"$_commandline\"\nset actual (_fifc_completion_group)\n@test \"group test files\" \"$actual\" = files\n\nset _commandline \"ls -\"\ncomplete -C --escape -- \"$_commandline\" >$_fifc_complist_path\nset fifc_commandline \"$_commandline\"\nset actual (_fifc_completion_group)\n@test \"group test options\" \"$actual\" = options\n\nset -e _fifc_complist\nset -e fifc_commandline\nrm $_fifc_complist_path\n"
  },
  {
    "path": "tests/test_match_order.fish",
    "content": "set curr_fifc_unordered_comp $_fifc_unordered_comp\nset curr_fifc_ordered_comp $_fifc_ordered_comp\nset dir \"tests/_resources/dir with spaces\"\nset _fifc_complist_path (mktemp)\n\n# Add unordered completions\nset comp_1 \\\n    'test -f $fifc_candidate' \\\n    '^cat $' \\\n    'echo comp_1' \\\n    open_cmd \\\n    source_cmd \\\n    --fzf_option \\\n    extract_regex\n\nset comp_2 \\\n    'test -d $fifc_candidate' \\\n    '^ls $' \\\n    'echo comp_2' \\\n    open_cmd \\\n    source_cmd \\\n    --fzf_option \\\n    extract_regex\n\nset _fifc_unordered_comp comp_1 comp_2\n\nset fifc_commandline \"cat \"\nset actual (_fifc_action \"preview\" \"$dir/file 1.txt\")\n@test \"preview match condition and regex first completion\" \"$actual\" = comp_1\n\nset fifc_commandline \"ls \"\nset actual (_fifc_action \"preview\" \"$dir\")\n@test \"preview match condition and regex second completion\" \"$actual\" = comp_2\n\necho \"fallback    description\" >$_fifc_complist_path\nset fifc_commandline \"fallback \"\nset actual (_fifc_action \"preview\" 'fallback')\n@test \"preview fallback fish description\" \"$actual\" = description\n\n# Add ordered completion, should be evaluated before unordered ones\nset o_comp_1 \\\n    'test -f $fifc_candidate' \\\n    '^cat $' \\\n    'echo o_comp_1' \\\n    open_cmd \\\n    source_cmd_1 \\\n    --fzf_option_1 \\\n    extract_regex_1\n\nset _fifc_ordered_comp o_comp_1\nset fifc_commandline \"cat \"\nset actual (_fifc_action \"preview\" \"$dir/file 1.txt\")\n@test \"preview match condition and regex ordered completion\" \"$actual\" = o_comp_1\n\nset -e fifc_commandline\nset -gx _fifc_unordered_comp $curr_fifc_unordered_comp\nset -gx _fifc_ordered_comp $curr_fifc_ordered_comp\nrm $_fifc_complist_path\n"
  },
  {
    "path": "tests/test_open_cmd.fish",
    "content": "set fifc_candidate mkdir\nset fifc_bat_opts '--color=never'\n\nset actual (_fifc_open_cmd)\nset expected (man mkdir)\n@test \"builtin cmd open\" \"$actual\" = \"$expected\"\n"
  },
  {
    "path": "tests/test_open_file.fish",
    "content": "set dir \"tests/_resources/dir with spaces\"\nset curr_fifc_editor $fifc_editor\nset fifc_editor cat\nset fifc_candidate \"$dir/file 1.txt\"\n\nset actual (_fifc_open_file)\n@test \"builtin file open\" \"$actual\" = 'foo 1'\n\nset fifc_editor $curr_fifc_editor\n"
  },
  {
    "path": "tests/test_preview_file.fish",
    "content": "set dir \"tests/_resources/dir with spaces\"\nset fifc_candidate \"$dir/file 1.txt\"\nset fifc_bat_opts '--color=never'\n\nset actual (_fifc_preview_file)\n@test \"builtin file preview\" \"$actual\" = 'foo 1'\n"
  },
  {
    "path": "tests/test_source.fish",
    "content": "set curr_fifc_unordered_comp $_fifc_unordered_comp\nset curr_fifc_ordered_comp $_fifc_ordered_comp\nset _fifc_complist_path (mktemp)\n\n# Add unordered sources\nset comp_1 'test \"$any\" = \"1\"' '^kill $' '' '' 'echo comp_1'\nset comp_2 'test \"$any\" = \"2\"' '^ps -p $' '' '' 'echo comp_2'\nset _fifc_unordered_comp comp_1 comp_2\n\nset fifc_commandline \"kill \"\nset any 1\nset actual (_fifc_action \"source\")\n@test \"source match first\" \"$actual\" = \"echo comp_1\"\n\nset fifc_commandline \"ps -p \"\nset any 2\nset actual (_fifc_action \"source\")\n@test \"source match second\" \"$actual\" = \"echo comp_2\"\n\nset fifc_commandline \"foo \"\nset actual (_fifc_action \"source\")\n@test \"source fallback fish suggestions\" \"$actual\" = _fifc_parse_complist\n\nset -e fifc_commandline\nset -gx _fifc_unordered_comp $curr_fifc_unordered_comp\nset -gx _fifc_unordered_comp $curr_fifc_ordered_comp\nrm $_fifc_complist_path\n"
  },
  {
    "path": "tests/version_test.fish",
    "content": "set -l actual (_fifc_test_version \"3.4\" -gt \"3.0\")\n@test \"version test basic gt\" $status = 0\n\nset -l actual (_fifc_test_version \"3.4\" -ge \"3.4\")\n@test \"version test basic ge equal\" $status = 0\n\nset -l actual (_fifc_test_version \"3.5\" -ge \"3.4\")\n@test \"version test basic ge greater\" $status = 0\n\nset -l actual (_fifc_test_version \"3.4\" -lt \"3.5\")\n@test \"version test basic lt\" $status = 0\n\nset -l actual (_fifc_test_version \"3.4\" -le \"3.4\")\n@test \"version test basic le equal\" $status = 0\n\nset -l actual (_fifc_test_version \"3.4\" -le \"3.5\")\n@test \"version test basic le lower\" $status = 0\n\nset -l actual (_fifc_test_version \"3.4\" -gt \"3\")\n@test \"version test length not equal\" $status = 0\n\nset -l actual (_fifc_test_version \"3.4\" -gt \"3\")\n@test \"version test length not equal 1\" $status = 0\n\nset -l actual (_fifc_test_version \"3\" -gt \"3.4\")\n@test \"version test length not equal 2\" $status = 1\n\nset -l actual (_fifc_test_version \"fish 3.5.0\" -gt \"3.4.2\")\n@test \"version test extract version left\" $status = 0\n\nset -l actual (_fifc_test_version \"3.5.0\" -gt \"fish 3.4.2\")\n@test \"version test extract version right\" $status = 0\n"
  }
]