bin: various adjustments, add browser html piping and wiked-diff

This commit is contained in:
xeruf 2022-08-28 22:36:34 +02:00
parent c9193ef1d7
commit 98f8c8a33c
6 changed files with 49 additions and 20 deletions

25
.local/bin/scripts/browser Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh -e
#
# Usage: browser
# pipe html to a browser
# e.g.
# $ echo '<h1>hi mom!</h1>' | browser
# $ ron -5 man/rip.5.ron | browser
if [ -t 0 ]; then
if [ -n "$1" ]; then
open $1
else
cat <<usage
Usage: browser
pipe html to a browser
$ echo '<h1>hi mom!</h1>' | browser
$ ron -5 man/rip.5.ron | browser
usage
fi
else
f="/tmp/browser.$RANDOM.html"
cat /dev/stdin > $f
xdg-open $f
fi

View File

@ -1,3 +1,4 @@
#!/bin/sh
# Find and remove sizeable files
find -size +${1:-50}M -exec rm -vi {} +
case $1 in ([0-9]|[0-9][0-9]) threshold=$1; shift;; esac
find -size +${threshold:-50}M -exec rm -vi "$@" {} +

View File

@ -4,5 +4,5 @@
if file --brief --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") --report-identical-files --label="$1" --label="$2" <(ff "$1") <(ff "$2")
else diff-color --report-identical-files "$@"
else wiked-diff "$@" # diff-color --report-identical-files "$@"
fi | less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen

View File

@ -24,12 +24,12 @@ case "$command" in
git add -f .SRCINFO
git commit -v "$@";;
(push)
updpkgsums
grep -q SKIP PKGBUILD || updpkgsums
git add -f *.install 2>/dev/null || true
git aur commit -a "$@"
git push;;
(clean)
find "$aurdir" -mindepth 2 -maxdepth 2 \( -iname "*.pkg.tar.*" -o -type d -not -name ".*" \) \
find "$aurdir" -mindepth 2 -maxdepth 2 \( -iname "*.pkg.tar.*" -o -iname "*.zip" -o -type d -not -name ".*" \) \
-print -exec sudo rm -rI {} +;;
(*) echo "Unknown command!"; exit 3;;
esac

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/sh -e
# open info-page, man-page or command help
# depends: unbuffer
# optdepends: highlight(dotfiles)
@ -17,25 +17,27 @@ showinfo() {
cmd="$1"
case "$cmd" in
(gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker|jrnl|difft|wiked-diff) unbuffer "$@" --help | $paginate;;
(caddy|stretchly|go|fossil) test "$cmd" = "fossil" -a $# -eq 1 && repo="$(locate -b -l 1 "fossil*.fossil")" && fossil ui "$repo" && exit
# TODO view fossil ui in terminal
shift
"$cmd" help "$@" | $paginate;;
# Non-standard help flags
(doom) "$@" --help;;
(mpw) "$@" -h 2>&1 | $paginate;;
(plantuml) unbuffer "$@" -help | $paginate;;
(rails) { "$@" -H && "$@" --help; } | $paginate;;
(vlc) shift && unbuffer vlc --full-help "$@" | $paginate;;
(kdeconnect*) shift && kdeconnect-cli --help-all "$@" | $paginate;;
# Show manpage with tweaks
(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-}";;
(zsh|zmv) # https://unix.stackexchange.com/questions/19290/zmv-for-zsh-dry-runs-and-man-pages
for last; do true; done
# need to install zsh-doc package for info pages
showinfo zsh $(test "$last" != zsh && echo "$last") ||
LESS="$LESS +/^ *$last *\\[" man zshall;;
(gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker) unbuffer "$@" --help | $paginate;;
(caddy|stretchly|go|fossil) test "$cmd" = "fossil" -a $# -eq 1 && repo="$(locate -b -l 1 "fossil*.fossil")" && fossil ui "$repo" && exit
# TODO view fossil ui in terminal
shift
"$cmd" help "$@" | $paginate;;
(doom) "$@" --help;;
(mpw) "$@" -h 2>&1 | $paginate;;
(rails) { "$@" -H && "$@" --help; } | $paginate;;
(plantuml) unbuffer "$@" -help | $paginate;;
(vlc) shift && unbuffer vlc --full-help "$@" | $paginate;;
(kdeconnect*) shift && kdeconnect-cli --help-all "$@" | $paginate;;
(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-}";;
(*) showinfo "$@" || man "$@"
return=$?
if test $return -gt 0 && which "$cmd" >/dev/null

View File

@ -1,8 +1,9 @@
#!/bin/sh -e
# Use xdg-mime with a file's mime type
# ARGS: file [application]
xdg-mime query default "$(xdg-mime query filetype "$1")"
if test $# -gt 1; then
desktop="$(find /usr/share/applications -name "*$2*" | fzf -0 -1)" &&
desktop="$(find /usr/share/applications $XDG_DATA_HOME/applications -name "*$2*" | fzf -0 -1)" &&
xdg-mime default "$desktop" "$(xdg-mime query filetype "$1")" &&
echo -n "Updated to: " &&
xdg-mime query default "$(xdg-mime query filetype "$1")"