This commit is contained in:
a 2024-03-26 16:15:01 -05:00
parent b1f7b8ff68
commit 7c63d6d420
Signed by: a
GPG Key ID: 374BC539FE795AF0
11 changed files with 492 additions and 0 deletions

20
.local/script/gamermode Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
gamermode_off(){
notify-send -t 1600 'disabled gamermode' --icon=video-display
picom -b --log-file /var/log/picom.log --log-level INFO
}
gamermode_on(){
notify-send -t 1600 'enabled gamermode' --icon=video-display
killall picom;
}
if [ `pgrep -x picom` ]; then
gamermode_on
else
gamermode_off
fi
exit

11
.local/script/gitsave Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
git add -A
if [ "$#" -ne 1 ]; then
git commit -m "a"
else
git commit -m $@
fi
git push

29
.local/script/goinstallbinaries Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
go install github.com/klauspost/asmfmt/cmd/asmfmt@latest
go install github.com/go-delve/delve/cmd/dlv@latest
go install github.com/kisielk/errcheck@latest
go install github.com/davidrjenni/reftools/cmd/fillstruct@master
go install github.com/rogpeppe/godef@latest
go install golang.org/x/tools/cmd/goimports@master
go install github.com/mgechev/revive@latest
go install golang.org/x/tools/gopls@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/fatih/gomodifytags@latest
go install golang.org/x/tools/cmd/gorename@master
go install github.com/jstemmer/gotags@master
go install golang.org/x/tools/cmd/guru@master
go install github.com/josharian/impl@main
go install honnef.co/go/tools/cmd/keyify@master
go install github.com/fatih/motion@latest
go install github.com/koron/iferr@master
go install golang.org/x/perf/cmd/benchstat@latest
go install github.com/Quasilyte/go-benchrun@latest
go install github.com/tmrts/boilr@latest
go install github.com/goreleaser/goreleaser@latest
go install github.com/wader/bump/cmd/bump@latest
go install mvdan.cc/gofumpt@latest
go install github.com/jackc/tern/v2@latest
asdf reshim golang

128
.local/script/inotify-consumers Executable file
View File

@ -0,0 +1,128 @@
#!/bin/bash
# Get the procs sorted by the number of inotify watches
# @author Carl-Erik Kopseng
# @latest https://github.com/fatso83/dotfiles/blob/master/utils/scripts/inotify-consumers
# Discussion leading up to answer: https://unix.stackexchange.com/questions/15509/whos-consuming-my-inotify-resources
#
#
########################################## Notice ##########################################
### Since Fall 2022 you should prefer using the following C++ version ###
### https://github.com/mikesart/inotify-info ###
############################################################################################
#
#
# The fastest version of this script is here: https://github.com/fatso83/dotfiles/commit/inotify-consumers-v1-fastest
# Later PRs introduced significant slowdowns at the cost of better output, but it is insignificant on most machines
# See this for details: https://github.com/fatso83/dotfiles/pull/10#issuecomment-1122374716
main(){
printf "\n%${WLEN}s %${WLEN}s\n" "INOTIFY" "INSTANCES"
printf "%${WLEN}s %${WLEN}s\n" "WATCHES" "PER "
printf "%${WLEN}s %${WLEN}s %s\n" " COUNT " "PROCESS " "PID USER COMMAND"
printf -- "------------------------------------------------------------\n"
generateData
}
usage(){
cat << EOF
Usage: $0 [--help|--limits]
-l, --limits Will print the current related limits and how to change them
-h, --help Show this help
FYI: Check out Michael Sartain's C++ take on this script. The resulting native executable
is much faster, modern and feature rich. It can be found at
https://github.com/mikesart/inotify-info
Requires building, but is well worth the few seconds :)
EOF
}
limits(){
printf "\nCurrent limits\n-------------\n"
sysctl fs.inotify.max_user_instances fs.inotify.max_user_watches
cat <<- EOF
Changing settings permanently
-----------------------------
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p # re-read config
EOF
}
generateData() {
local -i PROC
local -i PID
local -i CNT
local -i INSTANCES
local -i TOT
local -i TOTINSTANCES
# read process list into cache
local PSLIST="$(ps ax -o pid,user=WIDE-COLUMN,command $COLSTRING)"
local INOTIFY="$(find /proc/[0-9]*/fdinfo -type f 2>/dev/null | xargs grep ^inotify 2>/dev/null)"
local INOTIFYCNT="$(echo "$INOTIFY" | cut -d "/" -s --output-delimiter=" " -f 3 |uniq -c | sed -e 's/:.*//')"
# unique instances per process is denoted by number of inotify FDs
local INOTIFYINSTANCES="$(echo "$INOTIFY" | cut -d "/" -s --output-delimiter=" " -f 3,5 | sed -e 's/:.*//'| uniq |awk '{print $1}' |uniq -c)"
local INOTIFYUSERINSTANCES="$(echo "$INOTIFY" | cut -d "/" -s --output-delimiter=" " -f 3,5 | sed -e 's/:.*//' | uniq |
while read PID FD; do echo $PID $FD $(grep -e "^ *${PID} " <<< "$PSLIST"|awk '{print $2}'); done | cut -d" " -f 3 | sort | uniq -c |sort -nr)"
set -e
cat <<< "$INOTIFYCNT" |
{
while read -rs CNT PROC; do # count watches of processes found
echo "${PROC},${CNT},$(echo "$INOTIFYINSTANCES" | grep " ${PROC}$" |awk '{print $1}')"
done
} |
grep -v ",0," | # remove entires without watches
sort -n -t "," -k 2,3 -r | # sort to begin with highest numbers
{ # group commands so that $TOT is visible in the printf
IFS=","
while read -rs PID CNT INSTANCES; do # show watches and corresponding process info
printf "%$(( WLEN - 2 ))d %$(( WLEN - 2 ))d %s\n" "$CNT" "$INSTANCES" "$(grep -e "^ *${PID} " <<< "$PSLIST")"
TOT=$(( TOT + CNT ))
TOTINSTANCES=$(( TOTINSTANCES + INSTANCES))
done
# These stats should be per-user as well, since inotify limits are per-user..
printf "\n%$(( WLEN - 2 ))d %s\n" "$TOT" "WATCHES TOTAL COUNT"
# the total across different users is somewhat meaningless, not printing for now.
# printf "\n%$(( WLEN - 2 ))d %s\n" "$TOTINSTANCES" "TOTAL INSTANCES COUNT"
}
echo ""
echo "INotify instances per user (e.g. limits specified by fs.inotify.max_user_instances): "
echo ""
(
echo "INSTANCES USER"
echo "----------- ------------------"
echo "$INOTIFYUSERINSTANCES"
) | column -t
echo ""
exit 0
}
# get terminal width
declare -i COLS=$(tput cols 2>/dev/null || echo 80)
declare -i WLEN=10
declare COLSTRING="--columns $(( COLS - WLEN ))" # get terminal width
if [ "$1" = "--limits" -o "$1" = "-l" ]; then
limits
exit 0
fi
if [ "$1" = "--help" -o "$1" = "-h" ]; then
usage
exit 0
fi
# added this line and moved some declarations to allow for the full display instead of a truncated version
if [ "$1" = "--full" -o "$1" = "-f" ]; then
unset COLSTRING
main
fi
if [ -n "$1" ]; then
printf "\nUnknown parameter '$1'\n" >&2
usage
exit 1
fi
main

