From 4c522a0985c76bc0892fb9f152081b7d767e0520 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 13 Jun 2022 15:49:14 +0200 Subject: [PATCH] bin: overall helper improvements --- .config/shell/browse | 2 +- .config/shell/functions | 6 +++++- .config/topgrade.toml | 2 +- .local/bin/scripts/b | 2 +- .local/bin/scripts/dif | 4 ++-- .local/bin/scripts/diff-color | 2 +- .local/bin/scripts/duploc | 3 ++- .local/bin/scripts/ex | 17 +++++++++++++---- .local/bin/scripts/git-fork | 1 + 9 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.config/shell/browse b/.config/shell/browse index 49fe20b..faa84c7 100644 --- a/.config/shell/browse +++ b/.config/shell/browse @@ -53,7 +53,7 @@ cd() { # LOCATE {{{1 # TODO no double heading with bat -alias fselect='fzf -0 -1 --reverse --height=30% | while read f; do test -d "$f" && cd "$f" || { highlight "$f" && print -s "b $f" && b "$f"; }; done'; +alias fselect='fzf -0 -1 --reverse --height=30% | while read f; do test -d "$f" && cd "$f" || { highlight "$f" && print -s "b \"$f\"" && b "$f"; }; done'; loci() { locate --all --ignore-case --basename --existing "$@" | command grep --extended-regexp --ignore-case --color=always $(echo "$|${@:$#}" | sed 's/ /|/g') | diff --git a/.config/shell/functions b/.config/shell/functions index 1c1f320..8cd94c2 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -247,6 +247,8 @@ sshl() { 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' + # Listen to loopback of mic alias listen='pactl load-module module-loopback; echo "Press Enter to stop"; read; pactl unload-module module-loopback' @@ -280,7 +282,9 @@ grpr() { grp --color=always --recursive $(echo $DIRS_IGNORE | sed 's|-x |--exclu grsh() { grpr --no-ignore-case "$@" $HOME/.{ba,z}sh* $HOME/.local/bin $CONFIG_SHELLS $CONFIG_ZSH; } # Recover stray swap files from neovim -alias vrec="ls $XDG_DATA_HOME/nvim/swap | sed 's/\%/\//g' | sed 's|\(.*\)\..*|\1|' | head -1 | xargs --no-run-if-empty nvim" +vrec() { + ls "$XDG_DATA_HOME/nvim/swap/$1" | sed 's/\%/\//g' | sed 's|\(.*\)\..*|\1|' | head -1 | xargs --no-run-if-empty nvim +} alias vrecd="ls $XDG_DATA_HOME/nvim/swap | head -1 | xargs -r -i mv {} /tmp" # I think this was something about recovering backup files diff --git a/.config/topgrade.toml b/.config/topgrade.toml index cd08167..62813e3 100644 --- a/.config/topgrade.toml +++ b/.config/topgrade.toml @@ -2,7 +2,7 @@ #assume_yes = true # Disable specific steps - same options as the command line flag -disable = ["node", "pnpm", "nix", "emacs"] #, "config-update"] +disable = ["node", "nix", "emacs"] #, "pnpm", "config-update"] # Ignore failures for these steps #ignore_failures = ["powershell"] diff --git a/.local/bin/scripts/b b/.local/bin/scripts/b index 5eb154f..b78926b 100755 --- a/.local/bin/scripts/b +++ b/.local/bin/scripts/b @@ -151,7 +151,7 @@ if test "$bat" -o "$batplain"; then test "$(bat --version | cut -d. -f2)" -gt 16 && rule=,rule if test $# -gt ${#bat[@]} -a $# -gt ${#batplain[@]} && test -z "$flags" then cut="--line-range :7" - batpager="cut -c-$(echo $(tput cols) \* 19 / 10 | cut -d. -f1)" + batpager="cut -c-$(expr $(tput cols) \* 19 / 10 | cut -d. -f1)" fi batcommand="$elevate bat $cut $flags --pager" batstyle="--style plain$rule" diff --git a/.local/bin/scripts/dif b/.local/bin/scripts/dif index bbda655..c7a296c 100755 --- a/.local/bin/scripts/dif +++ b/.local/bin/scripts/dif @@ -2,6 +2,6 @@ # interactive diff with pagination and nice coloring if file --mime "$1" "$2" | grep --quiet audio then ff() { ffprobe -loglevel warning -print_format default=noprint_wrappers=1 -show_format -pretty "$@"; } - $(test $(tput cols) -gt 120 && echo "diff --color=always --side-by-side" || echo "diff-color") --label="$1" --label="$2" <(ff "$1") <(ff "$2") -else diff-color "$@" + $(test $(tput cols) -gt 120 && echo "diff --color=always --side-by-side" || echo "diff-color") --report-identical-files --label="$1" --label="$2" <(ff "$1") <(ff "$2") +else diff-color --report-identical-files "$@" fi | less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen diff --git a/.local/bin/scripts/diff-color b/.local/bin/scripts/diff-color index ecf7415..3a0371e 100755 --- a/.local/bin/scripts/diff-color +++ b/.local/bin/scripts/diff-color @@ -1,4 +1,4 @@ #!/bin/sh # Colorize with diffr -diff --color=always --report-identical-files --unified=2 "$@" | +diff --color=always --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 diff --git a/.local/bin/scripts/duploc b/.local/bin/scripts/duploc index f534af5..a2f378a 100755 --- a/.local/bin/scripts/duploc +++ b/.local/bin/scripts/duploc @@ -1,7 +1,8 @@ #!/bin/sh -e # Delete files under current or given path which exist elsewhere as listed in the locate database # Matches first by name, then by checksum (currently inefficiently via md5) -find "$@" -size +5M -type f -exec sh -c "IFS=$'\n'"' +case "$1" in ([0-9]) size=$1; shift;; esac +find "$@" -size +${size:-5}M -type f -exec sh -c "IFS=$'\n'"' filepath="{}" target="$(basename "$filepath" | synct-unarchive)" highlight "$filepath" diff --git a/.local/bin/scripts/ex b/.local/bin/scripts/ex index 9b1d32c..ed7a4b2 100755 --- a/.local/bin/scripts/ex +++ b/.local/bin/scripts/ex @@ -5,6 +5,10 @@ # and shows progress indications for some operations # optdepends: rewrite(part of my dotfiles) for arg do +case $arg in + (-d) del=$(expr ${del:-0} + 1);; + (-*) param="$arg";; + (*) if test -r "$arg"; then fullpath="$(realpath "$arg")" name="$(basename "${fullpath%.*}")" @@ -21,7 +25,7 @@ for arg do (*.tgz) tar xzf "$fullpath" ;; (*.7z|*.z01|*.zip|*.jar) if which 7z >/dev/null - then 7z x "$fullpath" + then 7z x $param "$fullpath" else unzip "$fullpath" | rewrite fi;; (*.gz) gunzip "$fullpath" ;; @@ -35,13 +39,18 @@ for arg do # If we created a temporary subfolder, check if it can be eliminated if test "$(basename "$PWD")" = "$namepart" then if test $# -lt 2 -a "$(ls -U | wc -l)" -lt 3 - then test "$(ls)" && mv * .. + then test "$(ls)" && mv -v * .. cd .. && rm -d "$namepart" - else cd .. && mv "$namepart" "$name" + else cd .. && mv -v "$namepart" "$name" fi fi + case $del in + (2) rm "$arg";; + (1) mv -v "$arg" "/tmp";; + esac ) else echo "'$1' is not a readable file" - fi + fi;; +esac done diff --git a/.local/bin/scripts/git-fork b/.local/bin/scripts/git-fork index 3577fb3..075331c 100755 --- a/.local/bin/scripts/git-fork +++ b/.local/bin/scripts/git-fork @@ -13,6 +13,7 @@ if test -d ".git" then repo="$(basename "$PWD")" git remote set-url origin "$(git-repo "${3:-github.com}" "$repo" "$2" "${@:4}")" else repo="$1" && shift + # TODO cd into 1-/0-forks git-get "${3:-github.com}" "$repo" "${2:-$(git config --get user.name)}" "${@:4}" cd "$(expr "$4" \| "$repo")" fi