fork/fish-shell

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

Johannes AltmanningerMark private functions that don't need localizationa53db7256

master
1.1 KiB34 linesraw
1# localization: skip(private)
2function __fish_preview_current_file --description "Open the file at the cursor in a pager"
3    if __fish_edit_command_if_at_cursor
4        return 0
5    end
6
7    set -l pager (__fish_anypager)
8    or set pager cat
9
10    # commandline -t will never return an empty list. However, the token
11    # could comprise multiple lines, so join them into a single string.
12    set -l file (commandline -t | string collect)
13    set -l prefix eval set
14
15    if test -z $file
16        # $backslash will parsed as regex which may need additional escaping.
17        set -l backslash '\\\\'
18        not status test-feature regex-easyesc && set backslash $backslash$backslash
19        set file (string replace -ra -- '([ ;#^<>&|()"\'])' "$backslash\$1" (commandline -xc)[-1])
20        set prefix set
21    end
22
23    set -q file[1] || return
24
25    # strip -option= from token if present
26    set file (string replace -r -- '^-[^\s=]*=' '' $file | string collect)
27
28    $prefix -l files $file || return # Bail if $file does not tokenize.
29
30    if set -q files[1] && test -f $files[1]
31        $pager $files
32        commandline -f repaint
33    end
34end