bin: improve some scripts

This commit is contained in:
xeruf 2022-07-05 11:40:11 +02:00
parent e5332e9a48
commit a99fee5553
9 changed files with 60 additions and 29 deletions

View File

@ -174,7 +174,7 @@ Version 2019-11-04 2021-02-16"
;;; Data Preservation ;;; Data Preservation
;; UNDO ;; Undo
(setq evil-want-fine-undo t) (setq evil-want-fine-undo t)
(setq amalgamating-undo-limit 5) (setq amalgamating-undo-limit 5)

View File

@ -45,7 +45,7 @@ let g:firenvim_config = {
\ 'takeover': 'once', \ 'takeover': 'once',
\ }, \ },
\ '.*church\.tools.*': { 'priority': 9, 'takeover': 'empty', }, \ '.*church\.tools.*': { 'priority': 9, 'takeover': 'empty', },
\ '.*element\.io.*': { 'priority': 9, 'takeover': 'empty', }, \ '.*element\.io.*': { 'priority': 9, 'takeover': 'never', },
\ '.*openstreetmap\.org.*': { 'priority': 9, 'takeover': 'once', }, \ '.*openstreetmap\.org.*': { 'priority': 9, 'takeover': 'once', },
\ '.*openstreetmap\.de.*': { 'priority': 9, 'takeover': 'once', }, \ '.*openstreetmap\.de.*': { 'priority': 9, 'takeover': 'once', },
\ \

View File

