diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2021-07-06 19:02:25 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2021-07-06 19:02:25 +0100 |
commit | 325d8b4ef7a02459172d6b6a423e36d7b3cadb88 (patch) | |
tree | 8543383279142b59510e3f0e5a7920cb58bbb2bf /Scripts | |
parent | 9fa164dc1148c3bab801d636f24873efe673fc3a (diff) | |
download | dotfiles-325d8b4ef7a02459172d6b6a423e36d7b3cadb88.tar.gz dotfiles-325d8b4ef7a02459172d6b6a423e36d7b3cadb88.tar.bz2 dotfiles-325d8b4ef7a02459172d6b6a423e36d7b3cadb88.zip |
(General)~loads of commits, getting ready to port dotfiles to another machine
Diffstat (limited to 'Scripts')
-rwxr-xr-x | Scripts/.local/scripts/emacs_curl | 4 | ||||
-rwxr-xr-x | Scripts/.local/scripts/status/music | 3 | ||||
-rwxr-xr-x | Scripts/.local/scripts/status/volume | 10 | ||||
-rwxr-xr-x | Scripts/.local/scripts/umpv | 88 |
4 files changed, 102 insertions, 3 deletions
diff --git a/Scripts/.local/scripts/emacs_curl b/Scripts/.local/scripts/emacs_curl new file mode 100755 index 0000000..f92835e --- /dev/null +++ b/Scripts/.local/scripts/emacs_curl @@ -0,0 +1,4 @@ +#!/bin/sh + +x=`xclip -o` +emacsclient --socket-name=MAIN -c --alternate-editor=emacs --eval "(eww \"$x\")"; diff --git a/Scripts/.local/scripts/status/music b/Scripts/.local/scripts/status/music index b7233d9..a1e734e 100755 --- a/Scripts/.local/scripts/status/music +++ b/Scripts/.local/scripts/status/music @@ -1,3 +1,4 @@ #!/usr/bin/env bash -echo "$(playerctl --player=spotify metadata title)" +title=$(playerctl --player=spotify metadata title) +echo "${title::40}" diff --git a/Scripts/.local/scripts/status/volume b/Scripts/.local/scripts/status/volume index 87cb121..cbbafbe 100755 --- a/Scripts/.local/scripts/status/volume +++ b/Scripts/.local/scripts/status/volume @@ -1,5 +1,11 @@ #!/usr/bin/env bash sinks="$(pactl list sinks)" vol="$(echo "$sinks" | grep '[0-9]\+%' | sed "s,.* \([0-9]\+\)%.*,\1,;1q")" - -echo " $vol%" +mute="$(echo "$sinks" | grep "Mute: " | sed "s/.*Mute: //g")" +case "$mute" in + "no") + printf "";; + "yes") + printf "";; +esac +echo " $vol%" diff --git a/Scripts/.local/scripts/umpv b/Scripts/.local/scripts/umpv new file mode 100755 index 0000000..762e73a --- /dev/null +++ b/Scripts/.local/scripts/umpv @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 + +""" +This script emulates "unique application" functionality on Linux. When starting +playback with this script, it will try to reuse an already running instance of +mpv (but only if that was started with umpv). Other mpv instances (not started +by umpv) are ignored, and the script doesn't know about them. + +This only takes filenames as arguments. Custom options can't be used; the script +interprets them as filenames. If mpv is already running, the files passed to +umpv are appended to mpv's internal playlist. If a file does not exist or is +otherwise not playable, mpv will skip the playlist entry when attempting to +play it (from the GUI perspective, it's silently ignored). + +If mpv isn't running yet, this script will start mpv and let it control the +current terminal. It will not write output to stdout/stderr, because this +will typically just fill ~/.xsession-errors with garbage. + +mpv will terminate if there are no more files to play, and running the umpv +script after that will start a new mpv instance. + +Note: you can supply custom mpv path and options with the MPV environment + variable. The environment variable will be split on whitespace, and the + first item is used as path to mpv binary and the rest is passed as options + _if_ the script starts mpv. If mpv is not started by the script (i.e. mpv + is already running), this will be ignored. +""" + +import sys +import os +import socket +import errno +import subprocess +import fcntl +import stat +import string + +files = sys.argv[1:] + +# this is the same method mpv uses to decide this +def is_url(filename): + parts = filename.split("://", 1) + if len(parts) < 2: + return False + # protocol prefix has no special characters => it's an URL + allowed_symbols = string.ascii_letters + string.digits + '_' + prefix = parts[0] + return all(map(lambda c: c in allowed_symbols, prefix)) + +# make them absolute; also makes them safe against interpretation as options +def make_abs(filename): + if not is_url(filename): + return os.path.abspath(filename) + return filename +files = [make_abs(f) for f in files] + +SOCK = os.path.join(os.getenv("HOME"), ".umpv_socket") + +sock = None +try: + sock = socket.socket(socket.AF_UNIX) + sock.connect(SOCK) +except socket.error as e: + if e.errno == errno.ECONNREFUSED: + sock = None + pass # abandoned socket + elif e.errno == errno.ENOENT: + sock = None + pass # doesn't exist + else: + raise e + +if sock: + # Unhandled race condition: what if mpv is terminating right now? + for f in files: + # escape: \ \n " + f = f.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n") + f = "\"" + f + "\"" + sock.send(("raw loadfile " + f + " append\n").encode("utf-8")) +else: + # Let mpv recreate socket if it doesn't already exist. + + opts = (os.getenv("MPV") or "mpv").split() + opts.extend(["--no-terminal", "--force-window", "--input-ipc-server=" + SOCK, + "--"]) + opts.extend(files) + + subprocess.check_call(opts) |