scripts

scripts to make my pc work
Index Commits Files Refs
commit 9a18bea026f9d7dad5aa42afc4c97eb69c341cc2
parent cecb3e8dd633fd5ba597ad536ffabd0c5f29726e
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Fri, 15 Oct 2021 12:41:02 -0300

First commit over inspiron scripts folder

Diffstat:
Aadbinput.sh | 3+++
Mlockscreen | 8+++++---
Mopenbook | 2+-
Apower.sh | 9+++++++++
Mstatusbar/sb-battery | 11++++++-----
Mstatusbar/sb-clock | 2+-
Astatusbar/sb-gpu | 16++++++++++++++++
Mstatusbar/sb-internet | 26+++++++++++++++++++++++---
Astatusbar/sb-internet_colored | 28++++++++++++++++++++++++++++
Mstatusbar/sb-kbselect | 5++++-
Mstatusbar/sb-memory | 2+-
Mstatusbar/sb-pacpackages | 20+++++++++++---------
Astatusbar/sb-pacpackages_update_status_bar | 9+++++++++
Mstatusbar/sb-price | 11++++++-----
Mstatusbar/sb-volume | 17++++++++++++++++-
Aswitchkblayout | 12++++++++++++
Mtakescreenshot | 13+++++++++----
Axinitrc | 1+
18 files changed, 161 insertions(+), 34 deletions(-)
diff --git a/adbinput.sh b/adbinput.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+# adb shell input swipe <start_x> <start_y> <end_x> <end_y> duration_ms>
diff --git a/lockscreen b/lockscreen
@@ -1,7 +1,9 @@
 #!/bin/bash
 
-#i3lock --color=000000
+# Pauses notifications so it wont show during lockscreen
+dunstctl set-paused true
 
-i3lock -c 00000000 -n --wrongtext="" --veriftext="" --veriftext="" --noinputtext="" -i $HOME/.cache/i3lock/current/dimblur.png --ringcolor=8B008B --keyhlcolor=ff00ff --verifcolor=0000FF --indicator
+i3lock -c 00000000 -n --wrong-text="" --lock-text="" --lockfailed-text="" --verif-text="" --verif-text="" --noinput-text="" -i $HOME/.cache/i3lock/current/dimblur.png -M --ring-color=8B008B --keyhl-color=ff00ff --verif-color=0000FF --indicator
 
-# betterlockscreen -l dim
+# Re-enables notifications when the device is unlocked
+dunstctl set-paused false
diff --git a/openbook b/openbook
@@ -7,7 +7,7 @@
 
 dir=$HOME/dox/books
 pdfviewer=zathura
-dmenucmds="-i -l 10 -h 14 -z 750 -bw 2 -c $@"
+dmenucmds="-i -l 30 -h 14 -z 750 -bw 2 -c $@"
 
 bookname=$(ls $dir | dmenu $dmenucmds)
 
diff --git a/power.sh b/power.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+pstatus=$(acpi | sed -e '/Battery 1/d' -e 's/,//' | awk '{ print $3 }')
+percentage=$(acpi | sed -e '/Battery 1/d' -e 's/,//g' -e 's/%//g'| awk '{ print $4 }')
+remaining=$(acpi | sed -e '/Battery 1/d' -e 's/,//g' | awk '{ print $5 }' | cut -d ":" -f 1,2)
+
+[ $pstatus = "Discharging" ] && [ $percentage -lt 20 ] && $(dunstify -t 3500 -u critical "Low battery!" "$remaining Remaining")
+
+echo $pstatus
diff --git a/statusbar/sb-battery b/statusbar/sb-battery
@@ -22,15 +22,16 @@ for battery in /sys/class/power_supply/BAT?*; do
     [ -n "${capacity+x}" ] && printf " "
     # Sets up the status and capacity
     case "$(cat "$battery/status")" in
-        "Full") status="⚑" ;;
+        "Full") status="πŸ”Œ" ;;
         "Discharging") status="πŸ”‹" ;;
-        "Charging") status="πŸ”Œ" ;;
+        "Charging") status="⚑" ;;
         "Not charging") status="πŸ›‘" ;;
-        "Unknown") status="♻️: " ;;
+        "Unknown") status="♻️ " ;;
     esac
     capacity=$(cat "$battery/capacity")
     # Will make a warn variable if discharging and low
