dotfiles

My collection of dotfiles
git clone git://git.noxz.tech/dotfiles
Log | Files | Refs

commit 9277a4c962acebdfd3cabb75a25499376ea0531c
parent 974683eef8ae8bafa5f2cb7aae084ad93c5c2950
Author: Chris Noxz <chris@noxz.tech>
Date:   Mon, 30 Mar 2020 18:29:56 +0200

[bin] move global scripts to dotfiles

Diffstat:
Abin/.local/bin/mpvc | 160+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/.local/bin/mpvd | 2++
Abin/.local/bin/pkg | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mx/.config/X11/xinitrc | 4++--
4 files changed, 276 insertions(+), 2 deletions(-)

diff --git a/bin/.local/bin/mpvc b/bin/.local/bin/mpvc @@ -0,0 +1,160 @@ +#!/bin/sh + +mpvdsock="/tmp/mpvd.sock" +cmd_socat="$(command -v socat) - '$mpvdsock'" +cmd_jq="$(command -v jq)" + +print_help() { + echo "Usage: mpvc ACTION [ARGS]\n" + echo "ACTIONS:" + echo " append append file to playlist." + echo " help print this help message." + echo " load load file, and override playlist." + echo " next go to next track." + echo " prev go to previous track." + echo " seek seek (-)n seconds" + echo " toggle toogle play and pause." + echo " lower lower volume 10 units" + echo " mute toggle mute" + echo " raise raise volume 10 units" + echo " " + echo "EXTRA:" + echo " ytdl-format set ytdl-format" + echo " " + echo "ALSA:" + echo " alower alsa lower 5%" + echo " amute alsa mute" + echo " araise alsa raise 5%" +} + +send_command() { + local input="" + for var in "$@"; do + [ "$input" != "" ] && input="$input, " + input="$input\"$var\"" + done + printf '{ "command": [%s] }\n' "$input" | $cmd_socat +} + +get_path() { + local path="$(readlink -f "$@")" + if [ -f "$path" ]; then + echo "$path" + else + echo "$@" + fi +} + +notify_vol() { + case $1 in + master) + local level="$(amixer sget Master | awk -F"[][]" '/dB/ { print ($2+0) }')" + local muted="$(amixer sget Master | awk -F"[][]" '/dB/ { print ($6) }' | sed 's/off/true/')" + ;; + mpv) + local level="$(send_command "get_property" "volume" | $cmd_jq -rM '.data')" + local muted="$(send_command "get_property" "mute" | $cmd_jq -rM '.data')" + ;; + *) return;; + esac + + echo $muted > /tmp/tttt + + local marks="$((($level + 5) / 10))" + [ "$marks" -gt 10 ] && marks=10 + + local output="$1" + if [ "$muted" = "true" ]; then + local output="$output (muted)" + fi + local output="$output: [$([ "$marks" -gt 0 ] && printf "%-$((marks))s" "+" | sed 's/\ /+/g')" + local output="$output$([ "$marks" -lt 10 ] && printf "%-$((10-marks))s" " ")]" + local output="$output$(printf " %3d" "$level")%" + ztatus-notify "$output" +} + +die() { + printf "Error: %s\n" "$@" + exit 1 +} + +# check if prerequisites exist +[ -z "$cmd_socat" ] && die "could not find 'socat'" +[ -z "$cmd_jq" ] && die "could not find 'jq'" + +# check if daemonization should apply +if [ "${0##*/}" = "mpvd" ]; then + if pidof -x "$(basename -- "$0")" -o $$ >/dev/null; then + die "Another instance of mpvd is already runnig..." + fi + [ -S "$mpvdsock" ] && rm "$mpvdsock" + while true; do + mpv --idle=yes \ + --input-ipc-server="$mpvdsock" \ + --ytdl-format=best \ + --load-scripts=yes \ + 2>&1 >/tmp/mpvd.log + done + exit 0 +fi + +# check if socket exists +[ ! -S "$mpvdsock" ] && die "socket: '$mpvdsock' is missing" + +# print help if no argument was passed +if [ $# -lt 1 ]; then + print_help + exit 0 +fi + +case "$1" in + + # actions + load) + shift; send_command "loadfile" "$(get_path "$@")" ;; + append) + shift; send_command "loadfile" "$(get_path "$@")" "append" ;; + stop) + send_command "stop" ;; + toggle) + send_command "cycle" "pause" ;; + prev) + send_command "playlist-prev" ;; + next) + send_command "playlist-next" ;; + list) + send_command "get_property" "playlist" \ + | $cmd_jq -rM '.data[]|( + if .current then + "\\e[1;37mcurrent\\e[0m\\t" + else + "\\t" end + )+.filename' \ + | sed -e "s/\\\\t/\\t/g" -e "s/\\\\e/`printf "\033"`/g";; + seek) + shift; send_command "seek" "$@" ;; + mute) + send_command "cycle" "mute"; notify_vol mpv;; + raise) + send_command "add" "volume" "10"; notify_vol mpv;; + lower) + send_command "add" "volume" "-10"; notify_vol mpv;; + + # extra + ytdl-format) + shift; send_command "set" "ytdl-format" "$@" ;; + + # alsa + amute) + amixer set Master toggle; notify_vol master;; + araise) + amixer -q sset Master 5%+; notify_vol master;; + alower) + amixer -q sset Master 5%-; notify_vol master;; + + # default behaviour + help) + print_help ;; + *) + echo "Unknown option: $*"; print_help ;; +esac diff --git a/bin/.local/bin/mpvd b/bin/.local/bin/mpvd @@ -0,0 +1 @@ +mpvc+ \ No newline at end of file diff --git a/bin/.local/bin/pkg b/bin/.local/bin/pkg @@ -0,0 +1,112 @@ +#!/bin/sh + +print_help() { + echo "Usage: pkg ACTION|WRAPPER [PKGNAME|FILE]\n" + echo "ACTIONS:" + echo " help print this help message." + echo " install install package with PKGNAME." + echo " remove remove package with PKGNAME." + echo " search search for PKGNAME in name/description." + echo " upgrade upgrade PKGNAME or all packages." + echo " info show information for package PKGNAME." + echo " which check to which package FILE belongs." + echo " files list files contained in package PKGNAME." + echo " clean remove obsolete packages from package cache." + echo " hold hold package with PKGNAME." + echo " unhold unhold package with PKGNAME." + echo " deps list dependencies for package PKGNAME" + echo " revdeps list packages which need package PKGNAME." + echo " orphans list orphaned packages." + echo " queue list available upgrades." + echo " " + echo "WRAPPERS:" + echo " db calls xbps-pkgdb." + echo " alternatives calls xbps-alternatives." + echo " query calls xbps-query." + echo " reconfigure calls xbps-reconfigure." + echo " rindex calls xbps-rindex." +} + +update_queue_count() { + xbps-install -un | wc -l > /tmp/.xbps.queue +} + +if [ $# -lt 1 ]; then + print_help + exit 0 +fi + +case "$1" in + help) + print_help + ;; + update) + xbps-install -S + update_queue_count + ;; + install) + shift; xbps-install -S "$@" + update_queue_count + ;; + remove) + shift; xbps-remove "$@" + update_queue_count + ;; + search) + shift; xbps-query -Rs "$@" + ;; + upgrade) + shift; xbps-install -Su "$@" + update_queue_count + ;; + info) + shift; xbps-query "$@" + ;; + which) + shift; xbps-query -o "$@" + ;; + files) + shift; xbps-query -f "$@" + ;; + clean) + shift; xbps-remove -O "$@" + ;; + hold) + shift; xbps-pkgdb -m hold "$@" + ;; + unhold) + shift; xbps-pkgdb -m unhold "$@" + ;; + deps|dependencies|depends-on) + shift; xbps-query -Rx "$@" + ;; + revdeps|reverse-dependencies|required-by) + shift; xbps-query -RX "$@" + ;; + orphans) + shift; xbps-query -O "$@" + ;; + queue) + shift; xbps-install -un | column -t + ;; + db) + shift; xbps-pkgdb "$@" + ;; + alternatives) + shift; xbps-alternatives "$@" + ;; + query) + shift; xbps-query "$@" + ;; + reconfigure) + shift; xbps-reconfigure "$@" + ;; + rindex) + shift; xbps-rindex "$@" + ;; + *) + echo "Unknown option: $*" + print_help + return 0; + ;; +esac diff --git a/x/.config/X11/xinitrc b/x/.config/X11/xinitrc @@ -48,13 +48,13 @@ dwm) # start daemons [ ! $(pidof -x monitor-daemon) ] && "$HOME"/.local/bin/monitor daemon & - [ ! $(pidof -x mpvd) ] && /usr/local/bin/mpvd & + [ ! $(pidof -x mpvd) ] && "$HOME"./local/bin/mpvd & # start prerequisites [ ! $(pidof -x listen-new-mail) ] && "$HOME/.local/bin/listen-new-mail" & [ ! $(pidof -x listen-new-pkg) ] && "$HOME/.local/bin/listen-new-pkg" & [ ! $(pidof -x listen-ac-change) ] && "$HOME/.local/bin/listen-ac-change" & - [ ! $(pidof -x ztatus) ] && sh -c 'sleep .5; /usr/local/bin/ztatus -d' & + [ ! $(pidof -x ztatus) ] && sh -c 'sleep .5; /usr/local/bin/ztatus' & # start sxhkd (Simple X hotkey daemon) sxhkd &