From b5cc1ac0f2d869f3c1f602c5b23926db900a8f26 Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Fri, 29 Sep 2023 15:47:51 +0800 Subject: [PATCH] implement scripts with rc --- .bash_profile | 2 +- .bashrc | 66 ++--------------------------------- .config/sway/config | 2 +- .local/bin/gogrep | 3 ++ .local/bin/imgcat | 8 +++++ .local/bin/play-playlist | 2 ++ .local/bin/psave | 9 +++++ .local/bin/rc | 1 + .local/bin/screenshot | 15 ++++---- .local/bin/st | 6 ++++ .local/bin/tiocgwinsz | 3 ++ .local/bin/vidcat | 4 +++ .local/libexec/title-watch | 9 +++++ .local/libexec/title-watch.sh | 31 ---------------- 14 files changed, 55 insertions(+), 106 deletions(-) create mode 100755 .local/bin/gogrep create mode 100755 .local/bin/imgcat create mode 100755 .local/bin/play-playlist create mode 100755 .local/bin/psave create mode 120000 .local/bin/rc create mode 100755 .local/bin/st create mode 100755 .local/bin/tiocgwinsz create mode 100755 .local/bin/vidcat create mode 100755 .local/libexec/title-watch delete mode 100755 .local/libexec/title-watch.sh diff --git a/.bash_profile b/.bash_profile index be88917..c1ad532 100644 --- a/.bash_profile +++ b/.bash_profile @@ -12,7 +12,7 @@ export XDG_DATA_HOME="$HOME/.local/share" export XDG_DATA_DIRS="$XDG_DATA_HOME/flatpak/exports/share:/var/lib/flatpak/exports/share:$XDG_DATA_HOME:/usr/local/share:/usr/share" # be careful that composer does not uses XDG when no XDG_* defined -PATH="$HOME/go/bin:$HOME/.local/bin:$XDG_DATA_HOME/npm/bin/:$XDG_CONFIG_HOME/composer/vendor/bin/:$PATH" +PATH="$HOME/go/bin:$HOME/.local/bin:$XDG_DATA_HOME/npm/bin/:$XDG_CONFIG_HOME/composer/vendor/bin/:$PATH:/usr/lib/9base/bin" # XDG workarounds [ ! -d "$XDG_CACHE_HOME" ] && mkdir "$XDG_CACHE_HOME" diff --git a/.bashrc b/.bashrc index d3492c6..b2f543e 100644 --- a/.bashrc +++ b/.bashrc @@ -57,78 +57,16 @@ if [ -f /usr/bin/composer.phar ]; then fi alias artisan81="php81 artisan" alias artisan="php82 artisan" -alias tiocgwinsz="python3 -c \"import struct, fcntl, termios; print('%d %d %d %d' % struct.unpack('4H', fcntl.ioctl(2, termios.TIOCGWINSZ, ' ' * 8)))\"" alias dl="curl -OJLR --compressed" alias errno="grep -h '^#define[[:space:]]*E' /usr/include/asm-generic/errno* | sed 's|^#define[[:space:]]*||'" alias signal="grep -h '^#define SIG' /usr/include/asm/signal.h | sed 's|^#define ||'" - -play-playlist() { - ARGS= - for list in $@;do - ARGS="$ARGS --playlist=$list" - done - mpv --ytdl-raw-options=audio-format=best --shuffle --slang=ja,zh-TW --sub-visibility --no-video $ARGS -} - -psave() { - if [ "$1" = "perf" ];then - echo powersave perfomance - echo performance | doas tee /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference >/dev/null - elif [ "$1" = "off" ];then - echo powersave off - echo balance_performance | doas tee /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference >/dev/null - else - echo powersave on - echo power | doas tee /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference >/dev/null - fi -} - -timesync() { - doas busybox ntpd -dqn -p time.stdtime.gov.tw - doas busybox hwclock -wu -} +alias timesync='doas busybox ntpd -dqn -p time.stdtime.gov.tw && doas busybox hwclock -wu' +alias notify="printf '\x1b]777;notify;title;%s\x1b'" sleepto() { sleep $(($(date --date="$1" +%s) - $EPOCHSECONDS)) } -imgcat_max_pixels() { - tiocgwinsz | ( - IFS=' ' read MROW MCOL MX MY - echo ${MX}x$(($MY / $MROW * $(($MROW - 1)))) - ) -} - -imgcat() { - MAX=$(imgcat_max_pixels) - for i; do - convert "$i" ${MAX:+-resize ${MAX}>} sixel:- - echo - done -} - -vidcat() { - for i; do - ffmpeg -i "$i" -ss 1 -loglevel warning -vframes 1 -f apng - | imgcat - - done -} - -notify() { - printf "\x1b]777;notify;title;%s\x1b"'\\\n' "$@" -} - -st() { - ST_SERVER=$(curl -q https://www.speedtest.net/speedtest-servers-static.php 2>/dev/null | head -n 3 | tail -n 1 | cut -f 2 -d '"') - echo download - curl -q "$(dirname "$ST_SERVER")"/random7000x7000.jpg -m 10 >/dev/null - echo upload - head -c 100M /dev/urandom | curl -q "$ST_SERVER" -m 10 --data-binary @- >/dev/null -} - -gogrep() { - IFS=$'\n' grep "$@" $(go list -deps -f '{{range .GoFiles}}{{printf "%s/%s\n" $.Dir .}}{{end}}') -} - # application envs export GPG_TTY=$(tty 2>/dev/null) diff --git a/.config/sway/config b/.config/sway/config index 10c0367..c33f29b 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -4,7 +4,7 @@ exec { pipewire mako foot --server - ~/.local/libexec/title-watch.sh + ~/.local/libexec/title-watch wlchewing -e -d no -f "Noto Sans CJK TC 11" -b#303030 -s#80cbc4 -S#101a19 2>/tmp/wlchewing.log dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP GTK_THEME } diff --git a/.local/bin/gogrep b/.local/bin/gogrep new file mode 100755 index 0000000..b2ab877 --- /dev/null +++ b/.local/bin/gogrep @@ -0,0 +1,3 @@ +#!/usr/lib/9base/bin/rc -e +ifs=' +' grep '--color=auto' $* `{go list -deps -f '{{range .GoFiles}}{{printf "%s/%s\n" $.Dir .}}{{end}}'} diff --git a/.local/bin/imgcat b/.local/bin/imgcat new file mode 100755 index 0000000..2e4630c --- /dev/null +++ b/.local/bin/imgcat @@ -0,0 +1,8 @@ +#!/usr/lib/9base/bin/rc -e +convert $* `{ + # XXX: $foo(1)x and `{}x produce spaces between? + rcxy=`{tiocgwinsz} && echo -resize $rcxy(3)^x`{ + echo $rcxy(4) / $rcxy(1) '* ('$rcxy(1) - 1')' | bc + }^'>' +} sixel:- +echo diff --git a/.local/bin/play-playlist b/.local/bin/play-playlist new file mode 100755 index 0000000..8c7448b --- /dev/null +++ b/.local/bin/play-playlist @@ -0,0 +1,2 @@ +#!/usr/lib/9base/bin/rc -e +mpv '--ytdl-raw-options=audio-format=best' --shuffle '--slang=ja,zh-TW' --sub-visibility --no-video '--playlist='$* diff --git a/.local/bin/psave b/.local/bin/psave new file mode 100755 index 0000000..a3f7a04 --- /dev/null +++ b/.local/bin/psave @@ -0,0 +1,9 @@ +#!/usr/lib/9base/bin/rc -e +switch($1) { + case p* + echo performance + case of* + echo balance_performance + case * + echo power +} | doas tee /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference diff --git a/.local/bin/rc b/.local/bin/rc new file mode 120000 index 0000000..c04b824 --- /dev/null +++ b/.local/bin/rc @@ -0,0 +1 @@ +/usr/lib/9base/bin/rc \ No newline at end of file diff --git a/.local/bin/screenshot b/.local/bin/screenshot index eecf60c..e53cecd 100755 --- a/.local/bin/screenshot +++ b/.local/bin/screenshot @@ -1,9 +1,6 @@ -#!/bin/sh - -set -e - -STAMP=$(date +%Y%m%d-%H%M%S) - -[ "$1" = crop ] && COR=$(slurp) -grim ${COR:+"-g$COR"} ~/Pictures/$STAMP.png -notify-send -i ~/Pictures/$STAMP.png Screenshot "$STAMP.png saved${COR:+, $COR}" +#!/usr/lib/9base/bin/rc -e +stamp=`{date +%Y%m%d-%H%M%S} +coord=`{~ $1 crop && slurp} +ifs=' +' grim `{~ $#coord 0 || echo -g$"coord} $home/Pictures/$stamp.png +notify-send -i $home/Pictures/$stamp.png Screenshot $stamp.png' 'saved' '$"coord diff --git a/.local/bin/st b/.local/bin/st new file mode 100755 index 0000000..19cb00e --- /dev/null +++ b/.local/bin/st @@ -0,0 +1,6 @@ +#!/usr/lib/9base/bin/rc -e +server=`{curl -q https://www.speedtest.net/speedtest-servers-static.php >[2=] | head -n 3 | tail -n 1 | cut -f 2 -d "} +echo download +curl -q $server/random7000x7000.jpg -m 10 >/dev/null || true +echo upload +head -c 100M /dev/urandom | curl -q $server -m 10 --data-binary @- >/dev/null || true diff --git a/.local/bin/tiocgwinsz b/.local/bin/tiocgwinsz new file mode 100755 index 0000000..b75be95 --- /dev/null +++ b/.local/bin/tiocgwinsz @@ -0,0 +1,3 @@ +#!/usr/bin/env python3 +import struct, fcntl, termios +print('%d %d %d %d' % struct.unpack('4H', fcntl.ioctl(2, termios.TIOCGWINSZ, ' ' * 8))) diff --git a/.local/bin/vidcat b/.local/bin/vidcat new file mode 100755 index 0000000..98fba9b --- /dev/null +++ b/.local/bin/vidcat @@ -0,0 +1,4 @@ +#!/usr/lib/9base/bin/rc -e +for(i) { + ffmpeg -i $i -ss 1 -loglevel warning -vframes 1 -f apng - | imgcat - +} diff --git a/.local/libexec/title-watch b/.local/libexec/title-watch new file mode 100755 index 0000000..047e442 --- /dev/null +++ b/.local/libexec/title-watch @@ -0,0 +1,9 @@ +#!/usr/lib/9base/bin/rc -e +ifs=' +' playerctl metadata -F --format '{{ title }} {{ emoji(status) }}' | + while(line=`{read}) switch($#line) { + case 0 + rm /tmp/cur_music + case * + echo $line >/tmp/cur_music + } diff --git a/.local/libexec/title-watch.sh b/.local/libexec/title-watch.sh deleted file mode 100755 index 0cc8c2d..0000000 --- a/.local/libexec/title-watch.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -#VALID_TITLE= -#VALID_STATUS=Playing - -#busctl -j --user monitor org.mpris.MediaPlayer2.vlc | while read -r LINE;do -# MEMBER=$(echo $LINE | jq -re '.member') -# if [ "$MEMBER" = 'NameLost' ]; then -# rm /tmp/cur_music -# elif [ ! -f /tmp/cur_music ]; then -# echo "$VALID_TITLE ($VALID_STATUS)" | tee /tmp/cur_music -# fi -# TITLE=$(echo $LINE | jq -re '.payload.data[1].Metadata.data."xesam:title".data') -# if [ $? -eq 0 ];then -# VALID_TITLE=$TITLE -# echo "$VALID_TITLE ($VALID_STATUS)" | tee /tmp/cur_music -# fi -# PS=$(echo $LINE | jq -re '.payload.data[1].PlaybackStatus.data') -# if [ $? -eq 0 ];then -# VALID_STATUS=$PS -# echo "$VALID_TITLE ($VALID_STATUS)" | tee /tmp/cur_music -# fi -#done - -playerctl metadata -F --format '{{ title }} {{ emoji(status) }}' | while read -r LINE;do - if [ -z "$LINE" ];then - rm /tmp/cur_music - else - echo $LINE > /tmp/cur_music - fi -done -- 2.43.0