-    [ "$status" = "πŸ”‹: " ] && [ "$capacity" -le 25 ] && warn="❗"
+    [ "$status" = "πŸ”‹" ] && [ "$capacity" -le 20 ] && status="❗" &&  color="^c#FF0000^"
+
     # Prints the info
-    printf "%s%.1s%*d%%" "$status" "$warn" "3" "$capacity"; unset warn
+    printf "%s%s%*d%%^d^" "$status" "$color" "3" "$capacity";
 done && exit 0
diff --git a/statusbar/sb-clock b/statusbar/sb-clock
@@ -27,4 +27,4 @@ esac
 #esac
 
 #date "+ %a %b %d %Y $icon: %I:%M%p"
-date "+πŸ“… %a %d/%m/%Y | $icon %R"
+date "+πŸ“… %a %d/%m/%Y  $icon %R"
diff --git a/statusbar/sb-gpu b/statusbar/sb-gpu
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# case $BLOCK_BUTTON in
+#     1) notify-send "πŸ–₯ CPU hogs" "$(ps axch -o cmd:15,%cpu --sort=-%cpu | head)\\n(100% per core)" ;;
+#     2) setsid -f "$TERMINAL" -e htop ;;
+#     3) notify-send "πŸ–₯ CPU module " "\- Shows CPU temperature.
+# - Click to show intensive processes.
+# - Middle click to open htop." ;;
+#     6) "$TERMINAL" -e "$EDITOR" "$0" ;;
+# esac
+
+ctemp=$(sensors | awk '/Package id/ {$4 = substr($4, 2, length($4) - 5); print $4}')
+# gtemp=$(sensors | awk '/edge/ {$2 = substr($2, 2, length($2) - 5); print $2}')
+
+# printf "🌑️ C$ctemp° G$gtemp°"
+printf "🌑️ $ctemp°"
diff --git a/statusbar/sb-internet b/statusbar/sb-internet
@@ -5,10 +5,30 @@
 # by github.com/klewer-martin
 
 estatus="$(cat /sys/class/net/e*/operstate)"
+wstatus="$(cat /sys/class/net/w*/operstate)"
 
 if [ "$estatus" = "down" ]; 
-    then ip=$(ip -o a | awk '/: w.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }'); icon="πŸ“‘";
-    else ip=$(ip -o a | awk '/: e.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }'); icon="🌐";
+    then if [ "$wstatus" = "down" ]
+        then ip="Disconnected"; icon="🌐"
+        else ip=$(ip -o a | awk '/: w.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }'); icon="πŸ“‘"
+    fi;
+    else ip=$(ip -o a | awk '/: e.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }'); icon="🌐"
 fi;
 
-printf "%s %s\n" "$icon" "$ip"
+case $icon in
+    🌐) speed=$(cat /sys/class/net/e*/speed);;
+    πŸ“‘) speed=$(cat /proc/net/wireless | awk '/wlp*/ { $3=substr($3, 0, length($3) - 1); $3=int($3 * 100 / 70); print $3 }');;
+esac
+
+case $speed in
+    -1)
+        color="^c#FF0000^";;
+    [0-2][0-9])
+        color="^c#FF0000^";;
+    [2-5][0-9])
+        color="^c#FFFF00^";;
+    [6-7][0-9] | 100)
+        color="^c#00FF00^";;
+esac
+
+printf "%s%s %s^d^\n" "$icon" "$color" "$ip"
diff --git a/statusbar/sb-internet_colored b/statusbar/sb-internet_colored
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# Prints your local ip address, if you are connected both via wireless & ethernet then the ethernet ip is printed
+
+# by github.com/klewer-martin
+
+estatus="$(cat /sys/class/net/e*/operstate)"
+espeed="$(cat /sys/class/net/e*/speed)"
+
+wstatus="$(cat /sys/class/net/w*/operstate)"
+wspeed=$(cat /proc/net/wireless | awk '/wlp*/ { $3=substr($3, 0, length($3) - 1); print $3 }')
+
+if [ "$estatus" = "down" ]; 
+    then if [ "$wstatus" = "down" ]
+        then ip="^c#FF2A2A^Disconnected^d^"; icon="🌐"
+        else case $wstatus in
+                [0-2][0-9])
+                    ip=$(ip -o a | awk '/: w.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }'); icon="πŸ“‘";;
+                [2-4][0-9])
+                    ip=$(ip -o a | awk '/: w.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }'); icon="πŸ“‘";;
+                [5-7][0-9])
+                    ip=$(ip -o a | awk '/: w.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }'); icon="πŸ“‘";;
+            esac
+        fi;
+    else ip=$(ip -o a | awk '/: e.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }'); icon="🌐";
+fi;
+
+printf "%s^c#00FF00^ %s^d^\n" "$icon" "$ip"
diff --git a/statusbar/sb-kbselect b/statusbar/sb-kbselect
@@ -1,8 +1,11 @@
 #!/bin/sh
 # works on any init system
 # requirements: dmenu, xorg-setxkbmap
