<commit_before>#!/usr/bin/perl

## Includes
use Getopt::Long;

## Constants
my $interval = 1;
my $wdev = "wlp3s0";
my @vpns = ( "openconnect", "vpnc" );

## Commands
my $awk = "/usr/bin/awk";
my $grep = "/bin/grep";
my ${ifconfig} = "/bin/ifconfig";
my $iw = "/usr/sbin/iw";
my $ps = "/bin/ps";
my $sed	= "/bin/sed";

## Flags
my $flag_test;

## Global Variables
my $wdev;

## Enable bundling of single character options... risky business
Getopt::Long::Configure( "bundling" );

## Process Parameters
GetOptions( "test|t"            => \$flag_test,
            "wireless|wdev|w=s" => \$wdev);

# Sanitize wireless device if it's provided
if( defined $wdev ) {
	$wdev = untaintValue($wdev);
} else {
	$wdev = getWireless();
}

## Infinite print loop
while(1){
	# Perform battery calculations
	my $sign = `cat /sys/class/power_supply/BAT0/status`;
	my $percentBattString;
	my $displayString;
	
	chomp($sign);
	# Apply a sign
	$sign =~ s/^Charging/+/g;
	$sign =~ s/^Discharging/-/g;
	
	# Retrieve date information and format it HH:MM
	my $dateString 	= `date +"%F %R"`;
	chomp($dateString);
	
	# Check for vpn
	if (&isVPN()){
		$displayString = "VPN ";
	}
	
	# Check the wireless status
	if ( defined $wdev ) {
		my $wstat = checkWireless( $wdev );
		$displayString = "${displayString}${wstat}"
	}

	# Retrieve battery status
	unless ( $sign =~ m/Full/ ) {
		my $fullBatt 	= `cat /sys/class/power_supply/BAT0/charge_full`;
		my $curBatt 	= `cat /sys/class/power_supply/BAT0/charge_now`;
		my $percentBatt = $curBatt / $fullBatt * 100;
		$percentBattString = sprintf('%.2f', $percentBatt);

		$displayString = "${displayString} ${sign}${percentBattString}\% ${dateString}";
	} else {
		$displayString = "${displayString} ${sign} ${dateString}";
	}
	
	# Update dwm root or just print to STDOUT
	unless( $flag_test) {
		`xsetroot -name "${displayString}"`;
	} else {
		print "${displayString}", "\n";
	}

	# Wait our sleep interval
	sleep $interval;
}

## isVPN ======================================================
# Determines the active SSID for the provided wireless device
## ============================================================
sub isVPN {
	my $rc = 0;
	foreach( @vpns ) {
		my $command = "${ps} -e | ${awk} \'{print \$4;}\' | ${grep} $_";
		chomp(my $rc_ps = `$command`);
		if($rc_ps) {
			$rc = 1;
			last;
		}
	}
	return $rc;
}
<commit_msg>Corrected status when the battery is removed<commit_after>#!/usr/bin/perl

## Includes
use Getopt::Long;

## Paths
my $battpath = "/sys/class/power_supply/BAT0/";

## Constants
my $interval = 1;
my @vpns = ( "openconnect", "vpnc" );

## Commands
my $awk = "/usr/bin/awk";
my $grep = "/bin/grep";
my ${ifconfig} = "/bin/ifconfig";
my $iw = "/usr/sbin/iw";
my $ps = "/bin/ps";
my $sed	= "/bin/sed";

## Flags
my $flag_test;

## Global Variables
my $wdev;

## Enable bundling of single character options... risky business
Getopt::Long::Configure( "bundling" );

## Process Parameters
GetOptions( "test|t"            => \$flag_test,
            "wireless|wdev|w=s" => \$wdev);

# Sanitize wireless device if it's provided
if( defined $wdev ) {
	$wdev = untaintValue($wdev);
} else {
	$wdev = getWireless();
}

## Infinite print loop
while( 1 ){
	my $displayString;
	
	# Retrieve date information and format it HH:MM
	my $dateString 	= `date +"%F %R"`;
	chomp( $dateString );
	
	# Check the wireless status
	if ( defined $wdev ) {
		my $wstat = checkWireless( $wdev );
		$displayString = "${displayString} ${wstat}"
	}
	
	# Check for vpn
	if( &isVPN() ) {
		$displayString = "VPN ${displayString}";
	}

	# Retrieve battery status
	if( -e $battpath ) {
		my $battStat = checkBattery();
		$displayString = "${displayString} ${battStat} ${dateString}";
	} else { 
		$displayString = "${displayString} ${dateString}";
	}
	
	# Update dwm root or just print to STDOUT
	unless( $flag_test ) {
		`xsetroot -name "${displayString}"`;
	} else {
		print "${displayString}", "\n";
	}

	# Wait our sleep interval
	sleep $interval;
}

## isVPN ======================================================
# Determines the active SSID for the provided wireless device
## ============================================================
sub isVPN {
	my $rc = 0;
	foreach( @vpns ) {
		my $command = "${ps} -e | ${awk} \'{print \$4;}\' | ${grep} $_";
		chomp(my $rc_ps = `$command`);
		if($rc_ps) {
			$rc = 1;
			last;
		}
	}
	return $rc;
}

## checkBattery ===============================================
# Calculate current battery statuses
## ============================================================
sub checkBattery {
	my $batteryStatus;
	
	# Charge statistics
	my $charge_design = `cat /sys/class/power_supply/BAT0/charge_full_design`;
	my $charge_full   = `cat /sys/class/power_supply/BAT0/charge_full`;
	my $charge        = `cat /sys/class/power_supply/BAT0/charge_now`;
	my $ac_offline    = `cat /sys/class/power_supply/AC/online`;

	# Perform battery calculations
	my $charge_percent;

	# Determine whether we're charging or not 
	my $sign;
	unless( $ac_offline ) {
		$sign = "+";
	} else {
		$sign = "-";
	}

	# Calculate battery status if we're not full
	unless( $charge == $charge_design ) {
		$charge_percent = $charge / $charge_full * 100;
		$charge_percent = sprintf( '%.2f', $charge_percent );
		$batteryStatus = "${sign}${charge_percent}\%";
	} else {
		$batteryStatus = "Full";
	}
	
	return $batteryStatus;
}

{'fraction_non_alphanumeric': 0.22780788637637825, 'fraction_numerical': 0.005045785834423472, 'mean_word_length': 3.9601482854494905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2161329', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1931, 'n_words': 482}