121
.local/script/kubectl-ssh Executable file
View File

@ -0,0 +1,121 @@
#!/usr/bin/env bash
set -e
ssh_node() {
node=$1
if [ "$node" = "" ]; then
node=$(kubectl get node -o name | sed 's/node\///' | tr '\n' ' ')
node=${node::-1}
if [[ "$node" =~ " " ]]; then
echo "Node name must be specified. Choose one of: [$node]"
exit 1
else
echo "Single-node cluster detected. Defaulting to node $node"
fi
fi
pod=$(
kubectl create -o name -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
generateName: ssh-node-
labels:
plugin: ssh-node
spec:
nodeName: $node
containers:
- name: ssh-node
image: busybox
imagePullPolicy: IfNotPresent
command: ["chroot", "/host"]
tty: true
stdin: true
stdinOnce: true
securityContext:
privileged: true
volumeMounts:
- name: host
mountPath: /host
volumes:
- name: host
hostPath:
path: /
hostNetwork: true
hostIPC: true
hostPID: true
restartPolicy: Never
EOF
)
deletePod() {
kubectl delete $pod --wait=false
}
trap deletePod EXIT
echo "Created $pod"
echo "Waiting for container to start..."
kubectl wait --for=condition=Ready $pod >/dev/null
kubectl attach -it $pod -c ssh-node
}
ssh_pod() {
# TODO: improve this
if [ "$1" == "" ]; then
echo "Pod name must be specified."
exit 1
fi
kubectl exec -it "$@" bash || (
echo "Running bash in pod failed; trying with sh"
kubectl exec -it "$@" sh
)
}
print_usage() {
echo "Provider-agnostic way of opening a remote shell to a Kubernetes node."
echo
echo "Enables you to access a node even when it doesn't run an SSH server or"
echo "when you don't have the required credentials. Also, the way you log in"
echo "is always the same, regardless of what provides the Kubernetes cluster"
echo "(e.g. Minikube, Kind, Docker Desktop, GKE, AKS, EKS, ...)"
echo
echo "You must have cluster-admin rights to use this plugin."
echo
echo "The primary focus of this plugin is to provide access to nodes, but it"
echo "also provides a quick way of running a shell inside a pod."
echo
echo "Examples: "
echo " # Open a shell to node of a single-node cluster (e.g. Docker Desktop)"
echo " kubectl ssh node"
echo
echo " # Open a shell to node of a multi-node cluster (e.g. GKE)"
echo " kubectl ssh node my-worker-node-1"
echo
echo " # Open a shell to a pod"
echo " kubectl ssh pod my-pod"
echo
echo "Usage:"
echo " kubectl ssh node [nodeName]"
echo " kubectl ssh pod [podName] [-n namespace] [-c container]"
exit 0
}
if [ "$1" == "--help" ]; then
print_usage
fi
if [[ "$1" == node/* ]]; then
ssh_node ${1:5}
elif [ "$1" == "node" ]; then
ssh_node $2
elif [[ "$1" == pod/* ]]; then
ssh_pod "$@"
elif [ "$1" == "pod" ]; then
shift
ssh_pod "$@"
else
print_usage
fi

6
.local/script/mfly Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
first=$1
shift
fly -c "fly.${first}.toml" $@

45
.local/script/proton Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
# Usage:
# proton program.exe
#
# Example Env Vars:
# PROTONPREFIX="$HOME/proton_316"
# PROTONVERSION="Proton 3.16"
# Folder name of the Proton version found under "steamapps/common/".
# proton_version="Proton - Experimental"
proton_version="Proton 7.0"
# Path to installation directory of Steam.
# Alternate path: "$HOME/.steam/steam"
client_dir="$HOME/.steam/steam"
# Default data folder for Proton/WINE environment. Folder must exist.
# If the environmental variable PROTONPREFIX is set, it will overwrite env_dir.
mkdir -p "$HOME/.proton/$proton_version"
env_dir="$HOME/.proton/$proton_version"
WINEPREFIX=protontricks
# Proton modes to run
# run = start target app
# waitforexitandrun = wait for wineserver to shut down
# getcompatpath = linux -> windows path
# getnativepath = windows -> linux path
mode=run
# ENVIRONMENTAL VARIABLES
if [ -n "${PROTONPREFIX+1}" ]
then
env_dir=$PROTONPREFIX
fi
if [ -n "${PROTONVERSION+1}" ]
then
proton_version=$PROTONVERSION
fi
# EXECUTE
export STEAM_COMPAT_CLIENT_INSTALL_PATH=$client_dir
export STEAM_COMPAT_DATA_PATH=$env_dir
"$client_dir/steamapps/common/$proton_version/proton" $mode $*

6
.local/script/replace-subdir Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
#
echo "use tool ruplacer instead"
echo "eget your-tools/ruplacer"

54
.local/script/repotool Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/zsh
ROOT_PREFIX="${REPO_ROOT_DIR:-$HOME/repo}"
GIT_USER="${REPO_GIT_USER:-git}"
clean_path()
{
stripped=$1
prefix="http://"
stripped="${stripped#"$prefix"}"
prefix="https://"
stripped="${stripped#"$prefix"}"
prefix="git@"
stripped="${stripped#"$prefix"}"
stripped=$(echo "$stripped" | sed -e "s/:/\//1")
echo $stripped
}
show_help()
{
printf "Usage: repo <get|goto> <repo>\n"
}
do_get()
{
cleaned=$(clean_path $1)
output_path="$ROOT_PREFIX/$cleaned"
mkdir -p $output_path
if [ ! -d $output_path/.git ]; then
repourl=$(echo "$GIT_USER@$cleaned" | sed -e "s/\//:/1")
git clone $repourl $output_path
fi
cd $output_path
}
do_goto()
{
cleaned=$(clean_path $1)
output_path="$ROOT_PREFIX/$cleaned"
cd $output_path
}
case "$1" in
'get' )
do_get $2
do_goto $2
;;
'go' | "goto")
do_goto $2
;;
'help' | "-h"| "-help" | "--help")
show_help
esac

3
.local/script/shot Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
scrot --freeze '/home/a/shots/%F_%T_$wx$h.png' -s -e 'xclip -selection clipboard -t image/png -i $f'

69
.local/script/wttr Executable file
View File

@ -0,0 +1,69 @@
#!/usr/local/bin/gentee
const : URL = "https://wttr.in/"
const : URLV2 = "https://v2.wttr.in/"
const : URLV3 = "https://v3.wttr.in/"
const : MOONURL = "https://wttr.in/moon@"
func dirs() arr.str {
arr.str res = {
GetEnv("HOME")+"/.config/wttr/default-city.txt",
GetEnv("HOME")+"/.wttr",
}
return res
}
func help() str {
return Format(`
Usage: wttr <region>
-v2
Use v2 (%s)
-v3
Use v3 (%s)
-m
display moon (%s)
-c
Use metric units
-f
Use imperial units
-t -today
Display today's weather
`,
URLV2,
URLV3,
MOONURL,
)
}
func request(str url) str {
map empty
map headers = {"User-Agent":"curl/7.87"}
return HTTPRequest(url, "GET", empty, headers)
}
run {
if IsArg("h") || IsArg("help") {
Println(help())
return
}
str loc = Arg("")
str url = URL
for fl in dirs() {
if ExistFile(fl): loc = TrimSpace(ReadFile(fl)); break;
}
if IsArg("v2"): url = URLV2
if IsArg("v3"): url = URLV3
if IsArg("m"): url = MOONURL
switch Arg("")
case "":
default: loc = Arg("")
switch loc
case "": url = url + "?"
default: url = url + loc +"?"
if IsArg("c"): url = url + "&m"
if IsArg("f"): url = url + "&u"
if (IsArg("t")||IsArg("today")): url = url + "&1n"
//Print(request(url))
Run(`head`,"-n","-1", stdin: buf(request(url)))
}