+
 kb="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" || exit 1
 
+printf "%s %s" "✍️" "${kb^^}"
+
 # case $BLOCK_BUTTON in
 #     1) kb_choice="$(awk '/! layout/{flag=1; next} /! variant/{flag=0} flag {print $2, "- " $1}' /usr/share/X11/xkb/rules/base.lst | dmenu -l 15)"
 #     kb="$(echo "$kb_choice" | awk '{print $3}')"
@@ -13,5 +16,5 @@ kb="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" || exit 1
 #     6) "$TERMINAL" -e "$EDITOR" "$0" ;;
 # esac
 
-printf "%s %s" "⌨️" "$kb"
+# printf "%s %s" "⌨️" "$kb"
 # echo "⌨️: $kb"
diff --git a/statusbar/sb-memory b/statusbar/sb-memory
@@ -9,4 +9,4 @@
 #    6) "$TERMINAL" -e "$EDITOR" "$0" ;;
 #esac
 
-free --mebi | sed -n '2{p;q}' | awk '{printf (" 🧠 %2.2fG\n", ( $3 / 1024), ($2 / 1024))}'
+free --mebi | sed -n '2{p;q}' | awk '{printf ("🧠 %2.2fG\n", ( $3 / 1024), ($2 / 1024))}'
diff --git a/statusbar/sb-pacpackages b/statusbar/sb-pacpackages
@@ -17,13 +17,15 @@
 # When = PostTransaction
 # Exec = /usr/bin/pkill -RTMIN+8 dwmblocks # Or i3blocks if using i3.
 
-case $BLOCK_BUTTON in
-    1) setsid -f "$TERMINAL" -e sb-popupgrade ;;
-    2) notify-send "$(/usr/bin/pacman -Qu)" ;;
-    3) notify-send "🎁 Upgrade module" "πŸ“¦: number of upgradable packages
-- Left click to upgrade packages
-- Middle click to show upgradable packages" ;;
-    6) "$TERMINAL" -e "$EDITOR" "$0" ;;
-esac
+# case $BLOCK_BUTTON in
+#     1) setsid -f "$TERMINAL" -e sb-popupgrade ;;
+#     2) notify-send "$(/usr/bin/pacman -Qu)" ;;
+#     3) notify-send "🎁 Upgrade module" "πŸ“¦: number of upgradable packages
+# - Left click to upgrade packages
+# - Middle click to show upgradable packages" ;;
+#     6) "$TERMINAL" -e "$EDITOR" "$0" ;;
+# esac
 
-pacman -Qu | grep -Fcv "[ignored]" | sed "s/^/πŸ“¦: /;s/^πŸ“¦0$//g"
+# pacman -Qu | grep -Fcv "[ignored]" | sed "s/^/πŸ“¦: /;s/^πŸ“¦0$//g"
+packages_to_update=$(checkupdates | wc -l)
+sed "s/^/πŸ“¦: /;s/^πŸ“¦0$//g"
diff --git a/statusbar/sb-pacpackages_update_status_bar b/statusbar/sb-pacpackages_update_status_bar
@@ -0,0 +1,9 @@
+[Trigger]
+Operation = Upgrade
+Type = Package
+Target = *
+
+[Action]
+Description = Updating statusbar...
+When = PostTransaction
+Exec = /usr/bin/pkill -RTMIN+8 dwmblocks # Or i3blocks if using i3.
diff --git a/statusbar/sb-price b/statusbar/sb-price
@@ -7,7 +7,7 @@
 
 [ -z "$3" ] && exit 1
 interval="@14d"    # History contained in chart preceded by '@' (7d = 7 days)
-dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices"
+dir="$HOME/.local/share/crypto-prices"
 pricefile="$dir/$1"
 # chartfile="$dir/$1-chart"
 
