scripts

scripts to make my pc work
Index Commits Files Refs
commit 49dbcfe9b3508f51856ea8ff06a1254f52009690
parent 3cbd9827fe2f993de261a20b078a66e461bff3b5
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Tue, 13 Jul 2021 19:35:44 -0300

Update: ...

Diffstat:
Mbacklight | 0
Abrightness.c | 26++++++++++++++++++++++++++
Acount.c | 11+++++++++++
Acount.py | 7+++++++
Acount.sh | 4++++
Acount.sh_ | 4++++
Adbdb.sh | 18++++++++++++++++++
Mdisablemouseaccel | 6++----
Aimagestodownload.txt | 3+++
Aimg.jpg | 0
Mlockscreen | 4+++-
Anasa_img_downloader | 5+++++
Mopenbook | 4++--
Aopendir | 11+++++++++++
Apactllowervolume | 12++++++++++++
Mpactlraisevolume | 11+++++++----
Apactlsetvolume | 12++++++++++++
Msetlockscreenbg | 9++-------
Mstatusbar/sb-clock | 2+-
Mstatusbar/sb-internet | 31++++++-------------------------
Cstatusbar/sb-internet -> statusbar/sb-internet2 | 0
Mstatusbar/sb-kbselect | 6+++---
Mstatusbar/sb-memory | 2+-
Mstatusbar/sb-price | 6+++---
Aswitchkblayout | 10++++++++++
Mtakescreenshot | 2+-
26 files changed, 154 insertions(+), 52 deletions(-)
diff --git a/backlight b/backlight
diff --git a/brightness.c b/brightness.c
@@ -0,0 +1,26 @@
+#include <stdlib.h>
+#include <stdio.h>
+#define BUFSIZE 10
+
+int main(int argc, char **argv) {
+  FILE *fp;
+  char scurr[BUFSIZE];
+  long new, curr, incr, min = 0;
+
+  /* An argument with an integer increment must be supplied */
+  if (argc != 2 || (incr = strtol(argv[1], NULL, 10)) == 0) { return(1); }
+
+  /* Retrieve the current brightness and increment it in the brightness file */
+  if ((fp = fopen("/sys/class/backlight/intel_backlight/brightness", "r+")) 
+      && fgets(scurr, BUFSIZE, fp)) {
+    curr = strtol(scurr, NULL, 10);
+    rewind(fp);
+    new = curr + incr;
+    if (new < min) { new = min; }
+    fprintf(fp, "%ld\n", new);
+    fclose(fp);
+  } else { return(2); }
+
+  return(0);
+}
+
diff --git a/count.c b/count.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int main (void)
+{
+    unsigned long x;
+
+    for(x = 0; x < 1000000; x++)
+        printf("%ld\n", x);
+
+    return 0;
+}
diff --git a/count.py b/count.py
@@ -0,0 +1,7 @@
+#!/usr/bin/python
+
+x = 0
+
+while x < 1000000:
+    print(x)
+    x = x + 1
diff --git a/count.sh b/count.sh
@@ -0,0 +1,4 @@
+#/usr/bin/sh
+
+x=0
+while [ "$x" -lt 1000000 ]; do echo $x; x=$((x+1));done
diff --git a/count.sh_ b/count.sh_
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+x=0
+while [ $x -lt 500000 ]; do echo "$x"; x=$((x+1)); done
diff --git a/dbdb.sh b/dbdb.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+# dmenu-based directory browser
+# to run from terminal:
+#    source /path/to/dbdb.sh
+# or bind it to shortcut:
+#   echo bind \'\"\\C-o\":\"source /path/to/dbdb.sh\\n\"\' >> ~/.bashrc
+
+chosen="placeholder"
+
+while [ ! -z "$chosen" ]; do
+    DIRs=$( ls -a1p | grep -P '^\w[^\$/]+/$' | awk -vRS="\n" -vORS="\t" '1')
+    DOTDs=$( ls -a1p | grep -P '^\.[^\$/]+/$' | awk -vRS="\n" -vORS="\t" '1')
+    FILEs=$( ls -a1p | grep -P '^\w[^\$/]+$' | awk -vRS="\n" -vORS=" \t" '1')
+    DOTFs=$( ls -a1p | grep -P '^\.[^\$/]+$' | awk -vRS="\n" -vORS=" \t" '1')
+    clear && printf "\e[1;7;33m $(pwd) \e[0m\n$FILEs\n\e[0;38;5;238m$DOTFs\e[0m\n"
+    chosen=`( ( echo -e "$DIRs$DOTDs" | awk -vRS="\t" -vORS="\n" '1' ) | dmenu -i -l 10)`
+    cd "$chosen"
+done
diff --git a/disablemouseaccel b/disablemouseaccel
@@ -1,9 +1,7 @@
 #!/bin/bash
 
