summaryrefslogtreecommitdiff
path: root/scripts/.local
diff options
context:
space:
mode:
authorivan-boikov <ik.boikov.public@protonmail.com>2023-01-22 17:05:30 +0100
committerivan-boikov <ik.boikov.public@protonmail.com>2023-01-22 17:05:30 +0100
commitf4ff2f79d2b7cbc691a1ebecd3919d4cc618da3b (patch)
tree309557ae1299e8ea5e8ad1e7c093fffce22004d2 /scripts/.local
parentf8070225744ddcae7ed861fd515f37784b878911 (diff)
1
Diffstat (limited to 'scripts/.local')
-rwxr-xr-xscripts/.local/bin/allow-screensaver6
-rwxr-xr-xscripts/.local/bin/bmark35
-rwxr-xr-xscripts/.local/bin/cdmenu4
-rwxr-xr-xscripts/.local/bin/check-cpu-freq (renamed from scripts/.local/bin/checkcpufreq)0
-rwxr-xr-xscripts/.local/bin/check-pipewire (renamed from scripts/.local/bin/checkpipewire)0
-rwxr-xr-xscripts/.local/bin/check-video-driver (renamed from scripts/.local/bin/checkvideodriver)0
-rwxr-xr-xscripts/.local/bin/check-zswap (renamed from scripts/.local/bin/checkzswap)13
-rwxr-xr-xscripts/.local/bin/chsink18
-rwxr-xr-xscripts/.local/bin/compress-pdf30
-rwxr-xr-xscripts/.local/bin/dcpug15
-rwxr-xr-xscripts/.local/bin/displayselect2
-rwxr-xr-xscripts/.local/bin/dkill20
-rwxr-xr-xscripts/.local/bin/dmnt103
-rwxr-xr-xscripts/.local/bin/dpass18
-rwxr-xr-xscripts/.local/bin/forbid-screensaver6
-rwxr-xr-xscripts/.local/bin/frc2
-rwxr-xr-xscripts/.local/bin/getbib9
-rwxr-xr-xscripts/.local/bin/getxcolor2
-rwxr-xr-xscripts/.local/bin/ilock12
-rwxr-xr-xscripts/.local/bin/maimpick2
-rwxr-xr-xscripts/.local/bin/makekernel33
-rwxr-xr-xscripts/.local/bin/pashare17
-rwxr-xr-xscripts/.local/bin/pass-askpass2
-rwxr-xr-xscripts/.local/bin/pin-compilers18
-rwxr-xr-xscripts/.local/bin/splitflac3
-rwxr-xr-xscripts/.local/bin/sysact2
-rwxr-xr-xscripts/.local/bin/unpin-compilers6
27 files changed, 248 insertions, 130 deletions
diff --git a/scripts/.local/bin/allow-screensaver b/scripts/.local/bin/allow-screensaver
new file mode 100755
index 0000000..0824816
--- /dev/null
+++ b/scripts/.local/bin/allow-screensaver
@@ -0,0 +1,6 @@
+#!/bin/sh
+export DISPLAY=:0.0
+xset s on
+xset s blank
+xset +dpms
+notify-send "Screensaver ON"
diff --git a/scripts/.local/bin/bmark b/scripts/.local/bin/bmark
new file mode 100755
index 0000000..c0164b3
--- /dev/null
+++ b/scripts/.local/bin/bmark
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+BOOKMARK_FILE="$HOME/sync/bookmarks.dat"
+
+DMENU="$(command -v cdmenu)"
+if [ -z "$DMENU" ]; then
+ DMENU="$(command -v dmenu)"
+fi
+ask(){ $DMENU -i -fn 'Monospace' -l 30; }
+
+if [ -z "$1" ]; then
+ link=$(grep -v "^$" "$BOOKMARK_FILE" | ask | cut -d' ' -f1)
+
+ if [ -n "$WAYLAND_DISPLAY" ]; then
+ ydotool type --clearmodifiers "$link"
+ elif [ -n "$DISPLAY" ]; then
+ xdotool type --clearmodifiers "$link"
+ else
+ echo "Error: No Wayland or X11 display detected" >&2
+ exit 1
+ fi
+
+ exit 0
+fi
+
+if [ "$1" = "add" ] && [ -n "$2" ]; then
+ if grep -q "$2" "$BOOKMARK_FILE"
+ then
+ notify-send "Bookmark already saved" "$2"
+ else
+ echo "$2 ; ; unsorted" >> "$BOOKMARK_FILE"
+ notify-send "Bookmark added" "$2"
+ fi
+ exit 0
+fi
diff --git a/scripts/.local/bin/cdmenu b/scripts/.local/bin/cdmenu
index c31f269..89d39a7 100755
--- a/scripts/.local/bin/cdmenu
+++ b/scripts/.local/bin/cdmenu
@@ -1,7 +1,7 @@
-#! /bin/bash
+#!/bin/sh
# colored dmenu for use in scripts
getcolor() {
- xrdb -query | awk '/*.'$1:'/ { print substr($2,2) }'
+ xrdb -query | awk '/*.'"$1":'/ { print substr($2,2) }'
}
dmenu -nb "#$(getcolor background)" -nf "#$(getcolor foreground)" -sb "#$(getcolor foreground)" -sf "#$(getcolor background)" "$@"
diff --git a/scripts/.local/bin/checkcpufreq b/scripts/.local/bin/check-cpu-freq
index 26edc2c..26edc2c 100755
--- a/scripts/.local/bin/checkcpufreq
+++ b/scripts/.local/bin/check-cpu-freq
diff --git a/scripts/.local/bin/checkpipewire b/scripts/.local/bin/check-pipewire
index d5b3389..d5b3389 100755
--- a/scripts/.local/bin/checkpipewire
+++ b/scripts/.local/bin/check-pipewire
diff --git a/scripts/.local/bin/checkvideodriver b/scripts/.local/bin/check-video-driver
index d398345..d398345 100755
--- a/scripts/.local/bin/checkvideodriver
+++ b/scripts/.local/bin/check-video-driver
diff --git a/scripts/.local/bin/checkzswap b/scripts/.local/bin/check-zswap
index d6a4a00..dc08006 100755
--- a/scripts/.local/bin/checkzswap
+++ b/scripts/.local/bin/check-zswap
@@ -2,14 +2,15 @@
# https://gist.github.com/phizev/31185a30e7d4984724f1fbbf9c2afe19
-ENABLED=$(cat /sys/module/zswap/parameters/enabled)
-COMPRESSOR=$(cat /sys/module/zswap/parameters/compressor)
-ZPOOL=$(cat /sys/module/zswap/parameters/zpool)
+echo "Need to read files in /sys/modules/zswap, need root permissions"
+ENABLED=$(sudo -A cat /sys/module/zswap/parameters/enabled)
+COMPRESSOR=$(sudo -A cat /sys/module/zswap/parameters/compressor)
+ZPOOL=$(sudo -A cat /sys/module/zswap/parameters/zpool)
PAGE_SIZE=$(getconf PAGE_SIZE)
-STORED_PAGES=$(cat /sys/kernel/debug/zswap/stored_pages)
-POOL_TOTAL_SIZE=$(cat /sys/kernel/debug/zswap/pool_total_size)
+STORED_PAGES=$(sudo -A cat /sys/kernel/debug/zswap/stored_pages)
+POOL_TOTAL_SIZE=$(sudo -A cat /sys/kernel/debug/zswap/pool_total_size)
-POOL_SIZE=$(numfmt --to=iec-i $POOL_TOTAL_SIZE)
+POOL_SIZE=$(numfmt --to=iec-i "$POOL_TOTAL_SIZE")
if [ "$POOL_TOTAL_SIZE" = "0" ]
then
diff --git a/scripts/.local/bin/chsink b/scripts/.local/bin/chsink
index 90355e6..9948ff6 100755
--- a/scripts/.local/bin/chsink
+++ b/scripts/.local/bin/chsink
@@ -1,14 +1,14 @@
#!/bin/sh
setsink() {
- tgtdevname=$(cat -)
+ tgtdevname="$(cat -)"
if [ -z "$tgtdevname" ]; then
echo "No device passed"
return
fi
- tgtdev=$(pactl list sinks short | grep $tgtdevname)
- tgtdevid=$(echo $tgtdev | awk '{print $1}')
+ tgtdev=$(pactl list sinks short | grep "$tgtdevname")
+ tgtdevid=$(echo "$tgtdev" | awk '{print $1}')
curdevid=$(pactl list sinks short | grep RUNNING | awk '{print $1}')
echo "Swapping to device $tgtdev"
@@ -17,16 +17,16 @@ setsink() {
echo "Current device ID $curdevid"
notify-send "Swapping to $tgtdevname"
- pactl set-default-sink $tgtdevid
+ pactl set-default-sink "$tgtdevid"
if [ -n "$curdevid" ]; then
- pactl suspend-sink $curdevid 1
+ pactl suspend-sink "$curdevid" 1
fi
- pactl suspend-sink $tgtdevid 0
+ pactl suspend-sink "$tgtdevid" 0
#move all audio streams to the new sink
- pactl list short sink-inputs | while read stream; do
- streamId=$(echo $stream | awk '{print $1}')
- echo 'Moving stream' $stream 'with id' $streamId
+ pactl list short sink-inputs | while read -r stream; do
+ streamId=$(echo "$stream" | awk '{print $1}')
+ echo 'Moving stream' "$stream" 'with id' "$streamId"
pactl move-sink-input "$streamId" "$tgtdevid"
done
}
diff --git a/scripts/.local/bin/compress-pdf b/scripts/.local/bin/compress-pdf
new file mode 100755
index 0000000..d1511d6
--- /dev/null
+++ b/scripts/.local/bin/compress-pdf
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+# https://askubuntu.com/questions/113544/how-can-i-reduce-the-file-size-of-a-scanned-pdf-file
+#-dPDFSETTINGS=/screen lower quality, smaller size. (72 dpi)
+#-dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. (150 dpi)
+#-dPDFSETTINGS=/prepress output similar to Acrobat Distiller "Prepress Optimized" setting (300 dpi)
+#-dPDFSETTINGS=/printer selects output similar to the Acrobat Distiller "Print Optimized" setting (300 dpi)
+#-dPDFSETTINGS=/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file
+PDFSETTINGS="/printer"
+image_resolution="300"
+
+basename=$(echo "$1" | cut -f 1 -d '.')
+
+# full list of parameters
+# https://ghostscript.com/docs/9.54.0/VectorDevices.htm
+
+#-dCompatibilityLevel=1.4 \
+gs -q -dNOPAUSE -dBATCH -dSAFER \
+ -sDEVICE=pdfwrite \
+ -dPDFSETTINGS="$PDFSETTINGS" \
+ -dEmbedAllFonts=true \
+ -dSubsetFonts=true \
+ -dColorImageDownsampleType=/Bicubic \
+ -dColorImageResolution="$image_resolution" \
+ -dGrayImageDownsampleType=/Bicubic \
+ -dGrayImageResolution="$image_resolution" \
+ -dMonoImageDownsampleType=/Bicubic \
+ -dMonoImageResolution="$image_resolution" \
+ -sOutputFile="$basename.compressed.pdf" \
+ "$1"
diff --git a/scripts/.local/bin/dcpug b/scripts/.local/bin/dcpug
index 762ad96..736cfd7 100755
--- a/scripts/.local/bin/dcpug
+++ b/scripts/.local/bin/dcpug
@@ -1,20 +1,15 @@
#!/bin/sh
dmenu="$(command -v cdmenu)"
-if [ "$dmenu" == "" ]; then
+if [ -z "$dmenu" ]; then
dmenu="dmenu"
fi
-sudo="$(command -v sudo)"
-if [ "$sudo" == "" ]; then
- sudo="doas"
-fi
-
-profiles="$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors | sed 's/ /\\n/g')"
+profiles="$(sed 's/ /\\n/g' /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)"
-profile=$(printf $profiles | $dmenu)
+profile=$(printf '%s' "$profiles" | $dmenu)
notify-send "Set CPU profile: $profile"
-$sudo cpupower frequency-set --governor $profile
+sudo -A cpupower frequency-set --governor "$profile"
# repeat, for good measure
-$sudo cpupower frequency-set --governor $profile
+sudo -A cpupower frequency-set --governor "$profile"
diff --git a/scripts/.local/bin/displayselect b/scripts/.local/bin/displayselect
index c8f54d2..c1e3908 100755
--- a/scripts/.local/bin/displayselect
+++ b/scripts/.local/bin/displayselect
@@ -55,7 +55,7 @@ multimon() { # Multi-monitor handler.
esac ;}
onescreen() { # If only one output available or chosen.
- xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
+ xrandr --output "$1" --auto --scale 1.0x1.0 "$(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)"
}
postrun() { # Stuff to run to clean up.
diff --git a/scripts/.local/bin/dkill b/scripts/.local/bin/dkill
index e3aca22..1cbf545 100755
--- a/scripts/.local/bin/dkill
+++ b/scripts/.local/bin/dkill
@@ -1,23 +1,17 @@
-#!/usr/bin/env bash
+#!/bin/sh
# dmenu theming
dmenu="$HOME/.local/bin/cdmenu"
-lines="-l 30"
-selected="$(ps -a -u $USER | \
- "$dmenu" -i -p "Select process to kill" \
- $lines | \
- awk '{print $1" "$4}')";
+selected="$(ps -a -u "$USER" | "$dmenu" -l 16 -i -p "Select process to kill" | awk '{print $1" "$4}')";
-if [[ ! -z $selected ]]; then
+if [ -n "$selected" ]; then
- answer="$(echo -e "Yes\nNo" | \
- "$dmenu" -i -p "$selected will be killed, are you sure?" \
- $lines )"
+ answer="$(printf 'Yes\nNo' | "$dmenu" -i -p "$selected will be killed, are you sure?")"
- if [[ $answer == "Yes" ]]; then
- selpid="$(awk '{print $1}' <<< $selected)";
- kill -9 $selpid
+ if [ "$answer" = "Yes" ]; then
+ selpid="$(echo "$selected" | awk '{print $1}')";
+ kill -9 "$selpid"
fi
fi
diff --git a/scripts/.local/bin/dmnt b/scripts/.local/bin/dmnt
index bb98902..7966d07 100755
--- a/scripts/.local/bin/dmnt
+++ b/scripts/.local/bin/dmnt
@@ -1,15 +1,15 @@
#!/bin/sh
#shopt -s expand_aliases
-DMENU="$(command -v cdmenu)"
+dmenu="$(command -v cdmenu)"
getmount() { \
[ -z "$chosen" ] && exit 1
# shellcheck disable=SC2086
- mp="$(find $1 2>/dev/null | "$DMENU" -l 16 -i -p "Type in mount point.")" || exit 1
+ mp="$(find $1 2>/dev/null | "$dmenu" -l 16 -i -p "Type in mount point.")" || exit 1
[ "$mp" = "" ] && exit 1
if [ ! -d "$mp" ]; then
- mkdiryn=$(printf "No\nYes" | "$DMENU" -i -p "$mp does not exist. Create it?") || exit 1
+ mkdiryn=$(printf "No\nYes" | "$dmenu" -i -p "$mp does not exist. Create it?") || exit 1
[ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp")
fi
}
@@ -45,14 +45,14 @@ mountusb() { \
mountandroid() { \
getmount "/mnt -maxdepth 1 -type d"
jmtpfs -device="$1" "$mp"
- #echo "OK" | "$DMENU" -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1
+ #echo "OK" | "$dmenu" -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1
#jmtpfs -device="$1" "$mp"
notify-send "Android mounted to $mp" ""
}
unmountdev() { \
- result="$(sudo umount \"$1\" 2>&1)"
+ result="$(sudo umount "$1" 2>&1)"
if [ -z "$result" ]; then
notify-send "$1 unmounted" ""
return
@@ -61,10 +61,10 @@ unmountdev() { \
pids="$(echo "$processes" | awk '{print $2}')"
#notify-send -u critical "Unmount device" "$result\nPreparing list of processes blocking $1..."
notify-send "Unmount $1" "$result\nBlocking processes:\n$processes"
- action=$(echo -e "nothing\nterminate\nkill" | "$DMENU" -i -p "What to do to processes blocking $1" -l 3)
+ action=$(printf 'nothing\nterminate\nkill' | "$dmenu" -i -p "What to do to processes blocking $1" -l 3)
case $action in
- terminate) echo "$pids" | while IFS='\n' read -r pid ; do kill $pid; done ;;
- kill) echo "$pids" | while IFS='\n' read -r pid ; do kill -9 $pid; done ;;
+ terminate) echo "$pids" | while IFS="$(printf '\n')" read -r pid ; do kill "$pid"; done ;;
+ kill) echo "$pids" | while IFS="$(printf '\n')" read -r pid ; do kill -9 "$pid"; done ;;
nothing)
notify-send "Unmount of $1 aborted" ""
return ;;
@@ -74,16 +74,16 @@ unmountdev() { \
}
selectusb() { \
- chosen=$(lsblk -lpo "vendor,model,name,label,size,mountpoint" | "$DMENU" -i -l 16 | xargs | cut -d' ' -f 1)
+ chosen=$(lsblk -lpo "vendor,model,name,label,size,mountpoint" | "$dmenu" -i -l 16 | xargs | cut -d' ' -f 1)
# if mounted
- if [ ! -z "$(grep $chosen "/etc/mtab")" ] ; then
- choice=$(echo -e "No\nYes" | "$DMENU" -i -l 2 -p "Partition is mounted. Unmount?")
+ if grep -q "$chosen" "/etc/mtab" ; then
+ choice=$(printf 'No\nYes' | "$dmenu" -i -l 2 -p "Partition is mounted. Unmount?")
case $choice in
- Yes) unmountdev $chosen ;;
+ Yes) unmountdev "$chosen" ;;
No) exit ;;
esac
else
- mountusb $chosen
+ mountusb "$chosen"
fi
}
@@ -91,15 +91,15 @@ selectusb() { \
mountsamba() { \
mounted=$(mount -t cifs)
- if [[ -z "$mounted" ]]; then
+ if [ -z "$mounted" ]; then
actions="mount\nunmount"
- action=$(printf "$actions" | "$DMENU" -i -p "Samba action:")
+ action=$(printf '%s' "$actions" | "$dmenu" -i -p "Samba action:")
- if [[ $action == "unmount" ]]; then
- mount=$(printf "$mounted" | "$DMENU" -i -p "Share to unmount:")
- printf "Selected: $mount\n"
- mount_dir=$(printf "$mount" | cut -d' ' -f 3)
- printf "$mount_dir\n"
+ if [ "$action" = "unmount" ]; then
+ mount=$(printf '%s' "$mounted" | "$dmenu" -i -p "Share to unmount:")
+ printf 'Selected: %s\n' "$mount"
+ mount_dir=$(printf '%s' "$mount" | cut -d' ' -f 3)
+ printf '%s\n' "$mount_dir"
sudo -A umount "$mount_dir"
exit 0
fi
@@ -108,57 +108,58 @@ mountsamba() { \
# get IP of this device
IP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
- printf "IP: $IP\n"
+ echo "IP: $IP"
# prepare subnet choices: choose IP or run a scan if a wildcard specified
- subnets="$IP\n$(echo $IP | cut -d. -f1-3).1\n$(echo $IP | cut -d. -f1-3).*\n$(echo $IP | cut -d. -f1-2).*.*"
- printf "Subnets available:\n$subnets\n"
- subnet=$(printf "$subnets" | "$DMENU" -i -l 16 -p "Input samba scan range")
- printf "Subnet chosen: $subnet\n"
+ subnets="$IP\n$(echo "$IP" | cut -d. -f1-3).1\n$(echo "$IP" | cut -d. -f1-3).*\n$(echo "$IP" | cut -d. -f1-2).*.*"
+ printf 'Subnets available:\n%s\n' "$subnets"
+ subnet=$(printf '%s' "$subnets" | "$dmenu" -i -l 16 -p "Input samba scan range")
+ printf 'Subnet chosen: %s' "$subnet"
- if [[ $subnet == *[*]* ]]; then
+ # if there's a * in subnet
+ if [ "${subnet#*\*}" != "$subnet" ]; then
notify-send "Scanning network for samba shares..." ""
- servers="$(nmap "$1" -p 445 --open -oG -)"
- printf "$servers\n"
+ servers="$(nmap "$subnet" -p 445 --open -oG -)"
+ echo "$servers"
IPs=$(echo "$servers" | grep Scan | cut -d' ' -f2-)
- printf "Server IPs:\n$IPs\n"
+ printf 'Server IPs:\n%s\n' "$IPs"
- IP=$(printf "$IPs" | "$DMENU" -i -l 16 -p "Choose samba server IP")
- printf "Selected IP: $IP\n"
+ IP=$(printf '%s' "$IPs" | "$dmenu" -i -l 16 -p "Choose samba server IP")
+ echo "Selected IP: $IP"
else
IP="$subnet"
fi
- user=$(printf "$(whoami)\nanonymous" | "$DMENU" -p "Samba username:")
- printf "$user\n"
- if [[ $user != "anonymous" ]]; then
+ user=$(printf '%s\nanonymous' "$(whoami)" | "$dmenu" -p "Samba username:")
+ echo "$user"
+ if [ "$user" != "anonymous" ]; then
password=$(pass-askpass "$user's password ")
- shares="""$(smbclient -L $IP --user $user --password $password)"""
+ shares="""$(smbclient -L "$IP" --user "$user" --password "$password")"""
else
notify-send "Attempting anonymous login..." ""
- shares="""$(smbclient -L $IP -N)"""
+ shares="""$(smbclient -L "$IP" -N)"""
fi
- printf "Raw shares:\n$shares\n"
+ printf 'Raw shares:\n%s\n' "$shares"
#shares=$(printf "$shares" | sed -e 's/^[[:space:]]*//')
#printf "Cleaned shares:\n$shares\n"
- share=$(printf "$shares" | "$DMENU" -i -l 16 -p "Which samba share to mount?")
- printf "$share\n"
+ share=$(printf '%s' "$shares" | "$dmenu" -i -l 16 -p "Which samba share to mount?")
+ echo "$share"
# leave only the share name, assuming no whitespace in share name
- chosen=$(printf $share | cut -d' ' -f 1)
- printf "Chosen: $chosen\n"
+ chosen=$(printf '%s' "$share" | cut -d' ' -f 1)
+ echo "Chosen: $chosen"
share="//$IP/$chosen"
getmount "/mnt -maxdepth 1 -type d"
- sudo -A mount -t cifs -o user="$user",password="$password",iocharset=utf8,uid=$(id -u),gid=$(id -g),file_mode=0644,dir_mode=0755 "$share" "$mp"
- if [ $? -ne 0 ]; then
- notify-send "Samba mount failed" "$1 to $mp as $user"
+
+ if ! sudo -A mount -t cifs -o user="$user",password="$password",iocharset=utf8,uid="$(id -u)",gid="$(id -g)",file_mode=0644,dir_mode=0755 "$share" "$mp"; then
+ notify-send "Samba mount failed" "$subnet to $mp as $user"
exit 1
fi
- notify-send "Samba share succeeded" "$1 mounted to $mp as $user"
+ notify-send "Samba share succeeded" "$subnet mounted to $mp as $user"
}
selectandroid() { \
@@ -166,23 +167,23 @@ selectandroid() { \
mounted=$(grep "jmtpfs" "/etc/mtab")
list="Mounted:\n"
- if [ ! -z "$mounted" ]; then
+ if [ -n "$mounted" ]; then
list="$list$mounted"
fi
list="$list\nUnmounted:\n"
- if [ ! -z "$unmounted" ]; then
+ if [ -n "$unmounted" ]; then
list="$list$unmounted"
fi
- chosen=$(echo "$list" "$mounted" | "$DMENU" -i -l 16)
+ chosen=$(echo "$list" "$mounted" | "$dmenu" -i -l 16)
#echo "CHOSEN" $chosen
case $chosen in
- *jmtpfs*) unmountdev $(echo $chosen | cut -d' ' -f 2) ;;
- *) mountandroid $(echo $chosen | awk '{print $1 $2}' | cut -d, -f1-2) ;;
+ *jmtpfs*) unmountdev "$(echo "$chosen" | cut -d' ' -f 2)" ;;
+ *) mountandroid "$(echo "$chosen" | awk '{print $1 $2}' | cut -d, -f1-2)" ;;
esac
}
-choice="$(printf "drive\\nSamba\\nAndroid" | "$DMENU" -i -p "(Un-)mount a")" || exit 1
+choice="$(printf 'drive\nSamba\nAndroid' | "$dmenu" -i -p "(Un-)mount a")" || exit 1
case $choice in
drive) selectusb ;;
Samba) mountsamba ;;
diff --git a/scripts/.local/bin/dpass b/scripts/.local/bin/dpass
index 424232a..adfb0e4 100755
--- a/scripts/.local/bin/dpass
+++ b/scripts/.local/bin/dpass
@@ -34,7 +34,7 @@ fi
#echo ${output_method[@]}
if [[ -n $WAYLAND_DISPLAY ]]; then
- dmenu=dmenu-wl
+ dmenu="dmenu-wl"
elif [[ -n $DISPLAY ]]; then
dmenu="$HOME/.local/bin/cdmenu"
else
@@ -53,7 +53,7 @@ if [[ -z "$password_file" ]]; then
exit 1
fi
-if [[ ! " ${password_files[*]} " =~ " ${password_file} " ]]; then
+if [[ ! ${password_files[*]} =~ "${password_file}" ]]; then
notify-send -u critical "No entry \"$password_file\" in the password store"
exit 1
fi
@@ -61,39 +61,39 @@ fi
action=$(printf "password\nlogin\ninfo" | "$dmenu" -l 3)
case $action in
login)
- login=$(pass show $password_file | sed -n -e '/^login:/p' | awk '{print $2}')
+ login=$(pass show "$password_file" | sed -n -e '/^login:/p' | awk '{print $2}')
if [[ -z $login ]]; then
notify-send -u critical "No login for \"$password_file\" was found"
exit 1
fi
- echo "$login" | ${output_method[@]}
+ echo "$login" | "${output_method[@]}"
if [[ -n $action_descr ]]; then
notify-send "Login for \"$password_file\" was $action_descr"
fi
;;
password)
- pass show "$password_file" | head -n 1 | ${output_method[@]}
+ pass show "$password_file" | head -n 1 | "${output_method[@]}"
#pass show -c "$password" 2>/dev/null
if [[ -n $action_descr ]]; then
notify-send "Password for \"$password_file\" was $action_descr"
fi
;;
info)
- data=$(pass show $password_file | tail -n +2 | sed '/login\:/d')
+ data="$(pass show "$password_file" | tail -n +2 | sed '/login\:/d')"
if [[ -z $data ]]; then
notify-send -u critical "No additional info for \"$password_file\" was found"
exit 1
fi
- data=$(echo $data | "$dmenu" -l 30)
+ data="$(echo "$data" | "$dmenu" -l 30)"
if [[ -z "$data" ]]; then
notify-send "No info for $password_file was selected"
exit 1
fi
- do_trim=$(printf 'Yes\nNo' | "$dmenu" -p "Trim \"$(echo $data | awk '{print $1}')\" in front?" -l 2)
+ do_trim=$(printf 'Yes\nNo' | "$dmenu" -p "Trim \"$(echo "$data" | awk '{print $1}')\" in front?" -l 2)
if [[ $do_trim == "Yes" ]]; then
data=$(echo "$data" | cut -f 2- -d ' ')
fi
- echo $data | ${output_method[@]}
+ echo "$data" | "${output_method[@]}"
if [[ -n $action_descr ]]; then
notify-send "Data for $password_file was $action_descr"
fi
diff --git a/scripts/.local/bin/forbid-screensaver b/scripts/.local/bin/forbid-screensaver
new file mode 100755
index 0000000..4ca55a6
--- /dev/null
+++ b/scripts/.local/bin/forbid-screensaver
@@ -0,0 +1,6 @@
+#!/bin/sh
+export DISPLAY=:0.0
+xset s off
+xset s noblank
+xset -dpms
+notify-send "Screensaver OFF"
diff --git a/scripts/.local/bin/frc b/scripts/.local/bin/frc
index cabb811..04511f0 100755
--- a/scripts/.local/bin/frc
+++ b/scripts/.local/bin/frc
@@ -1,3 +1,3 @@
#!/bin/sh
-cat ~/.local/share/dict/fr-conj.dat | cdmenu -l 32
+cat ~/.local/share/dict/fr-conj.dat | cdmenu -i -l 32
diff --git a/scripts/.local/bin/getbib b/scripts/.local/bin/getbib
index ed441c5..3c6d79d 100755
--- a/scripts/.local/bin/getbib
+++ b/scripts/.local/bin/getbib
@@ -4,11 +4,20 @@
if [ -f "$1" ]; then
# Try to get DOI from pdfinfo or pdftotext output.
doi=$(pdfinfo "$1" | grep -io "doi:.*") ||
+ doi=$(pdfinfo "$1" | grep -io "Digital Object Identifier.*") ||
doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi:.*" -m 1) ||
+ doi=$(pdftotext "$1" 2>/dev/null - | grep -io "Digital Object Identifier.*" -m 1) ||
exit 1
else
doi="$1"
fi
+# DOI never has spaces, so we can always take the last word in line
+doi=$(echo "$doi" | awk '{ print $NF }')
+
+echo "Detected DOI: $doi"
+
# Check crossref.org for the bib citation.
curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n"
+
+wget "https://doi.org/$doi"
diff --git a/scripts/.local/bin/getxcolor b/scripts/.local/bin/getxcolor
index b4cdd90..0626620 100755
--- a/scripts/.local/bin/getxcolor
+++ b/scripts/.local/bin/getxcolor
@@ -1,2 +1,2 @@
#!/bin/sh
-xrdb -query | grep $1 | awk '{print $2}'
+xrdb -query | grep "$1" | awk '{print $2}'
diff --git a/scripts/.local/bin/ilock b/scripts/.local/bin/ilock
index 885c60f..6bf0a02 100755
--- a/scripts/.local/bin/ilock
+++ b/scripts/.local/bin/ilock
@@ -1,21 +1,21 @@
-#!/usr/bin/env bash
+#!/bin/sh
# flush passwords
-if [ -n $(which gnome-keyring-daemon) ]; then
+if [ -n "$(which gnome-keyring-daemon)" ]; then
gnome-keyring-daemon -r -d >/dev/null
fi
-if [ -n $(which ssh-agent) ]; then
+if [ -n "$(which ssh-agent)" ]; then
ssh-agent -k >/dev/null
fi
-if [ -n $(which gpgconf) ]; then
+if [ -n "$(which gpgconf)" ]; then
gpgconf --kill gpg-agent >/dev/null
fi
# stop sounds
-if [ -n $(which playerctl) ]; then
+if [ -n "$(which playerctl)" ]; then
playerctl -a pause >/dev/null
fi
-if [ -n $(which mpc) ]; then
+if [ -n "$(which mpc)" ]; then
mpc pause >/dev/null
fi
diff --git a/scripts/.local/bin/maimpick b/scripts/.local/bin/maimpick
index c8bccd5..8b6549e 100755
--- a/scripts/.local/bin/maimpick
+++ b/scripts/.local/bin/maimpick
@@ -4,8 +4,6 @@
# choose the kind of screenshot to take, including copying the image or even
# highlighting an area to copy. scrotcucks on suicidewatch right now.
-dmenu=cdmenu
-
case "$(printf "a selected area\\ncurrent window\\nfull screen\\na selected area (copy)\\ncurrent window (copy)\\nfull screen (copy)" | cdmenu -l 6 -i -p "Screenshot which area?")" in
"a selected area") maim -s pic-selected-"$(date '+%y%m%d-%H%M-%S').png" ;;
"current window") maim -i "$(xdotool getactivewindow)" pic-window-"$(date '+%y%m%d-%H%M-%S').png" ;;
diff --git a/scripts/.local/bin/makekernel b/scripts/.local/bin/makekernel
index e897288..cb17215 100755
--- a/scripts/.local/bin/makekernel
+++ b/scripts/.local/bin/makekernel
@@ -1,44 +1,44 @@
#!/bin/sh
-
+KERNEL_SRC_DIR="/usr/src/linux"
KEYDIR="/etc/efikeys/"
KERNEL_NAME="vmlinuz-latest-gentoo"
THREADS="$(grep -c ^processor /proc/cpuinfo)"
-if [[ $(hostname) = "pc" ]]; then
+if [ "$(hostname)" = "pc" ]; then
ROOT_DEVICE="/dev/nvme0n1p3"
MICROCODE="amd"
KERNEL_DIR="/boot/efi/gentoo"
-else
+elif [ "$(hostname)" = "laptop" ]; then
ROOT_DEVICE="/dev/sda3"
MICROCODE="intel"
KERNEL_DIR="/boot/efi/EFI/gentoo"
+else
+ echo "Unknown device $(hostname), cannot choose kernel parameters"
+ exit 1
fi
ROOT="/dev/mapper/root"
CRYPT_ROOT="$(blkid -s UUID | grep $ROOT_DEVICE | cut -d' ' -f2 | sed 's/"//g')"
BOOT_PARAMS="ro crypt_root=$CRYPT_ROOT root=$ROOT rootfsype=btrfs rootflags=subvol=@ root_trim=yes lsm=selinux"
-echo -e "Boot parameters:\n$BOOT_PARAMS\n"
-echo -e "\"lsblk -f\" output:\n$(lsblk -f)\n"
-echo -e "Kernel image will compiled with $THREADS threads and be installed to $KERNEL_DIR\n"
+printf 'Boot parameters:\n%s\n' "$BOOT_PARAMS"
+printf '\"lsblk -f\" output:\n%s\n' "$(lsblk -f)"
+printf 'Kernel image will compiled with %s threads and be installed to %s' "$THREADS" "$KERNEL_DIR"
-if [[ $(/usr/bin/id -u) -ne 0 ]]; then
+if [ "$(/usr/bin/id -u)" -ne 0 ]; then
echo "Cannot proceed, need root permissions"
exit 1
fi
-echo "Proceed with kernel compiling?[Y/N]"
-read answer
+echo "Proceed with kernel compiling? [Y/N]"
+read -r answer
if [ "$answer" != "${answer#[Nn]}" ] ;then
echo "Aborted"
exit 1
fi
-echo "Starting compilation"
-#exit 1
-
-cd /usr/src/linux
+cd "$KERNEL_SRC_DIR" || exit 1
# inject $BOOT_PARAMS into kernel config
sed -i "s|^\(CONFIG_CMDLINE=\).*|\1\"$BOOT_PARAMS\"|" .config
@@ -46,9 +46,8 @@ sed -i "s|^\(CONFIG_CMDLINE=\).*|\1\"$BOOT_PARAMS\"|" .config
genkernel --no-clean --no-mrproper --no-save-config \
--microcode="$MICROCODE" \
--integrated-initramfs --compress-initramfs --compress-initramfs-type=lz4 \
- --luks --no-zfs \
- --btrfs \
- --kernel-config=/usr/src/linux/.config \
+ --luks --no-zfs --btrfs \
+ --kernel-config="$KERNEL_SRC_DIR/.config" \
--kernel-filename="$KERNEL_NAME" \
--makeopts="-j$THREADS" \
--loglevel=3 \
@@ -58,4 +57,4 @@ genkernel --no-clean --no-mrproper --no-save-config \
echo "Signing kernel image"
sbsign --key "$KEYDIR/db.key" --cert "$KEYDIR/db.crt" -o "$KERNEL_DIR/$KERNEL_NAME.efi" "/boot/$KERNEL_NAME"
-cd -
+cd - || exit 1
diff --git a/scripts/.local/bin/pashare b/scripts/.local/bin/pashare
new file mode 100755
index 0000000..d134d43
--- /dev/null
+++ b/scripts/.local/bin/pashare
@@ -0,0 +1,17 @@
+#!/bin/sh
+dmenu="cdmenu"
+case "$1" in
+ start)
+ $0 stop
+ source="$(pactl list sinks | grep Name | cut -d' ' -f2- | $dmenu -p "Source to stream:" -l 16).monitor"
+ port=$(echo 12345 | $dmenu -p "Port:")
+ pactl load-module module-simple-protocol-tcp channels=2 source="$source" record=true port="$port"
+ ;;
+ stop)
+ #pactl unload-module `pactl list | grep tcp -B1 | grep M | sed 's/[^0-9]//g'`
+ pactl unload-module module-simple-protocol-tcp
+ ;;
+ *)
+ echo "Usage: $0 start|stop" >&2
+ ;;
+esac
diff --git a/scripts/.local/bin/pass-askpass b/scripts/.local/bin/pass-askpass
index 8ec8665..0cbaad8 100755
--- a/scripts/.local/bin/pass-askpass
+++ b/scripts/.local/bin/pass-askpass
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
getcolor() {
xrdb -query | awk '/*.color'"$1":'/ { print substr($2,2) }'
diff --git a/scripts/.local/bin/pin-compilers b/scripts/.local/bin/pin-compilers
new file mode 100755
index 0000000..c3c21cf
--- /dev/null
+++ b/scripts/.local/bin/pin-compilers
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+pkgs_to_lock="llvm gcc clang"
+tmpfile="$(mktemp)"
+pinfile="/etc/portage/package.mask/pins"
+
+for pkg in $pkgs_to_lock; do
+ echo ">$(qlist -CIve "$pkg")" >> "$tmpfile"
+done
+
+echo "Package mask:"
+cat "$tmpfile"
+
+echo "Commiting mask to $pinfile, need root privileges"
+sudo -A cp -v "$tmpfile" "$pinfile"
+sudo -A chmod 644 "$pinfile"
+
+rm -v "$tmpfile"
diff --git a/scripts/.local/bin/splitflac b/scripts/.local/bin/splitflac
new file mode 100755
index 0000000..4820edc
--- /dev/null
+++ b/scripts/.local/bin/splitflac
@@ -0,0 +1,3 @@
+#!/bin/sh
+fname="${1%%.*}"
+shnsplit -f "$fname.cue" -t %n-%t -o flac "$fname.flac"
diff --git a/scripts/.local/bin/sysact b/scripts/.local/bin/sysact
index bf7f199..e7eab1c 100755
--- a/scripts/.local/bin/sysact
+++ b/scripts/.local/bin/sysact
@@ -9,7 +9,7 @@ case "$(readlink -f /sbin/init)" in
esac
if [ -z "$1" ]; then
- cmd=$(printf "lock\nleave dwm\nrenew dwm\nhibernate\nsleep\nreboot\nshutdown\ndisplay off" | $dmenu -i -p 'Action: ')
+ cmd=$(printf 'lock\nleave dwm\nrenew dwm\nhibernate\nsleep\nreboot\nshutdown\ndisplay off' | $dmenu -i -p 'Action: ')
else
cmd=$1
fi
diff --git a/scripts/.local/bin/unpin-compilers b/scripts/.local/bin/unpin-compilers
new file mode 100755
index 0000000..2ca4f07
--- /dev/null
+++ b/scripts/.local/bin/unpin-compilers
@@ -0,0 +1,6 @@
+#!/bin/sh
+pinfile="/etc/portage/package.mask/pins"
+if [ -f "$pinfile" ]; then
+ echo "Removing pin file $pinfile, need root permissions"
+ sudo -A rm -v "$pinfile"
+fi