@ -3,6 +3,7 @@
if test "$ZSH_NAME" = "zsh" if test "$ZSH_NAME" = "zsh"
then then
alias -g ___='"$(eval "$(fc -ln -1)" | tail -n 1)"' alias -g ___='"$(eval "$(fc -ln -1)" | tail -n 1)"'
alias -g B="| xargs bat"
alias -g G="| grp" alias -g G="| grp"
alias -g X="| xargs -d '\n' -L 1" alias -g X="| xargs -d '\n' -L 1"
alias -g X1="| xargs -d '\n' -n 1" alias -g X1="| xargs -d '\n' -n 1"
@ -227,26 +228,30 @@ dns() {
drill A @8.8.8.8 -Q "$@" drill A @8.8.8.8 -Q "$@"
drill AAAA @8.8.8.8 -Q "$@" drill AAAA @8.8.8.8 -Q "$@"
} }
alias delta="sudo systemctl restart openvpn-client@deltaPeak.service || jcl --unit openvpn-client@deltaPeak.service"
sshl() { sshl() {
test "$1" = "-a" && shift && local all=true test "$1" = "-a" && shift && local all=true
lemonade server -allow 127.0.0.1 & lemonade server -allow 127.0.0.1 &
local authcache="/var/tmp/ssh-keys" local authcache="/var/tmp/ssh-keys"
mkdir -p "$authcache" mkdir -p "$authcache"
file="$authcache/$1" file="$authcache/$1"
if test ! -e "$file"; then test "$all" && pass scp ~/.bash_aliases "$@:"
test "$all" && pass scp ~/.bash_aliases "$@:" if ssh -G "$1" | grep --silent "^user root$"
if ! ssh -G "$1" | grep --silent "^user root$" && touch "$file"; then then TERM=xterm-256color pass ssh "$@"
ssh-copy-id -i "$(ssh -G "$1" | grep --max-count 1 "^identityfile " | cut -d " " -f2- | sed "s|^~|$HOME|")" "$1" && touch "$file" else
test ! -e "$file" &&
ssh-copy-id -i "$(ssh -G "$1" |
grep --max-count 1 "^identityfile " |
cut -d " " -f2- |
sed "s|^~|$HOME|")" "$1" &&
touch "$file"
TERM=xterm-256color kitty +kitten ssh -R 2489:127.0.0.1:2489 "$@" TERM=xterm-256color kitty +kitten ssh -R 2489:127.0.0.1:2489 "$@"
return $? return $?
fi
fi fi
TERM=xterm-256color pass ssh "$@"
} }
alias delta="sudo systemctl restart openvpn-client@deltaPeak.service || jcl --unit openvpn-client@deltaPeak.service"
# Hardcoded Programs
alias startMinecraftServer='curl https://ipinfo.io/ip | xclip -sel clip && cd ~/daten/games/sharedgames/minecraft/server && java -jar forge-1.12.2-14.23.5.2768-universal.jar -mx 8G' alias startMinecraftServer='curl https://ipinfo.io/ip | xclip -sel clip && cd ~/daten/games/sharedgames/minecraft/server && java -jar forge-1.12.2-14.23.5.2768-universal.jar -mx 8G'
alias scenic='/usr/lib/jvm/java-11-openjdk/bin/java --module-path /usr/lib/jvm/java-11-openjfx/lib --add-modules javafx.web,javafx.fxml,javafx.swing -jar scenicview.jar' alias scenic='/usr/lib/jvm/java-11-openjdk/bin/java --module-path /usr/lib/jvm/java-11-openjfx/lib --add-modules javafx.web,javafx.fxml,javafx.swing -jar scenicview.jar'
# Listen to loopback of mic # Listen to loopback of mic
@ -440,8 +445,10 @@ compdef mkcd=mkdir
# Other stuff {{{1 # Other stuff {{{1
# This is a function rather than a script as it potentially needs to cd out of the directory
umoul() { umoul() {
local arg local arg
# get the last arg
for arg; do true; done for arg; do true; done
if test "$arg" if test "$arg"
then mountpoint="$(test -d "$arg" && realpath "$arg" || echo "${MNT:-${XDG_RUNTIME_DIR}/mnt}/$arg")" then mountpoint="$(test -d "$arg" && realpath "$arg" || echo "${MNT:-${XDG_RUNTIME_DIR}/mnt}/$arg")"
@ -456,10 +463,10 @@ umoul() {
test "$(dirname "$mountpoint")" = "/" && return 1 test "$(dirname "$mountpoint")" = "/" && return 1
fi fi
case "$PWD" in case "$PWD" in
("$mountpoint"*) cd "$(dirname $mountpoint)";; ("$mountpoint"*) builtin cd "$(dirname $mountpoint)";;
esac esac
# pass on all args except last # pass on all args except last
moul -u "${@:1:$#-1}" "$mountpoint" moul -u "${@:1:$(((# > 1) ? #-1 : 0))}" "$mountpoint"
} }
resetdocker() { resetdocker() {

View File

@ -2,4 +2,8 @@
# Colorize with diffr # Colorize with diffr
# TODO light mode # TODO light mode
diff --color=always --minimal --unified=2 "$@" | diff --color=always --minimal --unified=2 "$@" |
diffr --colors refine-added:none:background:0x33,0x66,0x33:bold --colors added:none:background:0x33,0x44,0x33 --colors refine-removed:none:background:0x66,0x33,0x33:bold --colors removed:none:background:0x44,0x33,0x33 $(which diffr >/dev/null 2>&1 && test "$THEME" != "light" && echo 'diffr
--colors refine-added:none:background:0x33,0x66,0x33:bold
--colors added:none:background:0x33,0x44,0x33
--colors refine-removed:none:background:0x66,0x33,0x33:bold
--colors removed:none:background:0x44,0x33,0x33' || echo cat)

View File

@ -1,12 +1,19 @@
#!/bin/sh #!/bin/sh -e
# Test disk performance # Test disk performance
# Adapted from https://www.shellhacks.com/disk-speed-test-read-write-hdd-ssd-perfomance-linux/ # Adapted from https://www.shellhacks.com/disk-speed-test-read-write-hdd-ssd-perfomance-linux/
test "$1" = "-w" && write=true && shift
disk="${1:-$(df --output=source . | tail -1)}" disk="${1:-$(df --output=source . | tail -1)}"
if test "$write"
then exec &> >(tee "disktest-$(date +"%y%m%d")")
fi
# Needs sudo for read test
sudo hdparm -MWAgt "$disk" sudo hdparm -MWAgt "$disk"
if test $# -eq 0 if test $# -eq 0
then echo "Write test:" then echo "Write test:"
sync sync
#sudo dd status=progress if=/dev/random of=/var/tmp/tempfile bs=1M count=1K && sudo dd status=progress if=/var/tmp/tempfile of=tempfile bs=1M count=1K # This prevents predictions by using random, but since that is too slow we have to copy a previously created file
sudo dd status=progress if=/dev/zero of=tempfile bs=1M count=1K # sudo dd status=progress if=/dev/random of=/var/tmp/tempfile bs=1M count=1K && sudo dd status=progress if=/var/tmp/tempfile of=tempfile bs=1M count=1K
# TODO adjust size to disk
sudo dd status=progress if=/dev/zero of=tempfile bs=1000K count=1000
sudo rm tempfile sudo rm tempfile
fi fi

View File

@ -4,14 +4,14 @@
alias dedup='awk '"'"'!a[$0]++'"'" alias dedup='awk '"'"'!a[$0]++'"'"
listconf() { listconf() {
{ cat "$conf_cache"; { cat "$conf_cache"
fd --hidden --type file --size -1m --max-depth 1 . ~; fd --hidden --type file --size -1m --max-depth 1 . "$HOME"
find /boot -name "*.c*f*" 2>/dev/null
find "${XDG_CONFIG_HOME:-$HOME/.config}" /etc /var/lib/postgres /var/lib/pleroma/static/instance \ find "${XDG_CONFIG_HOME:-$HOME/.config}" /etc /var/lib/postgres /var/lib/pleroma/static/instance \
-maxdepth 4 -follow \ -maxdepth 4 -follow \
\( -name Partitions -o -name mdn -o -name .git -o -name .local -o -name plugged \) -prune -o \ \( -name Partitions -o -name mdn -o -name .git -o -name .local -o -name plugged \) -prune -o \
! \( -iname "*.markdown" -o -iname "*.md" -o -name "Network Persistent State" -o -iname "*.pem" \) -a \ ! \( -iname "*.markdown" -o -iname "*.md" -o -name "Network Persistent State" -o -iname "*.pem" \) -a \
-type f -readable -exec grep -lI '' {} + 2>/dev/null; -type f -readable -exec grep -lI '' {} + 2>/dev/null
find /boot -name "*.c*" 2>/dev/null;
} | dedup } | dedup
} }

View File

@ -13,6 +13,6 @@ case $# in
(*) dir="${prefix}_$2";; (*) dir="${prefix}_$2";;
esac;; esac;;
esac esac
shift 3 shift $(expr $# \& $# \< 3 \| 3)
git clone $remote "$@" $dir --recurse-submodules git clone $remote "$@" $dir --recurse-submodules
cd "${dir:-${4:-$2}}" cd "${dir:-${4:-$2}}"

View File

@ -38,7 +38,7 @@ shift $(expr 2 \& $# \> 1 \| 1)
#uid=$(id --user),gid=$(id --group), \ #uid=$(id --user),gid=$(id --group), \
if ! mountpoint "$mountpoint" 2>/dev/null if ! mountpoint "$mountpoint" 2>/dev/null
then mp="/run/media/$USER/$arg" && test -e "$mp" && mountpoint="$mp" then mp="/run/media/$USER/$arg" && test -e "$mp" && mountpoint="$mp"
sudo mount -vo users,X-mount.mkdir,noatime $partition $mountpoint "$@" sudo mount -vo users,X-mount.mkdir,noatime,umask=003,gid=users,uid=$USER $partition $mountpoint "$@"
fi fi
cd $mountpoint cd $mountpoint
exec $SHELL exec $SHELL

View File

@ -1,10 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences/33206814 # https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences/33206814#33206814
print("\\033[XXm") print("\\033[XXm")
for i in range(30,37+1): for i in range(30,37+1):
print("\033[%dm%d\t\t\033[%dm%d" % (i,i,i+60,i+60)); print("\033[%dm%d\t\t\033[%dm%d" % (i,i,i+30,i+30));
print("\033[39m\\033[39m - Reset colour (0 to reset all)") print("\033[39m\\033[39m - Reset colour (0 to reset all)")
print("\\033[2K - Clear Line") print("\\033[2K - Clear Line")
@ -18,7 +18,20 @@ print("\\033[K Erase to end of line")
print("\\033[s Save cursor position") print("\\033[s Save cursor position")
print("\\033[u Restore cursor position") print("\\033[u Restore cursor position")
print(" ") print(" ")
print("\\033[4m Underline on")
print("\\033[24m Underline off") def illustrate(command, *text):
print("\\033[1m Bold on") print("\033[", command, "m\\033[", command, "m - ", *text, sep="", end="\t")
print("\\033[21m Bold off")
def toggle(command, text):
illustrate(command, text, " on")
illustrate(command + 20, text, " off\033[0m")
print()
toggle(1, "Bold")
toggle(2, "Grey")
toggle(3, "Italic")
toggle(4, "Underline")
#toggle(5, "Bold")
#toggle(6, "Bold")
toggle(7, "Highlight")
#toggle(8, "Bold")
toggle(9, "Strike")