@@ -18,13 +18,14 @@ pricefile="$dir/$1"
 #    curl -s "rate.sx/$1$interval" > "$chartfile" ;}
 
 updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 &&
-    binance-cli --keyfile /home/mk/go/bin/keys.json list-price --symbol $1 | grep price | awk {'print $2'} | sed 's/"//g' > "$pricefile" ;}
+    price=$(binance-cli --keyfile ~/.local/go/bin/keys.json list-price --symbol $1 | grep price | awk {'print $2'} | sed 's/"//g') &&
+    [ $(echo "$price == 0" | bc) -ne 1 ] &&
+    echo $price > "$pricefile" ;}
 
 [ -d "$dir" ] || mkdir -p "$dir"
 
-#[ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] &&
-#    updateprice "$1"
-
+# [ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] &&
+#     updateprice "$1"
 updateprice "$1" &
 
 # case $BLOCK_BUTTON in
diff --git a/statusbar/sb-volume b/statusbar/sb-volume
@@ -13,9 +13,24 @@
 #     6) "$TERMINAL" -e "$EDITOR" "$0" ;;
 # esac
 
-[ $(pamixer --get-mute) = true ] && echo "πŸ”‡  0%" && exit
+case $BLOCK_BUTTON in
+    1) pamixer -t ;;
+    2) setsid -f "$TERMINAL" -e pulsemixer ;;
+    # 4) pamixer --allow-boost -i 1 ;;
+    4) pamixer -i 1 ; pkill -RTMIN+10 dwmblocks; sleep .5;;
+    5) pamixer -d 1 ; pkill -RTMIN+10 dwmblocks;;
+    3) notify-send "πŸ“’ Volume module" "\- Shows volume πŸ”Š, πŸ”‡ if muted.
+- Middle click to mute.
+- Scroll to change." ;;
+    6) "$TERMINAL" -e "$EDITOR" "$0" ;;
+esac
+
+[ $(pamixer --get-mute) = true ] && echo "πŸ”‡  ^c#FF2a2a^0%^d^" && exit
+
+# [ $(awk -F "[][]" '/Left:/ { print $4 }' <(amixer sget Master)) == "off" ] && echo "πŸ”‡  0%" && exit
 
 vol="$(pamixer --get-volume)"
+# vol="$(awk -F "[][]" '/Left:/ { $2 - substr($2, 2, lenghth($2) - 1); print $2 }' <(amixer sget Master))"
 
 if [ "$vol" -gt "50" ]; then
     icon="πŸ”Š"
diff --git a/switchkblayout b/switchkblayout
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+kb="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" || exit 1
+
+case $kb in
+    # us) setxkbmap es && dunstctl close-all && dunstify -t 2000 -h "string:bgcolor:#111111" "Switched keyboard layout to ES";;
+    # es) setxkbmap us && dunstctl close-all && dunstify -t 2000 -h "string:bgcolor:#111111" "Switched keyboard layout to US";;
+    us) setxkbmap es && dunstify -r 1 -t 2000 -h "string:bgcolor:#111111" "Switched keyboard layout to ES πŸ‡¦πŸ‡·";;
+    es) setxkbmap us && dunstify -r 1 -t 2000 -h "string:bgcolor:#111111" "Switched keyboard layout to US πŸ‡ΊπŸ‡Έ";;
+esac
+
+pkill -RTMIN+30 dwmblocks
diff --git a/takescreenshot b/takescreenshot
@@ -1,7 +1,12 @@
-#!/bin/bash
+#!/bin/sh
 
-# Takes a screenshot of the screen and saves it on the folder below
+# Takes a screenshot of the screen and then saves it on the corresponding folder
 
-folder="~/pictures/screenshots/"
+FOLDER=~/pictures/screenshots
+FILENAME=$FOLDER/$(date "+%H-%M-%S_%d-%m-%Y_scrot.png")
 
-scrot -z -e 'mv $f '
+scrot $FILENAME
+
+ACTION=$(dunstify -r 1 -t 5000 -h "string:bgcolor:#111111" "Saving screenshot ..." -h "string:bgcolor:#111111" "Click to open" --action=3,Open)
+
+[ $ACTION -eq 3 ] && xdg-open $FILENAME;
diff --git a/xinitrc b/xinitrc
@@ -0,0 +1 @@
+#!/bin/sh