From 747b50f2e3e11298a1f118236c2fdc9e5e6e6230 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Tue, 12 Sep 2023 01:16:35 +0200 Subject: [PATCH] config: helpful helpers --- .config/mimeapps.list##user.janek | 16 +++++++++------- .config/nvim/init/firenvim.vim | 2 +- .config/shell/functions | 5 +++-- .local/bin/scripts/b | 26 +++++++++++++------------- .local/bin/scripts/clean | 2 +- .local/bin/scripts/downloads | 8 ++++++++ .local/bin/scripts/game | 2 +- .local/bin/scripts/gamedeveloperstudio | 6 ++++++ .local/bin/scripts/git-fuzz | 2 +- .local/bin/scripts/help | 11 ++++++++--- .local/bin/scripts/mpdr | 7 +++++++ .local/bin/scripts/mvconfl | 9 +++++++++ .local/bin/scripts/quickref | 2 +- .local/bin/scripts/save | 3 ++- .local/bin/scripts/sy | 2 +- .local/bin/scripts/topng | 4 +++- .local/bin/scripts/xdg-mime-file | 9 +++++---- .zshenv | 8 +++++--- 18 files changed, 84 insertions(+), 40 deletions(-) create mode 100755 .local/bin/scripts/downloads create mode 100755 .local/bin/scripts/gamedeveloperstudio create mode 100755 .local/bin/scripts/mpdr create mode 100755 .local/bin/scripts/mvconfl diff --git a/.config/mimeapps.list##user.janek b/.config/mimeapps.list##user.janek index 40ae92c..8708a70 100644 --- a/.config/mimeapps.list##user.janek +++ b/.config/mimeapps.list##user.janek @@ -31,13 +31,15 @@ image/jpeg=org.kde.showfoto.desktop; image/png=org.kde.showfoto.desktop; inode/directory=org.kde.dolphin.desktop; text/html=firefox.desktop; -x-scheme-handler/discord-757737740241731714=discord-757737740241731714.desktop -x-scheme-handler/etcher=balena-etcher-electron.desktop +x-scheme-handler/discord-757737740241731714=discord-757737740241731714.desktop; +x-scheme-handler/etcher=balena-etcher-electron.desktop; x-scheme-handler/ferdi=ferdi.desktop x-scheme-handler/http=firefox.desktop; x-scheme-handler/https=firefox.desktop; -x-scheme-handler/jitsi-meet=Jitsi Meet.desktop -x-scheme-handler/org-protocol=org-protocol.desktop -x-scheme-handler/sgnl=signal-desktop.desktop -x-scheme-handler/signalcaptcha=signal.desktop -x-scheme-handler/tg=telegram.desktop +x-scheme-handler/jitsi-meet=Jitsi Meet.desktop; +x-scheme-handler/org-protocol=org-protocol.desktop; +x-scheme-handler/sgnl=signal-desktop.desktop; +x-scheme-handler/signalcaptcha=signal.desktop; +x-scheme-handler/tg=telegram.desktop; +video/mp4=vlc.desktop; +text/calendar=emacsclient.desktop; diff --git a/.config/nvim/init/firenvim.vim b/.config/nvim/init/firenvim.vim index b4616ce..d900df7 100644 --- a/.config/nvim/init/firenvim.vim +++ b/.config/nvim/init/firenvim.vim @@ -8,7 +8,7 @@ let g:firenvim_config = { \ 'cmdline': 'firenvim', \ 'priority': 0, \ 'selector': 'textarea:not([readonly]):not([class="handsontableInput"]):not([wrap="off"]):not([rows="1"]):not([title="Replace"]):not([title="Search"]):not([name="message"]), - \ div[role="textbox"]:not([aria-label="Search"]), div[class="CodeMirror"]', + \ div[role="textbox"]:not([aria-label="Search"]):not([class="ProseMirror"]), div[class="CodeMirror"]', \ 'takeover': 'always', \ }, \ '.*com.*': { diff --git a/.config/shell/functions b/.config/shell/functions index 04e8c4e..ff7cc11 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -270,7 +270,7 @@ u() { if command -v pacman >/dev/null; then if test "$(stat /etc/pacman.d/mirrorlist --printf=%y | cut -d'-' -f1-2)" != "$(date +%Y-%m)" then - # TODO or if location changed significantly or very slow + # TODO also run if location changed significantly or mirror is slow if command -v pacman-mirrors >/dev/null then sudo pacman-mirrors --geoip else sudo touch /etc/pacman.d/mirrorlist @@ -282,7 +282,7 @@ u() { fi if command -v topgrade >/dev/null then - topgrade --disable node emacs remotes + nice -10 topgrade --disable node emacs remotes if test -d "$XDG_CONFIG_HOME/emacs" then builtin cd $XDG_CONFIG_HOME/emacs @@ -371,6 +371,7 @@ alias pmd='pandoc -t markdown_strict-raw_html' alias clr='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 | less -F' alias f='fossil' +alias fl='fossil timeline --format "[%d] %h %c <%a>"' alias fs='fossil status' alias fc='fossil commit -v' fdf() { diff --git a/.local/bin/scripts/b b/.local/bin/scripts/b index 733a2aa..71af948 100755 --- a/.local/bin/scripts/b +++ b/.local/bin/scripts/b @@ -26,13 +26,14 @@ case "$OPTION" in (v) set -eo xtrace; export PS4='+\#> ';; (h|?) echo "Usage: $(basename $0) [-$opts] " && exit 2;; + (--) break;; esac done shift "$(($OPTIND -1))" checkperm() { checkaccess -r "$@" || elevate=sudo - mime="$(test -n "$shifted" || $elevate file --dereference --mime "$@")" + mime="$(test -n "$shifted" || $elevate file --dereference --mime -- "$@")" } fileinfo() { tput setaf 4 @@ -45,8 +46,7 @@ fileinfo() { # TODO do not grep bitrate but extract properly #probe="$($elevate ffprobe "$arg" 2>&1)" #echo $probe | grep -v -e '00:00:00.04' -e 'ansi' && - $inspect || - $elevate ffprobe -hide_banner "$arg" 2>&1 | grep "bitrate: ....\? " | sed 's/, start:[^,]\+,/,/' || + { ! $inspect && $elevate ffprobe -hide_banner "$arg" 2>&1 | grep "bitrate: ....\? " | sed 's/, start:[^,]\+,/,/'; } || $elevate stat --format "%U:%G %A %s $( size="$($elevate unzip -l "$arg" 2>/dev/null | tail -1)" && echo "(uncompressed $(echo $size | cut -d' ' -f1 | numfmt --to=iec-i --suffix=B))" @@ -59,7 +59,7 @@ prefix=/tmp/b mkdir -p "$prefix" declare -a timg timga bat batplain ls for arg; do - case "$arg" in (-*) flags="$flags $arg"; continue;; esac + test -z "$noflags" && case "$arg" in (--) noflags=true; continue;; (-*) flags="$flags $arg"; continue;; esac checkperm "$arg" if ! $elevate test -e "$arg" then if test -h "$arg" @@ -70,7 +70,7 @@ for arg; do fi # amount of columns in a grid grid=$(expr $(tput cols) / \( 25 - \( $# / 2 \) \& $# \< 30 \| 5 \)) - tmpfile="$prefix/$(basename "$arg")_$(dd "if=$arg" bs=512 count=10 2>/dev/null | md5sum | tr -d ' ' || true)" + tmpfile="$prefix/$(basename -- "$arg")_$(dd "if=$arg" bs=512 count=10 2>/dev/null | md5sum | tr -d ' ' || true)" mkdir -p "$prefix" case "$mime" in (*\ application/pdf\;*) @@ -97,7 +97,7 @@ for arg; do suffix=_thumbs.jpg mtn -q -i -t -W -r$(expr 5 - $# \& $# \< 4 \| 1) -D6 -b 0.6 -c $grid -w $(expr $(tput cols) '*' 20) \ -O "$prefix" -o "$suffix" "$arg" && - timg -W "$prefix/$(basename "${arg%.*}")$suffix" + timg -W "$prefix/$(basename -- "${arg%.*}")$suffix" ;; (*\ image/*) timg+=("$arg") @@ -171,7 +171,7 @@ if test "$timg"; then for img in "${timg[@]}" do case $img in (*.gif) continue;; esac ident="$(identify -ping -precision 3 -format "%wx%h %b %m %[bit-depth]-bit %[colorspace]" "$img")" - printf "%11s %-30s %s\n" "${ident%% *}" "$(basename "$img")" "${ident#* }" + printf "%11s %-30s %s\n" "${ident%% *}" "$(basename -- "$img")" "${ident#* }" done tput sgr0 fi @@ -195,8 +195,8 @@ if test "$bat" -o "$batplain"; then then case $TERM in (*kitty) declare -a timgtxt for file in "${bat[@]}" - do txt="$prefix/$(basename "$file").txt" - cp "$file" "$txt" + do txt="$prefix/$(basename -- "$file").txt" + cp -- "$file" "$txt" timgtxt+=("$txt") done timg -V --grid="$(expr 4 \& ${#bat[@]} \> 5 \| ${#bat[@]})" --title="%b" --frames=3 "${timgtxt[@]}" || @@ -236,11 +236,11 @@ if test "$ls" -o $# -le $(echo "$flags" | wc -w); then # TODO listing sometimes doubles as exa prints partial listings while working timeout .6s sh -c " if test '$tree' - then $elevate tree -a --dirsfirst --du -h -C -L 3 $flags $(printf "'%s' " "${ls[@]:-.}") + then $elevate tree -a --dirsfirst --du -h -C -L 3 $flags -- $(printf "'%s' " "${ls[@]:-.}") elif which exa 2>/dev/null >&2 - then $elevate exa --icons --color=always --long --group --classify --all --all --sort=modified --reverse $flags $(printf "'%s' " "${ls[@]:-.}") - else $elevate ls -l $(test $# -gt ${#ls[@]} && echo '-d') --color=always --human-readable --si --group-directories-first --file-type --dereference-command-line-symlink-to-dir --all $flags $(printf "'%s' " "${ls[@]:-.}") + then $elevate exa --icons --color=always --long --group --classify --all --all --sort=modified --reverse $flags -- $(printf "'%s' " "${ls[@]:-.}") + else $elevate ls -l $(test $# -gt ${#ls[@]} && echo '-d') --color=always --human-readable --si --group-directories-first --file-type --dereference-command-line-symlink-to-dir --all $flags -- $(printf "'%s' " "${ls[@]:-.}") fi - " || $elevate ls $(test $# -gt ${#ls[@]} && echo "-d") --color=always --human-readable --si --dereference-command-line --all --sort=none $flags "${ls[@]:-.}" + " || $elevate ls $(test $# -gt ${#ls[@]} && echo "-d") --color=always --human-readable --si --dereference-command-line --all --sort=none $flags -- "${ls[@]:-.}" } | $pager --quit-if-one-screen fi diff --git a/.local/bin/scripts/clean b/.local/bin/scripts/clean index abfe8a3..6dc9fb9 100755 --- a/.local/bin/scripts/clean +++ b/.local/bin/scripts/clean @@ -6,7 +6,7 @@ typeset -A _clean_map _clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp [l]=/var/log [v]=/var/cache) # TODO .mix - outdated version in socha _clean_home=(.ant .autopsy .bundle .cache .cargo .cpanm .docker .electron .electron-gyp .gradle .gradle-kotlin-dsl .hex .java .kscript .konan .m2 .nix-defexpr .node-gyp .nv .openjfx .parallel .stack .surf .texlive - .yarn .node_modules .npm .pnpm-store + .yarn .node_modules .npm .pnpm-store luametatex-cache luatex-cache .lesshst .python_history .rubberband.wisdom.d .yarnrc) diff --git a/.local/bin/scripts/downloads b/.local/bin/scripts/downloads new file mode 100755 index 0000000..e014b50 --- /dev/null +++ b/.local/bin/scripts/downloads @@ -0,0 +1,8 @@ +#!/bin/sh -e +# Move common files into their place from the downloads folder. +dow=$DATA/5-*/download +rmlint --rank-by=l -o pretty -o sh:/tmp/dow.sh *.* +printf "Enter to confirm, any text to skip. " +read -r answer +test -n "$answer" || /tmp/dow.sh -d +mv -v -- $dow/*.mp3 $dow/*.flac $dow/*.wav $MUSIC/ diff --git a/.local/bin/scripts/game b/.local/bin/scripts/game index 3742a15..7bec1c5 100755 --- a/.local/bin/scripts/game +++ b/.local/bin/scripts/game @@ -1,4 +1,4 @@ #!/bin/sh +# Start Gaming Tools steam >/dev/null 2>&1 & discord >/dev/null 2>&1 & - diff --git a/.local/bin/scripts/gamedeveloperstudio b/.local/bin/scripts/gamedeveloperstudio new file mode 100755 index 0000000..2acb096 --- /dev/null +++ b/.local/bin/scripts/gamedeveloperstudio @@ -0,0 +1,6 @@ +#!/bin/sh +# Order images downloaded from gamedeveloperstudio into software-challenge assets +cd $DATA/1*/software-challenge/assets/illustrations +mv -v ${@:-$DATA/5*/download/*-*.zip} . +ex *.zip +find -name 'info_about_*' -name thankyou.png -delete diff --git a/.local/bin/scripts/git-fuzz b/.local/bin/scripts/git-fuzz index 5a8761d..293efb3 100755 --- a/.local/bin/scripts/git-fuzz +++ b/.local/bin/scripts/git-fuzz @@ -12,7 +12,7 @@ fzfpipe() { # Take nul-separated input from git-status short/porcelain # and return a newline-separated list of selected files cut -z -c2- | - git fzf-diff --read0 -d' ' --nth=2.. --bind="alt-enter:execute($EDITOR '$(git rev-parse --show-toplevel)/{2..}')" \ + git fzf-diff --read0 -d' ' --nth=2.. --bind="alt-enter:execute($EDITOR '$(git rev-parse --show-toplevel)/{2..}'),alt-d:execute(git restore --worktree --staged '$(git rev-parse --show-toplevel)/{2..}')" \ --preview="test {1} != \? && git diff --color HEAD --unified=4 -- {2..} | $(git config interactive.diffFilter | grep . || echo $PAGER) || find {2..} -type f | xargs -I% diff --recursive --color=always -u /dev/null %" | cut -c3- } diff --git a/.local/bin/scripts/help b/.local/bin/scripts/help index ce29384..3083973 100755 --- a/.local/bin/scripts/help +++ b/.local/bin/scripts/help @@ -26,9 +26,8 @@ showinfo() { cmd="$1" case "$cmd" in # TODO extract help in standard format from scripts - (fwupdmgr|hunt|rdoc|gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker|jrnl|difft|wiked-diff|qpdf) unbuffer "$@" --help | sed 's|^[^ ].*:|\0|' | $paginate;; - (caddy|stretchly|go|fossil|flutter) test "$cmd" = "fossil" -a $# -eq 1 && repo="$(locate -b -l 1 "fossil*.fossil")" && fossil ui "$repo" && exit - # TODO view fossil ui in terminal + (fwupdmgr|hunt|rdoc|gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker|jrnl|difft|wiked-diff|qpdf|ninja) unbuffer "$@" --help | sed 's|^[^ ].*:|\0|' | $paginate;; + (caddy|stretchly|go|flutter) shift "$cmd" help "$@" | $paginate;; # Non-standard help flags @@ -39,6 +38,12 @@ case "$cmd" in (vlc) shift && unbuffer vlc --full-help "$@" | $paginate;; (kdeconnect*) shift && kdeconnect-cli --help-all "$@" | $paginate;; # Show manpage with tweaks + (fossil) + # TODO view fossil ui in terminal + if test $# -eq 1 && repo="$(locate -b -l 1 "fossil*.fossil")" + then fossil ui --page=doc/trunk/www/permutedindex.html "$repo" + else shift; fossil help "$@" + fi;; (pandoc) man pandoc; highlight "Extensions" && pandoc --list-extensions | paste -s -d' ';; (swaymsg) test $# -gt 1 && shift && man sway "$@" || man swaymsg;; (swaymsg-*) man sway "${1#swaymsg-}";; diff --git a/.local/bin/scripts/mpdr b/.local/bin/scripts/mpdr new file mode 100755 index 0000000..cefaebd --- /dev/null +++ b/.local/bin/scripts/mpdr @@ -0,0 +1,7 @@ +#!/bin/sh -e +# Reload mpd with appropriate config +yadm alt +cd $XDG_CONFIG_HOME/mpd +mv *template .. +mv ../*template . +systemctl --user restart mpd diff --git a/.local/bin/scripts/mvconfl b/.local/bin/scripts/mvconfl new file mode 100755 index 0000000..669ac53 --- /dev/null +++ b/.local/bin/scripts/mvconfl @@ -0,0 +1,9 @@ +#!/bin/bash +# Move all given files to a syncthing-like conflict file name based on the last argument +for last; do true; done +i=1 +while test $i -lt $# +do file=${!i} + mv -iv $file $last.sync-conflict-$(stat -c %y $file | tr -d ':-' | cut -c-25 | tr ' .' '-') + i=$((i+1)) +done diff --git a/.local/bin/scripts/quickref b/.local/bin/scripts/quickref index dcbc3bf..d6c92f9 100755 --- a/.local/bin/scripts/quickref +++ b/.local/bin/scripts/quickref @@ -14,6 +14,6 @@ Examples: - ${VAR##*/} :: retain the basename - ${VAR%.*} :: remove extension - [[https://unix.stackexchange.com/a/486694][argument from end of list]] :: - : eval x=\$$(($#-1)) + : eval last=\$$(($#-1)) (uses arithmetic substitution, a non-POSIX feature) EOF diff --git a/.local/bin/scripts/save b/.local/bin/scripts/save index 647a800..05a1ca5 100755 --- a/.local/bin/scripts/save +++ b/.local/bin/scripts/save @@ -1,3 +1,4 @@ #!/bin/sh -e -sleep "$@" +# Put system to sleep after specified number of seconds +$(which timer || sleep) "${@:-10}" systemctl suspend diff --git a/.local/bin/scripts/sy b/.local/bin/scripts/sy index bde8a57..7d96bc2 100755 --- a/.local/bin/scripts/sy +++ b/.local/bin/scripts/sy @@ -13,5 +13,5 @@ case "$1" in (init) sudo -E sysyadm init -b main -w /;; (*) sudo -E sysyadm "$@";; esac +#sudo chmod +rw /tmp/git -R 2>/dev/null sudo chown -R $USER /etc/yadm -sudo chmod ugo+rw /tmp/git -R 2>/dev/null diff --git a/.local/bin/scripts/topng b/.local/bin/scripts/topng index 50a26da..cd62eb4 100755 --- a/.local/bin/scripts/topng +++ b/.local/bin/scripts/topng @@ -1,2 +1,4 @@ #!/bin/sh -convert -background white -density 500 "$@" "$1.png" +# Convert given file to PNG +pdftoppm -png "$@" >"$1.png" || + convert -background white -alpha off -density 500 "$@" "$1.png" diff --git a/.local/bin/scripts/xdg-mime-file b/.local/bin/scripts/xdg-mime-file index ea859fd..6310049 100755 --- a/.local/bin/scripts/xdg-mime-file +++ b/.local/bin/scripts/xdg-mime-file @@ -1,11 +1,12 @@ #!/bin/sh -e # Use xdg-mime with a file's mime type # ARGS: file [application] -xdg-mime query default "$(xdg-mime query filetype "$1")" +type="$(xdg-mime query filetype "$1")" +xdg-mime query default "$type" if test $# -gt 1; then - desktop="$(find /usr/share/applications $XDG_DATA_HOME/applications | fzf -0 -1 --query="$2")" && - xdg-mime default "$desktop" "$(xdg-mime query filetype "$1")" && + desktop="$(find /usr/share/applications $XDG_DATA_HOME/applications | fzf -0 -1 --query="$2" --preview 'bat --color=always --style=numbers --line-range :200 {}' | xargs -r basename)" && + xdg-mime default "$desktop" "$type" && echo -n "Updated to: " && - xdg-mime query default "$(xdg-mime query filetype "$1")" + xdg-mime query default "$type" fi # || echo "Cannot find application $2 in /usr/share/applications!" diff --git a/.zshenv b/.zshenv index e6db9f4..09621e8 100644 --- a/.zshenv +++ b/.zshenv @@ -44,7 +44,7 @@ export KREW_ROOT="$XDG_DATA_HOME"/krew export CARGO_HOME="$XDG_STATE_HOME"/cargo export RUSTUP_HOME="$XDG_STATE_HOME"/rustup -export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME"/npm/npmrc +export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME"/npm/npmrc export NVM_DIR="$XDG_DATA_HOME"/nvm export N_PREFIX="$XDG_STATE_HOME"/n @@ -146,10 +146,12 @@ $($_fzf_latest && echo '--preview-window=60%,border-left --marker=o')" FD_BASE="fd --hidden --color=always --no-ignore-vcs" export FZF_DEFAULT_COMMAND="$FD_BASE --type file" export FZF_CTRL_T_COMMAND="$FD_BASE -d 7" -## ctest +## cplusplus - ctest, cmake, ninja +SPARE_CORES=$(expr $(lscpu --extended | awk '{print $7}' | sort | uniq -c | head -1 | awk '{print $1}') \* 4 / 5) +export CMAKE_BUILD_PARALLEL_LEVEL=${SPARE_CORES} +export CTEST_PARALLEL_LEVEL=${SPARE_CORES} export CTEST_PROGRESS_OUTPUT=1 export CTEST_OUTPUT_ON_FAILURE=1 -export CTEST_PARALLEL_LEVEL=3 # TODO move to proper place - is also called when firenvim starts #autolight