Skip to main content

diskRipper.sh

Apr 21, 2021LeifMessinger
Loading...

More Shell Posts

getDependencies.sh

Oct 30, 2020LeifMessinger

0 likes • 2 views

#!/bin/bash
#getDependencies.sh by Leif Messinger
grep -Po '#include\s*"\K.+(?=")' | while read -r line ; do
echo -n " $line"
./getDependencies.sh < $line
done

unexpandDirectory.sh

May 13, 2023LeifMessinger

0 likes • 1 view

#!/bin/bash
# Turns 4 spaces into tabs.
# Mostly stolen from AI
# Define the directory to process
DIRECTORY=$1
TabCount=${2:-'4'} #Defaults to 4
# Check if directory is specified
if [ -z "$DIRECTORY" ]; then
echo "Error: Directory not specified."
exit 1
fi
# Check if directory exists
if [ ! -d "$DIRECTORY" ]; then
echo "Error: Directory does not exist."
exit 1
fi
# Find all files in directory and subdirectories
FILES=$(find "$DIRECTORY" -type f)
# Loop through each file and unexpand it
for FILE in $FILES; do
unexpand -t "$TabCount" "$FILE" > "$FILE.tmp"
mv "$FILE.tmp" "$FILE"
done
echo "Done!"

LeetCode #192: Word Frequency

Oct 15, 2022CodeCatch

0 likes • 60 views

awk '\
{ for (i=1; i<=NF; i++) { ++D[$i]; } }\
END { for (i in D) { print i, D[i] } }\
' words.txt | sort -nr -k 2

NPM Workspaces Commands

Aug 16, 2023CHS

0 likes • 2 views

# Run "test" script on all packages
npm run test --workspaces
# Tip - this also works:
npm run test -ws
----------------------------------------------------
# Runs "test" only on package-a
npm run test --workspace package-a
# Tip - this also works:
npm run test -w package-a
----------------------------------------------------
# Install `lodash` on `package-a`
npm install lodash --workspace package-a
# Install `tap` on `package-b` as a dev dependency
npm install tap --workspace package-b --save-dev
# Install `package-a` on `package-b`
npm install package-a --workspace package-b
# Install `eslint` in all packages
npm install eslint --workspaces

pinger.sh

Mar 21, 2021LeifMessinger

0 likes • 0 views

#pinger.sh by Leif Messinger
#./pinger.sh [ADDRESS] to search
#./pinger.sh [ADDRESS] & to search in the background
#https://serverfault.com/a/42382
ping_cancelled=false # Keep track of whether the loop was cancelled, or succeeded
until ping -c1 "$1" >/dev/null 2>&1; do :; done & # The "&" backgrounds it
trap "kill $!; ping_cancelled=true" SIGINT
wait $! # Wait for the loop to exit, one way or another
trap - SIGINT # Remove the trap, now we're done with it
if [ "$ping_cancelled" == true ] #https://stackoverflow.com/a/21210966/10141528
then
printf "The pinger for $1 just closed bro.\n"
else
printf "$1 IS UP BROOO\a\n"
fi

Untitled

May 20, 2024AustinLeath

0 likes • 10 views

#!/bin/sh
BAT_LOW=15
BAT_CRITICAL=5
if [ "$1" = "--help" ]
then
printf "
Usage:
\tbattery_check.sh warning%% hibernate%%
Description:
\tA script for notifying the user via dunst and logging when
\tthe battery is low and the system is going to hibernate.
\tCan be supplied arguments for the battery low warning and
\thibernation percentage thresholds as the first and second arguments.
\t Default behavior is to warn at 15% and hibernate at 5%."
exit
fi
if [[ -n "$1" && -n "$2" && $1 -gt $2 ]]
then
BAT_LOW=$1
BAT_CRITICAL=$2
fi
acpi -b | awk -F'[,:%]' '{print $2, $3}' | {
read -r status capacity
echo Low threshold: $BAT_LOW, Hibernate threshold: $BAT_CRITICAL
echo Status: $status, Capacity: $capacity
if [ "$status" = Discharging -a "$capacity" -le $BAT_CRITICAL ]; then
echo Battery critical threshold.
dunstify -u critical "Critical battery threshold, hibernating..."
logger "Critical battery threshold, hibernating..."
sleep .5
systemctl hibernate
exit
fi
if [ "$status" = Discharging -a "$capacity" -le $BAT_LOW ]; then
echo Battery low threshold.
dunstify -u critical 'Battery low! System will hibernate at 5%.'
logger 'Battery low! System will hibernate at 5%.'
sleep .5
light -S 15
exit
fi
}