summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2024-03-05 22:18:49 +0500
committerAnton Bobov <anton@bobov.name>2024-03-05 22:25:05 +0500
commite2917305c959106ab01018b4c768505fb2f655ac (patch)
tree55079dff911c81a5f9dbb84f3e584353a74c28ad
parentc1c648cabb419a0f281e32685287ca1e07e9271f (diff)
Updates
-rwxr-xr-xcpufreq26
-rwxr-xr-xd-backup9
-rwxr-xr-xdocker-netshoot52
-rwxr-xr-xdocker-shell30
-rwxr-xr-xgit-hotspots17
-rwxr-xr-xpaste-image-to-file29
6 files changed, 163 insertions, 0 deletions
diff --git a/cpufreq b/cpufreq
new file mode 100755
index 0000000..64dbbb9
--- /dev/null
+++ b/cpufreq
@@ -0,0 +1,26 @@
+#!/bin/bash
+# From: https://github.com/fmarier/root-scripts/blob/master/cpufreq
+#
+# Usage:
+#
+# cpufreq
+# cpufreq performance
+# cpufreq powersave
+
+if [ "z$1" = "z" ] ; then
+ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+ exit 0
+fi
+
+VALID="$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)"
+for valid in $VALID ; do
+ if [ "$1" = "$valid" ] ; then
+ for cpu in /sys/devices/system/cpu/cpu[0-9]* ; do
+ echo "$valid" > "$cpu/cpufreq/scaling_governor"
+ done
+ exit 0
+ fi
+done
+
+echo "Invalid parameter. Valid governors are: $VALID"
+exit 1
diff --git a/d-backup b/d-backup
index a6900e5..5cd0ef1 100755
--- a/d-backup
+++ b/d-backup
@@ -14,6 +14,7 @@ fi
HOME=/home/anton
REMOVE_ALL_BUT_N_FULL=4
+REMOVE_OLDER_THAN=1Y
FULL_IF_OLDER_THAN=3M
source "$HOME/.duplicity.conf"
@@ -48,6 +49,11 @@ cleanup() {
_duplicity remove-all-but-n-full $REMOVE_ALL_BUT_N_FULL --force "$TARGET"
}
+cleanup-old() {
+ _duplicity cleanup --force "$TARGET"
+ _duplicity remove-older-than $REMOVE_OLDER_THAN --force "$TARGET"
+}
+
stats() {
_duplicity collection-status "$TARGET"
}
@@ -73,6 +79,9 @@ while (("$#")); do
cleanup)
cleanup
;;
+ cleanup-old)
+ cleanup-old
+ ;;
stats)
stats
;;
diff --git a/docker-netshoot b/docker-netshoot
new file mode 100755
index 0000000..8b77e7f
--- /dev/null
+++ b/docker-netshoot
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+set -euo pipefail
+
+NETSHOOT_IMAGE="nicolaka/netshoot"
+
+usage() {
+ echo "Run netshoot container with docker network."
+ echo "Options:"
+ printf "\t%s\t\t%s\n" "-h" "print this help"
+ printf "\t%s\t%s\n" "-n NETWORK" "user provided network"
+ printf "\t%s\t\t%s\n" "-N" "user default network"
+}
+
+select_network() {
+ docker network ls | fzf \
+ --header-lines=1 \
+ --select-1 --exit-0 \
+ --preview-label="Containers" \
+ --preview-window=down,10 \
+ --preview "docker network inspect {1} | jq -r '.[].Containers | .[].Name'" | awk '{print $1}'
+}
+
+main() {
+ local network=
+ while getopts "hNn:" opt; do
+ case "${opt}" in
+ h)
+ usage
+ exit
+ ;;
+ N)
+ network="default"
+ ;;
+ n)
+ network="$OPTARG"
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+ done
+ shift $((OPTIND - 1))
+
+ if [ -z "$network" ]; then
+ network=$(select_network)
+ fi
+ docker run --interactive --tty --rm --network "$network" "$NETSHOOT_IMAGE"
+}
+
+main "$@"
diff --git a/docker-shell b/docker-shell
new file mode 100755
index 0000000..6728e1c
--- /dev/null
+++ b/docker-shell
@@ -0,0 +1,30 @@
+#!/bin/bash
+# Exec shell into running container.
+
+set -euo pipefail
+
+select_container() {
+ docker ps | fzf \
+ --header-lines=1 \
+ --select-1 --exit-0 \
+ --preview-label="Logs" \
+ --preview-window=down,10 \
+ --preview "docker logs --tail=9 {1}" | awk '{print $1}'
+}
+
+main() {
+ if [ $# -eq 0 ]; then
+ container=$(select_container)
+ else
+ if ! docker inspect "$1" >/dev/null 2>&1; then
+ echo "No running container: $1"
+ exit 1
+ fi
+ container="$1"
+ fi
+ for command in /bin/bash /bin/sh; do
+ docker exec --interactive --tty "$container" "$command" || continue && exit 0
+ done
+}
+
+main "$@"
diff --git a/git-hotspots b/git-hotspots
new file mode 100755
index 0000000..a18ce61
--- /dev/null
+++ b/git-hotspots
@@ -0,0 +1,17 @@
+#!/bin/bash
+# https://docs.mergestat.com/blog/2023/01/03/finding-code-hotspots-in-git-repos
+#
+# Finds hotspots as the files most frequently modified (by number of commits).
+
+set -euo pipefail
+
+main() {
+ git log --format=format: --name-only --since=12.month "$@" |
+ grep -vE '^$' |
+ sort |
+ uniq -c |
+ sort -nr |
+ head -50
+}
+
+main "$@"
diff --git a/paste-image-to-file b/paste-image-to-file
new file mode 100755
index 0000000..57887ed
--- /dev/null
+++ b/paste-image-to-file
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+set -euo pipefail
+
+find_clipboard_image_mime_type() {
+ xclip -selection clipboard -t TARGETS -o | grep '^image/' | head -1 || true
+}
+
+save_clipboard_image_to_file() {
+ mime="$1"
+ outdir="$2"
+ extension=${mime#*/}
+ date=$(date +%F-%R)
+ template="clipboard-$date-XXXX"
+ filename=$(mktemp --tmpdir="$outdir" --suffix ".$extension" -t "$template")
+ xclip -selection clipboard -t "$mime" -o >"$filename"
+ echo "$filename"
+}
+
+main() {
+ mime=$(find_clipboard_image_mime_type)
+ if [ -z "$mime" ]; then
+ echo No image in cliboard >&2
+ exit 1
+ fi
+ save_clipboard_image_to_file "$mime" "$PWD"
+}
+
+main "$@"