bin: all sorts of convenience fixes
This commit is contained in:
parent
130790b92e
commit
1637508a45
|
@ -12,25 +12,19 @@
|
|||
# - text files are displayed through bat
|
||||
# Automatically requests elevation through sudo when needed
|
||||
|
||||
set -o pipefail
|
||||
test "$1" = "-v" &&
|
||||
set -eo xtrace &&
|
||||
shift
|
||||
|
||||
inspect=false
|
||||
test "$1" = "-i" &&
|
||||
inspect=true &&
|
||||
shift
|
||||
|
||||
set -o pipefail
|
||||
for last; do true; done
|
||||
last="${last:-.}"
|
||||
|
||||
checkperm() {
|
||||
checkaccess -r "$@" || elevate=sudo
|
||||
mime="$(test -n "$shifted" || $elevate file --dereference --mime "$@")"
|
||||
}
|
||||
checkperm "$last"
|
||||
|
||||
fileinfo() {
|
||||
tput setaf 6
|
||||
for arg
|
||||
|
@ -106,7 +100,8 @@ done
|
|||
|
||||
if test "$timg"; then
|
||||
$inspect || $elevate timg $(test "$timga" && echo "-V") --rotate=exif -g $(tput cols)x$(expr $(tput lines) / 2) \
|
||||
$(test $# -gt 1 && echo "-t0.2 --center --title --grid=$(expr $(tput cols) / \( 30 - $# \& $# \< 20 \| 10 \))x2") \
|
||||
$(test $# -gt 1 && grid=$(expr $(tput cols) / \( 30 - $# \& $# \< 20 \| 10 \)) &&
|
||||
echo "-t0.2 --center --title --grid=$((grid*3 < $# ? $#/3 + 1 : grid < $# ? grid : $#))x2") \
|
||||
"${timg[@]}" "${timga[@]}" 2>/dev/null
|
||||
if $inspect || test $# -lt 15; then
|
||||
tput setaf 6
|
||||
|
@ -128,6 +123,7 @@ if test "$bat" -o "$batl"; then
|
|||
fileinfo "${bat[@]}"
|
||||
fi
|
||||
|
||||
if test "$ls"; then
|
||||
$elevate ls -l $(test $# -gt ${#ls[@]} && echo "-d") --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "${ls[@]}" | less -RF
|
||||
if test "$ls" -o $# -eq 0; then
|
||||
checkperm .
|
||||
$elevate ls -l $(test $# -gt ${#ls[@]} && echo "-d") --color=always --human-readable --si --group-directories-first --file-type --dereference-command-line --all "${ls[@]:-.}" | less -RF
|
||||
fi
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#!/bin/sh
|
||||
# Edit a file with appropriate rights, creating parent directories if necessary
|
||||
test ! -f "$1" && ( mkdir -p $(dirname "$1") || sudo mkdir -p $(dirname "$1") )
|
||||
echo "Editing $1..."
|
||||
echo "Editing $@..."
|
||||
if test -w "$1" || (test ! -f "$1" && test -w $(dirname "$1"))
|
||||
then $EDITOR "$1"
|
||||
else sudoedit "$1"
|
||||
then $EDITOR "$@"
|
||||
else sudoedit "$@"
|
||||
fi
|
||||
|
|
|
@ -8,9 +8,10 @@ case "$1" in
|
|||
(git:*) echo "$1" ;;
|
||||
(*) host=$1
|
||||
case $1 in
|
||||
(socha) user=software-challenge; host=git@github.com;;
|
||||
(hub) host=git@github.com;;
|
||||
(lab) host=git@gitlab.com;;
|
||||
(*) host=$1;;
|
||||
esac
|
||||
echo "${host:-git.jfischer.org}:${3:-$(git config user.name)}/${2:-$(basename $PWD)}.git" ;;
|
||||
echo "${host:-git.jfischer.org}:${3:-${user:-$(git config user.name)}}/${2:-$(basename $PWD)}.git" ;;
|
||||
esac
|
||||
|
|
|
@ -10,10 +10,11 @@ case $1 in
|
|||
LESS="$LESS +/^ *$last *\\[" man zshall;;
|
||||
(vlc) unbuffer vlc --full-help "${@:2}" | $paginate;;
|
||||
(gh|chordpro|bat) unbuffer "$@" --help | $paginate;;
|
||||
(plantuml) unbuffer "$@" -help | $paginate;;
|
||||
(caddy|stretchly|go) "$1" help "${@:2}" | $paginate;;
|
||||
(*) man "$@" ||
|
||||
{ info "$1" -w | grep -v "manpages" && pinfo "$@"; } ||
|
||||
if which "$1" >/dev/null; then "$@" --help || "$@" -help 2>&1 | $paginate; fi;;
|
||||
if which "$1" >/dev/null; then "$@" --help; "$@" -help 2>&1 | $paginate; fi;;
|
||||
esac
|
||||
docs="/usr/share/doc/$1"
|
||||
if test -d "$docs"; then
|
||||
|
|
|
@ -28,9 +28,9 @@ case "$arg" in
|
|||
esac
|
||||
shift $(expr 2 \& $# \> 1 \| 1)
|
||||
#uid=$(id --user),gid=$(id --group), \
|
||||
mountpoint "$mountpoint" >/dev/null 2>&1 ||
|
||||
{ mp="/run/media/$USER/$arg" && test -e "$mp" && mountpoint="$mp"; } ||
|
||||
if ! mountpoint "$mountpoint" 2>/dev/null
|
||||
then mp="/run/media/$USER/$arg" && test -e "$mp" && mountpoint="$mp"
|
||||
sudo mount -vo users,X-mount.mkdir,noatime $partition $mountpoint "$@"
|
||||
echo "Mounted at $mountpoint"
|
||||
fi
|
||||
cd $mountpoint
|
||||
exec $SHELL
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
#!/bin/sh
|
||||
# Lossy image compression using ImageMagick
|
||||
# Tries to eliminate artifacts
|
||||
while true
|
||||
do case $1 in
|
||||
(-o) out="$2"; shift 2;;
|
||||
(-q) quality="$2"; shift 2;;
|
||||
(*) break;;
|
||||
esac
|
||||
do case $1 in
|
||||
(-o) out="$2"; shift 2;;
|
||||
(-q) quality="$2"; shift 2;;
|
||||
(*) break;;
|
||||
esac
|
||||
done
|
||||
out="${out:-$1-shrinked.jpg}"
|
||||
test $# -eq 0 && echo "Usage: $0 [-q quality (default 85)] [-o outfile] <images...>" && exit 1
|
||||
magick "$@" -strip -interlace Plane -define jpeg:dct-method=float -sampling-factor 4:2:0 -gaussian-blur 0.05 -quality "${quality:-85}" "$out"
|
||||
|
||||
magick "$@" -auto-orient -strip -interlace Plane -define jpeg:dct-method=float -sampling-factor 4:2:0 -gaussian-blur 0.05 \
|
||||
-quality "${quality:-85}" "$out"
|
||||
printf "Shrinked $1(%s) to $out(%s) - reduced to %s%%\n" \
|
||||
$(stat --format "%s" IMG_20211124_115930.jpg IMG_20211124_115930.jpg-shrinked.jpg | numfmt --to=iec-i --suffix=B) \
|
||||
$(stat --format %s "$out" "$1" | sed 'N;s|\n|*100/|' | bc)
|
||||
|
|
Loading…
Reference in New Issue