diff options
author | Florian Pritz <bluewind@xinu.at> | 2024-10-14 21:34:04 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2024-10-14 21:54:03 +0200 |
commit | d5ffb01d87852eb74f6b17ae06ac0c476010065b (patch) | |
tree | 1ac6a86d874f30c968ba26bf0f8a5954fa0c67a6 | |
parent | d10ee7703e20ef844907e90797ad66bf0fb984da (diff) | |
download | bin-d5ffb01d87852eb74f6b17ae06ac0c476010065b.tar.gz bin-d5ffb01d87852eb74f6b17ae06ac0c476010065b.tar.xz |
Add new scripts
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-x | conky-update-interval | 13 | ||||
-rwxr-xr-x | dd-parallel | 31 | ||||
-rwxr-xr-x | disconnect-screen | 15 | ||||
-rwxr-xr-x | dump-chrome-history | 29 | ||||
-rwxr-xr-x | git-diff-gpg | 8 | ||||
-rwxr-xr-x | grep-email | 3 | ||||
-rwxr-xr-x | i3-continous-backup | 14 | ||||
-rwxr-xr-x | i3-dump-layout-all | 26 | ||||
-rwxr-xr-x | i3-load-layouts | 8 | ||||
-rw-r--r-- | mutt | 10 | ||||
-rw-r--r-- | myip-dns | 3 | ||||
-rwxr-xr-x | pkgctl | 24 | ||||
-rwxr-xr-x | rofi-gpgpass | 80 | ||||
-rwxr-xr-x | toggle-nm | 19 | ||||
-rwxr-xr-x | unload-pa | 4 | ||||
-rwxr-xr-x | update | 6 |
16 files changed, 293 insertions, 0 deletions
diff --git a/conky-update-interval b/conky-update-interval new file mode 100755 index 0000000..94d794f --- /dev/null +++ b/conky-update-interval @@ -0,0 +1,13 @@ +#!/bin/bash + +set-conky-update-interval() { + sed -ri 's#^(update_interval) = .*,#\1 = '"$1"',#' ~/.i3/conkyrc-perl +} + +if [[ $# -gt 0 ]]; then + set-conky-update-interval "$1" +elif [[ "$(cat /sys/class/power_supply/ACAD/online)" = "0" ]]; then + set-conky-update-interval 3 +else + set-conky-update-interval 0.5 +fi diff --git a/dd-parallel b/dd-parallel new file mode 100755 index 0000000..0745225 --- /dev/null +++ b/dd-parallel @@ -0,0 +1,31 @@ +#!/bin/bash + +# Run multiple dd processes in parallel to copy a single file/blockdevice. Each +# dd process will operate on a dedicated part of the file at a time (1GB chunks +# for big files). + +set -e + +# Source: https://stackoverflow.com/a/25268449 +min() { + printf "%s\n" "${@:2}" | sort "$1" | head -n1 +} +max() { + # using sort's -r (reverse) option - using tail instead of head is also possible + min "${1}r" "${@:2}" +} + +inputfile=$1 +if [[ -b "$inputfile" ]]; then + inputsize=$(blockdev --getsize64 "$inputfile") +else + inputsize=$(stat --format %s "$inputfile") +fi +outputfile=$2 + +stepsize=1000 +parallel=6 +# 1GB blocks or smaller blocks if we cannot achieve the required parallelization with 1GB +blocksize=$(min -g 1000000 "$((inputsize / stepsize / parallel))" ) + +seq 0 $stepsize $(($inputsize / $blocksize )) | xargs -P$parallel -I{} dd if="$inputfile" bs=$blocksize skip={} conv=sparse seek={} count=$stepsize status=none of="$outputfile" diff --git a/disconnect-screen b/disconnect-screen new file mode 100755 index 0000000..2ec148e --- /dev/null +++ b/disconnect-screen @@ -0,0 +1,15 @@ +#!/bin/bash + + +displays=( + $(xrandr | sed -rn 's#^([^ ]+) connected.*#\1#p' | grep -v '^eDP-1$') + $(xrandr | sed -rn 's#^([^ ]+) disconnected primary [0-9].*#\1#p' | grep -v '^eDP-1$') + $(xrandr | sed -rn 's#^([^ ]+) disconnected [0-9].*#\1#p' | grep -v '^eDP-1$') +) + +for display in "${displays[@]}"; do + xrandr --output "$display" --off +done + +xrandr --output eDP1 --primary +xrandr --output eDP-1 --primary diff --git a/dump-chrome-history b/dump-chrome-history new file mode 100755 index 0000000..d99e561 --- /dev/null +++ b/dump-chrome-history @@ -0,0 +1,29 @@ +#!/bin/bash + +TMPDIR="$(mktemp -d "/tmp/${0##*/}.XXXXXX")" +trap "rm -rf '${TMPDIR}'" EXIT TERM + +cp -n ~/.config/chromium/Default/History "$TMPDIR" + +sqlite_opts=() + +case $MODE in + zsh-history-compat) + select_fields="last_visit_time/1000000-11644473600 AS visit_date, url, title" + sqlite_opts=(-separator ' | ') + ;; + *) select_fields="datetime(last_visit_time/1000000-11644473600,'unixepoch', 'localtime') AS visit_date, url, title";; +esac + +output_filter() { + if [[ $MODE == 'zsh-history-compat' ]]; then + sed -r 's#^([0-9]+) \| (.*)$#: \1:0;\2#' + else + cat + fi +} + +sqlite3 "${sqlite_opts[@]}" "$TMPDIR/History" "SELECT $select_fields +FROM urls +WHERE last_visit_time/1000000-11644473600 > $(date +%s -d "${1:-2 months ago}") AND last_visit_time/1000000-11644473600 < $(date +%s -d "${2:-now}") +ORDER BY last_visit_time" | output_filter diff --git a/git-diff-gpg b/git-diff-gpg new file mode 100755 index 0000000..e249337 --- /dev/null +++ b/git-diff-gpg @@ -0,0 +1,8 @@ +#!/bin/bash + +if grep -q 'BEGIN PGP PUBLIC KEY BLOCK' "$1"; then + cat "$1" +else + echo "# GPG file SHA256 checksum: $(sha256sum - <"$1" | cut -d\ -f1)" + gpg --batch --decrypt 2>&1 "$1" +fi diff --git a/grep-email b/grep-email new file mode 100755 index 0000000..c37eb92 --- /dev/null +++ b/grep-email @@ -0,0 +1,3 @@ +#!/bin/bash + +exec grep -Eo "\b[^ ]*@[^ ]*\b" "$@" diff --git a/i3-continous-backup b/i3-continous-backup new file mode 100755 index 0000000..2c8ef2a --- /dev/null +++ b/i3-continous-backup @@ -0,0 +1,14 @@ +#!/bin/bash + +echo "${0##*/}: starting new backup job master" + +while :; do + if pgrep firefox &>/dev/null; then + echo "${0##*/}: creating new i3 backup" + i3-dump-layout-all + echo "${0##*/}: i3 backup complete" + else + echo "${0##*/}: skipping i3 backup creation due to firefox not running. is the system in an unclean state?" + fi + sleep 5m +done diff --git a/i3-dump-layout-all b/i3-dump-layout-all new file mode 100755 index 0000000..743328f --- /dev/null +++ b/i3-dump-layout-all @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +for i in {1..20}; do + i3-resurrect save -w $i --swallow=class,instance,title +done + +backupdir=~/.i3/i3-resurrect-backups +keep_backups=30 + +mkdir -p "$backupdir" +cp -r ~/.i3/i3-resurrect $backupdir/0 + +if [[ -d "$backupdir/$keep_backups" ]]; then + rm -rf "$backupdir/$keep_backups" +fi + +i=$((keep_backups - 1)) +while ((i >= 0)); do + if [[ -d "$backupdir/$i/" ]]; then + mv -n "$backupdir/$i/" "$backupdir/$((i + 1))"/ + fi + i=$((i - 1)) +done + diff --git a/i3-load-layouts b/i3-load-layouts new file mode 100755 index 0000000..3c736c6 --- /dev/null +++ b/i3-load-layouts @@ -0,0 +1,8 @@ +#!/bin/bash + +for i in {1..20}; do + #i3-msg "workspace $i; append_layout /home/flo/.i3/layouts/workspace-$i.json" + #sleep 2 + i3-resurrect restore -w $i --layout-only "$@" +done + @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +cachedir="$HOME/.cache/mutt" +if [[ ! -d "$cachedir" ]]; then + mkdir "$cachedir" +fi + +/usr/bin/mutt "$@" diff --git a/myip-dns b/myip-dns new file mode 100644 index 0000000..7052b07 --- /dev/null +++ b/myip-dns @@ -0,0 +1,3 @@ +#!/bin/bash + +dig +short myip.opendns.com @resolver1.opendns.com @@ -0,0 +1,24 @@ +#!/bin/bash + +cleanup_logs() { + if [[ -f PKGBUILD ]]; then + shopt -s nullglob + + dir="." + files=("$dir/"*.log "$dir/"*.log.*) + if [[ -f "${files[0]}" ]]; then + mkdir -p "$dir/logs" + mv "${files[@]}" "$dir/logs/" || return + gzip -f "$dir/logs/"*.log "$dir/logs/"*.log.{1,2,3,4,5,6,7,8,9} + fi + fi +} + +/usr/bin/pkgctl "$@" +exitcode=$? + +if [[ "$1" == "build" ]]; then + cleanup_logs +fi + +exit "$exitcode" diff --git a/rofi-gpgpass b/rofi-gpgpass new file mode 100755 index 0000000..5193ee2 --- /dev/null +++ b/rofi-gpgpass @@ -0,0 +1,80 @@ +#!/usr/bin/env ruby + +# +# rofi-gpgpass - small script to type passwords from my passwords.gpg +# +# Copyright (c) 2022 Florian Pritz <bluewind@xinu.at> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http: #www.gnu.org/licenses/ +# + +require 'open3' + +$pwfile = "#{ENV['HOME']}/passwords.gpg" + +def get_passwords(pwfile) + data = `gpg --quiet --batch --decrypt "#{pwfile}" | grep -v '^HIDEOLD'` + raise "Failed to get passwords" if $? != 0 or data == '""' + return data +end + +def get_single_password(passwords, identifier) + identifier.chomp! + passwords.split("\n").each do |line| + if line.end_with?(identifier) + return line.gsub(/^"([^"]+)" .*$/, '\1').chomp if line =~ /^"/ + return line.gsub(/^([^ ]+) .*$/, '\1').chomp + end + end + return nil +end + +def get_identifiers(passwords) + pass_array = passwords.split("\n").map do |line| + next line.gsub(/^"([^"]+)" (.*)$/, '\2') if line =~ /^"/ + next line.gsub(/^([^ ]+) (.*)$/, '\2') + end + return pass_array.join("\n") +end + +def rofi_select(passwords) + Open3.popen2("rofi -lines 20 -dmenu -i -p password") do |stdin, stdout, wait_thr| + stdin.puts get_identifiers(passwords) + return stdout.gets + end +end + +def type_password(identifier, passwords) + password = get_single_password(passwords, identifier) + + x_repeat_enabled = `xset q | awk '/auto repeat:/ {print $3}'`.chomp + system("xset r off") + + Open3.popen2("xdotool type --clearmodifiers --file -") do |stdin, stdout, wait_thr| + stdin.write password + end + + system("xset r '#{x_repeat_enabled}'") +end + +def main() + passwords = get_passwords($pwfile) + selection = rofi_select(passwords) + type_password(selection, passwords) + + return 1 +end + + +exit(main()) diff --git a/toggle-nm b/toggle-nm new file mode 100755 index 0000000..2f55119 --- /dev/null +++ b/toggle-nm @@ -0,0 +1,19 @@ +#! /bin/bash + +VPN="$1" + +if [[ -z "$VPN" ]]; then + #echo "usage: ${0##*/} <name>" >&2 + #exit 1 + VPN=$(nmcli --terse --fields NAME connection show | rofi -lines 20 -dmenu -i -p "network") +fi + +ACTIVE=$(nmcli con show --active "$VPN") + +if [[ -z "$ACTIVE" ]]; then + nmcli con up id "$VPN" +else + nmcli con down id "$VPN" +fi + +exit 0 diff --git a/unload-pa b/unload-pa new file mode 100755 index 0000000..3b4494c --- /dev/null +++ b/unload-pa @@ -0,0 +1,4 @@ +#!/bin/bash + +pacmd unload-module module-null-sink +pacmd unload-module module-ladspa-sink @@ -0,0 +1,6 @@ +#!/bin/bash + +set -ex + +pacman -Sy --needed archlinux-keyring +pacman -Su |