dotfiles

Mahdi's build of dotfiles
git clone git://mahdi.pw/dotfiles.git
Log | Files | Refs | README | LICENSE

commit c06c64085edad66cfccd87559fb5dd4e9878eef9
parent a9be8b7440badafd540d692672eaa12841735e09
Author: Mahdi Mirzade <me@mahdi.pw>
Date:   Sat,  6 Aug 2022 00:46:45 +0430

Update scripts

Diffstat:
M.local/bin/bg-gen | 13+++++++------
M.local/bin/bright | 1+
M.local/bin/dmenu-emoji | 2+-
M.local/bin/dwm-bar | 28++++++++++++++++++----------
M.local/bin/theme-sel | 22+++++++++++-----------
M.local/bin/volume | 111++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
M.local/bin/vpn | 19+++++++++++--------
M.local/bin/webcam | 28++++++++++++++--------------
8 files changed, 131 insertions(+), 93 deletions(-)

diff --git a/.local/bin/bg-gen b/.local/bin/bg-gen @@ -1,17 +1,18 @@ #!/bin/sh bg_set() { xwallpaper --zoom "$1"; } -CL1="$(xrdb -query | awk '/color0/{print $2;exit}')" -CL2="$(xrdb -query | awk '/color12/{print $2;exit}')" +CL1=$(xrdb -query | awk '/color0/{print $2;exit}') +CL2=$(xrdb -query | awk '/color12/{print $2;exit}') +mkdir -p "${XDG_CACHE_HOME:-$HOME/.cache}/bg-gen" IMG="${XDG_CACHE_HOME:-$HOME/.cache}/bg-gen/${CL1}_${CL2}.png" if [ ! -f "$IMG" ]; then - #RES="683x384" - RES="1366x768" + RES="683x384" + #RES="1366x768" #TAGS="xc: -attenuate 0.3 +noise Random" - #TAGS="xc: -attenuate 0.3 -attenuate 0.3 +noise Random" - #TAGS="xc: -attenuate 0.3 -attenuate 0.3 +noise Random -paint 10" + #TAGS="xc: -attenuate 0.3 +noise Random" + #TAGS="xc: -attenuate 0.3 +noise Random -paint 10" TAGS="plasma:" magick -size "$RES" $TAGS \ -channel B -separate +channel \ diff --git a/.local/bin/bright b/.local/bin/bright @@ -13,6 +13,7 @@ KERNEL=$(uname) case "$KERNEL" in Linux*) BRIGHTNESS_CARD=$(ls /sys/class/backlight | head -n 1) + BRIGHTNESS_CARD=/sys/class/backlight/$BRIGHTNESS_CARD BRIGHTNESS_MAX=$(cat "${BRIGHTNESS_CARD}/max_brightness") BRIGHTNESS=$(cat "${BRIGHTNESS_CARD}/brightness") BRIGHTNESS=$((BRIGHTNESS*100/BRIGHTNESS_MAX)) diff --git a/.local/bin/dmenu-emoji b/.local/bin/dmenu-emoji @@ -1,6 +1,6 @@ #!/bin/sh active_window="$(xdotool getactivewindow)" -emoji="$(sed '0,/^__DATA__$/d' "$0" | sed -e 's/\ufe0f//g' | dmenu -i -l 20 | sed 's/ .*//')" +emoji=$(sed '0,/^__DATA__$/d' "$(which "$0")" | sed -e 's/\ufe0f//g' | dmenu -i -l 20 | sed 's/ .*//') xdotool windowactivate "$active_window" [ "$emoji" ] || exit diff --git a/.local/bin/dwm-bar b/.local/bin/dwm-bar @@ -63,10 +63,10 @@ Battery() { case "$KERNEL" in Linux*) - BAT=$(ls /sys/class/power_supply/ | head -n 1) + BAT=$(find /sys/class/power_supply/ -name "BAT*") if [ -d "$BAT" ]; then - CAPACITY=$(ls "${BAT}/capacity") - CHARGING=$(ls "${BAT}/status") + CAPACITY=$(cat "${BAT}/capacity") + CHARGING=$(cat "${BAT}/status") fi [ "$CHARGING" = "Charging" ] && ICON=$CHARGING_ICON ;; @@ -98,9 +98,12 @@ Battery() { Brightness() { case "$KERNEL" in Linux*) - BRIGHTNESS_CARD=$(ls /sys/class/backlight/ | head -n 1) - [ -d "$BRIGHTNESS_CARD" ] && BRIGHTNESS=$(($(cat "${BRIGHTNESS_CARD}/brightness") \ - * 100 / $(cat "${BRIGHTNESS_CARD}/max_brightness"))) + BRIGHTNESS_CARD=$(ls /sys/class/backlight | head -n 1) + BRIGHTNESS_CARD=/sys/class/backlight/$BRIGHTNESS_CARD + BRIGHTNESS_MAX=$(cat "${BRIGHTNESS_CARD}/max_brightness") + BRIGHTNESS=$(cat "${BRIGHTNESS_CARD}/brightness") + BRIGHTNESS=$((BRIGHTNESS*100/BRIGHTNESS_MAX)) + BRIGHTNESS=${BRIGHTNESS%.*} ;; FreeBSD*) BRIGHTNESS=$(backlight | cut -d ' ' -f 2) @@ -123,8 +126,13 @@ Volume() { VOLUME=$(mixer vol | cut -d':' -f2) case "$KERNEL" in Linux*) - VOLUME=$(pactl get-sink-volume @DEFAULT_SOURCE@ | \ - awk '/%/{sub(/%/, "", $5);print $5}') + if pactl stat >/dev/null 2>&1; then + VOLUME=$(pactl get-sink-volume @DEFAULT_SOURCE@ | \ + awk '/%/{sub(/%/, "", $5);print $5}') + else + VOLUME=$(amixer sget Master on | \ + grep -o '[0-9]*%' | sed 's/%//') + fi ;; FreeBSD*) VOLUME=$(mixer -s vol | cut -d ':' -f 2) @@ -153,7 +161,7 @@ CPU() { CPUtemp() { case "$KERNEL" in Linux*) - TEMP=$(sensors | awk '/temp1/ {sub(/^\+/, "", $2);print $2}') + TEMP=$(sensors | awk '/temp1/ {sub(/^\+/, "", $2);print $2}' | sed 's/\..*//') ;; FreeBSD*) TEMP=$(sysctl -n dev.cpu.0.temperature | sed 's/\..*//') @@ -170,7 +178,7 @@ CPUtemp() { Uptime() { case "$KERNEL" in Linux) - SECS=$(cat /proc/uptime | sed 's/\ .*//g') + SECS=$(cat /proc/uptime | sed 's/\..*//g') ;; *BSD*) SECS=$(($(date +%s)-$(sysctl -n kern.boottime | \ diff --git a/.local/bin/theme-sel b/.local/bin/theme-sel @@ -20,14 +20,14 @@ generate_theme() { foreground="$(printf '%s\n' "$XRDB" | awk '/foreground/ {print $2;exit}')" cursorColor="$(printf '%s\n' "$XRDB" | awk '/cursorColor/ {print $2;exit}')" - sed -i "" "s|%clfg%|$foreground|g" "${DST}.tmp" - sed -i "" "s|%clbg%|$background|g" "${DST}.tmp" - sed -i "" "s|%clcr%|$cursorcolor|g" "${DST}.tmp" - sed -i "" "s|%HOME%|$HOME|g" "${DST}.tmp" + sed -i "s|%clfg%|$foreground|g" "${DST}.tmp" + sed -i "s|%clbg%|$background|g" "${DST}.tmp" + sed -i "s|%clcr%|$cursorcolor|g" "${DST}.tmp" + sed -i "s|%HOME%|$HOME|g" "${DST}.tmp" for i in $(seq 0 15); do v="$(echo "$XRDB" | awk "/color$i/ {print \$2;exit}")" - sed -i "" "s|%cl${i}%|$v|g" "${DST}.tmp" + sed -i "s|%cl${i}%|$v|g" "${DST}.tmp" done [ -f "${DST}" ] && rm "${DST}" @@ -45,15 +45,15 @@ apply_theme() { } reload_theme() { - pidof -x tabbed >/dev/null 2>&1 && for PID in $(pidof tabbed); do kill -s USR1 "$PID"; done - pidof -x st >/dev/null 2>&1 && for PID in $(pidof st); do kill -s USR1 "$PID"; done + pidof tabbed >/dev/null 2>&1 && for PID in $(pidof tabbed); do kill -s USR1 "$PID"; done + pidof st >/dev/null 2>&1 && for PID in $(pidof st); do kill -s USR1 "$PID"; done # Remove urgency mark for st, tabbed instances: xdotool search --class st set_window --urgency 0 "%@" xdotool search --class tabbed set_window --urgency 0 "%@" - pidof -x dwm >/dev/null 2>&1 && xdotool key "Super+F5" - #pidof -x bspwm && bspc wm -r - #pidof -x openbox && openbox --restart - setsid -f dwm-bar + pidof dwm >/dev/null 2>&1 && xdotool key "Super+F5" + #pidof bspwm && bspc wm -r + #pidof openbox && openbox --restart + setsid dwm-bar case "$OLDTHEME" in "${THEME}") NOTIF_TEXT="Reloaded ${THEME} theme." ;; diff --git a/.local/bin/volume b/.local/bin/volume @@ -3,46 +3,61 @@ AUDIO_STEPS="5" AUDIO_ACT="get" while getopts ':gidmGIDMs:' flag; do - case "${flag}" in - g) AUDIO_ACT="get" ;; - i) AUDIO_ACT="inc" ;; - d) AUDIO_ACT="dec" ;; - m) AUDIO_ACT="mute" ;; - G) AUDIO_ACT="mic-get" ;; - I) AUDIO_ACT="mic-inc" ;; - D) AUDIO_ACT="mic-dec" ;; - M) AUDIO_ACT="mic-mute" ;; - s) AUDIO_STEPS="${OPTARG}" ;; - *) - printf 'Usage: %s [-g] [-d] [-i] [-m] [-G] [-D] [-I] [-M] [-s audio steps (in %%)]\n' "$0" - printf ' -g: get volume\n' - printf ' -i: increase volume\n' - printf ' -d: decrease volume\n' - printf ' -m: mute volume\n' - printf ' -G: get mic volume\n' - printf ' -I: increase mic volume\n' - printf ' -D: decrease mic volume\n' - printf ' -M: mute mic volume\n' - exit 2 - ;; - esac + case "${flag}" in + g) AUDIO_ACT="get" ;; + i) AUDIO_ACT="inc" ;; + d) AUDIO_ACT="dec" ;; + m) AUDIO_ACT="mute" ;; + G) AUDIO_ACT="mic-get" ;; + I) AUDIO_ACT="mic-inc" ;; + D) AUDIO_ACT="mic-dec" ;; + M) AUDIO_ACT="mic-mute" ;; + s) AUDIO_STEPS="${OPTARG}" ;; + *) + printf 'Usage: %s [-g] [-d] [-i] [-m] [-G] [-D] [-I] [-M] [-s audio steps (in %%)]\n' "$0" + printf ' -g: get volume\n' + printf ' -i: increase volume\n' + printf ' -d: decrease volume\n' + printf ' -m: mute volume\n' + printf ' -G: get mic volume\n' + printf ' -I: increase mic volume\n' + printf ' -D: decrease mic volume\n' + printf ' -M: mute mic volume\n' + exit 2 + ;; + esac done vol() { case "$(uname)" in "Linux"*) - case "$1" in - get) pactl get-sink-volume @DEFAULT_SOURCE@ | awk '/%/{sub(/%/, "", $5);print $5}' ;; - inc) pactl set-sink-volume @DEFAULT_SINK@ "+$2%" ;; - dec) pactl set-sink-volume @DEFAULT_SINK@ "-$2%" ;; - mute) pactl set-sink-mute @DEFAULT_SINK@ toggle ;; - ismuted) pactl get-sink-mute @DEFAULT_SOURCE@ | grep -o 'yes' ;; - mic-get) pactl get-source-volume @DEFAULT_SOURCE@ | awk '/%/{sub(/%/, "", $5);print $5}' ;; - mic-inc) pactl set-source-volume @DEFAULT_SINK@ "+$2%" ;; - mic-dec) pactl set-source-volume @DEFAULT_SINK@ "-$2%" ;; - mic-mute) pactl set-source-mute @DEFAULT_SINK@ toggle ;; - mic-ismuted) pactl get-source-mute @DEFAULT_SOURCE@ | grep -o 'yes' ;; - esac + if pactl stat >/dev/null 2>&1; then + case "$1" in + get) pactl get-sink-volume @DEFAULT_SOURCE@ | awk '/%/{sub(/%/, "", $5);print $5}' ;; + inc) pactl set-sink-volume @DEFAULT_SINK@ "+$2%" ;; + dec) pactl set-sink-volume @DEFAULT_SINK@ "-$2%" ;; + mute) pactl set-sink-mute @DEFAULT_SINK@ toggle ;; + ismuted) pactl get-sink-mute @DEFAULT_SOURCE@ | grep -o 'yes' ;; + mic-get) pactl get-source-volume @DEFAULT_SOURCE@ | awk '/%/{sub(/%/, "", $5);print $5}' ;; + mic-inc) pactl set-source-volume @DEFAULT_SINK@ "+$2%" ;; + mic-dec) pactl set-source-volume @DEFAULT_SINK@ "-$2%" ;; + mic-mute) pactl set-source-mute @DEFAULT_SINK@ toggle ;; + mic-ismuted) pactl get-source-mute @DEFAULT_SOURCE@ | grep -o 'yes' ;; + esac + else + case "$1" in + get) amixer sget Master on | grep -o '[0-9]*%' | sed 's/%//' ;; + inc) amixer sset Master "$2%+" on -q ;; + dec) amixer sset Master "$2%-" on -q ;; + mute) amixer sset Master 1+ toggle -q ;; + ismuted) amixer sget Master on | grep -o '\[off\]' ;; + mic-get) pactl get-source-volume @DEFAULT_SOURCE@ | awk '/%/{sub(/%/, "", $5);print $5}' ;; + mic-inc) pactl set-source-volume @DEFAULT_SINK@ "+$2%" ;; + mic-dec) pactl set-source-volume @DEFAULT_SINK@ "-$2%" ;; + mic-mute) pactl set-source-mute @DEFAULT_SINK@ toggle ;; + mic-ismuted) pactl get-source-mute @DEFAULT_SOURCE@ | grep -o 'yes' ;; + esac + fi ;; "FreeBSD"*) case "$1" in @@ -81,15 +96,25 @@ notify() { } case "$AUDIO_ACT" in - inc|dec) - CURRENT_VOLUME="$(vol get)" - REMAINDER="$((CURRENT_VOLUME%AUDIO_STEPS))" - AUDIO_STEPS="$((AUDIO_STEPS-REMAINDER))" + inc) + CURRENT_VOLUME=$(vol get) + REMAINDER=$((CURRENT_VOLUME%AUDIO_STEPS)) + AUDIO_STEPS=$((AUDIO_STEPS-REMAINDER)) ;; - mic-inc|mic-dec) - CURRENT_VOLUME="$(vol mic-get)" - REMAINDER="$((CURRENT_VOLUME%AUDIO_STEPS))" - AUDIO_STEPS="$((AUDIO_STEPS-REMAINDER))" + dec) + CURRENT_VOLUME=$(vol get) + REMAINDER=$((CURRENT_VOLUME%AUDIO_STEPS)) + AUDIO_STEPS=$((AUDIO_STEPS+REMAINDER)) + ;; + mic-inc) + CURRENT_VOLUME=$(vol mic-get) + REMAINDER=$((CURRENT_VOLUME%AUDIO_STEPS)) + AUDIO_STEPS=$((AUDIO_STEPS-REMAINDER)) + ;; + mic-dec) + CURRENT_VOLUME=$(vol mic-get) + REMAINDER=$((CURRENT_VOLUME%AUDIO_STEPS)) + AUDIO_STEPS=$((AUDIO_STEPS+REMAINDER)) ;; esac diff --git a/.local/bin/vpn b/.local/bin/vpn @@ -1,11 +1,14 @@ #!/bin/sh -printf '\033[90m' -dhclient ue0 echo "nameserver 1.1.1.1" > /etc/resolv.conf -for pid in $(ps ax | grep "openvpn" | awk '{print $1}'); do - [ "$pid" = "$$" ] && continue - kill -9 "$pid" > /dev/null 2>&1 - wait +cd /dev +mkdir net +mknod net/tun c 10 200 +chmod 0666 net/tun +while :; do + for pid in $(ps ax | grep openvpn | awk '{print $1}'); do + [ "$pid" = "$$" ] && continue + kill -9 "$pid" > /dev/null 2>&1 + wait + done + openvpn /home/mahdi/.local/share/Mahdi.ovpn done -openvpn /home/mahdi/Mahdi.ovpn -printf '\033[0m' diff --git a/.local/bin/webcam b/.local/bin/webcam @@ -1,23 +1,23 @@ #!/bin/sh WEBCAM_DRIVER="v4l2" -WEBCAM_DEVICE="/dev/video0" +WEBCAM_DEVICE="$(ls /dev/video* | head -n 1)" -if [ ! -f "${WEBCAM_DEVICE}" ]; then +if [ ! -e "${WEBCAM_DEVICE}" ]; then merbe "Webcam" "Install a webcam first!" & exit 2 fi case "$1" in - shot) - ffmpeg -y -loglevel quiet -f "$WEBCAM_DRIVER" -i "$WEBCAM_DEVICE" \ - -frames:v 1 -f image2 -strftime 1 "$HOME/webcam-%Y-%m-%d-%H%M%S.jpg" - ;; - *) - ps ax | grep "mpv*av://$WEBCAM_DRIVER:$WEBCAM_DEVICE*" | \ - awk '{print $1}' | while read PID; do kill -9 "$PID"; wait; done - merbe " Webcam" "$WEBCAM_DEVICE is open now." & - mpv "av://$WEBCAM_DRIVER:$WEBCAM_DEVICE" --title=webcam \ - --profile=low-latency --untimed --load-scripts=no --no-osc - merbe "﫞 Webcam" "$WEBCAM_DEVICE has been closed." & - ;; + shot) + ffmpeg -y -loglevel quiet -f "$WEBCAM_DRIVER" -i "$WEBCAM_DEVICE" \ + -frames:v 1 -f image2 -strftime 1 "$HOME/webcam-%Y-%m-%d-%H%M%S.jpg" + ;; + *) + ps ax | grep "mpv*av://$WEBCAM_DRIVER:$WEBCAM_DEVICE*" | \ + awk '{print $1}' | while read PID; do kill -9 "$PID"; wait; done + merbe " Webcam" "$WEBCAM_DEVICE is open now." & + mpv "av://$WEBCAM_DRIVER:$WEBCAM_DEVICE" --title=webcam \ + --profile=low-latency --untimed --load-scripts=no --no-osc + merbe "﫞 Webcam" "$WEBCAM_DEVICE has been closed." & + ;; esac