aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorXiao Pan <gky44px1999@gmail.com>2023-04-21 23:12:25 -0700
committerXiao Pan <gky44px1999@gmail.com>2023-04-21 23:12:25 -0700
commit4f0d99e04c15e999afbe73af3b685a9704927918 (patch)
tree6bdf6ad7545ff546e17013cb3c47e1a659d1d37d /sh
parentf7b6653c92b6e20760b79eea49fe21194a7f3e4b (diff)
add new archive files
Diffstat (limited to 'sh')
-rwxr-xr-xsh/datec3
-rwxr-xr-xsh/dopro26
-rwxr-xr-xsh/mpvsel_douyu10
-rwxr-xr-xsh/my_aur_publish9
-rwxr-xr-xsh/sbar_mullvad_status112
-rw-r--r--sh/snippets45
6 files changed, 205 insertions, 0 deletions
diff --git a/sh/datec b/sh/datec
new file mode 100755
index 0000000..8146a68
--- /dev/null
+++ b/sh/datec
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+TZ=Asia/Shanghai date '+%a %m/%d/%Y %H:%M:%S UTC%:::z'
diff --git a/sh/dopro b/sh/dopro
new file mode 100755
index 0000000..981edad
--- /dev/null
+++ b/sh/dopro
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+sed -i '1s|^|# references:\
+# https://github.com/cspiegel/qmmp-adplug\
+# https://github.com/cspiegel/qmmp-openmpt\n\n|' ./*.pro
+echo '
+CONFIG += warn_on plugin link_pkgconfig
+
+TEMPLATE = lib
+
+QMAKE_CLEAN += lib$${TARGET}.so
+
+unix {
+ CONFIG += link_pkgconfig
+ PKGCONFIG += qmmp
+
+ QMMP_PREFIX = $$system(pkg-config qmmp --variable=prefix)
+ PLUGIN_DIR = $$system(pkg-config qmmp --variable=plugindir)/Input
+ LOCAL_INCLUDES = $${QMMP_PREFIX}/include
+ LOCAL_INCLUDES -= $$QMAKE_DEFAULT_INCDIRS
+ INCLUDEPATH += $$LOCAL_INCLUDES
+
+ plugin.path = $${PLUGIN_DIR}
+ plugin.files = lib$${TARGET}.so
+ INSTALLS += plugin
+}' >> "$(find . -type f -name "*.pro")"
diff --git a/sh/mpvsel_douyu b/sh/mpvsel_douyu
new file mode 100755
index 0000000..a5625f0
--- /dev/null
+++ b/sh/mpvsel_douyu
@@ -0,0 +1,10 @@
+#!/bin/sh
+# references:
+# https://www.rockyourcode.com/til-how-to-watch-youtube-videos-with-mpv-and-keyboard-shortcuts/
+# https://github.com/mpv-player/mpv/issues/7792
+
+url=$(xsel -ob)
+case $url in
+ *'douyu'*) alacritty -e mpv "$(basename "$url" | python "$HOME/programs/real-url/douyu.py" | tail -1)" & ;;
+ *) mpv --ytdl-format='bestvideo[height<=?900][fps<=?60][vcodec!^=?vp9][vcodec!^=?av01]+bestaudio/bestbestvideo[height<=?900][fps<=?60][vcodec!^=?vp9][vcodec!^=?av01]' --ytdl-raw-options='write-sub=,sub-lang="en,en-US,en-GB,zh-CN,zh-Hans,zh-Hant,zh-HK,zh-SG,zh-TW"' --fs --speed=2 --af=rubberband=pitch-scale=0.981818181818181 "$url" ;;
+esac
diff --git a/sh/my_aur_publish b/sh/my_aur_publish
new file mode 100755
index 0000000..18c829a
--- /dev/null
+++ b/sh/my_aur_publish
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+for dir; do
+ git -C "$dir" init
+ git -C "$dir" remote add origin "ssh://aur@aur.archlinux.org/$(basename "$(realpath "$dir")").git"
+ git -C "$dir" add PKGBUILD .SRCINFO
+ git -C "$dir" commit -m 'init'
+ git -C "$dir" push --set-upstream origin master
+done
diff --git a/sh/sbar_mullvad_status b/sh/sbar_mullvad_status
new file mode 100755
index 0000000..0a80dd4
--- /dev/null
+++ b/sh/sbar_mullvad_status
@@ -0,0 +1,112 @@
+#!/bin/sh
+# steal from pystardust, GPL3 license: https://github.com/pystardust/sbar
+# modified to fit my own need
+
+# INIT
+pid_file="$XDG_CACHE_HOME/pidofbar"
+vpn_fifo="$XDG_CACHE_HOME/sbar_vpn_fifo"
+sec=0
+
+# exit if sbar is already running, fix when startx in another tty, the other tty sbar not working
+# maybe try dwmblocks's approach of using `kill $(pidof -x sbar)`, so can run different sbar in different tty
+# but then vpn_fifo becomes a problem too, not sure how to solve
+if ! [ -e "$pid_file" ] || ! pidof -qsx sbar -o "$$"; then
+ printf '%s' "$$" > "$pid_file"
+else
+ exit
+fi
+if ! [ -e "$vpn_fifo" ]; then
+ mkfifo "$vpn_fifo"
+elif ! [ -p "$vpn_fifo" ]; then
+ exit 1
+fi
+
+bool () {
+ read str
+ if [ "$str" = "on" ] || [ "$str" = "up" ] || [ "$str" = "Connected" ]; then
+ echo 1
+ else
+ echo 0
+ fi
+}
+
+# MODULES
+update_time () {
+ time="$(date '+%a %m/%d %H:%M') $(TZ=Asia/Shanghai date '+/%d %H:')"
+}
+
+update_cap () {
+ cap="$(if xset q | grep -q "Caps Lock: *on"; then echo A; else echo a; fi)"
+}
+
+update_net () {
+ net="$(bool < /sys/class/net/wlp6s0/operstate)"
+}
+
+update_vpn () {
+ vpn="$(awk '{print $3}' "$vpn_fifo" | bool)"
+}
+
+update_vol () {
+ # $(NF-1) for both alsa and pulseaudio
+ vol="$(amixer get Master | awk -F'[][]' 'END{printf("%d %s",($(NF-1)=="on")?1:0,$2)}')"
+}
+
+update_mic () {
+ # $(NF-1) for both alsa and pulseaudio
+ mic="$(amixer get Capture | awk -F'[][]' 'END{print $(NF-1)}' | bool)"
+}
+
+update_bat () {
+ bat="$(cat /sys/class/power_supply/BAT1/capacity)%"
+}
+
+# For calcurse users, refer https://github.com/pystardust/automeet
+#update_event () {
+# event="$(calcurse -n | sed 1d | \
+# sed -E "s_^ *\[(.*):(.*)\] ([^\t]*)\t?.*_[\1h \2m->\3]_")"
+# [ "[]" = "$event" ] && event=""
+#}
+
+display () {
+ xsetroot -name "$time | N $net V $vpn | M $vol C $mic | $cap | $bat"
+}
+
+# modules that don't update on their own need to be run at the start for getting their initial value
+update_vol
+update_mic
+
+# SIGNALLING
+# trap "<function>;display" "RTMIN+n"
+trap "update_mic;display" "RTMIN"
+trap "update_vol;display" "RTMIN+1"
+# xev can't read my toggle internet keyboard key, don't know what key to use in sxhkd to send signal
+#trap "update_net;display" "RTMIN+2"
+trap "update_cap;display" "RTMIN+3"
+trap "update_vpn;display" "RTMIN+4"
+# to update it from external commands
+## kill -m "$(cat "$XDG_CACHE_HOME/pidofbar")"
+# where m = 34 + n
+
+# `mullvad status` write logs everytime it is called
+# so I use `mullvad status listen`, this implementation is kinda bloat, maybe there's better way
+# should be put after trap?
+sh -c '
+ mullvad status listen | while read -r line; do
+ kill -RTMIN+4 "$(cat "$1")"
+ echo "$line" > "$2"
+ done &
+' shell "$pid_file" "$vpn_fifo"
+
+while :; do
+ sleep 1 &
+ wait
+ [ $((sec % 5 )) -eq 0 ] && update_time # update time every 5 seconds
+ [ $((sec % 5 )) -eq 0 ] && update_net
+ update_cap
+ [ $((sec % 60)) -eq 0 ] && update_bat
+ #[ $((sec % 300)) -eq 1 ] && update_event
+ # how often the display updates ( 5 seconds )
+ [ $((sec % 5 )) -eq 0 ] && display
+ sec=$((sec + 1))
+done
diff --git a/sh/snippets b/sh/snippets
new file mode 100644
index 0000000..de50f1e
--- /dev/null
+++ b/sh/snippets
@@ -0,0 +1,45 @@
+#!/bin/sh
+# misc code snippets
+
+for cmd in pacdiff 'tree -a'; do
+ alias ${cmd%% *}="sudo -E $cmd"
+done
+
+for cmd in pacdiff 'tree -a'; do alias ${cmd%% *}="sudo -E $cmd"; done
+
+if [ -e "$XDG_PICTURES_DIR/wallpapers/wallpaper" ]; then
+ display -window root "$XDG_PICTURES_DIR/wallpapers/wallpaper" &
+else
+ shufwall &
+fi
+
+# ~/.config/nsxiv/exec/key-handler
+case "$1" in
+ "l") linkwall ;;
+ "w") tr '\n' '\0' | xargs -0 shufwall ;;
+esac
+linkwall() {
+ tr '\n' '\0' | xargs -0 realpath | sort | uniq | while read -r file; do
+ walldir="$XDG_PICTURES_DIR/wallpapers/"
+ name=$(basename "$file")
+ if [ ! -e "$walldir$name" ]; then
+ convwall "$file" "$walldir$name" || ln -s "$file" "$walldir"
+ else
+ notify-send 'error' "$name exist"
+ fi
+ done
+}
+
+for cmd in czkawka_gui firefox freecad gimp krita mpv qmmp songrec zathura; do
+ alias $cmd="o $cmd"
+done
+
+pidof -q monerod || alacritty -e monerod
+
+f () {
+ while read -r site; do
+ curl -sm5 "$site" | grep -iq "creative common\|cc-by\|cc-0\|gnu free documentation license\|gfdl\|unlicense\|wtfpl" && echo "$site"
+ done
+}
+f < ~/downloads/blogs > ~/downloads/cc_blogs
+f < ~/downloads/news > ~/downloads/cc_news