+xinput --set-prop 13 'libinput Accel Profile Enabled' 0, 1
 
-xinput --set-prop 10 'libinput Accel Profile Enabled' 0, 1
+xinput --set-prop 14 'libinput Accel Profile Enabled' 0, 1
 
 xinput --set-prop 'Logitech Wireless Mouse' 'libinput Accel Profile Enabled' 0, 1
-
-xinput --set-prop 'DLLA6AE:00 06CB:75DD Touchpad' 'libinput Tapping Enabled' 1
-
diff --git a/imagestodownload.txt b/imagestodownload.txt
@@ -0,0 +1,3 @@
+https://www.nasa.gov/sites/default/files/thumbnails/image/iss065e002848.jpg
+https://www.nasa.gov/sites/default/files/thumbnails/image/iss065e005888.jpg
+https://www.nasa.gov/sites/default/files/thumbnails/image/iss065e005888.jpg
diff --git a/img.jpg b/img.jpg
Binary files differ.
diff --git a/lockscreen b/lockscreen
@@ -2,4 +2,6 @@
 
 #i3lock --color=000000
 
-betterlockscreen -l dim
+i3lock -c 000000 -n --wrongtext="" --veriftext="" --veriftext="" --noinputtext="" -i $HOME/.cache/i3lock/current/dimblur.png --ringcolor=8B008B --keyhlcolor=ff00ff --verifcolor=0000FF --indicator
+
+# betterlockscreen -l dim
diff --git a/nasa_img_downloader b/nasa_img_downloader
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+[ -z "$1" ] && exit 1
+
+while read line; do url="$line"; imgname=$(echo "$url" | cut -d "/" -f 12); curl -# $url > $imgname; echo "\nDownloading: $imgname"; done < $1
diff --git a/openbook b/openbook
@@ -11,9 +11,9 @@ dmenucmds="-i -l 10 -h 14 -z 750 -bw 2 -c $@"
 
 bookname=$(ls $dir | dmenu $dmenucmds)
 
-[ "$bookname" = "" ] && exit
+[ -z "$bookname" ] && exit
 
 [ $(file "$dir/$bookname" | cut -d ":" -f 2) = "directory" ] &&
     dir=$dir/$bookname && bookname=$(ls "$dir" | dmenu $dmenucmds)
 
-[ "$bookname" != "" ] && $pdfviewer "$dir/$bookname"
+[ -n "$bookname" ] && $pdfviewer "$dir/$bookname"
diff --git a/opendir b/opendir
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Prints a list of books in dmenu and opens the chosen one with pdfviewer
+# The arguments receive are redirected to dmenu
+
+# by github.com/klewer-martin
+
+dmenucmds="-i -l 10 -h 14 -z 750 -bw 2 -c $@"
+dirname=$(fd -a | dmenu $dmenucmds)
+
+alacritty --working-directory "$dirname"
diff --git a/pactllowervolume b/pactllowervolume
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+amount_to_increase=$1
+
+current_volume=$(pamixer --get-volume)
+max_volume=$((100 - $amount_to_increase))
+
+(($current_volume<=$max_volume)) && $(pactl set-sink-volume @DEFAULT_SINK@ - $amount_to_increase%)
+
+current_volume=$(pamixer --get-volume)
+notify
+notify-send -h int:value:$current_volume "Volume" -h string:bgcolor:#111111 -h string:fgcolor:#ffffff -i 🔊 -t 1500;
diff --git a/pactlraisevolume b/pactlraisevolume
@@ -1,8 +1,11 @@
 #!/bin/bash
 
-AMOUNT_TO_INCREASE=$1
+amount_to_increase=$1
 
-CURRENT_VOLUME=$(pamixer --get-volume)
-MAX_VOLUME=$((100 - $AMOUNT_TO_INCREASE))
+current_volume=$(pamixer --get-volume)
+max_volume=$((100 - $amount_to_increase))
 
-(($CURRENT_VOLUME<=$MAX_VOLUME)) && $(pactl set-sink-volume @DEFAULT_SINK@ +$AMOUNT_TO_INCREASE%)
+(($current_volume<=$max_volume)) && $(pactl set-sink-volume @DEFAULT_SINK@ +$amount_to_increase%)
+
+current_volume=$(pamixer --get-volume)
+notify-send -h int:value:$current_volume "Volume" -h string:bgcolor:#111111 -h string:fgcolor:#ffffff -i 🔊 -t 1500;
diff --git a/pactlsetvolume b/pactlsetvolume
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+amount_to_increase=$1
+
+current_volume=$(pamixer --get-volume)
+max_volume=$((100 - $amount_to_increase))
+
+(($current_volume<=$max_volume)) && $(pactl set-sink-volume @DEFAULT_SINK@ +$amount_to_increase%)
+
+current_volume=$(pamixer --get-volume)
+# notify-send -h int:value:$current_volume " " -h string:bgcolor:#111111 -h string:fgcolor:#ffffff -i 🔊 -t 1500;
+# dunstify -h int:value:$current_volume "🔊" -r 10 -h string:bgcolor:#111111 -h string:fgcolor:#ffffff -t 1500;
diff --git a/setlockscreenbg b/setlockscreenbg
@@ -1,8 +1,3 @@
-#!/bin/bash
+#!/bin/sh
 
