summaryrefslogtreecommitdiff
path: root/mprisctl
blob: ce03642a3cce0582c4567d59719b7dbea49971d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh

printhelp () {
  exit
}

while getopts "hwxd:" o; do case "${o}" in
  w)
    DMENU="tofi"
    ;;
  x)
    DMENU="dmenu"
    ;;
  d) ARGS="$ARGS$OPTARG " ;;
  *) printhelp ;;
esac done

if [ -z "$DMENU" ]; then
  if [ -n "$WAYLAND_DISPLAY" ]; then
    DMENU="tofi"
    DEFARGS="--prompt-text"
  elif [ -n "$DISPLAY" ]; then
    DMENU="dmenu"
    DEFARGS="-p"
  else
    printf "Can't tell if Wayland or X; what gives?\n"
    exit 1
  fi
fi

DMENU_PROMPT=$(playerctl -l | $DMENU $ARGS $DEFARGS 'Players:')
[ -z "$DMENU_PROMPT" ] && exit 1

PLAYERCONTROLS_PROMPT=$(echo "play-pause
pause
play
stop
next
previous
position
volume
status
shuffle" | $DMENU $ARGS $DEFARGS 'Action:')
[ -z "$PLAYERCONTROLS_PROMPT" ] && exit 1

case "$PLAYERCONTROLS_PROMPT" in
  "pause"|"play"|"play-pause"|"stop"|"next"|"previous")
    playerctl -p "$DMENU_PROMPT" "$PLAYERCONTROLS_PROMPT"
    ;;
  "position")
    VALUE=$(seq -100 5 +100 | grep -v '^0$' | sed 's/^[0-9]/\+&/' | $DMENU $ARGS $DEFARGS 'Position:')
    [ -z "$VALUE" ] && exit 1
    playerctl -p "$DMENU_PROMPT" "$PLAYERCONTROLS_PROMPT" "$VALUE"
    ;;
  "volume")
    VALUE=$(set 0 5 100 |$DMENU $ARGS $DEFARGS 'Volume:')
    [ -z "$VALUE" ] && exit 1
    playerctl -p "$DMENU_PROMPT" "$PLAYERCONTROLS_PROMPT" "$VALUE"
    ;;
  "status")
    STATUS_MSG=$(playerctl -p "$DMENU_PROMPT" "$PLAYERCONTROLS_PROMPT")
    notify-send "$DMENU_PROMPT status" "$STATUS_MSG"
    ;;
  "shuffle")
    VALUE=$(echo "On
Off
Toggle
Status" | $DMENU $ARGS $DEFARGS "Shuffle:")
    [ -z "$VALUE" ] && exit 1
    case "$VALUE" in
      "On"|"Off"|"Toggle")
        playerctl -p "$DMENU_PROMPT" "$PLAYERCONTROLS_PROMPT" "$VALUE"
        ;;
      "Status")
        STATUS_MSG=$(playerctl -p "$DMENU_PROMPT" "$PLAYERCONTROLS_PROMPT")
        notify-send "$DMENU_PROMPT shuffle status" "$STATUS_MSG"
        ;;
      *)
        exit 1
        ;;
    esac
    ;;
  *)
    exit 1
    ;;
esac
exit 0