From e33012246571c7e19077b99b934e34bbb8115607 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 26 Jan 2019 18:51:26 +0100 Subject: [PATCH] add new scripts --- scripts/beep-charlie | 8 ++++++ scripts/brightness | 56 +++++++++++++++---------------------- scripts/colors | 18 ++++++++++++ scripts/fetch | 40 +++++++++++++++++++++++++++ scripts/lines | 10 +++++++ scripts/make-raspi-img | 63 ++++++++++++++++++++++++++++++++++++++++++ scripts/redshift-acpi | 30 ++++++++++++++++++++ scripts/redshift-i2c | 39 ++++++++++++++++++++++++++ 8 files changed, 230 insertions(+), 34 deletions(-) create mode 100755 scripts/beep-charlie create mode 100755 scripts/colors create mode 100755 scripts/fetch create mode 100755 scripts/lines create mode 100755 scripts/make-raspi-img create mode 100755 scripts/redshift-acpi create mode 100755 scripts/redshift-i2c diff --git a/scripts/beep-charlie b/scripts/beep-charlie new file mode 100755 index 0000000..45a44a6 --- /dev/null +++ b/scripts/beep-charlie @@ -0,0 +1,8 @@ +#!/bin/sh +head -c 8 /dev/urandom | \ + hexdump -v -e '/1 "%u\n"' | \ + awk '{ split("0,3,5,6,7,10,12",a,","); \ + for (i = 0; i < 1; i+= 0.00011) \ + printf("%08X\n", 60*sin(450*exp((a[$1 % 8]/12)*log(2))*i)) }' | \ + xxd -r -p | \ + aplay -c 1 -f S32_LE -r 48000 -D plug:default diff --git a/scripts/brightness b/scripts/brightness index 63ffee7..c51f8fa 100755 --- a/scripts/brightness +++ b/scripts/brightness @@ -1,39 +1,27 @@ #!/bin/sh -# Set brightness for DDC/CI enabled monitors +# set backlight brightness level -export PATH="/var/setuid-wrappers:$PATH" +current=$(cat /sys/class/backlight/intel_backlight/brightness) -# monitor i2c device -device=dev:/dev/i2c-0 - -# brightness values -night=35 -transition=45 -daytime=60 - - -deref() { - eval "echo \$$1" -} - -set_brightness() { - sudo ddccontrol $device -r 0x10 -w > /dev/null $1 2>&1 -} - -fade_to() { - current=$(sudo ddccontrol $device -r 0x10 2> /dev/null | grep -oP '\+/\K[0-9]+') - [ $current -gt $1 ] && step=-1 || step=1 - for i in $(seq $current $step $1); do - set_brightness $i - sleep 1 - done -} - - -if [ $1 = "period-changed" ]; then - if ! (lsmod | grep -q "^i2c_dev"); then - sudo modprobe i2c-dev - fi - fade_to $(deref $3) +if test -z "$1"; then + echo $current + exit 0 fi + +case "$1" in +'+' | '-') + if test -z "$2"; then + echo "missing increment" + exit 1 + fi + new=$(("$current" "$1" "$2")) +;; +*) + echo "invalid argument '$1'" + exit 1 +;; +esac + +echo "current: $new" +echo $new > /sys/class/backlight/intel_backlight/brightness diff --git a/scripts/colors b/scripts/colors new file mode 100755 index 0000000..e2186da --- /dev/null +++ b/scripts/colors @@ -0,0 +1,18 @@ +#!/usr/bin/env fish + +set colors black red green yellow blue magenta cyan white + +function colored + set_color -b $argv[1] + set_color 181b20 + echo -n $argv[2] + set_color normal +end + +for i in (seq 8) + printf "%02d %32s %02d %40s\n" \ + (math $i - 1) \ + (colored $colors[$i] $colors[$i]) \ + (math $i + 7) \ + (colored br$colors[$i] "bright "$colors[$i]) +end diff --git a/scripts/fetch b/scripts/fetch new file mode 100755 index 0000000..5bd641f --- /dev/null +++ b/scripts/fetch @@ -0,0 +1,40 @@ +#!/usr/bin/env fish + +# Outputs colored text +function color + set_color $argv[1] + for i in $argv[2..-1] + echo -n $i + end + set_color normal +end + + +set cpu_model (awk '/model name/ {print $6; exit}' /proc/cpuinfo) +set cpu_freq (awk '{printf("%.2fHz", $0/1e6)}' /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq) +set cpu_temp (awk '{printf("%dK", $0/1e3+273.15)}' /sys/class/thermal/thermal_zone3/temp) + +set gpu_model (lspci | awk -F [][] '/VGA/ {print $4}') + +set mem_used (awk '/Active/ {printf("%.1f", $2/1e6); exit}' /proc/meminfo) +set mem_tot (awk '/MemTotal/ {printf("%.1f", $2/1e6); exit}' /proc/meminfo) + +set uptime (awk '{printf("%d:%02d:%02d",($1/60/60/24),($1/60/60%24),($1/60%60))}' /proc/uptime) + +set kernel (uname -sr) +set os (awk -F= '/^NAME/ {print $2}' /etc/os-release) + +set screen (xrandr | grep \* | awk '{print $1}') +set shell (basename $SHELL) + +echo -n \33c +echo (color blue OS:) $os GNU+$kernel +echo (color blue CPU:) $cpu_model $cpu_freq [$cpu_temp] +echo (color blue GPU:) $gpu_model +echo (color blue RAM:) $mem_used/$mem_tot GB +echo (color blue Screen:) $screen +echo (color blue Uptime:) $uptime +echo (color blue WM:) bspwm +echo (color blue Shell:) $shell +echo (color blue Font:) gohufont +echo diff --git a/scripts/lines b/scripts/lines new file mode 100755 index 0000000..2cc973d --- /dev/null +++ b/scripts/lines @@ -0,0 +1,10 @@ +#!/usr/bin/env fish + +set char ╱ ╲ +set num (math (tput cols)'*'(tput lines)) + +set_color yellow +for i in (seq $num) + echo -n $char[(random 1 2)] +end +cat - diff --git a/scripts/make-raspi-img b/scripts/make-raspi-img new file mode 100755 index 0000000..991c88a --- /dev/null +++ b/scripts/make-raspi-img @@ -0,0 +1,63 @@ +#!/bin/sh + +# Packages required +# dosfstools parted +# Can be run on any Linux system +# loop.max_part=15 must be in kernel cmdline (cmdline.txt for rpi) +# then reboot + +echo "creating image to fit on 2Gb card" +dd if=/dev/zero of=arch-rpi.img bs=1M count=1850 + +echo "Partitioning" +fdisk arch-rpi.img < /dev/null + sleep 1 + done +} + + +if [ "$1" = "period-changed" ]; then + fade_to "$(deref "$3")" +fi diff --git a/scripts/redshift-i2c b/scripts/redshift-i2c new file mode 100755 index 0000000..63ffee7 --- /dev/null +++ b/scripts/redshift-i2c @@ -0,0 +1,39 @@ +#!/bin/sh + +# Set brightness for DDC/CI enabled monitors + +export PATH="/var/setuid-wrappers:$PATH" + +# monitor i2c device +device=dev:/dev/i2c-0 + +# brightness values +night=35 +transition=45 +daytime=60 + + +deref() { + eval "echo \$$1" +} + +set_brightness() { + sudo ddccontrol $device -r 0x10 -w > /dev/null $1 2>&1 +} + +fade_to() { + current=$(sudo ddccontrol $device -r 0x10 2> /dev/null | grep -oP '\+/\K[0-9]+') + [ $current -gt $1 ] && step=-1 || step=1 + for i in $(seq $current $step $1); do + set_brightness $i + sleep 1 + done +} + + +if [ $1 = "period-changed" ]; then + if ! (lsmod | grep -q "^i2c_dev"); then + sudo modprobe i2c-dev + fi + fade_to $(deref $3) +fi