~xdavidwu/dotfiles

b5cc1ac0f2d869f3c1f602c5b23926db900a8f26 — Pinghao Wu 1 year, 2 months ago 04ee30e
implement scripts with rc
M .bash_profile => .bash_profile +1 -1
@@ 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"

M .bashrc => .bashrc +2 -64
@@ 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)


M .config/sway/config => .config/sway/config +1 -1
@@ 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
}

A .local/bin/gogrep => .local/bin/gogrep +3 -0
@@ 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}}'}

A .local/bin/imgcat => .local/bin/imgcat +8 -0
@@ 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

A .local/bin/play-playlist => .local/bin/play-playlist +2 -0
@@ 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='$*

A .local/bin/psave => .local/bin/psave +9 -0
@@ 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

A .local/bin/rc => .local/bin/rc +1 -0
@@ 0,0 1,1 @@
/usr/lib/9base/bin/rc
\ No newline at end of file

M .local/bin/screenshot => .local/bin/screenshot +6 -9
@@ 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

A .local/bin/st => .local/bin/st +6 -0
@@ 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

A .local/bin/tiocgwinsz => .local/bin/tiocgwinsz +3 -0
@@ 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)))

A .local/bin/vidcat => .local/bin/vidcat +4 -0
@@ 0,0 1,4 @@
#!/usr/lib/9base/bin/rc -e
for(i) {
	ffmpeg -i $i -ss 1 -loglevel warning -vframes 1 -f apng - | imgcat -
}

A .local/libexec/title-watch => .local/libexec/title-watch +9 -0
@@ 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
	}

D .local/libexec/title-watch.sh => .local/libexec/title-watch.sh +0 -31
@@ 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