AutoYADM commit: 2025-01-22 13:45:06

This commit is contained in:
Daniel Fichtinger 2025-01-22 13:45:06 -05:00
parent e0a4daea1f
commit 5e452a1408

View file

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
WL_PRESENT_DMENU="tofi"
usage() { usage() {
echo "usage: wl-present [options] <command> [argument]" echo "usage: wl-present [options] <command> [argument]"
echo echo
@ -80,11 +80,15 @@ pipectl-shim() {
opt="$1" opt="$1"
shift shift
case "$opt" in case "$opt" in
-n|--name) arg="$1"; shift; PIPENAME="pipectl.$(id -u).$arg.pipe";; -n | --name)
-i|--in) MODE=in;; arg="$1"
-o|--out) MODE=out;; shift
-f|--force) FORCE=1;; PIPENAME="pipectl.$(id -u).$arg.pipe"
--) break;; ;;
-i | --in) MODE=in ;;
-o | --out) MODE=out ;;
-f | --force) FORCE=1 ;;
--) break ;;
esac esac
done done
@ -95,15 +99,21 @@ pipectl-shim() {
echo "error: could not open pipe at '$PIPE': No such file or directory" >&2 echo "error: could not open pipe at '$PIPE': No such file or directory" >&2
return 1 return 1
else else
cat > "$PIPE" cat >"$PIPE"
fi;; fi ;;
"out") if [[ "$FORCE" -eq 0 && -p "$PIPE" ]]; then "out") if [[ "$FORCE" -eq 0 && -p "$PIPE" ]]; then
echo "error: cannot create pipe at '$PIPE': File exists" >&2 echo "error: cannot create pipe at '$PIPE': File exists" >&2
return 1 return 1
else else
[[ "$FORCE" -eq 1 ]] && rm -f "$PIPE" [[ "$FORCE" -eq 1 ]] && rm -f "$PIPE"
mkfifo "$PIPE"; (tail -f "$PIPE" & echo > "$PIPE"; wait); rm -f "$PIPE" mkfifo "$PIPE"
fi;; (
tail -f "$PIPE" &
echo >"$PIPE"
wait
)
rm -f "$PIPE"
fi ;;
esac esac
} }
@ -122,7 +132,7 @@ slurp-output-or-region() {
mirror() { mirror() {
if [[ "$#" -eq 0 || "$1" =~ ^- ]]; then if [[ "$#" -eq 0 || "$1" =~ ^- ]]; then
OUTPUT_REGION=$(ask-output-or-region) OUTPUT_REGION=$(ask-output-or-region)
IFS='|' read -r OUTPUT REGION <<< "$OUTPUT_REGION" IFS='|' read -r OUTPUT REGION <<<"$OUTPUT_REGION"
mirror "$OUTPUT" -r "$REGION" "$@" mirror "$OUTPUT" -r "$REGION" "$@"
return return
@ -135,7 +145,7 @@ mirror() {
} }
mirror-cmd() { mirror-cmd() {
$PIPECTL -n "$PRESENT_PIPE_NAME" -i <<< "$1" $PIPECTL -n "$PRESENT_PIPE_NAME" -i <<<"$1"
} }
set-output() { set-output() {
@ -170,7 +180,13 @@ ask-output-or-region() {
} }
ask-scaling() { ask-scaling() {
(echo fit; echo cover; echo exact; echo linear; echo nearest) | $DMENU -p "wl-present scaling" (
echo fit
echo cover
echo exact
echo linear
echo nearest
) | $DMENU -p "wl-present scaling"
[[ $? -ne 0 ]] && exit 1 [[ $? -ne 0 ]] && exit 1
} }
@ -206,9 +222,13 @@ while [[ $# -gt 0 && "${1:0:1}" == "-" ]]; do
opt="$1" opt="$1"
shift shift
case "$opt" in case "$opt" in
-n|--name) arg="$1"; shift; PRESENT_PIPE_NAME="$arg";; -n | --name)
-h|--help) usage;; arg="$1"
--) break;; shift
PRESENT_PIPE_NAME="$arg"
;;
-h | --help) usage ;;
--) break ;;
esac esac
done done
@ -217,19 +237,22 @@ if [[ $# -eq 0 ]]; then
fi fi
case "$1" in case "$1" in
help) usage;; help) usage ;;
mirror) shift; mirror "$@";; mirror)
set-output) set-output "${2:-$(ask-output)}";; shift
set-region) set-region "${2:-$(ask-region)}";; mirror "$@"
unset-region|no-region) mirror-cmd --no-region;; ;;
set-scaling) set-scaling "${2:-$(ask-scaling)}";; set-output) set-output "${2:-$(ask-output)}" ;;
freeze) mirror-cmd --freeze;; set-region) set-region "${2:-$(ask-region)}" ;;
unfreeze) mirror-cmd --unfreeze;; unset-region | no-region) mirror-cmd --no-region ;;
toggle-freeze) mirror-cmd --toggle-freeze;; set-scaling) set-scaling "${2:-$(ask-scaling)}" ;;
fullscreen) mirror-cmd --fullscreen;; freeze) mirror-cmd --freeze ;;
unfullscreen|no-fullscreen) mirror-cmd --no-fullscreen;; unfreeze) mirror-cmd --unfreeze ;;
fullscreen-output) set-fullscreen-output "${2:-$(ask-output)}";; toggle-freeze) mirror-cmd --toggle-freeze ;;
no-fullscreen-output) mirror-cmd --no-fullscreen-output;; fullscreen) mirror-cmd --fullscreen ;;
custom) mirror-cmd "${2:-$(ask-custom)}";; unfullscreen | no-fullscreen) mirror-cmd --no-fullscreen ;;
*) usage;; fullscreen-output) set-fullscreen-output "${2:-$(ask-output)}" ;;
no-fullscreen-output) mirror-cmd --no-fullscreen-output ;;
custom) mirror-cmd "${2:-$(ask-custom)}" ;;
*) usage ;;
esac esac