mirror of
https://github.com/tiyn/dotfiles.git
synced 2025-10-09 19:11:15 +02:00
bin structure and vifm preview
This commit is contained in:
59
.local/bin/tools/dwm/dmenumount
Executable file
59
.local/bin/tools/dwm/dmenumount
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
# Gives a dmenu prompt to mount unmounted drives.
|
||||
# If they're in /etc/fstab, they'll be mounted automatically.
|
||||
# Otherwise, you'll be prompted to give a mountpoint from already existsing directories.
|
||||
# If you input a novel directory, it will prompt you to create that directory.
|
||||
|
||||
getmount() { \
|
||||
[ -z "$chosen" ] && exit 1
|
||||
mp="$(find $1 2>/dev/null | dmenu -i -p "Type in mount point.")"
|
||||
[ "$mp" = "" ] && exit 1
|
||||
if [ ! -d "$mp" ]; then
|
||||
mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?")
|
||||
[ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp")
|
||||
fi
|
||||
}
|
||||
|
||||
mountusb() { \
|
||||
chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?" | awk '{print $1}')"
|
||||
sudo -A mount "$chosen" 2>/dev/null && notify-send "💻 USB mounting" "$chosen mounted." && exit 0
|
||||
alreadymounted=$(lsblk -nrpo "name,type,mountpoint" | awk '$2=="part"&&$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not \\( -path *%s -prune \\) \\ \n",$3}')
|
||||
getmount "/mnt /media /mount /home -maxdepth 5 -type d $alreadymounted"
|
||||
partitiontype="$(lsblk -no "fstype" "$chosen")"
|
||||
case "$partitiontype" in
|
||||
"vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;;
|
||||
*) sudo -A mount "$chosen" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";;
|
||||
esac
|
||||
notify-send "💻 USB mounting" "$chosen mounted to $mp."
|
||||
}
|
||||
|
||||
mountandroid() { \
|
||||
chosen=$(echo "$anddrives" | dmenu -i -p "Which Android device?" | cut -d : -f 1)
|
||||
getmount "$HOME -maxdepth 3 -type d"
|
||||
simple-mtpfs --device "$chosen" "$mp"
|
||||
notify-send "🤖 Android Mounting" "Android device mounted to $mp."
|
||||
}
|
||||
|
||||
asktype() { \
|
||||
case $(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?") in
|
||||
USB) mountusb ;;
|
||||
Android) mountandroid ;;
|
||||
esac
|
||||
}
|
||||
|
||||
anddrives=$(simple-mtpfs -l 2>/dev/null)
|
||||
usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | awk '$2=="part"&&$4==""{printf "%s (%s)\n",$1,$3}')"
|
||||
|
||||
if [ -z "$usbdrives" ]; then
|
||||
[ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit
|
||||
echo "Android device(s) detected."
|
||||
mountandroid
|
||||
else
|
||||
if [ -z "$anddrives" ]; then
|
||||
echo "USB drive(s) detected."
|
||||
mountusb
|
||||
else
|
||||
echo "Mountable USB drive(s) and Android device(s) detected."
|
||||
asktype
|
||||
fi
|
||||
fi
|
41
.local/bin/tools/dwm/dmenuumount
Executable file
41
.local/bin/tools/dwm/dmenuumount
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
# A dmenu prompt to unmount drives.
|
||||
# Provides you with mounted partitions, select one to unmount.
|
||||
# Drives mounted at /, /boot and /home will not be options to unmount.
|
||||
|
||||
unmountusb() {
|
||||
[ -z "$drives" ] && exit
|
||||
chosen=$(echo "$drives" | dmenu -i -p "Unmount which drive?" | awk '{print $1}')
|
||||
[ -z "$chosen" ] && exit
|
||||
sudo -A umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted."
|
||||
}
|
||||
|
||||
unmountandroid() { \
|
||||
chosen=$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")
|
||||
[ -z "$chosen" ] && exit
|
||||
sudo -A umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted."
|
||||
}
|
||||
|
||||
asktype() { \
|
||||
case "$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" in
|
||||
USB) unmountusb ;;
|
||||
Android) unmountandroid ;;
|
||||
esac
|
||||
}
|
||||
|
||||
drives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$2=="part"&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}')
|
||||
|
||||
if ! grep simple-mtpfs /etc/mtab; then
|
||||
[ -z "$drives" ] && echo "No drives to unmount." && exit
|
||||
echo "Unmountable USB drive detected."
|
||||
unmountusb
|
||||
else
|
||||
if [ -z "$drives" ]
|
||||
then
|
||||
echo "Unmountable Android device detected."
|
||||
unmountandroid
|
||||
else
|
||||
echo "Unmountable USB drive(s) and Android device(s) detected."
|
||||
asktype
|
||||
fi
|
||||
fi
|
20
.local/bin/tools/dwm/startpagesearch
Executable file
20
.local/bin/tools/dwm/startpagesearch
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Gives a dmenu prompt to search Startpage.
|
||||
# Without input, will open Startpage.com.
|
||||
# URLs will be directly handed to the browser.
|
||||
# Anything else, it search it.
|
||||
browser=${RTVBROWSER:-firefox}
|
||||
|
||||
pgrep -x dmenu && exit
|
||||
|
||||
choice=$(echo "Startpage" | dmenu -i -p "Search Startpage:") || exit 1
|
||||
|
||||
if [ "$choice" = "Startpage" ]; then
|
||||
$RTV_BROWSER "https://startpage.com"
|
||||
else
|
||||
if echo "$choice" | grep "^(http:\/\/|https:\/\/)?[a-zA-Z0-9]+\.[a-zA-Z]+(/)?.*$"; then
|
||||
$RTV_BROWSER "$choice"
|
||||
else
|
||||
$RTV_BROWSER "https://startpage.com/do/search/?q=$choice"
|
||||
fi
|
||||
fi
|
13
.local/bin/tools/nvim/opout
Executable file
13
.local/bin/tools/nvim/opout
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
# opout: "open output": A general handler for opening a file's intended output,
|
||||
# usually the pdf of a compiled document. I find this useful especially
|
||||
# running from vim.
|
||||
|
||||
basename="$(echo "$1" | sed 's/\.[^\/.]*$//')"
|
||||
|
||||
case "$1" in
|
||||
*.tex|*.m[dse]|*.[rR]md|*.mom|*.[0-9]) setsid xdg-open "$basename".pdf >/dev/null 2>&1 & ;;
|
||||
*.html) setsid "$BROWSER" "$basename".html >/dev/null 2>&1 & ;;
|
||||
*.sent) setsid sent "$1" >/dev/null 2>&1 & ;;
|
||||
esac
|
12
.local/bin/tools/statusbar/battery
Executable file
12
.local/bin/tools/statusbar/battery
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env sh
|
||||
# Give a battery name (e.g. BAT0) as an argument.
|
||||
|
||||
capacity=$(cat /sys/class/power_supply/"$1"/capacity) || exit
|
||||
time=$(acpi | awk '{ print $5 }')
|
||||
status=$(cat /sys/class/power_supply/"$1"/status)
|
||||
|
||||
[ -z $warn ] && warn=" "
|
||||
|
||||
[ "$status" = "Charging" ] && color="#ffffff"
|
||||
|
||||
printf "%s%s\n" "$(echo "$status" | sed -e "s/,//;s/Discharging/🔋/;s/Not Charging/🛑/;s/Charging/🔌/;s/Unknown/♻️/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g")" "$warn" "$(echo "$capacity" | sed -e 's/$/%/' ) "
|
3
.local/bin/tools/statusbar/clock
Executable file
3
.local/bin/tools/statusbar/clock
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
date +"%d %b %H:%M"
|
3
.local/bin/tools/statusbar/cpu
Executable file
3
.local/bin/tools/statusbar/cpu
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
sensors | awk '/Core 0/ {print $3}'
|
12
.local/bin/tools/statusbar/disk
Executable file
12
.local/bin/tools/statusbar/disk
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Status bar module for disk space
|
||||
# $1 should be drive mountpoint
|
||||
# $2 is optional icon, otherwise mountpoint will displayed
|
||||
|
||||
[ -z "$1" ] && exit
|
||||
|
||||
icon="$2"
|
||||
[ -z "$2" ] && icon="$1"
|
||||
|
||||
printf "%s: %s\n" "$icon" "$(df -h "$1" | awk ' /[0-9]/ {print $3 "/" $2}')"
|
10
.local/bin/tools/statusbar/dwmbar
Executable file
10
.local/bin/tools/statusbar/dwmbar
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
status() { \
|
||||
echo "$(memory)|$(cpu)|$(disk /)|$(volume)|$(battery BAT0)|$(internet)|$(clock)"
|
||||
}
|
||||
while :; do
|
||||
xsetroot -name "$(status | tr '\n' ' ')"
|
||||
|
||||
sleep 1m
|
||||
done
|
||||
|
7
.local/bin/tools/statusbar/internet
Executable file
7
.local/bin/tools/statusbar/internet
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
[ "$(cat /sys/class/net/w*/operstate)" = 'down' ] && wifiicon="📡"
|
||||
|
||||
[ ! -n "${wifiicon+var}" ] && wifiicon=$(grep "^\s*w" /proc/net/wireless | awk '{ print "📶", int($3 * 100 / 70) "%" }')
|
||||
|
||||
printf "%s %s\n" "$wifiicon" "$(cat /sys/class/net/e*/operstate | sed "s/down/❎/;s/up/🌐/")"
|
3
.local/bin/tools/statusbar/memory
Executable file
3
.local/bin/tools/statusbar/memory
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
free -h | awk '/^Mem:/ {print $3 "/" $2}'
|
5
.local/bin/tools/statusbar/refbar
Executable file
5
.local/bin/tools/statusbar/refbar
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Refresh the dwmbar.
|
||||
|
||||
kill "$(pstree -lp | grep -- -dwmbar\([0-9] | sed "s/.*sleep(\([0-9]\+\)).*/\1/")"
|
15
.local/bin/tools/statusbar/volume
Executable file
15
.local/bin/tools/statusbar/volume
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "$(pulsemixer --get-mute)" = "1" ] && printf "🔇\\n" && exit
|
||||
|
||||
vol=$(pulsemixer --get-volume | awk '{print $1}')
|
||||
|
||||
if [ "$vol" -gt "70" ]; then
|
||||
icon="🔊"
|
||||
elif [ "$vol" -lt "30" ]; then
|
||||
icon="🔈"
|
||||
else
|
||||
icon="🔉"
|
||||
fi
|
||||
|
||||
printf "%s %s\\n" "$vol" "$icon"
|
@@ -1,27 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
# copying tex templates
|
||||
|
||||
[ -z "$2" ] && echo "missing argument: filename (no ending)" && return 1
|
||||
|
||||
articletemp=~/gitrepos/tools/latex_templates/latex_article/article.tex
|
||||
beamertemp=~/gitrepos/tools/latex_templates/latex_beamer/beamer.tex
|
||||
exercisetemp=~/gitrepos/tools/latex_templates/latex_exercise_header/header.tex
|
||||
handouttemp=~/gitrepos/tools/latex_templates/latex_handout/handout.tex
|
||||
|
||||
case "$1" in
|
||||
a*) cp "$articletemp" $2.tex ;;
|
||||
b*) cp "$beamertemp" $2.tex ;;
|
||||
e*) cp "$exercisetemp" $2.tex ;;
|
||||
h*) cp "$handouttemp" $2.tex ;;
|
||||
*) cat << EOF
|
||||
|
||||
Allowed options
|
||||
article NAME get handout-template with given NAME
|
||||
beamer NAME get handout-template with given NAME
|
||||
exercise NAME get handout-template with given NAME
|
||||
handout NAME get handout-template with given NAME
|
||||
|
||||
All of these commands can be truncated,
|
||||
i.e. \`textemp a\` for \`textemp article`\.
|
||||
EOF
|
||||
esac
|
165
.local/bin/tools/vifm/vifmimg
Executable file
165
.local/bin/tools/vifm/vifmimg
Executable file
@@ -0,0 +1,165 @@
|
||||
#!/usr/bin/env bash
|
||||
readonly ID_PREVIEW="preview"
|
||||
|
||||
#PLAY_GIF="yes"
|
||||
# By enabling this option the GIF will be animated, by leaving it commented like it
|
||||
# is now will make the gif previews behave the same way as video previews.
|
||||
|
||||
#AUTO_REMOVE="yes"
|
||||
# By enabling this option the script will remove the preview file after it is drawn
|
||||
# and by doing so the preview will always be up-to-date with the file.
|
||||
# This however, requires more CPU and therefore affects the overall performance.
|
||||
|
||||
# The messy code below is for moving pages in pdf files in the vifm file preview by
|
||||
# utilizing the < and > keys which will be bound to `vifmimg inc` or `vifmimg dec`.
|
||||
PDF_PAGE_CONFIG="$HOME/.config/vifm/vifmimgpdfpage"
|
||||
PDF_FILE_CONFIG="$HOME/.config/vifm/vifmimgpdffile"
|
||||
PDF_PAGE=1
|
||||
PDF_FILE=""
|
||||
# Initialize the variables and required files
|
||||
[[ -f "$PDF_PAGE_CONFIG" ]] && PDF_PAGE=$(cat $PDF_PAGE_CONFIG) || touch $PDF_PAGE_CONFIG
|
||||
[[ -f "$PDF_FILE_CONFIG" ]] && PDF_FILE=$(cat $PDF_FILE_CONFIG) || touch $PDF_FILE_CONFIG
|
||||
|
||||
|
||||
# Create temporary working directory if the directory structure doesn't exist
|
||||
if [[ ! -d "/tmp$PWD/" ]]; then
|
||||
mkdir -p "/tmp$PWD/"
|
||||
fi
|
||||
|
||||
function inc() {
|
||||
VAL="$(cat $PDF_PAGE_CONFIG)"
|
||||
echo "$(expr $VAL + 1)" > $PDF_PAGE_CONFIG
|
||||
}
|
||||
|
||||
function dec() {
|
||||
VAL="$(cat $PDF_PAGE_CONFIG)"
|
||||
echo "$(expr $VAL - 1)" > $PDF_PAGE_CONFIG
|
||||
if [[ $VAL -le 0 ]]; then
|
||||
echo 0 > $PDF_PAGE_CONFIG
|
||||
fi
|
||||
}
|
||||
|
||||
function previewclear() {
|
||||
declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
function fileclean() {
|
||||
if [[ -f "/tmp$PWD/$6.png" ]]; then
|
||||
rm -f "/tmp$PWD/$6.png"
|
||||
elif [[ -d "/tmp$PWD/$6/" ]]; then
|
||||
rm -rf "/tmp$PWD/$6/"
|
||||
fi
|
||||
}
|
||||
|
||||
function preview() {
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="$PWD/$6") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
function previewvideo() {
|
||||
if [[ ! -f "/tmp$PWD/$6.png" ]]; then
|
||||
ffmpegthumbnailer -i "$PWD/$6" -o "/tmp$PWD/$6.png" -s 0 -q 10
|
||||
fi
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp$PWD/$6.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
function previewepub() {
|
||||
if [[ ! -f "/tmp$PWD/$6.png" ]]; then
|
||||
epub-thumbnailer "$6" "/tmp$PWD/$6.png" 1024
|
||||
fi
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp$PWD/$6.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
function previewaudio() {
|
||||
if [[ ! -f "/tmp${PWD}/$6.png" ]]; then
|
||||
ffmpeg -i "$6" "/tmp${PWD}/$6.png" -y &> /dev/null
|
||||
fi
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp${PWD}/$6.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
function previewgif() {
|
||||
if [[ ! -d "/tmp$PWD/$6/" ]]; then
|
||||
mkdir -p "/tmp$PWD/$6/"
|
||||
convert -coalesce "$PWD/$6" "/tmp$PWD/$6/$6.png"
|
||||
fi
|
||||
if [[ ! -z "$PLAY_GIF" ]]; then
|
||||
for frame in $(ls -1 /tmp$PWD/$6/$6*.png | sort -V); do
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="$frame") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
# Sleep between frames to make the animation smooth.
|
||||
sleep .07
|
||||
done
|
||||
else
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp$PWD/$6/$6-0.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
fi
|
||||
}
|
||||
|
||||
function previewpdf() {
|
||||
if [[ ! "$6" == "$PDF_FILE" ]]; then
|
||||
PDF_PAGE=1
|
||||
echo 1 > $PDF_PAGE_CONFIG
|
||||
rm -f "/tmp$PWD/$6.png"
|
||||
fi
|
||||
|
||||
if [[ ! "$PDF_PAGE" == "1" ]] && [[ -f "/tmp$PWD/$6.png" ]]; then
|
||||
rm -f "/tmp$PWD/$6.png"
|
||||
fi
|
||||
|
||||
if [[ ! -f "/tmp$PWD/$6.png" ]]; then
|
||||
pdftoppm -png -f $PDF_PAGE -singlefile "$6" "/tmp$PWD/$6"
|
||||
fi
|
||||
echo "$6" > $PDF_FILE_CONFIG
|
||||
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp$PWD/$6.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
|
||||
function previewmagick() {
|
||||
if [[ ! -f "/tmp$PWD/$6.png" ]]; then
|
||||
convert -thumbnail $(identify -format "%wx%h" "$6") "$PWD/$6" "/tmp$PWD/$6.png"
|
||||
fi
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp$PWD/$6.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
|
||||
|
||||
function main() {
|
||||
case "$1" in
|
||||
"inc") inc "$@" ;;
|
||||
"dec") dec "$@" ;;
|
||||
"clear") previewclear "$@" ;;
|
||||
"clean") fileclean "$@" ;;
|
||||
"draw") preview "$@" ;;
|
||||
"videopreview") previewvideo "$@" ;;
|
||||
"epubpreview") previewepub "$@" ;;
|
||||
"gifpreview") previewgif "$@" ;;
|
||||
"pdfpreview") previewpdf "$@" ;;
|
||||
"magickpreview") previewmagick "$@" ;;
|
||||
"audiopreview") previewaudio "$@" ;;
|
||||
"*") echo "Unknown command: '$@'" ;;
|
||||
esac
|
||||
}
|
||||
main "$@"
|
20
.local/bin/tools/vifm/vifmrun
Executable file
20
.local/bin/tools/vifm/vifmrun
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}"
|
||||
|
||||
if [ ! -f "/usr/bin/ueberzug" ]; then
|
||||
vifm
|
||||
exit
|
||||
fi
|
||||
|
||||
function cleanup {
|
||||
rm "$FIFO_UEBERZUG" 2>/dev/null
|
||||
pkill -P $$ 2>/dev/null
|
||||
}
|
||||
pkill -P $$ 2>/dev/null
|
||||
rm "$FIFO_UEBERZUG" 2>/dev/null
|
||||
mkfifo "$FIFO_UEBERZUG" >/dev/null
|
||||
trap cleanup EXIT 2>/dev/null
|
||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser bash 2>&1 >/dev/null &
|
||||
|
||||
vifm "$@"
|
||||
cleanup
|
Reference in New Issue
Block a user