...

Text file src/github.com/alecthomas/chroma/lexers/testdata/fish.actual

Documentation: github.com/alecthomas/chroma/lexers/testdata

     1#!/usr/bin/env fish
     2
     3echo hello > output.txt
     4
     5alias something=echo
     6
     7sudo systemctl start postgresql
     8
     9# Outputs 'image.png'.
    10echo (basename image.jpg .jpg).png
    11
    12echo some text for testing
    13
    14# Convert all JPEG files in the current directory to the
    15# PNG format using the 'convert' program.
    16for i in *.jpg; convert $i (basename $i .jpg).png; end
    17
    18# Set the ``data`` variable to the contents of 'data.txt'
    19# without splitting it into a list.
    20begin; set -l IFS; set data (cat data.txt); end
    21
    22# Set ``$data`` to the contents of data, splitting on NUL-bytes.
    23set data (cat data | string split0)
    24
    25grep fish myanimallist1 | wc -l
    26
    27command some-arg-with-dash
    28
    29echo input.{c,h,txt}
    30
    31echo {$dogs}dog
    32
    33echo (seq 10)[1 2 3]
    34echo (seq 10)[2..5 1..3]
    35echo (seq 10)[-1..1]
    36set PATH $PATH[-1..1]
    37
    38set foo banana
    39foo=gagaga echo $foo # prints gagaga, while in other shells it might print "banana"
    40foo=gagaga somecommand $foo # prints gagaga, while in other shells it might print "banana"
    41
    42function some func
    43    echo 'function' with space
    44end
    45
    46function dirs --description 'Print directory stack'
    47    set -l options h/help c
    48    argparse -n dirs --max-args=0 $options -- $argv
    49    or return
    50
    51    if set -q _flag_help
    52        __fish_print_help dirs
    53        return 0
    54    end
    55
    56    if set -q _flag_c
    57        # Clear directory stack.
    58        set -e -g dirstack
    59        return 0
    60    end
    61
    62    # Replace $HOME with ~.
    63    string replace -r '^'"$HOME"'($|/)' '~$1' -- $PWD $dirstack | string join " "
    64end
    65
    66function ytdl_files -d "Download videos from text files with youtube-dl and put them into folders"
    67    argparse --name=ytdl_files 's/shutdown' -- $argv
    68
    69    for file in $argv
    70        echo "Operating on $file"
    71        youtube-dl -a $file -i -o (dirname $file)"/"(basename $file .txt)"/%(autonumber)s-%(title)s.%(ext)s"
    72    end
    73
    74    if test -n "$_flag_shutdown"
    75        echo "poweroff"
    76    end
    77end
    78
    79function cheat -d 'Get programming language cheat sheets from cheat.sh'
    80    if test $argv[1]
    81        curl https://cheat.sh/$argv[1]
    82    else
    83        curl https://cheat.sh
    84    end
    85end
    86
    87function dut -d 'Get top paths with most disk usage'
    88    du -hs $argv[2]/* | sort -rh | head -$argv[1]
    89end
    90
    91function m2d --description 'Move to desktop -- m2d program_name desktop_num'
    92    bspc node (xdo id -N $argv[1]) -d $argv[2]
    93end
    94
    95set -x no_proxy 'localhost,127.0.0.1'
    96
    97function toggle_proxy
    98    if not set -q HTTP_PROXY
    99        for proxy in HTTP_PROXY HTTPS_PROXY http_proxy https_proxy
   100            set -gx $proxy 'http://127.0.0.1:8118'
   101        end
   102        echo 'Proxy On'
   103    else
   104        set -e {HTTP_PROXY,HTTPS_PROXY,http_proxy,https_proxy}
   105        echo 'proxy Off'
   106    end
   107end
   108
   109function wttr -d 'Get weather info from wttr.in'
   110    if test $argv[1]
   111        curl https://wttr.in/$argv[1]
   112    else
   113        curl https://wttr.in/
   114    end
   115end
   116
   117function fish_config --description "Launch fish's web based configuration"
   118    argparse h/help -- $argv
   119    or return
   120
   121    if set -q _flag_help
   122        __fish_print_help fish_config
   123        return 0
   124    end
   125
   126    set -l cmd $argv[1]
   127    set -e argv[1]
   128
   129    set -q cmd[1]
   130    or set cmd browse
   131
   132    # The web-based configuration UI
   133    # Also opened with just `fish_config` or `fish_config browse`.
   134    if contains -- $cmd browse
   135        set -lx __fish_bin_dir $__fish_bin_dir
   136        if set -l python (__fish_anypython)
   137            $python "$__fish_data_dir/tools/web_config/webconfig.py" $argv
   138        else
   139            echo (set_color $fish_color_error)Cannot launch the web configuration tool:(set_color normal)
   140            echo (set_color -o)"fish_config browse"(set_color normal) requires Python.
   141            echo Installing python will fix this, and also enable completions to be
   142            echo automatically generated from man pages.\n
   143            echo To change your prompt, use (set_color -o)"fish_config prompt"(set_color normal) or create a (set_color -o)"fish_prompt"(set_color normal) function.
   144                echo To list the samples use (set_color -o)"fish_config prompt show"(set_color normal).\n
   145
   146                echo You can tweak your colors by setting the (set_color $fish_color_search_match)\$fish_color_\*(set_color normal) variables.
   147            end
   148            return 0
   149        end
   150
   151        if not contains -- $cmd prompt
   152            echo No such subcommand: $cmd >&2
   153            return 1
   154        end
   155        
   156        # prompt - for prompt switching
   157        set -l cmd $argv[1]
   158        set -e argv[1]
   159
   160        if contains -- $cmd list; and set -q argv[1]
   161            echo "Too many arguments" >&2
   162            return 1
   163        end
   164
   165        set -l prompt_dir $__fish_data_dir/sample_prompts $__fish_data_dir/tools/web_config/sample_prompts
   166        switch $cmd
   167            case show
   168                set -l fish (status fish-path)
   169                set -l prompts $prompt_dir/$argv.fish
   170                set -q prompts[1]; or set prompts $prompt_dir/*.fish
   171                for p in $prompts
   172                    if not test -e "$p"
   173                        continue
   174                    end
   175                    set -l promptname (string replace -r '.*/([^/]*).fish$' '$1' $p)
   176                    echo -s (set_color --underline) $promptname (set_color normal)
   177                    $fish -c "functions -e fish_right_prompt; source $p;
   178                    false
   179                    fish_prompt
   180                    echo (set_color normal)
   181                    if functions -q fish_right_prompt;
   182                    echo right prompt: (false; fish_right_prompt)
   183                end"
   184                echo
   185                end
   186            case list ''
   187                string replace -r '.*/([^/]*).fish$' '$1' $prompt_dir/*.fish
   188                return
   189            case choose
   190                if set -q argv[2]
   191                    echo "Too many arguments" >&2
   192                    return 1
   193                end
   194                if not set -q argv[1]
   195                    echo "Too few arguments" >&2
   196                    return 1
   197                end
   198
   199                set -l have 0
   200                for f in $prompt_dir/$argv[1].fish
   201                    if test -f $f
   202                        source $f
   203                        set have 1
   204                        break
   205                    end
   206                end
   207                if test $have -eq 0
   208                    echo "No such prompt: '$argv[1]'" >&2
   209                    return 1
   210                end
   211            case save
   212                read -P"Overwrite prompt? [y/N]" -l yesno
   213                if string match -riq 'y(es)?' -- $yesno
   214                    echo Overwriting
   215                    cp $__fish_config_dir/functions/fish_prompt.fish{,.bak}
   216
   217                    if set -q argv[1]
   218                        set -l have 0
   219                        for f in $prompt_dir/$argv[1].fish
   220                            if test -f $f
   221                                set have 1
   222                                source $f
   223                                or return 2
   224                            end
   225                        end
   226                        if test $have -eq 0
   227                            echo "No such prompt: '$argv[1]'" >&2
   228                            return 1
   229                        end
   230                    end
   231
   232                    funcsave fish_prompt
   233                    or return
   234
   235                    functions -q fish_right_prompt
   236                    and funcsave fish_right_prompt
   237
   238                    return
   239                else
   240                    echo Not overwriting
   241                    return 1
   242                end
   243        end
   244
   245        return 0
   246    end

View as plain text