feat: Add dmenu scripts
This commit is contained in:
21
bin/dmenuhandler
Executable file
21
bin/dmenuhandler
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Feed this script a link and it will give dmenu
|
||||||
|
# some choice programs to use to open it.
|
||||||
|
feed="${1:-$(printf "%s" | dmenu -p 'Paste URL or file path')}"
|
||||||
|
|
||||||
|
case "$(printf "Copy URL\\nsxiv\\nsetbg\\nPDF\\nbrowser\\nlynx\\nvim\\nmpv\\nmpv loop\\nmpv float\\nqueue download\\nqueue yt-dlp\\nqueue yt-dlp audio" | dmenu -i -p "Open it with?")" in
|
||||||
|
"Copy URL") echo "$feed" | xclip -selection clipboard ;;
|
||||||
|
mpv) setsid -f mpv -quiet "$feed" >/dev/null 2>&1 ;;
|
||||||
|
"mpv loop") setsid -f mpv -quiet --loop "$feed" >/dev/null 2>&1 ;;
|
||||||
|
"mpv float") setsid -f "$TERMINAL" -e mpv --geometry=+0-0 --autofit=30% --title="mpvfloat" "$feed" >/dev/null 2>&1 ;;
|
||||||
|
"queue yt-dlp") qndl "$feed" >/dev/null 2>&1 ;;
|
||||||
|
"queue yt-dlp audio") qndl "$feed" 'yt-dlp --embed-metadata -icx -f bestaudio/best' >/dev/null 2>&1 ;;
|
||||||
|
"queue download") qndl "$feed" 'curl -LO' >/dev/null 2>&1 ;;
|
||||||
|
PDF) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;;
|
||||||
|
sxiv) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;;
|
||||||
|
vim) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && setsid -f "$TERMINAL" -e "$EDITOR" "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;;
|
||||||
|
setbg) curl -L "$feed" > $XDG_CACHE_HOME/pic ; xwallpaper --zoom $XDG_CACHE_HOME/pic >/dev/null 2>&1 ;;
|
||||||
|
browser) setsid -f "$BROWSER" "$feed" >/dev/null 2>&1 ;;
|
||||||
|
lynx) lynx "$feed" >/dev/null 2>&1 ;;
|
||||||
|
esac
|
||||||
67
bin/dmenumount
Executable file
67
bin/dmenumount
Executable file
@@ -0,0 +1,67 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Gives a dmenu prompt to mount unmounted drives and Android phones. 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
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
mp="$(find $1 2>/dev/null | dmenu -i -p "Type in mount point.")" || exit 1
|
||||||
|
test -z "$mp" && exit 1
|
||||||
|
if [ ! -d "$mp" ]; then
|
||||||
|
mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") || exit 1
|
||||||
|
[ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mountusb() { \
|
||||||
|
chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?")" || exit 1
|
||||||
|
chosen="$(echo "$chosen" | 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 '$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not ( -path *%s -prune ) ",$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;;
|
||||||
|
"exfat") sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)";;
|
||||||
|
*) 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?")" || exit 1
|
||||||
|
chosen="$(echo "$chosen" | cut -d : -f 1)"
|
||||||
|
getmount "$HOME -maxdepth 3 -type d"
|
||||||
|
simple-mtpfs --device "$chosen" "$mp"
|
||||||
|
echo "OK" | dmenu -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1
|
||||||
|
simple-mtpfs --device "$chosen" "$mp"
|
||||||
|
notify-send "🤖 Android Mounting" "Android device mounted to $mp."
|
||||||
|
}
|
||||||
|
|
||||||
|
asktype() { \
|
||||||
|
choice="$(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?")" || exit 1
|
||||||
|
case $choice in
|
||||||
|
USB) mountusb ;;
|
||||||
|
Android) mountandroid ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
anddrives=$(simple-mtpfs -l 2>/dev/null)
|
||||||
|
usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom' | awk '$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
|
||||||
19
bin/dmenumountcifs
Executable file
19
bin/dmenumountcifs
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Gives a dmenu prompt to mount unmounted local NAS shares for read/write.
|
||||||
|
# Requirements - "%wheel ALL=(ALL) NOPASSWD: ALL"
|
||||||
|
#
|
||||||
|
# Browse for mDNS/DNS-SD services using the Avahi daemon...
|
||||||
|
srvname=$(avahi-browse _smb._tcp -t | awk '{print $4}' | dmenu -i -p "Which NAS?") || exit 1
|
||||||
|
notify-send "Searching for network shares..." "Please wait..."
|
||||||
|
# Choose share disk...
|
||||||
|
share=$(smbclient -L "$srvname" -N | grep Disk | awk '{print $1}' | dmenu -i -p "Mount which share?") || exit 1
|
||||||
|
# Format URL...
|
||||||
|
share2mnt=//"$srvname".local/"$share"
|
||||||
|
|
||||||
|
sharemount() {
|
||||||
|
mounted=$(mount -v | grep "$share2mnt") || ([ ! -d /mnt/"$share" ] && sudo mkdir /mnt/"$share")
|
||||||
|
[ -z "$mounted" ] && sudo mount -t cifs "$share2mnt" -o user=nobody,password="",noperm /mnt/"$share" && notify-send "Netshare $share mounted" && exit 0
|
||||||
|
notify-send "Netshare $share already mounted"; exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
sharemount
|
||||||
6
bin/dmenupass
Executable file
6
bin/dmenupass
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# This script is the SUDO_ASKPASS variable, meaning that it will be used as a
|
||||||
|
# password prompt if needed.
|
||||||
|
|
||||||
|
dmenu -fn Monospace-18 -P -p "$1" <&- && echo
|
||||||
123
bin/dmenurecord
Executable file
123
bin/dmenurecord
Executable file
@@ -0,0 +1,123 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# `$0`: Ask for recording type via dmenu
|
||||||
|
# `$0 screencast`: Record both audio and screen
|
||||||
|
# `$0 video`: Record only screen
|
||||||
|
# `$0 audio`: Record only audio
|
||||||
|
# `$0 kill`: Kill existing recording
|
||||||
|
#
|
||||||
|
# If there is already a running instance, user will be prompted to end it.
|
||||||
|
|
||||||
|
updateicon() { \
|
||||||
|
echo "$1" > /tmp/recordingicon
|
||||||
|
pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}"
|
||||||
|
}
|
||||||
|
|
||||||
|
killrecording() {
|
||||||
|
recpid="$(cat /tmp/recordingpid)"
|
||||||
|
# kill with SIGTERM, allowing finishing touches.
|
||||||
|
kill -15 "$recpid"
|
||||||
|
rm -f /tmp/recordingpid
|
||||||
|
updateicon ""
|
||||||
|
pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}"
|
||||||
|
# even after SIGTERM, ffmpeg may still run, so SIGKILL it.
|
||||||
|
sleep 3
|
||||||
|
kill -9 "$recpid"
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
screencast() { \
|
||||||
|
ffmpeg -y \
|
||||||
|
-f x11grab \
|
||||||
|
-framerate 60 \
|
||||||
|
-s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \
|
||||||
|
-i "$DISPLAY" \
|
||||||
|
-f alsa -i default \
|
||||||
|
-r 30 \
|
||||||
|
-c:v h264 -crf 0 -preset ultrafast -c:a aac \
|
||||||
|
"$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" &
|
||||||
|
echo $! > /tmp/recordingpid
|
||||||
|
updateicon "⏺️🎙️"
|
||||||
|
}
|
||||||
|
|
||||||
|
video() { ffmpeg \
|
||||||
|
-f x11grab \
|
||||||
|
-s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \
|
||||||
|
-i "$DISPLAY" \
|
||||||
|
-c:v libx264 -qp 0 -r 30 \
|
||||||
|
"$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" &
|
||||||
|
echo $! > /tmp/recordingpid
|
||||||
|
updateicon "⏺️"
|
||||||
|
}
|
||||||
|
|
||||||
|
webcamhidef() { ffmpeg \
|
||||||
|
-f v4l2 \
|
||||||
|
-i /dev/video0 \
|
||||||
|
-video_size 1920x1080 \
|
||||||
|
"$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
|
||||||
|
echo $! > /tmp/recordingpid
|
||||||
|
updateicon "🎥"
|
||||||
|
}
|
||||||
|
|
||||||
|
webcam() { ffmpeg \
|
||||||
|
-f v4l2 \
|
||||||
|
-i /dev/video0 \
|
||||||
|
-video_size 640x480 \
|
||||||
|
"$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
|
||||||
|
echo $! > /tmp/recordingpid
|
||||||
|
updateicon "🎥"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
audio() { \
|
||||||
|
ffmpeg \
|
||||||
|
-f alsa -i default \
|
||||||
|
-c:a flac \
|
||||||
|
"$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" &
|
||||||
|
echo $! > /tmp/recordingpid
|
||||||
|
updateicon "🎙️"
|
||||||
|
}
|
||||||
|
|
||||||
|
askrecording() { \
|
||||||
|
choice=$(printf "screencast\\nvideo\\nvideo selected\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:")
|
||||||
|
case "$choice" in
|
||||||
|
screencast) screencast;;
|
||||||
|
audio) audio;;
|
||||||
|
video) video;;
|
||||||
|
*selected) videoselected;;
|
||||||
|
webcam) webcam;;
|
||||||
|
"webcam (hi-def)") webcamhidef;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
asktoend() { \
|
||||||
|
response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") &&
|
||||||
|
[ "$response" = "Yes" ] && killrecording
|
||||||
|
}
|
||||||
|
|
||||||
|
videoselected()
|
||||||
|
{
|
||||||
|
slop -f "%x %y %w %h" > /tmp/slop
|
||||||
|
read -r X Y W H < /tmp/slop
|
||||||
|
rm /tmp/slop
|
||||||
|
|
||||||
|
ffmpeg \
|
||||||
|
-f x11grab \
|
||||||
|
-framerate 60 \
|
||||||
|
-video_size "$W"x"$H" \
|
||||||
|
-i :0.0+"$X,$Y" \
|
||||||
|
-c:v libx264 -qp 0 -r 30 \
|
||||||
|
"$HOME/box-$(date '+%y%m%d-%H%M-%S').mkv" &
|
||||||
|
echo $! > /tmp/recordingpid
|
||||||
|
updateicon "⏺️"
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
screencast) screencast;;
|
||||||
|
audio) audio;;
|
||||||
|
video) video;;
|
||||||
|
*selected) videoselected;;
|
||||||
|
kill) killrecording;;
|
||||||
|
*) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;;
|
||||||
|
esac
|
||||||
44
bin/dmenuumount
Executable file
44
bin/dmenuumount
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/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?")" || exit 1
|
||||||
|
chosen="$(echo "$chosen" | 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?")" || exit 1
|
||||||
|
[ -z "$chosen" ] && exit
|
||||||
|
sudo -A umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted."
|
||||||
|
}
|
||||||
|
|
||||||
|
asktype() { \
|
||||||
|
choice="$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" || exit 1
|
||||||
|
case "$choice" in
|
||||||
|
USB) unmountusb ;;
|
||||||
|
Android) unmountandroid ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
drives=$(lsblk -nrpo "name,type,size,mountpoint,label" | awk -F':' '{gsub(/ /,":")}$4!~/\/boot|\/efi|\/home$|SWAP/&&length($4)>1{printf "%s (%s) %s\n",$4,$3,$5}')
|
||||||
|
|
||||||
|
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
|
||||||
18
bin/dmenuunicode
Executable file
18
bin/dmenuunicode
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# The famous "get a menu of emojis to copy" script.
|
||||||
|
|
||||||
|
# Get user selection via dmenu from emoji file.
|
||||||
|
chosen=$(cut -d ';' -f1 ~/.local/share/larbs/emoji | dmenu -i -l 30 | sed "s/ .*//")
|
||||||
|
|
||||||
|
# Exit if none chosen.
|
||||||
|
[ -z "$chosen" ] && exit
|
||||||
|
|
||||||
|
# If you run this command with an argument, it will automatically insert the
|
||||||
|
# character. Otherwise, show a message that the emoji has been copied.
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
xdotool type "$chosen"
|
||||||
|
else
|
||||||
|
printf "$chosen" | xclip -selection clipboard
|
||||||
|
notify-send "'$chosen' copied to clipboard." &
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user