Adds / tweaks a bunch of scripts

This commit is contained in:
Jonathan Hodgson 2024-02-18 19:30:08 +00:00
parent 887f479d1f
commit 285165913d
13 changed files with 112 additions and 30 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
shopt -s nullglob
let playlist_duration_ms=0
for song_file in *.{mp3,ogg,m4a,flac,wav}; do
for song_file in */*.{mp3,ogg,m4a,flac,wav}; do
playlist_duration_ms=$(expr $playlist_duration_ms + $(mediainfo --Inform="Audio;%Duration%" "$song_file"))
done
shopt -u nullglob

View file

@ -12,18 +12,17 @@
# config.h files: (For suckless utils) recompiles and installs program.
# all others: run `sent` to show a presentation
echo "$1"
file=$(readlink -f "$1")
dir=$(dirname "$file")
file="$(readlink -f "$1")"
dir="$(dirname "$file")"
base="${file%.*}"
shebang=$(sed -n 1p "$file")
shebang="$(sed -n 1p "$file")"
cd "$dir" || exit
textype() { \
command="pdflatex"
( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex"
$command --output-directory="$dir" "$file"
command="latexmk -pdf"
( sed 5q "$file" | grep -i -q 'xelatex' ) && command="latexmk -pdfxe"
$command -output-directory="$dir" "$file"
#grep -i addbibresource "$file" >/dev/null &&
#biber --input-directory "$dir" "$base" &&
#$command --output-directory="$dir" "$base" &&
@ -36,7 +35,7 @@ mdtype(){ \
case "$command" in
"fplreport") pandoc "$file" --metadata-file="$HOME/.pandoc/defaults.yaml" --template fellowship.latex --pdf-engine=xelatex -o "${base}.pdf" ;;
"letter") pandoc "$file" --metadata-file="$HOME/.pandoc/defaults.yaml" --template template-letter.tex -o "${base}.pdf" ;;
*) pandoc "$file" -f markdown+pipe_tables --metadata-file="$HOME/.pandoc/defaults.yaml" -o "$base".pdf ;;
*) pandoc "$file" -f markdown+pipe_tables --metadata-file="$HOME/.pandoc/defaults.yaml" -o "$base".pdf ;;
esac
}
@ -60,7 +59,7 @@ case "$file" in
*\.c) cc "$file" -o "$base" && "$base" ;;
*\.py) python "$file" ;;
*\.js) cat "$file" | minify --js > "${base}.min.js" ;;
*\.less) lessc --clean-css "$file" "${base}.min.css" ;;
*\.less) lessc --clean-css -x "$file" "${base}.min.css" ;;
#*\.less) lessc "$file" "${base}.css" ;;
#*\.go) go run "$file" ;;
#*) shebangtest ;;

View file

@ -31,7 +31,7 @@ function type_password(){
# Then revert back to colemak
setxkbmap -layout gb,gb -variant "colemak," -option grp:shifts_toggle
xset r rate 200 70
xinput --list | grep -Ei 'ErgoDox EZ\s+id' | grep -oE 'id=[0-9]+' | cut -d'=' -f2 | xargs -r setxkbmap -layout gb -device
xinput --list | grep -Ei 'ErgoDox EZ Glow\s+id' | grep -oE 'id=[0-9]+' | cut -d'=' -f2 | xargs -r setxkbmap -layout gb -device
}
function copy_password(){
local password="$1"

View file

@ -33,8 +33,7 @@ hostname="$(hostname)"
if isPhone; then
selection="$(echo -e "$shutdown\n$reboot\n$lock\n$logout" | selectcommand)"
else
notify-send "Not phone"
selection="$(echo -e "$shutdown\n$reboot\n$lock\n$logout\n$suspend" | selectcommand)"
selection="$(echo -e "$lock\n$shutdown\n$reboot\n$logout\n$suspend" | selectcommand)"
fi
sleep .2

View file

@ -1,7 +1,7 @@
#!/bin/bash
rm /tmp/screen.png
scrot -z /tmp/screen.png
maim /tmp/screen.png
convert /tmp/screen.png -scale 10% -scale 1000% /tmp/screen.png
if [[ -f $HOME/.config/screen-lock.png ]]

View file

@ -1,9 +0,0 @@
#!/usr/bin/env bash
stdin="$(cat -)"
escaped="$(echo "$stdin" | sed 's/"/\\"/g')"
query="$(echo "" | fzf --preview-window=up:99% --print-query \
--preview "echo \"$escaped\" | jq -C {q}" | head -n 1)"
echo "$stdin" | jq "$query"

View file

@ -18,6 +18,9 @@ case "$url" in
sxiv "$tmp"
rm "$tmp"
;;
*.mp3|*.wma)
mpv "$url"
;;
*"//xkcd.com/"*) xkcd "$url"; exit 0 ;;
"mailto:"*) neomutt "$url"; exit 0 ;;
*) $browser "$url"; exit 0 ;;

View file

@ -2,11 +2,19 @@
# opout: "open output": A general handler for opening a file's intended output.
# I find this useful especially running from vim.
name="$1"
basename="${1%.*}"
case "$1" in
/tmp/neomutt*|*.tex|*.latex|*.md|*.rmd|*.ms|*.me|*.mom) setsid "$READER" "$basename".pdf >/dev/null 2>&1 & ;;
case "$name" in
/tmp/neomutt*|*.tex|*.latex|*.md|*.rmd|*.ms|*.me|*.mom)
if [ -f "$name".pdf ]; then
setsid "$READER" "$name".pdf >/dev/null 2>&1 &
elif [ -f "$basename".pdf ]; then
setsid "$READER" "$basename".pdf >/dev/null 2>&1 &
fi
;;
*.html) setsid "surf" "$basename".html >/dev/null 2>&1 & ;;
*.sent) setsid sent "$1" >/dev/null 2>&1 & ;;
*.scad) setsid openscad $1 & ;;
*.jpg|*.jpeg|*.png|*.gif) setsid sxiv "$1" > /dev/null 2>&1 & ;;
esac

View file

@ -7,7 +7,7 @@ externalScreen="$(xrandr | grep -Eo '^.* connected' | grep -v "$laptopScreen" |
externalResolution="$(xrandr | grep -A 1 "^$externalScreen" | sed -n 2p | awk '{print $1}')"
pkill compton
echo xrandr --output "$laptopScreen" --primary --mode "$laptopResolution" --pos 0x0 --rotate normal --output "$externalScreen" --mode "$externalResolution" --pos "${laptopResolution%x*}x0" --rotate normal
xrandr --output "$laptopScreen" --primary --mode "$laptopResolution" --pos 0x0 --rotate normal --output "$externalScreen" --mode "$externalResolution" --pos "${laptopResolution%x*}x0" --rotate normal
/usr/bin/compton --config "$HOME/.config/picom/picom.conf" & disown
# xrandr --output "$laptopScreen" --primary --mode 1920x1080 --pos 0x0 --rotate normal --output HDMI-2 --mode 1920x1080 --pos 1920x0 --rotate normal

View file

@ -47,6 +47,16 @@ case "$1" in
maim -s -c 0.41,0.62,0.42,0.2 -l -u "$file"
fi
;;
"monitor")
if [ -n "$WAYLAND_DISPLAY" ]; then
notify-send "No idea"
else
mousex="$(xdotool getmouselocation | awk -F "[: ]" '{print $2}')"
mousey="$(xdotool getmouselocation | awk -F "[: ]" '{print $4}')"
monitors="$(xrandr | grep -o '[0-9]*x[0-9]*[+-][0-9]*[+-][0-9]*')"
fi
;;
*)
if [ -n "$WAYLAND_DISPLAY" ]; then
grim "$file"

67
bin/.bin/sshportforward Executable file
View file

@ -0,0 +1,67 @@
#!/usr/bin/env bash
choice(){
local prompt=${1:-"Please make a selection"}
local choices="$(cat)"
local x=1
local selection
echo "$choices" | while read line; do
echo "$x: $line" | column -t -s $'\t' > /dev/tty
x=$((x+1))
done
echo -n "$prompt " > /dev/tty
read selection < /dev/tty
echo "$choices" | sed -n "$selection p" | cut -d $'\t' -f 1
}
print_help(){
echo "$0 This helps with generating ssh tunnels"
echo " -h||--help show this help"
exit 0
}
dryrun="false"
while [[ $1 = -?* ]]; do
case $1 in
-h|--help) print_help >&2 ;;
*) echo "Unknown option $1"; print_help >&2 ;;
esac
shift
done
forwardtype="$(
(
echo -e "local\tAccess on local machine something that is accessible on remote"
echo -e "remote\tAccess on remote machine something that is accessible on local"
echo -e "dynamic\tSimilar to local but creates a socks proxy"
) | choice "Forward Type:" )"
case "$forwardtype" in
"local")
echo "How would you access the resource if on the remote machine?"
echo "e.g. localhost:8834 if nessus is hosted on the remote machine"
echo -n "> "
read remote < /dev/tty
echo "Which local port would you like to listen on?"
echo -n "> "
read localport < /dev/tty
echo "ssh -L ${localport}:${remote} <server>"
;;
"remote")
echo "How would you access the resource if on the local machine?"
echo "e.g. internal-intranet:443 if there was an internal resource you wanted to get access to"
echo -n "> "
read localresource < /dev/tty
echo "Which remote port would you like to listen on the remote server (that you're sshing into)?"
echo -n "> "
read remoteport < /dev/tty
echo "ssh -R ${remoteport}:${localresource} <server>"
;;
"dynamic")
echo "Which local port would you like to listen on?"
echo -n "> "
read localport < /dev/tty
echo "ssh -D ${localport} <server>"
;;
esac

View file

@ -414,6 +414,8 @@ attacks (XSS).\n\n"
while read source; do
sourcemessage=''
case "$source" in
"'none'")
;;
"'self'")
sourcemessage+="This is normally fine \
although care should be taken if the site being tested has upload functionality"