<commit_before>use strict;
use warnings;

package AngelPS1::Shell::fish;

sub ps1_escape
{
    # Do nothing
    $_[1]
}

sub ps1_invisible
{
    shift; # $class
    # Do nothing
    @_
}

sub ps1_finalize
{
    # Do nothing
    $_[1]
}


sub shell_code
{
    my ($class, %options) = @_;
    my ($DEBUG, $NAME, $IN, $OUT, $PID, $env) =
        @options{qw<debug name in out pid env>};

    # The shell code will be evaluated with eval as a single line
    # so statements must be properly terminated with ';'
    # No shell comments allowed

    #set err \$status;
    #if test ! -e '$IN'; $NAME leave; fish_prompt; return; end;
    #if ! printf '%s\\0%s' "?=\$err" "PWD=\$PWD" > '$IN'; $NAME leave; fish_prompt; return; end;
    <<EOF;
if test -n "\$APS1_NAME"; eval \$APS1_NAME leave; end;
set -g aps1_prompt_orig (functions fish_prompt | sed 's/#[^'\\''"]*\$//;s/\$/;/');
function fish_prompt;
    set _err \$status;
    if test ! -e '$IN'; $NAME leave; fish_prompt; return; end;
    printf '%s\\0%s' "?=\$_err" "PWD=\$PWD" > '$IN';
    cat '$OUT';
end;
set -g aps1_prompt (functions fish_prompt | sed '1s/fish_prompt/fish_prompt;/');
function $NAME;
    switch "\$argv[1]";
    case quit;
        $NAME leave;
    case leave;
        kill \$APS1_PID 2>/dev/null;
        rm -f -- '$IN';
        set -e -g APS1_PID;
        set -e -g APS1_NAME;
        set -e -g aps1_prompt;
        functions -e fish_prompt $NAME;
        complete -c $NAME -e;
        eval "\$aps1_prompt_orig";
        set -e -g aps1_prompt_orig;
    case mute;
        $NAME off;
    case off;
        eval "\$aps1_prompt_orig";
        complete -c $NAME -e;
        complete -c $NAME -A -f -a 'quit on';
    case unmute;
        $NAME on;
    case on;
        eval "\$aps1_prompt";
        complete -c $NAME -e;
        complete -c $NAME -A -f -a 'quit off';
    case '*';
        echo 'usage: $NAME [quit|mute|off|unmute|on]' >&2;
        return 1;
    end;
end;
complete -c $NAME -A -f -a 'quit off';
set -g APS1_PID $PID;
set -g APS1_NAME '$NAME';
EOF
}

sub WorkingDir
{
    my $home = $ENV{'HOME'};
    sub {
        my $pwd = $_[0]->{'PWD'};
        $pwd =~ s{^$home/}{~/}s;
        $pwd
    }
}

sub UserPrivSymbol
{
    \( $< ? '$' : '#' )
}

'$';
# vim:set et ts=8 sw=4 sts=4:
<commit_msg>fish: workaround bug in builtin printf<commit_after>use strict;
use warnings;

package AngelPS1::Shell::fish;

sub ps1_escape
{
    # Do nothing
    $_[1]
}

sub ps1_invisible
{
    shift; # $class
    # Do nothing
    @_
}

sub ps1_finalize
{
    # Do nothing
    $_[1]
}


sub shell_code
{
    my ($class, %options) = @_;
    my ($DEBUG, $NAME, $IN, $OUT, $PID, $env) =
        @options{qw<debug name in out pid env>};

    # The shell code will be evaluated with eval as a single line
    # so statements must be properly terminated with ';'
    # No shell comments allowed

    #set err \$status;
    #if test ! -e '$IN'; $NAME leave; fish_prompt; return; end;
    #if ! printf '%s\\0%s' "?=\$err" "PWD=\$PWD" > '$IN'; $NAME leave; fish_prompt; return; end;
    <<EOF;
if test -n "\$APS1_NAME"; eval \$APS1_NAME leave; end;
set -g aps1_prompt_orig (functions fish_prompt | sed 's/#[^'\\''"]*\$//;s/\$/;/');
function fish_prompt;
    set _err \$status;
    if test ! -e '$IN'; $NAME leave; fish_prompt; return; end;
    /usr/bin/printf '%s\\0%s' "?=\$_err" "PWD=\$PWD" > '$IN';
    cat '$OUT';
end;
set -g aps1_prompt (functions fish_prompt | sed '1s/fish_prompt/fish_prompt;/');
function $NAME;
    switch "\$argv[1]";
    case quit;
        $NAME leave;
    case leave;
        kill \$APS1_PID 2>/dev/null;
        rm -f -- '$IN';
        set -e -g APS1_PID;
        set -e -g APS1_NAME;
        set -e -g aps1_prompt;
        functions -e fish_prompt $NAME;
        complete -c $NAME -e;
        eval "\$aps1_prompt_orig";
        set -e -g aps1_prompt_orig;
    case mute;
        $NAME off;
    case off;
        eval "\$aps1_prompt_orig";
        complete -c $NAME -e;
        complete -c $NAME -A -f -a 'quit on';
    case unmute;
        $NAME on;
    case on;
        eval "\$aps1_prompt";
        complete -c $NAME -e;
        complete -c $NAME -A -f -a 'quit off';
    case '*';
        echo 'usage: $NAME [quit|mute|off|unmute|on]' >&2;
        return 1;
    end;
end;
complete -c $NAME -A -f -a 'quit off';
set -g APS1_PID $PID;
set -g APS1_NAME '$NAME';
EOF
}

sub WorkingDir
{
    my $home = $ENV{'HOME'};
    sub {
        my $pwd = $_[0]->{'PWD'};
        $pwd =~ s{^$home/}{~/}s;
        $pwd
    }
}

sub UserPrivSymbol
{
    \( $< ? '$' : '#' )
}

'$';
# vim:set et ts=8 sw=4 sts=4:

{'fraction_non_alphanumeric': 0.1743119266055046, 'fraction_numerical': 0.013543031891655745, 'mean_word_length': 2.186499652052888, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4196711', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1768, 'n_words': 523}