-BACKGROUND_PATH=$(cat $HOME/.config/nitrogen/bg-saved.cfg \
-                    | grep file | cut -c6-)
-
-echo $BACKGROUND_PATH
-
-betterlockscreen -u $BACKGROUND_PATH
+betterlockscreen -u $(grep file $HOME/.config/nitrogen/bg-saved.cfg | cut -c6-)
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-internet b/statusbar/sb-internet
@@ -1,30 +1,11 @@
 #!/bin/sh
 
-# Show wifi 📶 and percent strength or 📡 if none.
-# Show 🌐 if connected to ethernet or ❎ if none.
-# Show 🔒 if a vpn connection is active
+# Prints your local ip address, if you are connected both via wireless & ethernet then the ethernet ip is printed
 
-case $BLOCK_BUTTON in
-    1) "$TERMINAL" -e nmtui; pkill -RTMIN+4 dwmblocks ;;
-    3) notify-send "🌐 Internet module" "\- Click to connect
-📡: no wifi connection
-📶: wifi connection with quality
-❎: no ethernet
-🌐: ethernet working
-🔒: vpn is active
-" ;;
-    6) "$TERMINAL" -e "$EDITOR" "$0" ;;
-esac
+# by github.com/klewer-martin
 
-case "$(cat /sys/class/net/w*/operstate 2>/dev/null)" in
-    down) wifiicon="📡:  -%" ;;
-    up) wifiicon="$(awk '/^\s*w/ { print "📶:", int($3 * 100 / 70) "%" }' /proc/net/wireless)" ;;
-esac
+ip=$(ip -o a | awk '/: e.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }');
+[[ -z $ip ]] && ip="Disconnected"
+icon="🌐";
 
-case "$(cat /sys/class/net/e*/operstate 2>/dev/null)" in
-    down) ip="" ;;
-    up) ip="| $(ip -o a | awk '/: e.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }')" ;;
-
-esac
-
-printf "%s%s%s%s\n" "$wifiicon" "$(sed "s/down//;s/up/ /" /sys/class/net/e*/operstate 2>/dev/null)" "$(sed "s/.*/🔒/" /sys/class/net/tun*/operstate 2>/dev/null)" "$ip"
+printf "%s %s\n" "$icon" "$ip"
diff --git a/statusbar/sb-internet b/statusbar/sb-internet2
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}')"
@@ -12,6 +15,3 @@ kb="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" || exit 1
 # - Left click to change keyboard.";;
 #     6) "$TERMINAL" -e "$EDITOR" "$0" ;;
 # esac
-
-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.2fGiB\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-price b/statusbar/sb-price
@@ -9,7 +9,7 @@
 interval="@14d"    # History contained in chart preceded by '@' (7d = 7 days)
 dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices"
 pricefile="$dir/$1"
-chartfile="$dir/$1-chart"
+# chartfile="$dir/$1-chart"
 
 # curl -s "rate.sx/1$1" > "$pricefile"
 
@@ -25,7 +25,7 @@ updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 &&
 #[ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] &&
 #    updateprice "$1"
 
-updateprice "$1"
+updateprice "$1" &
 
 # case $BLOCK_BUTTON in
 #     1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;;
@@ -42,4 +42,4 @@ updateprice "$1"
 #     6) "$TERMINAL" -e "$EDITOR" "$0" ;;
 # esac
 
-printf "$3$%0.3f" "$(cat "$pricefile")"
+printf "$3$%0.2f" "$(cat "$pricefile")"
diff --git a/switchkblayout b/switchkblayout
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+kb="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" || exit 1
+
+case $kb in
+    us) setxkbmap es && dunstify -t 2000 -h "string:bgcolor:#111111" "Switched keyboard layout to ES";;
+    es) setxkbmap us && dunstify -t 2000 -h "string:bgcolor:#111111" "Switched keyboard layout to US";;
+esac
+
+pkill -RTMIN+30 dwmblocks
diff --git a/takescreenshot b/takescreenshot
@@ -2,4 +2,4 @@
 
 # Takes a screenshot of the screen and saves it on the folder below
 
-scrot -e 'mv $f ~/pictures/screenshots/'
+scrot -z -e 'mv $f ~/pictures/screenshots/'