-
Notifications
You must be signed in to change notification settings - Fork 4
/
angel-PS1
executable file
·3356 lines (2727 loc) · 83.9 KB
/
angel-PS1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
# Copyright © 2013-2018 Olivier Mengué
# Original source code is available at https://github.com/dolmen/angel-PS1
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#!/usr/bin/perl
# This chunk of stuff was generated by App::FatPacker. To find the original
# file's code, look for the end of this BEGIN block or the string 'FATPACK'
BEGIN {
my %fatpacked;
$fatpacked{"AngelPS1.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1';
package AngelPS1;
use POSIX ();
our $VERSION = '0.97';
our $SHELL_PID = getppid;
our $NAME = 'angel';
our $VERBOSE = 0;
(our $TTYNAME = POSIX::ttyname(0)) =~ s{^/dev/}{};
our $ENCODING;
my $encoding;
sub _str_allowed
{
my $str = shift;
$encoding ||= do {
require Encode;
Encode::find_encoding($ENCODING)
};
local $@;
eval { Encode::encode($encoding, $str, Encode::FB_CROAK()) };
# Return true if no exception was thrown
!$@
}
1;
ANGELPS1
$fatpacked{"AngelPS1/Chrome.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_CHROME';
use strict;
use warnings;
package AngelPS1::Chrome;
use Term::Chrome 1.011;
*EXPORT = *Term::Chrome::EXPORT;
*import = *Term::Chrome::import;
1
ANGELPS1_CHROME
$fatpacked{"AngelPS1/Compiler.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_COMPILER';
use strict;
use warnings;
package AngelPS1::Compiler;
use Exporter 'import';
our @EXPORT = qw< reduce expand ps1_is_static >;
use AngelPS1::Shell ();
use Term::Chrome 2.000 ();
use Scalar::Util ();
sub expand
{
my $state = shift;
die "expand(): invalid arg" unless ref($state) eq 'HASH';
my @args = @_;
LOOP: for(my $i=0; $i<=$#args; $i++) {
#warn $i;
my $r = ref $args[$i];
if ($r eq 'CODE') {
#use B 'svref_2object';
#my $GV = svref_2object($args[$i])->GV;
#warn('expanding sub '.$GV->SAFENAME.' defined at '.$GV->FILE.' line '.$GV->LINE);
#undef $GV;
my @tmp = $args[$i]->($state);
splice @args, $i, 1, @tmp;
#warn "OK";
redo LOOP; # A dynamic part can return dynamic parts!
} elsif ($r eq 'ARRAY') {
$args[$i] = [ expand($state, @{$args[$i]}) ];
}
}
return @args
}
sub reduce;
sub reduce
{
my @template = @_;
my @out;
LOOP: while (@template) {
my $v = shift @template;
if (my $r = ref $v) {
# Scalar refs are for raw (non-escaped) strings
if ($r eq 'SCALAR') {
$v = $$v;
}
# => replace by the colored expanded result
elsif (Scalar::Util::blessed($v) && $v->isa('Term::Chrome')) {
if (@template && ref($template[0]) eq 'ARRAY') {
my $arr = shift @template;
if (@$arr) { # If non-empty
unshift @template,
AngelPS1::Shell->ps1_invisible($v->term),
# flatten the ARRAY
@$arr,
# close the colored part with the reverse of $v
AngelPS1::Shell->ps1_invisible((!$v)->term);
}
} else {
# Expand the color
unshift @template, AngelPS1::Shell->ps1_invisible($v->term);
}
redo LOOP;
} else {
if (wantarray) {
# Keep subs as they must be explicitely expanded using expand()
if ($r eq 'CODE') {
push @out, $v;
next LOOP;
# Array refs are only expanded after a chrome spec. See below
} elsif ($r eq 'ARRAY') {
push @out, [ reduce(@$v) ];
next LOOP;
}
}
warn "unexpected $r item in prompt\n";
next LOOP;
}
} else {
# Skip if undef
next unless defined $v;
$v = AngelPS1::Shell->ps1_escape($v);
}
if (@out && ref($out[-1]) eq 'SCALAR') {
${$out[-1]} .= $v
} else { # CODE refs (and anything else) are preserved
push @out, \$v;
}
}
return @out if wantarray;
return '' unless @out;
die "invalid state after reduce: @out\n" if @out != 1 || ref $out[0] ne 'SCALAR';
${pop @out}
}
sub ps1_is_static
{
my $PS1 = shift;
$#$PS1 == 0 && (ref $PS1->[0]) eq 'SCALAR'
}
'$';
ANGELPS1_COMPILER
$fatpacked{"AngelPS1/Plugin.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN';
use strict;
use warnings;
package AngelPS1::Plugin;
'$';
ANGELPS1_PLUGIN
$fatpacked{"AngelPS1/Plugin/Battery.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_BATTERY';
use utf8;
use strict;
use warnings;
package AngelPS1::Plugin::Battery;
our $VERSION = $AngelPS1::VERSION;
use Exporter 5.57 'import';
our @EXPORT = qw<BatteryPercent BatteryGauge>;
use AngelPS1::Shell;
use AngelPS1::System;
use AngelPS1::Chrome qw<Red Green Blue Bold color>;
our $SYMBOL_CHARGING = '⏚';
our $SYMBOL_DISCHARGING = '⌁';
if ($^O eq 'darwin' && $ENV{'TERM_PROGRAM'} eq 'iTerm.app') {
$_ .= ' ' for $SYMBOL_CHARGING, $SYMBOL_DISCHARGING;
}
sub BatteryPercent
{
my $fetch_battery_gen = AngelPS1::System->can('gen_fetch_battery')
or return;
my $fetch_battery = $fetch_battery_gen->()
or return;
return sub {
my @status = $fetch_battery->();
return if !@status || $status[0] >= 0.80;
(
(
$status[0] > 0.20
? Green
: Red
),
[
sprintf '%s%d',
($status[1] ? $SYMBOL_CHARGING
: $SYMBOL_DISCHARGING),
100 * $status[0]
]
)
}
}
use constant {
SYMBOL_CHARGING => Blue + Bold,
SYMBOL_DISCHARGING_HIGH => Green,
SYMBOL_DISCHARGING_LOW => Red,
GAUGE_DISCHARGING_HIGH => color(22) / color(235), # Dark green over dark gray
GAUGE_DISCHARGING_LOW => color(22) / color(124), # Dark green over dark red
GAUGE_CHARGING_HIGH => Blue / color(235) + Bold, # Light blue over dark red
GAUGE_CHARGING_LOW => Blue / color(124) + Bold, # Light blue over dark red
};
sub BatteryGauge
{
my $fetch_battery_gen = AngelPS1::System->can('gen_fetch_battery')
or return;
my $fetch_battery = $fetch_battery_gen->()
or return;
require AngelPS1::Plugin::Gauges;
return sub {
my @status = $fetch_battery->();
return if !@status || $status[0] >= 0.80;
my $charging = $status[1];
#$charging = 1;
my $high = $status[0] >= 0.3;
(
($charging ? (
SYMBOL_CHARGING, $SYMBOL_CHARGING,
$high ? GAUGE_CHARGING_HIGH : GAUGE_CHARGING_LOW,
)
: (
$high ? SYMBOL_DISCHARGING_HIGH : SYMBOL_DISCHARGING_LOW, $SYMBOL_DISCHARGING,
$high ? GAUGE_DISCHARGING_HIGH : GAUGE_DISCHARGING_LOW,
)
),
[
&AngelPS1::Plugin::Gauges::CharGauge($status[0])
],
)
}
}
'$';
ANGELPS1_PLUGIN_BATTERY
$fatpacked{"AngelPS1/Plugin/DateTime.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_DATETIME';
use utf8;
use strict;
use warnings;
package AngelPS1::Plugin::DateTime;
use AngelPS1 ();
use Exporter 'import';
our @EXPORT_OK = qw< Time StrFTime Clock >;
sub Time ()
{
# FIXME this does not take in account if the user changes $ENV{TZ} in the
# shell
# TODO provoke an angel reload in that case
sub { sprintf('%3$02d:%2$02d:%1$02d', localtime) }
}
sub StrFTime ($)
{
my $format = shift;
require POSIX;
sub { POSIX::strftime($format, localtime) }
}
my $CLOCK_FACES = '🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🕛 🕧 ';
sub Clock
{
return if ! AngelPS1::_str_allowed($CLOCK_FACES);
sub {
my ($min, $hour) = (localtime)[1,2];
substr($CLOCK_FACES, 2*(($hour*60+$min-45)/30%24), 1)
}
}
'$'
ANGELPS1_PLUGIN_DATETIME
$fatpacked{"AngelPS1/Plugin/Gauges.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_GAUGES';
use utf8;
use strict;
use warnings;
package AngelPS1::Plugin::Gauges;
our $VERSION = $AngelPS1::VERSION;
use Exporter 5.57 'import';
our @EXPORT_OK = qw<
CharGauge
ColoredGauge
StaticGauge
DynamicGauge
>;
use constant GAUGE_VALUES => '_▁▂▃▄▅▆▇█';
use constant GAUGE_COUNT => length(GAUGE_VALUES);
sub CharGauge ($)
{
my $offset = int((shift)*GAUGE_COUNT);
substr(GAUGE_VALUES, $offset, 1)
}
sub ColoredGauge ($$)
{
my $gauge = CharGauge(pop);
return @_, [ $gauge ];
}
sub StaticGauge ($;$)
{
my $gauge = CharGauge(pop);
return $gauge unless @_;
return @_, [ $gauge ];
}
sub DynamicGauge ($;$)
{
goto &StaticGauge if (!ref $_[$#_]);
my $generator = pop;
if (@_) {
return (@_, [ sub { CharGauge($generator->()) } ])
} else {
return sub { CharGauge($generator->()) }
}
}
'$';
ANGELPS1_PLUGIN_GAUGES
$fatpacked{"AngelPS1/Plugin/Git.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_GIT';
use strict;
use warnings;
package AngelPS1::Plugin::Git;
use Exporter 5.57 'import';
BEGIN {
our $VERSION = $AngelPS1::VERSION;
our @EXPORT = qw(GitInfo);
}
use AngelPS1::Util qw< which run one_line >;
use AngelPS1::Chrome;
my $git = eval { which 'git' };
sub git
{
# All Git commands we call return a single line. We don't want '\n'
one_line(run $git, @_)
}
sub GitInfo
{
unless ($git) {
warn "'git' not found in PATH";
return
}
# Cleanup the environment
# This is done globally!
delete @ENV{qw< GIT_DIR GIT_TRACE >};
# Return a dynamic PS1 element
sub {
my $shell_state = shift;
my $git_dir = $shell_state->{GIT_DIR};
$git_dir = "$shell_state->{'PWD'}/.git" unless defined $git_dir;
unless (-d $git_dir) {
($git_dir = git qw(rev-parse --git-dir))
or return;
}
# This seems to be incompatible with "git diff --shortstat"
#local $ENV{'GIT_DIR'} = $git_dir;
my @out;
my $local_commits = 0;
my $branch = git 'symbolic-ref', 'HEAD';
if ($branch eq '') {
($branch = git 'rev-parse', '--short')
or return;
} else {
$branch =~ s{^refs/heads/}{};
# Count the number of commits to push ($local_commits)
if ((my $remote_branch = git qw(config --get), "branch.$branch.merge")
&& (my $remote = git qw(config --get), "branch.$branch.remote")) {
# Compute the ref of our local image of the remote branch
(my $remote_branch_ref = $remote_branch) =~ s{^refs/heads/}{refs/remotes/$remote/};
# Count the commits
$local_commits =
git(qw(rev-list --no-merges --count),
"$remote_branch_ref..HEAD")
|| 0;
}
}
my $status = git qw(status --porcelain -z);
my $untracked = $status =~ /(?:^|\0)\?\? /s;
if ((my $shortstat = git qw(diff --shortstat)) && ($? >> 8) == 0) {
my ($ins) = ($shortstat =~ /([0-9]+) insertions?\(/);
my ($del) = ($shortstat =~ /([0-9]+) deletions?\(/);
push @out,
Red, [ $branch ],
'(',
Magenta,
[ ($ins ? ("+$ins" . ($del ? "/" : '')) : '') . ($del ? "-$del" : '') ],
($local_commits ? (',', Yellow, [ $local_commits ]) : ()),
')';
} elsif ($local_commits) {
push @out,
Yellow, [ $branch ],
'(', Yellow, [ $local_commits ], ')';
} else {
push @out, Green, [ $branch ];
}
if (-f "$git_dir/refs/stash") {
push @out, Red, [ '+' ];
}
if ($untracked) {
push @out, Red, [ '*' ];
}
# TODO Git mark
@out
}
}
'$';
ANGELPS1_PLUGIN_GIT
$fatpacked{"AngelPS1/Plugin/Jobs.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_JOBS';
use utf8;
use strict;
use warnings;
package AngelPS1::Plugin::Jobs;
use AngelPS1;
our $VERSION = $AngelPS1::VERSION;
use Exporter 5.57 'import';
our @EXPORT = qw<Jobs>;
use AngelPS1::System;
use AngelPS1::Chrome qw< Bold Yellow >;
sub Jobs
{
my $count_jobs = AngelPS1::System->gen_count_jobs()
or return;
my $theme = $_[0] || {};
my $chrome_suspended_count = $theme->{suspended} || (Yellow+Bold);
my @symbol_suspended = ( ($theme->{suspended_symbol} || Yellow), [ 'z' ] );
my $chrome_background_count = $theme->{background} || (Yellow+Bold);
my @symbol_background = ( ($theme->{background_symbol} || Yellow), [ '&' ] );
my @separator = exists $theme->{separator}
? ( $theme->{separator}, [ '/' ])
: ( '/' );
return sub {
my ($suspended, $background) = $count_jobs->();
return if !defined($suspended) || $suspended+$background == 0;
my @res;
push @res, $chrome_suspended_count, [ $suspended ], @symbol_suspended
if $suspended;
push @res, @separator if $suspended && $background;
push @res, $chrome_background_count, [ $background ], @symbol_background
if $background;
@res
}
}
1;
ANGELPS1_PLUGIN_JOBS
$fatpacked{"AngelPS1/Plugin/Layout.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_LAYOUT';
use strict;
use warnings;
package AngelPS1::Plugin::Layout;
our $VERSION = $AngelPS1::VERSION;
use Exporter 5.57 'import';
our @EXPORT = qw(MarginLeft MarginRight);
use AngelPS1::Compiler qw(expand);
sub MarginLeft ($;$)
{
my $code = pop;
if (!ref($code)) {
return defined($code) && length($code) ? " $code" : ();
}
die 'MarginLeft: not a CODEREF' unless ref($code) eq 'CODE';
my @margin = @_;
@margin = (' ') unless @margin;
sub {
my @result = expand(@_, $code);
return unless @result;
(@margin, @result)
}
}
sub MarginRight ($;$)
{
my $code = pop;
if (!ref($code)) {
return defined($code) && length($code) ? "$code " : ();
}
die 'MarginLeft: not a CODEREF' unless ref($code) eq 'CODE';
my @margin = @_;
@margin = (' ') unless @margin;
sub {
my @result = expand(@_, $code);
return unless @result;
(@result, @margin)
}
}
'$';
ANGELPS1_PLUGIN_LAYOUT
$fatpacked{"AngelPS1/Plugin/LoadAvg.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_LOADAVG';
use utf8;
use strict;
use warnings;
package AngelPS1::Plugin::LoadAvg;
our $VERSION = $AngelPS1::VERSION;
use Exporter 5.57 'import';
our @EXPORT = qw<LoadAvgPercent>;
use AngelPS1;
use AngelPS1::Shell;
use AngelPS1::System;
use AngelPS1::Chrome qw<Red Green Bold color>;
our $SYMBOL_LOADAVG = '⌂';
our $LOAD_THRESHOLD = 0.60;
sub LoadAvgPercent
{
my $loadavg_gen = AngelPS1::System->can('gen_loadavg')
or return;
# Plugin disabled if the encoding doesn't support the symbol
AngelPS1::_str_allowed($SYMBOL_LOADAVG) or return;
my $loadavg_func = $loadavg_gen->();
my $nproc = AngelPS1::System->nproc();
return sub {
my $loadavg = $loadavg_func->();
return if !defined($loadavg);
$loadavg /= $nproc;
return if $loadavg < $LOAD_THRESHOLD;
(
(
$loadavg < 0.80
? Green
: Red
),
[
sprintf '%s%d',
$SYMBOL_LOADAVG,
100 * $loadavg,
]
)
}
}
'$';
ANGELPS1_PLUGIN_LOADAVG
$fatpacked{"AngelPS1/Plugin/Term.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_TERM';
use strict;
use warnings;
package AngelPS1::Plugin::Term;
our $VERSION = $AngelPS1::VERSION;
use Exporter 5.57 'import';
our @EXPORT = qw(TermTitle);
use AngelPS1::Shell;
use constant {
TITLE_BEGIN => "\e]0;",
TITLE_END => "\a",
};
sub TermTitle
{
if (AngelPS1::Shell->name eq 'fish') {
require Carp;
Carp::carp("TermTitle is not supported on fish. See instead fish_title in the fish manual http://fishshell.com/docs/2.0/index.html#title");
return
}
# TODO use tsl/fsl from terminfo, if the terminfo definition has them
# TODO Truncate to wsl
# TODO check eslok and escape if necessary
AngelPS1::Shell->ps1_invisible(TITLE_BEGIN, @_, TITLE_END)
}
'$';
ANGELPS1_PLUGIN_TERM
$fatpacked{"AngelPS1/Plugin/Term/Size.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_TERM_SIZE';
use strict;
use warnings;
package AngelPS1::Plugin::Term::Size;
use AngelPS1; # $AngelPS1::TTYNAME
our $VERSION = $AngelPS1::VERSION;
use Exporter 5.57 ();
our @ISA = 'Exporter';
our @EXPORT = qw($LINES $COLUMNS);
our ($LINES, $COLUMNS);
my $TIOCGWINSZ =
# Shortcut static table
{
# $^O => ioctl TIOCGWINSZ constant
linux => 0x5413,
}->{$^O}
||
# Fallback: get the constant from ioctl.ph
eval {
package AngelPS1::Plugin::Term::Size::ioctl;
require 'sys/ioctl.ph';
delete $INC{'sys/ioctl.ph'};
\&TIOCGWINSZ
};
my $_WINSZ = pack('S4');
sub _update_from_ioctl
{
ioctl(STDERR, $TIOCGWINSZ, $_WINSZ);
($LINES, $COLUMNS) = unpack('S2', $_WINSZ);
}
sub _update_from_stty
{
my $line = $^O eq 'linux'
? `stty -F "/dev/$AngelPS1::TTYNAME" size`
# darwin, *BSD have '-f', Solaris has neither
: `stty size <"/dev/$AngelPS1::TTYNAME"`;
chomp($line);
($LINES, $COLUMNS) = split / /, $line;
}
sub import
{
# Avoid multiple install due to multiple import from different packages
unless ($SIG{WINCH}) {
if (defined $TIOCGWINSZ) {
# Terminal size change
$SIG{WINCH} = \&_update_from_ioctl;
} else {
$SIG{WINCH} = \&_update_from_stty;
}
# Fetch now
$SIG{WINCH}->();
}
$_[0]->export_to_level(1, @_);
}
'$';
ANGELPS1_PLUGIN_TERM_SIZE
$fatpacked{"AngelPS1/Plugin/Term/screen.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_TERM_SCREEN';
use strict;
use warnings;
package AngelPS1::Plugin::Term::screen;
our $VERSION = $AngelPS1::VERSION;
use Exporter 5.57 ();
our @ISA = 'Exporter';
our @EXPORT = qw(ScreenTitle);
use AngelPS1::Shell;
sub ScreenTitle
{
return if $ENV{'TERM'} ne 'screen'
|| exists $ENV{'TMUX'}
|| !exists $ENV{'TERMCAP'};
AngelPS1::Shell->ps1_invisible(
"\ek",
@_,
"\e\\"
)
}
'$';
ANGELPS1_PLUGIN_TERM_SCREEN
$fatpacked{"AngelPS1/Plugin/Term/tmux.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_TERM_TMUX';
use strict;
use warnings;
package AngelPS1::Plugin::Term::tmux;
our $VERSION = $AngelPS1::VERSION;
use Exporter 5.57 ();
our @ISA = 'Exporter';
our @EXPORT = qw(TmuxWindow TmuxTitle);
use AngelPS1::Shell;
sub TmuxWindow
{
return if !exists $ENV{'TMUX'}
|| $ENV{'TERM'} ne 'screen';
AngelPS1::Shell->ps1_invisible(
"\ek",
@_,
"\e\\"
)
}
sub TmuxTitle
{
return if !exists $ENV{'TMUX'}
|| $ENV{'TERM'} ne 'screen';
AngelPS1::Shell->ps1_invisible(
"\e]2;",
@_,
"\e\\"
)
}
'$';
ANGELPS1_PLUGIN_TERM_TMUX
$fatpacked{"AngelPS1/Plugin/VCS.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PLUGIN_VCS';
use strict;
use warnings;
package AngelPS1::Plugin::VCS;
use Exporter 'import';
our @EXPORT = qw<VCSInfo>;
use constant NO_DIR_STAT => (stat '..')[3] < 3;
sub _find_vcs_dir
{
my $dir = shift;
return if $dir eq '/';
my @stat = stat $dir;
my $dev = $stat[0];
# Look up while we are on the same filesystem
while ($stat[0] == $dev) {
if (NO_DIR_STAT || $stat[3] > 3) {
return (git => $dir) if -d "$dir/.git/objects";
return (svn => $dir) if -f "$dir/.svn/entries";
return (hg => $dir) if -d "$dir/.hg/store";
return (bzr => $dir) if -d "$dir/.bzr";
return ('git-bare' => $dir) if substr($dir, -4) eq '.git' && -d "$dir/objects"
}
# go up
substr($dir, rindex($dir, '/'), length($dir), '');
$dir or last;
@stat = stat $dir;
}
return
}
my %VCS = (
git => [
'AngelPS1/Plugin/Git.pm',
do {
require AngelPS1::Plugin::Git;
my @gitinfo = AngelPS1::Plugin::Git::GitInfo();
sub {
my ($state, $dir) = @_;
return (
sub {
$state->{GIT_DIR} = $dir;
()
},
@gitinfo,
sub {
delete $state->{GIT_DIR};
()
},
)
}
}
],
);
sub VCSInfo
{
my $options = (@_ && ref($_[0]) eq 'HASH') ? (shift) : {};
my @enabled_vcs = @_;
sub {
my $state = shift;
my ($vcs, $dir) = _find_vcs_dir($state->{PWD});
return unless defined $vcs;
my $vcs_plugin = $VCS{$vcs};
return unless defined $vcs_plugin;
require $vcs_plugin->[0];
return $vcs_plugin->[1]->($state, $dir)
}
}
1;
ANGELPS1_PLUGIN_VCS
$fatpacked{"AngelPS1/Prompt/Default.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PROMPT_DEFAULT';
use strict;
use warnings;
package AngelPS1::Prompt::Default;
use AngelPS1;
use AngelPS1::Shell qw< WorkingDir_Tilde UserPrivSymbol >;
use AngelPS1::Chrome;
use AngelPS1::Plugin::Layout 'MarginRight';
use AngelPS1::Plugin::DateTime 'Clock';
use AngelPS1::Plugin::Term;
use AngelPS1::Plugin::Term::Size;
use AngelPS1::Plugin::VCS;
use AngelPS1::Plugin::Battery 'BatteryGauge';
use AngelPS1::Plugin::LoadAvg 'LoadAvgPercent';
use AngelPS1::Plugin::Jobs 'Jobs';
use POSIX ();
return () unless AngelPS1::Shell->can('WorkingDir_Tilde')
&& AngelPS1::Shell->can('UserPrivSymbol');
(
(
# fish has its own special handling through the fish_title function
AngelPS1::Shell->name eq 'fish'
? ()
: TermTitle(
(%AngelPS1::DEBUG
? (
AngelPS1::Shell->name,
' ',
$AngelPS1::TTYNAME,
' (',
# Columns and lines are dynamic!
sub { "${COLUMNS}x${LINES}) " },
) : ()),
WorkingDir_Tilde,
)
),
# Disabled
#Blue, [ Time ], ' ',
Blue, [ Clock ], ' ',
MarginRight(' ', BatteryGauge),
MarginRight(' ', LoadAvgPercent),
MarginRight(' ', Jobs),
# User name
$< ? (scalar getpwuid $<) : (),
sub { -w $_[0]->{PWD} ? Green : Red }, [ ':' ],
WorkingDir_Tilde,
' ',
MarginRight(VCSInfo),
sub { my $err = $_[0]->{'?'}; $err == 0 ? () : (Red, [ $err ], ' ') },
# User mark: root => # else $
($< ? (Bold, [ UserPrivSymbol ]) : (Red + Bold, [ '#' ])),
' ',
)
ANGELPS1_PROMPT_DEFAULT
$fatpacked{"AngelPS1/Prompt/liquid.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'ANGELPS1_PROMPT_LIQUID';
use strict;
use warnings;
package AngelPS1::Prompt::liquid;
use AngelPS1::Chrome;
use AngelPS1::Plugin::Layout qw< MarginRight MarginLeft >;
use AngelPS1::Shell qw< WorkingDir_Tilde UserPrivSymbol >;
sub _shell_unquote ($)
{
my $txt = shift;
# This is a very simplistic implementation that
# should be enough for liquidprompt configs
$txt =~ s/^'(.*)'$/$1/
or ($txt =~ s/^"(.*)"$/$1/ and $txt =~ s/\\./\\/g);
$txt
}
my %COLOR_TRANSLATION = (
BLACK => Black,
BOLD_GRAY => Black + Bold,
WHITE => White,
BOLD_WHITE => White + Bold,