File: __fish_clang_complete.fish

package info (click to toggle)
fish 3.1.2-3%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 38,672 kB
  • sloc: ansic: 80,259; cpp: 47,069; javascript: 17,087; sh: 6,163; python: 3,429; makefile: 669; perl: 367; objc: 78; xml: 18
file content (16 lines) | stat: -rw-r--r-- 899 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# This function is compatible with clang, clang++, and variations thereof, and is shared
# by clang.fish and clang++.fish.
# We dynamically query the head at `(commandline -o)[1]` to get the correct completions.
function __fish_clang_complete
    # If the result is for a value, clang only prints the value, so completions
    # for `-std=` print `c++11` and not `-std=c++11` like we need. See #4174.
    set -l prefix (commandline -ct | string replace -fr -- '^(.*=)[^=]*' '$1')

    # Don't hard-code the name of the clang binary
    set -l clang (commandline -o)[1]
    # first get the completions from clang, with the prefix separated from the value by a comma
    $clang --autocomplete=(commandline -ct | string unescape | string replace -- "$prefix" "$prefix,") 2>/dev/null |
    # and put it in a format that fish understands
    string replace -r -- '^([^ ]+)\s*(.*)' "$prefix\$1\t\$2"
end