fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerMark private functions that don't need localizationa53db7256

master
1.9 KiB49 linesraw
1# localization: skip(private)
2function __fish_paste
3    # Also split on \r, otherwise it looks confusing
4    set -l data (string split \r -- $argv[1] | string split \n)
5    set data (string replace -ra [[:cntrl:]] '' -- $data)
6
7    if commandline --search-field >/dev/null
8        commandline --search-field -i -- $data
9        return
10    end
11
12    # If the current token has an unmatched single-quote,
13    # escape all single-quotes (and backslashes) in the paste,
14    # in order to turn it into a single literal token.
15    #
16    # This eases pasting non-code (e.g. markdown or git commitishes).
17    set -l quote_state (__fish_tokenizer_state -- (commandline -ct | string collect))
18    if contains -- $quote_state single single-escaped
19        if status test-feature regex-easyesc
20            set data (string replace -ra "(['\\\])" '\\\\$1' -- $data)
21        else
22            set data (string replace -ra "(['\\\])" '\\\\\\\$1' -- $data)
23        end
24    else if not contains -- $quote_state double double-escaped
25        and set -q data[2]
26        # Leading whitespace in subsequent lines is unneded, since fish
27        # already indents. Also gets rid of tabs (issue #5274).
28        set -l tmp
29        for line in $data
30            switch $quote_state
31                case normal
32                    set -a tmp (string trim -l -- $line)
33                case single single-escaped double double-escaped escaped
34                    set -a tmp $line
35            end
36            set quote_state (__fish_tokenizer_state -i $quote_state -- $line)
37        end
38        set data $data[1] $tmp[2..]
39    end
40    if not string length -q -- (commandline -c)
41        # If we're at the beginning of the first line, trim whitespace from the start,
42        # so we don't trigger ignoring history.
43        set data[1] (string trim -l -- $data[1])
44    end
45
46    if test -n "$data"
47        commandline --insert-smart -- $data
48    end
49end