File Coverage

blib/lib/App/Rakubrew/Shell/Fish.pm
Criterion Covered Total %
statement 29 62 46.7
branch 1 6 16.6
condition 0 6 0.0
subroutine 10 17 58.8
pod 0 8 0.0
total 40 99 40.4


line stmt bran cond sub pod time code
1             package App::Rakubrew::Shell::Fish;
2 1     1   8 use App::Rakubrew::Shell;
  1         3  
  1         61  
3             our @ISA = "App::Rakubrew::Shell";
4 1     1   6 use strict;
  1         3  
  1         25  
5 1     1   5 use warnings;
  1         3  
  1         60  
6 1     1   20 use 5.010;
  1         3  
7              
8 1     1   8 use Encode::Locale qw(env);
  1         2  
  1         74  
9              
10 1     1   6 use App::Rakubrew::Variables;
  1         2  
  1         241  
11 1     1   8 use App::Rakubrew::Tools;
  1         2  
  1         88  
12 1     1   6 use App::Rakubrew::VersionHandling;
  1         3  
  1         178  
13 1     1   7 use App::Rakubrew::Build;
  1         2  
  1         966  
14              
15             sub supports_hooking {
16 0     0 0 0 my $self = shift;
17 0         0 1;
18             }
19              
20             sub install_note {
21 1     1 0 988 my $text = <
22             Load $brew_name automatically by adding
23              
24             $brew_exec init Fish | source
25              
26             to ~/.config/fish/config.fish
27             This can be easily done using:
28              
29             echo '$brew_exec init Fish | source' >> ~/.config/fish/config.fish
30             EOT
31              
32 1 50       7 if ($prefix =~ / /) {
33 0         0 $text .= <
34              
35             =================================== WARNING ==================================
36              
37             rakubrews home directory is currently
38              
39             $prefix
40              
41             That folder contains spaces. This will break building rakudos as the build
42             system currently doesn't work in such a path. You can work around this problem
43             by changing that folder to a directory without spaces. Do so by putting
44              
45             set -x RAKUBREW_HOME "/some/folder/without/space/rakubrew"
46              
47             in your `~/.config/fish/config.fish` file *before* the `source` line.
48             EOW
49             }
50 1         32 return $text;
51             }
52              
53             sub get_init_code {
54 0     0 0   my $self = shift;
55 0           my $path = env('PATH');
56 0           $path = $self->clean_path($path);
57              
58 0           my @path_components = split /:/, $path;
59 0           @path_components = map { "'$_'" } @path_components;
  0            
60              
61 0           $path =~ s/:/ /g;
62 0 0         if (get_brew_mode() eq 'env') {
63 0           my $version = get_global_version();
64 0 0 0       if ($version && $version ne 'system' && !is_version_broken($version)) {
      0        
65 0           unshift @path_components, map({ "'$_'" } get_bin_paths($version));
  0            
66             }
67             }
68             else { # get_brew_mode() eq 'shim'
69 0           unshift @path_components, "'$shim_dir'";
70             }
71              
72 0           $path = join(' ', @path_components);
73              
74 0           return <
75             set -x PATH $path
76              
77             function $brew_name
78             command $brew_exec internal_hooked Fish \$argv
79             and eval (command $brew_exec internal_shell_hook Fish post_call_eval \$argv)
80             end
81              
82             function _${brew_name}_is_not_register
83             set args (commandline -poc)
84             if [ (count \$args) -eq 3 -a \$args[1] = 'register' ]
85             return 1
86             else
87             return 0
88             end
89             end
90              
91             complete -c $brew_name -f -n _${brew_name}_is_not_register -a '(command $brew_exec internal_shell_hook Fish completions (commandline -poc) (commandline -ct) | string split " ")'
92             EOT
93              
94             }
95              
96             sub post_call_eval {
97 0     0 0   my $self = shift;
98 0           $self->print_shellmod_code(@_);
99             }
100              
101             sub get_path_setter_code {
102 0     0 0   my $self = shift;
103 0           my $path = shift;
104 0           my @path_components = split /:/, $path;
105 0           @path_components = map { "'$_'" } @path_components;
  0            
106 0           return "set -gx PATH " . join(' ', @path_components);
107             }
108              
109             sub get_shell_setter_code {
110 0     0 0   my $self = shift;
111 0           my $version = shift;
112 0           return "set -gx $env_var $version";
113             }
114              
115             sub get_shell_unsetter_code {
116 0     0 0   my $self = shift;
117 0           return "set -ex $env_var";
118             }
119              
120             sub completions {
121 0     0 0   my $self = shift;
122 0           say join(" ", $self->get_completions($self->strip_executable($#_, @_)));
123             }
124              
125             1;
126